fix(doctor): unwrap double-nested API response and guard empty sections
The GET /api/v1/doctor/{uuid} response is double-nested
({ success, data: { data: {...} } }), but the page only unwrapped one
level, leaving every field (name, specialties, expertise, address)
undefined — so خدمات / موقعیت مکانی / نظرات rendered empty or broken.
- Extract the doctor object with res.data?.data?.data in both
generateMetadata and the page.
- Hide the خدمات block when expertise is empty (no fabricated data).
- Render the location map iframe and routing buttons only when the
address has real latitude/longitude (was building q=null,null).
- Fix the comments list rendering a stray 0 on empty arrays.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,7 @@ export async function generateMetadata({ params }) {
|
||||
|
||||
try {
|
||||
const res = await axiosInstance.get(`${API_URL}/api/v1/doctor/${slug}`);
|
||||
const doctor = res.data;
|
||||
const doctor = res.data?.data?.data;
|
||||
if (!doctor) return {};
|
||||
|
||||
const specialtyNames = doctor.specialties?.map((s) => s.name).join(" و ") || "";
|
||||
@@ -49,7 +49,7 @@ async function Doctor({ params }) {
|
||||
|
||||
try {
|
||||
const resDoctor = await axiosInstance.get(`${API_URL}/api/v1/doctor/${slug}`);
|
||||
doctor = resDoctor.data;
|
||||
doctor = resDoctor.data?.data?.data;
|
||||
if (doctor) {
|
||||
const resComments = await axiosInstance.get(
|
||||
`${API_URL}/api/v1/clinicpro/comments/${doctor.id}`
|
||||
|
||||
Reference in New Issue
Block a user