order page: integration

This commit is contained in:
2025-10-18 09:26:03 +03:00
parent 039bf64b46
commit 9d4621d0a4
14 changed files with 376 additions and 129 deletions

View File

@@ -49,10 +49,11 @@ interface CartState {
estimateTimeTime: string;
collectionMethod: string;
phone: string;
paymentMethod: string;
}
// localStorage keys
const CART_STORAGE_KEYS = {
export const CART_STORAGE_KEYS = {
ITEMS: 'fascano_cart_items',
SPECIAL_REQUEST: 'fascano_special_request',
COUPON: 'fascano_coupon',
@@ -67,6 +68,7 @@ const CART_STORAGE_KEYS = {
ESTIMATE_TIME_TIME: 'fascano_estimate_time_time',
COLLECTION_METHOD: 'fascano_collection_method',
PHONE: 'fascano_phone',
PAYMENT_METHOD: 'fascano_payment_method',
} as const;
// Utility functions for localStorage
@@ -98,6 +100,7 @@ const initialState: CartState = {
estimateTimeTime: getFromLocalStorage(CART_STORAGE_KEYS.ESTIMATE_TIME_TIME, ""),
collectionMethod: getFromLocalStorage(CART_STORAGE_KEYS.COLLECTION_METHOD, ""),
phone: getFromLocalStorage(CART_STORAGE_KEYS.PHONE, ""),
paymentMethod: getFromLocalStorage(CART_STORAGE_KEYS.PAYMENT_METHOD, ""),
};
const orderSlice = createSlice({
@@ -146,6 +149,7 @@ const orderSlice = createSlice({
clearCart(state) {
state.items = [];
state.specialRequest = "";
state.phone = "";
state.coupon = "";
state.tip = "";
state.tables = [];
@@ -157,7 +161,7 @@ const orderSlice = createSlice({
state.estimateTimeDate = new Date();
state.estimateTimeTime = "";
state.collectionMethod = "";
state.paymentMethod = "";
// Clear all cart data from localStorage
if (typeof window !== 'undefined') {
Object.values(CART_STORAGE_KEYS).forEach(key => {
@@ -198,7 +202,7 @@ const orderSlice = createSlice({
}
},
updateTables(state, action: PayloadAction<string[]>) {
state.tables = [...state.tables, ...action.payload];
state.tables = action.payload;
// Sync to localStorage
if (typeof window !== 'undefined') {
@@ -284,6 +288,14 @@ const orderSlice = createSlice({
localStorage.setItem(CART_STORAGE_KEYS.PHONE, JSON.stringify(state.phone));
}
},
updatePaymentMethod(state, action: PayloadAction<string>) {
state.paymentMethod = action.payload;
// Sync to localStorage
if (typeof window !== 'undefined') {
localStorage.setItem(CART_STORAGE_KEYS.PAYMENT_METHOD, JSON.stringify(state.paymentMethod));
}
},
},
});
@@ -307,6 +319,7 @@ export const {
updateEstimateTime,
updateCollectionMethod,
updatePhone,
updatePaymentMethod,
reset,
} = orderSlice.actions;