diff --git a/package.json b/package.json
index b7d4c1d1d..5dc2a5566 100644
--- a/package.json
+++ b/package.json
@@ -5,12 +5,14 @@
"type": "module",
"scripts": {
"dev": "vite",
+ "predeploy": "npm run build",
+ "deploy": "gh-pages -d dist",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite build; vite preview --host"
},
"dependencies": {
- "@reduxjs/toolkit": "^2.2.3",
+ "@reduxjs/toolkit": "^2.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^9.1.1"
@@ -23,7 +25,7 @@
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
- "gh-pages": "^6.1.1",
+ "gh-pages": "^6.2.0",
"vite": "^5.2.0"
}
}
diff --git a/src/CartItem.jsx b/src/CartItem.jsx
index e06317433..a8d1f8f1b 100644
--- a/src/CartItem.jsx
+++ b/src/CartItem.jsx
@@ -2,34 +2,42 @@ import React from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { removeItem, updateQuantity } from './CartSlice';
import './CartItem.css';
+import ProductList from './ProductList';
const CartItem = ({ onContinueShopping }) => {
const cart = useSelector(state => state.cart.items);
const dispatch = useDispatch();
- // Calculate total amount for all products in the cart
const calculateTotalAmount = () => {
-
+ return cart.reduce((total, item) => {
+ const itemCost = parseFloat(item.cost.replace('$', '')); // Remove '$' and convert to number
+ return total + (itemCost * item.quantity);
+ }, 0).toFixed(2);
};
- const handleContinueShopping = (e) => {
-
+ const handleContinueShopping = () => {
+ onContinueShopping();
};
-
-
const handleIncrement = (item) => {
+ dispatch(updateQuantity({ name: item.name, quantity: item.quantity + 1 }));
};
const handleDecrement = (item) => {
-
+ if (item.quantity > 1) {
+ dispatch(updateQuantity({ name: item.name, quantity: item.quantity - 1 }));
+ } else {
+ dispatch(removeItem({ name: item.name })); // Remove item if quantity reaches 0
+ }
};
const handleRemove = (item) => {
+ dispatch(removeItem({ name: item.name })); // Dispatch the remove action with item name
};
- // Calculate total cost based on quantity for an item
const calculateTotalCost = (item) => {
+ const itemCost = parseFloat(item.cost.replace('$', ''));
+ return (itemCost * item.quantity).toFixed(2);
};
return (
@@ -41,28 +49,8 @@ const CartItem = ({ onContinueShopping }) => {
{item.name}
-
{item.cost}
+
${parseFloat(item.cost.replace('$', '')).toFixed(2)}
{item.quantity}
-
-
-
Total: ${calculateTotalCost(item)}
-
-
-
- ))}
-
-
-
-
-
-
-
-
- );
-};
-
-export default CartItem;
-
-
+