move function handle change city to context
This commit is contained in:
@@ -8,13 +8,12 @@ import { styleDefault } from "@/mui";
|
|||||||
import statesData from "@/data/state.json";
|
import statesData from "@/data/state.json";
|
||||||
import citiesData from "@/data/city.json";
|
import citiesData from "@/data/city.json";
|
||||||
import Content from "./Content";
|
import Content from "./Content";
|
||||||
|
import { useProvince } from "@/context/ProvinceProvider";
|
||||||
|
|
||||||
function ModalSearchCity({ children, selected, setSelected, open, setOpen }) {
|
function ModalSearchCity({ children, selected, setSelected, open, setOpen }) {
|
||||||
const provinceSelected = selected.province;
|
const provinceSelected = selected.province;
|
||||||
const [hostName, setHostName] = useState("");
|
const { isProvinceInclude } = useProvince();
|
||||||
const isProvinceInclude = citiesData.find(
|
|
||||||
(city) => city.domain !== "nobat724.com" && hostName.includes(city.domain)
|
|
||||||
);
|
|
||||||
const [states, setStates] = useState([]);
|
const [states, setStates] = useState([]);
|
||||||
const [cities, setCities] = useState([]);
|
const [cities, setCities] = useState([]);
|
||||||
const [filteredCities, setFilteredCities] = useState([]);
|
const [filteredCities, setFilteredCities] = useState([]);
|
||||||
@@ -36,8 +35,6 @@ function ModalSearchCity({ children, selected, setSelected, open, setOpen }) {
|
|||||||
province_id: city.province_id,
|
province_id: city.province_id,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
setHostName(window.location.hostname);
|
|
||||||
|
|
||||||
setStates(formattedStates);
|
setStates(formattedStates);
|
||||||
setCities(formattedCities);
|
setCities(formattedCities);
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
+4
-1
@@ -8,6 +8,7 @@ import { GoogleTagManager } from "@next/third-parties/google";
|
|||||||
// Toastify
|
// Toastify
|
||||||
import "react-toastify/dist/ReactToastify.css";
|
import "react-toastify/dist/ReactToastify.css";
|
||||||
import CustomToastify from "./CustomToastify";
|
import CustomToastify from "./CustomToastify";
|
||||||
|
import { ProvinceProvider } from "@/context/ProvinceProvider";
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: "نوبت724",
|
title: "نوبت724",
|
||||||
@@ -28,7 +29,9 @@ export default function RootLayout({ children }) {
|
|||||||
<ThemeRegistry>
|
<ThemeRegistry>
|
||||||
<GoogleTagManager gtmId="GTM-NXBSV7GS" />
|
<GoogleTagManager gtmId="GTM-NXBSV7GS" />
|
||||||
<body className="bg-[#FAFAFA]">
|
<body className="bg-[#FAFAFA]">
|
||||||
<Providers>{children}</Providers>
|
<ProvinceProvider>
|
||||||
|
<Providers>{children}</Providers>
|
||||||
|
</ProvinceProvider>
|
||||||
<CustomToastify />
|
<CustomToastify />
|
||||||
</body>
|
</body>
|
||||||
<GoogleAnalytics gaId="G-HG3RZ1PJS5" />
|
<GoogleAnalytics gaId="G-HG3RZ1PJS5" />
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { createContext, useContext, useState, useEffect } from "react";
|
||||||
|
import citiesData from "@/data/city.json";
|
||||||
|
|
||||||
|
const ProvinceContext = createContext();
|
||||||
|
|
||||||
|
export const ProvinceProvider = ({ children }) => {
|
||||||
|
const [hostName, setHostName] = useState("");
|
||||||
|
const isProvinceInclude = citiesData.find(
|
||||||
|
(city) => city.domain !== "nobat724.com" && hostName.includes(city.domain)
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
setHostName(window.location.hostname);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ProvinceContext.Provider value={{ isProvinceInclude }}>
|
||||||
|
{children}
|
||||||
|
</ProvinceContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useProvince = () => useContext(ProvinceContext);
|
||||||
Reference in New Issue
Block a user