take "orderType" from url
This commit is contained in:
@@ -5,7 +5,7 @@ import XIcon from "components/Icons/social/XIcon";
|
||||
import { LanguageSwitch } from "components/LanguageSwitch/LanguageSwitch";
|
||||
import ProText from "components/ProText";
|
||||
import ProTitle from "components/ProTitle";
|
||||
import { useAppSelector } from "redux/hooks";
|
||||
import { useAppSelector, useAppDispatch } from "redux/hooks";
|
||||
import styles from "./restaurant.module.css";
|
||||
import RestaurantServices from "./RestaurantServices";
|
||||
|
||||
@@ -13,13 +13,29 @@ import RestaurantServices from "./RestaurantServices";
|
||||
import Ads1 from "components/Ads/Ads1";
|
||||
import { Loader } from "components/Loader/Loader";
|
||||
import { useRestaurant } from "hooks/useRestaurant";
|
||||
import { useParams, Outlet, useLocation } from "react-router-dom";
|
||||
import {
|
||||
useParams,
|
||||
Outlet,
|
||||
useLocation,
|
||||
useSearchParams,
|
||||
} from "react-router-dom";
|
||||
import { useGetRestaurantDetailsQuery } from "redux/api/others";
|
||||
import LocalStorageHandler from "../menu/components/LocalStorageHandler";
|
||||
import { useEffect } from "react";
|
||||
import {
|
||||
updateOrderType,
|
||||
CART_STORAGE_KEYS,
|
||||
} from "features/order/orderSlice.ts";
|
||||
import { OrderType } from "pages/checkout/hooks/types.ts";
|
||||
|
||||
const storedOrderType = localStorage.getItem(CART_STORAGE_KEYS.ORDER_TYPE);
|
||||
|
||||
export default function RestaurantPage() {
|
||||
const dispatch = useAppDispatch();
|
||||
const param = useParams();
|
||||
const [searchParams] = useSearchParams();
|
||||
const { pathname } = useLocation();
|
||||
const { orderType } = useAppSelector((state) => state.order);
|
||||
const { isRTL } = useAppSelector((state) => state.locale);
|
||||
const { data: restaurant, isLoading } = useGetRestaurantDetailsQuery("595", {
|
||||
skip: !param.id,
|
||||
@@ -28,6 +44,18 @@ export default function RestaurantPage() {
|
||||
// Automatically load restaurant taxes when restaurant data is available
|
||||
useRestaurant(restaurant);
|
||||
|
||||
useEffect(() => {
|
||||
const urlOrderType = searchParams.get("orderType");
|
||||
if (urlOrderType && urlOrderType !== orderType)
|
||||
dispatch(updateOrderType(urlOrderType as OrderType));
|
||||
else if (
|
||||
storedOrderType &&
|
||||
storedOrderType !== "" &&
|
||||
storedOrderType !== orderType
|
||||
)
|
||||
dispatch(updateOrderType(storedOrderType as OrderType));
|
||||
}, [searchParams, orderType]);
|
||||
|
||||
if (isLoading) {
|
||||
return <Loader />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user