From ad7b78688f79da1cc4ba77990ef7620f5caf8648 Mon Sep 17 00:00:00 2001 From: leedj312 Date: Sun, 6 Jul 2025 16:34:47 +0900 Subject: [PATCH] =?UTF-8?q?[=ED=95=98=EC=88=98=EC=9E=AC=EC=9D=B4=EC=9A=A9?= =?UTF-8?q?=EC=8B=9C=EC=84=A4=20=EB=93=B1=EB=A1=9D=20=EC=88=98=EC=A0=95]?= =?UTF-8?q?=20onVild=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=EB=A1=9C=20?= =?UTF-8?q?=EB=AA=A8=EB=8B=AC=EC=97=90=EA=B2=8C=20=EB=84=98=EA=B2=A8?= =?UTF-8?q?=EC=A3=BC=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ruseFcltMng/fcltReg/pbnstReg/page.tsx | 8 +- .../ruseFcltMng/fcltReg/pbnstReg/type.tsx | 2 +- .../fcltReg/pbnstRegModal/pbnstRegModal.tsx | 104 +++++++++--------- 3 files changed, 57 insertions(+), 57 deletions(-) diff --git a/apps/wr/app/ruseFcltMng/fcltReg/pbnstReg/page.tsx b/apps/wr/app/ruseFcltMng/fcltReg/pbnstReg/page.tsx index 0c3ad9dce..9f243627c 100644 --- a/apps/wr/app/ruseFcltMng/fcltReg/pbnstReg/page.tsx +++ b/apps/wr/app/ruseFcltMng/fcltReg/pbnstReg/page.tsx @@ -200,14 +200,10 @@ export default function PublicReuseFaciltyInsert() { useEffect(() => { if (pbnst.pbnstRes && pbnst.pbnstRes?.length > 0) { - // form.reset({ - // items: pbnstRegArrayZod.parse(pbnst.pbnstRes), - // }); + form.reset({ items: pbnst.pbnstRes }); - //form.reset({ items: pbnst.pbnstRes }); - } else { form.reset({ items: [] }); } @@ -425,6 +421,8 @@ export default function PublicReuseFaciltyInsert() { setIsRuseReg({ isModal: false }); } }} + + onInvalid ={onInvalid} > } bodyClass="w-[68vw] max-w-none h-[90vh]" diff --git a/apps/wr/app/store/ruseFcltMng/fcltReg/pbnstReg/type.tsx b/apps/wr/app/store/ruseFcltMng/fcltReg/pbnstReg/type.tsx index 2ef1c6d2f..ad3496a54 100644 --- a/apps/wr/app/store/ruseFcltMng/fcltReg/pbnstReg/type.tsx +++ b/apps/wr/app/store/ruseFcltMng/fcltReg/pbnstReg/type.tsx @@ -163,7 +163,7 @@ export const fcBizSchema = z.object({ etc: z.string().default(""), totalMoney: zNumNullish.default(0), rprcsFcltCpct: zNumDefaultZero, - majorPrcsMsrcCd: z.string().default(""), + majorPrcsMsrcCd: z.string().nullish(), addr: z.string().default(""), rprcsMthdCd: z.string().default(""), inoutYn: z.enum(["Y", "N"]).default("Y"), diff --git a/apps/wr/components/ui/modal/fcltReg/pbnstRegModal/pbnstRegModal.tsx b/apps/wr/components/ui/modal/fcltReg/pbnstRegModal/pbnstRegModal.tsx index 34bc71a46..846e427c6 100644 --- a/apps/wr/components/ui/modal/fcltReg/pbnstRegModal/pbnstRegModal.tsx +++ b/apps/wr/components/ui/modal/fcltReg/pbnstRegModal/pbnstRegModal.tsx @@ -29,9 +29,11 @@ import type { z } from "zod"; export function PbnstRegModal({ form, setPbnstInsert, + onInvalid }: { form: UseFormReturn<{ items: PbnstRegArrrayType }>; setPbnstInsert: (data: customPbnst) => void; + onInvalid:(errors: FieldErrors<{ items: z.infer[] }>) => void }) { const { pbnstInsert } = useWrStore((state) => { return state; @@ -51,69 +53,69 @@ export function PbnstRegModal({ setPbnstInsert(data[0]); } }; - const onInvalid = ( - errors: FieldErrors<{ items: z.infer[] }> - ) => { - // 재귀 함수를 사용해 중첩된 에러 객체에서 모든 에러 메시지와 경로를 찾습니다. + // const onInvalid = ( + // errors: FieldErrors<{ items: z.infer[] }> + // ) => { + // // 재귀 함수를 사용해 중첩된 에러 객체에서 모든 에러 메시지와 경로를 찾습니다. - const findAllErrors = ( - errorObject: any, - path: (string | number)[] = [] - ): { message: string; path: (string | number)[] }[] => { - if (!errorObject) return []; + // const findAllErrors = ( + // errorObject: any, + // path: (string | number)[] = [] + // ): { message: string; path: (string | number)[] }[] => { + // if (!errorObject) return []; - return Object.keys(errorObject).flatMap((key) => { - const value = errorObject[key]; - const currentKey = !isNaN(parseInt(key)) ? parseInt(key) : key; - const newPath = [...path, currentKey]; - if (value && typeof value === "object") { - if (typeof value.message === "string") { - return [{ message: value.message, path: newPath }]; // 에러 메시지와 경로 반환 - } - return findAllErrors(value, newPath); - } - return []; - }); - }; + // return Object.keys(errorObject).flatMap((key) => { + // const value = errorObject[key]; + // const currentKey = !isNaN(parseInt(key)) ? parseInt(key) : key; + // const newPath = [...path, currentKey]; + // if (value && typeof value === "object") { + // if (typeof value.message === "string") { + // return [{ message: value.message, path: newPath }]; // 에러 메시지와 경로 반환 + // } + // return findAllErrors(value, newPath); + // } + // return []; + // }); + // }; - const errorList = findAllErrors(errors); + // const errorList = findAllErrors(errors); - if (errorList.length > 0) { - errorList.forEach((errorInfo) => { - const { message, path } = errorInfo; - let prefix = ""; - const itemsIndex = path.indexOf("items"); + // if (errorList.length > 0) { + // errorList.forEach((errorInfo) => { + // const { message, path } = errorInfo; + // let prefix = ""; + // const itemsIndex = path.indexOf("items"); - if (itemsIndex > -1 && path.length > itemsIndex + 1) { - const itemIdx = path[itemsIndex + 1] as number; - const facilityName = form.getValues( - `items.${itemIdx}.ruseUtztnFcltNm` - ); - if (facilityName) { - prefix += `[${facilityName}] `; - } + // if (itemsIndex > -1 && path.length > itemsIndex + 1) { + // const itemIdx = path[itemsIndex + 1] as number; + // const facilityName = form.getValues( + // `items.${itemIdx}.ruseUtztnFcltNm` + // ); + // if (facilityName) { + // prefix += `[${facilityName}] `; + // } - const fcBizsIndex = path.indexOf("fcBizs"); - if (fcBizsIndex > -1 && path.length > fcBizsIndex + 1) { - const bizIdx = path[fcBizsIndex + 1] as number; - const cycle = form.getValues( - `items.${itemIdx}.fcBizs.${bizIdx}.cycl` - ); - if (cycle) { - prefix += `[${cycle}차수] `; - } - } - } + // const fcBizsIndex = path.indexOf("fcBizs"); + // if (fcBizsIndex > -1 && path.length > fcBizsIndex + 1) { + // const bizIdx = path[fcBizsIndex + 1] as number; + // const cycle = form.getValues( + // `items.${itemIdx}.fcBizs.${bizIdx}.cycl` + // ); + // if (cycle) { + // prefix += `[${cycle}차수] `; + // } + // } + // } - toast.error(`${prefix}${message}`); - }); - } - }; + // toast.error(`${prefix}${message}`); + // }); + // } + // }; const handleTabChange = (value: string) => { setCurrentTab(value);