From 5ec33d01653870a5f435b7a6989ba36dc1f29087 Mon Sep 17 00:00:00 2001 From: leedj312 Date: Mon, 7 Jul 2025 20:31:35 +0900 Subject: [PATCH] =?UTF-8?q?=EC=88=98=EC=9A=94=EC=B2=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B3=80=EA=B2=BD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ruseFcltMng/fcltReg/pbnstReg/page.tsx | 38 +++++++++-- apps/wr/app/store/common/searchCode/index.ts | 40 ++++++++---- .../ruseFcltMng/fcltReg/pbnstReg/index.tsx | 65 ++++++++----------- .../fcltReg/pbnstReg/buseReg/bugRegForm.tsx | 6 +- 4 files changed, 89 insertions(+), 60 deletions(-) diff --git a/apps/wr/app/ruseFcltMng/fcltReg/pbnstReg/page.tsx b/apps/wr/app/ruseFcltMng/fcltReg/pbnstReg/page.tsx index 9f243627c..ab8df5d8f 100644 --- a/apps/wr/app/ruseFcltMng/fcltReg/pbnstReg/page.tsx +++ b/apps/wr/app/ruseFcltMng/fcltReg/pbnstReg/page.tsx @@ -110,9 +110,37 @@ export default function PublicReuseFaciltyInsert() { fcOpers: fclt.fcOpers, }; }); - await pbnstRuseFcltUpdate(pbnst as customPbnst[]) - await pbnstRuseBizUpdate(bizs); + + Promise.allSettled([ + pbnstRuseFcltUpdate(pbnst as customPbnst[]), + pbnstRuseBizUpdate(bizs) + ]).then(([resFclt, resBiz]) => { + const isFcltSuccess = resFclt.status === "fulfilled"; + const isBizSuccess = resBiz.status === "fulfilled"; + + if (isFcltSuccess && isBizSuccess) { + toast.success('하수 재이용 시설 및 사업이 수정되었습니다. ') + // 메시지 표시, 페이지 이동 등 + } else { + + let message ='' + // ✅ 각각 어떤 항목이 실패했는지도 로그/알림 처리 + if (!isFcltSuccess) { + message = '하수재이용 시설 ' + } + if (!isBizSuccess) { + message += '하수재이용 시설 사업 ' + } + + toast.error(message+'오류 입니다 ') + pubHasuInit("1", "41"); + } + + + }); + + }; // 폼 유효성 검사 실패 시 호출될 함수 @@ -199,9 +227,6 @@ export default function PublicReuseFaciltyInsert() { useEffect(() => { if (pbnst.pbnstRes && pbnst.pbnstRes?.length > 0) { - - - form.reset({ items: pbnst.pbnstRes }); } else { @@ -214,6 +239,9 @@ export default function PublicReuseFaciltyInsert() { } }, [indexMng]); + + + useEffect(() => { console.log("form errors:", form.formState.errors); }, [form.formState.errors]); diff --git a/apps/wr/app/store/common/searchCode/index.ts b/apps/wr/app/store/common/searchCode/index.ts index 656bc33d9..4e383b4a4 100644 --- a/apps/wr/app/store/common/searchCode/index.ts +++ b/apps/wr/app/store/common/searchCode/index.ts @@ -7,12 +7,12 @@ import { import type { pubHasuType } from "../../ruseFcltMng/fcltReg/pbnstReg/type"; import type { DemandCompType } from "@common/business_components/ui/sdmInsertForm/form"; import type { conCostFeeType, rateFeeType } from "./type"; +import toast from "react-hot-toast"; export const comFcltStateExport: comFcltState = { searchFclts: [] as pubHasuType[], demandCompList: [], - dmdIsSucees: '', checkDemand: { index: 0, dmdInfoPk: "", @@ -52,7 +52,6 @@ export type comFcltType = comFcltState & comFcltActions; export type comFcltState = { searchFclts: pubHasuType[]; demandCompList: DemandCompType[]; - dmdIsSucees: string; checkDemand: DemandCompType; constCostRes:conCostFeeType[], rateFeeRes:rateFeeType[], @@ -110,19 +109,20 @@ export const comFcltSearchAction: (set: any) => comFcltActions = (set: any) => { data, fetchType.WR ); - let message = ""; if (response.status === 200) { - message = "success"; - } else { - message = "fail"; + toast.success('수요처가 등록되었습니다. ') + set((state: comFcltState) => { + + return { + ...state, + dmdIsSucees: "success" + } + }); } - - - set((state: comFcltState) => { - return state.dmdIsSucees = message; - }); } catch (err) { console.log(err); + toast.error('수요처가 등록 오류입니다.. ') + } }, updateDemandCompany: async (data: DemandCompType) => { @@ -137,7 +137,10 @@ export const comFcltSearchAction: (set: any) => comFcltActions = (set: any) => { } set((state: comFcltState) => { - return state.dmdIsSucees = message; + return { + ...state, + dmdIsSucees: message + } }); } catch (err) { console.log(err); @@ -149,7 +152,11 @@ export const comFcltSearchAction: (set: any) => comFcltActions = (set: any) => { const rateFeeRes = await getFetch(fetchType.COMMON, url); set((state: comFcltState) => { - return state.rateFeeRes = rateFeeRes;; + + return { + ...state, + rateFeeRes: rateFeeRes + } }); } catch (e) { console.log(" error ", e); @@ -159,7 +166,12 @@ export const comFcltSearchAction: (set: any) => comFcltActions = (set: any) => { const url = `/prcsFclt/CstRuse/${year}`; const constCost = await getFetch(fetchType.COMMON, url); set((state: comFcltState) => { - return state.constCostRes = constCost;; + + return { + ...state, + constCostRes: constCost + } + }); }catch (e) { } diff --git a/apps/wr/app/store/ruseFcltMng/fcltReg/pbnstReg/index.tsx b/apps/wr/app/store/ruseFcltMng/fcltReg/pbnstReg/index.tsx index 66c8c4dc8..3057cec7f 100644 --- a/apps/wr/app/store/ruseFcltMng/fcltReg/pbnstReg/index.tsx +++ b/apps/wr/app/store/ruseFcltMng/fcltReg/pbnstReg/index.tsx @@ -60,14 +60,11 @@ export type pubFacState = { type pubFacActions = { pubHasuInit: (page: string, sggOrCity: string) => void; pbnstRegClick: (pubHasuRes: pubHasuType) => void; - pbnstReg: (txt: string | undefined) => void; + //pbnstReg: (txt: string | undefined) => void; pbnstInsert(pbnstRes: customPbnst): Promise; appendRuseFclt(array: customPbnst[]): void; fileDelete: (atflCd: string) => void; fileDownLoad: (atflCd: string) => void; - //pbnstMngData: (data: customPbnst[]) => void; - //pbnstBizData(data: fcBizType): void; - // getBizCycle: (pbnstObj: customPbnst) => void; getpbnstInsertIndex: (data: pbnstInsertIndex) => void; pbnstRuseFcltUpdate: (ruseRes: customPbnst[]) => void; pbnstRuseBizUpdate: (ruseRes: fcBizType[]) => void; @@ -226,21 +223,21 @@ export const pubFacActionsExport: (set: any) => pubFacActions = (set: any) => { } }, - pbnstReg: async (txt: string | undefined) => { - try { - const pbnstRes = await hasuListFetch("11", "11"); - return set((state: pubFacState) => ({ - ...state, - pbnst: { - ...state.pbnst, - pbnstRes: pbnstRes, - isInit: false, - }, - })); - } catch (errorHasu) { - console.log(errorHasu); - } - }, + // pbnstReg: async (txt: string | undefined) => { + // try { + // const pbnstRes = await hasuListFetch("11", "11"); + // return set((state: pubFacState) => ({ + // ...state, + // pbnst: { + // ...state.pbnst, + // pbnstRes: pbnstRes, + // isInit: false, + // }, + // })); + // } catch (errorHasu) { + // console.log(errorHasu); + // } + // }, pbnstInsert: async (pbnstRes: customPbnst) => { try { @@ -272,14 +269,9 @@ export const pubFacActionsExport: (set: any) => pubFacActions = (set: any) => { `/reuseFc/pubFc`, ruseRes ); - - if(response){ - - toast.success(` 하수재이용 시설 정보가 수정되었습니다.`); - } + } catch (error) { console.error("Error pbnstRuseFcltUpdate:", error); - toast.error(` 하수재이용 시설 정보가 수정오류입니다.`); } } ,pbnstRuseBizUpdate : async(ruseRes:fcBizType[])=>{ try { @@ -290,22 +282,19 @@ export const pubFacActionsExport: (set: any) => pubFacActions = (set: any) => { ruseRes ); - if(response){ - toast.success(` 하수재이용 시설 사업이 수정되었습니다.`); - } - const pbnstRes = await hasuListFetch("11", "11"); + // const pbnstRes = await hasuListFetch("11", "11"); - return set((state: pubFacState) => ({ - ...state, - pbnst: { - ...state.pbnst, - pbnstRes: pbnstRes, - isInit: false, - }, - })); + // return set((state: pubFacState) => ({ + // ...state, + // pbnst: { + // ...state.pbnst, + // pbnstRes: pbnstRes, + // isInit: false, + // }, + // })); } catch (error) { console.error("Error pbnstRuseFcltUpdate:", error); - toast.error(` 하수재이용 시설 사업이 수정이 실패되엇습니다..`); + // toast.error(` 하수재이용 시설 사업이 수정이 실패되엇습니다..`); } } , getBizCycle: async (pbnstObj: customPbnst) => { diff --git a/apps/wr/components/ui/form/fcltReg/pbnstReg/buseReg/bugRegForm.tsx b/apps/wr/components/ui/form/fcltReg/pbnstReg/buseReg/bugRegForm.tsx index 4d4ad91d8..2a2e9defe 100644 --- a/apps/wr/components/ui/form/fcltReg/pbnstReg/buseReg/bugRegForm.tsx +++ b/apps/wr/components/ui/form/fcltReg/pbnstReg/buseReg/bugRegForm.tsx @@ -134,7 +134,6 @@ export function PbnstBuseForm({ (orgwt) => orgwt.bscFctCd === item.swtrmtFcltFk )?.bscFctNm; - console.log("orgwtNm ", orgwtNm); if (orgwtNm) { form.setValue( `items.${indexMng}.fcBizs.${indexBiz}.fcOrgwts.${index}.ruseUtztnFcltNm`, @@ -205,8 +204,6 @@ export function PbnstBuseForm({ prevDemandsLengthRef.current = fcDemands.length; }, [fcDemands.length]); - const fcOrgwtWatch = form.watch( `items.${indexMng}.fcBizs.${indexBiz}.fcOrgwts`) - const pplInstlsWatch = form.watch( `items.${indexMng}.fcBizs.${indexBiz}.pplInstls`) const { fields: fcOrgwtFiled } = useFieldArray({ control: form.control, @@ -319,6 +316,9 @@ useEffect(() =>{ }, [form.formState]); const pbnstBiz = form.watch(`items.${indexMng}.fcBizs`); + + + return ( <> {pbnstBiz && pbnstBiz?.length > 0 ? (