diff --git a/src/Components/cart/cart.js b/src/Components/cart/cart.js new file mode 100644 index 00000000..f46d9c05 --- /dev/null +++ b/src/Components/cart/cart.js @@ -0,0 +1,128 @@ +// src/components/ShoppingCart.js +import React, { useState, useEffect } from 'react'; + +const ShoppingCart = () => { + const [cartItems, setCartItems] = useState([]); + const [totalItems, setTotalItems] = useState(0); + const [totalPrice, setTotalPrice] = useState(0); + + useEffect(() => { + const items = JSON.parse(localStorage.getItem('cartItems')) || []; + setCartItems(items); + + let itemsCount = 0; + let priceTotal = 0; + + items.forEach(item => { + itemsCount += item.quantity; + priceTotal += item.price * item.quantity; + }); + + setTotalItems(itemsCount); + setTotalPrice(priceTotal); + }, []); + + const checkout = () => { + alert('Proceeding to checkout...'); + }; + + return ( +
+
+

Your Cart

+
+ {cartItems.map((item, index) => ( +
+
+

{item.name}

+

Quantity: {item.quantity}

+

Price: ${item.price * item.quantity}

+
+
+ ))} +
+
+

Total Items: {totalItems}

+

Total Price: ${totalPrice.toFixed(2)}

+ +
+
+ +
+ ); +}; + +export default ShoppingCart; diff --git a/src/configs/router.js b/src/configs/router.js index 5a3fe60f..ba09a5b9 100644 --- a/src/configs/router.js +++ b/src/configs/router.js @@ -25,6 +25,7 @@ import OTPVerification from "../Components/auth/resetPassword/OTPVerification"; import ResetPassword from "../Components/auth/resetPassword/ResetPassword"; import Freelancer from "../Components/FreeLancer/Freelancer"; import Feedbackform from "../Components/feedback/feedbackform"; +import ShoppingCart from "../Components/cart/cart"; const router = createBrowserRouter([ @@ -52,7 +53,9 @@ const router = createBrowserRouter([ { path: "/otpVerification/:email", element: }, { path: "/resetPassword/:email", element: }, { path: "/freelancer", element: }, - { path: "/feedback", element: } + { path: "/feedback", element: }, + { path: "/cart", element: }, + ]); export default router; \ No newline at end of file