diff --git a/apps/web/src/pages/peserta/csv.tsx b/apps/web/src/pages/peserta/csv.tsx index 6d6b343a..2a5c6aa9 100644 --- a/apps/web/src/pages/peserta/csv.tsx +++ b/apps/web/src/pages/peserta/csv.tsx @@ -43,7 +43,7 @@ import { import { api } from "~/utils/api"; import Sidebar from "~/components/Sidebar"; -type StateZodErr = Array<{ message: string; path: Array }>; +type StateZodErr = { error: Array<{ message: string; path: Array }>; dataOfError: Array<{ "Bagian Dari": string; Nama: string }> }; const HalamanTambah = () => { const toast = useToast(); @@ -96,13 +96,19 @@ const HalamanTambah = () => { const result = CSVDataValidator.safeParse(records); if (!result.success) { - const error = JSON.parse(result.error.message) as StateZodErr; + const error = JSON.parse(result.error.message) as StateZodErr['error']; - setErr(error); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const dataOfError = error.map(d => records[d.path[0]]) + + setErr({ error, dataOfError: dataOfError as StateZodErr['dataOfError'] }); return onOpen(); } + console.log(result.data) + insertManyMutation.mutate(result.data); }); }; @@ -196,9 +202,11 @@ const HalamanTambah = () => { - {errors?.map((error, idx) => ( + {errors?.error.map((error, idx) => ( - Kolom {error.path[1]} baris ke {(error.path[0] as number) + 1} + {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */} + {/** @ts-ignore */} + Kolom {error.path[1]} data {JSON.stringify(errors.dataOfError[idx][error.path[1]])} . {error.message} ))} diff --git a/packages/config/schema/admin.participant.schema.ts b/packages/config/schema/admin.participant.schema.ts index 1f784368..11a8cd02 100644 --- a/packages/config/schema/admin.participant.schema.ts +++ b/packages/config/schema/admin.participant.schema.ts @@ -5,7 +5,7 @@ import { validateId } from "@sora/id-generator"; const baseNameSchema = z .string() .min(1, { message: "Diperlukan nama peserta!" }) - .regex(/^[a-zA-Z0-9.,'\s]+$/, { + .regex(/^[a-zA-Z0-9.,'\s`-]+$/, { message: "Hanya diperbolehkan menulis alfabet, angka, koma, petik satu, dan titik!", });