Add the Workshops page and keep each sign-up on the site.
The form is built once to the settled field set, and a valid send is saved before anyone is emailed. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
974a5ace4c
commit
c0ba3a3798
50 files changed
+2773
-1
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import {
|
||||
EMPTY_WORKSHOP_FORM_VALUES,
|
||||
type WorkshopFieldErrors,
|
||||
type WorkshopFormValues,
|
||||
} from "../workshopSignup";
|
||||
|
||||
export const WORKSHOP_SIGNUP_DRAFT_COOKIE = "workshop_signup_draft";
|
||||
|
||||
export interface WorkshopSignupDraft {
|
||||
values: WorkshopFormValues;
|
||||
fieldErrors: WorkshopFieldErrors;
|
||||
}
|
||||
|
||||
export function encodeWorkshopSignupDraft(draft: WorkshopSignupDraft): string {
|
||||
return Buffer.from(JSON.stringify(draft), "utf8").toString("base64url");
|
||||
}
|
||||
|
||||
export function decodeWorkshopSignupDraft(raw: string | undefined): WorkshopSignupDraft | null {
|
||||
if (!raw) return null;
|
||||
try {
|
||||
const parsed = JSON.parse(Buffer.from(raw, "base64url").toString("utf8")) as Partial<WorkshopSignupDraft>;
|
||||
if (!parsed.values || typeof parsed.values !== "object") return null;
|
||||
return {
|
||||
values: { ...EMPTY_WORKSHOP_FORM_VALUES, ...parsed.values },
|
||||
fieldErrors: parsed.fieldErrors ?? {},
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function attachWorkshopSignupDraft(
|
||||
response: NextResponse,
|
||||
draft: WorkshopSignupDraft,
|
||||
): NextResponse {
|
||||
response.cookies.set(WORKSHOP_SIGNUP_DRAFT_COOKIE, encodeWorkshopSignupDraft(draft), {
|
||||
httpOnly: true,
|
||||
sameSite: "lax",
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
path: "/workshops",
|
||||
maxAge: 60 * 15,
|
||||
});
|
||||
return response;
|
||||
}
|
||||
Reference in new issue
Block a user