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

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
@@ -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>