feat: 빗물이용시설 삭제 버튼 구현
This commit is contained in:
@@ -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) => ({
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
@@ -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 ? "건축물 정보" : "빗물이용시설 정보"}
|
||||
</h1>
|
||||
{!readonly && (
|
||||
<Button
|
||||
type="submit"
|
||||
className="col-start-12 col-span-1"
|
||||
size={"sm"}
|
||||
>
|
||||
저장
|
||||
</Button>
|
||||
<div className="flex justify-end gap-2 mt-4">
|
||||
<Button
|
||||
type="submit"
|
||||
className="col-start-12 col-span-1"
|
||||
size={"sm"}
|
||||
>
|
||||
저장
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
className="!bg-red-500 text-white"
|
||||
size={"sm"}
|
||||
onClick={onDelete}
|
||||
>
|
||||
삭제
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user