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);