diff --git a/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx b/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx index 768f8a66d..e95c4c48d 100644 --- a/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx +++ b/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx @@ -98,6 +98,7 @@ type rainFacSActions = { rainSearch: (txt: string, pageNation: number, code: string) => void; rainBdstReg: (data: customRainBdst, code: string | number,myUUID:string) => void; rainBdstUpdate: (data: customRainBdst, code: string | number,myUUID:string) => void; + rainBdstDelete: (data: customRainBdst, code: string | number) => void; resetRainTableIndex:(index:number)=>void; }; @@ -267,6 +268,28 @@ export const rainFacActionsExport: (set: any) => rainFacSActions = ( } finally { } }, + // 빗물 이용시설을 삭제한다. + rainBdstDelete: async (data: customRainBdst, code: string | number) => { + try { + await deleteFectch(`/reuseFc/rainyInfo/${data.reuseBuilding?.[0]?.bdstRuseFcltSn}`); + toast.success(`${data.bdstNm} 시설이 삭제되었습니다.`); + + const rainRes = await initFetch(code); + set((state: rainFacState) => ({ + ...state, + rain: { + ...state.rain, + rainRes: rainRes.data, + rainResCount: rainRes.count, + }, + })); + } catch (e) { + console.log("e", e); + const errorMessage = e instanceof Error ? e.message : "삭제 중 오류가 발생했습니다."; + toast.error(errorMessage); + } finally { + } + }, resetRainTableIndex: (index: number) => { // 1) 동일값도 '변경'으로 느끼게 잠깐 -1 set((state: rainFacState) => ({ diff --git a/apps/wr/components/lib/api/index.ts b/apps/wr/components/lib/api/index.ts index 162ae9de3..6ff75f5a6 100644 --- a/apps/wr/components/lib/api/index.ts +++ b/apps/wr/components/lib/api/index.ts @@ -167,7 +167,18 @@ export const deleteFectch = async ( body: params ? JSON.stringify(params) : undefined, }); if (!response.ok) { - throw new Error(`오류 발생: ${response.status}`); + // 에러 응답 본문 파싱 + const errorText = await response.text(); + let errorMessage = `오류 발생: ${response.status}`; + + try { + const errorJson = JSON.parse(errorText); + errorMessage = errorJson.message || errorMessage; + } catch { + errorMessage = errorText || errorMessage; + } + + throw new Error(errorMessage); } return await response.text(); }; diff --git a/apps/wr/components/ui/form/fcltReg/rainReg/rainRegForm.tsx b/apps/wr/components/ui/form/fcltReg/rainReg/rainRegForm.tsx index c18a1d4fd..f2a9d2f6d 100644 --- a/apps/wr/components/ui/form/fcltReg/rainReg/rainRegForm.tsx +++ b/apps/wr/components/ui/form/fcltReg/rainReg/rainRegForm.tsx @@ -38,7 +38,7 @@ export default function RainRegForm({ readonly?: boolean; isMap?: boolean; }) { - const { auth,code, rainBdstReg, rainBdstUpdate ,resetRainTableIndex, getMyUUID} = useWrStore( + const { auth,code, rainBdstReg, rainBdstUpdate, rainBdstDelete, resetRainTableIndex, getMyUUID} = useWrStore( (state) => state ); const { rainFcltCd } = code; @@ -159,6 +159,11 @@ export default function RainRegForm({ } }; + const onDelete = async () => { + const code = rainForm.ctpvCd ? rainForm.ctpvCd : rainForm.sggCd ? rainForm.sggCd : "noCd"; + confirmToast(`정말 ${rainForm.bdstNm} 시설을 삭제하시겠습니까?`, () => rainBdstDelete(rainForm, code)); + } + useEffect(() => { if (rainZod) form.reset(cleanRainData(rainForm)); }, [rainForm]); @@ -176,13 +181,23 @@ export default function RainRegForm({ {isModal ? "건축물 정보" : "빗물이용시설 정보"} {!readonly && ( - +