cart & checkout: apply validation based on required inputs in each service & add phone input in checkout page

This commit is contained in:
2025-10-14 23:25:08 +03:00
parent af27d1e509
commit b88cc28c89
13 changed files with 186 additions and 113 deletions

View File

@@ -48,6 +48,7 @@ interface CartState {
estimateTimeDate: Date;
estimateTimeTime: string;
collectionMethod: string;
phone: string;
}
// localStorage keys
@@ -65,6 +66,7 @@ const CART_STORAGE_KEYS = {
ESTIMATE_TIME_DATE: 'fascano_estimate_time_date',
ESTIMATE_TIME_TIME: 'fascano_estimate_time_time',
COLLECTION_METHOD: 'fascano_collection_method',
PHONE: 'fascano_phone',
} as const;
// Utility functions for localStorage
@@ -95,6 +97,7 @@ const initialState: CartState = {
estimateTimeDate: new Date(getFromLocalStorage(CART_STORAGE_KEYS.ESTIMATE_TIME_DATE, new Date().toISOString())),
estimateTimeTime: getFromLocalStorage(CART_STORAGE_KEYS.ESTIMATE_TIME_TIME, ""),
collectionMethod: getFromLocalStorage(CART_STORAGE_KEYS.COLLECTION_METHOD, ""),
phone: getFromLocalStorage(CART_STORAGE_KEYS.PHONE, ""),
};
const orderSlice = createSlice({
@@ -273,6 +276,14 @@ const orderSlice = createSlice({
localStorage.setItem(CART_STORAGE_KEYS.COLLECTION_METHOD, JSON.stringify(state.collectionMethod));
}
},
updatePhone(state, action: PayloadAction<string>) {
state.phone = action.payload;
// Sync to localStorage
if (typeof window !== 'undefined') {
localStorage.setItem(CART_STORAGE_KEYS.PHONE, JSON.stringify(state.phone));
}
},
},
});
@@ -295,6 +306,7 @@ export const {
updateGiftDetails,
updateEstimateTime,
updateCollectionMethod,
updatePhone,
reset,
} = orderSlice.actions;