feat(clinic): enhance doctor data handling with improved pagination and default values

This commit is contained in:
hamed
2026-06-18 19:16:52 +03:30
parent fdb5866562
commit 4dca516598
4 changed files with 15 additions and 6 deletions
+4 -1
View File
@@ -48,7 +48,10 @@ async function Clinic({ params, searchParams }) {
const clinic = reqClinics?.data?.data || null; const clinic = reqClinics?.data?.data || null;
const doctors = reqDoctors?.data?.data || []; const doctors = reqDoctors?.data?.data || [];
const pagedoctors = reqDoctors?.data?.meta; const meta = reqDoctors?.data?.meta;
const pagedoctors = meta
? { current: meta.currentPage, total_pages: meta.totalPages }
: { current: 1, total_pages: 1 };
const jsonLd = clinic const jsonLd = clinic
? { ? {
@@ -3,7 +3,7 @@ import { FormControlLabel, Radio, RadioGroup } from "@mui/material";
function Radios({ group, value, updateData, name }) { function Radios({ group, value, updateData, name }) {
return ( return (
<RadioGroup <RadioGroup
value={value} value={value ?? ""}
className="radio-mui" className="radio-mui"
onChange={(e) => updateData(name, e.target.value)} onChange={(e) => updateData(name, e.target.value)}
sx={{ sx={{
@@ -32,7 +32,7 @@ function Form({ filter, changeSpecialty, updateData }) {
<div className="mt-[40px] mb-[32px]"> <div className="mt-[40px] mb-[32px]">
<RadioContent <RadioContent
updateData={updateData} updateData={updateData}
value={filter.gender} value={filter.gender ?? "هر دو"}
text="جنسیت پزشک" text="جنسیت پزشک"
group={gender} group={gender}
name="gender" name="gender"
@@ -40,7 +40,7 @@ function Form({ filter, changeSpecialty, updateData }) {
<span className="block mt-[16px] mb-[24px] w-full h-px bg-[#EFEFEF]"></span> <span className="block mt-[16px] mb-[24px] w-full h-px bg-[#EFEFEF]"></span>
<RadioContent <RadioContent
updateData={updateData} updateData={updateData}
value={filter.degree} value={filter.degree ?? "همه موارد"}
text="درجه علمی" text="درجه علمی"
group={degree} group={degree}
name="degree" name="degree"
+8 -2
View File
@@ -17,10 +17,16 @@ export async function getClinicDoctors(slug, params = {}) {
const json = await response.json(); const json = await response.json();
// پاسخ دو لایه nested است: آرایه‌ی پزشکان در json.data.data و صفحه‌بندی در json.data.meta
const doctors = json?.data?.data || [];
const meta = json?.data?.meta;
// ✅ خروجی همیشه ساختار ثابت دارد // ✅ خروجی همیشه ساختار ثابت دارد
return { return {
data: json?.data || [], data: doctors,
page: json?.page || json?.pages || { total_pages: 1, current: 1 }, page: meta
? { total_pages: meta.totalPages, current: meta.currentPage }
: { total_pages: 1, current: 1 },
}; };
} catch (error) { } catch (error) {
console.error("❌ خطا در دریافت دکترهای کلینیک:", error); console.error("❌ خطا در دریافت دکترهای کلینیک:", error);