action.ts
"use server";
import prisma from "@/utils/prisma";
type FormDataType = {
name: string;
email: string;
message: string;
subject: string;
pno?: string;
};
export const addDoc = async (formData: FormData) => {
try {
if (
!formData.get("name") ||
!formData.get("email") ||
!formData.get("message") ||
!formData.get("subject")
) {
return;
}
const rawFormData: FormDataType = {
name: formData.get("name") as string,
email: formData.get("email") as string,
message: formData.get("message") as string,
subject: formData.get("subject") as string,
pno: formData.get("pno") as string,
};
await prisma.contact.create({
data: {
name: rawFormData.name,
email: rawFormData.email,
message: rawFormData.message,
subject: rawFormData.subject,
phone: rawFormData.pno,
},
});
} catch (error) {
console.log(error);
}
};
Form.tsx
const Form = () => {
return (
<form className={styles.form} autoComplete="off" action={addDoc}>
...
</form>
);
};
i basically wanna toast a message if the action has been succesfull but i'm getting the following error, whenever i'm using the toast function