Files
nobat724_front/components/doctor/detailDoctor/cards/locations/Item.js
T
hamedandClaude Opus 5 179a6d5163 feat(doctor): open the first location on load
Every address started collapsed, so a doctor with one office made the visitor
click before seeing where that office is — the thing they came to the section
for. The first entry now renders expanded; the rest stay closed so a long list
does not push the page down.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-18 16:38:12 +03:30

104 lines
3.8 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import { useState } from "react";
import dynamic from "next/dynamic";
import { Button } from "@mui/material";
import ArrowBottomGrayD from "@/components/icons/ArrowBottomGrayD";
import ModalOpenLocation from "@/app/component/openLocation";
import RoutingWhiteC from "@/components/icons/RoutingWhiteC";
import RoutingC from "@/components/icons/RoutingC";
// Leaflet به window نیاز دارد → فقط کلاینت
const MapView = dynamic(() => import("@/components/common/MapView"), { ssr: false });
function Item({ data, bookable = true, defaultOpen = false }) {
const [isOpen, setIsOpen] = useState(defaultOpen);
const [open, setOpen] = useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
return (
<>
<a
id="location"
className="absolute -translate-y-[148px] sm:-translate-y-[157px] md:-translate-y-[166px] lg:-translate-y-[176px]"
></a>
<Button
variant="texts"
onClick={() => setIsOpen(!isOpen)}
className="!px-[2px] !py-[4px] !flex !items-center !justify-between !w-full"
>
<p className="text-[#616161] text-[16px] font-medium">
{data.name}
{!bookable && (
<span className="mr-2 text-[11px] font-normal text-[#A1A1A1]">
(بدون نوبتدهی آنلاین)
</span>
)}
</p>
<div
className={` transition-all duration-500 ${isOpen ? "rotate-180" : "rotate-0"} `}
>
<ArrowBottomGrayD />
</div>
</Button>
<div
className={` overflow-hidden transition-all duration-500 ${isOpen ? "max-h-[800px] " : "max-h-0"} `}
>
<div className="gap-3 md:gap-4 flex flex-col items-start mt-[16px] sm:mt-[19px] md:mt-[22px] lg:mt-[24px]">
<p className="text-[#525252] text-[16px] font-normal">
آدرس: {data.address}
</p>
{/* شمارهٔ مطب اینجا نمی‌آید: دادهٔ عمومی نیست و API هم دیگر آن را برنمی‌گرداند.
بیمار شماره را در «جزئیات نوبت شما» — بعد از گرفتن نوبت — می‌بیند. */}
<div className="flex w-full items-center justify-end">
{data?.map?.latitude && data?.map?.longitude && (
<ModalOpenLocation
open={open}
data={data}
setOpen={setOpen}
handleClose={handleClose}
>
<Button
className="!hidden md:!flex !gap-[8px] !py-[8px] !px-[12px]"
onClick={handleOpen}
variant="outlined"
>
<RoutingC />
مسیریابی
</Button>
</ModalOpenLocation>
)}
</div>
</div>
{isOpen && data?.map?.latitude && data?.map?.longitude && (
<div className="w-full relative h-[219px] sm:h-[302px] md:h-[385px] lg:h-[470px] mt-[24px]">
<MapView
latitude={data.map.latitude}
longitude={data.map.longitude}
/>
<ModalOpenLocation
open={open}
data={data}
setOpen={setOpen}
handleClose={handleClose}
>
<Button
className="!flex md:!hidden !p-2 !absolute !left-3 !bottom-3 !rounded-[4px] !border !border-[#5559CE] !py-2 !px-3 !bg-[#5559CE] !shadow-[0px_1px_24.8px_0px_rgba(69,_69,_69,_0.54)] !gap-[8px] !text-[#FAFAFA] !text-[14px] !font-medium"
onClick={handleOpen}
>
<RoutingWhiteC />
مسیریابی
</Button>
</ModalOpenLocation>
</div>
)}
</div>
</>
);
}
export default Item;