refactor(recipients): move mutations into use cases
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const recipientSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
username: z
|
||||
.string()
|
||||
.min(1, {
|
||||
error: "Username is required",
|
||||
})
|
||||
.nonempty("Username is required"),
|
||||
firstName: z.string().min(1, {
|
||||
error: "First name is required",
|
||||
}),
|
||||
lastName: z.string().min(1, {
|
||||
error: "Last name is required",
|
||||
}),
|
||||
department: z.enum(
|
||||
[
|
||||
"IT",
|
||||
"ENGINEERING",
|
||||
"TRAFFIC",
|
||||
"DRIVER",
|
||||
"LOGISTICS",
|
||||
"ADMINISTRATION",
|
||||
"SALES",
|
||||
"OTHER",
|
||||
],
|
||||
{
|
||||
error: "Department is required",
|
||||
},
|
||||
),
|
||||
email: z.string().optional().nullable(),
|
||||
phone: z.string().optional().nullable(),
|
||||
})
|
||||
|
||||
export const createRecipientSchema = recipientSchema.superRefine(
|
||||
(data, ctx) => {
|
||||
if (data.email && !z.string().email().safeParse(data.email).success) {
|
||||
ctx.addIssue({
|
||||
code: "custom",
|
||||
message: "Email format is invalid",
|
||||
path: ["email"],
|
||||
})
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
export type CreateRecipientFormType = z.infer<typeof createRecipientSchema>
|
||||
|
||||
export const updateRecipientSchema = recipientSchema.extend({
|
||||
id: z.string().nonempty("ID is required"),
|
||||
})
|
||||
|
||||
export type UpdateRecipientFormType = z.infer<typeof updateRecipientSchema>
|
||||
Reference in New Issue
Block a user