add_cow_data_batch_insert
This commit is contained in:
@@ -73,6 +73,7 @@ interface UploadState {
|
||||
status: "idle" | "uploading" | "success" | "error"
|
||||
message: string
|
||||
isDragging: boolean
|
||||
fileType: FileType
|
||||
}
|
||||
|
||||
function FileUploadCard({ fileType }: { fileType: FileType }) {
|
||||
@@ -81,6 +82,7 @@ function FileUploadCard({ fileType }: { fileType: FileType }) {
|
||||
status: "idle",
|
||||
message: "",
|
||||
isDragging: false,
|
||||
fileType: fileType,
|
||||
})
|
||||
const fileInputRef = React.useRef<HTMLInputElement>(null)
|
||||
|
||||
@@ -109,7 +111,7 @@ function FileUploadCard({ fileType }: { fileType: FileType }) {
|
||||
const files = e.dataTransfer.files
|
||||
if (files && files.length > 0) {
|
||||
const file = files[0]
|
||||
if (isValidExcelFile(file)) {
|
||||
if (isValidFile(file)) {
|
||||
setState(prev => ({ ...prev, file, status: "idle", message: "" }))
|
||||
} else {
|
||||
setState(prev => ({
|
||||
@@ -125,7 +127,7 @@ function FileUploadCard({ fileType }: { fileType: FileType }) {
|
||||
const files = e.target.files
|
||||
if (files && files.length > 0) {
|
||||
const file = files[0]
|
||||
if (isValidExcelFile(file)) {
|
||||
if (isValidFile(file)) {
|
||||
setState(prev => ({ ...prev, file, status: "idle", message: "" }))
|
||||
} else {
|
||||
setState(prev => ({
|
||||
@@ -137,18 +139,21 @@ function FileUploadCard({ fileType }: { fileType: FileType }) {
|
||||
}
|
||||
}
|
||||
|
||||
const isValidExcelFile = (file: File): boolean => {
|
||||
const isValidFile = (file: File): boolean => {
|
||||
const validExtensions = [
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"application/vnd.ms-excel",
|
||||
"text/csv",
|
||||
"application/csv",
|
||||
"application/haansoftxls",
|
||||
"text/plain",
|
||||
]
|
||||
return (
|
||||
validExtensions.includes(file.type) ||
|
||||
file.name.endsWith(".xlsx") ||
|
||||
file.name.endsWith(".xls") ||
|
||||
file.name.endsWith(".csv")
|
||||
file.name.endsWith(".csv") ||
|
||||
file.name.endsWith(".txt")
|
||||
)
|
||||
}
|
||||
|
||||
@@ -167,16 +172,28 @@ function FileUploadCard({ fileType }: { fileType: FileType }) {
|
||||
try {
|
||||
const formData = new FormData()
|
||||
formData.append("file", state.file)
|
||||
formData.append("fileType", fileType.fileType)
|
||||
formData.append("div", state.fileType.id)
|
||||
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/uploadfile`, {
|
||||
|
||||
// const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/uploadfile`, {
|
||||
// method: "POST",
|
||||
// body: formData,
|
||||
// headers: {
|
||||
// 'Authorization': `Bearer ${localStorage.getItem('accessToken')}`,
|
||||
// },
|
||||
// })
|
||||
|
||||
// 배치 파일 업로드 테스트
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/admin/batchUpload`, {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
headers: {
|
||||
'Authorization': `Bearer ${localStorage.getItem('accessToken')}`,
|
||||
'Authorization': `Bearer ${useAuthStore.getState().accessToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("파일 업로드에 실패했습니다.")
|
||||
}
|
||||
@@ -195,6 +212,7 @@ function FileUploadCard({ fileType }: { fileType: FileType }) {
|
||||
status: "idle",
|
||||
message: "",
|
||||
isDragging: false,
|
||||
fileType: fileType,
|
||||
})
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.value = ""
|
||||
@@ -218,6 +236,7 @@ function FileUploadCard({ fileType }: { fileType: FileType }) {
|
||||
status: "idle",
|
||||
message: "",
|
||||
isDragging: false,
|
||||
fileType: fileType,
|
||||
})
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.value = ""
|
||||
|
||||
@@ -525,9 +525,9 @@ export default function DashboardPage() {
|
||||
<div className="bg-white rounded-xl border border-slate-200 p-5 max-sm:p-4 shadow-sm hover:shadow-md transition-shadow">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<p className="text-base max-sm:text-sm font-semibold text-slate-700">번식능력검사 현황</p>
|
||||
<span className="text-xs max-sm:text-[10px] px-2 py-1 rounded-full bg-pink-50 text-pink-700 font-medium">
|
||||
{/* <span className="text-xs max-sm:text-[10px] px-2 py-1 rounded-full bg-pink-50 text-pink-700 font-medium">
|
||||
검사 {mptStats.totalMptCows}두
|
||||
</span>
|
||||
</span> */}
|
||||
</div>
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 max-sm:gap-3">
|
||||
{/* 에너지 균형 */}
|
||||
|
||||
Reference in New Issue
Block a user