Merge commit '1493d0c6968e38d5945bc2bef76f59d2495c2da9' into iipbs/wr/dev
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
import {
|
||||
ContentsDiv,
|
||||
DateMonthPicker,
|
||||
ScrollArea,
|
||||
SearchDiv,
|
||||
SearchFormLeft,
|
||||
@@ -31,7 +32,7 @@ import { PbnstBuseForm } from "@/components/ui/form/fcltReg/pbnstReg/buseReg/bug
|
||||
import { PbnstRegModal } from "@/components/ui/modal/fcltReg/pbnstRegModal/pbnstRegModal";
|
||||
import toast, { Toaster } from "react-hot-toast"; // toast 이미 import 되어 있음
|
||||
import { writeRgtrAndMdfr } from "@/app/store/ruseFcltMng/fcltReg/pbnstReg";
|
||||
import { useFieldArray, useForm, type FieldErrors } from "react-hook-form"; // FieldErrors 타입 추가
|
||||
import { set, useFieldArray, useForm, type FieldErrors } from "react-hook-form"; // FieldErrors 타입 추가
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -41,6 +42,7 @@ export default function PublicReuseFaciltyInsert() {
|
||||
pbnst,
|
||||
searchFclts,
|
||||
pubHasuInit,
|
||||
pbnstInsert,
|
||||
pbnstRegClick,
|
||||
pbnstRuseFcltUpdate,
|
||||
pubHasuSearch,
|
||||
@@ -50,8 +52,7 @@ export default function PublicReuseFaciltyInsert() {
|
||||
const [currentTab, setCurrentTab] = useState<string>("mng");
|
||||
const [isRuseReg, setIsRuseReg] = useState<{
|
||||
isModal: boolean;
|
||||
data: pubHasuType;
|
||||
}>({ isModal: false, data: {} as pubHasuType });
|
||||
}>({ isModal: false });
|
||||
|
||||
const [indexMng, setIndexMng] = useState<number>(0);
|
||||
const [indexBiz, setIndexBiz] = useState<number>(0);
|
||||
@@ -60,7 +61,6 @@ export default function PublicReuseFaciltyInsert() {
|
||||
const [selectRow, setSelectRow] = useState<pubHasuType>();
|
||||
const [pageNation, setPageNation] = useState<number>(1);
|
||||
|
||||
|
||||
const form = useForm<{
|
||||
items: z.infer<typeof pbnstRegZod>[];
|
||||
}>({
|
||||
@@ -88,30 +88,32 @@ export default function PublicReuseFaciltyInsert() {
|
||||
data.forEach((fclt) => {
|
||||
bizs = [...bizs, ...fclt.fcBizs];
|
||||
});
|
||||
const pbnst =data.map((fclt) => {
|
||||
return({
|
||||
pbnstRuseFcltPk: fclt.pbnstRuseFcltPk,
|
||||
fcltCpct: fclt.fcltCpct,
|
||||
ruseCpct: fclt.ruseCpct,
|
||||
splyExtraCpct: fclt.splyExtraCpct,
|
||||
rgtr: fclt.rgtr,
|
||||
mdfr: fclt.mdfr,
|
||||
fcFiles: fclt.fcFiles,
|
||||
fcOpers: fclt.fcOpers,
|
||||
})
|
||||
})
|
||||
const pbnst = data.map((fclt) => {
|
||||
return {
|
||||
pbnstRuseFcltPk: fclt.pbnstRuseFcltPk,
|
||||
fcltCpct: fclt.fcltCpct,
|
||||
ruseCpct: fclt.ruseCpct,
|
||||
splyExtraCpct: fclt.splyExtraCpct,
|
||||
rgtr: fclt.rgtr,
|
||||
mdfr: fclt.mdfr,
|
||||
fcFiles: fclt.fcFiles,
|
||||
fcOpers: fclt.fcOpers,
|
||||
};
|
||||
});
|
||||
await pbnstRuseFcltUpdate(pbnst as customPbnst[]);
|
||||
|
||||
await pbnstRuseBizUpdate(bizs);
|
||||
};
|
||||
|
||||
// 폼 유효성 검사 실패 시 호출될 함수
|
||||
const onInvalid = (errors: FieldErrors<{ items: z.infer<typeof pbnstRegZod>[]; }>) => {
|
||||
const onInvalid = (
|
||||
errors: FieldErrors<{ items: z.infer<typeof pbnstRegZod>[] }>
|
||||
) => {
|
||||
// 재귀 함수를 사용해 중첩된 에러 객체에서 모든 에러 메시지와 경로를 찾습니다.
|
||||
const findAllErrors = (
|
||||
errorObject: any,
|
||||
path: (string | number)[] = []
|
||||
): { message: string; path: (string | number)[]; }[] => {
|
||||
): { message: string; path: (string | number)[] }[] => {
|
||||
if (!errorObject) return [];
|
||||
|
||||
return Object.keys(errorObject).flatMap((key) => {
|
||||
@@ -136,7 +138,9 @@ export default function PublicReuseFaciltyInsert() {
|
||||
|
||||
if (itemsIndex > -1 && path.length > itemsIndex + 1) {
|
||||
const itemIdx = path[itemsIndex + 1] as number;
|
||||
const facilityName = form.getValues(`items.${itemIdx}.ruseUtztnFcltNm`);
|
||||
const facilityName = form.getValues(
|
||||
`items.${itemIdx}.ruseUtztnFcltNm`
|
||||
);
|
||||
if (facilityName) {
|
||||
prefix += `[${facilityName}] `;
|
||||
}
|
||||
@@ -144,7 +148,9 @@ export default function PublicReuseFaciltyInsert() {
|
||||
const fcBizsIndex = path.indexOf("fcBizs");
|
||||
if (fcBizsIndex > -1 && path.length > fcBizsIndex + 1) {
|
||||
const bizIdx = path[fcBizsIndex + 1] as number;
|
||||
const cycle = form.getValues(`items.${itemIdx}.fcBizs.${bizIdx}.cycl`);
|
||||
const cycle = form.getValues(
|
||||
`items.${itemIdx}.fcBizs.${bizIdx}.cycl`
|
||||
);
|
||||
if (cycle) {
|
||||
prefix += `[${cycle}차수] `;
|
||||
}
|
||||
@@ -156,12 +162,18 @@ export default function PublicReuseFaciltyInsert() {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (code.sggCd.length) {
|
||||
if (searchFclts) {
|
||||
setbdstTable(tableData(searchFclts, { code }));
|
||||
} else if (code.sggCd.length > 0 && pbnstHasuRes.length > 0) {
|
||||
setbdstTable(tableData(pbnstHasuRes, { code }));
|
||||
}
|
||||
console.log("bdstTable ", bdstTable);
|
||||
}, [bdstTable]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
if (code.sggCd.length &&pbnstHasuRes.length > 0) {
|
||||
setbdstTable(tableData(pbnstHasuRes, { code }));
|
||||
// if (searchFclts) {
|
||||
// setbdstTable(tableData(searchFclts, { code }));
|
||||
// } else if (code.sggCd.length > 0 && pbnstHasuRes.length > 0) {
|
||||
// }
|
||||
}
|
||||
}, [code, pbnstHasuRes, searchFclts]);
|
||||
|
||||
@@ -179,11 +191,10 @@ export default function PublicReuseFaciltyInsert() {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (pbnst.pbnstRes&& pbnst.pbnstRes?.length>0) {
|
||||
if (pbnst.pbnstRes && pbnst.pbnstRes?.length > 0) {
|
||||
console.log("pbnst.pbnstRes", pbnstRes);
|
||||
form.reset({ items: pbnstRegArrayZod.parse(pbnst.pbnstRes) });
|
||||
}else{
|
||||
|
||||
} else {
|
||||
console.log("pbnst.pbnstRes is null", pbnstRes);
|
||||
form.reset({ items: [] });
|
||||
}
|
||||
@@ -200,11 +211,9 @@ export default function PublicReuseFaciltyInsert() {
|
||||
|
||||
const appendPbnstRuseFclt = useCallback(() => {
|
||||
const selecTableRow = selectRow;
|
||||
|
||||
if (pbnstRes && pbnstRes.length > 0) {
|
||||
const lastPbnst = pbnstRes[pbnstRes.length - 1];
|
||||
if (lastPbnst && selecTableRow) {
|
||||
|
||||
append(
|
||||
pbnstRegZod.parse({
|
||||
pbnstRuseFcltPk:
|
||||
@@ -220,32 +229,37 @@ export default function PublicReuseFaciltyInsert() {
|
||||
] as fcBizType[],
|
||||
})
|
||||
);
|
||||
setIsRuseReg({ ...isRuseReg, isModal: true });
|
||||
setIsRuseReg({ isModal: true });
|
||||
}
|
||||
} else {
|
||||
if (selecTableRow) {
|
||||
append(
|
||||
pbnstRegZod.parse({
|
||||
pbnstRuseFcltPk: String(selecTableRow.bscFctCd)+'1',
|
||||
ruseUtztnFcltNm: "",
|
||||
regDt: null,
|
||||
mdfcnDt: null,
|
||||
fcBizs: [fcBizSchema.parse({pbnstRuseFcltFk:String(selecTableRow.bscFctCd)+'1',cycl:1})] as fcBizType[],
|
||||
})
|
||||
)
|
||||
setIsRuseReg({ ...isRuseReg, isModal: true });
|
||||
pbnstRegZod.parse({
|
||||
pbnstRuseFcltPk: String(selecTableRow.bscFctCd) + "1",
|
||||
ruseUtztnFcltNm: "",
|
||||
regDt: null,
|
||||
mdfcnDt: null,
|
||||
fcBizs: [
|
||||
fcBizSchema.parse({
|
||||
pbnstRuseFcltFk: String(selecTableRow.bscFctCd) + "1",
|
||||
cycl: 1,
|
||||
}),
|
||||
] as fcBizType[],
|
||||
})
|
||||
);
|
||||
setIsRuseReg({ isModal: true });
|
||||
}
|
||||
}
|
||||
}, [pbnstRegZod, pbnstRes, append, selectRow, form]);
|
||||
|
||||
useEffect(() => {
|
||||
// console.log(" page getgetvaslue ", form.getValues());
|
||||
// console.log(" page getgetvaslue ", form.getValues());
|
||||
}, [form.getValues()]);
|
||||
|
||||
useEffect(() =>{
|
||||
pubHasuInit(String(pageNation), "41");
|
||||
},[pageNation,pubHasuInit])
|
||||
|
||||
useEffect(() => {
|
||||
pubHasuInit(String(pageNation), "41");
|
||||
}, [pageNation, pubHasuInit]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<ContentsDiv>
|
||||
@@ -278,7 +292,7 @@ useEffect(() =>{
|
||||
size={"sm"}
|
||||
className=""
|
||||
onClick={() => {
|
||||
// pbnstMngData([] as customPbnst[]);
|
||||
// pbnstMngData([] as customPbnst[]);
|
||||
if (!selectRow) {
|
||||
toast.error(
|
||||
"하수리시시설을 테이블을 선택하고 등록버튼을 눌러주세요"
|
||||
@@ -291,6 +305,7 @@ useEffect(() =>{
|
||||
>
|
||||
신규등록
|
||||
</Button>
|
||||
|
||||
</div>
|
||||
</SearchFormLeft>
|
||||
</SearchDiv>
|
||||
@@ -300,7 +315,9 @@ useEffect(() =>{
|
||||
<div className="grid grid-cols-6 gap-4 h-full">
|
||||
<div className="col-span-4 h-full min-h-0">
|
||||
<ListDiv className="min-h-0">
|
||||
<ScrollArea className="h-[60vh]"> {/* 높이 조정 */}
|
||||
<ScrollArea className="h-[60vh]">
|
||||
{" "}
|
||||
{/* 높이 조정 */}
|
||||
<UiTable
|
||||
tableData={bdstTable || []}
|
||||
headlist={pubFacHeadList}
|
||||
@@ -326,7 +343,7 @@ useEffect(() =>{
|
||||
</TabsTrigger>
|
||||
<Button
|
||||
size={"sm"}
|
||||
onClick={form.handleSubmit(onSubmit,onInvalid)}
|
||||
onClick={form.handleSubmit(onSubmit, onInvalid)}
|
||||
className="!justify-end" // 저장 버튼 위치 조정
|
||||
>
|
||||
저장
|
||||
@@ -361,14 +378,19 @@ useEffect(() =>{
|
||||
body={
|
||||
<PbnstRegModal
|
||||
form={form} // form prop 전달
|
||||
data={isRuseReg.data || ({} as customPbnst)}
|
||||
setPbnstInsert={(data) => {
|
||||
if (data) {
|
||||
pbnstInsert(data); // pbnstInsert 함수 호출
|
||||
setIsRuseReg({ isModal: false });
|
||||
}
|
||||
}}
|
||||
></PbnstRegModal>
|
||||
}
|
||||
bodyClass="w-[68vw] max-w-none h-[90vh]"
|
||||
bodyClass="w-[68vw] max-w-none h-[90vh]"
|
||||
open={isRuseReg.isModal}
|
||||
onOpenChange={(open) => {
|
||||
remove(form.getValues("items").length - 1);
|
||||
setIsRuseReg({ data: {} as pubHasuType, isModal: open });
|
||||
setIsRuseReg({ isModal: open });
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user