so I’m trying to create a submitForm
using prisma
, react-hook-form
and zod
and mysql
as my database. But the problem I’m encountering right now is I get this error on form-submit.ts
Type 'string[]' is not assignable to type 'string'.ts(2322)
I know this comes from my schema.prisma
, because upon reading the docs, on Scalar
https://www.prisma.io/docs/orm/reference/prisma-schema-reference#-modifier
model AppoinmentSchedule {
id String @id @default(cuid())
doesHaveTCETAssitance String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Since my zod accepts array.
export const formSchemaData = z.object({
doesHaveDryRun: z.enum(["yes", "no"], {
required_error: "Please select if yes or not"
}),
})
form-submit.ts
export const submitForm = async (
values: z.infer<typeof formSchemaData>
) => {
const validatedFields = formSchemaData.safeParse(values)
if(!validatedFields.success){
return {error: "Form not submitted successfully!"}
}
const {
doesHaveTCETAssitance,
} = validatedFields.data
try {
await db.appoinmentSchedule.create({
data: {
doesHaveTCETAssitance,
}
})
} catch (error) {
return {error: "Something went wrong"}
}
}