add to cart online in khoshbinane
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
@@ -1,3 +1,4 @@
|
||||
import { useMemo } from "react";
|
||||
import { useGetProfile } from "@/app/[name]/(Profile)/profile/hooks/userProfileData";
|
||||
import { useReceiptStore } from "@/zustand/receiptStore";
|
||||
import {
|
||||
@@ -39,7 +40,7 @@ export const useCart = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const getCartItems = () => {
|
||||
const cartItemsMap = useMemo(() => {
|
||||
if (isSuccess) {
|
||||
if (!cartItems?.data?.items) {
|
||||
return {};
|
||||
@@ -51,14 +52,14 @@ export const useCart = () => {
|
||||
} else {
|
||||
return items;
|
||||
}
|
||||
};
|
||||
}, [isSuccess, cartItems?.data?.items, items]);
|
||||
|
||||
const isItemLoading = () => {
|
||||
return false;
|
||||
};
|
||||
|
||||
return {
|
||||
items: getCartItems(),
|
||||
items: cartItemsMap,
|
||||
increment,
|
||||
decrement,
|
||||
clear,
|
||||
|
||||
@@ -29,6 +29,7 @@ export const useIncrementCart = () => {
|
||||
);
|
||||
|
||||
if (existingItem) {
|
||||
// بهروزرسانی خوشبینانه برای آیتم موجود
|
||||
const updatedItems = previousCart.data.items.map((item) => {
|
||||
if (item.foodId === String(id)) {
|
||||
return {
|
||||
@@ -47,6 +48,25 @@ export const useIncrementCart = () => {
|
||||
totalItems: previousCart.data.totalItems + 1,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// افزودن خوشبینانه برای آیتم جدید
|
||||
const newItem: CartItem = {
|
||||
foodId: String(id),
|
||||
foodTitle: "", // این بعداً از سرور پر میشود
|
||||
quantity: 1,
|
||||
price: 0,
|
||||
discount: 0,
|
||||
totalPrice: 0,
|
||||
};
|
||||
|
||||
queryClient.setQueryData<CartResponse>(["cart-items"], {
|
||||
...previousCart,
|
||||
data: {
|
||||
...previousCart.data,
|
||||
items: [...previousCart.data.items, newItem],
|
||||
totalItems: previousCart.data.totalItems + 1,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,9 +119,9 @@ function Combobox({ title, options, placeholder, icon: Icon, expanded, selectedI
|
||||
>
|
||||
<label
|
||||
htmlFor="content-select"
|
||||
className="pointer-events-none inline-flex flex-col items-end justify-center px-1 py-0 absolute -top-6 right-0 z-[2]"
|
||||
className="pointer-events-none inline-flex flex-col items-end justify-center px-1 py-0 absolute -top-6 right-0 z-2"
|
||||
>
|
||||
<span className="relative text-foreground w-fit mt-[-1px] text-xs tracking-[0] leading-4 whitespace-nowrap">
|
||||
<span className="relative text-foreground w-fit -mt-px text-xs tracking-[0] leading-4 whitespace-nowrap">
|
||||
{title}
|
||||
</span>
|
||||
</label>
|
||||
|
||||
@@ -144,6 +144,7 @@ const MenuItem = ({ food }: MenuItemProps) => {
|
||||
<button
|
||||
onClick={handleAddToCart}
|
||||
className="inline-flex w-full justify-center items-center gap-2"
|
||||
|
||||
>
|
||||
<PlusIcon />
|
||||
<div className="text-sm2 pt-0.5 font-normal text-foreground">
|
||||
|
||||
Reference in New Issue
Block a user