Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+96
@@ -0,0 +1,96 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
buildProjectSignaturePanelVM,
|
||||
signatureDocumentStatusKey,
|
||||
signatureProviderKey,
|
||||
signatureSignerStatusKey,
|
||||
type ProjectSignatureDocumentRow,
|
||||
} from "@hivegrid/view-models";
|
||||
import { ProjectSignaturePanel } from "./ProjectSignaturePanel";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (key: string) => key, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
const documentRow: ProjectSignatureDocumentRow = {
|
||||
id: "doc-1",
|
||||
title: "Angebot 2026",
|
||||
provider: "ses_selfhosted",
|
||||
providerKey: signatureProviderKey("ses_selfhosted"),
|
||||
status: "sent",
|
||||
statusKey: signatureDocumentStatusKey("sent"),
|
||||
sourcePdfFileId: "file-1",
|
||||
signedPdfFileId: "file-2",
|
||||
completionCertFileId: null,
|
||||
sourcePdfUrl: "/acme/media/file-1/original",
|
||||
signedPdfUrl: "/acme/media/file-2/original",
|
||||
completionCertUrl: null,
|
||||
sentAtIso: "2026-07-01T10:00:00.000Z",
|
||||
completedAtIso: null,
|
||||
expiresAtIso: null,
|
||||
signers: [
|
||||
{
|
||||
id: "signer-1",
|
||||
signerName: "Erika Mustermann",
|
||||
signerEmail: "erika@example.test",
|
||||
signerRole: "kunde",
|
||||
status: "sent",
|
||||
statusKey: signatureSignerStatusKey("sent"),
|
||||
signedAtIso: null,
|
||||
lastReminderAtIso: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
function renderPanel(rows: ProjectSignatureDocumentRow[] = [documentRow]) {
|
||||
const onSubmit = vi.fn();
|
||||
const vm = buildProjectSignaturePanelVM({ rows, canRead: true, canSend: true, canRevoke: true, canAdmin: false });
|
||||
render(<ProjectSignaturePanel vm={vm} submitting={false} actions={{ onSubmit }} />);
|
||||
return { onSubmit };
|
||||
}
|
||||
|
||||
describe("ProjectSignaturePanel", () => {
|
||||
it("renders documents with signer status rows and artifact downloads", () => {
|
||||
renderPanel();
|
||||
|
||||
expect(screen.getByText("Angebot 2026")).toBeInTheDocument();
|
||||
expect(screen.getByText("signature.status.document.sent")).toBeInTheDocument();
|
||||
expect(screen.getByText("Erika Mustermann")).toBeInTheDocument();
|
||||
expect(screen.getByText("signature.actions.downloadSource")).toHaveAttribute("href", "/acme/media/file-1/original");
|
||||
expect(screen.getByText("signature.actions.downloadSigned")).toHaveAttribute("href", "/acme/media/file-2/original");
|
||||
expect(screen.queryByText("signature.actions.downloadCertificate")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the empty state when no documents exist", () => {
|
||||
renderPanel([]);
|
||||
|
||||
expect(screen.getByText("signature.project.empty.headline")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("submits a reminder directly without a confirm dialog", () => {
|
||||
const { onSubmit } = renderPanel();
|
||||
|
||||
fireEvent.click(screen.getByText("signature.actions.remind"));
|
||||
expect(onSubmit).toHaveBeenCalledWith("remindSignatureSigner", { signerId: "signer-1" });
|
||||
});
|
||||
|
||||
it("revokes only after the confirm dialog is accepted", () => {
|
||||
const { onSubmit } = renderPanel();
|
||||
|
||||
fireEvent.click(screen.getByText("signature.actions.revoke"));
|
||||
expect(onSubmit).not.toHaveBeenCalled();
|
||||
expect(screen.getByText("signature.confirm.revoke.title")).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByText("signature.confirm.revoke.confirm"));
|
||||
expect(onSubmit).toHaveBeenCalledWith("revokeSignatureDocument", { documentId: "doc-1" });
|
||||
});
|
||||
|
||||
it("opens the preparation wizard from the header action", () => {
|
||||
renderPanel();
|
||||
|
||||
fireEvent.click(screen.getByText("signature.actions.createDraft"));
|
||||
expect(screen.getByText("signature.wizard.title")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+225
@@ -0,0 +1,225 @@
|
||||
// AK-P16d Interim-UI (AD-28) — project signature panel (D-P16 "Signatur-Wizard"
|
||||
// surface inside the project detail): per-document status tracking with signer
|
||||
// rows, remind/revoke/send actions, artifact downloads and the preparation
|
||||
// wizard dialog. Pure presentational: VM + actions come in as props, submits go
|
||||
// through the project route's existing signature intents. Final Subframe optics
|
||||
// land as a tracked design-nachzug once David's D-P16 ships.
|
||||
//
|
||||
// Remind honesty note: the backend records the reminder timestamp/event only —
|
||||
// no reminder email is queued yet, so the UI copy says "vermerkt".
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { ProjectSignatureDocumentRow, ProjectSignaturePanelVM } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { APP_TIME_ZONE } from "~/locale/format";
|
||||
import { SignatureWizardDialog, type SignatureWizardSubmitFields } from "./SignatureWizardDialog";
|
||||
|
||||
export type SignaturePanelSubmit = (intent: string, fields?: Record<string, string>) => void;
|
||||
|
||||
export type ProjectSignaturePanelProps = {
|
||||
vm: ProjectSignaturePanelVM;
|
||||
submitting: boolean;
|
||||
errorKey?: string | null;
|
||||
actions: {
|
||||
onSubmit: SignaturePanelSubmit;
|
||||
uploadPdf?: (file: File) => Promise<{ id: string; displayName: string }>;
|
||||
};
|
||||
};
|
||||
|
||||
const mutedText = "text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary";
|
||||
const headingText = "text-body-large-0 font-body-large-0 text-text-neutral-primary";
|
||||
const linkText = "text-body-default-medium-0 font-body-default-medium-0 text-brand-brand-text-default hover:underline";
|
||||
|
||||
type ConfirmState = { kind: "send" | "revoke"; documentId: string; documentTitle: string } | null;
|
||||
|
||||
function formatDateTime(value: string | null, language: string): string {
|
||||
if (!value) return "—";
|
||||
return new Intl.DateTimeFormat(language, { timeZone: APP_TIME_ZONE, dateStyle: "medium", timeStyle: "short" }).format(new Date(value));
|
||||
}
|
||||
|
||||
function documentBadgeColor(status: ProjectSignatureDocumentRow["status"]): "subtle-positive" | "subtle-negative" | "subtle-warning" | "subtle-neutral" {
|
||||
if (status === "signed") return "subtle-positive";
|
||||
if (status === "declined" || status === "revoked" || status === "expired") return "subtle-negative";
|
||||
if (status === "sent" || status === "viewed") return "subtle-warning";
|
||||
return "subtle-neutral";
|
||||
}
|
||||
|
||||
export function ProjectSignaturePanel(props: ProjectSignaturePanelProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [wizardOpen, setWizardOpen] = useState(false);
|
||||
const [confirm, setConfirm] = useState<ConfirmState>(null);
|
||||
if (props.vm.status !== "ready" || !props.vm.data.canRead) return null;
|
||||
const data = props.vm.data;
|
||||
const submit = props.actions.onSubmit;
|
||||
|
||||
function submitWizard(intent: "create" | "createAndSend", fields: SignatureWizardSubmitFields) {
|
||||
submit(intent === "create" ? data.createActionIntent : data.createAndSendActionIntent, fields);
|
||||
setWizardOpen(false);
|
||||
}
|
||||
|
||||
function confirmAction() {
|
||||
if (!confirm) return;
|
||||
submit(confirm.kind === "send" ? data.sendActionIntent : data.revokeActionIntent, { documentId: confirm.documentId });
|
||||
setConfirm(null);
|
||||
}
|
||||
|
||||
return (
|
||||
<Card data-ui-id="ui.projects.operations.signature">
|
||||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className={headingText}>{t("signature.project.title")}</span>
|
||||
<span className={mutedText}>{t(data.designBlockedByKey)}</span>
|
||||
</div>
|
||||
{data.canSend ? (
|
||||
<Button loading={props.submitting} onClick={() => setWizardOpen(true)} data-ui-id="ui.projects.operations.signature.prepare">
|
||||
{t("signature.actions.createDraft")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{props.errorKey ? <Alert variant="error" title={t(props.errorKey)} /> : null}
|
||||
|
||||
{data.rows.length === 0 ? (
|
||||
<EmptyState outlined title={t(data.emptyHeadlineKey)} body={t(data.emptyBodyKey)} />
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
{data.rows.map((document) => (
|
||||
<div key={document.id} className="flex w-full flex-col gap-4 rounded-md border border-solid border-border-default p-4" data-ui-id="ui.projects.operations.signature.document">
|
||||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className={headingText}>{document.title}</span>
|
||||
<BadgeFeedback farbe={documentBadgeColor(document.status)}>{t(document.statusKey)}</BadgeFeedback>
|
||||
<BadgeFeedback farbe="subtle-neutral">{t(document.providerKey)}</BadgeFeedback>
|
||||
</div>
|
||||
<span className={mutedText}>
|
||||
{t("signature.panel.sentAt")}: {formatDateTime(document.sentAtIso, i18n.language)} · {t("signature.panel.expiresAt")}: {formatDateTime(document.expiresAtIso, i18n.language)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{data.canSend && document.status === "draft" ? (
|
||||
<Button size="small" loading={props.submitting} onClick={() => setConfirm({ kind: "send", documentId: document.id, documentTitle: document.title })}>
|
||||
{t("signature.actions.send")}
|
||||
</Button>
|
||||
) : null}
|
||||
{data.canRevoke && document.status !== "signed" && document.status !== "revoked" ? (
|
||||
<Button
|
||||
variant="tertiary"
|
||||
size="small"
|
||||
loading={props.submitting}
|
||||
onClick={() => setConfirm({ kind: "revoke", documentId: document.id, documentTitle: document.title })}
|
||||
>
|
||||
{t("signature.actions.revoke")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-4">
|
||||
{document.sourcePdfUrl ? (
|
||||
<a className={linkText} href={document.sourcePdfUrl} target="_blank" rel="noreferrer">
|
||||
{t("signature.actions.downloadSource")}
|
||||
</a>
|
||||
) : null}
|
||||
{document.signedPdfUrl ? (
|
||||
<a className={linkText} href={document.signedPdfUrl} target="_blank" rel="noreferrer">
|
||||
{t("signature.actions.downloadSigned")}
|
||||
</a>
|
||||
) : null}
|
||||
{document.completionCertUrl ? (
|
||||
<a className={linkText} href={document.completionCertUrl} target="_blank" rel="noreferrer">
|
||||
{t("signature.actions.downloadCertificate")}
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<Table>
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("signature.fields.signerName")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("signature.fields.signerEmail")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("signature.fields.signerRole")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("signature.panel.signerStatus")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("signature.panel.signedAt")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("signature.panel.lastReminder")}</Table.HeaderCell>
|
||||
<Table.HeaderCell />
|
||||
</Table.HeaderRow>
|
||||
{document.signers.map((signer) => (
|
||||
<Table.Row key={signer.id}>
|
||||
<Table.Cell>{signer.signerName}</Table.Cell>
|
||||
<Table.Cell>{signer.signerEmail}</Table.Cell>
|
||||
<Table.Cell>{t(`signature.roles.${signer.signerRole}`)}</Table.Cell>
|
||||
<Table.Cell>
|
||||
<BadgeFeedback farbe={signer.status === "signed" ? "subtle-positive" : "subtle-neutral"}>{t(signer.statusKey)}</BadgeFeedback>
|
||||
</Table.Cell>
|
||||
<Table.Cell>{formatDateTime(signer.signedAtIso, i18n.language)}</Table.Cell>
|
||||
<Table.Cell>{formatDateTime(signer.lastReminderAtIso, i18n.language)}</Table.Cell>
|
||||
<Table.Cell>
|
||||
{data.canSend && (signer.status === "sent" || signer.status === "viewed") ? (
|
||||
<Button
|
||||
variant="tertiary"
|
||||
size="small"
|
||||
loading={props.submitting}
|
||||
onClick={() => submit(data.remindActionIntent, { signerId: signer.id })}
|
||||
data-ui-id="ui.projects.operations.signature.remind"
|
||||
>
|
||||
{t("signature.actions.remind")}
|
||||
</Button>
|
||||
) : null}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
{data.canSend ? <span className={mutedText}>{t("signature.panel.remindHint")}</span> : null}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<SignatureWizardDialog
|
||||
open={wizardOpen}
|
||||
pdfFileOptions={data.pdfFileOptions}
|
||||
kontaktSuggestions={data.kontaktSuggestions}
|
||||
submitting={props.submitting}
|
||||
errorKey={props.errorKey}
|
||||
onSubmit={submitWizard}
|
||||
onClose={() => setWizardOpen(false)}
|
||||
uploadPdf={props.actions.uploadPdf}
|
||||
/>
|
||||
|
||||
<Dialog open={confirm !== null} onOpenChange={(nextOpen: boolean) => (nextOpen ? undefined : setConfirm(null))}>
|
||||
<Dialog.Content className="w-[420px] max-w-[90vw] p-6">
|
||||
{confirm ? (
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.projects.operations.signature.confirm">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t(`signature.confirm.${confirm.kind}.title`)}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t(`signature.confirm.${confirm.kind}.body`, { title: confirm.documentTitle })}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button variant="tertiary" onClick={() => setConfirm(null)}>
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
variant={confirm.kind === "revoke" ? "destructive" : "primary"}
|
||||
loading={props.submitting}
|
||||
onClick={confirmAction}
|
||||
data-ui-id="ui.projects.operations.signature.confirm.action"
|
||||
>
|
||||
{t(`signature.confirm.${confirm.kind}.confirm`)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
// AK-P16d Interim-UI (AD-28) — public signer page for /sign/:token, restyled
|
||||
// from hand-written markup to ~/ui components (analog to the login/verify
|
||||
// public routes, which also use ~/ui; the embed-safe PublicFormRenderer rule
|
||||
// does not apply here because this page never runs inside a host iframe).
|
||||
// The form posts the route action's existing contract: otp, signatureSvg,
|
||||
// intentAccepted. Final Subframe optics land as a tracked design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { Form } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Checkbox } from "~/ui/components/Checkbox";
|
||||
import { TextArea } from "~/ui/components/TextArea";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
export type PublicSignPageProps = {
|
||||
documentTitle: string;
|
||||
signerName: string;
|
||||
signerEmail: string;
|
||||
isComplete: boolean;
|
||||
errorKey: string | null;
|
||||
submitting: boolean;
|
||||
};
|
||||
|
||||
export function PublicSignPage(props: PublicSignPageProps) {
|
||||
const { t } = useTranslation();
|
||||
// The ~/ui Checkbox is a controlled Radix button; the hidden input carries
|
||||
// the value into the plain form POST the route action expects.
|
||||
const [intentAccepted, setIntentAccepted] = useState(false);
|
||||
|
||||
return (
|
||||
<main className="mx-auto flex min-h-screen w-full max-w-xl flex-col justify-center gap-6 p-6" data-ui-id="ui.signature.public.page">
|
||||
<header className="flex flex-col gap-1">
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{props.signerEmail}</span>
|
||||
<h1 className="text-heading-2 font-heading-2 text-text-neutral-primary">{props.documentTitle}</h1>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("signature.public.intentIntro", { name: props.signerName })}
|
||||
</span>
|
||||
</header>
|
||||
|
||||
{props.isComplete ? (
|
||||
<Alert
|
||||
variant="success"
|
||||
notDismissible
|
||||
title={t("signature.public.completeTitle")}
|
||||
description={t("signature.public.completeBody")}
|
||||
data-ui-id="ui.signature.public.complete"
|
||||
/>
|
||||
) : (
|
||||
<Form method="post" className="flex w-full flex-col gap-4 rounded-md border border-solid border-border-default bg-surface-neutral-primary p-4">
|
||||
{props.errorKey ? <Alert variant="error" notDismissible title={t(props.errorKey)} /> : null}
|
||||
<TextInput className="w-full" label={t("signature.public.otp")} showLabel>
|
||||
<TextInput.Input name="otp" inputMode="numeric" maxLength={6} autoComplete="one-time-code" data-ui-id="ui.signature.public.otp" />
|
||||
</TextInput>
|
||||
<TextArea className="w-full max-w-none" label={t("signature.public.signature")} showLabel>
|
||||
<TextArea.Input name="signatureSvg" data-ui-id="ui.signature.public.signature" />
|
||||
</TextArea>
|
||||
<input type="hidden" name="intentAccepted" value={intentAccepted ? "on" : ""} readOnly />
|
||||
<Checkbox
|
||||
label={t("signature.public.intentCheckbox")}
|
||||
checked={intentAccepted}
|
||||
onCheckedChange={setIntentAccepted}
|
||||
data-ui-id="ui.signature.public.intent"
|
||||
/>
|
||||
<div className="flex w-full items-center justify-end">
|
||||
<Button type="submit" loading={props.submitting} data-ui-id="ui.signature.public.submit">
|
||||
{t("signature.public.submit")}
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { serializeSignatureSigners, SignatureWizardDialog } from "./SignatureWizardDialog";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
|
||||
describe("serializeSignatureSigners", () => {
|
||||
it("serializes rows into the parseSignatureSigners line contract in row order", () => {
|
||||
const text = serializeSignatureSigners([
|
||||
{ name: "Erika Mustermann", email: "erika@example.test", role: "kunde" },
|
||||
{ name: "Max Bau", email: "max@example.test", role: "bauherr" },
|
||||
]);
|
||||
expect(text).toBe("Erika Mustermann; erika@example.test; kunde\nMax Bau; max@example.test; bauherr");
|
||||
});
|
||||
|
||||
it("strips separators and line breaks from free-text parts so rows can never split", () => {
|
||||
const text = serializeSignatureSigners([{ name: "Erika; GmbH\nCo", email: " erika@example.test ", role: "intern" }]);
|
||||
expect(text).toBe("Erika GmbH Co; erika@example.test; intern");
|
||||
});
|
||||
});
|
||||
|
||||
describe("SignatureWizardDialog", () => {
|
||||
function renderWizard(overrides?: Partial<Parameters<typeof SignatureWizardDialog>[0]>) {
|
||||
const onSubmit = vi.fn();
|
||||
const uploadPdf = vi.fn().mockResolvedValue({ id: "file_new", displayName: "Angebot.pdf" });
|
||||
render(
|
||||
<SignatureWizardDialog
|
||||
open
|
||||
pdfFileOptions={[]}
|
||||
kontaktSuggestions={[]}
|
||||
submitting={false}
|
||||
onSubmit={onSubmit}
|
||||
onClose={() => undefined}
|
||||
uploadPdf={uploadPdf}
|
||||
{...overrides}
|
||||
/>
|
||||
);
|
||||
return { onSubmit, uploadPdf };
|
||||
}
|
||||
|
||||
it("gates the document step until title and source pdf are set", () => {
|
||||
renderWizard();
|
||||
|
||||
expect(screen.getByText("shared.next").closest("button")).toBeDisabled();
|
||||
fireEvent.change(screen.getByLabelText("signature.fields.title"), { target: { value: "Angebot 2026" } });
|
||||
expect(screen.getByText("shared.next").closest("button")).toBeDisabled();
|
||||
});
|
||||
|
||||
it("uploads a PDF, walks the steps and submits the serialized signer lines", async () => {
|
||||
const { onSubmit, uploadPdf } = renderWizard();
|
||||
|
||||
fireEvent.change(screen.getByLabelText("signature.fields.title"), { target: { value: "Angebot 2026" } });
|
||||
const file = new File(["%PDF-1.7"], "Angebot.pdf", { type: "application/pdf" });
|
||||
const input = document.querySelector('[data-wizard-field="uploadInput"]') as HTMLInputElement;
|
||||
fireEvent.change(input, { target: { files: [file] } });
|
||||
await waitFor(() => expect(uploadPdf).toHaveBeenCalledWith(file));
|
||||
await screen.findByText("signature.wizard.uploadedAs");
|
||||
|
||||
fireEvent.click(screen.getByText("shared.next"));
|
||||
|
||||
// Signers step: one empty row gates Next until it is valid.
|
||||
expect(screen.getByText("shared.next").closest("button")).toBeDisabled();
|
||||
fireEvent.change(screen.getByLabelText("signature.fields.signerName"), { target: { value: "Erika; Mustermann" } });
|
||||
fireEvent.change(screen.getByLabelText("signature.fields.signerEmail"), { target: { value: "erika@example.test" } });
|
||||
fireEvent.click(screen.getByText("shared.next"));
|
||||
|
||||
fireEvent.click(screen.getByText("signature.wizard.createAndSend"));
|
||||
expect(onSubmit).toHaveBeenCalledWith("createAndSend", {
|
||||
title: "Angebot 2026",
|
||||
sourcePdfFileId: "file_new",
|
||||
subject: "",
|
||||
message: "",
|
||||
signers: "Erika Mustermann; erika@example.test; kunde",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects non-pdf uploads with a plain-language error", async () => {
|
||||
const { uploadPdf } = renderWizard();
|
||||
|
||||
const file = new File(["hi"], "notes.txt", { type: "text/plain" });
|
||||
const input = document.querySelector('[data-wizard-field="uploadInput"]') as HTMLInputElement;
|
||||
fireEvent.change(input, { target: { files: [file] } });
|
||||
|
||||
await screen.findByText("signature.wizard.onlyPdf");
|
||||
expect(uploadPdf).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
+368
@@ -0,0 +1,368 @@
|
||||
// AK-P16d Interim-UI (AD-28) — signature preparation wizard as a REAL ~/ui
|
||||
// Dialog (D-P16 "Signatur-Wizard", size M 720) with a StepperHorizontal:
|
||||
// document (PDF from Files or fresh upload) → signers (structured rows with
|
||||
// Kontakt prefill; row order = signing order) → review & create/send.
|
||||
// Submits go through the project detail route's existing signature intents via
|
||||
// the injected actions callback — no fetching in here. Final Subframe optics
|
||||
// land as a tracked design-nachzug once David's D-P16 ships.
|
||||
//
|
||||
// Not built on purpose (no backend yet): sequential/parallel send enforcement,
|
||||
// a remote-vs-touch signature mode switch, linkedKontaktId persistence.
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherArrowDown, FeatherArrowUp, FeatherTrash2 } from "@subframe/core";
|
||||
import type { ProjectSignatureKontaktSuggestion, ProjectSignaturePdfFileOption } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { IconButton } from "~/ui/components/IconButton";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { StepperHorizontal } from "~/ui/components/StepperHorizontal";
|
||||
import { TextArea } from "~/ui/components/TextArea";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
export type SignatureWizardSignerRow = { name: string; email: string; role: string };
|
||||
|
||||
export type SignatureWizardSubmitFields = {
|
||||
title: string;
|
||||
sourcePdfFileId: string;
|
||||
subject: string;
|
||||
message: string;
|
||||
signers: string;
|
||||
};
|
||||
|
||||
export type SignatureWizardDialogProps = {
|
||||
open: boolean;
|
||||
pdfFileOptions: readonly ProjectSignaturePdfFileOption[];
|
||||
kontaktSuggestions: readonly ProjectSignatureKontaktSuggestion[];
|
||||
submitting: boolean;
|
||||
errorKey?: string | null;
|
||||
onSubmit: (intent: "create" | "createAndSend", fields: SignatureWizardSubmitFields) => void;
|
||||
onClose: () => void;
|
||||
/** Optional chunked-upload callback injected by the route; hides upload when absent. */
|
||||
uploadPdf?: (file: File) => Promise<{ id: string; displayName: string }>;
|
||||
};
|
||||
|
||||
const STEPS = ["document", "signers", "review"] as const;
|
||||
const SIGNER_ROLES = ["kunde", "bauherr", "auftraggeber", "rechnungsempfaenger", "intern"] as const;
|
||||
|
||||
const bodyText = "text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary";
|
||||
const summaryText = "text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary";
|
||||
|
||||
function emptySigner(): SignatureWizardSignerRow {
|
||||
return { name: "", email: "", role: "kunde" };
|
||||
}
|
||||
|
||||
function isEmailValid(email: string): boolean {
|
||||
return email.trim().includes("@");
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes structured signer rows into the existing `parseSignatureSigners`
|
||||
* line contract ("name; email; role" per line). Separators and line breaks are
|
||||
* stripped from free-text parts so a name can never split the line; row order
|
||||
* becomes the persisted signingOrder.
|
||||
*/
|
||||
export function serializeSignatureSigners(rows: readonly SignatureWizardSignerRow[]): string {
|
||||
const clean = (value: string) => value.replace(/[;\r\n]+/g, " ").replace(/\s+/g, " ").trim();
|
||||
return rows.map((row) => `${clean(row.name)}; ${clean(row.email)}; ${row.role}`).join("\n");
|
||||
}
|
||||
|
||||
type UploadState =
|
||||
| { status: "idle" }
|
||||
| { status: "uploading"; percent: number }
|
||||
| { status: "done"; displayName: string }
|
||||
| { status: "error"; errorKey: string };
|
||||
|
||||
export function SignatureWizardDialog(props: SignatureWizardDialogProps) {
|
||||
const { open, pdfFileOptions, kontaktSuggestions, submitting, errorKey, onSubmit, onClose, uploadPdf } = props;
|
||||
const { t } = useTranslation();
|
||||
const [step, setStep] = useState(0);
|
||||
const [title, setTitle] = useState("");
|
||||
const [subject, setSubject] = useState("");
|
||||
const [message, setMessage] = useState("");
|
||||
const [sourcePdfFileId, setSourcePdfFileId] = useState("");
|
||||
const [signers, setSigners] = useState<SignatureWizardSignerRow[]>([emptySigner()]);
|
||||
const [upload, setUpload] = useState<UploadState>({ status: "idle" });
|
||||
// Controlled kontakt picker value that resets after each pick so the same
|
||||
// kontakt can be added again (Radix Select only fires on value change).
|
||||
const [kontaktPick, setKontaktPick] = useState("");
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
// Options grow when an upload finishes so the fresh file is pickable/visible.
|
||||
const [uploadedOptions, setUploadedOptions] = useState<ProjectSignaturePdfFileOption[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setStep(0);
|
||||
setTitle("");
|
||||
setSubject("");
|
||||
setMessage("");
|
||||
setSourcePdfFileId("");
|
||||
setSigners([emptySigner()]);
|
||||
setUpload({ status: "idle" });
|
||||
setKontaktPick("");
|
||||
setUploadedOptions([]);
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
const allPdfOptions = [...uploadedOptions, ...pdfFileOptions];
|
||||
const documentIncomplete = title.trim().length === 0 || sourcePdfFileId.trim().length === 0;
|
||||
const signersIncomplete = signers.length === 0 || signers.some((row) => row.name.trim().length === 0 || !isEmailValid(row.email));
|
||||
|
||||
function updateSigner(index: number, patch: Partial<SignatureWizardSignerRow>) {
|
||||
setSigners((current) => current.map((row, i) => (i === index ? { ...row, ...patch } : row)));
|
||||
}
|
||||
|
||||
function moveSigner(index: number, direction: -1 | 1) {
|
||||
setSigners((current) => {
|
||||
const target = index + direction;
|
||||
if (target < 0 || target >= current.length) return current;
|
||||
const next = [...current];
|
||||
[next[index], next[target]] = [next[target], next[index]];
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
function addFromKontakt(kontaktId: string) {
|
||||
const kontakt = kontaktSuggestions.find((suggestion) => suggestion.kontaktId === kontaktId);
|
||||
if (!kontakt) return;
|
||||
const prefilled: SignatureWizardSignerRow = { name: kontakt.name, email: kontakt.email ?? "", role: "kunde" };
|
||||
setSigners((current) => {
|
||||
const [first, ...rest] = current;
|
||||
// Fill the first still-empty row instead of stacking empty rows.
|
||||
if (first && first.name.trim().length === 0 && first.email.trim().length === 0) return [prefilled, ...rest];
|
||||
return [...current, prefilled];
|
||||
});
|
||||
}
|
||||
|
||||
async function handleFileChosen(fileList: FileList | null) {
|
||||
const file = fileList?.[0];
|
||||
if (!file || !uploadPdf) return;
|
||||
if (file.type !== "application/pdf") {
|
||||
setUpload({ status: "error", errorKey: "signature.wizard.onlyPdf" });
|
||||
return;
|
||||
}
|
||||
setUpload({ status: "uploading", percent: 0 });
|
||||
try {
|
||||
const uploaded = await uploadPdf(file);
|
||||
setUploadedOptions((current) => [{ id: uploaded.id, displayName: uploaded.displayName, createdAtIso: null }, ...current]);
|
||||
setSourcePdfFileId(uploaded.id);
|
||||
setUpload({ status: "done", displayName: uploaded.displayName });
|
||||
} catch (error) {
|
||||
const key = error instanceof Error && "errorKey" in error ? String((error as { errorKey: unknown }).errorKey) : "signature.wizard.uploadError";
|
||||
setUpload({ status: "error", errorKey: key });
|
||||
} finally {
|
||||
if (fileInputRef.current) fileInputRef.current.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
function submit(intent: "create" | "createAndSend") {
|
||||
onSubmit(intent, {
|
||||
title: title.trim(),
|
||||
sourcePdfFileId: sourcePdfFileId.trim(),
|
||||
subject: subject.trim(),
|
||||
message: message.trim(),
|
||||
signers: serializeSignatureSigners(signers),
|
||||
});
|
||||
}
|
||||
|
||||
const selectedPdf = allPdfOptions.find((option) => option.id === sourcePdfFileId);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={(nextOpen: boolean) => (nextOpen ? undefined : onClose())}>
|
||||
<Dialog.Content className="w-[720px] max-w-[90vw] p-6">
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.projects.signature.wizard">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("signature.wizard.title")}</span>
|
||||
{errorKey ? <Alert variant="error" title={t(errorKey)} /> : null}
|
||||
</div>
|
||||
|
||||
<StepperHorizontal>
|
||||
{STEPS.map((key, index) => (
|
||||
<StepperHorizontal.Step
|
||||
key={key}
|
||||
firstStep={index === 0}
|
||||
lastStep={index === STEPS.length - 1}
|
||||
stepNumber={String(index + 1)}
|
||||
label={t(`signature.wizard.step.${key}`)}
|
||||
variant={index === step ? "active" : index < step ? "completed" : "default"}
|
||||
/>
|
||||
))}
|
||||
</StepperHorizontal>
|
||||
|
||||
{step === 0 ? (
|
||||
<div className="flex w-full flex-col gap-4" data-wizard-step="document">
|
||||
<TextInput className="w-full" label={t("signature.fields.title")} showLabel>
|
||||
<TextInput.Input value={title} onChange={(event) => setTitle(event.target.value)} required data-wizard-field="title" />
|
||||
</TextInput>
|
||||
{allPdfOptions.length > 0 ? (
|
||||
<Select
|
||||
className="w-full max-w-none"
|
||||
showLabel
|
||||
label={t("signature.wizard.selectPdf")}
|
||||
placeholder={t("signature.wizard.selectPdfPlaceholder")}
|
||||
value={sourcePdfFileId || undefined}
|
||||
onValueChange={(value: string) => setSourcePdfFileId(value)}
|
||||
data-wizard-field="sourcePdf"
|
||||
>
|
||||
{allPdfOptions.map((option) => (
|
||||
<Select.Item key={option.id} value={option.id}>
|
||||
{option.displayName}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
) : (
|
||||
<span className={bodyText}>{t("signature.wizard.noPdfOptions")}</span>
|
||||
)}
|
||||
{uploadPdf ? (
|
||||
<div className="flex flex-col gap-2">
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept="application/pdf"
|
||||
className="hidden"
|
||||
onChange={(event) => void handleFileChosen(event.target.files)}
|
||||
data-wizard-field="uploadInput"
|
||||
/>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="secondary"
|
||||
loading={upload.status === "uploading"}
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
data-ui-id="ui.projects.signature.wizard.upload"
|
||||
>
|
||||
{t("signature.wizard.uploadPdf")}
|
||||
</Button>
|
||||
{upload.status === "done" ? <span className={bodyText}>{t("signature.wizard.uploadedAs", { name: upload.displayName })}</span> : null}
|
||||
</div>
|
||||
{upload.status === "error" ? <Alert variant="error" title={t(upload.errorKey)} /> : null}
|
||||
</div>
|
||||
) : null}
|
||||
<TextInput className="w-full" label={t("signature.fields.subject")} showLabel>
|
||||
<TextInput.Input value={subject} onChange={(event) => setSubject(event.target.value)} data-wizard-field="subject" />
|
||||
</TextInput>
|
||||
<TextArea className="w-full max-w-none" label={t("signature.fields.message")} showLabel>
|
||||
<TextArea.Input value={message} onChange={(event) => setMessage(event.target.value)} data-wizard-field="message" />
|
||||
</TextArea>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{step === 1 ? (
|
||||
<div className="flex w-full flex-col gap-4" data-wizard-step="signers">
|
||||
{kontaktSuggestions.length > 0 ? (
|
||||
<Select
|
||||
className="w-full max-w-none"
|
||||
showLabel
|
||||
label={t("signature.wizard.addFromKontakt")}
|
||||
placeholder={t("signature.wizard.addFromKontaktPlaceholder")}
|
||||
value={kontaktPick || undefined}
|
||||
onValueChange={(value: string) => {
|
||||
addFromKontakt(value);
|
||||
setKontaktPick("");
|
||||
}}
|
||||
data-wizard-field="kontaktSuggestion"
|
||||
>
|
||||
{kontaktSuggestions.map((suggestion) => (
|
||||
<Select.Item key={suggestion.kontaktId} value={suggestion.kontaktId}>
|
||||
{suggestion.email ? `${suggestion.name} (${suggestion.email})` : suggestion.name}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
) : null}
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
{signers.map((row, index) => {
|
||||
const emailInvalid = row.email.trim().length > 0 && !isEmailValid(row.email);
|
||||
return (
|
||||
<div key={index} className="flex w-full items-end gap-2" data-wizard-signer-row={index}>
|
||||
<TextInput className="grow" label={t("signature.fields.signerName")} showLabel>
|
||||
<TextInput.Input value={row.name} onChange={(event) => updateSigner(index, { name: event.target.value })} required />
|
||||
</TextInput>
|
||||
<TextInput className="grow" label={t("signature.fields.signerEmail")} showLabel error={emailInvalid} message={emailInvalid ? t("signature.wizard.emailInvalid") : undefined}>
|
||||
<TextInput.Input type="email" value={row.email} onChange={(event) => updateSigner(index, { email: event.target.value })} required />
|
||||
</TextInput>
|
||||
<Select
|
||||
className="w-48 flex-none"
|
||||
showLabel
|
||||
label={t("signature.fields.signerRole")}
|
||||
value={row.role}
|
||||
onValueChange={(value: string) => updateSigner(index, { role: value })}
|
||||
>
|
||||
{SIGNER_ROLES.map((role) => (
|
||||
<Select.Item key={role} value={role}>
|
||||
{t(`signature.roles.${role}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<div className="flex flex-none items-center gap-1 pb-1">
|
||||
<IconButton size="small" icon={<FeatherArrowUp />} disabled={index === 0} onClick={() => moveSigner(index, -1)} aria-label={t("signature.wizard.moveUp")} />
|
||||
<IconButton size="small" icon={<FeatherArrowDown />} disabled={index === signers.length - 1} onClick={() => moveSigner(index, 1)} aria-label={t("signature.wizard.moveDown")} />
|
||||
<IconButton
|
||||
size="small"
|
||||
icon={<FeatherTrash2 />}
|
||||
disabled={signers.length === 1}
|
||||
onClick={() => setSigners((current) => current.filter((_, i) => i !== index))}
|
||||
aria-label={t("signature.wizard.removeSigner")}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<Button variant="secondary" onClick={() => setSigners((current) => [...current, emptySigner()])} data-ui-id="ui.projects.signature.wizard.add-signer">
|
||||
{t("signature.wizard.addSigner")}
|
||||
</Button>
|
||||
<span className={bodyText}>{t("signature.wizard.orderHint")}</span>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{step === 2 ? (
|
||||
<div className="flex w-full flex-col gap-2" data-wizard-step="review">
|
||||
<span className={bodyText}>{t("signature.wizard.review.body")}</span>
|
||||
<span className={summaryText}>
|
||||
{t("signature.wizard.review.document")}: {title || "—"} · {selectedPdf?.displayName ?? sourcePdfFileId ?? "—"}
|
||||
</span>
|
||||
<span className={summaryText}>{t("signature.wizard.review.signers")}:</span>
|
||||
{signers.map((row, index) => (
|
||||
<span key={index} className={bodyText}>
|
||||
{index + 1}. {row.name} · {row.email} · {t(`signature.roles.${row.role}`)}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button variant="tertiary" onClick={onClose}>
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
{step > 0 ? (
|
||||
<Button variant="secondary" onClick={() => setStep(step - 1)}>
|
||||
{t("shared.back")}
|
||||
</Button>
|
||||
) : null}
|
||||
{step < STEPS.length - 1 ? (
|
||||
<Button
|
||||
disabled={(step === 0 && documentIncomplete) || (step === 1 && signersIncomplete)}
|
||||
onClick={() => setStep(step + 1)}
|
||||
data-ui-id="ui.projects.signature.wizard.next"
|
||||
>
|
||||
{t("shared.next")}
|
||||
</Button>
|
||||
) : (
|
||||
<>
|
||||
<Button variant="secondary" loading={submitting} onClick={() => submit("create")} data-ui-id="ui.projects.signature.wizard.create">
|
||||
{t("signature.actions.createDraft")}
|
||||
</Button>
|
||||
<Button loading={submitting} onClick={() => submit("createAndSend")} data-ui-id="ui.projects.signature.wizard.create-send">
|
||||
{t("signature.wizard.createAndSend")}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user