68 lines
2.4 KiB
JavaScript
68 lines
2.4 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";
|
|
|
|
export async function generateMetadata() {
|
|
const { matchedCity, matchedState } = await getStateInfo();
|
|
const siteName = matchedCity?.site_name || "نوبت 724";
|
|
const cityName = matchedCity?.name || matchedState?.name || "";
|
|
const title = cityName
|
|
? `پزشکان ${cityName} | جستجو و رزرو نوبت | ${siteName}`
|
|
: `جستجوی پزشک و رزرو نوبت آنلاین | ${siteName}`;
|
|
const description = cityName
|
|
? `لیست پزشکان متخصص در ${cityName}. جستجو بر اساس تخصص و منطقه. رزرو آنلاین نوبت پزشکی در ${cityName}.`
|
|
: `جستجوی پزشکان متخصص در سراسر کشور. رزرو آنلاین نوبت پزشکی سریع و آسان با نوبت 724.`;
|
|
const image = "https://www.nobat724.com/assets/images/logo.png";
|
|
return {
|
|
title,
|
|
description,
|
|
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 } = 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);
|
|
|
|
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;
|