feat(doctors-page): enhance doctor data mapping for representation role and improve rate handling

This commit is contained in:
hamed
2026-06-19 13:27:11 +03:30
parent fe73fa1a05
commit aeef59fe0d
+22 -3
View File
@@ -141,7 +141,26 @@ export default function DoctorsPage() {
const stats: DoctorStats | undefined = useMemo(
() => (statsQ.data?.data as any)?.data ?? statsQ.data?.data, [statsQ.data]
);
const items: AdminDoctor[] = doctorsQ.data?.data ?? [];
// endpoint عمومی /doctors شکل متفاوتی دارد؛ به شکل AdminDoctor نگاشت می‌شود تا جدول کرش نکند.
const rawItems = doctorsQ.data?.data ?? [];
const items: AdminDoctor[] = isRepresentation
// eslint-disable-next-line @typescript-eslint/no-explicit-any
? (rawItems as any[]).map((d) => ({
uuid: d.uuid,
id: d.id,
name: d.name,
gender: d.gender ?? null,
degree: d.degree ?? null,
medical_code: d.medical_code ?? null,
mobile: d.mobile ?? null,
email: d.email ?? null,
is_active: d.is_active ?? d.active ?? false,
rate: Number(d.rate ?? d.point ?? 0) || 0,
specialties: d.specialties ?? [],
profile_image: d.profile_image ?? d.img?.[0]?.url ?? null,
created_at: d.created_at ?? null,
}) as AdminDoctor)
: (rawItems as AdminDoctor[]);
const total = doctorsQ.data?.meta?.totalRecords ?? 0;
const specialties: SpecialtyOption[] = useMemo(
() => (specialtiesQ.data?.data as any)?.data ?? specialtiesQ.data?.data ?? [],
@@ -325,7 +344,7 @@ export default function DoctorsPage() {
</span>
)}
</td>
<td><b style={{ fontSize: 12.5 }}>{doc.rate.toFixed(1)}</b></td>
<td><b style={{ fontSize: 12.5 }}>{(doc.rate ?? 0).toFixed(1)}</b></td>
<td style={{ fontFamily: 'monospace', direction: 'ltr', textAlign: 'right' }} className="muted">
{doc.mobile ?? '—'}
</td>
@@ -401,7 +420,7 @@ export default function DoctorsPage() {
</span>
</div>
<div className="flex" style={{ justifyContent: 'space-between', fontSize: 12.5 }}>
<b>{doc.rate.toFixed(1)}</b>
<b>{(doc.rate ?? 0).toFixed(1)}</b>
<span className="muted">{formatDate(doc.created_at)}</span>
</div>
</div>