Four pages on the existing design system: a resources list whose branch/type/skill/
status filters live in the URL and go straight to the server, and three supporting
pages for types, skills and pools. Filtering client-side over a list the server had
already filtered would have been a second source of truth, so the page does neither.
The pool members dialog only offers resources from the pool's own branch and type —
the same rule the server enforces with 422, applied early so the user never reaches
the error. Skill assignment and pool membership are both full replacements, and both
say so in the dialog, because a partial-looking save that silently drops rows is
worse than an explicit one.
Wiring that was missing: deactivating a staff member through
PATCH /api/v1/staff/{uuid}/toggle now closes their resource too. Without it an
inactive operator would still have shown up in availability search. It is an explicit
call rather than a Doctrine lifecycle callback, since callbacks do not fire for
getArrayResult() — which is how every admin list is built — and that asymmetry is
its own bug. The reverse does not hold: closing a resource does not deactivate the
person, who may be purely administrative.
docs/api/resource.md documents all sixteen endpoints with responses captured from
real curl runs against ddev, including the 422 bodies for person-capacity and
non-scalar attributes. staff.md gains a "relationship to resources" section stating
that job_title is not a skill. tenancy.md contrasts these aggregate children —
whose roots do carry a tenant pair — with the branch_working_hours case from task 01,
where the root was global and the classification was wrong.
Also fixed a pre-existing flaky test: NumericFieldNormalizerTest guarded its random
mobile against collision on the never-reset db_test but not its random national code,
so a full-suite run could fail with 422 and close the EntityManager, taking an
unrelated test down with it. Both are now guarded, and the assertion prints the
server's response instead of a bare "422 is not 201".
Verified: phpunit 1119 tests / 3113 assertions green; slot-mode frozen contract green;
phpstan 14 errors before and after, none in touched files; tsc clean; vitest 88 files
/ 617 tests green.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
231 lines
9.0 KiB
TypeScript
231 lines
9.0 KiB
TypeScript
import React, { useMemo, useState } from 'react';
|
|
import { PlusIcon } from '@heroicons/react/24/outline';
|
|
import PageHeader from '../components/ui/PageHeader';
|
|
import DataTable, { type Column } from '../components/ui/DataTable';
|
|
import ConfirmDialog from '../components/ui/ConfirmDialog';
|
|
import SearchableSelect from '../components/ui/SearchableSelect';
|
|
import { ActiveBadge } from '../components/ui/StatusBadge';
|
|
import { useUrlState } from '../hooks/useUrlState';
|
|
import { usePermissions } from '../hooks/usePermissions';
|
|
import { useBranches } from '../hooks/useBranches';
|
|
import { useResources, useResourceTypes, useSkills } from '../hooks/useResources';
|
|
import ResourceFormModal from '../components/resources/ResourceFormModal';
|
|
import ResourceSkillsModal from '../components/resources/ResourceSkillsModal';
|
|
import type { ClinicResource } from '../types';
|
|
|
|
/** برچسب فارسی پلِ هر منبع؛ `null` یعنی تجهیزاتی که پشتش موجودیت دیگری نیست. */
|
|
const SUBJECT_LABEL: Record<string, string> = {
|
|
doctor: 'پزشک',
|
|
staff: 'پرسنل',
|
|
room: 'اتاق',
|
|
};
|
|
|
|
/**
|
|
* منابع — هر چیزی که ممکن است اشغال باشد.
|
|
*
|
|
* فیلترها (شعبه/نوع/مهارت/وضعیت) در URL مینشینند تا «بازگشت» و رفرش همان نما را
|
|
* بدهند، و همانها مستقیم به سرور میروند: فیلتر کردن سمت کلاینت با فهرستی که خودش
|
|
* فیلترشده آمده، دوبارهکاری و منبع اختلاف است.
|
|
*/
|
|
export default function ResourcesPage() {
|
|
const [urlState, setUrlState] = useUrlState({
|
|
search: '', address: '', type: '', skill: '', status: '',
|
|
});
|
|
|
|
const { branches } = useBranches();
|
|
const { types } = useResourceTypes();
|
|
const { skills } = useSkills();
|
|
const { can } = usePermissions();
|
|
const canUpdate = can('appointment_settings', 'update');
|
|
|
|
const { resources, loading, create, update, remove, setSkills } = useResources({
|
|
address_uuid: urlState.address || undefined,
|
|
type_uuid: urlState.type || undefined,
|
|
skill_uuid: urlState.skill || undefined,
|
|
active: urlState.status || undefined,
|
|
});
|
|
|
|
const [editing, setEditing] = useState<{ open: boolean; resource: ClinicResource | null }>({ open: false, resource: null });
|
|
const [skillsFor, setSkillsFor] = useState<ClinicResource | null>(null);
|
|
const [toDelete, setToDelete] = useState<ClinicResource | null>(null);
|
|
|
|
const rows = useMemo(() => {
|
|
const q = urlState.search.trim();
|
|
return q === '' ? resources : resources.filter((r) => `${r.name} ${r.type_name}`.includes(q));
|
|
}, [resources, urlState.search]);
|
|
|
|
const columns: Column<ClinicResource>[] = [
|
|
{
|
|
key: 'name',
|
|
header: 'منبع',
|
|
render: (r) => (
|
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
|
<span style={{ fontWeight: 600 }}>{r.name}</span>
|
|
<span style={{ fontSize: 12, color: 'var(--text-3)' }}>
|
|
{r.type_name}
|
|
{r.subject_kind ? ` · ${SUBJECT_LABEL[r.subject_kind]}` : ' · تجهیزات'}
|
|
</span>
|
|
</div>
|
|
),
|
|
},
|
|
{ key: 'address_name', header: 'شعبه', render: (r) => <span style={{ fontSize: 13 }}>{r.address_name || '—'}</span> },
|
|
{
|
|
key: 'capacity',
|
|
header: 'ظرفیت همزمان',
|
|
render: (r) => <span style={{ fontSize: 13 }}>{r.capacity} نفر</span>,
|
|
},
|
|
{
|
|
key: 'buffers',
|
|
header: 'آمادهسازی / تمیزکاری',
|
|
render: (r) => (
|
|
<span style={{ fontSize: 13, color: 'var(--text-2)' }}>
|
|
{r.setup_minutes} / {r.cleanup_minutes} دقیقه
|
|
</span>
|
|
),
|
|
},
|
|
{
|
|
key: 'skills',
|
|
header: 'مهارتها',
|
|
render: (r) =>
|
|
r.skills.length === 0 ? (
|
|
<span style={{ fontSize: 12, color: 'var(--text-3)' }}>—</span>
|
|
) : (
|
|
<div style={{ display: 'flex', gap: 4, flexWrap: 'wrap' }}>
|
|
{r.skills.map((s) => (
|
|
<span key={s.skill_uuid} className="badge blue" style={{ fontSize: 11 }}>
|
|
{s.skill_name} · {s.level}
|
|
</span>
|
|
))}
|
|
</div>
|
|
),
|
|
},
|
|
{ key: 'active', header: 'وضعیت', render: (r) => <ActiveBadge active={r.active} /> },
|
|
];
|
|
|
|
return (
|
|
<div className="fade-in">
|
|
<PageHeader
|
|
title="منابع"
|
|
description="هر چیزی که ممکن است اشغال باشد: پزشک، اپراتور، اتاق، دستگاه. ظرفیت یعنی تعداد بیمار همزمان."
|
|
backTo="/admin/settings-menu"
|
|
action={
|
|
canUpdate ? (
|
|
<button type="button" className="btn primary" onClick={() => setEditing({ open: true, resource: null })}>
|
|
<PlusIcon style={{ width: 16 }} /> افزودن منبع
|
|
</button>
|
|
) : undefined
|
|
}
|
|
/>
|
|
|
|
<DataTable
|
|
columns={columns}
|
|
data={rows}
|
|
loading={loading}
|
|
searchValue={urlState.search}
|
|
onSearchChange={(v) => setUrlState({ search: v })}
|
|
searchPlaceholder="جستجو در منابع..."
|
|
emptyMessage="هیچ منبعی با این فیلترها یافت نشد"
|
|
headerExtra={
|
|
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', marginRight: 'auto' }}>
|
|
<div style={{ minWidth: 180 }}>
|
|
<SearchableSelect
|
|
options={branches.map((b) => ({ value: b.uuid, label: b.name || 'بدون نام' }))}
|
|
value={urlState.address || null}
|
|
onChange={(v) => setUrlState({ address: v ? String(v) : '' })}
|
|
placeholder="همهٔ شعبهها"
|
|
isClearable
|
|
height={36}
|
|
/>
|
|
</div>
|
|
<div style={{ minWidth: 170 }}>
|
|
<SearchableSelect
|
|
options={types.map((t) => ({ value: t.uuid, label: t.name }))}
|
|
value={urlState.type || null}
|
|
onChange={(v) => setUrlState({ type: v ? String(v) : '' })}
|
|
placeholder="همهٔ نوعها"
|
|
isClearable
|
|
height={36}
|
|
/>
|
|
</div>
|
|
<div style={{ minWidth: 170 }}>
|
|
<SearchableSelect
|
|
options={skills.map((s) => ({ value: s.uuid, label: s.name }))}
|
|
value={urlState.skill || null}
|
|
onChange={(v) => setUrlState({ skill: v ? String(v) : '' })}
|
|
placeholder="همهٔ مهارتها"
|
|
isClearable
|
|
height={36}
|
|
/>
|
|
</div>
|
|
<div style={{ minWidth: 140 }}>
|
|
<SearchableSelect
|
|
options={[
|
|
{ value: '1', label: 'فعال' },
|
|
{ value: '0', label: 'غیرفعال' },
|
|
]}
|
|
value={urlState.status || null}
|
|
onChange={(v) => setUrlState({ status: v ? String(v) : '' })}
|
|
placeholder="همهٔ وضعیتها"
|
|
isClearable
|
|
height={36}
|
|
/>
|
|
</div>
|
|
</div>
|
|
}
|
|
actions={
|
|
canUpdate
|
|
? (r) => (
|
|
<div style={{ display: 'flex', gap: 6 }}>
|
|
<button type="button" className="btn secondary sm" onClick={() => setEditing({ open: true, resource: r })}>
|
|
ویرایش
|
|
</button>
|
|
<button type="button" className="btn secondary sm" onClick={() => setSkillsFor(r)}>
|
|
مهارتها
|
|
</button>
|
|
<button type="button" className="btn secondary sm" onClick={() => setToDelete(r)}>
|
|
حذف
|
|
</button>
|
|
</div>
|
|
)
|
|
: undefined
|
|
}
|
|
/>
|
|
|
|
<ResourceFormModal
|
|
open={editing.open}
|
|
resource={editing.resource}
|
|
branches={branches}
|
|
types={types}
|
|
saving={create.isPending || update.isPending}
|
|
onClose={() => setEditing({ open: false, resource: null })}
|
|
onSave={(payload) => {
|
|
const opts = { onSuccess: () => setEditing({ open: false, resource: null }) };
|
|
if (editing.resource) update.mutate({ uuid: editing.resource.uuid, d: payload }, opts);
|
|
else create.mutate(payload, opts);
|
|
}}
|
|
/>
|
|
|
|
<ResourceSkillsModal
|
|
resource={skillsFor}
|
|
skills={skills}
|
|
saving={setSkills.isPending}
|
|
onClose={() => setSkillsFor(null)}
|
|
onSave={(lines) =>
|
|
skillsFor &&
|
|
setSkills.mutate({ uuid: skillsFor.uuid, skills: lines }, { onSuccess: () => setSkillsFor(null) })
|
|
}
|
|
/>
|
|
|
|
<ConfirmDialog
|
|
open={!!toDelete}
|
|
title="حذف منبع"
|
|
message={`آیا از حذف «${toDelete?.name}» مطمئن هستید؟`}
|
|
confirmLabel="حذف"
|
|
loading={remove.isPending}
|
|
onConfirm={() => toDelete && remove.mutate(toDelete.uuid, { onSuccess: () => setToDelete(null) })}
|
|
onCancel={() => setToDelete(null)}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|