diff --git a/apps/sn/app/components/lib/api/index.ts b/apps/sn/app/components/lib/api/index.ts index a171844a1..e2f5cbf95 100644 --- a/apps/sn/app/components/lib/api/index.ts +++ b/apps/sn/app/components/lib/api/index.ts @@ -55,7 +55,7 @@ export const deleteData = async (url: string, data?: object): Promise => { }, 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; }; \ No newline at end of file diff --git a/apps/sn/app/components/ui/fileUploadForm.tsx b/apps/sn/app/components/ui/fileUploadForm.tsx index 58712b130..0760b3252 100644 --- a/apps/sn/app/components/ui/fileUploadForm.tsx +++ b/apps/sn/app/components/ui/fileUploadForm.tsx @@ -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(null); const [internalAtflId, setInternalAtflId] = useState(null); const [currentFile, setCurrentFile] = useState(null); // 현재 선택된 파일을 저장할 상태 + const [fileName, setFileName] = useState(''); const [files, setFiles] = useState(null); const [upload, setUpload] = useState(null); const uniqueId = useId(); // 각 FileUploadForm 인스턴스에 대한 고유 ID 생성 @@ -40,18 +39,6 @@ const FileUploadForm = ({ const [selectedYear, setSelectedYear] = useState(yearOptions[0]?.val || ''); const [selectedQuarter, setSelectedQuarter] = useState(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 ? (
{files && files.length > 0 - ? Array.from(files).map((file) => file.name).join(", ") + ? fileName : "파일을 선택하세요."}
) : null @@ -143,6 +131,8 @@ const FileUploadForm = ({ if (onSubmit) { // 부모에게 전달할 때는 내부 상태인 internalAtflCd, internalAtflId 사용 onSubmit(fileNm, selectedYear, selectedQuarter, internalAtflCd || '', internalAtflId || ''); + setFiles(null); // 파일 업로드 후 파일 목록 초기화 + setFileName(''); // 파일명 초기화 } }} > diff --git a/apps/sn/app/oper/floodPre/page.tsx b/apps/sn/app/oper/floodPre/page.tsx index 661326090..ec0608fd7 100644 --- a/apps/sn/app/oper/floodPre/page.tsx +++ b/apps/sn/app/oper/floodPre/page.tsx @@ -12,18 +12,19 @@ import { formatDate } from '@/components/lib/utils/date' import { deleteData, getData, postData } from '@/components/lib/api' const Page = () => { + // 조회조건 const [fromDate, setFromDate] = useState(new Date()) const [toDate, setToDate] = useState(new Date()) const [manageYear, setManageYear] = useState('') const [mngQu, setMngQu] = useState('') const [usr, setUsr] = useState('') const [pjNm, setpjNm] = useState('') - const [fileNm, setFileNm] = useState('') - const [atflId, setAtflId] = useState('') - const [atflCd, setAtflCd] = useState('') - const [sbmrgPrevntBizSn, setSbmrgPrevntBizSn] = useState('') - const [tableData, setTableData] = useState([{}]) - const [curPage, setCurPage] = useState(1) + // 파일업로드 관련 상태 + const [fileNm, setFileNm] = useState('') //파일명 + const [atflId, setAtflId] = useState('') //파일 ID + const [sbmrgPrevntBizSn, setSbmrgPrevntBizSn] = useState('') //파일 일련번호 + const [tableData, setTableData] = useState([{}]) //테이블 데이터 + const [curPage, setCurPage] = useState(1) //현재 페이지 const fetchData = async () => { const data = await searchData('v1/sbmrgPrevnt', { fromRegDt: formatDate(fromDate), @@ -49,30 +50,29 @@ const Page = () => { handleDownload(`/attach-service/api/v1/download/${atflId}`, fileNm) } const isDeleteFile = async () => { - if (fileNm === '' || fileNm === undefined) { + if (sbmrgPrevntBizSn === '' || sbmrgPrevntBizSn === undefined) { alert('삭제할 파일을 선택해주세요') return false } - const data = await getData(`/attach-service/api/v1/atfl/attachments/${atflId}`) + const data = await deleteData(`/attach-service/api/v1/atfl/attachments/${atflId}`) if (data) { const delData = await deleteData(`v1/sbmrgPrevnt/${sbmrgPrevntBizSn}`) - if (delData) { + if (delData.status === 200) { alert('삭제되었습니다.') fetchData() - } else { - alert('삭제에 실패했습니다.') } } } - const registFile = async (fileNm: string, year: string, quater: string, cd: string, id: string) => { + const registFile = async (fileName: string, year: string, quater: string, cd: string, id: string) => { const data = await postData('v1/sbmrgPrevnt', { - atflNm: fileNm, + atflNm: fileName, mngYr: year, mngQu: quater, atflCd: cd, - atflId: id + atflId: id, + sbmrgPrevntBizNm:fileName }) - if (data.ok) { setAtflId(data.atflId); setAtflCd(data.atflCd) } + if (data) {alert('파일이 등록되었습니다.'); fetchData() } } return ( @@ -133,7 +133,7 @@ const Page = () => { - { if (index != null) { const fileName = tableData[index]?.fileNm ?? ""; setFileNm(fileName); setSbmrgPrevntBizSn(tableData[index]?.sbmrgPrevntBizSn) } }} onPageChange={async (page:number)=>{setCurPage(page); await fetchData()}}> + { if (index != null) {const fileName = tableData[index]?.sbmrgPrevntBizNm ?? ""; setFileNm(fileName); const id = tableData[index]?.atflId ?? ''; setAtflId(id); setSbmrgPrevntBizSn(tableData[index]?.sbmrgPrevntBizSn) } }} onPageChange={async (page:number)=>{setCurPage(page); await fetchData()}}> { await registFile(file, year, quater, cd, id) }} /> diff --git a/apps/sn/app/oper/index.ts b/apps/sn/app/oper/index.ts index f4ebe7eeb..54ba00374 100644 --- a/apps/sn/app/oper/index.ts +++ b/apps/sn/app/oper/index.ts @@ -1,9 +1,17 @@ export const tableHeadlist = [ { id: 'sbmrgPrevntBizSn', title: '일련번호' }, - { id: 'fileNm', title: '파일명' }, + { id: 'sbmrgPrevntBizNm', title: '파일명' }, { id: 'mngYr', title: '년도' }, { id: 'mngQu', title: '분기' }, - { id: 'registDt', title: '등록 일자' }, - { id: 'registUsr', title: '등록자' } + { id: 'regDt', title: '등록 일자' }, + { id: 'rgtr', title: '등록자' } +] +export const tableHeadlistOldPp = [ + { id: 'dcrpPplMtncBizSn', title: '일련번호' }, + { id: 'dcrpPplMtncBizNm', title: '파일명' }, + { id: 'mngYr', title: '년도' }, + { id: 'mngQu', title: '분기' }, + { id: 'regDt', title: '등록 일자' }, + { id: 'rgtr', title: '등록자' } ] \ No newline at end of file