하수재이용 시설 등록 메시지 표출
This commit is contained in:
@@ -14,7 +14,7 @@ import { useWrStore } from "../../../store";
|
||||
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@common/components";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import ListDiv from "@common/business_components/ui/list_div";
|
||||
import { tableData } from "@/components/lib/func/commom";
|
||||
import { confirmToast, tableData } from "@/components/lib/func/commom";
|
||||
import type {
|
||||
customPbnst,
|
||||
fcBizType,
|
||||
@@ -34,6 +34,7 @@ import { useFieldArray, useForm, type FieldErrors } from "react-hook-form"; // F
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
import { createDefaultPbnstItem } from "./utilsZod";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export default function PublicReuseFaciltyInsert() {
|
||||
const {
|
||||
@@ -46,7 +47,8 @@ export default function PublicReuseFaciltyInsert() {
|
||||
pubHasuSearch,
|
||||
pbnstRuseBizUpdate,
|
||||
} = useWrStore((state) => state);
|
||||
const { pubFacHeadList, pbnstHasuResCount,pbnstHasuRes, pbnstRes } = pbnst;
|
||||
const { t } = useTranslation("base");
|
||||
const { pubFacHeadList, pbnstHasuResCount, pbnstHasuRes, pbnstRes } = pbnst;
|
||||
const [, setCurrentTab] = useState<string>("mng");
|
||||
const [isRuseReg, setIsRuseReg] = useState<{
|
||||
isModal: boolean;
|
||||
@@ -108,28 +110,31 @@ export default function PublicReuseFaciltyInsert() {
|
||||
};
|
||||
});
|
||||
|
||||
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 = "하수재이용 시설 ";
|
||||
const handleConfirm = async () => {
|
||||
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");
|
||||
}
|
||||
if (!isBizSuccess) {
|
||||
message += "하수재이용 시설 사업 ";
|
||||
}
|
||||
toast.error(message + "오류 입니다 ");
|
||||
pubHasuInit("1", "41");
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
confirmToast(t("isUpdatetMsg"), handleConfirm);
|
||||
};
|
||||
|
||||
// 폼 유효성 검사 실패 시 호출될 함수
|
||||
@@ -230,7 +235,6 @@ export default function PublicReuseFaciltyInsert() {
|
||||
useEffect(() => {
|
||||
if (pbnst.pbnstRes && pbnst.pbnstRes?.length > 0) {
|
||||
form.reset({ items: pbnst.pbnstRes });
|
||||
|
||||
} else {
|
||||
form.reset({ items: [] });
|
||||
}
|
||||
@@ -238,14 +242,16 @@ export default function PublicReuseFaciltyInsert() {
|
||||
|
||||
const appendPbnstRuseFclt = useCallback(() => {
|
||||
if (pbnstRes && pbnstRes.length > 0) {
|
||||
if (selectRow) { // pbnstRes.length를 사용하여 새로운 항목의 인덱스를 결정
|
||||
append(createDefaultPbnstItem(selectRow, pbnstRes.length));
|
||||
if (selectRow) {
|
||||
// pbnstRes.length를 사용하여 새로운 항목의 인덱스를 결정
|
||||
append(createDefaultPbnstItem(selectRow, pbnstRes.length));
|
||||
setIsRuseReg({ isModal: true });
|
||||
}
|
||||
} else {
|
||||
if (selectRow) { // pbnstRes가 비어있으면 첫 항목이므로 인덱스 0
|
||||
if (selectRow) {
|
||||
// pbnstRes가 비어있으면 첫 항목이므로 인덱스 0
|
||||
|
||||
append(createDefaultPbnstItem(selectRow, 0));
|
||||
append(createDefaultPbnstItem(selectRow, 0));
|
||||
setIsRuseReg({ isModal: true });
|
||||
}
|
||||
}
|
||||
@@ -277,14 +283,12 @@ export default function PublicReuseFaciltyInsert() {
|
||||
className=""
|
||||
size={"sm"}
|
||||
onClick={() => {
|
||||
if(searchTxt && searchTxt?.length > 0) {
|
||||
pubHasuSearch(String(pageNation), "41", searchTxt)
|
||||
|
||||
}else{
|
||||
pubHasuInit(String(pageNation), "41");
|
||||
}
|
||||
isResetPage(true);
|
||||
|
||||
if (searchTxt && searchTxt?.length > 0) {
|
||||
pubHasuSearch(String(pageNation), "41", searchTxt);
|
||||
} else {
|
||||
pubHasuInit(String(pageNation), "41");
|
||||
}
|
||||
isResetPage(true);
|
||||
}}
|
||||
>
|
||||
조회
|
||||
@@ -322,7 +326,7 @@ export default function PublicReuseFaciltyInsert() {
|
||||
tableData={bdstTable || []}
|
||||
headlist={pubFacHeadList}
|
||||
pageSize={10}
|
||||
total={pbnstHasuResCount||20}
|
||||
total={pbnstHasuResCount || 20}
|
||||
headName={"공공 하수처리시설 목록"}
|
||||
cellClick={cellClick}
|
||||
onPageChange={setPageNation}
|
||||
|
||||
@@ -73,10 +73,6 @@ export default function Home() {
|
||||
|
||||
};
|
||||
|
||||
// const bdstChgModal = (chgBuilding: chgBuilding[]) => {
|
||||
// setBdstChgProps({ isOpen: true, chgBuilding: chgBuilding });
|
||||
// };
|
||||
|
||||
useEffect(() => {
|
||||
getRainData(pageNation, "41");
|
||||
}, [pageNation]);
|
||||
|
||||
@@ -15,42 +15,42 @@ import {
|
||||
} from "@common/components/ui";
|
||||
import { useEffect, useState } from "react";
|
||||
import { PbnstBuseForm } from "@/components/ui/form/fcltReg/pbnstReg/buseReg/bugRegForm";
|
||||
import {
|
||||
type FieldErrors,
|
||||
type UseFormReturn,
|
||||
} from "react-hook-form";
|
||||
import { type FieldErrors, type UseFormReturn } from "react-hook-form";
|
||||
import { writeRgtrAndMdfr } from "@/app/store/ruseFcltMng/fcltReg/pbnstReg";
|
||||
import type { z } from "zod";
|
||||
import { confirmToast } from "@/components/lib/func/commom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export function PbnstRegModal({
|
||||
form,
|
||||
setPbnstInsert,
|
||||
onInvalid
|
||||
onInvalid,
|
||||
}: {
|
||||
form: UseFormReturn<{ items: PbnstRegArrrayType }>;
|
||||
setPbnstInsert: (data: customPbnst) => void;
|
||||
onInvalid:(errors: FieldErrors<{ items: z.infer<typeof pbnstRegZod>[] }>) => void
|
||||
onInvalid: (
|
||||
errors: FieldErrors<{ items: z.infer<typeof pbnstRegZod>[] }>
|
||||
) => void;
|
||||
}) {
|
||||
|
||||
// const [pbnstBdstForm, setPbnstBdstForm] = useState<customPbnst>(
|
||||
// {} as customPbnst
|
||||
// );
|
||||
const { t } = useTranslation("base");
|
||||
|
||||
//TODO: 유즈 스테이트에 set만해도 되나?
|
||||
const [, setCurrentTab] = useState<string>("mng");
|
||||
//const setCurrentTab = "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]) : [];
|
||||
//
|
||||
const handleConfirm = () => {
|
||||
if (data && data[0]) {
|
||||
setPbnstInsert(data[0]);
|
||||
}
|
||||
};
|
||||
confirmToast(t("isInsertMsg"), handleConfirm);
|
||||
};
|
||||
|
||||
const onSubmit = async (valuse: { items: PbnstRegArrrayType }) => {
|
||||
const item = valuse.items[indexMng];
|
||||
const data = item ? writeRgtrAndMdfr([item]) : [];
|
||||
if (data && data[0]) {
|
||||
setPbnstInsert(data[0]);
|
||||
}
|
||||
};
|
||||
|
||||
const handleTabChange = (value: string) => {
|
||||
setCurrentTab(value);
|
||||
};
|
||||
@@ -60,7 +60,6 @@ export function PbnstRegModal({
|
||||
}, [form.formState.errors]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
const firstForm = form.getValues("items");
|
||||
if (firstForm) {
|
||||
setIndexMng(firstForm.length - 1);
|
||||
@@ -94,7 +93,6 @@ export function PbnstRegModal({
|
||||
<PbnstMngForm
|
||||
form={form}
|
||||
formType={"reg"}
|
||||
// firstFcltData={pbnstBdstForm}
|
||||
indexMng={indexMng}
|
||||
setIndexMng={setIndexMng}
|
||||
/>
|
||||
@@ -106,7 +104,6 @@ export function PbnstRegModal({
|
||||
indexBiz={indexBiz}
|
||||
setIndexBiz={setIndexBiz}
|
||||
formType={"reg"}
|
||||
// firstBizData={pbnstBdstForm.fcBizs}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
|
||||
Reference in New Issue
Block a user