diff --git a/src/apis/board2.js b/src/apis/board2.js new file mode 100644 index 0000000..f53ae95 --- /dev/null +++ b/src/apis/board2.js @@ -0,0 +1,32 @@ +//---------------------------------------------------------------------------- +// Board : 게시판 관리 +//---------------------------------------------------------------------------- + +import axios from 'utils/axios'; +import { GET_BOARD_LIST, REMOVE_BOARD, SAVE_BOARD, SAVE_BOARD_HIT_CNT, GET_BOARD_LIST2 } from 'commons/ApiUrl'; +import { setRowId } from './common'; + +// eslint-disable-next-line import/prefer-default-export +export async function findBoards2(params) { + const res = await axios.get(GET_BOARD_LIST2, { params }); + if (res.success) { + res.data = res.data.resultList.map((d, idx) => ({ ...d, rowId: setRowId(params, idx) })); + return res; + } + return res; +} + +export async function saveBoard(params) { + // eslint-disable-next-line no-return-await + return await axios.post(SAVE_BOARD, params); +} + +export async function removeBoard(inCode) { + // eslint-disable-next-line no-return-await + return await axios.post(REMOVE_BOARD + inCode); +} + +export async function modifyBoardHitCount(inCode) { + // eslint-disable-next-line no-return-await + return await axios.put(SAVE_BOARD_HIT_CNT + inCode); +} diff --git a/src/commons/ApiUrl.js b/src/commons/ApiUrl.js index a3dc57b..1ba05f1 100644 --- a/src/commons/ApiUrl.js +++ b/src/commons/ApiUrl.js @@ -17,6 +17,7 @@ export const GET_BOARD_LIST = '/api/v1/ctgy/board'; export const SAVE_BOARD_HIT_CNT = '/api/v1/ctgy/board/hit/'; export const SAVE_BOARD = '/api/v1/ctgy/board'; export const REMOVE_BOARD = '/api/v1/ctgy/board/'; +export const GET_BOARD_LIST2 = '/api/v2/ctgy/board/'; // 주정차 의견 진술 export const GET_PARKING_LIST = '/api/v1/ctgy/parking'; diff --git a/src/routes/MainRoutes.js b/src/routes/MainRoutes.js index 62711c4..283a0e6 100755 --- a/src/routes/MainRoutes.js +++ b/src/routes/MainRoutes.js @@ -4,6 +4,7 @@ import { lazy } from 'react'; import MainLayout from 'layout/MainLayout'; import Loadable from 'ui-component/Loadable'; import AuthGuard from 'utils/route-guard/AuthGuard'; +import Board2 from '../views/biz/board/Board2'; // sample page routing const SamplePage = Loadable(lazy(() => import('views/sample-page'))); @@ -100,7 +101,10 @@ const MainRoutes = { path: '/board', element: }, - + { + path: '/board2', + element: + }, // ---------------------------------------- { path: '/judge/parking/review', diff --git a/src/views/biz/board/Board2.jsx b/src/views/biz/board/Board2.jsx new file mode 100644 index 0000000..0179410 --- /dev/null +++ b/src/views/biz/board/Board2.jsx @@ -0,0 +1,260 @@ +import { useCallback, useEffect, useState } from 'react'; + +// material-ui +import { Button, Divider, FormControl, Grid, InputAdornment, InputLabel, Link, MenuItem, OutlinedInput, Select } from '@mui/material'; + +// assets +import { IconSearch } from '@tabler/icons'; + +// berry ui +import MainCard from 'ui-component/cards/MainCard'; + +// project imports +import MuiDataGrid from 'views/cmm/mui-grid/MuiDataGrid'; +import { findBoards2, modifyBoardHitCount, removeBoard, saveBoard } from 'apis/board2'; +import { useAlert } from 'react-alert'; +import CmmModal from 'views/cmm/CmmModal'; +import ModifyBoardForm from './ModifyBoardForm'; +import useAuth from 'hooks/useAuth'; +import { Save } from '@mui/icons-material'; +import NewBoardForm from './NewBoardForm'; + +const Board = () => { + const { user } = useAuth(); + const [owner, setOwner] = useState(false); + const [category, setCategory] = useState('ciTitle'); + const [searchTxt, setSearchTxt] = useState(''); + + const [totalCount, setTotalCount] = useState(0); + const [rowsState, setRowsState] = useState({ + page: 0, + pageSize: 20, + rows: [] + // loading: false + }); + const [open, setOpen] = useState(false); + const [newBoard, setNewBoard] = useState(false); + const [selectedRow, setSelectedRow] = useState({}); + const [create, setCreate] = useState(false); + const [title, setTitle] = useState(); + const alert = useAlert(); + + const columns = [ + { headerName: '글번호', headerAlign: 'center', field: 'ciContentno', align: 'center' }, + { + headerName: '제목', + headerAlign: 'center', + field: 'ciTitle', + editable: true, + width: 400, + renderCell: (params) => { + let prefix = ''; + // eslint-disable-next-line no-plusplus + for (let idx = 0; idx < params.row.ciStep; idx++) { + prefix += ' '; + } + if (params.row.ciStep > 0) prefix += '↳ '; + return ( + + {prefix} + {params.value} + + ); + } + }, + { headerName: '작성자', headerAlign: 'center', field: 'ciName', align: 'center' }, + { headerName: '작성일', headerAlign: 'center', field: 'ciNalja', align: 'center' }, + { headerName: '조회수', headerAlign: 'center', field: 'ciHit', align: 'center' }, + { headerName: '게시판코드', headerAlign: 'center', field: 'ciCode', hide: true }, + { headerName: '작성자ID', headerAlign: 'center', field: 'ciId', hide: true }, + { headerName: '등록시간', headerAlign: 'center', field: 'ciTime', hide: true }, + { headerName: 'ref', headerAlign: 'center', field: 'ciRef', hide: true }, + { headerName: 'step', headerAlign: 'center', field: 'ciStep', hide: true }, + { headerName: '비번', headerAlign: 'center', field: 'ciPass', hide: true }, + { headerName: '내용', headerAlign: 'center', field: 'ciContents', hide: true }, + { headerName: 'IP', headerAlign: 'center', field: `ciIp`, hide: true }, + { headerName: 'level', headerAlign: 'center', field: 'ciRevel', hide: true } + ]; + + const search = useCallback(() => { + let params = { + page: rowsState.page, + size: rowsState.pageSize + }; + + if (searchTxt) { + params = { + ...params, + [category]: searchTxt + }; + } + + findBoards2(params).then((response) => { + if (response && response.data) { + setTotalCount(response.count); + setRowsState((prevState) => ({ ...prevState, rows: response.data })); + } + }); + }, [rowsState.page, rowsState.pageSize, category, searchTxt]); + + const handleSearch = async (event) => { + if (event.type === 'keydown' && event.key === 'Enter') { + const newString = event?.target.value; + setSearchTxt(newString); + } + }; + + const handleOnCellClick = (e) => { + if (e?.field === 'ciTitle') { + setOwner(user.id === e?.row.ciId); + setNewBoard(false); + setCreate(false); + setTitle('게시판 상세'); + setSelectedRow(e?.row); + if (user.id !== e?.row.ciId) modifyBoardHitCount(e?.row?.ciCode); + setOpen(true); + } + }; + + const submitBoard = (type, payload) => { + switch (type) { + case 'SAVE': + if (window.confirm('저장 하시겠습니까?')) { + saveBoard(payload).then((res) => { + if (res?.success) { + search(); + setOpen(false); + } else { + alert.show(`${res?.data.message}`); + } + }); // .then((res) => { + } else { + window.close(); + } + break; + case 'DELETE': + if (window.confirm('삭제 하시겠습니까?')) { + removeBoard(payload).then((res) => { + if (res?.success) { + search(); + setOpen(false); + } else { + alert.show(`${res?.data.message}`); + } + }); // .then((res) => { + } else { + window.close(); + } + break; + default: + } + }; + + /** + * 댓글인 경우 부모 댓글 번호를 ciRef, ciStep set + * @param parentCiCode + */ + const onNewBoard = (e, parentCiCode, parentCiRef) => { + let title = ''; + if (parentCiCode) { + setSelectedRow({ + ciName: user.name, + ciRef: parentCiRef ?? parentCiCode, + ciStep: 1, + ciRevel: 1 + }); + title = '게시판 댓글 등록'; + } else { + setSelectedRow({ + ciName: user.name, + ciStep: 0, + ciRevel: 0 + }); + title = '게시판 새글 등록'; + } + setNewBoard(true); + setTitle(title); + setOpen(true); + }; + + useEffect(() => { + search(); + }, [search]); // rowsState.page, rowsState.pageSize, rowsState.rows]); + + return ( + + + + + + + 구분 + + + + + + + + } + /> + {/* */} + + + + + + + + + + + + + {newBoard && } + {!newBoard && ( + + )} + + + ); +}; +export default Board;