Files
nobat724_front/app/doctors/page.js
T
hamed ab2ab0dea2 feat: enhance domain handling for global representatives
- Updated `getStateInfo` to fetch site context for domains not in city.json, returning `repContext` with representative details.
- Implemented caching for site context requests to optimize performance.
- Modified doctor and clinic listing pages to pass the `domain` parameter when fetching data for global representatives.
- Adjusted metadata generation in layout and pages to reflect representative branding based on `repContext`.
- Added documentation for the new functionality in `.claude/prompt/global-rep-domain-site.md`.
2026-07-09 07:34:09 +03:30

89 lines
3.3 KiB
JavaScript

import DoctorsPage from "@/components/doctors";
import Layout from "@/components/layout/StLayout";
import { buildDoctorParams } from "@/helper";
import { getStateInfo } from "@/lib/getStateInfo";
import { fetchReq } from "@/lib/req";
const FILTER_KEYS = ["specialty", "state", "city", "gender", "degree", "active", "sort", "name"];
// جستجوی داخلی و ترکیب چند فیلتر نباید ایندکس شوند — crawl budget و duplicate
function listingRobots(params) {
const activeFilters = FILTER_KEYS.filter((key) => params?.[key]);
if (params?.name || activeFilters.length >= 2) {
return { robots: { index: false, follow: true } };
}
return {};
}
export async function generateMetadata({ searchParams }) {
const awaitedParams = await searchParams;
const { matchedCity, matchedState, repContext } = await getStateInfo();
const siteName = matchedCity?.site_name || repContext?.full_name || "نوبت 724";
const cityName = matchedCity?.name || matchedState?.name || "";
const title = cityName
? `پزشکان ${cityName} | جستجو و رزرو نوبت | ${siteName}`
: `جستجوی پزشک و رزرو نوبت آنلاین | ${siteName}`;
const description = cityName
? `لیست پزشکان متخصص در ${cityName}. جستجو بر اساس تخصص و منطقه. رزرو آنلاین نوبت پزشکی در ${cityName}.`
: `جستجوی پزشکان متخصص در سراسر کشور. رزرو آنلاین نوبت پزشکی سریع و آسان با نوبت 724.`;
const image = "https://nobat724.com/assets/images/logo.png";
return {
title,
description,
...listingRobots(awaitedParams),
openGraph: { title, description, images: [image] },
twitter: { card: "summary_large_image", title, description, images: [image] },
};
}
async function Doctors({ searchParams }) {
const awaitedSearchParams = await searchParams;
const { matchedCity, matchedState, isRoot, repContext, host } = await getStateInfo();
const API_URL = process.env.NEXT_PUBLIC_API_URL;
let doctors = null;
const stateParams = awaitedSearchParams.state;
const cityParams = awaitedSearchParams.city;
try {
let newSearchParams = awaitedSearchParams;
// Conditional State — روی دامنهٔ ریشه (nobat724) فیلتر اعمال نمی‌شود.
if (stateParams) newSearchParams.state = stateParams;
else if (matchedState && !isRoot) newSearchParams.state = matchedState.name;
// Conditional City
if (cityParams) newSearchParams.city = cityParams;
else if (matchedCity && !isRoot) newSearchParams.city = matchedCity.name;
const params = buildDoctorParams(newSearchParams);
// دامنه‌ی نماینده سراسری: backend فقط پزشکان همان نماینده را برمی‌گرداند؛ فیلتر شهر بی‌معنی است.
if (repContext?.is_global) {
delete params.city_id;
delete params.state_id;
params.domain = host;
}
doctors = await fetchReq(`${API_URL}/api/v1/doctors`, {
params,
});
} catch (error) {
console.error("Error fetching doctors:", error);
}
return (
<Layout>
<DoctorsPage
list={doctors}
params={searchParams}
matchedCity={matchedCity}
matchedState={matchedState}
/>
</Layout>
);
}
export default Doctors;