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]; -}; 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, 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 = () => { />