Merge branch 'iipbs/sn/dev' of https://www.onasys.co.kr:3000/ONAANDALL/frontend into iipbs/sn/ii
iipbs_sn / build (push) Waiting to run

This commit is contained in:
swcho
2025-05-27 10:19:43 +09:00
4 changed files with 39 additions and 41 deletions
+3 -3
View File
@@ -55,7 +55,7 @@ export const deleteData = async (url: string, data?: object): Promise<any> => {
},
body: data ? JSON.stringify(data) : undefined,
};
const res = await fetch(`${BASE_URL}/${url}`, options);
const resData = await res.json();
return resData;
const res = await fetch(url.startsWith('/') ? `${url}` : `${BASE_URL}/${url}`, options);
if(res.status === 204) return true
return res;
};
+9 -19
View File
@@ -1,11 +1,9 @@
"use client"
import { SelectBox } from '@common/business_components/ui';
import { Button, Input } from '@common/components/ui';
import React, { useState, useId } from 'react'
import type { HttpResponse, Upload } from "tus-js-client";
import { FileUploader } from "@common/components";
import { Button } from '@common/components/ui';
import { handleUpload } from "@utils";
import { set } from 'react-hook-form';
import { useId, useState } from 'react';
import type { HttpResponse, Upload } from "tus-js-client";
interface FileUploadFormProps {
onSubmit?: (files: string, year: string, quarter: string, code: string, id: string) => void;
@@ -21,12 +19,13 @@ const FileUploadForm = ({
onFileSelect,
showButton = true,
showPreview = false,
accept = ".jpeg,.jpg,.png",
accept = ".jpeg, .jpg, .png",
fileIdx // props에서 fileIdx 받기
}: FileUploadFormProps) => {
const [internalAtflCd, setInternalAtflCd] = useState<string | null>(null);
const [internalAtflId, setInternalAtflId] = useState<string | null>(null);
const [currentFile, setCurrentFile] = useState<File | null>(null); // 현재 선택된 파일을 저장할 상태
const [fileName, setFileName] = useState<string>('');
const [files, setFiles] = useState<FileList | null>(null);
const [upload, setUpload] = useState<Upload | null>(null);
const uniqueId = useId(); // 각 FileUploadForm 인스턴스에 대한 고유 ID 생성
@@ -40,18 +39,6 @@ const FileUploadForm = ({
const [selectedYear, setSelectedYear] = useState<string>(yearOptions[0]?.val || '');
const [selectedQuarter, setSelectedQuarter] = useState<string>(quater[0]?.val || '');
// const handleUploadResponse = (file: File) => async (res: HttpResponse) => {
// const fileInfo = res.getHeader("X-File-Info");
// if (!fileInfo) return;
// const { atflCd: newAtflCd, atflId: newAtflId } = JSON.parse(fileInfo) ?? {};
// const orgnlFileNm = file.name;
// console.log('orgnlFileNm', orgnlFileNm, atflCd, atflId);
// setAtflCd(newAtflCd);
// setAtflId(newAtflId);
// // 파일 정보가 업데이트되면 onFileSelect 호출
// if (onFileSelect) onFileSelect(file, newAtflCd, newAtflId);
// };
const internalHandleUploadResponse = (file: File) => async (res: HttpResponse) => {
const fileInfo = res.getHeader("X-File-Info");
if (!fileInfo) {
@@ -61,6 +48,7 @@ const FileUploadForm = ({
const { atflCd: newAtflCd, atflId: newAtflId } = JSON.parse(fileInfo) ?? {};
const orgnlFileNm = file.name;
console.log(`FileUploadForm (idx: ${fileIdx ?? 'N/A'}) - orgnlFileNm:`, orgnlFileNm, 'New AtflCd:', newAtflCd, 'New AtflId:', newAtflId);
setFileName(orgnlFileNm);
setInternalAtflCd(newAtflCd);
setInternalAtflId(newAtflId);
@@ -114,7 +102,7 @@ const FileUploadForm = ({
showPreview ? (
<div className="file-uploader-preview">
{files && files.length > 0
? Array.from(files).map((file) => file.name).join(", ")
? fileName
: "파일을 선택하세요."}
</div>
) : null
@@ -143,6 +131,8 @@ const FileUploadForm = ({
if (onSubmit) {
// 부모에게 전달할 때는 내부 상태인 internalAtflCd, internalAtflId 사용
onSubmit(fileNm, selectedYear, selectedQuarter, internalAtflCd || '', internalAtflId || '');
setFiles(null); // 파일 업로드 후 파일 목록 초기화
setFileName(''); // 파일명 초기화
}
}}
>