diff --git a/src/apis/judge.js b/src/apis/judge.js index 2da4b9d..0c40820 100644 --- a/src/apis/judge.js +++ b/src/apis/judge.js @@ -69,7 +69,7 @@ export async function findJudgeResults2(params) { export async function findJudgeResults(params, isParking) { const res = await axios.get(isParking ? GET_PARKING_JUDGE_RESULT_LIST : GET_JUDGE_RESULT_LIST, { params }); - if (res && res.data) { + if (res && res.success && res.data) { const totJudgeUserData = res.data?.totJudgeUserData; // tot데이타 정제 @@ -84,15 +84,18 @@ export async function findJudgeResults(params, isParking) { // 마지막 '결과' 맵 삭제 totJudgeUserData.pop(); return { - // 심사자별 심사 합산 - totJudgeUsers: totJudgeUserData, - // 심사자별 심사 합산에서 추출한 심사 합산 데이타 - totJudgeUserData: totUserData, - // 심사대상 차량 목록 - judgeCars: res.data?.judgeCarData, - // 차량별 심시 결과 - judgeUserData: res.data?.judgeUserData, - judgeTeam: res.data?.teamList[0].msuTeam + success: true, + data: { + // 심사자별 심사 합산 + totJudgeUsers: totJudgeUserData, + // 심사자별 심사 합산에서 추출한 심사 합산 데이타 + totJudgeUserData: totUserData, + // 심사대상 차량 목록 + judgeCars: res.data?.judgeCarData, + // 차량별 심시 결과 + judgeUserData: res.data?.judgeUserData, + judgeTeam: res.data?.teamList[0].msuTeam + } }; } return res; diff --git a/src/index.js b/src/index.js index db7e418..133b706 100755 --- a/src/index.js +++ b/src/index.js @@ -23,8 +23,8 @@ import 'assets/scss/style.scss'; // optional configuration const options = { position: positions.BOTTOM_CENTER, // positions.BOTTOM_CENTER, - timeout: 2000, - type: types.INFO, // info / success / error + timeout: 5000, + type: types.ERROR, // info / success / error offset: '50px', transition: transitions.SCALE, // 'scale' / fade containerStyle: { diff --git a/src/utils/axios.js b/src/utils/axios.js index e19fec2..4b4789e 100755 --- a/src/utils/axios.js +++ b/src/utils/axios.js @@ -133,7 +133,7 @@ axiosService.interceptors.response.use( alertError(config, request, response, error); // error 데이타 return // return response.data; - return error; + return response; } ); diff --git a/src/utils/useAsync.js b/src/utils/useAsync.js new file mode 100644 index 0000000..9f0f772 --- /dev/null +++ b/src/utils/useAsync.js @@ -0,0 +1,72 @@ +import { useReducer, useEffect, useCallback } from 'react'; + +const initialState = { + loading: false, + data: null, + error: false +}; + +function reducer(state, action) { + switch (action.type) { + case 'LOADING': + return { + loading: true, + data: null, + error: null + }; + + case 'SUCCESS': + return { + loading: false, + data: action.data, + error: null + }; + + case 'ERROR': + return { + loading: false, + data: null, + error: action.error + }; + + case 'CLEAR': + return initialState; + + default: + throw new Error(`Unhandled action type: ${action.type}`); + } +} + +function useAsync(callback, deps = [], skip = false) { + const [state, dispatch] = useReducer(reducer, initialState); + + // const fetchData = async () => { + // dispatch({ type: 'LOADING' }); + // try { + // const data = await callback(); + // dispatch({ type: 'SUCCESS', data }); + // } catch (e) { + // dispatch({ type: 'ERROR', error: e }); + // } + // }; + + const fetchData = useCallback(async () => { + dispatch({ type: 'LOADING' }); + try { + const data = await callback(); + dispatch({ type: 'SUCCESS', data }); + } catch (e) { + dispatch({ type: 'ERROR', error: e }); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, deps); + + useEffect(() => { + if (skip) return; + fetchData(); + }, [fetchData, skip]); + + return [state, fetchData]; +} + +export default useAsync; diff --git a/src/views/biz/board/PublicBoard.jsx b/src/views/biz/board/PublicBoard.jsx index 9e0062e..d1bb3f7 100644 --- a/src/views/biz/board/PublicBoard.jsx +++ b/src/views/biz/board/PublicBoard.jsx @@ -14,6 +14,7 @@ import MuiDataGrid from 'views/cmm/MuiDataGrid'; import CmmModal from 'views/cmm/CmmModal'; import PublicBoardForm from './PublicBoardForm'; import { deletePublicBoard, findPublicBoards, modifyPublicBoardHitCount, savePublicBoard } from 'apis/public'; +import { useAlert } from 'react-alert'; const PublicBoard = () => { const [totalCount, setTotalCount] = useState(0); @@ -27,6 +28,7 @@ const PublicBoard = () => { const [selectedRow, setSelectedRow] = useState({}); const [create, setCreate] = useState(false); const [title, setTitle] = useState(); + const alert = useAlert(); const columns = [ { headerName: 'No.', headerAlign: 'center', field: 'rowId', align: 'center', width: 80 }, @@ -95,9 +97,13 @@ const PublicBoard = () => { const submitPublicBoard = (type, payload) => { switch (type) { case 'SAVE': - savePublicBoard(payload).then(() => { - search(); - setOpen(false); + savePublicBoard(payload).then((res) => { + if (res?.success) { + search(); + setOpen(false); + } else { + alert.show(`${res?.data.message}`); + } }); // .then((res) => { break; case 'DELETE': diff --git a/src/views/biz/judge/JudgeReview.jsx b/src/views/biz/judge/JudgeReview.jsx index 9aeb73e..c3e52f3 100644 --- a/src/views/biz/judge/JudgeReview.jsx +++ b/src/views/biz/judge/JudgeReview.jsx @@ -155,9 +155,9 @@ const JudgeReview = ({ msDatagb, menuName }) => { }; const res = await findJudgeResults(params); setJudgeResultData({ - ...res, + ...res?.data, selectedRow: e.row, - judgeTeam: res.judgeTeam + judgeTeam: res.data?.judgeTeam }); setTitle(`${e.row.msCdate} ${menuName} 심사 결과 (${e.row.msChasu}차 - 총 ${e.row.cnt}건)`); diff --git a/src/views/biz/judge/ModalJudgeResult.jsx b/src/views/biz/judge/ModalJudgeResult.jsx index af1842f..8ad9c21 100644 --- a/src/views/biz/judge/ModalJudgeResult.jsx +++ b/src/views/biz/judge/ModalJudgeResult.jsx @@ -6,7 +6,7 @@ import TableContainer from '@mui/material/TableContainer'; import TableHead from '@mui/material/TableHead'; import TableRow from '@mui/material/TableRow'; import { styled } from '@mui/material/styles'; -import { Divider, FormControl, Grid, InputLabel, MenuItem, Select, TableFooter, Typography } from '@mui/material'; +import { Divider, FormControl, Grid, InputLabel, MenuItem, Select, TableFooter, TextField, Typography } from '@mui/material'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; import combo from 'commons/combo_data'; @@ -16,6 +16,7 @@ import { IconSearch } from '@tabler/icons'; import { findJudgeResults } from 'apis/judge'; import MuiAlert from 'views/cmm/MuiAlert'; import _ from 'lodash'; +import { useAlert } from 'react-alert'; const StyledTableCell = styled(TableCell)(({ theme }) => ({ [`&.${tableCellClasses.head}`]: { @@ -54,8 +55,8 @@ const ModalJudgeResult = ({ totJudgeUsers, totJudgeUserData, judgeCars, judgeUse title: '', message: '' }); - const totLabel = ['부과', '서손', '미부과', '계']; + const alert = useAlert(); console.log(totJudgeUsers, totJudgeUserData, judgeCars, judgeUserData, judgeTeam); const onSearch = async () => { setAlertOpen(false); @@ -69,8 +70,15 @@ const ModalJudgeResult = ({ totJudgeUsers, totJudgeUserData, judgeCars, judgeUse }; const res = await findJudgeResults(params, params.msDatagb === ''); - // TODO: 에러 alert 반영 필요 - if (res && res.isAxiosError) { + if (res && res?.success) { + setJudgeResult({ + ...judgeResult, + totJudgeUsers: res.data?.totJudgeUsers, + totJudgeUserData: res.data?.totJudgeUserData, + judgeCars: res.data?.judgeCars, + judgeUserData: res.data?.judgeUserData + }); + } else { setJudgeResult({ ...judgeResult, totJudgeUsers: [], @@ -80,36 +88,27 @@ const ModalJudgeResult = ({ totJudgeUsers, totJudgeUserData, judgeCars, judgeUse // judgeData: [], // simsaUser: [] }); - // alert.show('조회된 데이타가 없습니다.'); - setAlertState({ - ...alertState, - message: '조회된 데이타가 없습니다.' - }); - setAlertOpen(true); - // descriptionAlertsDescriptionAlerts(); - } else { - setJudgeResult({ - ...judgeResult, - totJudgeUsers: res.totJudgeUsers, - totJudgeUserData: res.totJudgeUserData, - judgeCars: res.judgeCars, - judgeUserData: res.judgeUserData - }); + alert.show('조회된 데이타가 없습니다.'); + // setAlertState({ + // ...alertState, + // message: '조회된 데이타가 없습니다.' + // }); + // setAlertOpen(true); } } }; return ( - + - + 심의차수: {selectedRow.msChasu}차 심의기간: {selectedRow.msSdate} ~ {selectedRow.msEdate} - + - + @@ -143,7 +142,7 @@ const ModalJudgeResult = ({ totJudgeUsers, totJudgeUserData, judgeCars, judgeUse 차량번호 - {judgeResult.totJudgeUsers.map((u) => ( + {judgeResult?.totJudgeUsers.map((u) => ( {u.NAME} @@ -155,7 +154,7 @@ const ModalJudgeResult = ({ totJudgeUsers, totJudgeUserData, judgeCars, judgeUse {/* 심사 통계 */} - {judgeResult.totJudgeUserData.map((totData, idx) => ( + {judgeResult?.totJudgeUserData.map((totData, idx) => ( {totLabel[idx]} @@ -174,7 +173,7 @@ const ModalJudgeResult = ({ totJudgeUsers, totJudgeUserData, judgeCars, judgeUse {/* 접수번호별 심사 결과 */} - {judgeResult.judgeCars.map((row, carIdx) => ( + {judgeResult?.judgeCars.map((row, carIdx) => ( {/* {row.msMaincode} */} @@ -198,7 +197,7 @@ const ModalJudgeResult = ({ totJudgeUsers, totJudgeUserData, judgeCars, judgeUse ))} - {`총 ${selectedRow.cnt} 건중 ${judgeResult.judgeCars.length} 건`} + {judgeResult && `총 ${selectedRow.cnt} 건중 ${judgeResult.judgeCars.length} 건`} diff --git a/src/views/biz/parking/ParkingReview.jsx b/src/views/biz/parking/ParkingReview.jsx index 6babd2e..fe538ca 100644 --- a/src/views/biz/parking/ParkingReview.jsx +++ b/src/views/biz/parking/ParkingReview.jsx @@ -155,8 +155,9 @@ const ParkingReview = () => { const res = await findJudgeResults(params, true); setJudgeResultData({ - ...res, - selectedRow: e.row + ...res.data, + selectedRow: e.row, + judgeTeam: res.data?.judgeTeam }); setTitle(`${e.row.msCdate} 주정차 심사 결과 (${e.row.msChasu}차 - 총 ${e.row.cnt}건)`); diff --git a/src/views/cmm/Filedownload.jsx b/src/views/cmm/Filedownload.jsx new file mode 100644 index 0000000..97f119d --- /dev/null +++ b/src/views/cmm/Filedownload.jsx @@ -0,0 +1,23 @@ +import React from 'react'; + +const Filedownload = () => { + useEffect(() => { + if (fileData) { + const url = window.URL.createObjectURL(new Blob([fileData.data])); + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', 'test.xlsx'); + link.setAttribute('id', 'tempLink'); + document.body.appendChild(link); + link.click(); + } + return () => { + const link = document.querySelector('#tempLink'); + link && link.remove(); + }; + }, [fileData]); + + return
; +}; + +export default Filedownload;