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,8 +11,7 @@ function Comment({ comments }) {
|
|||||||
false && "w-full"
|
false && "w-full"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{comments &&
|
{comments?.length > 0 &&
|
||||||
comments.length &&
|
|
||||||
comments.map((item, idx) => (
|
comments.map((item, idx) => (
|
||||||
<ItemUser
|
<ItemUser
|
||||||
key={idx}
|
key={idx}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export async function generateMetadata({ params }) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await axiosInstance.get(`${API_URL}/api/v1/doctor/${slug}`);
|
const res = await axiosInstance.get(`${API_URL}/api/v1/doctor/${slug}`);
|
||||||
const doctor = res.data;
|
const doctor = res.data?.data?.data;
|
||||||
if (!doctor) return {};
|
if (!doctor) return {};
|
||||||
|
|
||||||
const specialtyNames = doctor.specialties?.map((s) => s.name).join(" و ") || "";
|
const specialtyNames = doctor.specialties?.map((s) => s.name).join(" و ") || "";
|
||||||
@@ -49,7 +49,7 @@ async function Doctor({ params }) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const resDoctor = await axiosInstance.get(`${API_URL}/api/v1/doctor/${slug}`);
|
const resDoctor = await axiosInstance.get(`${API_URL}/api/v1/doctor/${slug}`);
|
||||||
doctor = resDoctor.data;
|
doctor = resDoctor.data?.data?.data;
|
||||||
if (doctor) {
|
if (doctor) {
|
||||||
const resComments = await axiosInstance.get(
|
const resComments = await axiosInstance.get(
|
||||||
`${API_URL}/api/v1/clinicpro/comments/${doctor.id}`
|
`${API_URL}/api/v1/clinicpro/comments/${doctor.id}`
|
||||||
|
|||||||
@@ -39,12 +39,13 @@ function AboutDcotor({ doctor }) {
|
|||||||
</Button>
|
</Button>
|
||||||
</MultilineLoading>
|
</MultilineLoading>
|
||||||
</div>
|
</div>
|
||||||
|
{doctor?.expertise?.length > 0 && (
|
||||||
<div className="mt-[12px] lg:mt-[8px] mb-6 md:mb-7 lg:mb-8">
|
<div className="mt-[12px] lg:mt-[8px] mb-6 md:mb-7 lg:mb-8">
|
||||||
<p className="text-[#525252] text-[14px] md:text-[16px] font-bold">
|
<p className="text-[#525252] text-[14px] md:text-[16px] font-bold">
|
||||||
خدمات
|
خدمات
|
||||||
</p>
|
</p>
|
||||||
<ul className="flex flex-col mt-[12px] sm:flex-row gap-y-[16px] items-start sm:items-center justify-start gap-4 flex-wrap">
|
<ul className="flex flex-col mt-[12px] sm:flex-row gap-y-[16px] items-start sm:items-center justify-start gap-4 flex-wrap">
|
||||||
{doctor?.expertise?.map((item, idx) => (
|
{doctor.expertise.map((item, idx) => (
|
||||||
<li key={idx} className="flex items-center justify-start gap-1">
|
<li key={idx} className="flex items-center justify-start gap-1">
|
||||||
<span className="w-2 h-2 bg-[#F17732] rounded-full"></span>
|
<span className="w-2 h-2 bg-[#F17732] rounded-full"></span>
|
||||||
<TextLoading width={70} height={18}>
|
<TextLoading width={70} height={18}>
|
||||||
@@ -56,6 +57,7 @@ function AboutDcotor({ doctor }) {
|
|||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ function Item({ data }) {
|
|||||||
<p className="text-[#525252] text-[16px] font-normal">
|
<p className="text-[#525252] text-[16px] font-normal">
|
||||||
تلفن: {data.telephone}
|
تلفن: {data.telephone}
|
||||||
</p>
|
</p>
|
||||||
|
{data?.map?.latitude && data?.map?.longitude && (
|
||||||
<ModalOpenLocation
|
<ModalOpenLocation
|
||||||
open={open}
|
open={open}
|
||||||
data={data}
|
data={data}
|
||||||
@@ -64,8 +65,10 @@ function Item({ data }) {
|
|||||||
مسیریابی
|
مسیریابی
|
||||||
</Button>
|
</Button>
|
||||||
</ModalOpenLocation>
|
</ModalOpenLocation>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{data?.map?.latitude && data?.map?.longitude && (
|
||||||
<div className="w-full relative h-[219px] sm:h-[302px] md:h-[385px] lg:h-[470px] mt-[24px]">
|
<div className="w-full relative h-[219px] sm:h-[302px] md:h-[385px] lg:h-[470px] mt-[24px]">
|
||||||
<iframe
|
<iframe
|
||||||
src={`https://maps.google.com/maps?q=${data.map.latitude},${data.map.longitude}&z=14&output=embed`}
|
src={`https://maps.google.com/maps?q=${data.map.latitude},${data.map.longitude}&z=14&output=embed`}
|
||||||
@@ -91,6 +94,7 @@ function Item({ data }) {
|
|||||||
</Button>
|
</Button>
|
||||||
</ModalOpenLocation>
|
</ModalOpenLocation>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user