clean code

This commit is contained in:
2025-12-25 23:39:45 +03:00
parent 611f26f6ff
commit 4bf18087cc
2 changed files with 45 additions and 17 deletions

View File

@@ -17,7 +17,9 @@ export function OrderTypesBottomSheet({
}: OrderTypesBottomSheetBottomSheetProps) { }: OrderTypesBottomSheetBottomSheetProps) {
const { t } = useTranslation(); const { t } = useTranslation();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { restaurant, orderType } = useAppSelector((state) => state.order); const { restaurant, orderType, hiddenServices } = useAppSelector(
(state) => state.order,
);
const buttonStyle = { const buttonStyle = {
height: 48, height: 48,
@@ -27,21 +29,7 @@ export function OrderTypesBottomSheet({
alignItems: "center", 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 // Calculate height: base 620px, subtract 48px for each hidden service
const totalServices = 8;
const hiddenServices = totalServices - visibleServicesCount;
const calculatedHeight = 620 - hiddenServices * 64; const calculatedHeight = 620 - hiddenServices * 64;
const handleOrderTypeSelect = (selectedOrderType: OrderType) => { const handleOrderTypeSelect = (selectedOrderType: OrderType) => {

View File

@@ -71,6 +71,9 @@ interface CartState {
order: any; order: any;
splitBillAmount: number; splitBillAmount: number;
customerName: string; customerName: string;
totalServices: number;
hiddenServices: number;
visibleServices: number;
} }
// localStorage keys // localStorage keys
@@ -101,6 +104,9 @@ export const CART_STORAGE_KEYS = {
PICKUP_TIME: "fascano_pickup_time", PICKUP_TIME: "fascano_pickup_time",
PICKUP_TYPE: "fascano_pickup_type", PICKUP_TYPE: "fascano_pickup_type",
ORDER: "fascano_order", ORDER: "fascano_order",
TOTAL_SERVICES: "fascano_total_services",
HIDDEN_SERVICES: "fascano_hidden_services",
VISIBLE_SERVICES: "fascano_visible_services",
} as const; } as const;
// Utility functions for localStorage // Utility functions for localStorage
@@ -189,6 +195,9 @@ const initialState: CartState = {
order: getFromLocalStorage(CART_STORAGE_KEYS.ORDER, null), order: getFromLocalStorage(CART_STORAGE_KEYS.ORDER, null),
splitBillAmount: 0, splitBillAmount: 0,
customerName: "", customerName: "",
totalServices: 8,
hiddenServices: 0,
visibleServices: 0,
}; };
const orderSlice = createSlice({ const orderSlice = createSlice({
@@ -200,11 +209,33 @@ const orderSlice = createSlice({
}, },
updateRestaurant(state, action: PayloadAction<Partial<RestaurantDetails>>) { updateRestaurant(state, action: PayloadAction<Partial<RestaurantDetails>>) {
state.restaurant = action.payload; 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") { if (typeof window !== "undefined") {
localStorage.setItem( localStorage.setItem(
CART_STORAGE_KEYS.RESTAURANT, CART_STORAGE_KEYS.RESTAURANT,
JSON.stringify(state.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( addItem(
@@ -633,7 +664,10 @@ const orderSlice = createSlice({
updateOrder(state, action: PayloadAction<any>) { updateOrder(state, action: PayloadAction<any>) {
state.order = action.payload; state.order = action.payload;
if (typeof window !== "undefined") { 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>) { updateSplitBillAmount(state, action: PayloadAction<number>) {
@@ -787,7 +821,13 @@ export const selectGrandTotal = (state: RootState) => {
? Number(state.order.restaurant?.delivery_fees) || 0 ? Number(state.order.restaurant?.delivery_fees) || 0
: 0; : 0;
return subtotal + taxAmount - totalDiscount + deliveryFee - state.order.splitBillAmount; return (
subtotal +
taxAmount -
totalDiscount +
deliveryFee -
state.order.splitBillAmount
);
}; };
export default orderSlice.reducer; export default orderSlice.reducer;