diff --git a/frontend/src/context/BookingContext.jsx b/frontend/src/context/BookingContext.jsx index fa1784e..4738610 100644 --- a/frontend/src/context/BookingContext.jsx +++ b/frontend/src/context/BookingContext.jsx @@ -19,7 +19,10 @@ export const BookingProvider = ({ children }) => { }, []); const fetchActiveBooking = async () => { - if (!user?._id || !user?.token) { + // console.log("Fetching active booking for user:", user); + // console.log("User ID:", user._id), console.log("User Token:", user.token); + if (!user._id) { + // console.log("No user logged in, cannot fetch bookings."); setActiveBooking(null); return; } @@ -65,13 +68,16 @@ export const BookingProvider = ({ children }) => { }; const addToCart = (item, type = "service") => { - setCart((prev) => ({ - ...prev, - [type === "service" ? "services" : "products"]: [ - ...prev[type === "service" ? "services" : "products"], - item, - ], - })); + setCart((prev) => { + // Prevent duplicates based on ID + const list = type === "service" ? prev.services : prev.products; + if (list.find(i => (i._id || i.id) === (item._id || item.id))) return prev; + + return { + ...prev, + [type === "service" ? "services" : "products"]: [...list, item], + }; + }); }; const removeFromCart = (itemId, type = "service") => { diff --git a/frontend/src/pages/Services.jsx b/frontend/src/pages/Services.jsx index 1947063..c33ef16 100644 --- a/frontend/src/pages/Services.jsx +++ b/frontend/src/pages/Services.jsx @@ -239,7 +239,7 @@ const ServicesFull = () => {
- + {cart.services.length + cart.products.length} Services Selected
@@ -336,10 +336,13 @@ const ServicesFull = () => {
- {item.price ? `₹ ${item.price}` : ""} + {/* {console.log("Item Price:", item.prices)} */} + {(typeof item.prices === "object" && item.prices.male !== item.prices.female)|| (item.price) + ? `₹ ${item.prices?.male} / ₹ ${item.prices.female}` + : `₹ ${item.prices.male}`} - {item.price && item.price.includes("/") ? ( + {(item.prices && item.prices.male && item.prices.female) || (typeof item.price === "string" && item.price.includes("/")) ? (
{ > {/* Default Content: 'Add' */}
Add
{/* Hover/Selected Content: M | F selection */}