Files
nobat724_front/components/dashboard/userAccount/sidebars/turns/isTurnsDetails/ButtonData.js
T
hamedandClaude Opus 5 4c912dc6c1 feat(panel): let a patient actually cancel or move their own appointment
The site's own copy has been promising cancellation for a while —
lib/specialtyContent.js and components/appointment/information/Detail.js both
tell users they can cancel from "نوبت‌های من" and get a refund up to five hours
before the visit. The UI never could. The cancel modal existed, but its confirm
button called handleClose: it closed the dialog and sent nothing. And the whole
button row it lived in (ButtonData.js) had been commented out since the PDF
download commit, so it was not even reachable.

Cancelling now goes through POST /appointment/{uuid}/cancel and shows the
penalty from /cancellation-preview before the confirm — the same calculation
the cancel itself runs, so the number the patient sees is the number they are
charged. If the preview fails, the dialog says so rather than blocking; the
cancellation is still allowed.

Rescheduling is new and service-aware. It asks for slots with
exclude_appointment_uuid, so the patient's own hour counts as free rather than
showing as taken, and it sends only the start time — the server computes the
duration. Sending a client-side duration would mean two parallel calculations,
and the day a service's minutes change the appointment would move with a stale
one. The services on the appointment are carried over unchanged.

Both actions only appear for an appointment that is still in the future and not
already cancelled, and both refresh the list afterwards so a just-cancelled
appointment stops showing as confirmed.

The day strip in the reschedule modal is its own small component rather than
the booking flow's DatePicker: that one reads the doctor uuid from route params
and would be undefined inside the dashboard.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-01 14:32:10 +03:30

42 lines
1.4 KiB
JavaScript

import { Button } from "@mui/material";
import ModalDeleteComment from "./modal";
import RescheduleModal from "./modal/RescheduleModal";
import DownloadD from "@/components/icons/DownloadD";
/** نوبتی که گذشته یا از قبل لغو شده، نه لغو می‌شود نه جابه‌جا. */
function isOpen(appointment) {
if (!appointment?.uuid) return false;
if (String(appointment.status ?? "").startsWith("cancelled")) return false;
return (appointment.slot_start ?? 0) > Math.floor(Date.now() / 1000);
}
function ButtonData({ loading, onDownload, appointment, onChanged }) {
const actionable = isOpen(appointment);
return (
<div className="flex mt-[48px] md:mt-0 items-center justify-center md:justify-end gap-[16px] sm:gap-[16px] md:gap-[20px] lg:gap-[24px]">
{onDownload && (
<Button
className="!rounded-[4px] !border !border-solid !border-[#D7D7D7] !shadow-none !gap-[4px] !py-[6px] md:!py-[7px] lg:!py-[8px] !px-[12px]"
disabled={loading}
variant="outlined"
onClick={onDownload}
>
<DownloadD />
دانلود اطلاعات نوبت
</Button>
)}
{actionable && (
<>
<ModalDeleteComment loading={loading} appointment={appointment} onDone={onChanged} />
<RescheduleModal loading={loading} appointment={appointment} onDone={onChanged} />
</>
)}
</div>
);
}
export default ButtonData;