import { Button } from "@repo/shadcn-ui/components/button"; import { EntityAction, EntityListHeader, EntityRowActions, EntityStatus, EntityTable, } from "@repo/shadcn-ui/components/entity-list"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import type { CompanyDTO } from "../../common"; import { DepartmentEditorDialog } from "./department-editor-dialog"; export function DepartmentSection({ company, csrfToken, }: { company: CompanyDTO; csrfToken: string; }) { const { t, i18n } = useTranslation("companies"); const [editor, setEditor] = useState(); const selected = company.departments.find((item) => item.id === editor); return (
setEditor("new")}>{t("newDepartment")}} locale={i18n.language} title={t("departments")} /> item.name, hideable: false, render: (item) => <>{item.name}, }, { id: "state", label: t("status"), value: (item) => t(item.active ? "active" : "inactive"), render: (item) => ( {t(item.active ? "active" : "inactive")} ), }, { id: "people", label: t("people"), value: (item) => company.assignments.filter( (entry) => entry.departmentId === item.id && entry.endDate === null ).length, render: (item) => ( <> { company.assignments.filter( (entry) => entry.departmentId === item.id && entry.endDate === null ).length } ), }, { id: "actions", label: t("actions"), hideable: false, render: (item) => ( setEditor(item.id)}>{t("edit")} ), }, ]} emptyMessage={t("noDepartments")} items={company.departments} locale={i18n.language} title={t("departments")} /> { if (!open) { setEditor(undefined); } }} onSaved={() => setEditor(undefined)} open={editor !== undefined} />
); }