@@ -42,6 +42,8 @@ export function PbnstRegModal({
|
||||
const [currentTab, setCurrentTab] = useState<string>("mng");
|
||||
const [indexMng, setIndexMng] = useState<number>(0);
|
||||
const [indexBiz, setIndexBiz] = useState<number>(0);
|
||||
|
||||
|
||||
const onSubmit = async (valuse: { items: PbnstRegArrrayType }) => {
|
||||
const item = valuse.items[indexMng];
|
||||
const data = item ? writeRgtrAndMdfr([item]) : [];
|
||||
@@ -53,6 +55,8 @@ export function PbnstRegModal({
|
||||
errors: FieldErrors<{ items: z.infer<typeof pbnstRegZod>[] }>
|
||||
) => {
|
||||
// 재귀 함수를 사용해 중첩된 에러 객체에서 모든 에러 메시지와 경로를 찾습니다.
|
||||
|
||||
|
||||
const findAllErrors = (
|
||||
errorObject: any,
|
||||
path: (string | number)[] = []
|
||||
@@ -72,13 +76,18 @@ export function PbnstRegModal({
|
||||
return [];
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const errorList = findAllErrors(errors);
|
||||
|
||||
|
||||
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(
|
||||
@@ -99,6 +108,8 @@ export function PbnstRegModal({
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
toast.error(`${prefix}${message}`);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user