"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 (
{/* Button Modal */} {/* Content Modal */}

لغو نوبت

آیا از لغو کردن نوبت مطمئن هستید؟

{preview === null ? ( پیامد مالی لغو در دسترس نیست؛ لغو انجام می‌شود ولی مبلغ را از پشتیبانی بپرسید. ) : ( <>
جریمهٔ لغو 0 ? "text-[#D64545]" : "text-[#2E9E63]"}> {preview.penalty_rials > 0 ? `${numberToArStyle(Math.round(preview.penalty_rials / 10))} تومان` : "بدون جریمه"}
{preview.within_free_window && (
این لغو در بازهٔ رایگان است.
)} {(preview.notes ?? []).map((note, i) => (
{note}
))} )}
{error &&

{error}

}
); } export default ModalDeleteComment;