import { Button } from "@repo/shadcn-ui/components/button"; import { Checkbox } from "@repo/shadcn-ui/components/checkbox"; import { FormDialog } from "@repo/shadcn-ui/components/form-dialog"; import { Input } from "@repo/shadcn-ui/components/input"; import { Label } from "@repo/shadcn-ui/components/label"; import { useQuery } from "@tanstack/react-query"; import { useId, useState } from "react"; import { useTranslation } from "react-i18next"; import { interventionTemplateApi, interventionTemplateKeys } from "./template-api"; import { TemplateHistory, TemplateSteps } from "./template-detail"; import { InterventionTemplateForm, copyTemplateValues } from "./template-form"; import { InterventionTemplateFeedback } from "./template-help"; export function InterventionTemplatesPage({ scope = "global", csrfToken, }: { scope?: string; csrfToken: string; }) { const { t } = useTranslation("companies"); const prefix = useId(); const query = useQuery({ queryKey: interventionTemplateKeys.list(scope), queryFn: () => interventionTemplateApi.list(scope), }); const [editor, setEditor] = useState<{ id?: string; copyId?: string }>(); const [search, setSearch] = useState(""); const [showInactive, setShowInactive] = useState(true); const templates = query.data?.templates ?? []; const selected = templates.find((item) => item.id === editor?.id); const copied = templates.find((item) => item.id === editor?.copyId); const visible = templates.filter( (item) => (showInactive || item.values.active) && item.values.name.toLocaleLowerCase().includes(search.trim().toLocaleLowerCase()) ); return (
{t( scope === "global" ? "interventionTemplates.scopeGlobal" : "interventionTemplates.scopeCompany" )}
{t("loading")}
}{t("interventionTemplates.empty")}
} {visible.map((template) => ({t( template.companyId ? "interventionTemplates.company" : "interventionTemplates.global" )}{" "} ยท {t(template.values.active ? "active" : "inactive")}