diff --git a/fe-admin/src/pages/master/DepartmentsPage.tsx b/fe-admin/src/pages/master/DepartmentsPage.tsx index ffdf7ef..657525c 100644 --- a/fe-admin/src/pages/master/DepartmentsPage.tsx +++ b/fe-admin/src/pages/master/DepartmentsPage.tsx @@ -8,6 +8,7 @@ import { PermissionGuard } from '@/components/PermissionGuard' import { Button } from '@/components/ui/Button' import { Input } from '@/components/ui/Input' import { Label } from '@/components/ui/Label' +import { Select } from '@/components/ui/Select' import { Textarea } from '@/components/ui/Textarea' import { Dialog } from '@/components/ui/Dialog' import { api } from '@/lib/api' @@ -15,8 +16,8 @@ import { getErrorMessage } from '@/lib/apiError' import { MenuKeys } from '@/lib/menuKeys' import type { Department, Paged } from '@/types/master' -type FormState = { id?: string; code: string; name: string; note: string } -const emptyForm: FormState = { code: '', name: '', note: '' } +type FormState = { id?: string; code: string; name: string; parentId: string; note: string } +const emptyForm: FormState = { code: '', name: '', parentId: '', note: '' } export function DepartmentsPage() { const qc = useQueryClient() @@ -38,9 +39,24 @@ export function DepartmentsPage() { }, }) + // Toàn bộ phòng ban (không phân trang) để chọn "Phòng cha" + tra tên phòng cha cho cột bảng. + const allDepts = useQuery({ + queryKey: ['departments-all'], + queryFn: async () => + (await api.get>('/departments', { params: { page: 1, pageSize: 200 } })).data.items, + }) + const deptNameById = new Map((allDepts.data ?? []).map(d => [d.id, `${d.code} — ${d.name}`])) + const mutate = useMutation({ mutationFn: async (d: FormState) => { - const payload = { id: d.id, code: d.code, name: d.name, managerUserId: null, note: d.note || null } + const payload = { + id: d.id, + code: d.code, + name: d.name, + parentId: d.parentId || null, + managerUserId: null, + note: d.note || null, + } if (d.id) await api.put(`/departments/${d.id}`, payload) else await api.post('/departments', payload) }, @@ -65,6 +81,7 @@ export function DepartmentsPage() { const columns: Column[] = [ { key: 'code', header: 'Mã', sortable: true, render: d => {d.code}, width: 'w-32' }, { key: 'name', header: 'Tên phòng ban', sortable: true, render: d => d.name }, + { key: 'parentId', header: 'Thuộc', render: d => (d.parentId ? deptNameById.get(d.parentId) ?? '—' : '—') }, { key: 'note', header: 'Ghi chú', render: d => d.note ?? '—' }, { key: 'actions', @@ -75,7 +92,7 @@ export function DepartmentsPage() {
+
+ + +