feat: enhance SpecialtyPicker to support parent-child relationship for specialties
This commit is contained in:
@@ -457,9 +457,16 @@ function SpecialtiesTab() {
|
||||
queryFn: () => api.get<PaginatedResponse<SpecialtyFull>>(`/api/v1/admin/specialties?page=${page}&limit=20&search=${encodeURIComponent(search)}`),
|
||||
});
|
||||
|
||||
const { data: rootData } = useQuery({
|
||||
queryKey: ['admin-specialties-roots'],
|
||||
queryFn: () => api.get<PaginatedResponse<SpecialtyFull>>('/api/v1/admin/specialties?limit=100'),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
|
||||
const items = data?.data ?? [];
|
||||
const total = data?.meta?.totalRecords ?? 0;
|
||||
const parentMap = Object.fromEntries(items.map((s) => [s.id, s.name]));
|
||||
const rootItems = (rootData?.data ?? []).filter((s) => s.parent_id === null);
|
||||
const parentMap = Object.fromEntries((rootData?.data ?? []).map((s) => [s.id, s.name]));
|
||||
|
||||
const { register, handleSubmit, reset, control, formState: { errors } } = useForm<SpecialtyForm>({
|
||||
resolver: zodResolver(specialtySchema),
|
||||
@@ -491,7 +498,7 @@ function SpecialtiesTab() {
|
||||
reset({ name: s.name, weight: String(s.weight), status: String(s.status), parent_id: s.parent_id ?? null });
|
||||
};
|
||||
|
||||
const parentOptions = items.filter((s) => s.parent_id === null).map((s) => ({ value: s.id, label: s.name }));
|
||||
const parentOptions = rootItems.map((s) => ({ value: s.id, label: s.name }));
|
||||
|
||||
const columns: Column<SpecialtyFull>[] = [
|
||||
{ key: 'id', header: 'شناسه', render: (s) => <span className="muted" style={{ fontFamily: 'monospace', fontSize: 12 }}>{s.id}</span> },
|
||||
|
||||
Reference in New Issue
Block a user