Files
2026-07-08 16:15:37 +02:00

66 lines
3.2 KiB
TypeScript

import { Link, useLoaderData } from "react-router";
import { useTranslation } from "react-i18next";
import type { LoaderFunctionArgs } from "react-router";
import { loadAutomationListVM, type AutomationListVM } from "~/services/automation/automation.server";
import { appPath } from "~/utils/app/CanonicalUrlUtils";
export async function loader({ request, params }: LoaderFunctionArgs) {
return Response.json(await loadAutomationListVM({ request, params }));
}
export default function AutomationsIndexRoute() {
const data = useLoaderData() as AutomationListVM;
const { t } = useTranslation();
return (
<main className="mx-auto flex w-full max-w-6xl flex-col gap-6 p-6">
<header className="flex flex-col gap-2">
<h1 className="text-foreground text-2xl font-semibold">{t("automation.title")}</h1>
<p className="text-muted-foreground text-sm">{t("automation.subtitle")}</p>
<Link className="text-theme-600 text-sm font-medium" to={appPath({ tenantSlug: data.tenantSlug, path: "automations/templates", mode: "host-aware" })}>
{t("automation.templatesPage.title")}
</Link>
</header>
<section className="grid gap-3 md:grid-cols-3">
<MetricCard label={t("automation.metrics.triggers")} value={String(data.triggers.length)} />
<MetricCard label={t("automation.metrics.actions")} value={String(data.actions.length)} />
<MetricCard label={t("automation.metrics.templates")} value={String(data.templates.length)} />
</section>
<section className="overflow-hidden rounded-lg border">
<div className="border-b px-4 py-3">
<h2 className="text-foreground text-sm font-semibold">{t("automation.sections.rules")}</h2>
</div>
{data.rules.length === 0 ? (
<div className="text-muted-foreground px-4 py-8 text-sm">{t("automation.empty.rules")}</div>
) : (
<div className="divide-y">
{data.rules.map((rule) => (
<Link className="hover:bg-muted/40 grid gap-2 px-4 py-3 md:grid-cols-[1fr_160px_120px_140px_120px]" key={rule.id} to={rule.editUrl}>
<span>
<span className="text-foreground block text-sm font-medium">{rule.name}</span>
<span className="text-muted-foreground block text-xs">{rule.triggerKey ?? t("automation.values.noTrigger")}</span>
</span>
<span className="text-muted-foreground text-sm">{t(`automation.status.${rule.status}`, { defaultValue: rule.status })}</span>
<span className="text-muted-foreground text-sm">{rule.runs30d}</span>
<span className="text-muted-foreground text-sm">{rule.lastExecutionAt ?? t("automation.values.never")}</span>
<span className="text-theme-600 text-sm">{t("automation.editor.actions.openEditor")}</span>
</Link>
))}
</div>
)}
</section>
</main>
);
}
function MetricCard({ label, value }: { label: string; value: string }) {
return (
<div className="rounded-lg border px-4 py-3">
<div className="text-muted-foreground text-xs">{label}</div>
<div className="text-foreground mt-1 text-2xl font-semibold">{value}</div>
</div>
);
}