잠재수요처 페이지 오류 수정
This commit is contained in:
@@ -43,8 +43,9 @@ export default function LdrmntCoSttn() {
|
||||
const [objSearch, setObjSearch] = useState<objSearchType>({ sgg: "", city: "" });
|
||||
const [bdstTable, setBdstTable] = useState<customLdrmnt[]>();
|
||||
const [searchTxt, setSearchTxt] = useState<string>();
|
||||
const [excelData, setExcelData] = useState<any[]>();
|
||||
const [excelData, setExcelData] = useState<any[] | undefined>()
|
||||
const [resetPage, isResetPage] = useState(false);
|
||||
const [isDownloadClicked, setIsDownloadClicked] = useState(false);
|
||||
const { t } = useTranslation('base');
|
||||
|
||||
const excelClick = useCallback(() => {
|
||||
@@ -79,10 +80,31 @@ export default function LdrmntCoSttn() {
|
||||
|
||||
const excelDownloadClick = useCallback(() => {
|
||||
const cityNm = computeCityNm();
|
||||
setExcelData(undefined);
|
||||
setIsDownloadClicked(true);
|
||||
ldrmntSearch(true, 1, String(ldrmntResCount), cityNm, searchTxt || "");
|
||||
}, [objSearch, searchTxt, code, ldrmntSearch, computeCityNm, ldrmntResCount]);
|
||||
|
||||
useEffect(() => {
|
||||
const transData = Array.isArray(excelList) ? excelList : [excelList];
|
||||
const exData = tableData(transData, { code });
|
||||
const data = Array.isArray(exData)
|
||||
? exData.map((item: customLdrmnt) => {
|
||||
return {
|
||||
"시도": item.fctryAddr?.split(" ")[0] || "",
|
||||
"시군구": item.fctryAddr?.split(" ")[1] || "",
|
||||
"회사명": item.dmdCoNm,
|
||||
"공장주소": item.fctryAddr,
|
||||
"공장관리번호": item.fctryMngNo,
|
||||
"전화번호": item.telno
|
||||
}
|
||||
}) : [];
|
||||
setExcelData(data)
|
||||
}, [excelList])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isDownloadClicked) return;
|
||||
if (excelData === undefined) return;
|
||||
if (excelData && excelData.length > 0) {
|
||||
downloadExcel({
|
||||
data: excelData,
|
||||
@@ -93,7 +115,8 @@ export default function LdrmntCoSttn() {
|
||||
} else {
|
||||
toast.error(t('excelDownErrMsg'));
|
||||
}
|
||||
}, [excelData]);
|
||||
setIsDownloadClicked(false);
|
||||
}, [excelData, isDownloadClicked]);
|
||||
|
||||
const [isExcelOpen, setIsExcelOpen] = useState<{
|
||||
isModal: boolean;
|
||||
@@ -125,7 +148,7 @@ export default function LdrmntCoSttn() {
|
||||
|
||||
useEffect(() => {
|
||||
if (!ldrmnt.isInit) {
|
||||
ldrmntInit("0");
|
||||
ldrmntInit(false, "0");
|
||||
}
|
||||
}, [ldrmnt.isInit, ldrmntInit]);
|
||||
|
||||
@@ -144,23 +167,6 @@ export default function LdrmntCoSttn() {
|
||||
setBdstTable(tbData);
|
||||
}, [ldrmntRes, code]);
|
||||
|
||||
useEffect(() => {
|
||||
const transData = Array.isArray(excelList) ? excelList : [excelList];
|
||||
const exData = tableData(transData, { code });
|
||||
const data = Array.isArray(exData)
|
||||
? exData.map((item: customLdrmnt) => {
|
||||
return {
|
||||
"시도": item.fctryAddr?.split(" ")[0] || "",
|
||||
"시군구": item.fctryAddr?.split(" ")[1] || "",
|
||||
"회사명": item.dmdCoNm,
|
||||
"공장주소": item.fctryAddr,
|
||||
"공장관리번호": item.fctryMngNo,
|
||||
"전화번호": item.telno
|
||||
}
|
||||
}) : [];
|
||||
setExcelData(data)
|
||||
}, [excelList])
|
||||
|
||||
useEffect(() => {
|
||||
ldrmntSearch(false, pageNation, '20', computeCityNm(), searchTxt || "");
|
||||
isResetPage(false)
|
||||
@@ -264,10 +270,6 @@ export default function LdrmntCoSttn() {
|
||||
}}
|
||||
bodyClass={"w-[40vw] max-w-none max-h-[calc(100%-70px)]"}
|
||||
body={<CoDetailModal formObj={detailModal.data} onFormSubmit={async (value) => {
|
||||
// confirmToast(t('isUpdateMsg'), await ldrmntUpdate(value))
|
||||
// // await ldrmntUpdate(value)
|
||||
// setDetailModal({ ...detailModal, isOpen: false })
|
||||
// ldrmntSearch(false, pageNation, '20', computeCityNm(), searchTxt || "");
|
||||
const handleConfirm = async () => {
|
||||
await ldrmntUpdate(value);
|
||||
setDetailModal({ ...detailModal, isOpen: false });
|
||||
@@ -286,12 +288,8 @@ export default function LdrmntCoSttn() {
|
||||
body={<CoRegExcel isModal={(isOpen) => setIsExcelOpen({ isModal: isOpen })} />}
|
||||
/>
|
||||
<Toaster position="top-center"></Toaster>
|
||||
|
||||
</div>
|
||||
|
||||
</ContentsDiv>
|
||||
</>
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
@@ -29,11 +29,11 @@ type ExcelType = {
|
||||
[key: string]: string | number | undefined;
|
||||
};
|
||||
|
||||
const excelDownList: ExcelType[] = [];
|
||||
// const excelDownList: ExcelType[] = [];
|
||||
|
||||
type ldrmntActions = {
|
||||
ldrmntRegData: (data: any[]) => void,
|
||||
ldrmntInit: (con: string) => void
|
||||
ldrmntInit: (isExcel: boolean, con: string) => void
|
||||
ldrmntSearch: (isExcel: boolean, page: number, sggCd: string, total: string, coNm: string) => void;
|
||||
ldrmntUpdate: (ldrmntRes: customLdrmnt) => void;
|
||||
ldrmntDelete: () => void;
|
||||
@@ -58,25 +58,47 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
|
||||
set: any
|
||||
) => {
|
||||
return {
|
||||
ldrmntInit: async (con: string) => {
|
||||
ldrmntInit: async (isExcel: boolean,con: string) => {
|
||||
try {
|
||||
const ldrmntRes = await getFetchWithCount(
|
||||
fetchType.WR,
|
||||
`/reuseFc/request/temp/1/20/${con}`
|
||||
);
|
||||
|
||||
set((state: ldrmntState) => {
|
||||
return {
|
||||
...state,
|
||||
ldrmnt: {
|
||||
...state.ldrmnt,
|
||||
ldrmntRes: ldrmntRes.data,
|
||||
ldrmntResCount: ldrmntRes.count,
|
||||
isInit: false,
|
||||
excelList: excelDownList,
|
||||
},
|
||||
}
|
||||
});
|
||||
if (isExcel) {
|
||||
const excelDownList: ExcelType[] = [];
|
||||
ldrmntRes.data.forEach((item: customLdrmnt) => {
|
||||
excelDownList.push({
|
||||
ctpvCd: item.ctpvCd,
|
||||
sggCd: item.sggCd,
|
||||
dmdCoNm: item.dmdCoNm,
|
||||
fctryAddr: item.fctryAddr,
|
||||
fctryMngNo: item.fctryMngNo,
|
||||
telno: item.telno,
|
||||
})
|
||||
})
|
||||
set((state: ldrmntState) => {
|
||||
return {
|
||||
...state,
|
||||
ldrmnt: {
|
||||
...state.ldrmnt,
|
||||
excelList: excelDownList,
|
||||
ldrmntResCount: ldrmntRes.count,
|
||||
},
|
||||
};
|
||||
});
|
||||
} else {
|
||||
set((state: ldrmntState) => {
|
||||
return {
|
||||
...state,
|
||||
ldrmnt: {
|
||||
...state.ldrmnt,
|
||||
ldrmntRes: ldrmntRes.data,
|
||||
ldrmntResCount: ldrmntRes.count,
|
||||
isInit: false,
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
@@ -96,6 +118,7 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
|
||||
await deleteFectch(
|
||||
`/reuseFc/request/temp`,
|
||||
);
|
||||
console.log("deleteFectch", deleteFectch)
|
||||
|
||||
const response = await postFectch(
|
||||
"/reuseFc/request/temp",
|
||||
@@ -121,7 +144,6 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
|
||||
fetchType.WR,
|
||||
searchUrl
|
||||
);
|
||||
console.log("알이에스", ldrmntRes)
|
||||
if (isExcel) {
|
||||
const excelDownList: ExcelType[] = [];
|
||||
ldrmntRes.data.forEach((item: customLdrmnt) => {
|
||||
@@ -144,7 +166,6 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
|
||||
},
|
||||
};
|
||||
});
|
||||
return excelDownList;
|
||||
} else
|
||||
set((state: ldrmntState) => {
|
||||
return {
|
||||
@@ -157,27 +178,26 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
|
||||
},
|
||||
};
|
||||
});
|
||||
return ldrmntRes;
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
},
|
||||
ldrmntUpdate: async (ldrmntRes: customLdrmnt) => {
|
||||
if(ldrmntRes)
|
||||
try {
|
||||
ldrmntRes.rgtr = TEST_UUID;
|
||||
const res = await putFectch(
|
||||
`/reuseFc/request/temp`,
|
||||
ldrmntRes
|
||||
);
|
||||
if (ldrmntRes)
|
||||
try {
|
||||
ldrmntRes.rgtr = TEST_UUID;
|
||||
const res = await putFectch(
|
||||
`/reuseFc/request/temp`,
|
||||
ldrmntRes
|
||||
);
|
||||
|
||||
if (res.ok) {
|
||||
toast.success("잠재수요처 상세정보가 수정되었습니다.",)
|
||||
if (res.ok) {
|
||||
toast.success("잠재수요처 상세정보가 수정되었습니다.",)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error ldrmntUpdate:", error);
|
||||
toast.error("잠재수요처 상세정보 수정에 실패하였습니다.")
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error ldrmntUpdate:", error);
|
||||
toast.error("잠재수요처 상세정보 수정에 실패하였습니다.")
|
||||
}
|
||||
},
|
||||
ldrmntDelete: async () => {
|
||||
try {
|
||||
@@ -193,7 +213,6 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
|
||||
await deleteFectch(
|
||||
`/reuseFc/request/temp`,
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
console.log("error", error)
|
||||
set((state: ldrmntState) => {
|
||||
|
||||
@@ -89,7 +89,7 @@ export default function CoRegExcel({
|
||||
<h3 className="text-2xl font-bold text-gray-900 mt-1 ml-7">
|
||||
{"잠재수요처 파일"}
|
||||
</h3>
|
||||
<Button className="" type="submit" size={"sm"} onClick={onSubmit}>
|
||||
<Button className="" type="submit" size={"sm"}>
|
||||
저장
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user