bam/lib/actions.ts

22 lines
585 B
TypeScript
Raw Normal View History

2024-10-18 13:12:19 +02:00
"use server";
import { z } from "zod";
import { oldestDate, signupFormSchema, youngestDate } from "@/app/sign-up/sign-up-form";
2024-10-18 13:36:15 +02:00
import listmonk, { listmonkData } from "./listmonk";
2024-10-18 13:12:19 +02:00
export async function signupFormSubmit(data: z.infer<typeof signupFormSchema>) {
if (data.dob > youngestDate || data.dob < oldestDate) {
return { error: "Invalid date of birth" };
}
2024-10-18 13:36:15 +02:00
const listmonkData: listmonkData = {
2024-10-18 13:12:19 +02:00
email: data.email,
name: data.name,
2024-10-18 13:36:15 +02:00
status: "enabled",
lists: [6],
2024-10-18 13:12:19 +02:00
attribs: {
dob: data.dob.toISOString(),
},
};
2024-10-18 13:36:15 +02:00
listmonk(listmonkData);
2024-10-18 13:12:19 +02:00
}