68 lines
1.3 KiB
TypeScript
68 lines
1.3 KiB
TypeScript
import { format } from 'date-fns'
|
|
import { z } from 'zod'
|
|
|
|
export const MAX_ITEMS = 50
|
|
|
|
export const enrollment = z.object({
|
|
id: z.uuidv4().optional(),
|
|
user: z
|
|
.object(
|
|
{
|
|
id: z.string(),
|
|
name: z.string(),
|
|
email: z.string(),
|
|
cpf: z.string('a')
|
|
},
|
|
{ error: 'Escolha um colaborador' }
|
|
)
|
|
.required(),
|
|
course: z
|
|
.object(
|
|
{
|
|
id: z.string(),
|
|
name: z.string(),
|
|
access_period: z.number(),
|
|
unit_price: z.number().optional()
|
|
},
|
|
{ error: 'Escolha um curso' }
|
|
)
|
|
.required(),
|
|
deduplication_window: z
|
|
.object({
|
|
offset_days: z.number()
|
|
})
|
|
.optional(),
|
|
scheduled_for: z
|
|
.date()
|
|
.optional()
|
|
.transform((date) => (date ? format(date, 'yyyy-MM-dd') : undefined)),
|
|
seat: z.object({ order_id: z.uuidv4() }).optional()
|
|
})
|
|
|
|
export const formSchema = z.object({
|
|
enrollments: z.array(enrollment).min(1).max(MAX_ITEMS)
|
|
})
|
|
|
|
export type Schema = z.infer<typeof formSchema>
|
|
|
|
export type Enrollment = z.infer<typeof enrollment>
|
|
|
|
export type User = {
|
|
id: string
|
|
name: string
|
|
email: string
|
|
cpf: string
|
|
}
|
|
|
|
export type Course = {
|
|
id: string
|
|
name: string
|
|
access_period: number
|
|
metadata__unit_price?: number
|
|
}
|
|
|
|
export type Enrolled = {
|
|
status: 'fail' | 'success'
|
|
input_record: { user: any; course: any }
|
|
}
|