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
@@ -1,7 +1,8 @@
|
||||
import { Form, useActionData, useLoaderData, type ActionFunctionArgs, type LoaderFunctionArgs } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useActionData, useLoaderData, useNavigation, type ActionFunctionArgs, type LoaderFunctionArgs } from "react-router";
|
||||
import { CatalogError } from "@hivegrid/foundation";
|
||||
import { recordSignatureLinkOpened, signWithOtp, SignatureServiceError } from "~/modules/signature/services/signatureService.server";
|
||||
import { getTrustedClientIp } from "~/utils/server/IpUtils";
|
||||
import { PublicSignPage } from "~/components/screens/signature/PublicSignPage";
|
||||
|
||||
type LoaderData = {
|
||||
title: string;
|
||||
@@ -13,7 +14,8 @@ type LoaderData = {
|
||||
type ActionData = { ok: true } | { ok: false; error: string };
|
||||
|
||||
function requestIp(request: Request): string | null {
|
||||
return request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || request.headers.get("x-real-ip");
|
||||
const ip = getTrustedClientIp(request);
|
||||
return ip === "unknown" ? null : ip;
|
||||
}
|
||||
|
||||
function userAgent(request: Request): string | null {
|
||||
@@ -49,55 +51,40 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
||||
intentAccepted: formData.get("intentAccepted") === "on",
|
||||
ipAddress: requestIp(request),
|
||||
userAgent: userAgent(request),
|
||||
trustedClientIp: getTrustedClientIp(request),
|
||||
});
|
||||
return Response.json({ ok: true } satisfies ActionData);
|
||||
} catch (error) {
|
||||
if (error instanceof SignatureServiceError) {
|
||||
return Response.json({ ok: false, error: error.messageKey } satisfies ActionData, { status: 400 });
|
||||
const headers = error.retryAfterSeconds ? { "Retry-After": String(error.retryAfterSeconds) } : undefined;
|
||||
return Response.json({ ok: false, error: error.messageKey } satisfies ActionData, { status: error.status, headers });
|
||||
}
|
||||
if (error instanceof CatalogError) throw new Response(null, { status: 404 });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export function headers() {
|
||||
return {
|
||||
"Cache-Control": "no-store",
|
||||
"Referrer-Policy": "no-referrer",
|
||||
};
|
||||
}
|
||||
|
||||
export default function SignatureLinkRoute() {
|
||||
const { t } = useTranslation();
|
||||
const data = useLoaderData<LoaderData>();
|
||||
const actionData = useActionData<ActionData>();
|
||||
const navigation = useNavigation();
|
||||
const isComplete = actionData?.ok === true || data.status === "signed";
|
||||
|
||||
return (
|
||||
<main className="mx-auto flex min-h-screen w-full max-w-xl flex-col justify-center gap-6 p-6">
|
||||
<header className="grid gap-2">
|
||||
<p className="text-muted-foreground text-sm">{data.signerEmail}</p>
|
||||
<h1 className="text-2xl font-semibold">{data.title}</h1>
|
||||
<p className="text-muted-foreground text-sm">{t("signature.public.intentIntro", { name: data.signerName })}</p>
|
||||
</header>
|
||||
{isComplete ? (
|
||||
<section className="bg-background rounded-md border p-4">
|
||||
<h2 className="font-semibold">{t("signature.public.completeTitle")}</h2>
|
||||
<p className="text-muted-foreground mt-2 text-sm">{t("signature.public.completeBody")}</p>
|
||||
</section>
|
||||
) : (
|
||||
<Form className="bg-background grid gap-4 rounded-md border p-4" method="post">
|
||||
{actionData?.ok === false ? <p className="border-destructive/40 bg-destructive/10 rounded-md border p-3 text-sm">{t(actionData.error)}</p> : null}
|
||||
<label className="grid gap-2 text-sm">
|
||||
<span>{t("signature.public.otp")}</span>
|
||||
<input className="rounded-md border px-3 py-2" inputMode="numeric" maxLength={6} name="otp" />
|
||||
</label>
|
||||
<label className="grid gap-2 text-sm">
|
||||
<span>{t("signature.public.signature")}</span>
|
||||
<textarea className="min-h-28 rounded-md border px-3 py-2" name="signatureSvg" />
|
||||
</label>
|
||||
<label className="flex gap-2 text-sm">
|
||||
<input name="intentAccepted" type="checkbox" />
|
||||
<span>{t("signature.public.intentCheckbox")}</span>
|
||||
</label>
|
||||
<button className="bg-primary text-primary-foreground rounded-md px-3 py-2 text-sm" type="submit">
|
||||
{t("signature.public.submit")}
|
||||
</button>
|
||||
</Form>
|
||||
)}
|
||||
</main>
|
||||
<PublicSignPage
|
||||
documentTitle={data.title}
|
||||
signerName={data.signerName}
|
||||
signerEmail={data.signerEmail}
|
||||
isComplete={isComplete}
|
||||
errorKey={actionData?.ok === false ? actionData.error : null}
|
||||
submitting={navigation.state !== "idle"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user