import { Button } from "@repo/shadcn-ui/components/button"; import { EntityTable } from "@repo/shadcn-ui/components/entity-list"; import { FormDialog } from "@repo/shadcn-ui/components/form-dialog"; import { entityListLabels } from "@repo/shadcn-ui/lib/entity-list"; import { useTranslation } from "react-i18next"; import { CompanyIdentity } from "../../../companies/shared/ui/company-identity"; import { BlockState, DashboardNavigationButton, DashboardTable } from "../../shared"; import { entryDestination } from "../../shared/helpers"; import { useDashboardDetailsDialogController } from "../controllers"; import { detailsTitle } from "../helpers"; import type { DashboardDetailsDialogProps } from "../types"; export function DashboardDetailsDialog(props: DashboardDetailsDialogProps) { const { details, onClose, onNavigate } = props; const { page, setPage, query, companies, total } = useDashboardDetailsDialogController(props); const { t, i18n } = useTranslation("companies"); const title = t(detailsTitle(details)); const labels = entityListLabels(i18n.language); const range = labels.range( total ? (page - 1) * 10 + 1 : 0, Math.min(page * 10, total), total, t("dashboard.records") ); return ( { if (!open) { onClose(); } }} open title={title} wide > {details.companies ? ( item.name, render: (item) => ( onNavigate({ area: "company", id: item.id, section: "inventory" }) } > ), }, { id: "tickets", label: t("dashboard.openTickets"), value: (item) => item.tickets, render: (item) => item.tickets, }, { id: "interventions", label: t("dashboard.pendingInterventions"), value: (item) => item.interventions, render: (item) => item.interventions, }, { id: "assets", label: t("dashboard.registeredAssets"), value: (item) => item.assets, render: (item) => item.assets, }, { id: "people", label: t("people"), value: (item) => item.people, render: (item) => item.people, }, ]} entityLabel={t("title")} items={companies.data?.items ?? []} locale={i18n.language} title={title} /> ) : ( <>

{range}

{t("name")} {t("tickets.company")} {details.activity && {t("dashboard.recordedAt")}} {details.activity && {t("dashboard.recordedBy")}} {details.work && {t("tickets.state")}} {query.data?.items.map((item) => ( onNavigate(entryDestination(item))} > {item.reference ? `${item.reference} · ` : ""} {item.name} {details.activity && ( {item.recordedAt ? new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium", timeStyle: "short", }).format(new Date(item.recordedAt)) : "—"} )} {details.activity && {item.actorName ?? "—"}} {details.work && ( {t( (item.kind === "ticket" ? "tickets.states." : "interventions.states.") + item.state )} )} ))}
{!details.activity && query.isSuccess && ( )} )}
); }