styles, form, backend partial
This commit is contained in:
19
lib/actions.ts
Normal file
19
lib/actions.ts
Normal file
@ -0,0 +1,19 @@
|
||||
"use server";
|
||||
|
||||
import { z } from "zod";
|
||||
import { oldestDate, signupFormSchema, youngestDate } from "@/app/sign-up/sign-up-form";
|
||||
import listmonk from "./listmonk";
|
||||
|
||||
export async function signupFormSubmit(data: z.infer<typeof signupFormSchema>) {
|
||||
if (data.dob > youngestDate || data.dob < oldestDate) {
|
||||
return { error: "Invalid date of birth" };
|
||||
}
|
||||
const listmonkData = {
|
||||
email: data.email,
|
||||
name: data.name,
|
||||
attribs: {
|
||||
dob: data.dob.toISOString(),
|
||||
},
|
||||
};
|
||||
console.log(listmonkData);
|
||||
}
|
21
lib/listmonk.ts
Normal file
21
lib/listmonk.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import "server-only";
|
||||
|
||||
async function makeApiCall(url: string, options?: RequestInit) {
|
||||
try {
|
||||
const response = await fetch(url, options);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("Error making API call:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function listmonk() {
|
||||
const listmonkUrl = process.env.LISTMONK_URL ?? "";
|
||||
makeApiCall(listmonkUrl);
|
||||
}
|
||||
|
||||
export default listmonk;
|
Reference in New Issue
Block a user