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>
105 lines
4.2 KiB
TypeScript
105 lines
4.2 KiB
TypeScript
import React, { useEffect, useState } from 'react';
|
|
import Modal from '../ui/Modal';
|
|
import SearchableSelect from '../ui/SearchableSelect';
|
|
import type { ClinicResource, Skill } from '../../types';
|
|
|
|
type Line = { skill_uuid: string; level: number };
|
|
|
|
interface Props {
|
|
resource: ClinicResource | null;
|
|
skills: Skill[];
|
|
saving: boolean;
|
|
onClose: () => void;
|
|
onSave: (lines: Line[]) => void;
|
|
}
|
|
|
|
/**
|
|
* مهارتهای یک منبع. ذخیره یک PUT است و **جایگزینی کامل**: مهارتی که اینجا نباشد،
|
|
* از منبع برداشته میشود.
|
|
*/
|
|
export default function ResourceSkillsModal({ resource, skills, saving, onClose, onSave }: Props) {
|
|
const [lines, setLines] = useState<Line[]>([]);
|
|
|
|
useEffect(() => {
|
|
if (!resource) return;
|
|
setLines(resource.skills.map((s) => ({ skill_uuid: s.skill_uuid, level: s.level })));
|
|
}, [resource]);
|
|
|
|
const chosen = new Set(lines.map((l) => l.skill_uuid));
|
|
const available = skills.filter((s) => !chosen.has(s.uuid));
|
|
|
|
const nameOf = (uuid: string) => skills.find((s) => s.uuid === uuid)?.name ?? uuid;
|
|
|
|
return (
|
|
<Modal
|
|
open={resource !== null}
|
|
onClose={onClose}
|
|
title={`مهارتهای ${resource?.name ?? 'منبع'}`}
|
|
>
|
|
<div style={{ display: 'grid', gap: 14 }}>
|
|
{skills.length === 0 && (
|
|
<p style={{ fontSize: 13, color: 'var(--text-3)', margin: 0 }}>
|
|
هنوز هیچ مهارتی تعریف نشده است. اول از صفحهٔ «مهارتها» یکی بسازید.
|
|
</p>
|
|
)}
|
|
|
|
{lines.length === 0 ? (
|
|
<p style={{ fontSize: 13, color: 'var(--text-3)', margin: 0 }}>این منبع هیچ مهارتی ندارد.</p>
|
|
) : (
|
|
<div style={{ display: 'grid', gap: 8 }}>
|
|
{lines.map((line, index) => (
|
|
<div key={line.skill_uuid} style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
|
|
<span style={{ flex: 1, fontSize: 13, fontWeight: 600 }}>{nameOf(line.skill_uuid)}</span>
|
|
<label style={{ fontSize: 12, color: 'var(--text-3)' }}>سطح</label>
|
|
<div style={{ width: 92 }}>
|
|
<SearchableSelect
|
|
options={[1, 2, 3, 4, 5].map((lv) => ({ value: String(lv), label: String(lv) }))}
|
|
value={String(line.level)}
|
|
onChange={(v) =>
|
|
setLines((l) => l.map((x, i) => (i === index ? { ...x, level: Number(v) || 1 } : x)))
|
|
}
|
|
placeholder="سطح"
|
|
height={36}
|
|
/>
|
|
</div>
|
|
<button
|
|
type="button"
|
|
className="btn secondary sm"
|
|
onClick={() => setLines((l) => l.filter((_, i) => i !== index))}
|
|
aria-label={`حذف ${nameOf(line.skill_uuid)}`}
|
|
>
|
|
✕
|
|
</button>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
{available.length > 0 && (
|
|
<div style={{ display: 'grid', gap: 6 }}>
|
|
<label style={{ fontSize: 12, color: 'var(--text-2)' }}>افزودن مهارت</label>
|
|
<SearchableSelect
|
|
options={available.map((s) => ({ value: s.uuid, label: s.name }))}
|
|
value={null}
|
|
onChange={(v) => v && setLines((l) => [...l, { skill_uuid: String(v), level: 1 }])}
|
|
placeholder="یک مهارت انتخاب کنید"
|
|
height={38}
|
|
/>
|
|
</div>
|
|
)}
|
|
|
|
<p style={{ fontSize: 12, color: 'var(--text-3)', margin: 0 }}>
|
|
ذخیره کل فهرست را جایگزین میکند؛ مهارتی که اینجا نباشد از منبع برداشته میشود.
|
|
</p>
|
|
|
|
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 8 }}>
|
|
<button type="button" className="btn secondary" onClick={onClose}>انصراف</button>
|
|
<button type="button" className="btn primary" disabled={saving} onClick={() => onSave(lines)}>
|
|
{saving ? 'در حال ذخیره...' : 'ذخیره'}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</Modal>
|
|
);
|
|
}
|