import { Button } from "@repo/shadcn-ui/components/button"; import { EntityAction, EntityListHeader, EntityRowActions, EntityTable, } from "@repo/shadcn-ui/components/entity-list"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import type { CompanyDTO } from "../../common"; import { SiteEditorDialog } from "./site-editor-dialog"; 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)} open={createOpen} /> { if (!open) { setSelectedId(undefined); } }} onSaved={() => setSelectedId(undefined)} open={selected !== undefined} {...(selected ? { site: selected } : {})} />
); }