From cdc538a8d399f4777c2aab075aa8e063e1576a50 Mon Sep 17 00:00:00 2001 From: anjaemin Date: Wed, 9 Nov 2022 17:12:08 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20deletePage=20redux=20=EA=B0=9C?= =?UTF-8?q?=ED=8E=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/state/action-types/index.ts | 2 +- src/state/actions-creators/index.ts | 6 +++--- src/state/actions/index.ts | 4 ++-- .../reducers/{DeleteFileName.ts => DeleteFileProps.ts} | 6 +++--- src/state/reducers/index.ts | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) rename src/state/reducers/{DeleteFileName.ts => DeleteFileProps.ts} (53%) diff --git a/src/state/action-types/index.ts b/src/state/action-types/index.ts index 5d87f5e..402bf25 100644 --- a/src/state/action-types/index.ts +++ b/src/state/action-types/index.ts @@ -1,5 +1,5 @@ export enum ActionType { - DeleteFileName = 'DeleteFileName', + DeleteFileProps = 'DeleteFileProps', DownloadFileProps = 'DownloadFileProps', CheckPasswordFileProps = 'CheckPasswordFileProps', } diff --git a/src/state/actions-creators/index.ts b/src/state/actions-creators/index.ts index 6ecabad..f3fe99b 100644 --- a/src/state/actions-creators/index.ts +++ b/src/state/actions-creators/index.ts @@ -3,10 +3,10 @@ import { Dispatch } from 'redux'; import { ActionType } from '../action-types'; import { Action } from '../actions'; -export const SetDeleteFileName = (name: string) => (dispatch: Dispatch) => { +export const SetDeleteFileProps = (props: any) => (dispatch: Dispatch) => { dispatch({ - type: ActionType.DeleteFileName, - name: name, + type: ActionType.DeleteFileProps, + props: props, }); }; diff --git a/src/state/actions/index.ts b/src/state/actions/index.ts index 670b8c8..28eaa0e 100644 --- a/src/state/actions/index.ts +++ b/src/state/actions/index.ts @@ -1,8 +1,8 @@ import { ActionType } from '../action-types'; interface DeleteFileProps { - type: ActionType.DeleteFileName; - name: string; + type: ActionType.DeleteFileProps; + props: any; } interface DownloadFileProps { diff --git a/src/state/reducers/DeleteFileName.ts b/src/state/reducers/DeleteFileProps.ts similarity index 53% rename from src/state/reducers/DeleteFileName.ts rename to src/state/reducers/DeleteFileProps.ts index 871b915..9409794 100644 --- a/src/state/reducers/DeleteFileName.ts +++ b/src/state/reducers/DeleteFileProps.ts @@ -1,10 +1,10 @@ import { ActionType } from '../action-types'; import { Action } from '../actions'; -const reducer = (state: string = '', action: Action): string => { +const reducer = (state: any = { filename: null, token: null }, action: Action): any => { switch (action.type) { - case ActionType.DeleteFileName: - return action.name; + case ActionType.DeleteFileProps: + return action.props; default: return state; } diff --git a/src/state/reducers/index.ts b/src/state/reducers/index.ts index 4e6b8ba..14c4bf4 100644 --- a/src/state/reducers/index.ts +++ b/src/state/reducers/index.ts @@ -1,7 +1,7 @@ import { combineReducers } from 'redux'; import CheckPasswordFileProps from './CheckPasswordFileProps'; -import DeleteFileName from './DeleteFileName'; +import DeleteFileName from './DeleteFileProps'; import DownloadFileProps from './DownloadFileProps'; const reducers = combineReducers({ From feea7d0eaf03a26611c58fa0875d243ec14760d0 Mon Sep 17 00:00:00 2001 From: anjaemin Date: Wed, 9 Nov 2022 17:12:54 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20DeletePageNavigator=20hook=20token?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/index.ts | 1 - src/hooks/useDeletePageNavigate.ts | 6 +++--- src/hooks/useDownloadPageNavigate.ts | 16 ---------------- 3 files changed, 3 insertions(+), 20 deletions(-) delete mode 100644 src/hooks/useDownloadPageNavigate.ts diff --git a/src/hooks/index.ts b/src/hooks/index.ts index a64239a..45c5a95 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -1,2 +1 @@ export * from './useDeletePageNavigate'; -export * from './useDownloadPageNavigate'; diff --git a/src/hooks/useDeletePageNavigate.ts b/src/hooks/useDeletePageNavigate.ts index 1ad4d0d..8f178aa 100644 --- a/src/hooks/useDeletePageNavigate.ts +++ b/src/hooks/useDeletePageNavigate.ts @@ -4,12 +4,12 @@ import { bindActionCreators } from 'redux'; import { actionCreators } from '../state'; -export const useDeletePageNavigator = (fileName: string) => { +export const useDeletePageNavigator = (filename: string, token: string) => { const navigate = useNavigate(); const dispatch = useDispatch(); - const { SetDeleteFileName } = bindActionCreators(actionCreators, dispatch); + const { SetDeleteFileProps } = bindActionCreators(actionCreators, dispatch); const move = () => { - SetDeleteFileName(fileName); + SetDeleteFileProps({ filename: filename, token: token }); navigate('/delete'); }; return [move]; diff --git a/src/hooks/useDownloadPageNavigate.ts b/src/hooks/useDownloadPageNavigate.ts deleted file mode 100644 index 0dc35af..0000000 --- a/src/hooks/useDownloadPageNavigate.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { useDispatch } from 'react-redux'; -import { useNavigate } from 'react-router-dom'; -import { bindActionCreators } from 'redux'; - -import { actionCreators } from '../state'; - -export const useDownloadPageNavigate = (props: any) => { - const navigate = useNavigate(); - const dispatch = useDispatch(); - const { SetDownloadFileProps } = bindActionCreators(actionCreators, dispatch); - const move = () => { - SetDownloadFileProps(props); - navigate('/download'); - }; - return [move]; -}; From 86ae7905aadd5648eac293da39695f71dc4d0865 Mon Sep 17 00:00:00 2001 From: anjaemin Date: Wed, 9 Nov 2022 17:13:15 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20token=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/delete/index.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/delete/index.tsx b/src/pages/delete/index.tsx index 27b7d62..8b5d30c 100644 --- a/src/pages/delete/index.tsx +++ b/src/pages/delete/index.tsx @@ -10,9 +10,9 @@ import * as S from './styled'; export const DeletePage: React.FC = () => { const navigate = useNavigate(); - const DeleteFileName = useSelector((state: RootState) => state.DeleteFileName); + const DeleteFileProps = useSelector((state: RootState) => state.DeleteFileName); useEffect(() => { - if (DeleteFileName === '') { + if (DeleteFileProps.filename === null) { navigate(-1); } }); @@ -20,10 +20,11 @@ export const DeletePage: React.FC = () => { const deleteFile = async () => { await axios({ method: 'delete', - url: `${process.env.REACT_APP_BACKEND_BASEURL}/del/${DeleteFileName}`, + url: `${process.env.REACT_APP_BACKEND_BASEURL}/del/${DeleteFileProps.filename}${ + DeleteFileProps.token != null ? `?token=${DeleteFileProps.token}` : '' + }`, }) - .then((res) => { - console.log(res); + .then(() => { navigate('/'); toast.success('삭제 완료', { autoClose: 3000, @@ -31,7 +32,6 @@ export const DeletePage: React.FC = () => { }); }) .catch((err) => { - console.log(err); toast.error(`삭제 실패 ${err.response.status}`, { autoClose: 3000, position: toast.POSITION.BOTTOM_RIGHT, From e2c21793c7ebdae2d01f7937663b5ffd68935796 Mon Sep 17 00:00:00 2001 From: anjaemin Date: Wed, 9 Nov 2022 17:13:52 +0900 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=ED=8C=8C=EC=9D=BC=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=B2=84=ED=8A=BC=20=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/download/index.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pages/download/index.tsx b/src/pages/download/index.tsx index 452f049..f989046 100644 --- a/src/pages/download/index.tsx +++ b/src/pages/download/index.tsx @@ -4,6 +4,7 @@ import { useNavigate } from 'react-router-dom'; import { toast } from 'react-toastify'; import { Button, FileBox } from '../../components'; +import { useDeletePageNavigator } from '../../hooks'; import { RootState } from '../../state/reducers'; import { getDate } from '../../utils'; import * as S from './styled'; @@ -12,6 +13,7 @@ export const DownloadPage: React.FC = () => { const navigate = useNavigate(); const downloadFileProps: any = useSelector((state: RootState) => state.DownloadFileProps); const { year, month, day } = getDate(downloadFileProps.lastModified); + const [move] = useDeletePageNavigator(downloadFileProps.filename, downloadFileProps.token); useEffect(() => { if ( downloadFileProps.filename === null || @@ -48,10 +50,7 @@ export const DownloadPage: React.FC = () => { />