From ff54daf1ae62462a7483c5431905ee17076880ed Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Mon, 15 Jun 2026 15:18:06 +0330 Subject: [PATCH] fix(doctor): unwrap double-nested API response and guard empty sections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app/component/comment/index.js | 3 +- app/doctor/[slug]/page.js | 4 +- .../doctor/detailDoctor/cards/AboutDcotor.js | 36 ++++++----- .../detailDoctor/cards/locations/Item.js | 62 ++++++++++--------- 4 files changed, 55 insertions(+), 50 deletions(-) diff --git a/app/component/comment/index.js b/app/component/comment/index.js index 373e4ba..59e4def 100644 --- a/app/component/comment/index.js +++ b/app/component/comment/index.js @@ -11,8 +11,7 @@ function Comment({ comments }) { false && "w-full" }`} > - {comments && - comments.length && + {comments?.length > 0 && comments.map((item, idx) => ( 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}` diff --git a/components/doctor/detailDoctor/cards/AboutDcotor.js b/components/doctor/detailDoctor/cards/AboutDcotor.js index ccb2a53..917ca0c 100644 --- a/components/doctor/detailDoctor/cards/AboutDcotor.js +++ b/components/doctor/detailDoctor/cards/AboutDcotor.js @@ -39,23 +39,25 @@ function AboutDcotor({ doctor }) { -
-

- خدمات -

-
    - {doctor?.expertise?.map((item, idx) => ( -
  • - - -

    - {item.name} -

    -
    -
  • - ))} -
-
+ {doctor?.expertise?.length > 0 && ( +
+

+ خدمات +

+
    + {doctor.expertise.map((item, idx) => ( +
  • + + +

    + {item.name} +

    +
    +
  • + ))} +
+
+ )} ); } diff --git a/components/doctor/detailDoctor/cards/locations/Item.js b/components/doctor/detailDoctor/cards/locations/Item.js index d19a7f5..715e9b8 100644 --- a/components/doctor/detailDoctor/cards/locations/Item.js +++ b/components/doctor/detailDoctor/cards/locations/Item.js @@ -49,6 +49,35 @@ function Item({ data }) {

تلفن: {data.telephone}

+ {data?.map?.latitude && data?.map?.longitude && ( + + + + )} + + + {data?.map?.latitude && data?.map?.longitude && ( +
+ +
- -
- - - - - -
+ )} );