"use client"; import { useEffect, useState } from "react"; import { Box, Button, Modal } from "@mui/material"; import { styleDefault } from "@/mui"; import CloseModalD from "@/components/icons/CloseModalD"; import { request } from "@/services/response"; import { numberToArStyle } from "@/helper"; /** * لغو نوبت با نمایش پیامد مالی **پیش از** تأیید. * * پیشنمایش از همان محاسبهای میآید که خودِ لغو انجام میدهد، پس عددی که بیمار میبیند * همان است که کسر میشود. تا پیش از این، این مودال هیچ درخواستی نمیفرستاد و دکمهٔ * «لغو نوبت» فقط پنجره را میبست — یعنی متن تبلیغاتی سایت وعدهای میداد که UI نداشت. */ function ModalDeleteComment({ loading, appointment, onDone }) { const [open, setOpen] = useState(false); const [preview, setPreview] = useState(null); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const handleOpen = () => setOpen(true); const handleClose = () => { setOpen(false); setPreview(null); setError(null); }; useEffect(() => { if (!open || !appointment?.uuid) return; let cancelled = false; request .getCancellationPreview(appointment.uuid) .then((res) => { if (!cancelled) setPreview(res?.data ?? res ?? null); }) // نبودِ پیشنمایش نباید لغو را قفل کند؛ فقط باید صریح گفته شود. .catch(() => { if (!cancelled) setPreview(null); }); return () => { cancelled = true; }; }, [open, appointment?.uuid]); const submit = async () => { setBusy(true); setError(null); try { await request.cancelAppointment(appointment.uuid, { by: "user" }); handleClose(); onDone?.(); } catch (e) { setError(e?.message || "لغو نوبت ناموفق بود"); } finally { setBusy(false); } }; return (
لغو نوبت
آیا از لغو کردن نوبت مطمئن هستید؟
{error}
}