kcscDev/egovframe-template-simple-r.../src/pages/admin/board/AdminPostMgtList.jsx

222 lines
9.8 KiB
React
Raw Normal View History

2024-02-20 06:06:42 +00:00
import React, { useState, useEffect, useCallback, useRef } from 'react';
import { Link, useLocation } from 'react-router-dom';
import * as EgovNet from 'api/egovFetch';
import URL from 'constants/url';
import { default as EgovLeftNav } from 'components/leftmenu/EgovLeftNavAdmin';
import EgovPaging from 'components/EgovPaging';
import { itemIdxByPage } from 'utils/calc';
2024-03-07 08:57:35 +00:00
import CODE from "../../../constants/code";
import AboutSiteModal from "../config/aboutSiteMgt/AboutSiteModal";
import AdminPostMgtEdit from "./AdminPostMgtEdit";
import Modal from "react-bootstrap/Modal";
2024-03-08 08:56:00 +00:00
import {format} from "date-fns";
2024-03-22 01:34:43 +00:00
import {Form} from "react-bootstrap";
const fileIconPath = require('../../../css/images/ico_file.png');
2024-02-20 06:06:42 +00:00
2024-02-28 00:08:26 +00:00
function AdminPostMgtList(props) {
2024-03-07 08:57:35 +00:00
console.group("EgovAdminPostList");
console.log("[Start] EgovAdminPostList ------------------------------");
console.log("EgovAdminPostList [props] : ", props);
2024-02-20 06:06:42 +00:00
const location = useLocation();
2024-03-07 08:57:35 +00:00
console.log("EgovAdminPostList [location] : ", location);
2024-02-20 06:06:42 +00:00
// eslint-disable-next-line no-unused-vars
const [searchCondition, setSearchCondition] = useState(location.state?.searchCondition || { pageIndex: 1, searchCnd: '0', searchKeyword: '', bbsSeq:8 });// 기존 조회에서 접근 했을 시 || 신규로 접근 했을 시
2024-02-20 06:06:42 +00:00
const [paginationInfo, setPaginationInfo] = useState({});
const cndRef = useRef();
const wrdRef = useRef();
const [listTag, setListTag] = useState([]);
2024-03-22 01:34:43 +00:00
const [categoryList, setCategoryList] = useState([]);
2024-02-20 06:06:42 +00:00
2024-03-07 08:57:35 +00:00
const [show, setShow] = useState(false);
const [modalBody, setModalBody] = useState();
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
2024-02-20 06:06:42 +00:00
const retrieveList = useCallback((searchCondition) => {
2024-03-08 08:56:00 +00:00
handleClose();
const params = EgovNet.convParams(searchCondition);
2024-03-07 08:57:35 +00:00
console.groupCollapsed("EgovAdminPostList.retrieveList()");
const retrieveListURL = '/admin/boards/posts/post-list' + params;
2024-02-20 06:06:42 +00:00
const requestOptions = {
2024-03-07 08:57:35 +00:00
method: "GET",
2024-02-20 06:06:42 +00:00
headers: {
'Content-type': 'application/json',
}
2024-02-20 06:06:42 +00:00
}
EgovNet.requestFetch(retrieveListURL,
requestOptions,
(resp) => {
setPaginationInfo(resp.result.paginationInfo);
2024-03-22 01:34:43 +00:00
setCategoryList(resp.result.categoryList);
console.log("@@@ resultCnt : " + resp.result.resultCnt);
2024-02-20 06:06:42 +00:00
let mutListTag = [];
setListTag([]);
resp.result.fixedList.forEach(function (item) {
const finalModifiedDate = item?.lastChgDt ? item?.lastChgDt : item?.frstCrtDt;
const formattedDate = finalModifiedDate ? format(finalModifiedDate, "yyyy-MM-dd HH:mm") : "";
mutListTag.push(
<div className="list_item">
<div>공지</div>
<div>{item?.bbsContTitle}</div>
<div>{item?.frstCrtId}</div>
<div>{formattedDate}</div>
<div>{item?.bbsReadCnt}</div>
<div>{item?.fileGrpId && <img src={fileIconPath} alt="File Icon" />}</div>
<div><button className={"btn btn_blue_h31 px-1"} onClick={()=>{editPost(item)}}>수정</button></div>
</div>
);
});
2024-02-20 06:06:42 +00:00
2024-03-07 08:57:35 +00:00
resp.result.postList.forEach(function (item, index) {
const finalModifiedDate = item?.lastChgDt ? item?.lastChgDt : item?.frstCrtDt;
2024-03-08 08:56:00 +00:00
const formattedDate = finalModifiedDate ? format(finalModifiedDate, "yyyy-MM-dd HH:mm") : "";
2024-02-20 06:06:42 +00:00
mutListTag.push(
2024-03-07 08:57:35 +00:00
<div className="list_item">
<div>{resp.result.resultCnt - (resp.result.paginationInfo.pageIndex -1) * resp.result.paginationInfo.rowCnt - index}</div>
<div>{item?.bbsContTitle}</div>
<div>{item?.frstCrtId}</div>
2024-03-08 08:56:00 +00:00
<div>{formattedDate}</div>
<div>{item?.bbsReadCnt}</div>
<div>{item?.fileGrpId && <img src={fileIconPath} alt="File Icon" />}</div>
2024-03-08 08:56:00 +00:00
<div><button className={"btn btn_blue_h31 px-1"} onClick={()=>{editPost(item)}}>수정</button></div>
2024-03-07 08:57:35 +00:00
</div>
2024-02-20 06:06:42 +00:00
);
});
if(!mutListTag.length) mutListTag.push(<p className="no_data" key="0">검색된 결과가 없습니다.</p>); // 게시판 목록 초기값
2024-02-20 06:06:42 +00:00
setListTag(mutListTag);
},
function (resp) {
console.log("err response : ", resp);
}
);
2024-03-07 08:57:35 +00:00
console.groupEnd("EgovAdminPostList.retrieveList()");
},[listTag]);
2024-02-20 06:06:42 +00:00
useEffect(() => {
retrieveList(searchCondition);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchCondition]);
2024-02-20 06:06:42 +00:00
2024-03-22 01:34:43 +00:00
const handleSelectChange = (e) => {
setSearchCondition({...searchCondition, bbsSeq: e.target.value})
2024-03-22 01:34:43 +00:00
}
2024-03-07 08:57:35 +00:00
function editPost(item){
handleShow();
if(item != undefined) {
item.mode = CODE.MODE_MODIFY;
}
setModalBody(<AdminPostMgtEdit props={item} reloadFunction={(searchCondition) => retrieveList(searchCondition)}/>)
2024-03-07 08:57:35 +00:00
}
console.log("------------------------------EgovAdminPostList [End]");
console.groupEnd("EgovAdminPostList");
2024-02-20 06:06:42 +00:00
return (
<div className="container">
<div className="c_wrap">
{/* <!-- Location --> */}
<div className="location">
<ul>
<li><Link to={URL.MAIN} className="home">Home</Link></li>
2024-03-07 08:57:35 +00:00
<li>사이트관리</li>
<li>게시판현황</li>
2024-02-28 00:08:26 +00:00
<li>게시물 관리</li>
2024-02-20 06:06:42 +00:00
</ul>
</div>
{/* <!--// Location --> */}
<div className="layout">
{/* <!-- Navigation --> */}
<EgovLeftNav></EgovLeftNav>
{/* <!--// Navigation --> */}
<div className="contents BOARD_CREATE_LIST" id="contents">
{/* <!-- 본문 --> */}
<div className="top_tit">
2024-03-07 08:57:35 +00:00
<h1 className="tit_1">게시물 관리</h1>
2024-02-20 06:06:42 +00:00
</div>
{/* <!-- 검색조건 --> */}
<div className="condition">
<ul>
<li className="third_1 L">
<span className="lb">게시판선택</span>
2024-02-20 06:06:42 +00:00
<label className="f_select" htmlFor="searchCnd">
<Form.Select id="select1" name="bbsSeq" value={searchCondition.bbsSeq} onChange={handleSelectChange}>
2024-03-22 01:34:43 +00:00
<option value="">선택</option>
{categoryList.map((item) => (
<option key={item.bbsSeq} value={item.bbsSeq}>{item.bbsTitle}</option>
2024-03-22 01:34:43 +00:00
))}
</Form.Select>
2024-02-20 06:06:42 +00:00
</label>
</li>
<li className="third_2 R">
<span className="lb">검색어</span>
<span className="f_search w_400">
<input type="text" name="" defaultValue={searchCondition.searchKeyword} placeholder=""
onChange={(e) => {setSearchCondition({...searchCondition, searchKeyword: e.target.value})}}/>
<button type="button" onClick={() => {retrieveList(searchCondition)}}>조회</button>
2024-02-20 06:06:42 +00:00
</span>
</li>
</ul>
</div>
{/* <!--// 검색조건 --> */}
{/* <!-- 게시판목록 --> */}
<div className="board_list BRD007">
2024-02-20 06:06:42 +00:00
<div className="head">
<span>번호</span>
2024-03-07 08:57:35 +00:00
<span>제목</span>
<span>작성자</span>
2024-03-08 08:56:00 +00:00
<span>최종수정일</span>
2024-03-07 08:57:35 +00:00
<span>조회수</span>
<span>파일</span>
<span><button className={"btn btn_blue_h31 px-1"} onClick={()=>{editPost(undefined)}}>추가</button></span>
2024-02-20 06:06:42 +00:00
</div>
<div className="result">
{listTag}
</div>
</div>
{/* <!--// 게시판목록 --> */}
<div className="board_bot">
{/* <!-- Paging --> */}
<EgovPaging pagination={paginationInfo} moveToPage={passedPage => {
retrieveList({ ...searchCondition, pageIndex: passedPage}) //, searchCnd: cndRef.current.value, searchKeyword: wrdRef.current.value
2024-02-20 06:06:42 +00:00
}} />
{/* <!--/ Paging --> */}
</div>
{/* <!--// 본문 --> */}
</div>
</div>
</div>
2024-03-07 08:57:35 +00:00
<Modal show={show} onHide={handleClose} keyboard={false}>
{modalBody}
</Modal>
2024-02-20 06:06:42 +00:00
</div>
);
}
2024-02-28 00:08:26 +00:00
export default AdminPostMgtList;