clean code
This commit is contained in:
@@ -71,6 +71,9 @@ interface CartState {
|
||||
order: any;
|
||||
splitBillAmount: number;
|
||||
customerName: string;
|
||||
totalServices: number;
|
||||
hiddenServices: number;
|
||||
visibleServices: number;
|
||||
}
|
||||
|
||||
// localStorage keys
|
||||
@@ -101,6 +104,9 @@ export const CART_STORAGE_KEYS = {
|
||||
PICKUP_TIME: "fascano_pickup_time",
|
||||
PICKUP_TYPE: "fascano_pickup_type",
|
||||
ORDER: "fascano_order",
|
||||
TOTAL_SERVICES: "fascano_total_services",
|
||||
HIDDEN_SERVICES: "fascano_hidden_services",
|
||||
VISIBLE_SERVICES: "fascano_visible_services",
|
||||
} as const;
|
||||
|
||||
// Utility functions for localStorage
|
||||
@@ -189,6 +195,9 @@ const initialState: CartState = {
|
||||
order: getFromLocalStorage(CART_STORAGE_KEYS.ORDER, null),
|
||||
splitBillAmount: 0,
|
||||
customerName: "",
|
||||
totalServices: 8,
|
||||
hiddenServices: 0,
|
||||
visibleServices: 0,
|
||||
};
|
||||
|
||||
const orderSlice = createSlice({
|
||||
@@ -200,11 +209,33 @@ const orderSlice = createSlice({
|
||||
},
|
||||
updateRestaurant(state, action: PayloadAction<Partial<RestaurantDetails>>) {
|
||||
state.restaurant = action.payload;
|
||||
state.visibleServices = [
|
||||
action.payload.dineIn,
|
||||
action.payload.delivery,
|
||||
action.payload.pickup,
|
||||
action.payload.gift,
|
||||
action.payload.toRoom,
|
||||
action.payload.toOffice,
|
||||
].filter(Boolean).length;
|
||||
state.hiddenServices = state.totalServices - state.visibleServices;
|
||||
if (typeof window !== "undefined") {
|
||||
localStorage.setItem(
|
||||
CART_STORAGE_KEYS.RESTAURANT,
|
||||
JSON.stringify(state.restaurant),
|
||||
);
|
||||
|
||||
localStorage.setItem(
|
||||
CART_STORAGE_KEYS.TOTAL_SERVICES,
|
||||
JSON.stringify(state.totalServices),
|
||||
);
|
||||
localStorage.setItem(
|
||||
CART_STORAGE_KEYS.HIDDEN_SERVICES,
|
||||
JSON.stringify(state.hiddenServices),
|
||||
);
|
||||
localStorage.setItem(
|
||||
CART_STORAGE_KEYS.VISIBLE_SERVICES,
|
||||
JSON.stringify(state.visibleServices),
|
||||
);
|
||||
}
|
||||
},
|
||||
addItem(
|
||||
@@ -633,7 +664,10 @@ const orderSlice = createSlice({
|
||||
updateOrder(state, action: PayloadAction<any>) {
|
||||
state.order = action.payload;
|
||||
if (typeof window !== "undefined") {
|
||||
localStorage.setItem(CART_STORAGE_KEYS.ORDER, JSON.stringify(state.order));
|
||||
localStorage.setItem(
|
||||
CART_STORAGE_KEYS.ORDER,
|
||||
JSON.stringify(state.order),
|
||||
);
|
||||
}
|
||||
},
|
||||
updateSplitBillAmount(state, action: PayloadAction<number>) {
|
||||
@@ -787,7 +821,13 @@ export const selectGrandTotal = (state: RootState) => {
|
||||
? Number(state.order.restaurant?.delivery_fees) || 0
|
||||
: 0;
|
||||
|
||||
return subtotal + taxAmount - totalDiscount + deliveryFee - state.order.splitBillAmount;
|
||||
return (
|
||||
subtotal +
|
||||
taxAmount -
|
||||
totalDiscount +
|
||||
deliveryFee -
|
||||
state.order.splitBillAmount
|
||||
);
|
||||
};
|
||||
|
||||
export default orderSlice.reducer;
|
||||
|
||||
Reference in New Issue
Block a user