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
+434
@@ -0,0 +1,434 @@
|
||||
import { Form, Link, useLoaderData, type ActionFunctionArgs, type LoaderFunctionArgs } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
addProjectMember,
|
||||
createProjectAppointment,
|
||||
createProjectChecklist,
|
||||
createProjectInvoice,
|
||||
loadProjectSubAreas,
|
||||
updateProjectInvoiceStatus,
|
||||
upsertProjectChecklistItem,
|
||||
type ProjectSubAreasVM,
|
||||
type ProjektChecklistTyp,
|
||||
type ProjektMitgliedRolle,
|
||||
type RechnungStatus,
|
||||
} from "~/utils/integrations/projects/auftragService.server";
|
||||
import { loadProjectContext, projectActionErrorResponse, requireAnyProjectPermission, requireProjectPermission } from "~/utils/integrations/projects/projectAccess.server";
|
||||
import { projectAcceptancePath, projectsPath } from "~/utils/integrations/projects/projectRoutePaths";
|
||||
import type { ProjektRow } from "~/utils/integrations/projects/projectService.server";
|
||||
import {
|
||||
createSignatureDraft,
|
||||
loadProjectSignaturePanel,
|
||||
parseSignatureSigners,
|
||||
remindSignatureSigner,
|
||||
revokeSignatureDocument,
|
||||
sendSignatureDocument,
|
||||
SignatureServiceError,
|
||||
} from "~/modules/signature/services/signatureService.server";
|
||||
import type { ProjectSignaturePanelVM } from "@hivegrid/view-models";
|
||||
|
||||
type LoaderData = { tenantSlug: string; project: ProjektRow; subAreas: ProjectSubAreasVM; signature: ProjectSignaturePanelVM };
|
||||
|
||||
export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
const ctx = requireAnyProjectPermission(await loadProjectContext({ request, params, requireModule: true }), [
|
||||
"projects.read_all",
|
||||
"projects.read_own_pl",
|
||||
"projects.read_own",
|
||||
"projects.read_own_member",
|
||||
]);
|
||||
const subAreas = await loadProjectSubAreas({ tenantId: ctx.tenantId, projectId: params.id!, ctx });
|
||||
const signature = await loadProjectSignaturePanel({ tenantId: ctx.tenantId, projectId: params.id!, tenantSlug: params.tenant!, ctx });
|
||||
return Response.json({ tenantSlug: params.tenant!, project: subAreas.project, subAreas, signature } satisfies LoaderData);
|
||||
}
|
||||
|
||||
function formString(formData: FormData, name: string): string | null {
|
||||
const value = formData.get(name);
|
||||
return typeof value === "string" ? value : null;
|
||||
}
|
||||
|
||||
function formRole(formData: FormData): ProjektMitgliedRolle {
|
||||
const value = formString(formData, "rolle");
|
||||
if (value === "projektleiter" || value === "zustaendig" || value === "beobachter") return value;
|
||||
return "monteur";
|
||||
}
|
||||
|
||||
function formChecklistType(formData: FormData): ProjektChecklistTyp {
|
||||
const value = formString(formData, "typ");
|
||||
if (value === "maengel" || value === "abnahme_doku") return value;
|
||||
return "generisch";
|
||||
}
|
||||
|
||||
function formInvoiceStatus(formData: FormData): RechnungStatus {
|
||||
const value = formString(formData, "status");
|
||||
if (value === "gestellt" || value === "bezahlt" || value === "storniert") return value;
|
||||
return "entwurf";
|
||||
}
|
||||
|
||||
function formPosition(formData: FormData): number | undefined {
|
||||
const value = formString(formData, "position");
|
||||
if (!value) return undefined;
|
||||
const parsed = Number(value);
|
||||
return Number.isInteger(parsed) ? parsed : undefined;
|
||||
}
|
||||
|
||||
export async function action({ request, params }: ActionFunctionArgs) {
|
||||
const ctx = await loadProjectContext({ request, params, requireModule: true });
|
||||
const formData = await request.formData();
|
||||
const intent = formString(formData, "_action");
|
||||
const projectId = params.id!;
|
||||
try {
|
||||
if (intent === "addMember") {
|
||||
requireProjectPermission(ctx, "projects.manage_members");
|
||||
const member = await addProjectMember({
|
||||
tenantId: ctx.tenantId,
|
||||
projectId,
|
||||
createdByUserId: ctx.userId,
|
||||
userId: formString(formData, "userId"),
|
||||
groupId: formString(formData, "groupId"),
|
||||
rolle: formRole(formData),
|
||||
});
|
||||
return Response.json({ ok: true, member });
|
||||
}
|
||||
if (intent === "createAppointment") {
|
||||
requireProjectPermission(ctx, "projects.write");
|
||||
const appointment = await createProjectAppointment({
|
||||
tenantId: ctx.tenantId,
|
||||
projectId,
|
||||
createdByUserId: ctx.userId,
|
||||
titel: formString(formData, "titel") ?? "",
|
||||
beschreibung: formString(formData, "beschreibung"),
|
||||
startAt: formString(formData, "startAt") ?? "",
|
||||
endAt: formString(formData, "endAt"),
|
||||
assignedToUserId: formString(formData, "assignedToUserId"),
|
||||
assignedToGroupId: formString(formData, "assignedToGroupId"),
|
||||
});
|
||||
return Response.json({ ok: true, appointment });
|
||||
}
|
||||
if (intent === "createInvoice") {
|
||||
requireProjectPermission(ctx, "projects.write");
|
||||
const invoice = await createProjectInvoice({
|
||||
tenantId: ctx.tenantId,
|
||||
projectId,
|
||||
createdByUserId: ctx.userId,
|
||||
betrag: formString(formData, "betrag") ?? "0",
|
||||
datum: formString(formData, "datum"),
|
||||
faelligAm: formString(formData, "faelligAm"),
|
||||
dateiId: formString(formData, "dateiId"),
|
||||
});
|
||||
return Response.json({ ok: true, invoice });
|
||||
}
|
||||
if (intent === "updateInvoiceStatus") {
|
||||
requireProjectPermission(ctx, "projects.write");
|
||||
const invoice = await updateProjectInvoiceStatus({
|
||||
tenantId: ctx.tenantId,
|
||||
invoiceId: formString(formData, "invoiceId") ?? "",
|
||||
userId: ctx.userId,
|
||||
status: formInvoiceStatus(formData),
|
||||
});
|
||||
return Response.json({ ok: true, invoice });
|
||||
}
|
||||
if (intent === "createChecklist") {
|
||||
requireProjectPermission(ctx, "projects.write");
|
||||
const checklist = await createProjectChecklist({
|
||||
tenantId: ctx.tenantId,
|
||||
projectId,
|
||||
createdByUserId: ctx.userId,
|
||||
titel: formString(formData, "titel") ?? "",
|
||||
typ: formChecklistType(formData),
|
||||
});
|
||||
return Response.json({ ok: true, checklist });
|
||||
}
|
||||
if (intent === "upsertChecklistItem") {
|
||||
requireProjectPermission(ctx, "projects.write");
|
||||
const item = await upsertProjectChecklistItem({
|
||||
tenantId: ctx.tenantId,
|
||||
checklistId: formString(formData, "checklistId") ?? "",
|
||||
itemId: formString(formData, "itemId"),
|
||||
titel: formString(formData, "titel") ?? "",
|
||||
status: formString(formData, "status") === "erledigt" ? "erledigt" : "offen",
|
||||
maengelKlasse: formString(formData, "maengelKlasse"),
|
||||
fotoFileId: formString(formData, "fotoFileId"),
|
||||
assignedToUserId: formString(formData, "assignedToUserId"),
|
||||
dueAt: formString(formData, "dueAt"),
|
||||
position: formPosition(formData),
|
||||
});
|
||||
return Response.json({ ok: true, item });
|
||||
}
|
||||
if (intent === "createSignatureDraft") {
|
||||
const document = await createSignatureDraft({
|
||||
tenantId: ctx.tenantId,
|
||||
projectId,
|
||||
userId: ctx.userId,
|
||||
ctx,
|
||||
title: formString(formData, "title"),
|
||||
sourcePdfFileId: formString(formData, "sourcePdfFileId"),
|
||||
signers: parseSignatureSigners(formString(formData, "signers")),
|
||||
subject: formString(formData, "subject"),
|
||||
message: formString(formData, "message"),
|
||||
});
|
||||
return Response.json({ ok: true, document });
|
||||
}
|
||||
if (intent === "sendSignatureDocument") {
|
||||
const publicBaseUrl = new URL(request.url).origin;
|
||||
const result = await sendSignatureDocument({ tenantId: ctx.tenantId, documentId: formString(formData, "documentId") ?? "", userId: ctx.userId, ctx, publicBaseUrl });
|
||||
return Response.json({ ok: true, result });
|
||||
}
|
||||
if (intent === "remindSignatureSigner") {
|
||||
const result = await remindSignatureSigner({ tenantId: ctx.tenantId, signerId: formString(formData, "signerId") ?? "", userId: ctx.userId, ctx });
|
||||
return Response.json({ ok: true, result });
|
||||
}
|
||||
if (intent === "revokeSignatureDocument") {
|
||||
const result = await revokeSignatureDocument({ tenantId: ctx.tenantId, documentId: formString(formData, "documentId") ?? "", userId: ctx.userId, ctx });
|
||||
return Response.json({ ok: true, result });
|
||||
}
|
||||
return Response.json({ error: "projects.error.unsupportedAction" }, { status: 400 });
|
||||
} catch (error) {
|
||||
if (error instanceof SignatureServiceError) {
|
||||
return Response.json({ error: error.messageKey }, { status: 400 });
|
||||
}
|
||||
return projectActionErrorResponse(error);
|
||||
}
|
||||
}
|
||||
|
||||
export default function ProjectDetailRoute() {
|
||||
const { t } = useTranslation();
|
||||
const data = useLoaderData<LoaderData>();
|
||||
const project = data.project;
|
||||
const { subAreas } = data;
|
||||
|
||||
return (
|
||||
<main className="mx-auto flex w-full max-w-5xl flex-col gap-6 p-6">
|
||||
<nav className="flex flex-wrap gap-3 text-sm">
|
||||
<Link className="text-primary underline-offset-2 hover:underline" to={projectsPath(data.tenantSlug)}>
|
||||
{t("projects.actions.backToList")}
|
||||
</Link>
|
||||
<Link className="text-primary underline-offset-2 hover:underline" to={projectAcceptancePath(data.tenantSlug, project.id)}>
|
||||
{t("projects.actions.openAcceptance")}
|
||||
</Link>
|
||||
</nav>
|
||||
<header className="flex flex-col gap-1">
|
||||
<p className="text-sm text-muted-foreground">{project.projektNummer}</p>
|
||||
<h1 className="text-2xl font-semibold">{project.projektname}</h1>
|
||||
</header>
|
||||
<dl className="grid gap-4 rounded-md border bg-background p-4 md:grid-cols-2">
|
||||
<div>
|
||||
<dt className="text-sm text-muted-foreground">{t("projects.fields.pipeline")}</dt>
|
||||
<dd className="font-medium">{project.pipelineId}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-sm text-muted-foreground">{t("projects.fields.stage")}</dt>
|
||||
<dd className="font-medium">{project.stageId}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-sm text-muted-foreground">{t("projects.fields.sourceLead")}</dt>
|
||||
<dd className="font-medium">{project.konvertiertAusLeadId ?? "—"}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-sm text-muted-foreground">{t("projects.fields.owner")}</dt>
|
||||
<dd className="font-medium">{project.zustaendigePersonId ?? "—"}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
{subAreas.openDefects > 0 ? (
|
||||
<aside className="rounded-md border border-amber-300 bg-amber-50 p-4 text-sm text-amber-950">
|
||||
{t("projects.subAreas.openDefects", { count: subAreas.openDefects })}
|
||||
</aside>
|
||||
) : null}
|
||||
<SignaturePanel vm={data.signature} />
|
||||
<section className="grid gap-4 md:grid-cols-2">
|
||||
<article className="rounded-md border bg-background p-4">
|
||||
<h2 className="font-semibold">{t("projects.subAreas.members")}</h2>
|
||||
<ul className="mt-3 grid gap-2 text-sm">
|
||||
{subAreas.members.map((member) => (
|
||||
<li key={member.id} className="rounded border px-3 py-2">
|
||||
{member.rolle} · {member.userId ?? member.groupId}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Form className="mt-4 grid gap-2" method="post">
|
||||
<input type="hidden" name="_action" value="addMember" />
|
||||
<input className="rounded-md border px-3 py-2 text-sm" name="userId" placeholder={t("projects.fields.userId")} />
|
||||
<select className="rounded-md border px-3 py-2 text-sm" name="rolle" defaultValue="monteur">
|
||||
<option value="monteur">{t("projects.roles.monteur")}</option>
|
||||
<option value="projektleiter">{t("projects.roles.projektleiter")}</option>
|
||||
<option value="zustaendig">{t("projects.roles.zustaendig")}</option>
|
||||
<option value="beobachter">{t("projects.roles.beobachter")}</option>
|
||||
</select>
|
||||
<button className="rounded-md bg-primary px-3 py-2 text-sm text-primary-foreground" type="submit">
|
||||
{t("projects.actions.addMember")}
|
||||
</button>
|
||||
</Form>
|
||||
</article>
|
||||
<article className="rounded-md border bg-background p-4">
|
||||
<h2 className="font-semibold">{t("projects.subAreas.appointments")}</h2>
|
||||
<ul className="mt-3 grid gap-2 text-sm">
|
||||
{subAreas.appointments.map((appointment) => (
|
||||
<li key={appointment.id} className="rounded border px-3 py-2">
|
||||
{appointment.titel} · {appointment.status}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Form className="mt-4 grid gap-2" method="post">
|
||||
<input type="hidden" name="_action" value="createAppointment" />
|
||||
<input className="rounded-md border px-3 py-2 text-sm" name="titel" placeholder={t("projects.fields.appointmentTitle")} />
|
||||
<input className="rounded-md border px-3 py-2 text-sm" name="startAt" type="datetime-local" />
|
||||
<button className="rounded-md bg-primary px-3 py-2 text-sm text-primary-foreground" type="submit">
|
||||
{t("projects.actions.createAppointment")}
|
||||
</button>
|
||||
</Form>
|
||||
</article>
|
||||
<article className="rounded-md border bg-background p-4">
|
||||
<h2 className="font-semibold">{t("projects.subAreas.invoices")}</h2>
|
||||
<ul className="mt-3 grid gap-2 text-sm">
|
||||
{subAreas.invoices.map((invoice) => (
|
||||
<li key={invoice.id} className="rounded border px-3 py-2">
|
||||
{invoice.rechnungsnummer} · {invoice.status}
|
||||
<Form className="mt-2 flex gap-2" method="post">
|
||||
<input type="hidden" name="_action" value="updateInvoiceStatus" />
|
||||
<input type="hidden" name="invoiceId" value={invoice.id} />
|
||||
<select className="rounded-md border px-2 py-1 text-sm" name="status" defaultValue={invoice.status}>
|
||||
<option value="entwurf">{t("projects.invoiceStatus.entwurf")}</option>
|
||||
<option value="gestellt">{t("projects.invoiceStatus.gestellt")}</option>
|
||||
<option value="bezahlt">{t("projects.invoiceStatus.bezahlt")}</option>
|
||||
<option value="storniert">{t("projects.invoiceStatus.storniert")}</option>
|
||||
</select>
|
||||
<button className="rounded-md border px-2 py-1 text-sm" type="submit">
|
||||
{t("projects.actions.updateStatus")}
|
||||
</button>
|
||||
</Form>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Form className="mt-4 grid gap-2" method="post">
|
||||
<input type="hidden" name="_action" value="createInvoice" />
|
||||
<input className="rounded-md border px-3 py-2 text-sm" name="betrag" placeholder={t("projects.fields.amount")} />
|
||||
<input className="rounded-md border px-3 py-2 text-sm" name="dateiId" placeholder={t("projects.fields.fileId")} />
|
||||
<button className="rounded-md bg-primary px-3 py-2 text-sm text-primary-foreground" type="submit">
|
||||
{t("projects.actions.createInvoice")}
|
||||
</button>
|
||||
</Form>
|
||||
</article>
|
||||
<article className="rounded-md border bg-background p-4">
|
||||
<h2 className="font-semibold">{t("projects.subAreas.checklists")}</h2>
|
||||
<ul className="mt-3 grid gap-2 text-sm">
|
||||
{subAreas.checklists.map((checklist) => (
|
||||
<li key={checklist.id} className="rounded border px-3 py-2">
|
||||
{checklist.titel} · {checklist.typ}
|
||||
<ul className="mt-2 grid gap-1">
|
||||
{checklist.items?.map((item) => (
|
||||
<li key={item.id}>{item.titel}</li>
|
||||
))}
|
||||
</ul>
|
||||
<Form className="mt-2 flex gap-2" method="post">
|
||||
<input type="hidden" name="_action" value="upsertChecklistItem" />
|
||||
<input type="hidden" name="checklistId" value={checklist.id} />
|
||||
<input className="min-w-0 flex-1 rounded-md border px-2 py-1 text-sm" name="titel" placeholder={t("projects.fields.checklistItem")} />
|
||||
<button className="rounded-md border px-2 py-1 text-sm" type="submit">
|
||||
{t("projects.actions.addItem")}
|
||||
</button>
|
||||
</Form>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Form className="mt-4 grid gap-2" method="post">
|
||||
<input type="hidden" name="_action" value="createChecklist" />
|
||||
<input className="rounded-md border px-3 py-2 text-sm" name="titel" placeholder={t("projects.fields.checklistTitle")} />
|
||||
<select className="rounded-md border px-3 py-2 text-sm" name="typ" defaultValue="generisch">
|
||||
<option value="generisch">{t("projects.checklistTypes.generisch")}</option>
|
||||
<option value="maengel">{t("projects.checklistTypes.maengel")}</option>
|
||||
<option value="abnahme_doku">{t("projects.checklistTypes.abnahmeDoku")}</option>
|
||||
</select>
|
||||
<button className="rounded-md bg-primary px-3 py-2 text-sm text-primary-foreground" type="submit">
|
||||
{t("projects.actions.createChecklist")}
|
||||
</button>
|
||||
</Form>
|
||||
</article>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function SignaturePanel({ vm }: { vm: ProjectSignaturePanelVM }) {
|
||||
const { t } = useTranslation();
|
||||
if (vm.status !== "ready" || !vm.data.canRead) return null;
|
||||
const data = vm.data;
|
||||
return (
|
||||
<section className="rounded-md border bg-background p-4">
|
||||
<div className="flex flex-col gap-1">
|
||||
<h2 className="font-semibold">{t("signature.project.title")}</h2>
|
||||
<p className="text-sm text-muted-foreground">{t(data.designBlockedByKey)}</p>
|
||||
</div>
|
||||
{data.rows.length === 0 ? (
|
||||
<div className="mt-4 rounded-md border border-dashed p-4 text-sm">
|
||||
<p className="font-medium">{t(data.emptyHeadlineKey)}</p>
|
||||
<p className="mt-1 text-muted-foreground">{t(data.emptyBodyKey)}</p>
|
||||
</div>
|
||||
) : (
|
||||
<ul className="mt-4 grid gap-3">
|
||||
{data.rows.map((document) => (
|
||||
<li key={document.id} className="rounded-md border p-3">
|
||||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<h3 className="font-medium">{document.title}</h3>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t(document.providerKey)} · {t(document.statusKey)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{data.canSend && document.status === "draft" ? (
|
||||
<Form method="post">
|
||||
<input type="hidden" name="_action" value={data.sendActionIntent} />
|
||||
<input type="hidden" name="documentId" value={document.id} />
|
||||
<button className="rounded-md bg-primary px-3 py-2 text-sm text-primary-foreground" type="submit">
|
||||
{t("signature.actions.send")}
|
||||
</button>
|
||||
</Form>
|
||||
) : null}
|
||||
{data.canRevoke && document.status !== "signed" && document.status !== "revoked" ? (
|
||||
<Form method="post">
|
||||
<input type="hidden" name="_action" value={data.revokeActionIntent} />
|
||||
<input type="hidden" name="documentId" value={document.id} />
|
||||
<button className="rounded-md border px-3 py-2 text-sm" type="submit">
|
||||
{t("signature.actions.revoke")}
|
||||
</button>
|
||||
</Form>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<ul className="mt-3 grid gap-2 text-sm">
|
||||
{document.signers.map((signer) => (
|
||||
<li key={signer.id} className="flex flex-wrap items-center justify-between gap-2 rounded border px-3 py-2">
|
||||
<span>
|
||||
{signer.signerName} · {signer.signerEmail} · {t(signer.statusKey)}
|
||||
</span>
|
||||
{data.canSend && signer.status !== "signed" && document.status !== "draft" ? (
|
||||
<Form method="post">
|
||||
<input type="hidden" name="_action" value={data.remindActionIntent} />
|
||||
<input type="hidden" name="signerId" value={signer.id} />
|
||||
<button className="rounded-md border px-2 py-1 text-sm" type="submit">
|
||||
{t("signature.actions.remind")}
|
||||
</button>
|
||||
</Form>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{data.canSend ? (
|
||||
<Form className="mt-4 grid gap-2" method="post">
|
||||
<input type="hidden" name="_action" value={data.createActionIntent} />
|
||||
<input className="rounded-md border px-3 py-2 text-sm" name="title" placeholder={t("signature.fields.title")} />
|
||||
<input className="rounded-md border px-3 py-2 text-sm" name="sourcePdfFileId" placeholder={t("signature.fields.sourcePdfFileId")} />
|
||||
<input className="rounded-md border px-3 py-2 text-sm" name="subject" placeholder={t("signature.fields.subject")} />
|
||||
<textarea className="min-h-24 rounded-md border px-3 py-2 text-sm" name="signers" placeholder={t("signature.fields.signers")} />
|
||||
<textarea className="min-h-20 rounded-md border px-3 py-2 text-sm" name="message" placeholder={t("signature.fields.message")} />
|
||||
<button className="rounded-md bg-primary px-3 py-2 text-sm text-primary-foreground" type="submit">
|
||||
{t("signature.actions.createDraft")}
|
||||
</button>
|
||||
</Form>
|
||||
) : null}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user