-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
175 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import ReactPaginate from "react-paginate"; | ||
import { customAxios } from "../../config/axios-config"; | ||
import './noticePage.css'; | ||
|
||
export default function NoticePage() { | ||
const [noticeData, setNoticeData] = useState([]); | ||
const [pageCount, setPageCount] = useState(0); | ||
const [currentPage, setCurrentPage] = useState(0); | ||
const itemsPerPage = 10; | ||
|
||
const getNoticeData = async (page = 0) => { | ||
try { | ||
const res = await customAxios.get(`/v1/notices`, { | ||
params: { page, size: itemsPerPage } | ||
}); | ||
if (res.data.success && res.data.data.content) { | ||
setNoticeData(res.data.data.content); | ||
setPageCount(res.data.data.totalPages); | ||
} else { | ||
setNoticeData([]); | ||
} | ||
} catch (error) { | ||
console.error("Error fetching data: ", error); | ||
setNoticeData([]); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
getNoticeData(currentPage); | ||
}, [currentPage]); | ||
|
||
const handlePageClick = ({ selected }) => { | ||
setCurrentPage(selected); | ||
}; | ||
|
||
return ( | ||
<div className="notice_container"> | ||
<h2>공지사항</h2> | ||
<div className="notice_list"> | ||
<div className="notice_header"> | ||
<span>번호</span> | ||
<span>제목</span> | ||
<span>날짜</span> | ||
<span>작성자</span> | ||
<span>조회수</span> | ||
</div> | ||
{noticeData.length > 0 ? ( | ||
noticeData.map((item, index) => ( | ||
<div key={item.noticeId} className="notice_item"> | ||
<span>{currentPage * itemsPerPage + index + 1}</span> | ||
<span>{item.title}</span> | ||
<span>{new Date(item.createdAt).toLocaleDateString()}</span> | ||
<span>관리자</span> | ||
{item.totalView ? <span>{item.totalView}</span> : <span>0</span>} | ||
</div> | ||
)) | ||
) : ( | ||
<div className="notice_item"> | ||
<span>공지사항이 없습니다.</span> | ||
</div> | ||
)} | ||
</div> | ||
<ReactPaginate | ||
previousLabel={'<'} | ||
nextLabel={'>'} | ||
pageCount={pageCount} | ||
onPageChange={handlePageClick} | ||
containerClassName={'pagination'} | ||
previousLinkClassName={'pagination_link'} | ||
nextLinkClassName={'pagination_link'} | ||
disabledClassName={'pagination_link_disabled'} | ||
activeClassName={'pagination_link_active'} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
.notice_container { | ||
width: 80%; | ||
margin: 0 auto; | ||
font-family: Arial, sans-serif; | ||
} | ||
|
||
h2 { | ||
text-align: center; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.notice_list { | ||
width: 100%; | ||
border-collapse: collapse; | ||
} | ||
|
||
.notice_header, .notice_item { | ||
display: grid; | ||
grid-template-columns: 1fr 4fr 2fr 2fr 1fr; | ||
border-bottom: 1px solid #ddd; | ||
padding: 10px 0; | ||
} | ||
|
||
.notice_header { | ||
background-color: #f4f4f4; | ||
font-weight: bold; | ||
} | ||
|
||
.notice_item span { | ||
text-align: center; | ||
} | ||
|
||
.notice_item { | ||
color: #666; | ||
transition: background-color 0.3s; | ||
} | ||
|
||
.notice_item:hover { | ||
background-color: #f9f9f9; | ||
} | ||
|
||
.notice_item:nth-child(even) { | ||
background-color: #f4f4f4; | ||
} | ||
|
||
.notice_item:nth-child(odd) { | ||
background-color: #fff; | ||
} | ||
|
||
.pagination { | ||
display: flex; | ||
justify-content: center; | ||
margin-top: 20px; | ||
list-style: none; | ||
padding: 0; | ||
} | ||
|
||
.pagination_link { | ||
margin: 0 5px; | ||
padding: 8px 12px; | ||
border: 1px solid #ddd; | ||
cursor: pointer; | ||
color: #007bff; | ||
} | ||
|
||
.pagination_link_active { | ||
background-color: #007bff; | ||
color: #fff; | ||
border: none; | ||
} | ||
|
||
.pagination_link_disabled { | ||
color: #ccc; | ||
cursor: not-allowed; | ||
} | ||
|