bam/lib/actions.ts
Felix Schulze b1952edb84 fixes
2025-03-04 17:59:19 +01:00

25 lines
722 B
TypeScript

"use server";
import { z } from "zod";
import { oldestDate, signupFormSchema, youngestDate } from "@/app/sign-up-form";
import listmonk, { listmonkData } from "./listmonk";
export async function signupFormSubmit(data: z.infer<typeof signupFormSchema>): Promise<string> {
if (data.dob > youngestDate || data.dob < oldestDate) {
return "Invalid date of birth";
}
const offset = data.dob.getTimezoneOffset();
data.dob = new Date(data.dob.getTime() - offset * 60 * 1000);
const listmonkData: listmonkData = {
email: data.email,
name: data.name,
status: "enabled",
lists: [3],
attribs: {
dob: data.dob.toISOString().split("T")[0],
},
};
return await listmonk(listmonkData);
}