This commit is contained in:
2025-10-18 16:32:22 +03:00
parent 9d4621d0a4
commit a5418b3724
5 changed files with 33 additions and 29 deletions

View File

@@ -4,24 +4,24 @@ import { useEffect } from "react";
// Cart storage keys - same as in CartContext
const CART_STORAGE_KEYS = {
ITEMS: 'fascano_cart_items',
SPECIAL_REQUEST: 'fascano_special_request',
COUPON: 'fascano_coupon',
TIP: 'fascano_tip',
TABLES: 'fascano_tables',
LOCATION: 'fascano_location',
ROOM_DETAILS: 'fascano_room_details',
OFFICE_DETAILS: 'fascano_office_details',
GIFT_DETAILS: 'fascano_gift_details',
ESTIMATE_TIME: 'fascano_estimate_time',
ESTIMATE_TIME_DATE: 'fascano_estimate_time_date',
ESTIMATE_TIME_TIME: 'fascano_estimate_time_time',
COLLECTION_METHOD: 'fascano_collection_method',
ITEMS: "fascano_cart_items",
SPECIAL_REQUEST: "fascano_special_request",
COUPON: "fascano_coupon",
TIP: "fascano_tip",
TABLES: "fascano_tables",
LOCATION: "fascano_location",
ROOM_DETAILS: "fascano_room_details",
OFFICE_DETAILS: "fascano_office_details",
GIFT_DETAILS: "fascano_gift_details",
ESTIMATE_TIME: "fascano_estimate_time",
ESTIMATE_TIME_DATE: "fascano_estimate_time_date",
ESTIMATE_TIME_TIME: "fascano_estimate_time_time",
COLLECTION_METHOD: "fascano_collection_method",
} as const;
const clearCartFromLocalStorage = () => {
// Clear all cart-related data from localStorage
Object.values(CART_STORAGE_KEYS).forEach(key => {
Object.values(CART_STORAGE_KEYS).forEach((key) => {
localStorage.removeItem(key);
});
};
@@ -29,26 +29,27 @@ const clearCartFromLocalStorage = () => {
export default function LocalStorageHandler({
restaurantID,
restaurantName,
orderType,
}: {
restaurantID: string;
restaurantName: string;
orderType: string;
}) {
useEffect(() => {
// Check if restaurant has changed
const currentStoredRestaurantID = localStorage.getItem("restaurantID");
// If there's a stored restaurant ID and it's different from the current one, clear the cart
if (currentStoredRestaurantID && currentStoredRestaurantID !== restaurantID) {
if (
currentStoredRestaurantID &&
currentStoredRestaurantID !== restaurantID
) {
clearCartFromLocalStorage();
}
// Update localStorage with new values
localStorage.setItem("restaurantID", restaurantID);
localStorage.setItem("restaurantName", restaurantName);
localStorage.setItem("orderType", orderType);
}, [restaurantID, restaurantName, orderType]);
// localStorage.setItem("orderType", orderType);
}, [restaurantID, restaurantName]);
return null;
}

View File

@@ -8,7 +8,7 @@ import ProTitle from "components/ProTitle";
import { useScrollHandler } from "contexts/ScrollHandlerContext";
import useBreakPoint from "hooks/useBreakPoint";
import { useTranslation } from "react-i18next";
import { useParams, useSearchParams } from "react-router-dom";
import { useParams } from "react-router-dom";
import {
useGetMenuQuery,
useGetRestaurantDetailsQuery,
@@ -28,8 +28,6 @@ import styles from "./menu.module.css";
function MenuPage() {
const { id } = useParams();
const [searchParams] = useSearchParams();
const orderType = searchParams.get("orderType");
const { isRTL } = useAppSelector((state) => state.locale);
const { t } = useTranslation();
const { data: restaurantDetails, isLoading: isLoadingRestaurant } =
@@ -45,7 +43,6 @@ function MenuPage() {
);
const { categoryRefs } = useScrollHandler();
const { isMobile, isTablet, isDesktop } = useBreakPoint();
const isLoading = isLoadingRestaurant || isLoadingMenu;
return (
@@ -53,7 +50,6 @@ function MenuPage() {
<LocalStorageHandler
restaurantID={restaurant?.id || ""}
restaurantName={restaurant?.subdomain || ""}
orderType={orderType || ""}
/>
{isLoading ? (