feat(resources): warn before switching a resource off, and pick dates in Jalali
The deactivation warning was blocked on task 07: there was no way to count "the
appointments on this resource" until occupancy rows linked the two. They do
now, so GET /resource/{uuid} returns upcoming_appointments. It stays off the
list endpoint, where it would be one count query per row.
It is a warning, not a block, and the wording says so: switching a resource off
does not cancel anything, it only removes the resource from future searches.
The panel shows it the moment the "active" box is unticked.
The calendar's exception range still used <input type="date">, which is
Gregorian. Operators say dates in Jalali, and the mental conversion is exactly
where an exception gets recorded a day off. PersianDateInput takes the same
YYYY-MM-DD string, so this is a drop-in swap.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,8 @@ import React, { useEffect, useState } from 'react';
|
||||
import Modal from '../ui/Modal';
|
||||
import SearchableSelect from '../ui/SearchableSelect';
|
||||
import type { Branch, ClinicResource, ResourcePayload, ResourceType } from '../../types';
|
||||
import { useResourceDetail } from '../../hooks/useResources';
|
||||
import { formatNumber } from '../../lib/utils';
|
||||
|
||||
/** کلیدهای شناختهشدهٔ ویژگی — قرارداد است نه اجبار؛ سرور هر کلید snake_case را میپذیرد. */
|
||||
const KNOWN_ATTRIBUTES = ['gender', 'device_model', 'floor', 'brand'];
|
||||
@@ -21,6 +23,8 @@ interface Props {
|
||||
export default function ResourceFormModal({
|
||||
open, resource, branches, types, saving, onClose, onSave,
|
||||
}: Props) {
|
||||
// شمار نوبتهای آینده فقط برای منبعِ موجود معنا دارد و فقط وقتی مودال باز است.
|
||||
const { upcomingAppointments: upcoming } = useResourceDetail(open ? resource?.uuid : undefined);
|
||||
const [name, setName] = useState('');
|
||||
const [addressUuid, setAddressUuid] = useState<string | null>(null);
|
||||
const [typeUuid, setTypeUuid] = useState<string | null>(null);
|
||||
@@ -184,6 +188,25 @@ export default function ResourceFormModal({
|
||||
منبع فعال است
|
||||
</label>
|
||||
|
||||
{/* غیرفعالکردن نوبتهای ثبتشده را لغو نمیکند؛ فقط از جستجوی وقتِ بعدی حذف
|
||||
میشود. پس این هشدار است نه مانع — ولی اپراتور باید بداند چند بیمار روی
|
||||
منبعی نوبت دارند که دارد خاموش میشود. */}
|
||||
{!active && upcoming > 0 && (
|
||||
<span
|
||||
style={{
|
||||
fontSize: 12,
|
||||
lineHeight: 1.8,
|
||||
color: 'var(--warning)',
|
||||
background: 'var(--warning-bg)',
|
||||
borderRadius: 'var(--r-sm)',
|
||||
padding: '8px 10px',
|
||||
}}
|
||||
>
|
||||
این منبع {formatNumber(upcoming)} نوبت آیندهٔ فعال دارد. غیرفعالکردن آنها را
|
||||
لغو نمیکند؛ فقط این منبع دیگر در جستجوی وقت نمیآید.
|
||||
</span>
|
||||
)}
|
||||
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 8, marginTop: 4 }}>
|
||||
<button type="button" className="btn secondary" onClick={onClose}>انصراف</button>
|
||||
<button type="button" className="btn primary" disabled={saving || invalid} onClick={submit}>
|
||||
|
||||
Reference in New Issue
Block a user