fix take "orderType" from url
This commit is contained in:
@@ -27,11 +27,13 @@ import {
|
|||||||
CART_STORAGE_KEYS,
|
CART_STORAGE_KEYS,
|
||||||
} from "features/order/orderSlice.ts";
|
} from "features/order/orderSlice.ts";
|
||||||
import { OrderType } from "pages/checkout/hooks/types.ts";
|
import { OrderType } from "pages/checkout/hooks/types.ts";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const storedOrderType = localStorage.getItem(CART_STORAGE_KEYS.ORDER_TYPE);
|
const storedOrderType = localStorage.getItem(CART_STORAGE_KEYS.ORDER_TYPE);
|
||||||
|
|
||||||
export default function RestaurantPage() {
|
export default function RestaurantPage() {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
const { t } = useTranslation();
|
||||||
const param = useParams();
|
const param = useParams();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
@@ -48,21 +50,13 @@ export default function RestaurantPage() {
|
|||||||
const urlOrderType = searchParams.get("orderType");
|
const urlOrderType = searchParams.get("orderType");
|
||||||
if (urlOrderType && urlOrderType !== orderType)
|
if (urlOrderType && urlOrderType !== orderType)
|
||||||
dispatch(updateOrderType(urlOrderType as OrderType));
|
dispatch(updateOrderType(urlOrderType as OrderType));
|
||||||
else if (
|
else if (storedOrderType && !orderType)
|
||||||
storedOrderType &&
|
|
||||||
storedOrderType !== "" &&
|
|
||||||
storedOrderType !== orderType
|
|
||||||
)
|
|
||||||
dispatch(updateOrderType(storedOrderType as OrderType));
|
dispatch(updateOrderType(storedOrderType as OrderType));
|
||||||
}, [searchParams, orderType]);
|
}, [searchParams, orderType]);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) return <Loader />;
|
||||||
return <Loader />;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!restaurant) {
|
if (!restaurant) return <div>{t("Restaurant not found")}</div>;
|
||||||
return <div>Restaurant not found</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (restaurant) {
|
if (restaurant) {
|
||||||
localStorage.setItem("restaurantID", restaurant.restautantId);
|
localStorage.setItem("restaurantID", restaurant.restautantId);
|
||||||
|
|||||||
Reference in New Issue
Block a user