26 lines
1.0 KiB
TypeScript
26 lines
1.0 KiB
TypeScript
import { z } from 'zod'
|
|
|
|
const ACCEPTED_UPLOAD_TYPES = ['image/jpeg', 'image/png', 'application/pdf']
|
|
const MAX_SIZE_BYTES = 1 * 1024 * 1024 // 1MB
|
|
|
|
const DocumentUploadSchema = z.object({
|
|
entityType_code: z.string().default('encounter'),
|
|
ref_id: z.number(),
|
|
upload_employee_id: z.number().optional(),
|
|
// upload_employee_id: z.number(),
|
|
name: z.string({ required_error: 'Mohon isi', }),
|
|
type_code: z.string({ required_error: 'Mohon isi', }),
|
|
content: z.custom<File>()
|
|
.refine((f) => f, { message: 'File tidak boleh kosong' })
|
|
.refine((f) => !f || f instanceof File, { message: 'Harus berupa file yang valid' })
|
|
.refine((f) => !f || ACCEPTED_UPLOAD_TYPES.includes(f.type), {
|
|
message: 'Format file harus JPG, PNG, atau PDF',
|
|
})
|
|
.refine((f) => !f || f.size <= MAX_SIZE_BYTES, { message: 'Maksimal 1MB' }),
|
|
})
|
|
|
|
type DocumentUploadFormData = z.infer<typeof DocumentUploadSchema>
|
|
|
|
export { DocumentUploadSchema }
|
|
export type { DocumentUploadFormData }
|