implement scheduled order type

This commit is contained in:
2025-10-29 20:41:26 +03:00
parent 144cfa3f3a
commit ab5d0da47e
18 changed files with 219 additions and 82 deletions

View File

@@ -56,6 +56,7 @@ interface CartState {
orderType: OrderType | "";
useLoyaltyPoints: boolean;
loyaltyValidationError: string | null;
scheduledDate: string;
}
// localStorage keys
@@ -79,6 +80,7 @@ export const CART_STORAGE_KEYS = {
USE_LOYALTY_POINTS: "fascano_use_loyalty_points",
LOYALTY_VALIDATION_ERROR: "fascano_loyalty_validation_error",
RESTAURANT: "fascano_restaurant",
SCHEDULED_DATE: "fascano_scheduled_date",
} as const;
// Utility functions for localStorage
@@ -127,7 +129,10 @@ const initialState: CartState = {
),
phone: getFromLocalStorage(CART_STORAGE_KEYS.PHONE, ""),
paymentMethod: getFromLocalStorage(CART_STORAGE_KEYS.PAYMENT_METHOD, ""),
orderType: getFromLocalStorage(CART_STORAGE_KEYS.ORDER_TYPE, "" as OrderType | ""),
orderType: getFromLocalStorage(
CART_STORAGE_KEYS.ORDER_TYPE,
"" as OrderType | "",
),
useLoyaltyPoints: getFromLocalStorage(
CART_STORAGE_KEYS.USE_LOYALTY_POINTS,
false,
@@ -137,6 +142,7 @@ const initialState: CartState = {
null,
),
restaurant: getFromLocalStorage(CART_STORAGE_KEYS.RESTAURANT, { taxes: [] }),
scheduledDate: getFromLocalStorage(CART_STORAGE_KEYS.SCHEDULED_DATE, ""),
};
const orderSlice = createSlice({
@@ -504,6 +510,17 @@ const orderSlice = createSlice({
);
}
},
updateScheduledDate(state, action: PayloadAction<string>) {
state.scheduledDate = action.payload;
// Sync to localStorage
if (typeof window !== "undefined") {
localStorage.setItem(
CART_STORAGE_KEYS.SCHEDULED_DATE,
JSON.stringify(state.scheduledDate),
);
}
},
},
});
@@ -534,6 +551,7 @@ export const {
clearLoyaltyValidationError,
reset,
updateRestaurant,
updateScheduledDate,
} = orderSlice.actions;
// Tax calculation helper functions