잠재수요처 엑셀 등록 시 로딩바 추가

This commit is contained in:
jyha00
2025-07-03 19:46:11 +09:00
parent bcf57b21ca
commit b20948fcfe
3 changed files with 69 additions and 41 deletions
@@ -28,8 +28,10 @@ import {
type SelectDataType
} from "@common/business_components/ui";
import ListDiv from "@common/business_components/ui/list_div";
import LoadingOverlay from "@common/business_components/ui/loadingBar";
import { Button } from "@common/components/ui";
import { useCallback, useEffect, useRef, useState } from "react";
import { Toaster } from "react-hot-toast";
export default function LdrmntCoSttn() {
const { code, ldrmnt, ldrmntInit, ldrmntSearch, } = useWrStore(
@@ -273,7 +275,7 @@ export default function LdrmntCoSttn() {
<div className="overflow-x-auto">
<ListDiv className="min-w-max">
<UiTable
headName={[]}
headName={undefined}
tableData={bdstTable || []}
headlist={ldrmntHeadListExport}
pageSize={20}
@@ -299,8 +301,9 @@ export default function LdrmntCoSttn() {
setIsExcelOpen({ isModal: !isExcelOpen.isModal })
}}
bodyClass={"w-[40vw] max-w-none"}
body={<CoRegExcel />}
body={<CoRegExcel isModal={(isOpen) => setIsExcelOpen({ isModal: isOpen })} />}
/>
<Toaster position="top-center"></Toaster>
</div>
+43 -21
View File
@@ -20,6 +20,7 @@ export type ldrmntState = {
excelList: ExcelType[];
isInit: boolean;
ldrmntRes: customLdrmnt[];
isLoading: boolean;
};
};
@@ -35,6 +36,7 @@ type ldrmntActions = {
ldrmntSearch: (page: number, sggCd: string, total: string, coNm: string) => void;
ldrmntUpdate: (ldrmntRes: customLdrmnt) => void;
ldrmntDelete: () => void;
loadingOpen: (isOpen: boolean) => void
};
export type ldrmntType = ldrmntState & ldrmntActions;
@@ -46,6 +48,7 @@ export const ldrmntStateExport: ldrmntState = {
excelList: [],
isInit: false,
ldrmntRes: ldrmntRes,
isLoading: false,
},
};
@@ -75,31 +78,30 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
console.log(e)
}
},
loadingOpen: (isOpen) => {
return set((state: ldrmntState) => {
return {
...state,
ldrmnt: {
...state.ldrmnt,
isLoading: isOpen,
},
};
});
},
ldrmntRegData: async (data) => {
try {
const response = await postFectch(
"/reuseFc/request/temp",
data,
fetchType.WR
);
await deleteFectch(
`/reuseFc/request/temp`,
);
console.log('response ', response)
const response = await postFectch(
"/reuseFc/request/temp",
data,
fetchType.WR
);
if (response.status === 200) {
ToastFormUi({
body: "잠재수요처 등록이 완료되었습니다. ",
title: "잠재수요처 등록",
});
console.log('response ', response)
}
} catch (e) {
console.log(e)
ToastFormUi({
body: "잠재수요처 등록이 실패하였습니다. ",
title: "잠재수요처 등록",
});
}
},
ldrmntSearch: async (page: number, total: string, sggCd: string, coNm: string) => {
let searchUrl = "";
@@ -111,6 +113,7 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
searchUrl = `/reuseFc/request/temp/${page}/${total}/${sggCd}`;
}
}
try {
const ldrmntRes = await getFetch(
fetchType.WR,
@@ -178,11 +181,30 @@ export const ldrmntActionsExport: (set: any) => ldrmntActions = (
},
ldrmntDelete: async () => {
try {
set((state: ldrmntState) => {
return {
...state,
ldrmnt: {
...state.ldrmnt,
isLoading: true,
},
};
});
const response = await deleteFectch(
`/reuseFc/request/temp`,
);
} catch (error) {
console.log("error", error)
set((state: ldrmntState) => {
return {
...state,
ldrmnt: {
...state.ldrmnt,
isLoading: false,
},
};
});
console.error("Error ldrmntDelete:", error);
}
},
@@ -4,32 +4,36 @@ import type { customLdrmnt } from "@/app/store/matDmd/ldrmntCoSttn";
import { names } from "@/app/store/matDmd/ldrmntCoSttn/excel";
import { filePicked, FileUpload, FormUi, Title } from "@common/business_components/ui";
import { Form, FormField } from "@common/business_components/ui/form";
import LoadingOverlay from "@common/business_components/ui/loadingBar";
import { Button, Progress } from "@common/components/ui";
import { zodResolver } from "@hookform/resolvers/zod";
import { useEffect, useState } from "react";
import { useForm } from "react-hook-form";
import toast from "react-hot-toast";
import type { z } from "zod";
export default function CoRegExcel() {
export default function CoRegExcel({ isModal }: { isModal: (open: boolean) => void }) {
const { ldrmnt,loadingOpen } = useWrStore((state) => state);
const { isLoading } = ldrmnt;
const form = useForm<z.infer<typeof coRegExcel>>({
resolver: zodResolver(coRegExcel),
});
const { ldrmntRegData, ldrmntDelete } = useWrStore((state) => state);
const [excelData, setExcelData] = useState<customLdrmnt[]>();
const [file, setFiles] = useState<File | undefined>();
useEffect(() => {
console.log("ldrmnt", ldrmnt)
}, [ldrmnt])
const onSubmit = (values: z.infer<typeof coRegExcel>) => {
ldrmntDelete();
loadingOpen(true);
if (file) {
filePicked(file, 0).then((res) => {
//TODO:loading
filePicked(file, 0).then(async (res) => {
try {
let array: { [key: string]: string | number }[] = []
let isError = false;
if (Array.isArray(res)) {
res.some((item, index) => {
let object: { [key: string]: string | number } = {}
@@ -43,26 +47,24 @@ export default function CoRegExcel() {
}
return false;
})
if (isError === true)
return true;
array.push(object)
if (index != 0 && index % 5000 == 0) {
ldrmntRegData(array);
array = []
array.length = 0;
}
return false;
})
}
if (isError === false)
ldrmntRegData(array);
await ldrmntRegData(array);
isModal(false);
loadingOpen(false);
toast.success(`잠재수요처 등록이 완료되었습니다.`);
} catch (e) {
console.log(e)
loadingOpen(false);
alert(e)
return true;
}
}).catch((e)=>{
console.log("file", e);
});
};
}
@@ -70,6 +72,7 @@ export default function CoRegExcel() {
return (
<>
<div>
<LoadingOverlay isLoading={isLoading}></LoadingOverlay>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<div>