Coupon system working properly

This commit is contained in:
augmentedpotato
2026-04-15 00:54:46 -06:00
parent 51a03fe2c5
commit 3f5add59e8
7 changed files with 263 additions and 32 deletions

View File

@@ -9,6 +9,7 @@ import {
apiRemoveCartItem,
apiClearCart,
apiApplyCoupon,
apiRemoveCoupon,
apiCheckout,
apiCancelCheckout,
} from "@/lib/cartApi";
@@ -124,6 +125,17 @@ export function CartProvider({ children }) {
[token, selectedStoreId]
);
const removeCoupon = useCallback(
async () => {
if (!token || !selectedStoreId) throw new Error("Select a store first");
const updated = await apiRemoveCoupon(token, selectedStoreId);
setCart(updated);
return updated;
},
[token, selectedStoreId]
);
const checkout = useCallback(
async () => {
if (!token || !selectedStoreId) throw new Error("Select a store first");
@@ -159,6 +171,7 @@ export function CartProvider({ children }) {
removeItem,
clearCart,
applyCoupon,
removeCoupon,
checkout,
cancelCheckout,
refreshCart,