feat: enhance clinic contact information display with new helper functions for phone, city, and state
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import ContentDetail from "./ContentDetail";
|
||||
import { getClinicPhone, telHref, getClinicAddress } from "@/lib/clinicContact";
|
||||
|
||||
function Detail({ data }) {
|
||||
// API برای فیلدهای پرنشده null میفرستد؛ درج مستقیم در template رشتهٔ «null»
|
||||
@@ -6,8 +7,9 @@ function Detail({ data }) {
|
||||
const workingDays = data?.["24_7"]
|
||||
? "۲۴ ساعته، تمام روزهای هفته"
|
||||
: data?.field_working_days?.trim();
|
||||
const phone = (data?.phone_number || data?.phone || "").trim();
|
||||
const address = data?.location?.trim();
|
||||
const phone = getClinicPhone(data);
|
||||
const href = telHref(phone);
|
||||
const address = getClinicAddress(data);
|
||||
|
||||
if (!workingDays && !phone && !address) return null;
|
||||
|
||||
@@ -20,9 +22,13 @@ function Detail({ data }) {
|
||||
<ContentDetail
|
||||
head="تلفن: "
|
||||
detail={
|
||||
<a href={`tel:${phone}`} dir="ltr" className="hover:text-[#5559CE]">
|
||||
{phone}
|
||||
</a>
|
||||
href ? (
|
||||
<a href={href} dir="ltr" className="hover:text-[#5559CE]">
|
||||
{phone}
|
||||
</a>
|
||||
) : (
|
||||
<span dir="ltr">{phone}</span>
|
||||
)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
|
||||
import RoutingWhiteC from "@/components/icons/RoutingWhiteC";
|
||||
import { Button } from "@mui/material";
|
||||
@@ -6,20 +7,25 @@ import Detail from "./Detail";
|
||||
import RoutingC from "@/components/icons/RoutingC";
|
||||
import ModalOpenLocation from "@/app/component/openLocation";
|
||||
import CustomLoading from "@/app/component/loading/Custom";
|
||||
import { hasClinicContact } from "@/lib/clinicContact";
|
||||
|
||||
// همان نقشهٔ صفحهٔ پزشک: Leaflet روی تایلهای OpenStreetMap. embed گوگلمپ
|
||||
// در ایران بارگذاری نمیشد و کادر نقشه خالی میماند.
|
||||
const MapView = dynamic(() => import("@/components/common/MapView"), {
|
||||
ssr: false,
|
||||
});
|
||||
|
||||
function Contact({ data }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const handleOpen = () => setOpen(true);
|
||||
const handleClose = () => setOpen(false);
|
||||
|
||||
// بدون مختصات و بدون نشانی، کوئری نقشه خالی میماند و iframe نقطهٔ بیربط
|
||||
// نشان میدهد؛ در آن حالت نقشه و دکمهٔ مسیریابی اصلاً معنا ندارند.
|
||||
// نقشه و مسیریابی هر دو مختصات میخواهند — لینکهای مسیریابی (بلد/گوگل/ویز)
|
||||
// بدون lat/lng به `undefined,undefined` میرسند. با نشانیِ متنی تنها، هیچکدام
|
||||
// معنا ندارد و فقط ردیف آدرس نمایش داده میشود.
|
||||
const hasCoords = Boolean(data?.map?.latitude && data?.map?.longitude);
|
||||
const mapQuery = hasCoords
|
||||
? `${data.map.latitude},${data.map.longitude}`
|
||||
: data?.location?.trim()
|
||||
? encodeURIComponent(data.location.trim())
|
||||
: "";
|
||||
|
||||
if (!hasClinicContact(data)) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -27,7 +33,7 @@ function Contact({ data }) {
|
||||
>
|
||||
<div className="flex items-end justify-between">
|
||||
<Detail data={data} />
|
||||
{mapQuery && <ModalOpenLocation
|
||||
{hasCoords && <ModalOpenLocation
|
||||
data={data}
|
||||
open={open}
|
||||
setOpen={setOpen}
|
||||
@@ -43,14 +49,12 @@ function Contact({ data }) {
|
||||
</Button>
|
||||
</ModalOpenLocation>}
|
||||
</div>
|
||||
{mapQuery && <div className="w-full relative h-[460px] mt-[24px]">
|
||||
{hasCoords && <div className="w-full relative h-[460px] mt-[24px]">
|
||||
<CustomLoading width="full" height={400}>
|
||||
<iframe
|
||||
src={`https://maps.google.com/maps?q=${mapQuery}&z=14&output=embed`}
|
||||
title="موقعیت کلینیک روی نقشه"
|
||||
className="w-full h-full rounded-lg"
|
||||
loading="lazy"
|
||||
></iframe>
|
||||
<MapView
|
||||
latitude={data.map.latitude}
|
||||
longitude={data.map.longitude}
|
||||
/>
|
||||
<ModalOpenLocation
|
||||
data={data}
|
||||
open={open}
|
||||
@@ -58,7 +62,7 @@ function Contact({ data }) {
|
||||
handleClose={handleClose}
|
||||
>
|
||||
<Button
|
||||
className="!flex md:!hidden !text-[#FAFAFA] !gap-[8px] !p-2 !absolute !left-3 !bottom-3 !rounded-[4px] !border !border-[#5559CE] !bg-[#5559CE] !shadow-[0px_1px_24px_0px_rgba(69,_69,_69,_0.54)]"
|
||||
className="!flex md:!hidden !text-[#FAFAFA] !gap-[8px] !p-2 !absolute !left-3 !bottom-3 !z-[1000] !rounded-[4px] !border !border-[#5559CE] !bg-[#5559CE] !shadow-[0px_1px_24px_0px_rgba(69,_69,_69,_0.54)]"
|
||||
onClick={handleOpen}
|
||||
>
|
||||
<RoutingWhiteC />
|
||||
|
||||
@@ -9,7 +9,7 @@ import RoutingWhiteC from "@/components/icons/RoutingWhiteC";
|
||||
import RoutingC from "@/components/icons/RoutingC";
|
||||
|
||||
// Leaflet به window نیاز دارد → فقط کلاینت
|
||||
const MapView = dynamic(() => import("./MapView"), { ssr: false });
|
||||
const MapView = dynamic(() => import("@/components/common/MapView"), { ssr: false });
|
||||
|
||||
function Item({ data, bookable = true }) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
Reference in New Issue
Block a user