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,22 +1,25 @@
|
||||
/**
|
||||
* AK-P14b (P14 email marketing) — public double-opt-in confirmation route.
|
||||
*
|
||||
* The opt-in mail carries `/optin/<token>`. Verifies the HMAC marketing token
|
||||
* (purpose "optin") and flips the contact's KontaktMarketingConsent to `double`.
|
||||
* Idempotent: a second click is a no-op. No session / CSRF — the token IS the
|
||||
* auth (same stance as the unsubscribe route).
|
||||
* The opt-in mail carries `/optin/<token>`. GET verifies and displays a
|
||||
* confirmation without writing. Only the CSRF-protected POST flips the
|
||||
* contact's KontaktMarketingConsent to `double`; repeats are idempotent.
|
||||
*/
|
||||
|
||||
import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
|
||||
import { useLoaderData } from "react-router";
|
||||
import { Form, useActionData, useLoaderData } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { confirmOptIn } from "~/modules/emailMarketing/services/ConsentService.server";
|
||||
import { confirmOptIn, getOptInConfirmationStatus } from "~/modules/emailMarketing/services/ConsentService.server";
|
||||
import { createScopedLogger } from "~/utils/logger.server";
|
||||
import { MarketingResultPage } from "~/components/screens/email-marketing/EmailMarketingInterimScreens";
|
||||
import { validateCSRFToken } from "~/utils/session.server";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
|
||||
const logger = createScopedLogger("marketing.optin");
|
||||
|
||||
type LoaderData = {
|
||||
status: "confirmed" | "already_confirmed" | "invalid";
|
||||
status: "confirm" | "confirmed" | "already_confirmed" | "invalid";
|
||||
};
|
||||
|
||||
async function processOptIn(token: string): Promise<LoaderData> {
|
||||
@@ -26,14 +29,19 @@ async function processOptIn(token: string): Promise<LoaderData> {
|
||||
}
|
||||
|
||||
export async function loader({ params }: LoaderFunctionArgs): Promise<LoaderData> {
|
||||
return processOptIn(params.token ?? "");
|
||||
return { status: await getOptInConfirmationStatus(params.token ?? "") };
|
||||
}
|
||||
|
||||
export async function action({ params }: ActionFunctionArgs): Promise<LoaderData> {
|
||||
export async function action({ request, params }: ActionFunctionArgs): Promise<LoaderData> {
|
||||
await validateCSRFToken(request);
|
||||
return processOptIn(params.token ?? "");
|
||||
}
|
||||
|
||||
const MESSAGES: Record<LoaderData["status"], { title: string; description: string }> = {
|
||||
confirm: {
|
||||
title: "marketing.optin.confirm.title",
|
||||
description: "marketing.optin.confirm.description",
|
||||
},
|
||||
confirmed: {
|
||||
title: "marketing.optin.confirmed.title",
|
||||
description: "marketing.optin.confirmed.description",
|
||||
@@ -49,13 +57,25 @@ const MESSAGES: Record<LoaderData["status"], { title: string; description: strin
|
||||
};
|
||||
|
||||
export default function OptInRoute() {
|
||||
const data = useLoaderData<LoaderData>();
|
||||
const loaderData = useLoaderData<LoaderData>();
|
||||
const actionData = useActionData<LoaderData>();
|
||||
const data = actionData ?? loaderData;
|
||||
const { t } = useTranslation();
|
||||
const { csrf } = useRootData();
|
||||
const msg = MESSAGES[data.status];
|
||||
return (
|
||||
<main style={{ maxWidth: "600px", margin: "60px auto", padding: "0 20px", fontFamily: "system-ui, sans-serif" }}>
|
||||
<h1 style={{ fontSize: "24px" }}>{t(msg.title)}</h1>
|
||||
<p style={{ fontSize: "16px", lineHeight: "1.5", color: "#475569" }}>{t(msg.description)}</p>
|
||||
</main>
|
||||
);
|
||||
const action =
|
||||
data.status === "confirm" ? (
|
||||
<Form method="post">
|
||||
<input type="hidden" name="csrf" value={csrf} readOnly />
|
||||
<Button type="submit">{t("marketing.optin.confirm.action")}</Button>
|
||||
</Form>
|
||||
) : undefined;
|
||||
return <MarketingResultPage title={t(msg.title)} description={t(msg.description)} action={action} />;
|
||||
}
|
||||
|
||||
export function headers() {
|
||||
return {
|
||||
"Cache-Control": "no-store",
|
||||
"Referrer-Policy": "no-referrer",
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user