Points now subtract from costs

This commit is contained in:
augmentedpotato
2026-04-15 02:44:14 -06:00
parent 404f162728
commit 914e0bceda
6 changed files with 192 additions and 7 deletions

View File

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