Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+183
@@ -0,0 +1,183 @@
|
||||
import { useLoaderData, type ActionFunctionArgs, type LoaderFunctionArgs } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
archivePipeline,
|
||||
createPipeline,
|
||||
duplicatePipeline,
|
||||
ensureDefaultSalesPipeline,
|
||||
listPipelines,
|
||||
updatePipeline,
|
||||
upsertPipelineAccess,
|
||||
upsertPipelineFieldConfig,
|
||||
upsertPipelineFieldVisibility,
|
||||
} from "~/utils/integrations/projects/projectService.server";
|
||||
import { upsertAuftragPipelineStageConfig } from "~/utils/integrations/projects/auftragService.server";
|
||||
import { loadProjectContext, projectActionErrorResponse, requireProjectPermission } from "~/utils/integrations/projects/projectAccess.server";
|
||||
import type { CreatePipelineStageInput, PipelinePrincipalType, PipelineRow, PipelineStageRow, PipelineTypHint } from "~/utils/integrations/projects/projectService.server";
|
||||
|
||||
type LoaderData = { pipelines: Array<PipelineRow & { stages: PipelineStageRow[] }> };
|
||||
|
||||
export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
const ctx = requireProjectPermission(await loadProjectContext({ request, params, requireModule: true }), "projects.admin");
|
||||
await ensureDefaultSalesPipeline({ tenantId: ctx.tenantId, userId: ctx.userId });
|
||||
const pipelines = await listPipelines({ tenantId: ctx.tenantId });
|
||||
return Response.json({ pipelines } satisfies LoaderData);
|
||||
}
|
||||
|
||||
function formString(formData: FormData, name: string): string | null {
|
||||
const value = formData.get(name);
|
||||
return typeof value === "string" ? value : null;
|
||||
}
|
||||
|
||||
function formBoolean(formData: FormData, name: string): boolean | undefined {
|
||||
const value = formString(formData, name);
|
||||
if (value === null) return undefined;
|
||||
return value === "true" || value === "1" || value === "on";
|
||||
}
|
||||
|
||||
function formNumber(formData: FormData, name: string): number | undefined {
|
||||
const value = formString(formData, name);
|
||||
if (!value) return undefined;
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : undefined;
|
||||
}
|
||||
|
||||
function formStages(formData: FormData): CreatePipelineStageInput[] {
|
||||
const raw = formString(formData, "stages");
|
||||
if (!raw) return [];
|
||||
const parsed = JSON.parse(raw) as unknown;
|
||||
if (!Array.isArray(parsed)) return [];
|
||||
return parsed.filter((stage): stage is CreatePipelineStageInput => typeof stage === "object" && stage !== null && "name" in stage && "stageKind" in stage);
|
||||
}
|
||||
|
||||
export async function action({ request, params }: ActionFunctionArgs) {
|
||||
const ctx = requireProjectPermission(await loadProjectContext({ request, params, requireModule: true }), "projects.admin");
|
||||
const formData = await request.formData();
|
||||
const intent = formString(formData, "_action");
|
||||
try {
|
||||
if (intent === "createPipeline") {
|
||||
const pipeline = await createPipeline({
|
||||
tenantId: ctx.tenantId,
|
||||
userId: ctx.userId,
|
||||
name: formString(formData, "name") ?? "",
|
||||
typHint: (formString(formData, "typHint") as PipelineTypHint | null) ?? "custom",
|
||||
position: formNumber(formData, "position"),
|
||||
stages: formStages(formData),
|
||||
});
|
||||
return Response.json({ ok: true, pipeline });
|
||||
}
|
||||
if (intent === "updatePipeline") {
|
||||
const pipeline = await updatePipeline({
|
||||
tenantId: ctx.tenantId,
|
||||
pipelineId: formString(formData, "pipelineId") ?? "",
|
||||
name: formString(formData, "name"),
|
||||
position: formNumber(formData, "position"),
|
||||
typHint: formString(formData, "typHint") as PipelineTypHint | null,
|
||||
});
|
||||
return Response.json({ ok: true, pipeline });
|
||||
}
|
||||
if (intent === "archivePipeline") {
|
||||
const pipeline = await archivePipeline({ tenantId: ctx.tenantId, pipelineId: formString(formData, "pipelineId") ?? "" });
|
||||
return Response.json({ ok: true, pipeline });
|
||||
}
|
||||
if (intent === "duplicatePipeline") {
|
||||
const pipeline = await duplicatePipeline({
|
||||
tenantId: ctx.tenantId,
|
||||
userId: ctx.userId,
|
||||
pipelineId: formString(formData, "pipelineId") ?? "",
|
||||
name: formString(formData, "name") ?? "",
|
||||
});
|
||||
return Response.json({ ok: true, pipeline });
|
||||
}
|
||||
if (intent === "upsertAccess") {
|
||||
await upsertPipelineAccess({
|
||||
tenantId: ctx.tenantId,
|
||||
pipelineId: formString(formData, "pipelineId") ?? "",
|
||||
principalType: formString(formData, "principalType") as PipelinePrincipalType,
|
||||
principalId: formString(formData, "principalId") ?? "",
|
||||
kannSehen: formBoolean(formData, "kannSehen"),
|
||||
kannBearbeiten: formBoolean(formData, "kannBearbeiten"),
|
||||
});
|
||||
return Response.json({ ok: true });
|
||||
}
|
||||
if (intent === "upsertFieldConfig") {
|
||||
await upsertPipelineFieldConfig({
|
||||
tenantId: ctx.tenantId,
|
||||
pipelineId: formString(formData, "pipelineId") ?? "",
|
||||
stageId: formString(formData, "stageId"),
|
||||
fieldKey: formString(formData, "fieldKey") ?? "",
|
||||
sichtbar: formBoolean(formData, "sichtbar"),
|
||||
pflicht: formBoolean(formData, "pflicht"),
|
||||
reihenfolge: formNumber(formData, "reihenfolge"),
|
||||
});
|
||||
return Response.json({ ok: true });
|
||||
}
|
||||
if (intent === "upsertFieldVisibility") {
|
||||
await upsertPipelineFieldVisibility({
|
||||
tenantId: ctx.tenantId,
|
||||
fieldConfigId: formString(formData, "fieldConfigId") ?? "",
|
||||
principalType: formString(formData, "principalType") as PipelinePrincipalType,
|
||||
principalId: formString(formData, "principalId") ?? "",
|
||||
kannSehen: formBoolean(formData, "kannSehen"),
|
||||
kannBearbeiten: formBoolean(formData, "kannBearbeiten"),
|
||||
});
|
||||
return Response.json({ ok: true });
|
||||
}
|
||||
if (intent === "upsertAuftragStageConfig") {
|
||||
await upsertAuftragPipelineStageConfig({
|
||||
tenantId: ctx.tenantId,
|
||||
pipelineId: formString(formData, "pipelineId") ?? "",
|
||||
stageId: formString(formData, "stageId") ?? "",
|
||||
requiresAcceptanceProtocol: formBoolean(formData, "requiresAcceptanceProtocol"),
|
||||
acceptanceFormTemplateId: formString(formData, "acceptanceFormTemplateId"),
|
||||
autoArchiveAfterDays: formNumber(formData, "autoArchiveAfterDays") ?? null,
|
||||
});
|
||||
return Response.json({ ok: true });
|
||||
}
|
||||
return Response.json({ error: "projects.error.unsupportedAction" }, { status: 400 });
|
||||
} catch (error) {
|
||||
return projectActionErrorResponse(error);
|
||||
}
|
||||
}
|
||||
|
||||
export default function PipelinesAdminRoute() {
|
||||
const { t } = useTranslation();
|
||||
const data = useLoaderData<LoaderData>();
|
||||
|
||||
return (
|
||||
<main className="mx-auto flex w-full max-w-5xl flex-col gap-6 p-6">
|
||||
<header>
|
||||
<h1 className="text-2xl font-semibold">{t("projects.pipelines.title")}</h1>
|
||||
</header>
|
||||
<section className="grid gap-4">
|
||||
{data.pipelines.map((pipeline) => (
|
||||
<article key={pipeline.id} className="rounded-md border bg-background p-4">
|
||||
<h2 className="font-semibold">{pipeline.name}</h2>
|
||||
<p className="text-sm text-muted-foreground">{pipeline.typHint}</p>
|
||||
<ol className="mt-3 flex flex-wrap gap-2">
|
||||
{pipeline.stages.map((stage) => (
|
||||
<li key={stage.id} className="rounded-md border px-3 py-1 text-sm">
|
||||
{stage.name} · {stage.stageKind}
|
||||
<form className="mt-2 grid gap-2" method="post">
|
||||
<input type="hidden" name="_action" value="upsertAuftragStageConfig" />
|
||||
<input type="hidden" name="pipelineId" value={pipeline.id} />
|
||||
<input type="hidden" name="stageId" value={stage.id} />
|
||||
<label className="flex items-center gap-2">
|
||||
<input name="requiresAcceptanceProtocol" type="checkbox" />
|
||||
{t("projects.fields.requiresAcceptanceProtocol")}
|
||||
</label>
|
||||
<input className="rounded-md border px-2 py-1" name="acceptanceFormTemplateId" placeholder={t("projects.fields.acceptanceFormTemplateId")} />
|
||||
<input className="rounded-md border px-2 py-1" name="autoArchiveAfterDays" placeholder={t("projects.fields.autoArchiveAfterDays")} type="number" />
|
||||
<button className="rounded-md border px-2 py-1" type="submit">
|
||||
{t("projects.actions.saveAuftragConfig")}
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</article>
|
||||
))}
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user