refactor: improve key assignment in FrequentSearches and update TextHeader to use async getStateInfo

This commit is contained in:
hamed
2025-12-10 09:53:51 +03:30
parent 1df39909ea
commit 23f20626a6
3 changed files with 11 additions and 6 deletions
+2 -1
View File
@@ -14,6 +14,7 @@ function FrequentSearches() {
<ul className="flex items-center justify-start gap-[14px] pl-[14px]">
{childrenList.map((item, idx) => (
<Link
key={item.id || idx}
href={{
pathname: "/doctors",
query: {
@@ -21,7 +22,7 @@ function FrequentSearches() {
},
}}
>
<li key={idx}>
<li>
<Button
variant="contained"
color="secondary"
+2 -2
View File
@@ -2,8 +2,8 @@ import { getStateInfo } from "@/lib/getStateInfo";
import AText from "../icons/AText";
import BText from "../icons/BText";
function TextHeader() {
const { matchedCity } = getStateInfo();
async function TextHeader() {
const { matchedCity } = await getStateInfo();
return (
<div className="z-[50]">
+7 -3
View File
@@ -6,12 +6,16 @@ import statesData from "@/data/state.json";
export async function getStateInfo() {
const headersList = await headers();
const host = headersList.get("host") || "";
const subdomain = host.split(".")[0];
const matchedCity = citiesData.find((city) =>
city.domain.includes(subdomain),
);
// Match city by domain (supports both full domain and 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 =
matchedCity &&
statesData.find((state) => state.id === matchedCity.province_id);