feat: close the last four domain events, and the panel paths they describe

Every one of the fourteen named events now has an emit point. The four that
were missing all sat on paths owned by earlier tasks:

- AppointmentCompleted fires from both status-change routes, after the row is
  saved. A rejected transition or a version conflict leaves no event; otherwise
  the completed count runs ahead of the appointments themselves.
- AppointmentRescheduled is a third event, not a replacement. A rebook is a
  confirm plus a cancel, and a consumer that only hears the cancel messages a
  patient who still has an appointment.
- ResourceBlocked / ResourceReleased are a pair. Capacity coming back has to be
  as audible as capacity going away, or the resource reads as permanently taken.

Publishing is now on the scheduler rather than an unregistered command: the
logic moved out of PublishDomainEventsCommand into OutboxPublisher so the
recurring message and the manual command share it, and the existing
worker-scheduler container consumes it. The scheduler message carries no data
on purpose — what to publish is read from the table, so an event recorded
between two ticks is not skipped. DomainEventMessage routes to async, since a
slow consumer was otherwise slowing the drain itself and its failure marked a
row failed that had in fact been delivered.

Panel work that these paths made reachable:

- Cancelling from the appointment page now goes through the policy-aware
  endpoint and shows the penalty preview before the confirm, so the operator
  does not discover the patient's penalty after the fact. The cancellation
  service writes the timeline entry itself and accepts a reason, which that
  path previously dropped on the floor.
- Rescheduling reuses the booking page under ?rebook=<uuid> — the search and
  hold steps are identical and only the final step differs. The doctor picker
  is hidden there: a reschedule is not an invitation to change doctors.
- A new GET /appointment/{uuid}/segments exposes the recorded plan. An empty
  list is not an error, it means the appointment is slot-based, and that is
  exactly what gates the resource-mode reschedule button.

AppointmentInvoiceCard no longer crashes the whole detail page when an older
invoice has no discount breakdown.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-07-31 21:27:55 +03:30
co-authored by Claude Opus 5
parent b55c33f686
commit 4049daf071
29 changed files with 977 additions and 118 deletions
+59 -25
View File
@@ -1,5 +1,5 @@
import React, { useCallback, useMemo, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useNavigate, useSearchParams } from 'react-router-dom';
import PageHeader from '../components/ui/PageHeader';
import SearchableSelect from '../components/ui/SearchableSelect';
import HoldCountdown from '../components/HoldCountdown';
@@ -31,9 +31,19 @@ function timeOf(ts: number): string {
*/
export default function ResourceBookingPage() {
const navigate = useNavigate();
const [params] = useSearchParams();
const { branches } = useBranches();
const { items: services } = useAllServiceItems();
const { create, release, confirm } = useHold();
const { create, release, confirm, rebook } = useHold();
/**
* حالت جابه‌جایی — همان سه مرحله، با یک تفاوت در گام آخر.
*
* صفحهٔ جدا نساختیم چون جستجو و رزرو موقت دقیقاً همان‌اند؛ چیزی که فرق می‌کند فقط
* این است که در پایان به‌جای «ثبت نوبت تازه»، نوبت موجود جابه‌جا می‌شود و زمان قدیم
* در همان درخواست آزاد می‌شود.
*/
const rebookUuid = params.get('rebook');
const [serviceUuid, setServiceUuid] = useState('');
const [branchUuid, setBranchUuid] = useState('');
@@ -121,9 +131,13 @@ export default function ResourceBookingPage() {
return (
<div className="fade-in">
<PageHeader
title="رزرو نوبت منبع‌محور"
description="وقت آزاد از تقاطع تقویم منابع می‌آید؛ هر وقت با منابع پیشنهادی خودش نمایش داده می‌شود."
backTo="/admin/appointments"
title={rebookUuid ? 'جابه‌جایی نوبت' : 'رزرو نوبت منبع‌محور'}
description={
rebookUuid
? 'زمان تازه را انتخاب و نگه دارید؛ زمان قبلی در همان لحظهٔ جابه‌جایی آزاد می‌شود.'
: 'وقت آزاد از تقاطع تقویم منابع می‌آید؛ هر وقت با منابع پیشنهادی خودش نمایش داده می‌شود.'
}
backTo={rebookUuid ? `/admin/appointments/${rebookUuid}` : '/admin/appointments'}
/>
<div className="card" style={{ marginBottom: 16, display: 'flex', gap: 12, flexWrap: 'wrap', alignItems: 'flex-end' }}>
@@ -285,15 +299,18 @@ export default function ResourceBookingPage() {
نمایش داده نمیشود.
</span>
<div className="field" style={{ maxWidth: 280, margin: 0 }}>
<label>پزشک نوبت</label>
<SearchableSelect
value={doctorUuid}
onChange={(v) => setDoctorUuid(String(v ?? ''))}
options={doctors.map((d) => ({ value: d.uuid, label: d.name }))}
placeholder="انتخاب پزشک"
/>
</div>
{/* در جابه‌جایی پزشک عوض نمی‌شود؛ پرسیدنش یعنی دعوت به تغییری که خواسته نشده. */}
{!rebookUuid && (
<div className="field" style={{ maxWidth: 280, margin: 0 }}>
<label>پزشک نوبت</label>
<SearchableSelect
value={doctorUuid}
onChange={(v) => setDoctorUuid(String(v ?? ''))}
options={doctors.map((d) => ({ value: d.uuid, label: d.name }))}
placeholder="انتخاب پزشک"
/>
</div>
)}
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
{hold === null ? (
@@ -307,17 +324,34 @@ export default function ResourceBookingPage() {
</button>
) : (
<>
<button
type="button"
className="btn primary"
disabled={expired || doctorUuid === '' || confirm.isPending}
onClick={async () => {
await confirm.mutateAsync({ hold_uuid: hold.hold_uuid, doctor_uuid: doctorUuid });
navigate('/admin/appointments');
}}
>
ثبت نهایی نوبت
</button>
{rebookUuid ? (
<button
type="button"
className="btn primary"
disabled={expired || rebook.isPending}
onClick={async () => {
await rebook.mutateAsync({
appointmentUuid: rebookUuid,
holdUuid: hold.hold_uuid,
});
navigate(`/admin/appointments/${rebookUuid}`);
}}
>
جابهجایی به این زمان
</button>
) : (
<button
type="button"
className="btn primary"
disabled={expired || doctorUuid === '' || confirm.isPending}
onClick={async () => {
await confirm.mutateAsync({ hold_uuid: hold.hold_uuid, doctor_uuid: doctorUuid });
navigate('/admin/appointments');
}}
>
ثبت نهایی نوبت
</button>
)}
<button
type="button"