Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -1,17 +1,20 @@
import { type ActionFunctionArgs, type LoaderFunctionArgs, Form, redirect, useActionData } from "react-router";
import { useTranslation } from "react-i18next";
import { type ActionFunctionArgs, type LoaderFunctionArgs, redirect, useActionData, useNavigation, useParams, useSubmit } from "react-router";
import { badRequestResponse, leadActionErrorResponse, loadLeadContext, requireLeadPermission } from "~/utils/integrations/leads/leadAccess.server";
import { auditLeadEvent, logLeadActivity } from "~/utils/integrations/leads/leadAudit.server";
import { leadDetailPath, leadsPath, LEADS_MODULE_KEY } from "~/utils/integrations/leads/leadRoutePaths";
import { leadsPath, LEADS_MODULE_KEY } from "~/utils/integrations/leads/leadRoutePaths";
import { createLead, type LeadQuelle } from "~/utils/integrations/leads/leadService.server";
import { LeadNewPage, type LeadNewFields } from "~/components/screens/leads/LeadNewPage";
import ServerError from "~/components/ui/errors/ServerError";
import { getTranslations } from "~/locale/i18next.server";
const QUELLEN = new Set<LeadQuelle>(["form", "email", "aircall", "manual", "custom"]);
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
const ctx = await loadLeadContext({ request, params, requireModule: true });
requireLeadPermission(ctx, "leads.write");
return Response.json({});
const { t } = await getTranslations(request);
// Page title consumed by the shell breadcrumb (useTitleData).
return Response.json({ title: t("leads.new.title") });
};
export const action = async ({ request, params }: ActionFunctionArgs) => {
@@ -34,31 +37,33 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
zustaendigerUserId: form.get("zustaendigerUserId")?.toString() || ctx.userId,
});
await auditLeadEvent({ ctx, action: "lead.created", targetType: "lead", targetId: lead.id, metadata: { quelle } });
await logLeadActivity({ ctx, leadId: lead.id, activityType: "lead_created", summaryText: "lead.activity.created" });
return redirect(leadDetailPath(tenantSlug, lead.id));
await logLeadActivity({ ctx, leadId: lead.id, activityType: "lead_created", summaryText: "leads.activity.created" });
// Back to the inbox, not into the new lead: creating one is a triage step,
// and the list is where the next one gets handled.
return redirect(`${leadsPath(tenantSlug)}?toast=${encodeURIComponent("leads.toast.created")}`);
} catch (error) {
return leadActionErrorResponse(error);
}
};
export default function LeadNewRoute() {
const { t } = useTranslation();
const params = useParams();
const actionData = useActionData<{ error?: string }>();
const submit = useSubmit();
const navigation = useNavigation();
return (
<main className="mx-auto max-w-3xl px-4 py-10" data-ui-id="ui.leads.new">
<a href="../leads" className="text-theme-600 text-sm font-medium">{t("leads.actions.backToList")}</a>
<h1 className="text-foreground mt-4 text-xl font-semibold">{t("leads.new.title")}</h1>
{actionData?.error ? <p className="mt-4 text-sm text-red-600">{t(actionData.error)}</p> : null}
<Form method="post" className="mt-6 grid gap-4">
<label className="grid gap-1 text-sm">{t("leads.field.quelle")}<select name="quelle" className="rounded border px-3 py-2">{Array.from(QUELLEN).map((q) => <option key={q} value={q}>{t(`leads.quelle.${q}`)}</option>)}</select></label>
<label className="grid gap-1 text-sm">{t("leads.field.vorname")}<input name="vorname" className="rounded border px-3 py-2" /></label>
<label className="grid gap-1 text-sm">{t("leads.field.nachname")}<input name="nachname" className="rounded border px-3 py-2" /></label>
<label className="grid gap-1 text-sm">{t("leads.field.email")}<input name="email" type="email" className="rounded border px-3 py-2" /></label>
<label className="grid gap-1 text-sm">{t("leads.field.telefon")}<input name="telefon" className="rounded border px-3 py-2" /></label>
<label className="grid gap-1 text-sm">{t("leads.field.message")}<textarea name="message" className="min-h-32 rounded border px-3 py-2" /></label>
<button type="submit" className="bg-foreground text-background rounded px-4 py-2 text-sm font-medium">{t("leads.actions.create")}</button>
</Form>
</main>
<LeadNewPage
backHref={leadsPath(params.tenant ?? "")}
submitting={navigation.state !== "idle"}
errorKey={actionData?.error ?? null}
actions={{
onCreate: (fields: LeadNewFields) => {
const form = new FormData();
for (const [key, value] of Object.entries(fields)) form.set(key, value);
submit(form, { method: "post" });
},
}}
/>
);
}