feat(appointment): derive service section from service item when missing in appointment

This commit is contained in:
hamed
2026-08-08 07:14:40 +03:30
parent da07e3ad9c
commit b699476305
5 changed files with 144 additions and 22 deletions
@@ -50,6 +50,29 @@ describe('AppointmentEditPage (ویرایش نوبت)', () => {
expect(screen.getByDisplayValue('یادداشت')).toBeInTheDocument();
});
// بخش و سرویس هر دو باید برچسب واقعی نشان دهند، نه placeholder. فهرست سرویس‌ها
// از بخش می‌آید، پس بخشِ خالی یعنی سرویسِ ذخیره‌شده هم انتخاب‌نشده دیده می‌شود —
// همان باگی که در ۲۰۲۶-۰۸-۰۸ گزارش شد.
it('shows the stored section and service, not their placeholders', async () => {
renderEdit();
await screen.findByText('مشخصات سرویس:');
expect(await screen.findByText('زیبایی')).toBeInTheDocument();
expect(await screen.findByText('لیزر')).toBeInTheDocument();
expect(screen.queryByText('انتخاب بخش')).not.toBeInTheDocument();
expect(screen.queryByText('انتخاب سرویس')).not.toBeInTheDocument();
});
// بلوک بیعانه فعلاً از فرم برداشته شده، ولی مقدارش همچنان ذخیره می‌شود
// (اثباتش در تست بعدی: deposit_required در payload هست).
it('no longer renders the deposit block', async () => {
renderEdit();
await screen.findByText('مشخصات سرویس:');
expect(screen.queryByText('بیعانه:')).not.toBeInTheDocument();
expect(screen.queryByText('بیعانه مورد نیاز است.')).not.toBeInTheDocument();
});
it('patches the general update endpoint with the edited values', async () => {
renderEdit();
await screen.findByText('مشخصات سرویس:');
+6 -21
View File
@@ -6,9 +6,7 @@ import { toast } from 'sonner';
import { api } from '../lib/api';
import type { ApiResponse } from '../lib/api';
import PersianDateInput from '../components/ui/PersianDateInput';
import PriceInput from '../components/ui/PriceInput';
import SearchableSelect from '../components/ui/SearchableSelect';
import { WalletChargeLink } from '../components/AppointmentActions';
import { formatRial, rialToToman, tomanToRial } from '../lib/utils';
import { DEFAULT_SERVICE_CATEGORY } from '../lib/insuranceShares';
import BackButton from '../components/ui/BackButton';
@@ -16,7 +14,6 @@ import { useAppointmentInsurance } from '../hooks/useAppointmentInsurance';
import { useDoctorBookingServices } from '../hooks/useDoctorBookingServices';
import ServiceSlotPicker from '../components/appointments/ServiceSlotPicker';
import type { PickedService, ServicePick } from '../components/appointments/ServiceSlotPicker';
import Switch from '../components/ui/Switch';
interface Option { uuid: string; name?: string; full_name?: string }
@@ -357,24 +354,12 @@ export default function AppointmentEditPage() {
</div>
)}
<div style={{ fontSize: 14, fontWeight: 700, marginBottom: 12 }}>بیعانه:</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 16, flexWrap: 'wrap', marginBottom: 18 }}>
<Switch
inline
checked={depositRequired}
onChange={setDepositRequired}
label="بیعانه مورد نیاز است."
/>
{depositRequired && (
<>
<div style={{ minWidth: 220 }}>
<label style={label}>مبلغ بیعانه (تومان)</label>
<div style={{ marginTop: 6 }}><PriceInput value={depositToman} onChange={setDepositToman} /></div>
</div>
<WalletChargeLink mobile={a.patient_mobile || a.user?.mobile || ''} />
</>
)}
</div>
{/*
بخش «بیعانه» فعلاً از فرم برداشته شد (درخواست ۲۰۲۶-۰۸-۰۸).
state و ارسالش عمداً سر جایشان ماندند: مقدارِ فعلیِ نوبت هنگام هیدریت
خوانده و همان هنگام ذخیره پس فرستاده می‌شود، پس ویرایشِ بقیهٔ فیلدها
بیعانهٔ ثبت‌شده را پاک نمی‌کند. برگرداندنِ UI یعنی همین بلوک، نه بیشتر.
*/}
<div style={{ maxWidth: 320, marginBottom: 18 }}>
<label style={label}>انتخاب وضعیت</label>