import { Button } from "@repo/shadcn-ui/components/button"; import { EntityAction, EntityListHeader, EntityRowActions, EntityTable, } from "@repo/shadcn-ui/components/entity-list"; import { FormDialog } from "@repo/shadcn-ui/components/form-dialog"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import type { CompanyDTO } from "../../common"; import { SiteForm } from "./site-form"; export function SiteSection({ company, csrfToken }: { company: CompanyDTO; csrfToken: string }) { const { t, i18n } = useTranslation("companies"); const [createOpen, setCreateOpen] = useState(false); const [selectedId, setSelectedId] = useState(); const selected = company.sites.find((site) => site.id === selectedId); return (
setCreateOpen(true)}>{t("newSite")}} locale={i18n.language} title={t("sites")} /> site.name, hideable: false, render: (site) => {site.name}, }, { id: "address", label: t("addressOptional"), value: (site) => site.address, render: (site) => ( {site.address ?? t("noAddress")} ), }, { id: "actions", label: t("actions"), hideable: false, render: (site) => ( setSelectedId(site.id)}>{t("edit")} ), }, ]} emptyMessage={t("noSites")} items={company.sites} locale={i18n.language} title={t("sites")} /> setCreateOpen(false)} showTitle={false} /> { if (!open) { setSelectedId(undefined); } }} open={selected !== undefined} title={t("editSite")} > {selected && ( setSelectedId(undefined)} showTitle={false} site={selected} /> )}
); }