diff --git a/src/pages/Admin/Report.tsx b/src/pages/Admin/Report.tsx index 0838c4c..dc52d8c 100644 --- a/src/pages/Admin/Report.tsx +++ b/src/pages/Admin/Report.tsx @@ -5,6 +5,7 @@ import { AlarmIcon } from '@/assets/icons'; import AdminPageTitle from './components/AdminPageTitle'; import ListHeaderFrame from './components/ListHeaderFrame'; +import PagenationNavigation from './components/PagenationNavigation'; import ReportDetailModal from './components/ReportDetailModal'; import ReportHandlingModal from './components/ReportHandlingModal'; import ReportListItem from './components/ReportListItem'; @@ -19,28 +20,33 @@ export default function ReportManage() { currentPage: '1', totalPages: '0', }); + const [selectedReport, setSelectReport] = useState(null); const [selectedReportId, setSelectedReportId] = useState(null); - // const [allReports, setAllReports] = useState(); - const [reportQueryString, setReportQueryString] = useState({ reportType: null, status: 'PENDING', page: '1', - size: '3', + size: '2', }); + const handleGetReports = async (reportQueryString: ReportQueryString) => { const res = await getReports(reportQueryString); if (res?.status === 200) { - console.log(res.data.data.content); - setReports(res.data.data.content); + const data = res.data.data; + setReports(data.content); setReportPages(() => ({ - currentPage: res.data.data.currentPage, - totalPages: res.data.data.totalPages, + currentPage: data.currentPage, + totalPages: data.totalPages, })); } }; + + const handleNowPage = (page: string) => { + setReportQueryString((cur) => ({ ...cur, page: page })); + }; + useEffect(() => { handleGetReports(reportQueryString); }, [reportQueryString]); @@ -68,39 +74,11 @@ export default function ReportManage() { setSelectReport={setSelectReport} /> ))} -
-
- - - {reportPages.currentPage}/{reportPages.totalPages} - - -
-
+ {detailModalOpen && ( diff --git a/src/pages/Admin/components/PagenationNavigation.tsx b/src/pages/Admin/components/PagenationNavigation.tsx new file mode 100644 index 0000000..350ffdd --- /dev/null +++ b/src/pages/Admin/components/PagenationNavigation.tsx @@ -0,0 +1,93 @@ +import { useState } from 'react'; +import { twMerge } from 'tailwind-merge'; + +interface PagenationNavigation { + totalPage: number; + buttonLength: number; + handlePageNumberButtonClick: (page: string) => void; +} +export default function PagenationNavigation({ + totalPage, + buttonLength, + handlePageNumberButtonClick, +}: PagenationNavigation) { + const totalSection = Math.ceil(totalPage / buttonLength) - 1; + const [nowSection, setNowSection] = useState(0); + const [nowPageNumberAt, setNowPageNumberAt] = useState(1); + + // 네비게이션 시작점, 끝점 + const navigationRange = { + start: nowSection * buttonLength + 1, + end: nowSection * buttonLength + buttonLength, + }; + + // 페이지 버튼 배열 + const pageNumberButtonArray = Array.from( + { length: navigationRange.end - navigationRange.start + 1 }, + (_, index) => navigationRange.start + index, + ); + + // 페이지 버튼 클릭시 해당 번호값이 파라미터에 담김 + const handlePageButtonClick = (page: number) => { + const pageString = page.toString(); + handlePageNumberButtonClick(pageString); + setNowPageNumberAt(page); + }; + + const handlePrevButtonClick = () => { + if (nowSection > 0) { + const prev = (nowSection - 1) * buttonLength + buttonLength; + setNowSection((cur) => cur - 1); + handlePageButtonClick(prev); + } + }; + + const handleNextButtonClick = () => { + if (nowSection < totalSection) { + const next = (nowSection + 1) * buttonLength + 1; + setNowSection((cur) => cur + 1); + handlePageButtonClick(next); + } + }; + + const buttonStyle = 'border bg-white px-2 py-1 disabled:bg-gray-20'; + + return ( +
+
+ + {pageNumberButtonArray.map((num) => { + if (totalPage < num) return null; + return ( + + ); + })} + +
+
+ ); +}