Skip to content

Commit

Permalink
fix: data baru
Browse files Browse the repository at this point in the history
  • Loading branch information
reacto11mecha committed Oct 14, 2023
1 parent 0ece121 commit 862e2aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions apps/web/src/pages/peserta/csv.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
import { api } from "~/utils/api";
import Sidebar from "~/components/Sidebar";

type StateZodErr = Array<{ message: string; path: Array<number | string> }>;
type StateZodErr = { error: Array<{ message: string; path: Array<number | string> }>; dataOfError: Array<{ "Bagian Dari": string; Nama: string }> };

const HalamanTambah = () => {
const toast = useToast();
Expand Down Expand Up @@ -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);
});
};
Expand Down Expand Up @@ -196,9 +202,11 @@ const HalamanTambah = () => {
</Text>

<UnorderedList>
{errors?.map((error, idx) => (
{errors?.error.map((error, idx) => (
<ListItem key={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}
</ListItem>
))}
Expand Down
2 changes: 1 addition & 1 deletion packages/config/schema/admin.participant.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
});
Expand Down

0 comments on commit 862e2aa

Please sign in to comment.