import { Form, Link, redirect, useLoaderData } from "react-router"; import { useTranslation } from "react-i18next"; import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router"; import { createAutomationRuleFromTemplateForRoute, loadAutomationTemplateCatalogVM, type AutomationTemplateCatalogVM } from "~/services/automation/automation.server"; import { appPath } from "~/utils/app/CanonicalUrlUtils"; export async function loader({ request, params }: LoaderFunctionArgs) { return Response.json(await loadAutomationTemplateCatalogVM({ request, params })); } export async function action({ request, params }: ActionFunctionArgs) { const formData = await request.formData(); const intent = String(formData.get("intent") ?? ""); if (intent === "use-template") { const result = await createAutomationRuleFromTemplateForRoute({ request, params, templateId: String(formData.get("templateId") ?? ""), name: String(formData.get("ruleName") ?? "").trim() || undefined, }); return redirect(result.editUrl); } return redirect(appPath({ tenantSlug: params.tenant ?? "", path: "automations/templates", mode: "host-aware" })); } export default function AutomationTemplatesRoute() { const data = useLoaderData() as AutomationTemplateCatalogVM; const { t } = useTranslation(); return (
{t("automation.templatesPage.back")}

{t("automation.templatesPage.title")}

{t("automation.templatesPage.subtitle")}

{data.templates.map((template) => (

{t(template.name, { defaultValue: template.name })}

{template.description ? t(template.description, { defaultValue: template.description }) : t("automation.templatesPage.noDescription")}

{template.isTenantTemplate ? t("automation.templatesPage.tenantTemplate") : t("automation.templatesPage.platformTemplate")}
{t("automation.templatesPage.category")}
{template.category}
{t("automation.templatesPage.useCount")}
{template.useCount}
))}
); }