물재이용: 업데이트시 테이블 목록 초기화
This commit is contained in:
@@ -36,10 +36,11 @@ export default function Home() {
|
||||
const [htdflForm, setHtdflForm] = useState<customHtdflBdst>();
|
||||
const [bdstTable, setbdstTable] = useState<customHtdflBdst[]>();
|
||||
const [issNewReg, setIsNewReg] = useState<boolean>(false);
|
||||
const [resetPageNo, setResetPageNo] = useState<boolean>(false);
|
||||
|
||||
const { htdflRes, htdflResCount } = htdfl;
|
||||
const { regAuthrtYn, mdfcnAuthrtYn, laeSeCd } = auth;
|
||||
const { htdflRes, htdflResCount, htdfTableIndex } = htdfl;
|
||||
const useInitRef = useRef(false);
|
||||
const { regAuthrtYn, mdfcnAuthrtYn, laeSeCd } = auth;
|
||||
|
||||
useEffect(() => {
|
||||
getLaeSeCdCheck();
|
||||
@@ -74,17 +75,27 @@ export default function Home() {
|
||||
}
|
||||
}, [code, htdflRes]);
|
||||
|
||||
const cellClick: (val: number, headId: string) => void = (val) => {
|
||||
if (!htdflRes || !Array.isArray(htdflRes)) return;
|
||||
const idx = Number(val);
|
||||
console.log('htdflRes[idx]', htdflRes[idx]);
|
||||
setHtdflForm(htdflRes[idx]);
|
||||
};
|
||||
const cellClick: (val: number) => void = (val) => {
|
||||
if (!htdflRes || !Array.isArray(htdflRes)) return;
|
||||
const idx = Number(val);
|
||||
setHtdflForm(htdflRes[idx]);
|
||||
setResetPageNo(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getHtdflBdstData(pageNation, "0");
|
||||
getHtdflBdstData(pageNation, laeSeCd);
|
||||
setResetPageNo(false);
|
||||
}, [pageNation]);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof htdfTableIndex === "number" && htdfTableIndex >= 0) {
|
||||
|
||||
console.log('htdfTableIndex ', htdfTableIndex)
|
||||
cellClick(htdfTableIndex);
|
||||
setResetPageNo(true);
|
||||
}
|
||||
}, [htdfTableIndex]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<ContentsDiv>
|
||||
@@ -138,12 +149,14 @@ const cellClick: (val: number, headId: string) => void = (val) => {
|
||||
pageSize={20}
|
||||
total={htdflResCount}
|
||||
headName={"시설물 목록"}
|
||||
cellClick={(val, headId) => {
|
||||
cellClick={(val) => {
|
||||
if (val !== null && val !== undefined) {
|
||||
cellClick(val, headId);
|
||||
cellClick(val);
|
||||
}
|
||||
}}
|
||||
onPageChange={setPageNation}
|
||||
index={htdfTableIndex}
|
||||
resetPageNo={resetPageNo}
|
||||
></UiTable>
|
||||
</ListDiv>
|
||||
</div>
|
||||
|
||||
@@ -49,7 +49,9 @@ export default function Home() {
|
||||
const [pageNation, setPageNation] = useState(1);
|
||||
const [selectVal, setSelect] = useState<number>();
|
||||
const [bdstTable, setbdstTable] = useState<customRswtBdst[]>();
|
||||
const { rswtRes, rswtResCount } = rswt;
|
||||
const [resetPageNo, setResetPageNo] = useState<boolean>(false);
|
||||
|
||||
const { rswtRes, rswtResCount ,rswtTableIndex} = rswt;
|
||||
const useInitRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -96,20 +98,29 @@ export default function Home() {
|
||||
}
|
||||
}, [rswtRes, selectVal]);
|
||||
|
||||
const cellClick: (val: number | undefined, headId: string) => void = (
|
||||
const cellClick: (val: number | undefined) => void = (
|
||||
val
|
||||
) => {
|
||||
if ((bdstTable ?? []).length > 0 && val !== undefined) {
|
||||
{
|
||||
setSelect(val);
|
||||
setResetPageNo(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getRswtBdstData(pageNation,laeSeCd);
|
||||
setResetPageNo(false);
|
||||
}, [pageNation]);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof rswtTableIndex === 'number' && rswtTableIndex >= 0) {
|
||||
cellClick(rswtTableIndex);
|
||||
setResetPageNo(true);
|
||||
}
|
||||
}, [rswtTableIndex]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<ContentsDiv>
|
||||
@@ -163,7 +174,8 @@ export default function Home() {
|
||||
headName={"건축물 목록"}
|
||||
cellClick={cellClick}
|
||||
onPageChange={setPageNation}
|
||||
index={0}
|
||||
index={rswtTableIndex}
|
||||
resetPageNo={resetPageNo}
|
||||
></UiTable>
|
||||
</ListDiv>
|
||||
</div>
|
||||
|
||||
@@ -94,6 +94,7 @@ export type htdflFacState = {
|
||||
upHeadList: TableUpperProps[];
|
||||
htdflRes: customHtdflBdst[];
|
||||
htdflResCount:number
|
||||
htdfTableIndex?: number;
|
||||
};
|
||||
};
|
||||
type htdflFacSActions = {
|
||||
@@ -102,6 +103,7 @@ type htdflFacSActions = {
|
||||
htdflBdstUpdate: (data: customHtdflBdst, code: string | number) => void;
|
||||
htdflBdstReg: (data: customHtdflBdst, code: string | number) => void;
|
||||
getHtdflBdstData: (pageNation: number, code: string | number) => void;
|
||||
resetHtdflTableIndex:(index:number)=>void;
|
||||
};
|
||||
|
||||
const htdflRes: customHtdflBdst[] = [];
|
||||
@@ -113,6 +115,7 @@ export const htdflFacStateExport: htdflFacState = {
|
||||
upHeadList: htdTableHeadList,
|
||||
htdflRes: htdflRes,
|
||||
htdflResCount:1,
|
||||
htdfTableIndex: undefined,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -235,5 +238,20 @@ export const htdflFacActionsExport: (set: any) => htdflFacSActions = (
|
||||
console.log(error);
|
||||
}
|
||||
},
|
||||
resetHtdflTableIndex: (index: number) => {
|
||||
// 1) 동일값도 '변경'으로 느끼게 잠깐 -1
|
||||
set((state: htdflFacState) => ({
|
||||
...state,
|
||||
htdfl: { ...state.htdfl, htdfTableIndex: -1 },
|
||||
}));
|
||||
// 2) 다음 마이크로태스크에서 진짜 값 복구
|
||||
Promise.resolve().then(() => {
|
||||
set((state: htdflFacState) => ({
|
||||
...state,
|
||||
htdfl: { ...state.htdfl, htdfTableIndex: index },
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -97,7 +97,7 @@ type rainFacSActions = {
|
||||
rainSearch: (txt: string, pageNation: number, code: string) => void;
|
||||
rainBdstReg: (data: customRainBdst, code: string | number) => void;
|
||||
rainBdstUpdate: (data: customRainBdst, code: string | number) => void;
|
||||
ResetRainTableIndex:(index:number)=>void;
|
||||
resetRainTableIndex:(index:number)=>void;
|
||||
};
|
||||
|
||||
export type rainFacType = rainFacState & rainFacSActions;
|
||||
@@ -265,7 +265,7 @@ export const rainFacActionsExport: (set: any) => rainFacSActions = (
|
||||
} finally {
|
||||
}
|
||||
},
|
||||
ResetRainTableIndex: (index: number) => {
|
||||
resetRainTableIndex: (index: number) => {
|
||||
// 1) 동일값도 '변경'으로 느끼게 잠깐 -1
|
||||
set((state: rainFacState) => ({
|
||||
...state,
|
||||
|
||||
@@ -1,28 +1,30 @@
|
||||
import { z } from "zod";
|
||||
|
||||
|
||||
export const validationMessages = {
|
||||
required: (field: string) => `${field}을(를) 입력해주세요.`,
|
||||
requiredSelect: (field: string) => `${field}을(를) 선택해주세요.`,
|
||||
yearFormat: '4자리 연도만 입력하세요',
|
||||
};
|
||||
required: (field: string) => `${field}을(를) 입력해주세요.`,
|
||||
requiredSelect: (field: string) => `${field}을(를) 선택해주세요.`,
|
||||
yearFormat: "4자리 연도만 입력하세요",
|
||||
};
|
||||
export const baseReuseBuildingSchema = z.object({
|
||||
bdstRuseFcltSn: z.number().nullish(),
|
||||
bdstInfoSn: z.number().nullish(),
|
||||
instlCmptnDt: z.coerce.date().default(() => new Date()),
|
||||
instlCst: z
|
||||
.number()
|
||||
.max(999_999_999_999, { message: "최대 1,000,000,000,000까지 입력 가능합니다." })
|
||||
.nullish(),
|
||||
.number()
|
||||
.max(999_999_999_999, {
|
||||
message: "최대 1,000,000,000,000까지 입력 가능합니다.",
|
||||
})
|
||||
.nullish(),
|
||||
operMngCd: z.string().optional().default(""),
|
||||
anlOperCst: z.number().default(0),
|
||||
instlCstSprtYn: z.string().default("Y"),
|
||||
instlCstSprtAmt: z.number().nullish(),
|
||||
grntchBdstCertYn: z.string().default("Y"),
|
||||
grntchBdstCertYr: z.string().refine(
|
||||
(val) => val === "" || /^\d{4}$/.test(val),
|
||||
{ message: "연도는 빈값 또는 4자리 숫자여야 합니다." }
|
||||
),
|
||||
grntchBdstCertYr: z
|
||||
.string()
|
||||
.refine((val) => val === "" || /^\d{4}$/.test(val), {
|
||||
message: "연도는 빈값 또는 4자리 숫자여야 합니다.",
|
||||
}),
|
||||
grntchBdstCertNo: z.string().default(""),
|
||||
grntchBdstCertGrd: z.string().default(""),
|
||||
crgRdctYn: z.string().default("N").nullish(), /// 안쓰는 값
|
||||
@@ -30,11 +32,11 @@ export const baseReuseBuildingSchema = z.object({
|
||||
crgRdctAmt: z.number().default(0), // 안쓰는 값
|
||||
ruseFcltFlg: z.string().default(""),
|
||||
bdstUsgCd: z
|
||||
.string()
|
||||
.default('000')
|
||||
.refine((val) => val.trim().length > 0, {
|
||||
message: validationMessages.requiredSelect("건축물용도"),
|
||||
}),
|
||||
.string()
|
||||
.default("000")
|
||||
.refine((val) => val.trim().length > 0, {
|
||||
message: validationMessages.requiredSelect("건축물용도"),
|
||||
}),
|
||||
lawTrgtYn: z.string().default("Y"),
|
||||
rgtr: z.string().nullish(),
|
||||
mdfr: z.string().nullish(),
|
||||
@@ -42,15 +44,17 @@ export const baseReuseBuildingSchema = z.object({
|
||||
|
||||
export const chgBuildingSchema = z.object({
|
||||
bdstInfoSn: z.number().nullish(),
|
||||
archChgPrmsnDt: z.coerce.date({required_error: validationMessages.required("허가일")}),
|
||||
archChgPrmsnDt: z.coerce.date({
|
||||
required_error: validationMessages.required("허가일"),
|
||||
}),
|
||||
archChgArea: z.string().default("-"),
|
||||
bdstChgNm: z.string().min(1, { message: validationMessages.requiredSelect("구분") }),
|
||||
rgtr:z.string().nullish(),
|
||||
mdfr:z.string().nullish(),
|
||||
bdstChgNm: z
|
||||
.string()
|
||||
.min(1, { message: validationMessages.requiredSelect("구분") }),
|
||||
rgtr: z.string().nullish(),
|
||||
mdfr: z.string().nullish(),
|
||||
});
|
||||
|
||||
|
||||
|
||||
export const htdflReuseBuildingSchema = z.object({
|
||||
bdstRuseFcltSn: z.number().nullish(),
|
||||
bdstInfoSn: z.number().nullish(),
|
||||
@@ -62,26 +66,25 @@ export const htdflReuseBuildingSchema = z.object({
|
||||
instlCstSprtAmt: z.number().nullish(),
|
||||
grntchBdstCertYn: z.string().default("Y"),
|
||||
grntchBdstCertYr: z
|
||||
.string()
|
||||
.max(4, { message: validationMessages.yearFormat })
|
||||
.refine(
|
||||
(year) => year.length === 0 || /^\d{4}$/.test(year),
|
||||
{
|
||||
.string()
|
||||
.max(4, { message: validationMessages.yearFormat })
|
||||
.refine((year) => year.length === 0 || /^\d{4}$/.test(year), {
|
||||
message: validationMessages.yearFormat,
|
||||
}
|
||||
)
|
||||
.nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
grntchBdstCertNo: z.string().default(""),
|
||||
grntchBdstCertGrd: z.string().default(""),
|
||||
crgRdctYn: z.string().default("N").nullish(), /// 안쓰는 값
|
||||
crgRdctBss: z.string().default("").nullish(), /// 안쓰는 값
|
||||
crgRdctAmt: z.number().default(0), // 안쓰는 값
|
||||
ruseFcltFlg: z.string().default(""),
|
||||
bdstUsgCd: z.number().default(0).nullish(),
|
||||
bdstUsgCd: z
|
||||
.string()
|
||||
.default("000")
|
||||
.refine((val) => val.trim().length > 0, {
|
||||
message: validationMessages.requiredSelect("건축물용도"),
|
||||
}),
|
||||
lawTrgtYn: z.string().default("Y").nullish(),
|
||||
rgtr: z.string().nullish(),
|
||||
mdfr: z.string().nullish(),
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ export type rswtFacState = {
|
||||
upHeadList: TableUpperProps[];
|
||||
rswtRes: customRswtBdst[];
|
||||
rswtResCount: number;
|
||||
rswtTableIndex?: number;
|
||||
};
|
||||
};
|
||||
type rswtFacSActions = {
|
||||
@@ -74,6 +75,7 @@ type rswtFacSActions = {
|
||||
code: string | number
|
||||
) => void;
|
||||
rswtBdstReg: (data: customRswtBdst, code: string | number) => void;
|
||||
resetRswtTableIndex:(index:number)=>void;
|
||||
};
|
||||
|
||||
export type rswtFacType = rswtFacState & rswtFacSActions;
|
||||
@@ -219,7 +221,6 @@ export const rswtFacActionsExport: (set: any) => rswtFacSActions = (
|
||||
|
||||
if (chch.status === 200) {
|
||||
|
||||
console.log('chch.status', chch.status)
|
||||
toast.success("건축물(중수도) 및 증축/개축/중축 등록이 완료되었습니다.");
|
||||
} else {
|
||||
toast.error("건축물(중수도 증축/개축/중축 오류입니다.");
|
||||
@@ -233,7 +234,7 @@ export const rswtFacActionsExport: (set: any) => rswtFacSActions = (
|
||||
const rswtRes = await initFetch(code);
|
||||
set((state: rswtFacState) => ({
|
||||
...state,
|
||||
rain: {
|
||||
rswt: {
|
||||
...state.rswt,
|
||||
rswtRes: rswtRes.data,
|
||||
rswtResCount: rswtRes.count,
|
||||
@@ -245,5 +246,19 @@ export const rswtFacActionsExport: (set: any) => rswtFacSActions = (
|
||||
} finally {
|
||||
}
|
||||
},
|
||||
resetRswtTableIndex: (index: number) => {
|
||||
// 1) 동일값도 '변경'으로 느끼게 잠깐 -1
|
||||
set((state: rswtFacState) => ({
|
||||
...state,
|
||||
rswt: { ...state.rswt, rswtTableIndex: -1 },
|
||||
}));
|
||||
// 2) 다음 마이크로태스크에서 진짜 값 복구
|
||||
Promise.resolve().then(() => {
|
||||
set((state: rswtFacState) => ({
|
||||
...state,
|
||||
rswt: { ...state.rswt, rswtTableIndex: index },
|
||||
}));
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -67,8 +67,8 @@ export default function BdstReg({ form, type }: { form: any; type?: string }) {
|
||||
}, [form.form]);
|
||||
|
||||
useEffect(() => {
|
||||
const bdstInfoSn = form.getValues("bdstInfoSn");
|
||||
if (bdstInfoSn && bdstInfoSn > 0) form.setValue("daddr", bdstInfoSn);
|
||||
//const bdstInfoSn = form.getValues("bdstInfoSn");
|
||||
// if (bdstInfoSn && bdstInfoSn > 0) form.setValue("daddr", bdstInfoSn);
|
||||
}, [form.getValues("bdstInfoSn")]);
|
||||
|
||||
const userCtpvCd = form.watch("ctpvCd");
|
||||
|
||||
@@ -42,7 +42,8 @@ export default function HtdflRegForm({
|
||||
setIsModal?: (modal: boolean) => void;
|
||||
isMap?: boolean;
|
||||
}) {
|
||||
const { code, htdflBdstUpdate, htdflBdstReg } = useWrStore((state) => state);
|
||||
const { auth, code, htdflBdstUpdate, htdflBdstReg, resetHtdflTableIndex } =
|
||||
useWrStore((state) => state);
|
||||
const [frontPHdata, setFrontPHdata] = useState("");
|
||||
const [backPHdata, setBackPHdata] = useState("");
|
||||
|
||||
@@ -52,12 +53,14 @@ export default function HtdflRegForm({
|
||||
resolver: zodResolver(hdtflZod),
|
||||
defaultValues: defaultValues,
|
||||
});
|
||||
const { laeSeCd } = auth;
|
||||
|
||||
const [regCtpvCd, regSggcd] = form.watch(["ctpvCd", "sggCd"]);
|
||||
|
||||
const bdstNm = form.watch("bdstNm");
|
||||
const isPowerPlant = bdstNm?.includes("발전소");
|
||||
const { t } = useTranslation("base");
|
||||
const onSubmit = (values: z.infer<typeof hdtflZod>) => {
|
||||
const onSubmit = async (values: z.infer<typeof hdtflZod>) => {
|
||||
if (isModal) {
|
||||
const data = regCtpvCd ? regCtpvCd : regSggcd ? regSggcd : "noCd";
|
||||
if (data === "noCd") {
|
||||
@@ -71,7 +74,9 @@ export default function HtdflRegForm({
|
||||
confirmToast(t("isInsertMsg"), handleConfirm);
|
||||
} else {
|
||||
const handleConfirm = async () => {
|
||||
htdflBdstUpdate(values, "0");
|
||||
await htdflBdstUpdate(values, laeSeCd);
|
||||
console.log(' htdflBdstUpdate ')
|
||||
resetHtdflTableIndex(0);
|
||||
};
|
||||
confirmToast(t("isUpdateMsg"), handleConfirm);
|
||||
}
|
||||
@@ -194,7 +199,7 @@ export default function HtdflRegForm({
|
||||
const firstYnValue = code.yn?.[0]?.val;
|
||||
const firstHtdPowerMthdCd = code.htdPowerMthdCd?.[0]?.val;
|
||||
const firstHtdUtztnUsgCd = code.htdUtztnUsgCd?.[0]?.val;
|
||||
|
||||
console.log('htdflForm ', htdflForm)
|
||||
if (firstHtdPowerMthdCd) {
|
||||
form.setValue(
|
||||
"reuseBuilding.0.htdflObj.etgtType",
|
||||
|
||||
@@ -38,7 +38,7 @@ export default function RainRegForm({
|
||||
readonly?: boolean;
|
||||
isMap?: boolean;
|
||||
}) {
|
||||
const { auth,code, rainBdstReg, rainBdstUpdate ,ResetRainTableIndex} = useWrStore(
|
||||
const { auth,code, rainBdstReg, rainBdstUpdate ,resetRainTableIndex} = useWrStore(
|
||||
(state) => state
|
||||
);
|
||||
const { rainFcltCd } = code;
|
||||
@@ -145,7 +145,7 @@ export default function RainRegForm({
|
||||
} else {
|
||||
const handleConfirm = async () => {
|
||||
await rainBdstUpdate(values, laeSeCd);
|
||||
ResetRainTableIndex(0)
|
||||
resetRainTableIndex(0)
|
||||
};
|
||||
confirmToast(t('isUpdateMsg'), handleConfirm);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import BdstAdd from "../bdstReg/bdstAdd";
|
||||
import BdstReg from "../bdstReg/bdstReg";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { numSize, txtSize } from "@/app/store/common/code/basicCode";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
export default function RswtrRegForm({
|
||||
rswtForm,
|
||||
@@ -42,13 +43,15 @@ export default function RswtrRegForm({
|
||||
readonly?: boolean;
|
||||
isMap?: boolean;
|
||||
}) {
|
||||
const { code, rswtBdstUpdate, rswtBdstReg } = useWrStore((state) => state);
|
||||
const { auth,code, rswtBdstUpdate, rswtBdstReg ,resetRswtTableIndex} = useWrStore((state) => state);
|
||||
// const [divStyle, setDivStyle] = useState("h-[53vh]");
|
||||
const {laeSeCd } = auth;
|
||||
useEffect(() => {
|
||||
if (isMap) {
|
||||
}
|
||||
}, [isMap]);
|
||||
// const defaultValues: z.infer<typeof rswtZod> = rswtZod.parse({});
|
||||
const { t } = useTranslation("base");
|
||||
|
||||
const form = useForm<z.infer<typeof rswtZod>>({
|
||||
resolver: zodResolver(rswtZod),
|
||||
@@ -60,18 +63,26 @@ export default function RswtrRegForm({
|
||||
"reuseBuilding.0.instlCstSprtYn",
|
||||
"reuseBuilding.0.rswtrObj.filtrTrtmfctProcs",
|
||||
]);
|
||||
const [regCtpvCd, regSggcd] = form.watch(["ctpvCd", "sggCd"]);
|
||||
|
||||
const { t } = useTranslation("base");
|
||||
|
||||
|
||||
const onSubmit = (values: z.infer<typeof rswtZod>) => {
|
||||
if (isModal) {
|
||||
const data = regCtpvCd ? regCtpvCd : regSggcd ? regSggcd : "noCd";
|
||||
if (data === "noCd") {
|
||||
toast.error("시도/시군구 코드를 선택해야합니다.");
|
||||
return;
|
||||
}
|
||||
const handleConfirm = async () => {
|
||||
rswtBdstReg(values, "41");
|
||||
rswtBdstReg(values, data);
|
||||
if (setIsModal) setIsModal(false);
|
||||
};
|
||||
confirmToast(t("isInsertMsg"), handleConfirm);
|
||||
} else {
|
||||
const handleConfirm = async () => {
|
||||
rswtBdstUpdate(values, "41");
|
||||
rswtBdstUpdate(values, laeSeCd);
|
||||
resetRswtTableIndex(0)
|
||||
};
|
||||
confirmToast(t("isUpdateMsg"), handleConfirm);
|
||||
}
|
||||
@@ -114,6 +125,8 @@ export default function RswtrRegForm({
|
||||
useEffect(() => {
|
||||
console.log("form errors:", form.formState.errors);
|
||||
}, [form.formState.errors]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (grntchBdstCertYn === "N") {
|
||||
form.setValue("reuseBuilding.0.grntchBdstCertYr", "");
|
||||
|
||||
Reference in New Issue
Block a user