feat: react-query 적용

main
Jonguk. Lim 2 years ago
parent 876385577e
commit 8c62f73c82

@ -65,6 +65,7 @@
"react-otp-input-rc-17": "^2.4.1-minor", "react-otp-input-rc-17": "^2.4.1-minor",
"react-pdf": "^5.7.2", "react-pdf": "^5.7.2",
"react-perfect-scrollbar": "^1.5.8", "react-perfect-scrollbar": "^1.5.8",
"react-query": "^3.39.1",
"react-quill": "^2.0.0-beta.4", "react-quill": "^2.0.0-beta.4",
"react-redux": "^7.2.6", "react-redux": "^7.2.6",
"react-resizable": "^3.0.4", "react-resizable": "^3.0.4",

@ -3,6 +3,9 @@ import ReactDOM from 'react-dom';
// third party // third party
import { BrowserRouter } from 'react-router-dom'; import { BrowserRouter } from 'react-router-dom';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { QueryClient, QueryClientProvider } from 'react-query';
import { ReactQueryDevtools } from 'react-query/devtools';
import { PersistGate } from 'redux-persist/integration/react'; import { PersistGate } from 'redux-persist/integration/react';
import { transitions, positions, Provider as AlertProvider, types } from 'react-alert'; import { transitions, positions, Provider as AlertProvider, types } from 'react-alert';
import AlertTemplate from 'react-alert-template-basic'; import AlertTemplate from 'react-alert-template-basic';
@ -32,17 +35,22 @@ const options = {
} }
}; };
const queryClient = new QueryClient();
ReactDOM.render( ReactDOM.render(
<Provider store={store}> <Provider store={store}>
<PersistGate loading={null} persistor={persister}> <QueryClientProvider client={queryClient}>
<ConfigProvider> <PersistGate loading={null} persistor={persister}>
<BrowserRouter basename={BASE_PATH}> <ConfigProvider>
<AlertProvider template={AlertTemplate} {...options}> <BrowserRouter basename={BASE_PATH}>
<App /> <AlertProvider template={AlertTemplate} {...options}>
</AlertProvider> <App />
</BrowserRouter> </AlertProvider>
</ConfigProvider> </BrowserRouter>
</PersistGate> </ConfigProvider>
</PersistGate>
<ReactQueryDevtools initialIsOpen />
</QueryClientProvider>
</Provider>, </Provider>,
document.getElementById('root') document.getElementById('root')
); );

@ -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:

@ -26,7 +26,7 @@ const FileForm = ({
<TextField <TextField
fullWidth fullWidth
placeholder={labelName} placeholder={labelName}
value={selectedFile} value={selectedFile || ''}
size="small" size="small"
InputProps={{ InputProps={{
display: 'none', display: 'none',
@ -39,7 +39,7 @@ const FileForm = ({
onClick={handleFileDownload} onClick={handleFileDownload}
/> />
) : ( ) : (
<TextField fullWidth placeholder={labelName} value={selectedFile} size="small" /> <TextField fullWidth placeholder={labelName} value={selectedFile || ''} size="small" />
)} )}
</Grid> </Grid>
<Grid item xs={4.5}> <Grid item xs={4.5}>

Loading…
Cancel
Save