diff --git a/apps/wr/app/ruseFcltMng/fcltReg/rswtReg/page.tsx b/apps/wr/app/ruseFcltMng/fcltReg/rswtReg/page.tsx index b2ff99104..568145707 100644 --- a/apps/wr/app/ruseFcltMng/fcltReg/rswtReg/page.tsx +++ b/apps/wr/app/ruseFcltMng/fcltReg/rswtReg/page.tsx @@ -45,7 +45,7 @@ export default function Home() { useEffect(() => { if (code.sggCd.length > 0) { - if( rswtRes?.length > 0){ + if (rswtRes?.length > 0) { const rswtData = tableData(rswtRes, { code })?.map( (item: customRswtBdst) => { let archArea = @@ -62,12 +62,20 @@ export default function Home() { ); setbdstTable(rswtData); setRswtForm(rswtRes[selectVal ?? 0]); - }else{ + } else { setbdstTable([]); setRswtForm({} as customRswtBdst); } } - }, [code, rswtRes, selectVal]); + // }, [code, rswtRes, selectVal]); + + }, [code, rswtRes]); + useEffect(() => { + if (rswtRes && rswtRes.length > 0) { + setRswtForm(rswtRes[selectVal ?? 0]); + } + }, [rswtRes, selectVal]); + const cellClick: (val: number | undefined, headId: string) => void = ( val, headId @@ -75,7 +83,7 @@ export default function Home() { if ((bdstTable ?? []).length > 0 && val !== undefined) { { setSelect(val); - setRswtForm(rswtRes[val]); + // setRswtForm(rswtRes[val]); } } diff --git a/apps/wr/components/ui/form/fcltReg/bdstReg/bdstAdd.tsx b/apps/wr/components/ui/form/fcltReg/bdstReg/bdstAdd.tsx new file mode 100644 index 000000000..f7b24e628 --- /dev/null +++ b/apps/wr/components/ui/form/fcltReg/bdstReg/bdstAdd.tsx @@ -0,0 +1,143 @@ +"use client"; + +import { useWrStore } from "@/app/store"; +import { selectClass } from "@/app/store/ruseFcltMng/fcltReg/rainReg"; +import { formH1Class } from "@/components/lib/class/comClass"; +import { safeDate } from "@/components/lib/func/commom"; +import { DatePicker, FormField, FormUi, SelectBox } from "@common/business_components"; +import { Button, Checkbox, Input } from "@common/components"; +import { useEffect, useState } from "react"; +import { useFieldArray } from "react-hook-form"; + +export default function BdstAdd({ form, readonly }: { form: any; readonly?: boolean; }) { + + const { code } = useWrStore((state) => { + return state; + }); + + const { fields, append, remove } = useFieldArray({ + name: "chgBuilding", + control: form?.control, // Provide a fallback to avoid errors + }); + + const plusHist = () => { + append({ + bdstNm: "", + daddr: "", + bdstUsgCd: "", + }); + }; + const [selectedIds, setSelectedIds] = useState([]); + + const toggleSelect = (id: string) => { + setSelectedIds((prev) => + prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id] + ); + }; + + const removeSelected = () => { + const idxsToRemove = fields + .map((item, idx) => (selectedIds.includes(item.id) ? idx : -1)) + .filter((index) => index > -1) + .sort((prevIndex, nextIndex) => nextIndex - prevIndex); + + remove(idxsToRemove); + setSelectedIds([]); + }; + + return ( + <> +

중축, 개축, 재축

+ {!readonly && ( +
+ + + + +
+ )} + {fields.map((field, index) => ( +
+ {!readonly && ( +
+ toggleSelect(field.id)} + /> +
+ )} +
+ ( + + f.onChange(val)} + value={f.value ?? code.chBuCd[0]?.val} + className={""} + label={""} + /> + + )} + /> +
+ +
+ ( + + f.onChange(date), + }} + selectClass="w-full" + /> + + )} + /> +
+
+ ( + + f.onChange(e.target.value)} + value={f.value || ''} + className={selectClass} + /> + + )} + /> +
+
+ ))} +
+ + ) +} \ No newline at end of file diff --git a/apps/wr/components/ui/form/fcltReg/bdstReg/bdstReg.tsx b/apps/wr/components/ui/form/fcltReg/bdstReg/bdstReg.tsx index 188b1380a..c14bd7d48 100644 --- a/apps/wr/components/ui/form/fcltReg/bdstReg/bdstReg.tsx +++ b/apps/wr/components/ui/form/fcltReg/bdstReg/bdstReg.tsx @@ -28,28 +28,6 @@ export default function BdstReg({ form, type }: { form: any; type?: string }) { const [useCityCd, setUserCityCd] = useState([]) const [useSggCd, setUserSggCd] = useState([]) - const { fields, append, remove } = useFieldArray({ - name: "chgBuilding", - control: form?.control, // Provide a fallback to avoid errors - }); - - const plusHist = () => { - append({ - bdstNm: "", - daddr: "", - bdstUsgCd: "", - }); - }; - const removeSelected = () => { - const idxsToRemove = fields - .map((item, idx) => (selectedIds.includes(item.id) ? idx : -1)) - .filter((index) => index > -1) - .sort((prevIndex, nextIndex) => nextIndex - prevIndex); - - remove(idxsToRemove); - setSelectedIds([]); - }; - const [selectSgg, setSelectSgg] = useState(); const [objSearch, setObjSearch] = useState({ sgg: "", @@ -80,9 +58,6 @@ export default function BdstReg({ form, type }: { form: any; type?: string }) { } },[form, userSiSggCd, code.cityCd, code.sggCd]) - - - const getSelCity = (val: string) => { const data = getCity(val, code.sggCd); setSelectSgg(data); @@ -110,13 +85,7 @@ export default function BdstReg({ form, type }: { form: any; type?: string }) { return () => subscription?.unsubscribe(); }, [form.form]); - const [selectedIds, setSelectedIds] = useState([]); - const toggleSelect = (id: string) => { - setSelectedIds((prev) => - prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id] - ); - }; useEffect(() =>{ @@ -296,88 +265,7 @@ export default function BdstReg({ form, type }: { form: any; type?: string }) { /> -

중축, 개축, 재축

-
- - -
- {fields.map((field, index) => ( -
-
- toggleSelect(field.id)} - /> -
-
- ( - - f.onChange(val)} - value={f.value ?? code.chBuCd[0]?.val} - className={""} - label={""} - /> - - )} - /> -
-
- ( - - f.onChange(date), - }} - selectClass="w-full" - /> - - )} - /> -
-
- ( - - f.onChange} - value={f.value||''} - className={selectClass} - /> - - )} - /> -
-
- ))} -
- + ) : ( <> )} diff --git a/apps/wr/components/ui/form/fcltReg/rainReg/rainRegForm.tsx b/apps/wr/components/ui/form/fcltReg/rainReg/rainRegForm.tsx index be436be82..bb62fee61 100644 --- a/apps/wr/components/ui/form/fcltReg/rainReg/rainRegForm.tsx +++ b/apps/wr/components/ui/form/fcltReg/rainReg/rainRegForm.tsx @@ -20,6 +20,7 @@ import { useForm } from "react-hook-form"; import { z } from "zod"; import BdstReg from "../bdstReg/bdstReg"; import toast from "react-hot-toast"; +import BdstAdd from "../bdstReg/bdstAdd"; export default function RainRegForm({ rainForm, @@ -92,9 +93,6 @@ export default function RainRegForm({ })), }; }; - useEffect(()=>{ - console.log("이즈모달", isModal) - }, []) useEffect(() => { if (grntchBdstCertYn === "N") { @@ -601,6 +599,7 @@ export default function RainRegForm({ /> + diff --git a/apps/wr/components/ui/form/fcltReg/rswtrReg/rswtrRegForm.tsx b/apps/wr/components/ui/form/fcltReg/rswtrReg/rswtrRegForm.tsx index 33a847565..a3d849b29 100644 --- a/apps/wr/components/ui/form/fcltReg/rswtrReg/rswtrRegForm.tsx +++ b/apps/wr/components/ui/form/fcltReg/rswtrReg/rswtrRegForm.tsx @@ -9,8 +9,7 @@ import { import { formH1Class, formH2Class } from "@/components/lib/class/comClass"; import { formatCommaNumber, - handleCommaNumberChange, - handleMinusNumberChange, + handleMinusNumberChange } from "@/components/lib/func/commom"; import { DatePicker, @@ -22,8 +21,9 @@ import { import { Button, Input, ScrollArea } from "@common/components/ui"; import { zodResolver } from "@hookform/resolvers/zod"; import { useEffect, useState } from "react"; -import { useForm, type UseFormReturn } from "react-hook-form"; +import { useForm } from "react-hook-form"; import { z } from "zod"; +import BdstAdd from "../bdstReg/bdstAdd"; import BdstReg from "../bdstReg/bdstReg"; export default function RswtrRegForm({ @@ -459,9 +459,6 @@ export default function RswtrRegForm({ } }} disabled={grntchBdstCertYn == "N" || grntchBdstCertYn == "D"} - - - /> ) @@ -488,6 +485,7 @@ export default function RswtrRegForm({ /> +