From e4d4be276f445c6dd93f8ded4b4d93a73de1308a Mon Sep 17 00:00:00 2001 From: minuk926 Date: Mon, 28 Mar 2022 20:53:03 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B3=B5=EC=A7=80=EC=82=AC=ED=95=AD?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20/=20=EC=82=AD=EC=A0=9C=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/AuthService.js | 16 ----- src/apis/CmmService.js | 17 ----- src/apis/OpstBizService.js | 30 ++++++++- src/commons/ApiUrl.js | 2 + src/views/biz/board/PublicBoard.jsx | 28 ++++++-- src/views/biz/board/PublicBoardForm.jsx | 86 ++++++++++++++++++------- src/views/form/FileUploadForm.jsx | 51 +++++++++++++++ 7 files changed, 167 insertions(+), 63 deletions(-) delete mode 100644 src/apis/AuthService.js delete mode 100644 src/apis/CmmService.js create mode 100644 src/views/form/FileUploadForm.jsx diff --git a/src/apis/AuthService.js b/src/apis/AuthService.js deleted file mode 100644 index a251b66..0000000 --- a/src/apis/AuthService.js +++ /dev/null @@ -1,16 +0,0 @@ -import { IUser } from 'types/auth'; -import reqApi from './ApiService'; -import { LOGIN_URL } from 'commons/ApiUrl'; -import { IApiResponse } from 'types/api'; - -class AuthService { - login = (user) => reqApi.post(LOGIN_URL, user); - - // getCurrentUser = async () => { - // if (!localStorage.getItem(ACCESS_TOKEN_NAME)) { - // return Promise.reject('No access token set.'); - // } - // }; -} - -export default new AuthService(); diff --git a/src/apis/CmmService.js b/src/apis/CmmService.js deleted file mode 100644 index 1b79e38..0000000 --- a/src/apis/CmmService.js +++ /dev/null @@ -1,17 +0,0 @@ -import { GET_CMM_CODE_LIST } from 'commons/ApiUrl'; -import axios from 'utils/axios'; - -class CmmService { - // eslint-disable-next-line no-return-await - getComboCodeList = async (params) => await axios.get(GET_CMM_CODE_LIST, { params }); - - // getComboCodeList(params) { - // return reqApi.get(CMM_CODE_LIST_URL, { params }); - // .then(r => console.log(r)) - // .catch(e => { - // console.log(e) - // }); - // } -} - -export default CmmService; diff --git a/src/apis/OpstBizService.js b/src/apis/OpstBizService.js index 019dac7..a268b81 100644 --- a/src/apis/OpstBizService.js +++ b/src/apis/OpstBizService.js @@ -5,7 +5,10 @@ import { GET_PARKING_SIMSA_LIST, GET_PARKING_SIMSA_TARGET_LIST, SAVE_PARKING_SIMSA_TARGET, - GET_PUBLIC_BOARD + GET_PUBLIC_BOARD, + GET_CMM_CODE_LIST, + SAVE_PUBLIC_BOARD, + DELETE_PUBLIC_BOARD } from 'commons/ApiUrl'; import axios from 'utils/axios'; @@ -88,6 +91,29 @@ class OpstBizService { return res; }; - SAVE_PARKING_SIMSA_TARGET; + // eslint-disable-next-line no-return-await + getComboCodeList = async (params) => await axios.get(GET_CMM_CODE_LIST, { params }); + + // getComboCodeList(params) { + // return reqApi.get(CMM_CODE_LIST_URL, { params }); + // .then(r => console.log(r)) + // .catch(e => { + // console.log(e) + // }); + // } + + savePublicBoard = async (formData) => { + const config = { + method: 'post', + data: formData, + headers: { 'Content-Type': 'multipart/form-data' } // , Authorization: localStorage.getItem('access_token') } + }; + // eslint-disable-next-line no-return-await + return await axios(SAVE_PUBLIC_BOARD, config); + }; + + deletePublicBoard = async (inCode) => + // eslint-disable-next-line no-return-await + await axios.post(DELETE_PUBLIC_BOARD + inCode); } export default new OpstBizService(); diff --git a/src/commons/ApiUrl.js b/src/commons/ApiUrl.js index 758632f..6844b8f 100644 --- a/src/commons/ApiUrl.js +++ b/src/commons/ApiUrl.js @@ -6,6 +6,8 @@ export const GET_CMM_CODE_LIST = '/api/v1/biz/cmm/combo'; // 공지사항 export const GET_PUBLIC_BOARD_LIST = '/api/v1/ctgy/pboard'; export const GET_PUBLIC_BOARD = '/api/v1/ctgy/pboard/'; +export const SAVE_PUBLIC_BOARD = '/api/v1/ctgy/file/pboard'; +export const DELETE_PUBLIC_BOARD = '/api/v1/ctgy/file/pboard/'; // 게시판 export const GET_BOARD_LIST = '/api/v1/ctgy/board'; diff --git a/src/views/biz/board/PublicBoard.jsx b/src/views/biz/board/PublicBoard.jsx index 1cee2d2..b49cce9 100644 --- a/src/views/biz/board/PublicBoard.jsx +++ b/src/views/biz/board/PublicBoard.jsx @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react'; // material-ui -import { Button, Divider, FormControlLabel, Grid, InputAdornment, Link, Radio, RadioGroup, TextField } from '@mui/material'; +import { Divider, Grid, Link } from '@mui/material'; // assets import { IconFile, IconFileCheck, IconFileText } from '@tabler/icons'; @@ -11,10 +11,8 @@ import MainCard from 'ui-component/cards/MainCard'; // project imports import MuiDataGrid from 'views/form/MuiDataGrid'; -import InputLabel from 'ui-component/extended/Form/InputLabel'; import opstBizService from '../../../apis/OpstBizService'; import * as React from 'react'; -import SaveParkingSimsaForm from '../parking/SaveParkingSimsaForm'; import CmmModal from '../../form/Modal/CmmModal'; import * as PropTypes from 'prop-types'; import PublicBoardForm from './PublicBoardForm'; @@ -63,7 +61,7 @@ const PublicBoard = () => { { headerName: '조회수', headerAlign: 'center', field: 'inHit', align: 'right' } ]; - useEffect(() => { + const search = () => { const params = { page: rowsState.page, size: rowsState.pageSize @@ -76,6 +74,10 @@ const PublicBoard = () => { setRowsState((prevState) => ({ ...prevState, rows: response.data })); } }); + }; + + useEffect(() => { + search(); }, [rowsState.page, rowsState.pageSize]); // rowsState.page, rowsState.pageSize, rowsState.rows]); const handleOnCellClick = (e) => { @@ -85,8 +87,22 @@ const PublicBoard = () => { } }; - const submitPublicBoard = () => { - console.log('save'); + const submitPublicBoard = (type, payload) => { + switch (type) { + case 'SAVE': + opstBizService.savePublicBoard(payload); + search(); + setOpen(false); + break; + case 'DELETE': + opstBizService.deletePublicBoard(payload); + search(); + setOpen(false); + break; + default: + search(); + setOpen(false); + } }; return ( diff --git a/src/views/biz/board/PublicBoardForm.jsx b/src/views/biz/board/PublicBoardForm.jsx index 2232e87..f59fbd8 100644 --- a/src/views/biz/board/PublicBoardForm.jsx +++ b/src/views/biz/board/PublicBoardForm.jsx @@ -1,49 +1,51 @@ -import { useEffect, useMemo, useRef, useState } from 'react'; +import { useMemo, useRef, useState } from 'react'; // material-ui -import { Button, Divider, FormControlLabel, Grid, InputAdornment, Radio, RadioGroup, TextField } from '@mui/material'; +import { Button, Grid, IconButton, Input, InputAdornment, TextField, Tooltip } from '@mui/material'; // assets -import { IconFile, IconFileCheck, IconFileText } from '@tabler/icons'; // berry ui import ReactQuill from 'react-quill'; import 'react-quill/dist/quill.snow.css'; // project imports -import MuiDataGrid from 'views/form/MuiDataGrid'; import InputLabel from 'ui-component/extended/Form/InputLabel'; import opstBizService from '../../../apis/OpstBizService'; import * as React from 'react'; -import SaveParkingSimsaForm from '../parking/SaveParkingSimsaForm'; -import CmmModal from '../../form/Modal/CmmModal'; -import * as PropTypes from 'prop-types'; + import axios from 'axios'; +import { FileDownload, FileUpload } from '@mui/icons-material'; const PublicBoardForm = (props) => { console.log(props); - const { inCode, inBgubun, inTitle, inHit, inName, inNalja, inFileName, inContents, setOpen } = props; + const { inCode, inBgubun, inTitle, inHit, inName, inNalja, inFilename, inContents, setOpen, handleModalSave } = props; const quillRef = useRef(); const [contents, setContents] = useState(inContents); + const [filesInfo, setFilesInfo] = useState(null); + const [selectedFile, setSelectedFile] = useState(inFilename); // 파일 const onList = (e) => { setOpen(false); }; const onSave = (e) => { - const data = { - inCode, - inTitle, - inBgubun, - inContents: contents, - inFileName - }; - alert(JSON.stringify(data)); + const formData = new FormData(); + formData.append('inCode', inCode); + formData.append('inTitle', inTitle); + formData.append('inBgubun', inBgubun); + formData.append('inContents', contents); + formData.append('inFilename', inFilename); + + if (filesInfo !== null && filesInfo.length > 0) { + // eslint-disable-next-line no-plusplus + for (let i = 0; i < filesInfo.length; i++) formData.append('files', filesInfo[i]); + } + handleModalSave('SAVE', formData); }; - const onDelete = (e) => {}; - const onEditorStateChange = (editorState) => {}; - // (editorState) => setEditorState(editorState) - // useEffect(() => {}, []); + const onDelete = (e) => { + handleModalSave('DELETE', inCode); + }; const imageHandler = () => { const input = document.createElement('input'); @@ -56,7 +58,6 @@ const PublicBoardForm = (props) => { const file = input.files[0]; const formData = new FormData(); formData.append('image', file); - const fileName = file.name; console.log(formData); @@ -108,6 +109,16 @@ const PublicBoardForm = (props) => { [] ); + const onChangeFile = (e) => { + console.log(e.target.files); + + setSelectedFile(e.target.files[0].name); + setFilesInfo(e.target.files); + }; + + const handleFileDownload = (e) => { + alert('download'); + }; return ( <> @@ -130,7 +141,38 @@ const PublicBoardForm = (props) => { - + + + + + ) + }} + /> + + + + + {selectedFile ? : } + + + + {/* {selectedFile ? selectedFile.name : 'Select Image'}. . . */} + {/* */} + ({ +// root: { +// '& > *': { +// margin: theme.spacing(1) +// } +// }, +// input: { +// display: 'none' +// }, +// faceImage: { +// color: theme.palette.primary.light +// } +// })); + +const FileUploadForm = ({ onSaveFile }) => { + const theme = useTheme(); + const [selectedFile, setSelectedFile] = useState(null); + + const handleCapture = ({ target }) => { + setSelectedFile(target.files[0]); + }; + + const handleSubmit = () => { + onSaveFile(selectedFile); + }; + + return ( + <> + + + + + + + + + {selectedFile ? selectedFile.name : 'Select Image'}. . . + + + ); +}; + +export default FileUploadForm;