diff --git a/apps/sn/app/components/lib/common/apiHelpers.ts b/apps/sn/app/components/lib/common/apiHelpers.ts index d01ad96de..508556571 100644 --- a/apps/sn/app/components/lib/common/apiHelpers.ts +++ b/apps/sn/app/components/lib/common/apiHelpers.ts @@ -10,9 +10,5 @@ export const searchData = async>(url: string, para }, {} as Record) ); const data = await getData(`${url}?${params.toString()}`); - if (data) { - console.log(data.content) - // TODO: data 들어오면 data 보여주게 작업필요 ~ ! - data.content && console.log(data) - } + return data && data.content } diff --git a/apps/sn/app/components/ui/fileUploadForm.tsx b/apps/sn/app/components/ui/fileUploadForm.tsx index 736d8b4be..c59c8852d 100644 --- a/apps/sn/app/components/ui/fileUploadForm.tsx +++ b/apps/sn/app/components/ui/fileUploadForm.tsx @@ -1,32 +1,34 @@ "use client" -import { FileUpload, SelectBox } from '@common/business_components/ui'; -import { Button, Input } from '@common/components/ui'; +import { SelectBox } from '@common/business_components/ui'; +import { Button } from '@common/components/ui'; import React, { useState } from 'react' import type { HttpResponse, Upload } from "tus-js-client"; import { FileUploader } from "@common/components"; import { handleUpload } from "@utils"; +import { set } from 'react-hook-form'; -const FileUploadForm = ({ title, onSubmit }: { title: string, onSubmit:(files:FileList, year:string, quarter:string) => void }) => { - +const FileUploadForm = ({ title, onSubmit }: { title: string, onSubmit: (files: string, year: string, quarter: string, code:string, id:string) => void }) => { + const [atflCd, setAtflCd] = useState(null); + const [atflId, setAtflId] = useState(null); const handleUploadResponse = (file: File) => async (res: HttpResponse) => { const fileInfo = res.getHeader("X-File-Info"); if (!fileInfo) return; - const { atflCd, atflId } = JSON.parse(fileInfo) ?? {}; const orgnlFileNm = file.name; - - console.log(atflCd, atflId, orgnlFileNm); - }; - + console.log('orgnlFileNm', orgnlFileNm, atflCd, atflId); + setAtflCd(atflCd); + setAtflId(atflId); + }; + // 현재 년도부터 10년 전까지의 년도 옵션 생성 const yearOptions = Array.from({ length: 10 }, (_, i) => { const year = new Date().getFullYear() - i; return { text: `${year}년`, val: year.toString() }; }); - const quater = [{text: '1분기', val: '1'}, {text: '2분기', val: '2'}, {text: '3분기', val: '3'}, {text: '4분기', val: '4'}] - const [files, setFiles] = useState(null); + const quater = [{ text: '1분기', val: '1' }, { text: '2분기', val: '2' }, { text: '3분기', val: '3' }, { text: '4분기', val: '4' }] + const [files, setFiles] = useState(null); const [selectedYear, setSelectedYear] = useState(yearOptions[0]?.val || ''); - const [selectedQuarter, setSelectedQuarter] = useState(quater[0]?.val || ''); + const [selectedQuarter, setSelectedQuarter] = useState(quater[0]?.val || ''); const [upload, setUpload] = useState(null); return ( @@ -37,50 +39,48 @@ const FileUploadForm = ({ title, onSubmit }: { title: string, onSubmit:(files:Fi
- setSelectedYear(String(value))} - /> setSelectedQuarter(String(value))} - /> -
+ setSelectedYear(String(value))} + /> setSelectedQuarter(String(value))} + /> +
- { - const selectedFiles = e.target.files; - if (!selectedFiles) return; + { + const selectedFiles = e.target.files; + if (!selectedFiles) return + const fileArray = selectedFiles + setFiles(selectedFiles[0] || null); + if (fileArray[0]) { + handleUpload(selectedFiles, { + handleUploadStart: setUpload, + handleSuccess: setUpload, + handleResponse: handleUploadResponse(fileArray[0]), + }); + } - const fileArray = Array.from(selectedFiles); - if(!fileArray){ - setFiles(fileArray); - } - if (fileArray[0]) { - handleUpload(selectedFiles, { - handleUploadStart: setUpload, - handleSuccess: setUpload, - handleResponse: handleUploadResponse(fileArray[0]), - }); - } - - }} - customPreview={<>} - /> + }} + customPreview={<>} + />
+ + + +
+

사업정보 등록현황

+
+ +
- - - - - - -
-

사업정보 등록현황

-
- - -
-
- { if (index != null) { const fileName = tableData[index]?.fileNm ?? ""; setFileNm(fileName) } }} onPageChange={function (page: number): void { - throw new Error('Function not implemented.') - }}> -
- - {}}/> - - -) + { if (index != null) { const fileName = tableData[index]?.fileNm ?? ""; setFileNm(fileName) } }} onPageChange={function (page: number): void { + throw new Error('Function not implemented.') + }}> +
+ + { await registFile }} /> + + + ) } export default Page \ No newline at end of file diff --git a/apps/sn/app/oper/oldPp/page.tsx b/apps/sn/app/oper/oldPp/page.tsx index 227521dee..fdbcde6e6 100644 --- a/apps/sn/app/oper/oldPp/page.tsx +++ b/apps/sn/app/oper/oldPp/page.tsx @@ -1,7 +1,7 @@ 'use client' import { SearchDiv, SearchFormLeft, SearchFormRight, UiTable } from '@common/business_components/ui' import { Button, DatePicker, Input, Label } from '@common/components/ui' -import React, { useState } from 'react' +import React, { useEffect, useState } from 'react' import FileUploadForm from '../../components/ui/fileUploadForm' import ListDiv from '@common/business_components/ui/list_div' import ContentLayout from '@/components/ui/contentLayout' @@ -9,9 +9,7 @@ import { tableHeadlist } from '..' import { handleDownload } from '@/components/lib/utils/fileDownload' import { searchData } from '@/components/lib/common/apiHelpers' import { formatDate } from '@/components/lib/utils/date' -// TODO: 임시 id - -export const tableData = [{ 'no': '1', 'fileNm': '2023년 노후하수관로 정비사업', 'mngYr': '2023', 'mngQu': '1', 'registDt': '2023-10-01', 'registUsr': '홍길동' },] +import { postData } from '@/components/lib/api' const Page = () => { const [fromDate, setFromDate] = useState(new Date()); const [toDate, setToDate] = useState(new Date()); @@ -20,15 +18,39 @@ const Page = () => { const [usr, setUsr] = useState('') const [pjNm, setpjNm] = useState('') const [fileNm, setFileNm] = useState('') - const isChckFile = () => { - if (fileNm === '' || fileNm === undefined) { - alert('파일을 선택해주세요') - return false - } - // TODO: 추후 파일코드 동적으로 세팅 - handleDownload('/sn/attach-service/api/v1/download/6066b08c-2a55-438c-b8ff-2aed9739a0c6', fileNm) - return true - } + const [atflId, setAtflId] = useState('') + const [atflCd, setAtflCd] = useState('') + const [tableData, setTableData] = useState() + useEffect(() => { + const fetchData = async () => { + const data = await searchData('v1/dcrpPpl', { + fromRegDt: formatDate(new Date()), + toRegDt: formatDate(new Date()), + page: '0', + size: '10' + }) + setTableData(data) + } + fetchData() + }, []) + const isChckFile = () => { + if (fileNm === '' || fileNm === undefined) { + alert('파일을 선택해주세요') + return false + } + handleDownload(`/sn/attach-service/api/v1/download/${atflId}}`, fileNm) + return true + } + const registFile = async (fileNm:string, year: string, quater: string,cd: string, id: string) => { + const data = await postData('api/v1/dcrpPpl', { + atflNm: fileNm, + mngYr: year, + mngQu: quater, + atflCd: cd, + atflId: id + }) + if (data.ok) { setAtflId(data.atflId); setAtflCd(data.atflCd) } + } return ( @@ -77,7 +99,7 @@ const Page = () => {
- + @@ -93,7 +115,7 @@ const Page = () => { }}> - { }} /> + { registFile }} /> )