preserve cart & checkout elment on refersh
This commit is contained in:
@@ -34,6 +34,7 @@ export interface GiftDetailsType {
|
||||
senderEmail: string;
|
||||
isSecret: boolean;
|
||||
cardId: string;
|
||||
giftType: "items" | "vouchers" | "itemsAndVouchers";
|
||||
}
|
||||
|
||||
interface DiscountData {
|
||||
@@ -69,6 +70,7 @@ interface CartState {
|
||||
pickupDate: string;
|
||||
pickupTime: string;
|
||||
pickupType: string;
|
||||
estimateWay: string;
|
||||
order: any;
|
||||
splitBillAmount: number;
|
||||
customerName: string;
|
||||
@@ -76,7 +78,6 @@ interface CartState {
|
||||
hiddenServices: number;
|
||||
visibleServices: number;
|
||||
fee: number;
|
||||
giftType: string;
|
||||
}
|
||||
|
||||
// localStorage keys
|
||||
@@ -110,7 +111,7 @@ export const CART_STORAGE_KEYS = {
|
||||
TOTAL_SERVICES: "fascano_total_services",
|
||||
HIDDEN_SERVICES: "fascano_hidden_services",
|
||||
VISIBLE_SERVICES: "fascano_visible_services",
|
||||
GIFT_TYPE: "fascano_gift_type",
|
||||
ESTIMATE_WAY: "fascano_estimate_way",
|
||||
} as const;
|
||||
|
||||
// Utility functions for localStorage
|
||||
@@ -196,6 +197,7 @@ const initialState: CartState = {
|
||||
pickupDate: getFromLocalStorage(CART_STORAGE_KEYS.PICKUP_DATE, ""),
|
||||
pickupTime: getFromLocalStorage(CART_STORAGE_KEYS.PICKUP_TIME, ""),
|
||||
pickupType: getFromLocalStorage(CART_STORAGE_KEYS.PICKUP_TYPE, ""),
|
||||
estimateWay: getFromLocalStorage(CART_STORAGE_KEYS.ESTIMATE_WAY, "now"),
|
||||
order: getFromLocalStorage(CART_STORAGE_KEYS.ORDER, null),
|
||||
splitBillAmount: 0,
|
||||
customerName: "",
|
||||
@@ -203,7 +205,6 @@ const initialState: CartState = {
|
||||
hiddenServices: 0,
|
||||
visibleServices: 0,
|
||||
fee: 0,
|
||||
giftType: getFromLocalStorage(CART_STORAGE_KEYS.GIFT_TYPE, ""),
|
||||
};
|
||||
|
||||
const orderSlice = createSlice({
|
||||
@@ -676,6 +677,12 @@ const orderSlice = createSlice({
|
||||
);
|
||||
}
|
||||
},
|
||||
updateEstimateWay(state, action: PayloadAction<string>) {
|
||||
state.estimateWay = action.payload;
|
||||
if (typeof window !== "undefined") {
|
||||
localStorage.setItem(CART_STORAGE_KEYS.ESTIMATE_WAY, JSON.stringify(state.estimateWay));
|
||||
}
|
||||
},
|
||||
updateOrder(state, action: PayloadAction<any>) {
|
||||
state.order = action.payload;
|
||||
if (typeof window !== "undefined") {
|
||||
@@ -691,9 +698,6 @@ const orderSlice = createSlice({
|
||||
updateCustomerName(state, action: PayloadAction<string>) {
|
||||
state.customerName = action.payload;
|
||||
},
|
||||
updateGiftType(state, action: PayloadAction<string>) {
|
||||
state.giftType = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -730,10 +734,10 @@ export const {
|
||||
updatePickupDate,
|
||||
updatePickupTime,
|
||||
updatePickUpType,
|
||||
updateEstimateWay,
|
||||
updateOrder,
|
||||
updateSplitBillAmount,
|
||||
updateCustomerName,
|
||||
updateGiftType,
|
||||
} = orderSlice.actions;
|
||||
|
||||
// Tax calculation helper functions
|
||||
|
||||
Reference in New Issue
Block a user