feat : Ajout de zod, création d'un composant de chargement loading-dots.vue et finalisation du flow d'une reception
This commit is contained in:
17
frontend/utils/zod-errors.ts
Normal file
17
frontend/utils/zod-errors.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { ZodError } from 'zod'
|
||||
|
||||
export type FieldErrors<T extends Record<string, unknown>> = Partial<Record<keyof T, string>>
|
||||
|
||||
export const mapZodErrors = <T extends Record<string, unknown>>(error: ZodError<T>): FieldErrors<T> => {
|
||||
const flattened = error.flatten().fieldErrors
|
||||
const result: FieldErrors<T> = {}
|
||||
|
||||
for (const key in flattened) {
|
||||
const message = flattened[key]?.[0]
|
||||
if (message) {
|
||||
result[key as keyof T] = message
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user