하수재이용시설 파일테스트 등록 테스트 완료
This commit is contained in:
@@ -89,7 +89,6 @@ export default function PublicReuseFaciltyInsert() {
|
||||
}, [pbnst.isInit, pubHasuInit]);
|
||||
|
||||
const onSubmit = async (valuse: { items: PbnstRegArrrayType }) => {
|
||||
|
||||
if (!isDirty) {
|
||||
toast.error("변경사항이 없습니다."); // 변경사항이 없으면 메시지 표시
|
||||
return;
|
||||
@@ -98,6 +97,8 @@ export default function PublicReuseFaciltyInsert() {
|
||||
data.forEach((fclt) => {
|
||||
bizs = [...bizs, ...fclt.fcBizs];
|
||||
});
|
||||
|
||||
|
||||
const pbnst = data.map((fclt) => {
|
||||
return {
|
||||
pbnstRuseFcltPk: fclt.pbnstRuseFcltPk,
|
||||
@@ -390,7 +391,6 @@ export default function PublicReuseFaciltyInsert() {
|
||||
formType="update"
|
||||
form={form}
|
||||
setIndexMng={(index: number) => {
|
||||
console.log("setIndexMng", index);
|
||||
setIndexMng(index);
|
||||
}}
|
||||
indexMng={indexMng}
|
||||
|
||||
@@ -177,9 +177,6 @@ export const pubFacActionsExport: (set: any) => pubFacActions = (set: any) => {
|
||||
pubHasuInit: async (page: string, sggOrCity: string) => {
|
||||
try {
|
||||
const pbnstHasuRes = await hasuListFetch(page, sggOrCity);
|
||||
|
||||
|
||||
|
||||
return set((state: pubFacState) => ({
|
||||
...state,
|
||||
pbnst: {
|
||||
@@ -222,22 +219,6 @@ export const pubFacActionsExport: (set: any) => pubFacActions = (set: any) => {
|
||||
console.log(errorHasu);
|
||||
}
|
||||
},
|
||||
|
||||
// pbnstReg: async (txt: string | undefined) => {
|
||||
// try {
|
||||
// const pbnstRes = await hasuListFetch("11", "11");
|
||||
// return set((state: pubFacState) => ({
|
||||
// ...state,
|
||||
// pbnst: {
|
||||
// ...state.pbnst,
|
||||
// pbnstRes: pbnstRes,
|
||||
// isInit: false,
|
||||
// },
|
||||
// }));
|
||||
// } catch (errorHasu) {
|
||||
// console.log(errorHasu);
|
||||
// }
|
||||
// },
|
||||
pbnstInsert: async (pbnstRes: customPbnst) => {
|
||||
try {
|
||||
|
||||
@@ -249,8 +230,6 @@ export const pubFacActionsExport: (set: any) => pubFacActions = (set: any) => {
|
||||
toast.success(`${pbnstRes.ruseUtztnFcltNm} 하수재이용 시설이 등록되었습니다.`);
|
||||
}
|
||||
const pbnstHasuRes = await hasuListFetch('1', '0');
|
||||
|
||||
|
||||
return set((state: pubFacState) => ({
|
||||
...state,
|
||||
pbnst: {
|
||||
@@ -276,25 +255,13 @@ export const pubFacActionsExport: (set: any) => pubFacActions = (set: any) => {
|
||||
} ,pbnstRuseBizUpdate : async(ruseRes:fcBizType[])=>{
|
||||
try {
|
||||
|
||||
console.log('ruseRes ', ruseRes)
|
||||
const response = await putFectch(
|
||||
`/reuseFc/pubFcBiz`,
|
||||
ruseRes
|
||||
);
|
||||
|
||||
// const pbnstRes = await hasuListFetch("11", "11");
|
||||
|
||||
// return set((state: pubFacState) => ({
|
||||
// ...state,
|
||||
// pbnst: {
|
||||
// ...state.pbnst,
|
||||
// pbnstRes: pbnstRes,
|
||||
// isInit: false,
|
||||
// },
|
||||
// }));
|
||||
} catch (error) {
|
||||
console.error("Error pbnstRuseFcltUpdate:", error);
|
||||
// toast.error(` 하수재이용 시설 사업이 수정이 실패되엇습니다..`);
|
||||
}
|
||||
} ,
|
||||
getBizCycle: async (pbnstObj: customPbnst) => {
|
||||
@@ -341,50 +308,33 @@ export const pubFacActionsExport: (set: any) => pubFacActions = (set: any) => {
|
||||
fetchType.CS,
|
||||
`/attach-service/api/v1/atflcd/download/${atflCd}`
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error downloading file:", error);
|
||||
throw new Error(`Error downloading file: ${error}`);
|
||||
|
||||
}
|
||||
},
|
||||
fileInfoUpdate:async(atflCd: string)=>{
|
||||
|
||||
const WrTableInfo={
|
||||
"lnkgDmnNm": "tbWrRuseFcltFile",
|
||||
"lnkgDmnId": "fileTkn"
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await putFectch(
|
||||
`/attach-service/api/v1/atfl/attachments/${atflCd}/info`,
|
||||
WrTableInfo,
|
||||
fetchType.CS
|
||||
)
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error downloading file: ${response.statusText}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error downloading file:", error);
|
||||
}catch(e){
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
// pbnstMngData: (data: customPbnst[]) => {
|
||||
// if (data.length > 0) {
|
||||
// }
|
||||
// return set((state: pubFacState) => {
|
||||
// state.pbnst.pbnstMngRegData = data;
|
||||
// state.pbnst.pbnstBizCycle =
|
||||
// data.length <= 0
|
||||
// ? [{ text: "없음", val: "1" }]
|
||||
// : state.pbnst.pbnstBizCycle;
|
||||
// return state;
|
||||
// });
|
||||
// },
|
||||
|
||||
// pbnstBizData: (data: fcBizType) => {
|
||||
// return set((state: pubFacState) => {
|
||||
// if (state.pbnst.pbnstMngRegData) {
|
||||
// const regData = state.pbnst.pbnstMngRegData.find(
|
||||
// (item) => data.pbnstRuseFcltFk === item.pbnstRuseFcltPk
|
||||
// );
|
||||
// if (regData) {
|
||||
// const bizIdx = regData.fcBizs.findIndex(
|
||||
// (item) => item.pbnstRuseFcltBizPk == data.pbnstRuseFcltBizPk
|
||||
// );
|
||||
|
||||
// if (bizIdx >= 0) {
|
||||
// regData.fcBizs[bizIdx] = data;
|
||||
// const pbnstData = state.pbnst.pbnstMngRegData
|
||||
// state.pbnst.pbnstMngRegData= [...pbnstData]
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return state;
|
||||
// });
|
||||
// },
|
||||
getpbnstInsertIndex: async (data: pbnstInsertIndex) => {
|
||||
return set((state: pubFacState) => {
|
||||
state.pbnst.pbnsUpdateIndex = data;
|
||||
@@ -420,9 +370,7 @@ export const pubFacActionsExport: (set: any) => pubFacActions = (set: any) => {
|
||||
fcOrgwtsNmList:fcOrgwtsNmList.data??[]
|
||||
},
|
||||
}));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -108,8 +108,18 @@ export const postFectch = async (url: string, params: any, type?: string) => {
|
||||
return await response.json();
|
||||
};
|
||||
|
||||
export const putFectch = async (url: string, params: any) => {
|
||||
const response = await fetch(DEV_URL_WR + url, {
|
||||
export const putFectch = async (url: string, params: any,type?:string) => {
|
||||
const div =
|
||||
type === fetchType.COMMON
|
||||
? DEV_URL_FO
|
||||
: type === fetchType.LOCAL
|
||||
? LOCAL_URL
|
||||
: type === fetchType.CS
|
||||
? ''
|
||||
: DEV_URL_WR;
|
||||
|
||||
|
||||
const response = await fetch(div + url, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -132,7 +142,6 @@ export const deleteFectch = async (url: string, params?: any, type?: string) =>
|
||||
? ''
|
||||
: DEV_URL_WR;
|
||||
|
||||
console.log("deleteFectch url", div + url);
|
||||
const response = await fetch(div + url, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
|
||||
@@ -7,6 +7,9 @@ import {
|
||||
} from "tus-js-client";
|
||||
import { CS_TUS_UPLOAD, CS_URL } from "../config";
|
||||
import type { FilesType } from "@/components/ui/form/fcltReg/pbnstReg/mngReg/mngRegForm";
|
||||
import { fetchType, putFectch } from "../api";
|
||||
import { error } from "console";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
type UploadOptions = {
|
||||
handleUploadStart?: (upload: Upload) => void;
|
||||
@@ -60,8 +63,30 @@ export const TusClientUpload = (oFile: FilesType, options?: UploadOptions) =>
|
||||
onSuccess(payload: OnSuccessPayload) {
|
||||
options?.handleSuccess?.(payload);
|
||||
if (fileInfo) {
|
||||
console.log('fileInfo', fileInfo);
|
||||
resolve(JSON.parse(fileInfo) as ReturnFileType);
|
||||
|
||||
|
||||
const WrTableInfo = {
|
||||
lnkgDmnNm: "tbWrRuseFcltFile",
|
||||
lnkgDmnId: "fileTkn",
|
||||
};
|
||||
|
||||
console.log('fileInfo ', fileInfo)
|
||||
const fileParse = JSON.parse(fileInfo) as ReturnFileType;
|
||||
putFectch(
|
||||
`/attach-service/api/v1/atfl/attachments/${fileParse.atflCd}/info`,
|
||||
WrTableInfo,
|
||||
fetchType.CS
|
||||
)
|
||||
.then((res) => {
|
||||
resolve(fileParse);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject({
|
||||
causingError: {
|
||||
cause: "파일 업로드 업데이트 실패",
|
||||
},
|
||||
} as DetailedError);
|
||||
});
|
||||
} else reject({} as DetailedError);
|
||||
},
|
||||
});
|
||||
@@ -71,6 +96,8 @@ export const TusClientUpload = (oFile: FilesType, options?: UploadOptions) =>
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
reject(e as DetailedError);
|
||||
|
||||
toast.error(String(e));
|
||||
}
|
||||
// setUpload(uploader);
|
||||
});
|
||||
|
||||
@@ -111,12 +111,9 @@ export function PbnstBuseForm({
|
||||
const fcOrgwts = form.watch(`items.${indexMng}.fcBizs.${indexBiz}.fcOrgwts`);
|
||||
|
||||
useEffect(() => {
|
||||
console.log("fcOrgwts", fcOrgwts);
|
||||
if (fcOrgwts && fcOrgwts?.length > 0) {
|
||||
const swtrmtFcltFkList = fcOrgwts?.map((item) => item.swtrmtFcltFk);
|
||||
|
||||
console.log("swtrmtFcltFkList ", swtrmtFcltFkList);
|
||||
|
||||
if (swtrmtFcltFkList.length > 0) {
|
||||
getFcOrgwts(
|
||||
swtrmtFcltFkList.filter((item): item is string => item != null),
|
||||
|
||||
@@ -9,9 +9,8 @@ import {
|
||||
} from "@common/business_components/ui";
|
||||
import { Form, FormField } from "@common/business_components/ui/form";
|
||||
import { Button, Input } from "@common/components";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useFieldArray, useWatch, type UseFormReturn } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useFieldArray, type UseFormReturn } from "react-hook-form";
|
||||
import {
|
||||
commonButonSize,
|
||||
formH1Class,
|
||||
@@ -19,7 +18,6 @@ import {
|
||||
} from "@/components/lib/class/comClass";
|
||||
import { TusClientUpload } from "@/components/lib/useTus_wr/useTusWr";
|
||||
import {
|
||||
pbnstRegZod,
|
||||
type customPbnst,
|
||||
type fcFileType,
|
||||
type PbnstRegArrrayType,
|
||||
@@ -50,11 +48,11 @@ export function PbnstMngForm({
|
||||
indexMng: number;
|
||||
setIndexMng: (index: number) => void;
|
||||
}) {
|
||||
const { code, pbnst, pbnstInsert, fileDelete, fileDownLoad } = useWrStore(
|
||||
const { code, pbnst, fileDelete, fileDownLoad } = useWrStore(
|
||||
(state) => state
|
||||
);
|
||||
|
||||
const { pbnstRes } = pbnst;
|
||||
const fileInitRef = useRef<{ index: number; key: string } | null>(null);
|
||||
const [regFileList, setRegFileList] = useState<fcFileType[] | null>(null);
|
||||
const [planFiles, setPlanFiles] = useState<FilesType[] | null>(null);
|
||||
const [relationfiles, setRelationFiles] = useState<FilesType[] | null>(null);
|
||||
@@ -71,11 +69,6 @@ export function PbnstMngForm({
|
||||
name: `items.${indexMng}.fcOpers`,
|
||||
});
|
||||
|
||||
const watchedItem = useWatch({
|
||||
control: form.control,
|
||||
name: `items.${indexMng}`,
|
||||
});
|
||||
|
||||
const plusHist = () => {
|
||||
prepend({
|
||||
choose: false,
|
||||
@@ -171,47 +164,49 @@ export function PbnstMngForm({
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (indexMng >= 0) {
|
||||
const defaultFiles = watchedItem?.fcFiles;
|
||||
if (defaultFiles && defaultFiles.length > 0) {
|
||||
const relationFileList = defaultFiles.filter(
|
||||
(item) => item.fileKnd === "계통도"
|
||||
);
|
||||
const currentItem = form.getValues(`items.${indexMng}`);
|
||||
const currentKey = JSON.stringify(currentItem);
|
||||
|
||||
const planFileList = defaultFiles.filter(
|
||||
(item) => item.fileKnd === "평면도"
|
||||
);
|
||||
if (relationFileList.length > 0)
|
||||
setRelationFiles(
|
||||
relationFileList.map((item) => ({
|
||||
atflCd: item.fileTkn,
|
||||
file: new File([] as BlobPart[], item.filePath),
|
||||
}))
|
||||
);
|
||||
else {
|
||||
setRelationFiles(null);
|
||||
}
|
||||
const isNewItem =
|
||||
!fileInitRef.current ||
|
||||
fileInitRef.current.index !== indexMng ||
|
||||
fileInitRef.current.key !== currentKey;
|
||||
|
||||
if (planFileList.length > 0)
|
||||
setPlanFiles(
|
||||
planFileList.map((item) => ({
|
||||
atflCd: item.fileTkn,
|
||||
file: new File([] as BlobPart[], item.filePath),
|
||||
}))
|
||||
);
|
||||
else {
|
||||
setPlanFiles(null);
|
||||
}
|
||||
} else {
|
||||
setRelationFiles(null);
|
||||
setPlanFiles(null);
|
||||
}
|
||||
}
|
||||
}, [watchedItem, indexMng]);
|
||||
if (!isNewItem) return; //
|
||||
|
||||
const defaultFiles = currentItem?.fcFiles || [];
|
||||
|
||||
const relationFileList = defaultFiles.filter(
|
||||
(item) => item.fileKnd === "계통도"
|
||||
);
|
||||
const planFileList = defaultFiles.filter(
|
||||
(item) => item.fileKnd === "평면도"
|
||||
);
|
||||
|
||||
setRelationFiles(
|
||||
relationFileList.length > 0
|
||||
? relationFileList.map((item) => ({
|
||||
atflCd: item.fileTkn,
|
||||
file: new File([], item.filePath),
|
||||
}))
|
||||
: null
|
||||
);
|
||||
|
||||
setPlanFiles(
|
||||
planFileList.length > 0
|
||||
? planFileList.map((item) => ({
|
||||
atflCd: item.fileTkn,
|
||||
file: new File([], item.filePath),
|
||||
}))
|
||||
: null
|
||||
);
|
||||
// ✅ 다음 루프에선 다시 안 하도록 저장
|
||||
fileInitRef.current = {
|
||||
index: indexMng,
|
||||
key: currentKey,
|
||||
};
|
||||
}, [indexMng, form.getValues(`items.${indexMng}`)]);
|
||||
|
||||
useEffect(() => {
|
||||
// pbnstMngData(pbnst.pbnstMngRegData);
|
||||
}, [pbnst.pbnstMngRegData]);
|
||||
|
||||
useEffect(() => {
|
||||
if (pbnst.pbnstRes && pbnst.pbnstRes?.length >= 0) {
|
||||
@@ -220,19 +215,17 @@ export function PbnstMngForm({
|
||||
val: String(index),
|
||||
}));
|
||||
|
||||
console.log(" fcltNmList ", fcltNmList);
|
||||
if (fcltNmList) setFcltNm(fcltNmList);
|
||||
} else {
|
||||
setFcltNm(null);
|
||||
}
|
||||
}, [pbnst.pbnstRes]);
|
||||
|
||||
// 2. Define a submit handler.
|
||||
function onSubmit(values: z.infer<typeof pbnstRegZod>) {
|
||||
values.fcOpers = [];
|
||||
values.fcFiles = regFileList || [];
|
||||
pbnstInsert(values);
|
||||
}
|
||||
useEffect(() => {
|
||||
if (regFileList && regFileList?.length > 0) {
|
||||
form.setValue(`items.${indexMng}.fcFiles`, regFileList);
|
||||
}
|
||||
}, [regFileList, indexMng]);
|
||||
|
||||
useEffect(() => {
|
||||
if (relationfiles) {
|
||||
@@ -245,20 +238,18 @@ export function PbnstMngForm({
|
||||
}
|
||||
}, [planFiles]);
|
||||
|
||||
useEffect(() => {
|
||||
if (regFileList && regFileList?.length > 0) {
|
||||
form.setValue(`items.${indexMng}.fcFiles`, regFileList);
|
||||
}
|
||||
}, [regFileList, indexMng]);
|
||||
|
||||
useEffect(() => {
|
||||
if (code.ruseMngMtd) {
|
||||
setMngMtdCode([{ name: "ruseMngMtd", val: code.ruseMngMtd }]);
|
||||
}
|
||||
}, [code]);
|
||||
|
||||
useEffect(() => {
|
||||
// console.log(' fcltNm ', watchedItem?.ruseUtztnFcltNm)
|
||||
}, [watchedItem]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(" form indexMng ", indexMng);
|
||||
}, [indexMng]);
|
||||
|
||||
return (
|
||||
<div className=" !mx-[1.6rem] !p-0r">
|
||||
<div>
|
||||
@@ -342,11 +333,11 @@ export function PbnstMngForm({
|
||||
headList={
|
||||
formType === "sttn"
|
||||
? pbnst.pbnstMngUpHeadList.map((item) => {
|
||||
return {
|
||||
...item,
|
||||
readonly: true,
|
||||
};
|
||||
})
|
||||
return {
|
||||
...item,
|
||||
readonly: true,
|
||||
};
|
||||
})
|
||||
: pbnst.pbnstMngUpHeadList
|
||||
}
|
||||
upHeadList={pbnst.pbnstMngNm}
|
||||
@@ -357,7 +348,7 @@ export function PbnstMngForm({
|
||||
indexMng={indexMng}
|
||||
form={form}
|
||||
formNm={"fcOpers"}
|
||||
// ref={ref}
|
||||
// ref={ref}
|
||||
></RuseMngTableForm>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user