diff --git a/src/components/CustomBottomSheet/OrderTypesBottomSheet.tsx b/src/components/CustomBottomSheet/OrderTypesBottomSheet.tsx index 929d494..9347a6f 100644 --- a/src/components/CustomBottomSheet/OrderTypesBottomSheet.tsx +++ b/src/components/CustomBottomSheet/OrderTypesBottomSheet.tsx @@ -17,7 +17,9 @@ export function OrderTypesBottomSheet({ }: OrderTypesBottomSheetBottomSheetProps) { const { t } = useTranslation(); const dispatch = useAppDispatch(); - const { restaurant, orderType } = useAppSelector((state) => state.order); + const { restaurant, orderType, hiddenServices } = useAppSelector( + (state) => state.order, + ); const buttonStyle = { height: 48, @@ -27,21 +29,7 @@ export function OrderTypesBottomSheet({ alignItems: "center", }; - // Count visible services - const visibleServicesCount = [ - restaurant?.dineIn == true, - restaurant?.delivery == true, - restaurant?.pickup == true, - restaurant?.gift == true, - restaurant?.toRoom == true, - restaurant?.toOffice == true, - restaurant?.is_schedule_order_enabled == 1, - restaurant?.is_booking_enabled == 1, - ].filter(Boolean).length; - // Calculate height: base 620px, subtract 48px for each hidden service - const totalServices = 8; - const hiddenServices = totalServices - visibleServicesCount; const calculatedHeight = 620 - hiddenServices * 64; const handleOrderTypeSelect = (selectedOrderType: OrderType) => { diff --git a/src/features/order/orderSlice.ts b/src/features/order/orderSlice.ts index 6e392d0..8aa14da 100644 --- a/src/features/order/orderSlice.ts +++ b/src/features/order/orderSlice.ts @@ -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>) { 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) { 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) { @@ -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;