|
|
@ -1,4 +1,5 @@
|
|
|
|
import { useCallback, useEffect, useState } from 'react';
|
|
|
|
import { useCallback, useEffect, useState } from 'react';
|
|
|
|
|
|
|
|
import { useMutation, useQuery, useQueryClient } from 'react-query';
|
|
|
|
|
|
|
|
|
|
|
|
// material-ui
|
|
|
|
// material-ui
|
|
|
|
import { Button, Grid, Link } from '@mui/material';
|
|
|
|
import { Button, Grid, Link } from '@mui/material';
|
|
|
@ -22,6 +23,7 @@ import { removeAlert, saveAlert } from '../../../commons/XitCmm';
|
|
|
|
|
|
|
|
|
|
|
|
const PublicBoard = () => {
|
|
|
|
const PublicBoard = () => {
|
|
|
|
const { user } = useAuth();
|
|
|
|
const { user } = useAuth();
|
|
|
|
|
|
|
|
const queryClient = useQueryClient();
|
|
|
|
const [owner, setOwner] = useState();
|
|
|
|
const [owner, setOwner] = useState();
|
|
|
|
const [totalCount, setTotalCount] = useState(0);
|
|
|
|
const [totalCount, setTotalCount] = useState(0);
|
|
|
|
const [rowsState, setRowsState] = useState({
|
|
|
|
const [rowsState, setRowsState] = useState({
|
|
|
@ -72,24 +74,24 @@ const PublicBoard = () => {
|
|
|
|
{ headerName: '조회수', headerAlign: 'center', field: 'inHit', align: 'right', width: 80 }
|
|
|
|
{ headerName: '조회수', headerAlign: 'center', field: 'inHit', align: 'right', width: 80 }
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const search = useCallback(() => {
|
|
|
|
const params = {
|
|
|
|
const params = {
|
|
|
|
page: rowsState.page,
|
|
|
|
page: rowsState.page,
|
|
|
|
size: rowsState.pageSize
|
|
|
|
size: rowsState.pageSize
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const search = async () => {
|
|
|
|
findPublicBoards(params).then((response) => {
|
|
|
|
const res = await findPublicBoards(params);
|
|
|
|
// console.log(response);
|
|
|
|
if (res && res.data) {
|
|
|
|
if (response && response.data) {
|
|
|
|
setTotalCount(res.count);
|
|
|
|
setTotalCount(response.count);
|
|
|
|
setRowsState((prevState) => ({ ...prevState, rows: res.data }));
|
|
|
|
setRowsState((prevState) => ({ ...prevState, rows: response.data }));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
useQuery(['pboards', params.page, params.size], search);
|
|
|
|
}, [rowsState.page, rowsState.pageSize]);
|
|
|
|
// const { isLoading, data, isError } = useQuery(['pboards', params.page, params.size], search);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
// useEffect(() => {
|
|
|
|
search();
|
|
|
|
// search();
|
|
|
|
}, [search]); // rowsState.page, rowsState.pageSize, rowsState.rows]);
|
|
|
|
// }, [search]); // rowsState.page, rowsState.pageSize, rowsState.rows]);
|
|
|
|
|
|
|
|
|
|
|
|
const handleOnCellClick = (e) => {
|
|
|
|
const handleOnCellClick = (e) => {
|
|
|
|
if (e?.field === 'inTitle') {
|
|
|
|
if (e?.field === 'inTitle') {
|
|
|
@ -97,6 +99,12 @@ const PublicBoard = () => {
|
|
|
|
setTitle('공지사항 상세');
|
|
|
|
setTitle('공지사항 상세');
|
|
|
|
setSelectedRow(e?.row);
|
|
|
|
setSelectedRow(e?.row);
|
|
|
|
setOwner(user.name === e?.row.inName);
|
|
|
|
setOwner(user.name === e?.row.inName);
|
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
|
|
|
|
|
|
// useMutation(modifyPublicBoardHitCount(e?.row?.inCode), {
|
|
|
|
|
|
|
|
// onSuccess: () => {
|
|
|
|
|
|
|
|
// queryClient.invalidateQueries('pboards');
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// });
|
|
|
|
modifyPublicBoardHitCount(e?.row?.inCode);
|
|
|
|
modifyPublicBoardHitCount(e?.row?.inCode);
|
|
|
|
setOpen(true);
|
|
|
|
setOpen(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -108,26 +116,16 @@ const PublicBoard = () => {
|
|
|
|
setOpen(false);
|
|
|
|
setOpen(false);
|
|
|
|
|
|
|
|
|
|
|
|
saveAlert(() =>
|
|
|
|
saveAlert(() =>
|
|
|
|
savePublicBoard(payload).then((res) => {
|
|
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
|
|
if (res?.success) {
|
|
|
|
useMutation(savePublicBoard(payload))
|
|
|
|
search();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
alert.show(`${res?.data.message}`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'DELETE':
|
|
|
|
case 'DELETE':
|
|
|
|
setOpen(false);
|
|
|
|
setOpen(false);
|
|
|
|
|
|
|
|
|
|
|
|
removeAlert(() =>
|
|
|
|
removeAlert(
|
|
|
|
removePublicBoard(payload).then((res) => {
|
|
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
|
|
if (res?.success) {
|
|
|
|
() => useMutation(removePublicBoard(payload))
|
|
|
|
search();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
alert.show(`${res?.data.message}`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|