refactor: improve key assignment in FrequentSearches and update TextHeader to use async getStateInfo
This commit is contained in:
@@ -14,6 +14,7 @@ function FrequentSearches() {
|
|||||||
<ul className="flex items-center justify-start gap-[14px] pl-[14px]">
|
<ul className="flex items-center justify-start gap-[14px] pl-[14px]">
|
||||||
{childrenList.map((item, idx) => (
|
{childrenList.map((item, idx) => (
|
||||||
<Link
|
<Link
|
||||||
|
key={item.id || idx}
|
||||||
href={{
|
href={{
|
||||||
pathname: "/doctors",
|
pathname: "/doctors",
|
||||||
query: {
|
query: {
|
||||||
@@ -21,7 +22,7 @@ function FrequentSearches() {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<li key={idx}>
|
<li>
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { getStateInfo } from "@/lib/getStateInfo";
|
|||||||
import AText from "../icons/AText";
|
import AText from "../icons/AText";
|
||||||
import BText from "../icons/BText";
|
import BText from "../icons/BText";
|
||||||
|
|
||||||
function TextHeader() {
|
async function TextHeader() {
|
||||||
const { matchedCity } = getStateInfo();
|
const { matchedCity } = await getStateInfo();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="z-[50]">
|
<div className="z-[50]">
|
||||||
|
|||||||
+7
-3
@@ -6,12 +6,16 @@ import statesData from "@/data/state.json";
|
|||||||
|
|
||||||
export async function getStateInfo() {
|
export async function getStateInfo() {
|
||||||
const headersList = await headers();
|
const headersList = await headers();
|
||||||
|
|
||||||
const host = headersList.get("host") || "";
|
const host = headersList.get("host") || "";
|
||||||
const subdomain = host.split(".")[0];
|
const subdomain = host.split(".")[0];
|
||||||
|
|
||||||
const matchedCity = citiesData.find((city) =>
|
// Match city by domain (supports both full domain and subdomain)
|
||||||
city.domain.includes(subdomain),
|
const matchedCity = citiesData.find((city) => {
|
||||||
);
|
const cityDomain = city.domain.split(".")[0]; // Extract subdomain from domain (e.g., "yasuj-nobat" from "yasuj-nobat.ir")
|
||||||
|
return cityDomain === subdomain;
|
||||||
|
});
|
||||||
|
|
||||||
const matchedState =
|
const matchedState =
|
||||||
matchedCity &&
|
matchedCity &&
|
||||||
statesData.find((state) => state.id === matchedCity.province_id);
|
statesData.find((state) => state.id === matchedCity.province_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user