From 54f47afaee46668776df085b71fa39761d35539b Mon Sep 17 00:00:00 2001 From: truthwing Date: Tue, 1 Apr 2025 13:11:49 +0900 Subject: [PATCH] =?UTF-8?q?type=20=EC=97=90=EB=9F=AC=20=EC=A0=95=EB=A6=AC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ruseFcltMng/fcltReg/rainReg/page.tsx | 121 +++++++------ .../ruseFcltMng/fcltReg/rainReg/index.tsx | 163 ++++++++---------- .../ui/form/fcltReg/rainReg/component.tsx | 45 +++-- 3 files changed, 162 insertions(+), 167 deletions(-) diff --git a/apps/wr/app/ruseFcltMng/fcltReg/rainReg/page.tsx b/apps/wr/app/ruseFcltMng/fcltReg/rainReg/page.tsx index d348a07d5..d5ebba35f 100644 --- a/apps/wr/app/ruseFcltMng/fcltReg/rainReg/page.tsx +++ b/apps/wr/app/ruseFcltMng/fcltReg/rainReg/page.tsx @@ -1,65 +1,88 @@ -'use client' +"use client"; import { useWrStore } from "@/app/store"; -import type { RainyInfoResponse, TableUpperProps } from "@/app/store/ruseFcltMng/fcltReg/rainReg" +import type { + RainyBuilding, + TableUpperProps, +} from "@/app/store/ruseFcltMng/fcltReg/rainReg"; import { RainRegForm } from "@/components/ui/form/fcltReg/rainReg/component"; import { BdstReg } from "@/components/ui/modal/bdstReg/component"; -import { ContentsDiv, ScrollArea, SearchDiv, SearchFormLeft, SearchFormRight, SearchInput, Title, UiModal, UiTable } from "@common/business_components"; +import { + ContentsDiv, + ScrollArea, + SearchDiv, + SearchFormLeft, + SearchFormRight, + SearchInput, + Title, + UiModal, + UiTable, +} from "@common/business_components"; import ListDiv from "@common/business_components/ui/list_div"; import { Button, TableHead, TableRow } from "@common/components"; -import { useEffect, useState } from "react"; +import { useEffect, useState } from "react"; export const headMakeColSpan = (upHeadList: TableUpperProps[]) => { - return (<> - { - upHeadList.map((head: TableUpperProps) => - (!head.upSequnce ? {head.title} : - head.upName === 'upChangeRe' && head.upSequnce === 1 ? {'중축 개축 증축 '} : null))} - - - {upHeadList.map((head: TableUpperProps) => - (head.upName === 'upChangeRe' ? {head.title} : null))} - - ) -} + return ( + <> + + {upHeadList.map((head: TableUpperProps) => + !head.upSequnce ? ( + + {head.title} + + ) : head.upName === "upChangeRe" && head.upSequnce === 1 ? ( + + {"중축 개축 증축 "} + + ) : null + )} + + + {upHeadList.map((head: TableUpperProps) => + head.upName === "upChangeRe" ? ( + {head.title} + ) : null + )} + + + ); +}; export default function Home() { - const { rain, code,init } = useWrStore((state) => { - return state + const { rain, code, init } = useWrStore((state) => { + return state; }); - const {bdstObj, rainRes } =rain - const [rainForm, setRainForm] = useState (); - const [bdstTable, setbdstTable] = useState (); + const { rainRes } = rain; + const [rainForm, setRainForm] = useState(); + const [bdstTable, setbdstTable] = useState(); const nodeList = headMakeColSpan(rain.upHeadList); useEffect(() => { - - if (!rain.isInit) { - + if (!rain.isInit) { init(); - - } - }, [rain.isInit,init]); - - useEffect ( () => { - - if(code.sggCd.length>0){ - const table = rainRes.map((item) => { - const sggText= code.sggCd.find((cd)=>cd.val.toString() === item.sggCd )?.text; - const cityText= code.cityCd.find((cd)=>cd.val.toString() === item.ctpvCd )?.text; - return( - {...item, - sggText:sggText, - cityText:cityText - }) - }) - - setbdstTable(table) } -}, [code,rainRes]); - const cellClick: (val: number ) => void = (val) => { - if((bdstTable ?? []).length > 0) { - setRainForm(rainRes[val]) - } - } + }, [rain.isInit, init]); + useEffect(() => { + if (code.sggCd.length > 0) { + const table = rainRes.map((item) => { + const sggText = code.sggCd.find( + (cd) => cd.val.toString() === item.sggCd + )?.text; + const cityText = code.cityCd.find( + (cd) => cd.val.toString() === item.ctpvCd + )?.text; + return { ...item, sggText: sggText, cityText: cityText }; + }); + + setbdstTable(table); + } + }, [code, rainRes]); + const cellClick: (val: number | undefined) => void = (val) => { + if ((bdstTable ?? []).length > 0 && val !== undefined) { + { + setRainForm(rainRes[val]); + } + } + }; return ( <> @@ -73,7 +96,7 @@ export default function Home() { className="col-span-3 my-7" label="건물명" textValue={""} - setText={function (val: string): void { + setText={function (): void { throw new Error("Function not implemented."); }} /> diff --git a/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx b/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx index e3442dc3d..9268edcb5 100644 --- a/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx +++ b/apps/wr/app/store/ruseFcltMng/fcltReg/rainReg/index.tsx @@ -1,7 +1,6 @@ -import { bdstUsgCd, comCodeStateExport } from "@/app/store/common/code"; import { getFectch, postFectch, putFectch } from "@/components/lib/api"; -export type RainyInfoResponse = { +export type RainyBuilding = { ctpvCd: string; sggCd: string; bdstNm: string; @@ -10,37 +9,37 @@ export type RainyInfoResponse = { archArea: string; archChgArea: string; bdstInfoPk: number; - reuseBuilding:reuseBuilding + reuseBuilding: reuseBuilding[]; }; -export type reuseBuilding= Array<{ - lawTrgtYn: string; - bdstUsgCd: string; +export type reuseBuilding = { + lawTrgtYn: string|undefined; + bdstUsgCd: string|undefined; bdstRuseFcltPk: number; bdstInfoFk: number; - operMngCd: number ; - anlOperCst: number ; - instlCmptnDt: Date ; - instlCst: number ; - archChgPrmsnDt: string ; - instlCstSprtYn: string ; - instlCstSprtAmt: number - grntchBdstCertYn: string - grntchBdstCertNo: string - grntchBdstCertGrd: string - grntchBdstCertYr: string - rainyObj:rainyObj| null -}>; -export type rainyObj= { - bdstReuseFcltFk:number - pntfColKnd: string | undefined - pntfColArea: number | undefined - dtfcltCpct:number - filtrTrtmfctCpct: number | undefined - filtrTrtmfctYn: string| undefined - filtrTrtmfctPrs: string | undefined - annRnwtQty:number - oilqMeasMthd:string| undefined + operMngCd: number; + anlOperCst: number; + instlCmptnDt: Date; + instlCst: number|undefined; + archChgPrmsnDt: string; + instlCstSprtYn: string|undefined; + instlCstSprtAmt: number|undefined; + grntchBdstCertYn: string|undefined; + grntchBdstCertNo: string|undefined; + grntchBdstCertGrd: string|undefined; + grntchBdstCertYr: string|undefined; + rainyObj: rainyObj | null; +}; +export type rainyObj = { + bdstReuseFcltFk: number; + pntfColKnd: string | undefined; + pntfColArea: number | undefined; + dtfcltCpct: number; + filtrTrtmfctCpct: number | undefined; + filtrTrtmfctYn: string | undefined; + filtrTrtmfctPrs: string | undefined; + annRnwtQty: number; + oilqMeasMthd: string | undefined; }; export type TableUpperProps = { @@ -50,21 +49,6 @@ export type TableUpperProps = { upSequnce?: number; }; - -// export type bdstType = { -// ctpvCd: string; // 시도 -// sggCd: string; // 시군구 -// daddr: string; // 위치 -// bdstUsgCd: string; // 건축물용도 -// frstArchPrmsnDt: string; // 최초건축허가일 -// archArea: string; // 건축면적 -// lawTrgtYn: string; // 법적의무대상여부 -// archChgPrmsnDt: string; // 건축변경 허가일시 -// archChgArea: string; // 변경 면적 -// bdstInfoPk: number; -// bdstNm: string; -// }; - export const upHeadList: TableUpperProps[] = [ { id: "cityText", title: "시도" }, { id: "sggText", title: "시군구" }, @@ -72,17 +56,14 @@ export const upHeadList: TableUpperProps[] = [ { id: "daddr", title: "위치" }, { id: "bdstUsgCd", title: "건축물용도" }, { id: "frstArchPrmsnDt", title: "최초건축허가일" }, - { id: "archArea", title: "건축면적", }, - { id: "lawTrgtYn", title: "법적의무대상여부", }, + { id: "archArea", title: "건축면적" }, + { id: "lawTrgtYn", title: "법적의무대상여부" }, { id: "archChgYn", title: "여부", upName: "upChangeRe", upSequnce: 1 }, { id: "archChgPrmsnDt", title: "허가일", upName: "upChangeRe", upSequnce: 2 }, { id: "archChgArea", title: "면적", upName: "upChangeRe", upSequnce: 3 }, ]; -const rainRes: RainyInfoResponse[] = [] - - const bdstObj: bdstType[] =[] - const rainRuseObj: rainRuseBd[] = [] +const rainRes: RainyBuilding[] = []; export type selectArray = { text: string; @@ -98,29 +79,24 @@ export type rainFacState = { rain: { isInit: boolean; upHeadList: TableUpperProps[]; - rainRuseObj: rainRuseBd[]; - bdstObj: bdstType[]; selectYN: selectArray[]; - rainRes:RainyInfoResponse[]; + rainRes: RainyBuilding[]; }; }; type rainFacSActions = { init: () => void; dataInit: () => void; - rainReg: (data: RainyInfoResponse) => void; - rainUpdate: (data: RainyInfoResponse) => void; + rainReg: (data: RainyBuilding) => void; + rainUpdate: (data: RainyBuilding) => void; }; - export type rainFacType = rainFacState & rainFacSActions; export const rainFacStateExport: rainFacState = { rain: { isInit: false, - rainRes:rainRes, + rainRes: rainRes, upHeadList: upHeadList, - rainRuseObj: rainRuseObj, - bdstObj: bdstObj, selectYN: selectYN, }, }; @@ -129,62 +105,59 @@ export const rainFacActionsExport: (set: any) => rainFacSActions = ( set: any ) => { return { - init: async() =>{ + init: async () => { try { // 파라이터 수정 통합관리자 =0, 시관리자=시코드, 시군구 관리자= 시군구 코드 를 세번째 파라미터로 지정 / 건축물 서치가 있을경우 4번째 파라미터로 던지기 즉 1/20/42(서울시)/영현빌딩 이런식으로) - const rainRes = await getFectch('wr', "/reuseFc/rainyInfoList/1/20/42"); + const rainRes = await getFectch("wr", "/reuseFc/rainyInfoList/1/20/42"); // 여기서 상태 업데이트 return set((state: rainFacState) => ({ ...state, rain: { ...state.rain, - rainRes:rainRes, - isInit: false - } + rainRes: rainRes, + isInit: false, + }, })); } catch (error) { - console.log('error', error); + console.log("error", error); } finally { - console.log('finally'); + console.log("finally"); } }, dataInit: () => set(async (state: rainFacState) => { - console.log(" state ", state.rain.bdstObj) - return ({ + console.log(" state ", state.rain); + return { rain: { ...state.rain, - isInit: false, - }, - }) + }, + }; }), - rainReg:(data:RainyInfoResponse)=> - set(async(state:rainFacState) =>{ - try{ - const res= postFectch('/reuseFc/rainyInfo' , data) - - }catch (e){ - alert('등록이 오류입니다.') - }finally{ - alert('등록이 완료되었습니다.') - } + rainReg: (data: RainyBuilding) => + set(async () => { + try { + const res = postFectch("/reuseFc/rainyInfo", data); + console.log("res", res); + } catch (e) { + console.log("e", e); + alert("등록이 오류입니다."); + } finally { + alert("등록이 완료되었습니다."); } - ), - rainUpdate:(data:RainyInfoResponse)=> - set(async(state:rainFacState) =>{ - try{ - const res= putFectch('/reuseFc/rainyInfo' , data) - - }catch (e){ - alert('업데이트 오류입니다.') - }finally{ - alert('업데이트가 완료되었습니다.') - } - - + }), + rainUpdate: (data: RainyBuilding) => + set(async () => { + try { + const res = putFectch("/reuseFc/rainyInfo", data); + console.log("res", res); + } catch (e) { + console.log("e", e); + alert("업데이트 오류입니다."); + } finally { + alert("업데이트가 완료되었습니다."); } - ), + }), }; }; diff --git a/apps/wr/components/ui/form/fcltReg/rainReg/component.tsx b/apps/wr/components/ui/form/fcltReg/rainReg/component.tsx index b2ea6404f..a8591ff4a 100644 --- a/apps/wr/components/ui/form/fcltReg/rainReg/component.tsx +++ b/apps/wr/components/ui/form/fcltReg/rainReg/component.tsx @@ -1,30 +1,29 @@ "use client"; -import { Form, FormField, SelectBox } from "@common/business_components/ui"; -import { Button, Input } from "@common/components/ui"; -import { zodResolver } from "@hookform/resolvers/zod"; -import { useForm } from "react-hook-form"; -import { z } from "zod"; -import { FormUi } from "@common/business_components"; import { useWrStore } from "@/app/store"; import { selectClass, - type RainyInfoResponse, + type RainyBuilding, } from "@/app/store/ruseFcltMng/fcltReg/rainReg"; -import { useEffect } from "react"; import { bdstDefZod, rainDefZod, rainZod, } from "@/components/lib/type/zod/fcltReg/controlZod"; +import { DatePicker, FormUi } from "@common/business_components"; +import { Form, FormField, SelectBox } from "@common/business_components/ui"; +import { Button, Input } from "@common/components/ui"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useEffect } from "react"; +import { useForm } from "react-hook-form"; +import { z } from "zod"; import BdstReg from "../bdstReg/component"; -import { DatePicker } from "@common/business_components"; export function RainRegForm({ rainForm, isModal, }: { - rainForm: RainyInfoResponse | undefined; + rainForm: RainyBuilding | undefined; isModal: boolean; }) { const formSchema = z.object(rainZod); @@ -40,7 +39,7 @@ export function RainRegForm({ }, }); - const { rain, code, rainReg, rainUpdate, init } = useWrStore( + const { code, rainReg, rainUpdate, init } = useWrStore( (state) => state ); const { rainFcltCd } = code; @@ -112,31 +111,31 @@ export function RainRegForm({ oilqMeasMthd: rainObj?.oilqMeasMthd, }; regRainForm.reuseBuilding[0] = { - ...rainForm.reuseBuilding[0], + ...rainForm?.reuseBuilding[0], instlCmptnDt: raw.instlCmptnDt, - instlCst: raw.instlCst || rainForm.reuseBuilding[0]?.instlCst, + instlCst: raw.instlCst || rainForm?.reuseBuilding[0]?.instlCst, instlCstSprtYn: - raw.instlCstSprtYn || rainForm.reuseBuilding[0]?.instlCstSprtYn, + raw.instlCstSprtYn || rainForm?.reuseBuilding[0]?.instlCstSprtYn, instlCstSprtAmt: - raw.instlCstSprtAmt || rainForm.reuseBuilding[0]?.instlCstSprtAmt, + raw.instlCstSprtAmt || rainForm?.reuseBuilding[0]?.instlCstSprtAmt, grntchBdstCertYn: - raw.grntchBdstCertYn || rainForm.reuseBuilding[0]?.grntchBdstCertYn, + raw.grntchBdstCertYn || rainForm?.reuseBuilding[0]?.grntchBdstCertYn, grntchBdstCertYr: - raw.grntchBdstCertYr || rainForm.reuseBuilding[0]?.grntchBdstCertYr, + raw.grntchBdstCertYr || rainForm?.reuseBuilding[0]?.grntchBdstCertYr, grntchBdstCertNo: - raw.grntchBdstCertNo || rainForm.reuseBuilding[0]?.grntchBdstCertNo, + raw.grntchBdstCertNo || rainForm?.reuseBuilding[0]?.grntchBdstCertNo, grntchBdstCertGrd: - raw.grntchBdstCertGrd || rainForm.reuseBuilding[0]?.grntchBdstCertGrd, - bdstUsgCd: raw.bdstUsgCd || rainForm.reuseBuilding[0]?.bdstUsgCdd, - lawTrgtYn: raw.lawTrgtYn || rainForm.lawTrgtYn, + raw.grntchBdstCertGrd || rainForm?.reuseBuilding[0]?.grntchBdstCertGrd, + bdstUsgCd: raw.bdstUsgCd || rainForm?.reuseBuilding[0]?.bdstUsgCd, + lawTrgtYn: raw.lawTrgtYn || rainForm?.reuseBuilding[0]?.lawTrgtYn, }; } if (isModal) { - rainReg(regRainForm); + rainReg(raw); } else { - rainUpdate(regRainForm); + rainUpdate(raw); } init();