Points now subtract from costs
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user