type을 조드로 대체 유효성 검사 추가

This commit is contained in:
leedj312
2025-04-17 14:06:23 +09:00
parent da67f24491
commit bed9927e97
13 changed files with 153 additions and 321 deletions
@@ -17,7 +17,7 @@ import { headMakeColSpan } from "../rainReg/page";
import ListDiv from "@common/business_components/ui/list_div";
import { useEffect, useState } from "react";
import { tableData } from "@/components/lib/func/commom";
import { HtdflRegForm } from "@/components/ui/form/fcltReg/htdflReg/htdflRegForm";
import HtdflRegForm from "@/components/ui/form/fcltReg/htdflReg/htdflRegForm";
import type { chgBuilding } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
import BdstChgModal from "@/components/ui/modal/bdstChgModal/bdstChgModal";
import { BdstReg } from "@/components/ui/modal/bdstRegModal/bdstRegModal";
@@ -6,7 +6,7 @@ import type {
TableUpperProps,
} from "@/app/store/ruseFcltMng/fcltReg/rainReg";
import { tableData } from "@/components/lib/func/commom";
import { RainRegForm } from "@/components/ui/form/fcltReg/rainReg/rainRegForm";
import RainRegForm from "@/components/ui/form/fcltReg/rainReg/rainRegForm";
import BdstChgModal from "@/components/ui/modal/bdstChgModal/bdstChgModal";
import { BdstReg } from "@/components/ui/modal/bdstRegModal/bdstRegModal";
import {
@@ -18,7 +18,7 @@ import { headMakeColSpan } from "../rainReg/page";
import { useEffect, useState } from "react";
import type { customRswtBdst } from "@/app/store/ruseFcltMng/fcltReg/rswtReg";
import { tableData } from "@/components/lib/func/commom";
import { RswtrRegForm } from "@/components/ui/form/fcltReg/rswtrReg/RswtrRegForm";
import RswtrRegForm from "@/components/ui/form/fcltReg/rswtrReg/rswtrRegForm";
import BdstChgModal from "@/components/ui/modal/bdstChgModal/bdstChgModal";
import type { chgBuilding } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
@@ -1,5 +1,5 @@
import { getFectch } from "@/components/lib/api";
import { TEST_UUID, type bdstAll, type customRainBdst } from "../rainReg";
import { TEST_UUID, type customRainBdst } from "../rainReg";
import type { TableProps } from "../pbnstReg";
import type { customHtdflBdst } from "../htdflReg";
import type { customRswtBdst } from "../rswtReg";
@@ -32,7 +32,7 @@ type TableUpperProps = {
const bdstBase: bdstAll[] = [];
const bdstBase:any[] = [];
const isRainBdst = (data: any): data is customRainBdst=> {
@@ -25,20 +25,21 @@ export const hdtflZod = z.object({
instlCst: z.number().nullish().default(0),
operMngCd: z.string().nullish().default(""),
anlOperCst: z.number().default(0),
instlCstSprtYn: z.string().default(""),
instlCstSprtYn: z.enum(["Y", "N"]),
instlCstSprtAmt: z.number().nullish().default(0),
grntchBdstCertYn: z.string().default(""),
grntchBdstCertYr: z
.string()
.nullish(),
grntchBdstCertYn: z.enum(["Y", "N"]),
grntchBdstCertYr: z .string().default("")
.refine((year) =>year.length ===0 || /^\d{4}$/.test(year),{
message:'4자리 연도만 입력하세요'
}),
grntchBdstCertNo: z.string().nullish().default(""),
grntchBdstCertGrd: z.string().nullish().default(""),
crgRdctYn: z.string().default(""),
crgRdctYn: z.enum(["Y", "N"]),
crgRdctBss: z.string().nullish().default(""),
crgRdctAmt: z.number().nullish().default(0),
ruseFcltFlg: z.string().nullish().default(""),
bdstUsgCd: z.number().default(0),
lawTrgtYn: z.string().default(""),
lawTrgtYn: z.enum(["Y", "N"]),
rgtr:z.string().nullish().default(null),
mdfr:z.string().nullish().default(null),
// htdflObj 매핑
@@ -92,67 +93,9 @@ export const hdtflZod = z.object({
.default([]),
});
export type customHtdflBdst = Omit<bdstAll, 'reuseBuilding'> & {
reuseBuilding: htdflReuseBuilding[];
};
export type customHtdflBdst = z.infer<typeof hdtflZod>
//export type customHtdflBdst = z.infer<typeof hdtflZod>;
//export type customHtdflBdst = z.infer<typeof hdtflZod>;
// 타입을 조드로 만들어가 하는ㅓㄹ로 테트
export type htdflReuseBuilding = {
bdstRuseFcltPk: number | undefined;
bdstInfoFk: number | undefined;
instlCmptnDt: Date | undefined;
instlCst: number | undefined;
operMngCd: string;
anlOperCst: number | undefined;
instlCstSprtYn: string | undefined;
instlCstSprtAmt: number | undefined;
grntchBdstCertYn?: string | undefined;
grntchBdstCertYr: string | undefined;
grntchBdstCertNo: string | undefined;
grntchBdstCertGrd: string | undefined;
crgRdctYn: string;
crgRdctBss: string | undefined;
crgRdctAmt: number | undefined;
ruseFcltFlg: string;
bdstUsgCd: number | undefined;
lawTrgtYn: string;
htdflObj: htdflObj;
rgtr?:string;
mdfr?:string;
};
export type htdflObj = {
htdflFcltPk?: number;
bdstRuseFcltFk?: number;
etgtType?: string;
fclCpct?: number | undefined;
plwtYn?: string;
orgwtWtritSpt: number | undefined;
orgwtOcrnProcs: string;
wtritEntrcTp: number | undefined;
amtgnr: number | undefined;
prcsProcsYn: string;
prcsFcltCpct: number | undefined;
fmYn: string;
utztnCpct: number | undefined;
utztnUsg: string;
grssClfg: number | undefined;
combResdch: number | undefined;
trbt: number | undefined;
bod: number | undefined;
smll: number | undefined;
crmty: number | undefined;
tn: number | undefined;
tph: number | undefined;
ph: number | undefined;
clIonQnt: number | undefined;
cdtnv: number | undefined;
emsnExitTp: number | undefined;
rgtr?:string;
mdfr?:string;
};
export type htdflFacState = {
htdfl: {
@@ -1,12 +1,6 @@
import type { selectArray } from "@/app/store/common/code";
import { getFectch, postFectch, putFectch } from "@/components/lib/api";
import { FormItem } from "@common/business_components/ui";
import { zodResolver } from "@hookform/resolvers/zod";
import type { UUID } from "crypto";
import { useForm } from "react-hook-form";
import { z } from "zod";
import type { customHtdflBdst } from "../htdflReg";
import type { customRswtBdst } from "../rswtReg";
import { makeMdfr, makeRstr } from "../bdstReg";
@@ -24,7 +18,7 @@ export const rainZod = z.object({
archArea: z.number().default(0),
archChgArea: z.number().default(0),
rgtr:z.string().nullish(),
mdfr:z.string().optional(),
mdfr:z.string().nullish(),
reuseBuilding: z.array(
z.object({
@@ -36,34 +30,34 @@ export const rainZod = z.object({
anlOperCst: z.number().default(0),
instlCstSprtYn: z.string().default(""),
instlCstSprtAmt: z.number().nullish(),
grntchBdstCertYn: z.string().default(""),
grntchBdstCertYr: z.string()
.max(4, "4자리 연도를 입력하세요")
.regex(/^\d{4}$/, "4자리 연도를 입력하세요")
.default(""),
grntchBdstCertYn: z.enum(["Y", "N"]).nullish(),
grntchBdstCertYr: z.string().default("")
.refine((year)=> year.length===0 || /^\d{4}$/.test(year),{
message:'4자리 연도만 입력하세요'
}),
grntchBdstCertNo: z.string().default(""),
grntchBdstCertGrd: z.string().default(""),
crgRdctYn: z.string().default("").nullish(),
crgRdctBss: z.string().default("").nullish(),
crgRdctAmt: z.number().default(0),
crgRdctYn: z.enum(["Y", "N"]), // 안쓰는 값
crgRdctBss: z.string().default("").nullish(), /// 안쓰는 값
crgRdctAmt: z.number().default(0), // 안쓰는 값
ruseFcltFlg: z.string().default(""),
bdstUsgCd: z.number().default(0),
lawTrgtYn: z.string().default(""),
lawTrgtYn: z.enum(["Y", "N"]),
rgtr:z.string().nullish(),
mdfr:z.string().optional(),
mdfr:z.string().nullish(),
rainyObj: z.object({
bdstReuseFcltFk: z.number().nullish(),
pntfColKnd: z.string().default(""),
pntfColArea: z.number().default(0),
dtfcltCpct: z.number().default(0),
filtrTrtmfctYn: z.enum(["Y", "N"]).nullish(),
filtrTrtmfctCpct: z.number().nullish().default(0),
filtrTrtmfctYn: z.string().default(""),
filtrTrtmfctPrs: z.string().default(""),
annRnwtQty: z.number().default(0),
oilqMeasMthd: z.string().default("").nullish(),
rgtr:z.string().nullish(),
mdfr:z.string().optional(),
mdfr:z.string().nullish(),
}).default({})
@@ -95,59 +89,8 @@ export type chgBuilding={
}
export type bdstAll = {
bdstInfoPk?: number;
ctpvCd: number;
sggCd: number;
bdstNm: string;
daddr: string;
frstArchPrmsnDt: Date;
archArea: number;
archChgArea: number;
rgtr?:string|null;
mdfr?:string|null;
reuseBuilding: rainReuseBuilding[];
chgBuilding:chgBuilding[]
};
export type customRainBdst = z.infer<typeof rainZod>
export type customRainBdst = Omit<bdstAll, 'reuseBuilding'> & {
reuseBuilding: rainReuseBuilding[];
};
export type rainReuseBuilding = {
lawTrgtYn: string|undefined;
bdstUsgCd: number|undefined;
bdstRuseFcltPk?: number|null;
bdstInfoFk: number|undefined;
operMngCd?: number;
anlOperCst: number;
instlCmptnDt: Date|undefined;
instlCst: number;
//archChgPrmsnDt: string;
instlCstSprtYn: string|undefined;
instlCstSprtAmt?: number|undefined;
grntchBdstCertYn: string|undefined;
grntchBdstCertNo: string|undefined;
grntchBdstCertGrd: string|undefined;
grntchBdstCertYr: string|undefined;
rgtr?:string|null;
mdfr?:string|null;
rainyObj: rainyObj | null |undefined;
};
export type rainyObj = {
bdstReuseFcltFk?: number|undefined;
pntfColKnd?: string | undefined;
pntfColArea?: number | undefined;
dtfcltCpct?: number;
filtrTrtmfctCpct?: number | undefined;
filtrTrtmfctYn?: string | undefined;
filtrTrtmfctPrs?: string | undefined;
annRnwtQty?: number;
oilqMeasMthd?: string | undefined;
rgtr?:string|null,
mdfr?:string|null,
};
export type TableUpperProps = {
id: string;
@@ -177,62 +120,6 @@ export const upHeadList: TableUpperProps[] = [
const rainRes: customRainBdst[] = [];
const regRainForm:customRainBdst = {
ctpvCd: 0,
sggCd: 0,
bdstNm: "",
daddr: "",
frstArchPrmsnDt:new Date(),
archArea: 0,
archChgArea: 0,
bdstInfoPk: 0,
rgtr:"",
mdfr:"",
reuseBuilding: [{
rainyObj: {
bdstReuseFcltFk: 0,
pntfColKnd: undefined,
pntfColArea: undefined,
dtfcltCpct: 0,
filtrTrtmfctCpct: undefined,
filtrTrtmfctYn: undefined,
filtrTrtmfctPrs: undefined,
annRnwtQty: 0,
oilqMeasMthd: undefined,
rgtr:"",
mdfr:"",
},
lawTrgtYn: undefined,
bdstUsgCd: undefined,
bdstRuseFcltPk: 0,
bdstInfoFk: 0,
operMngCd: 0,
anlOperCst: 0,
instlCmptnDt: undefined,
instlCst: 0,
// archChgPrmsnDt: "",
instlCstSprtYn: undefined,
instlCstSprtAmt: undefined,
grntchBdstCertYn: undefined,
grntchBdstCertNo: undefined,
grntchBdstCertGrd: undefined,
grntchBdstCertYr: undefined,
rgtr:"",
mdfr:"",
}],
//추가됨
chgBuilding:[{
bdstInfoFk: 0,
archChgPrmsnDt: new Date(),
archChgArea: "-",
bdstChgNm: "",
rgtr:"",
mdfr:"",
}]
};
export const selectClass = "w-full h-full text-2xl";
const selectYN = [
{ text: "Y", val: "1" },
@@ -244,7 +131,7 @@ export type rainFacState = {
upHeadList: TableUpperProps[];
selectYN: selectArray[];
rainRes: customRainBdst[];
regRainForm:customRainBdst,
// regRainForm:customRainBdst,
};
};
@@ -263,7 +150,7 @@ export const rainFacStateExport: rainFacState = {
rainRes: rainRes,
upHeadList: upHeadList,
selectYN: selectYN,
regRainForm:regRainForm,
//regRainForm:regRainForm,
},
};
@@ -1,6 +1,5 @@
import { getFectch, postFectch, putFectch } from "@/components/lib/api";
import { upHeadList, type bdstAll, type chgBuilding, type TableUpperProps } from "../rainReg";
import { rswtBdstType } from "@/app/store/common/code";
import { upHeadList, type chgBuilding, type TableUpperProps } from "../rainReg";
import { z } from "zod";
import { makeMdfr, makeRstr } from "../bdstReg";
@@ -28,19 +27,20 @@ export const rswtZod = z.object({
operMngCd: z.string().nullish().default(""),
anlOperCst: z.number().default(0),
instlCstSprtYn: z.string().default(""),
instlCstSprtYn: z.enum(["Y", "N"]),
instlCstSprtAmt: z.number().default(0),
grntchBdstCertYn: z.string().default("N"),
grntchBdstCertYr: z.string().max(4, "4자리 연도를 입력하세요")
.regex(/^\d{4}$/, "4자리 연도를 입력하세요")
.default(""),
grntchBdstCertNo: z.string().nullish().default(""),
grntchBdstCertGrd: z.string().nullish().default(""),
grntchBdstCertYn: z.enum(["Y", "N"]),
grntchBdstCertYr: z.string().default("")
.refine((year)=> year.length===0 ||/^\d{4}$/.test(year),{
message:'4자리 연도만 입력하세요'
}),
grntchBdstCertNo: z.string().default(""),
grntchBdstCertGrd: z.string().default(""),
crgRdctYn: z.string().default(""),
crgRdctBss: z.string().default(""),
crgRdctAmt: z.number().default(0),
crgRdctYn: z.enum(["Y", "N"]), // 안쓰는 값
crgRdctBss: z.string().default("").nullish(), /// 안쓰는 값
crgRdctAmt: z.number().default(0), // 안쓰는 값
ruseFcltFlg: z.string().default(""),
bdstUsgCd: z.number().default(0),
lawTrgtYn: z.string().default(""),
@@ -55,10 +55,10 @@ export const rswtZod = z.object({
filtrTrtmfctProcs: z.string().default(""),
filtrTrtmfctUsgCd: z.string().default(""),
rswtrUsqty: z.number().default(0),
altUswtrUtztnYn: z.string().default(""),
altUswtrKndCd: z.string().default(""),
altUswtrUtztnQnt: z.number().default(0),
altUswtrIdntyMthdCd: z.string().default(""),
altUswtrUtztnYn: z.enum(["Y", "N"]).nullish(),//안쓰는값
altUswtrKndCd: z.string().default(""),//안쓰는값
altUswtrUtztnQnt: z.number().default(0),//안쓰는값
altUswtrIdntyMthdCd: z.string().default(""),//안쓰는값
rgtr:z.string().nullish().default(null),
mdfr:z.string().nullish().default(null),
}).default({})
@@ -81,48 +81,7 @@ export const rswtZod = z.object({
});
export type customRswtBdst = Omit<bdstAll, 'reuseBuilding'> & {
reuseBuilding: rswtReuseBuilding[];
};
export type rswtReuseBuilding = {
bdstRuseFcltPk: number;
bdstInfoFk: number;
instlCmptnDt: Date | undefined;
instlCst: number | undefined;
operMngCd: number;
lawTrgtYn: string | undefined;
anlOperCst: number;
instlCstSprtYn: string | undefined;
instlCstSprtAmt: number | undefined;
bdstUsgCd: number | undefined;
grntchBdstCertYn: string ;
grntchBdstCertNo?: string | undefined;
grntchBdstCertGrd?: string | undefined;
grntchBdstCertYr?: string | undefined;
rgtr?:string;
mdfr?:string;
rswtrObj: rswtrObj | null;
};
export type rswtrObj = {
bdstRuseFcltFk?: number | undefined;
wtrUsqty?: number | undefined;
oblgTrgtWtrUsqty?: number ;
orgwtKndCd?: string | undefined;
filtrTrtmfctProcs?: string | undefined;
filtrTrtmfctUsgCd?: string | undefined;
rswtrUsqty?: number;
altUswtrUtztnYn?: string;
altUswtrKndCd?: string;
altUswtrUtztnQnt?: number;
altUswtrIdntyMthdCd?: string;
rgtr?:string;
mdfr?:string;
}
export type customRswtBdst = z.infer<typeof rswtZod>
const rswtRes: customRswtBdst[] = [];
-1
View File
@@ -1,5 +1,4 @@
import type { comCodeState, selectArray } from "@/app/store/common/code";
import type { bdstAll } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
@@ -1,6 +1,6 @@
import { useWrStore } from "@/app/store";
import type { selectArray } from "@/app/store/common/code";
import { selectClass, type bdstAll } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
import { selectClass } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
import { getCity } from "@/components/lib/func/commom";
import type { objSearchType } from "@/components/ui/modal/bdstRegModal/bdstRegModal";
import { FormField, FormUi, DatePicker, SelectBox } from "@common/business_components";
@@ -19,7 +19,7 @@ import {
import { useEffect } from "react";
import BdstReg from "../bdstReg/bdstReg";
export function HtdflRegForm({
export default function HtdflRegForm({
htdflForm,
isModal,
}: {
@@ -35,7 +35,7 @@ export function HtdflRegForm({
defaultValues: defaultValues,
});
function onSubmit(values: z.infer<typeof hdtflZod>) {
const onSubmit=(values: z.infer<typeof hdtflZod>)=> {
if (isModal) {
htdflReg(values);
} else {
@@ -47,7 +47,7 @@ export function HtdflRegForm({
console.log(val);
};
function cleanHtdflData(raw: any): z.infer<typeof hdtflZod> {
const cleanHtdflData=(raw: any): z.infer<typeof hdtflZod> =>{
return {
...raw,
frstArchPrmsnDt: new Date(raw?.frstArchPrmsnDt || null),
@@ -71,6 +71,10 @@ export function HtdflRegForm({
})),
};
}
useEffect(() => {
console.log("form errors:", form.formState.errors);
}, [form.formState.errors]);
@@ -12,11 +12,11 @@ import { Form, FormField, SelectBox } from "@common/business_components/ui";
import { Button, Input } 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, useWatch, type UseFormReturn } from "react-hook-form";
import { z } from "zod";
import BdstReg from "../bdstReg/bdstReg";
export function RainRegForm({
export default function RainRegForm({
rainForm,
isModal,
}: {
@@ -25,7 +25,6 @@ export function RainRegForm({
}) {
const { code, rainReg, rainUpdate, rain } = useWrStore((state) => state);
const { rainFcltCd } = code;
const defaultValues: z.infer<typeof rainZod> = rainZod.parse({});
const form = useForm<z.infer<typeof rainZod>>({
@@ -33,11 +32,13 @@ export function RainRegForm({
defaultValues: defaultValues,
});
const [grntchBdstCertYn, instlCstSprtYn, filtrTrtmfctYn] = form.watch([
"reuseBuilding.0.grntchBdstCertYn",
"reuseBuilding.0.instlCstSprtYn",
"reuseBuilding.0.rainyObj.filtrTrtmfctYn",
]);
function cleanRainData(raw: any): z.infer<typeof rainZod> {
const cleanRainData =(raw: any): z.infer<typeof rainZod> =>{
return {
...raw,
frstArchPrmsnDt: new Date(raw?.frstArchPrmsnDt||null),
@@ -56,7 +57,19 @@ export function RainRegForm({
};
}
useEffect(() =>{
if(grntchBdstCertYn ==='N'){
form.setValue('reuseBuilding.0.grntchBdstCertYr' ,"" )
form.setValue('reuseBuilding.0.grntchBdstCertNo' ,"" )
form.setValue('reuseBuilding.0.grntchBdstCertGrd' ,"" )
}else if(instlCstSprtYn ==='N'){
form.setValue('reuseBuilding.0.instlCstSprtAmt' ,0 )
}else if(filtrTrtmfctYn ==='N'){
form.setValue('reuseBuilding.0.rainyObj.filtrTrtmfctCpct' ,0 )
form.setValue('reuseBuilding.0.rainyObj.filtrTrtmfctPrs' ,"" )
}
},[grntchBdstCertYn,instlCstSprtYn ,filtrTrtmfctYn])
// form 값이 변경될 때마다 로그 출력
@@ -65,23 +78,21 @@ export function RainRegForm({
return () => subscription.unsubscribe();
}, [form]);
function onSubmit(values: z.infer<typeof rainZod>) {
if (isModal) {
rainReg(values);
} else {
rainUpdate(values);
}
}
useEffect(() => {
console.log("form errors:", form.formState.errors);
}, [form.formState.errors]);
const onSubmit =(values: z.infer<typeof rainZod>)=> {
if (isModal) {
rainReg(values);
} else {
rainUpdate(values);
}
}
useEffect(() => {
if(rainZod)
@@ -89,6 +100,9 @@ export function RainRegForm({
}, [rainForm]);
return (
<div className="">
<Form {...form}>
@@ -147,7 +161,7 @@ export function RainRegForm({
<Input
className=""
placeholder="1,000,000"
type=""
type="number"
value={field.value ?? 0}
onChange={(e) => {
field.onChange(e.target.value === "" ? "" : Number(e.target.value));
@@ -195,7 +209,7 @@ export function RainRegForm({
<Input
className=""
placeholder="1,000,000"
type=""
type="number"
value={field.value ?? 0}
onChange={(e) => field.onChange(Number(e.target.value))}
/>
@@ -236,9 +250,10 @@ export function RainRegForm({
<Input
className=""
placeholder="1,000,000"
type=""
type="number"
value={field.value ?? 0}
onChange={(e) => field.onChange(Number(e.target.value))}
readOnly={filtrTrtmfctYn!=='Y'}
/>
</FormUi>
@@ -257,6 +272,7 @@ export function RainRegForm({
type=""
value={field.value ?? ""}
onChange={field.onChange}
readOnly={filtrTrtmfctYn!=='Y'}
/>
</FormUi>
)}
@@ -285,6 +301,7 @@ export function RainRegForm({
selectArray={code.yn}
onSelectValue={field.onChange}
value={field.value ?? code.yn[0]?.val}
/>
</FormUi>
)}
@@ -299,12 +316,13 @@ export function RainRegForm({
<Input
className=""
placeholder="1,000,000"
type=""
type="number"
onChange={(e) => {
const value = e.target.value;
field.onChange(value === "" ? "" : Number(value));
}}
value={field.value ?? 0}
readOnly={instlCstSprtYn!=='Y'}
/>
</FormUi>
)}
@@ -341,7 +359,9 @@ export function RainRegForm({
render={({ field }) => (
<FormUi label="인증년도">
<Input className="" placeholder="2024" type="" value={field.value ?? ""}
onChange={field.onChange} />
onChange={field.onChange}
readOnly={grntchBdstCertYn!=='Y'}/>
</FormUi>
)}
/>
@@ -358,6 +378,7 @@ export function RainRegForm({
type=""
value={field.value ?? ""}
onChange={field.onChange}
readOnly={grntchBdstCertYn!=='Y'}
/>
</FormUi>
)}
@@ -370,7 +391,9 @@ export function RainRegForm({
render={({ field }) => (
<FormUi label="인증등급">
<Input className="" placeholder="A" type="" value={field.value ?? ""}
onChange={field.onChange}/>
onChange={field.onChange}
readOnly={grntchBdstCertYn!=='Y'}
/>
</FormUi>
)}
/>
@@ -9,8 +9,8 @@ import {
} from "@common/business_components/ui";
import { Button, Input } from "@common/components/ui";
import { zodResolver } from "@hookform/resolvers/zod";
import { useFieldArray, useForm } from "react-hook-form";
import { number, z } from "zod";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { useWrStore } from "@/app/store";
import { selectClass } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
import {
@@ -20,7 +20,7 @@ import {
import { useEffect } from "react";
import BdstReg from "../bdstReg/bdstReg";
export function RswtrRegForm({
export default function RswtrRegForm({
rswtForm,
isModal,
}: {
@@ -39,29 +39,20 @@ export function RswtrRegForm({
})
// 2. Define a submit handler.
async function onSubmit(values: z.infer<typeof rswtZod>) {
// Do something with the form values.
// ✅ This will be type-safe and validated.
console.log(values);
const [grntchBdstCertYn, instlCstSprtYn,filtrTrtmfctProcs] = form.watch([
"reuseBuilding.0.grntchBdstCertYn",
"reuseBuilding.0.instlCstSprtYn",
"reuseBuilding.0.rswtrObj.filtrTrtmfctProcs",
]);
const onSubmit =(values: z.infer<typeof rswtZod>) => {
if (isModal) {
// regRainForm.bdstInfoPk = null;
await rswtReg(values);
rswtReg(values);
} else {
rswtUpdate(values);
}
}
const onSelectValue = (val: string | number) => {
console.log(val);
};
function cleanRswtData(raw: any): z.infer<typeof rswtZod> {
const cleanRswtData = (raw: any): z.infer<typeof rswtZod> =>{
return {
...raw,
frstArchPrmsnDt: new Date(raw?.frstArchPrmsnDt||null),
@@ -81,9 +72,29 @@ export function RswtrRegForm({
}
useEffect(() => {
console.log("form errors:", form.formState.errors);
}, [form.formState.errors]);
useEffect(() =>{
console.log("filtrTrtmfctProcs ", filtrTrtmfctProcs)
if(grntchBdstCertYn ==='N'){
form.setValue('reuseBuilding.0.grntchBdstCertYr' ,"" )
form.setValue('reuseBuilding.0.grntchBdstCertNo' ,"" )
form.setValue('reuseBuilding.0.grntchBdstCertGrd' ,"" )
}else if(instlCstSprtYn ==='N'){
form.setValue('reuseBuilding.0.instlCstSprtAmt' ,0 )
}
},[grntchBdstCertYn,instlCstSprtYn,filtrTrtmfctProcs ])
useEffect(() => {
if(rswtZod)
console.log("rswtForm", rswtForm);
form.reset( cleanRswtData(rswtForm))
}, [rswtForm]);
@@ -151,7 +162,7 @@ useEffect(() => {
<Input
className=""
placeholder="1,000,000"
type="text"
type="number"
value={field.value ?? ""}
onChange={(e) => field.onChange(Number(e.target.value))}
/>
@@ -170,7 +181,7 @@ useEffect(() => {
<Input
className=""
placeholder="1,000,000"
type=""
type="number"
value={field.value ?? 0}
onChange={(e) => field.onChange(Number(e.target.value))}
/>
@@ -188,7 +199,7 @@ useEffect(() => {
<Input
className=""
placeholder="1,000,000"
type="text"
type="number"
value={field.value ?? 0}
onChange={(e) => field.onChange(Number(e.target.value))}
/>
@@ -277,11 +288,12 @@ useEffect(() => {
<Input
className=""
placeholder="1,000,000"
type=""
value={field.value ?? ""}
type="number"
value={field.value ?? 0}
onChange={(e) => {
field.onChange(Number(e.target.value));
}}
readOnly={instlCstSprtYn!=='Y'}
/>
</FormUi>
)}
@@ -320,10 +332,11 @@ useEffect(() => {
<Input
className=""
placeholder="2024"
type=""
type="text"
{...field}
value={field.value ?? ""}
onChange={field.onChange}
readOnly={grntchBdstCertYn!=='Y'}
/>
</FormUi>
)}
@@ -341,6 +354,8 @@ useEffect(() => {
type=""
value={field.value ?? ""}
onChange={field.onChange}
readOnly={grntchBdstCertYn!=='Y'}
/>
</FormUi>
)}
@@ -358,6 +373,8 @@ useEffect(() => {
type=""
value={field.value ?? ""}
onChange={field.onChange}
readOnly={grntchBdstCertYn!=='Y'}
/>
</FormUi>
)}
@@ -8,13 +8,13 @@ import {
import { ScrollArea, SelectBox, UiTable } from "@common/business_components";
import { Button, Input, Label } from "@common/components";
import { useEffect, useState } from "react";
import { RainRegForm } from "../../form/fcltReg/rainReg/rainRegForm";
import RainRegForm from "../../form/fcltReg/rainReg/rainRegForm";
import { type selectArray } from "@/app/store/common/code";
import { getCity, tableData } from "@/components/lib/func/commom";
import type { customRswtBdst } from "@/app/store/ruseFcltMng/fcltReg/rswtReg";
import { HtdflRegForm } from "../../form/fcltReg/htdflReg/htdflRegForm";
import HtdflRegForm from "../../form/fcltReg/htdflReg/htdflRegForm";
import type { customHtdflBdst } from "@/app/store/ruseFcltMng/fcltReg/htdflReg";
import { RswtrRegForm } from "../../form/fcltReg/rswtrReg/RswtrRegForm";
import RswtrRegForm from "../../form/fcltReg/rswtrReg/rswtrRegForm";
export type objSearchType = {
sgg: string|number;
@@ -145,7 +145,7 @@ export function BdstReg<T extends MoType>({ moType }: BdstRegProps<T>) {
<RainRegForm rainForm={rainBdstForm as customRainBdst} isModal={true} />
:moType==='RST'
? <RswtrRegForm rswtForm={rainBdstForm as customRswtBdst} isModal={true}></RswtrRegForm>
:<HtdflRegForm htdflForm={rainBdstForm as customHtdflBdst} isModal={true}></HtdflRegForm>
:<HtdflRegForm htdflForm={rainBdstForm as unknown as customHtdflBdst} isModal={true}></HtdflRegForm>
}
</div>