From a77abb8c0611301611726c615a496241b7e1234a Mon Sep 17 00:00:00 2001 From: yoonc01 Date: Tue, 20 Aug 2024 15:03:55 +0900 Subject: [PATCH 1/8] remove global.css in files --- admin/src/components/header/AdminHeader.jsx | 8 ++++++-- admin/src/pages/AdminEventStatus/EntryRow.jsx | 1 - admin/src/pages/Indicator/TableHeader.jsx | 1 - admin/src/pages/UploadPrize/UploadPrize.jsx | 1 - admin/src/pages/UploadReward/UploadReward.jsx | 1 - service/src/components/buttons/BlueButton.jsx | 1 - service/src/components/buttons/BluePurpleButton.jsx | 1 - service/src/components/buttons/WhiteButton.jsx | 1 - service/src/pages/joinEvent/CarCard.jsx | 1 - service/src/pages/joinEvent/MiniQuiz.jsx | 1 - service/src/pages/joinEvent/ToolBoxCard.jsx | 1 - service/src/pages/miniquiz/ClickBox.jsx | 1 - service/src/pages/miniquiz/LoadingQuiz.jsx | 1 - service/src/pages/miniquiz/MiniQuiz.jsx | 1 - service/src/pages/miniquiz/MiniQuizMain.jsx | 1 - service/src/pages/miniquiz/NoQuizMain.jsx | 1 - service/src/pages/miniquiz/SubmitButton.jsx | 1 - 17 files changed, 6 insertions(+), 18 deletions(-) diff --git a/admin/src/components/header/AdminHeader.jsx b/admin/src/components/header/AdminHeader.jsx index f15182b..6e19224 100644 --- a/admin/src/components/header/AdminHeader.jsx +++ b/admin/src/components/header/AdminHeader.jsx @@ -36,7 +36,9 @@ function AdminHeader() { previousDay.setDate(previousDay.getDate() - 1); const pathSegments = location.pathname.split('/'); const tabName = pathSegments[2]; - navigator(`/${dateFormatting(previousDay)}/${tabName}`); + navigator( + `/${dateFormatting(previousDay)}${tabName !== undefined ? `/${tabName}` : ''}`, + ); } }; @@ -46,7 +48,9 @@ function AdminHeader() { nextDay.setDate(nextDay.getDate() + 1); const pathSegments = location.pathname.split('/'); const tabName = pathSegments[2]; - navigator(`/${dateFormatting(nextDay)}/${tabName}`); + navigator( + `/${dateFormatting(nextDay)}${tabName !== undefined ? `/${tabName}` : ''}`, + ); } }; diff --git a/admin/src/pages/AdminEventStatus/EntryRow.jsx b/admin/src/pages/AdminEventStatus/EntryRow.jsx index db4aa3c..a2f4dce 100644 --- a/admin/src/pages/AdminEventStatus/EntryRow.jsx +++ b/admin/src/pages/AdminEventStatus/EntryRow.jsx @@ -1,6 +1,5 @@ import React from 'react'; import PropTypes from 'prop-types'; -import '@/styles/global.css'; function EntryRow({ id, phoneNumber, time, result }) { return ( diff --git a/admin/src/pages/Indicator/TableHeader.jsx b/admin/src/pages/Indicator/TableHeader.jsx index 261c079..4270ac3 100644 --- a/admin/src/pages/Indicator/TableHeader.jsx +++ b/admin/src/pages/Indicator/TableHeader.jsx @@ -1,6 +1,5 @@ import React from 'react'; import PropTypes from 'prop-types'; -import '@/styles/global.css'; function TableHeader({ col }) { return ( diff --git a/admin/src/pages/UploadPrize/UploadPrize.jsx b/admin/src/pages/UploadPrize/UploadPrize.jsx index 3f68b7e..be30851 100644 --- a/admin/src/pages/UploadPrize/UploadPrize.jsx +++ b/admin/src/pages/UploadPrize/UploadPrize.jsx @@ -4,7 +4,6 @@ import ModalFrame from '@/components/modal/ModalFrame'; import { postPrize, getProbability } from '@/api/UploadPrize'; import useNavigationBlocker from '@/hooks/useNavigationBlocker'; import useFormData from '@/hooks/useFormData'; -import '@/styles/global.css'; import JSZip from 'jszip'; function UploadPrize() { diff --git a/admin/src/pages/UploadReward/UploadReward.jsx b/admin/src/pages/UploadReward/UploadReward.jsx index 3622760..5a4cc81 100644 --- a/admin/src/pages/UploadReward/UploadReward.jsx +++ b/admin/src/pages/UploadReward/UploadReward.jsx @@ -6,7 +6,6 @@ import { postQuizReward } from '@/api/UploadReward'; import { DateContext } from '@/context/dateContext'; import useFormData from '@/hooks/useFormData'; import useNavigationBlocker from '@/hooks/useNavigationBlocker'; -import '@/styles/global.css'; import JSZip from 'jszip'; function UploadReward() { diff --git a/service/src/components/buttons/BlueButton.jsx b/service/src/components/buttons/BlueButton.jsx index 1b3c9f9..0869e66 100644 --- a/service/src/components/buttons/BlueButton.jsx +++ b/service/src/components/buttons/BlueButton.jsx @@ -1,6 +1,5 @@ import React from 'react'; import PropTypes from 'prop-types'; -import '@/styles/global.css'; function BlueButton({ value, styles, onClickFunc, disabled = false }) { return ( diff --git a/service/src/components/buttons/BluePurpleButton.jsx b/service/src/components/buttons/BluePurpleButton.jsx index 53753b3..5dfc9c3 100644 --- a/service/src/components/buttons/BluePurpleButton.jsx +++ b/service/src/components/buttons/BluePurpleButton.jsx @@ -1,6 +1,5 @@ import React from 'react'; import PropTypes from 'prop-types'; -import '@/styles/global.css'; function BluePurpleButton({ value, onClickFunc, styles, disabled = false }) { return ( diff --git a/service/src/components/buttons/WhiteButton.jsx b/service/src/components/buttons/WhiteButton.jsx index e8d8d8f..418d00b 100644 --- a/service/src/components/buttons/WhiteButton.jsx +++ b/service/src/components/buttons/WhiteButton.jsx @@ -1,6 +1,5 @@ import React from 'react'; import PropTypes from 'prop-types'; -import '@/styles/global.css'; function WhiteButton({ value, onClickFunc, styles, disabled = false }) { return ( diff --git a/service/src/pages/joinEvent/CarCard.jsx b/service/src/pages/joinEvent/CarCard.jsx index 1b1861c..5b6ea86 100644 --- a/service/src/pages/joinEvent/CarCard.jsx +++ b/service/src/pages/joinEvent/CarCard.jsx @@ -5,7 +5,6 @@ import BlueButton from '@/components/buttons/BlueButton'; import questionMark from '@/assets/images/questionMark.svg'; import { AuthContext } from '@/context/authContext'; import { useNavigate } from 'react-router-dom'; -import '@/styles/global.css'; function CarCard() { const { userInfo } = useContext(AuthContext); diff --git a/service/src/pages/joinEvent/MiniQuiz.jsx b/service/src/pages/joinEvent/MiniQuiz.jsx index 478d352..7a2ca8a 100644 --- a/service/src/pages/joinEvent/MiniQuiz.jsx +++ b/service/src/pages/joinEvent/MiniQuiz.jsx @@ -10,7 +10,6 @@ import { } from '@/utils/miniQuizUtils'; import { useNavigate } from 'react-router-dom'; -import '@/styles/global.css'; function MiniQuiz() { const navigate = useNavigate(); diff --git a/service/src/pages/joinEvent/ToolBoxCard.jsx b/service/src/pages/joinEvent/ToolBoxCard.jsx index 23cfdd3..247597a 100644 --- a/service/src/pages/joinEvent/ToolBoxCard.jsx +++ b/service/src/pages/joinEvent/ToolBoxCard.jsx @@ -5,7 +5,6 @@ import toolBoxImage from '@/assets/images/toolBoxImage.svg'; import questionMark from '@/assets/images/questionMark.svg'; import { AuthContext } from '@/context/authContext'; import { useNavigate } from 'react-router-dom'; -import '@/styles/global.css'; function ToolBoxCard() { const navigate = useNavigate(); diff --git a/service/src/pages/miniquiz/ClickBox.jsx b/service/src/pages/miniquiz/ClickBox.jsx index 953fbd4..d174ee5 100644 --- a/service/src/pages/miniquiz/ClickBox.jsx +++ b/service/src/pages/miniquiz/ClickBox.jsx @@ -1,6 +1,5 @@ import React, { useState } from 'react'; import PropTypes from 'prop-types'; -import '@/styles/global.css'; function ClickBox({ id, value, isChosen, onClick }) { let className = diff --git a/service/src/pages/miniquiz/LoadingQuiz.jsx b/service/src/pages/miniquiz/LoadingQuiz.jsx index 596d2c4..588af3b 100644 --- a/service/src/pages/miniquiz/LoadingQuiz.jsx +++ b/service/src/pages/miniquiz/LoadingQuiz.jsx @@ -2,7 +2,6 @@ import React, { useEffect, useCallback, useState } from 'react'; import BlueButton from '@/components/buttons/BlueButton'; import WhiteButton from '@/components/buttons/WhiteButton'; import { useNavigate } from 'react-router-dom'; -import '@/styles/global.css'; function LoadingQuiz() { const navigate = useNavigate(); diff --git a/service/src/pages/miniquiz/MiniQuiz.jsx b/service/src/pages/miniquiz/MiniQuiz.jsx index 6fdb1f4..3f834db 100644 --- a/service/src/pages/miniquiz/MiniQuiz.jsx +++ b/service/src/pages/miniquiz/MiniQuiz.jsx @@ -2,7 +2,6 @@ import React, { useState } from 'react'; import EventHeader from '@/components/header/EventHeader'; import ExitModal from '@/components/modal/ExitModal'; import MiniQuizMain from '@/pages/miniquiz/MiniQuizMain'; -import '@/styles/global.css'; function MiniQuiz() { const [openExitModal, setOpenExitModal] = useState(false); diff --git a/service/src/pages/miniquiz/MiniQuizMain.jsx b/service/src/pages/miniquiz/MiniQuizMain.jsx index de71097..1db151b 100644 --- a/service/src/pages/miniquiz/MiniQuizMain.jsx +++ b/service/src/pages/miniquiz/MiniQuizMain.jsx @@ -4,7 +4,6 @@ import ClickBox from '@/pages/miniquiz/ClickBox'; import SubmitButton from '@/pages/miniquiz/SubmitButton'; import { useNavigate } from 'react-router-dom'; import LoadingQuiz from '@/pages/miniquiz/LoadingQuiz'; -import '@/styles/global.css'; function MiniQuizMain() { const navigate = useNavigate(); diff --git a/service/src/pages/miniquiz/NoQuizMain.jsx b/service/src/pages/miniquiz/NoQuizMain.jsx index 7f7a5f5..194f739 100644 --- a/service/src/pages/miniquiz/NoQuizMain.jsx +++ b/service/src/pages/miniquiz/NoQuizMain.jsx @@ -1,7 +1,6 @@ import React, { useCallback } from 'react'; import WhiteButton from '@/components/buttons/WhiteButton'; import { useNavigate } from 'react-router-dom'; -import '@/styles/global.css'; function NoQuizMain() { const navigate = useNavigate(); //useNavigate은 리렌더링 시에는 재생성이 되지 않음 그렇기에 useCallback 안 씀 diff --git a/service/src/pages/miniquiz/SubmitButton.jsx b/service/src/pages/miniquiz/SubmitButton.jsx index 3b629a7..dba393b 100644 --- a/service/src/pages/miniquiz/SubmitButton.jsx +++ b/service/src/pages/miniquiz/SubmitButton.jsx @@ -3,7 +3,6 @@ import { postAnswer } from '@/api/miniQuiz'; import { useNavigate } from 'react-router-dom'; import BluePurpleButton from '@/components/buttons/BluePurpleButton'; import PropTypes from 'prop-types'; -import '@/styles/global.css'; function SubmitButton({ quizId, isChosen, disabled, setDisabled }) { const navigate = useNavigate(); From ba170fa414f21f3f92658517f120ac521b5bab8f Mon Sep 17 00:00:00 2001 From: yoonc01 Date: Tue, 20 Aug 2024 15:07:01 +0900 Subject: [PATCH 2/8] fix navigation bug --- admin/src/components/header/AdminHeader.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/src/components/header/AdminHeader.jsx b/admin/src/components/header/AdminHeader.jsx index 6e19224..8727a8a 100644 --- a/admin/src/components/header/AdminHeader.jsx +++ b/admin/src/components/header/AdminHeader.jsx @@ -37,7 +37,7 @@ function AdminHeader() { const pathSegments = location.pathname.split('/'); const tabName = pathSegments[2]; navigator( - `/${dateFormatting(previousDay)}${tabName !== undefined ? `/${tabName}` : ''}`, + `/${dateFormatting(previousDay)}${tabName !== undefined ? `/${tabName}` : ' '}`, ); } }; @@ -49,7 +49,7 @@ function AdminHeader() { const pathSegments = location.pathname.split('/'); const tabName = pathSegments[2]; navigator( - `/${dateFormatting(nextDay)}${tabName !== undefined ? `/${tabName}` : ''}`, + `/${dateFormatting(nextDay)}${tabName !== undefined ? `/${tabName}` : ' '}`, ); } }; From 62bb57165916915b9a8fa7891c13063cd85f2cf0 Mon Sep 17 00:00:00 2001 From: yoonc01 Date: Tue, 20 Aug 2024 15:07:26 +0900 Subject: [PATCH 3/8] fix admin navigation bug --- admin/src/components/header/AdminHeader.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/src/components/header/AdminHeader.jsx b/admin/src/components/header/AdminHeader.jsx index 8727a8a..6e19224 100644 --- a/admin/src/components/header/AdminHeader.jsx +++ b/admin/src/components/header/AdminHeader.jsx @@ -37,7 +37,7 @@ function AdminHeader() { const pathSegments = location.pathname.split('/'); const tabName = pathSegments[2]; navigator( - `/${dateFormatting(previousDay)}${tabName !== undefined ? `/${tabName}` : ' '}`, + `/${dateFormatting(previousDay)}${tabName !== undefined ? `/${tabName}` : ''}`, ); } }; @@ -49,7 +49,7 @@ function AdminHeader() { const pathSegments = location.pathname.split('/'); const tabName = pathSegments[2]; navigator( - `/${dateFormatting(nextDay)}${tabName !== undefined ? `/${tabName}` : ' '}`, + `/${dateFormatting(nextDay)}${tabName !== undefined ? `/${tabName}` : ''}`, ); } }; From e947a37cd21dbf2dfcb422d54181df07c511af47 Mon Sep 17 00:00:00 2001 From: yoonc01 Date: Tue, 20 Aug 2024 16:45:54 +0900 Subject: [PATCH 4/8] didn't move when submitted so add modified state --- admin/src/pages/UploadPrize/UploadPrize.jsx | 9 ++++++--- admin/src/pages/UploadReward/UploadReward.jsx | 11 ++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/admin/src/pages/UploadPrize/UploadPrize.jsx b/admin/src/pages/UploadPrize/UploadPrize.jsx index be30851..30b0674 100644 --- a/admin/src/pages/UploadPrize/UploadPrize.jsx +++ b/admin/src/pages/UploadPrize/UploadPrize.jsx @@ -19,6 +19,7 @@ function UploadPrize() { const [totalPrize, setTotalPrize] = useState({}); const [openChangeModal, setOpenChangeModal] = useState(false); const [openSubmitModal, setOpenSubmitModal] = useState(false); + const [modified, setModified] = useState(false); const createFormData = useFormData(); @@ -26,8 +27,8 @@ function UploadPrize() { unsavedChangesModal, handleConfirmNavigation, handleCancelNavigation, - } = useNavigationBlocker(selectedFile, () => { - setSelectedFile(null); + } = useNavigationBlocker(modified, () => { + setModified(false); }); useEffect(() => { @@ -43,7 +44,7 @@ function UploadPrize() { }, []); const handleRank = rank => { - if (!selectedFile) { + if (!modified) { setRank(rank); } else { tempRank.current = rank; @@ -91,11 +92,13 @@ function UploadPrize() { setErrorMessage('파일 업로드 중 오류가 발생했습니다.'); } finally { setIsLoading(false); + setModified(false); } }; const handleFileChange = async files => { if (!files.length) return; + setModified(true); setErrorMessage(''); setIsLoading(true); diff --git a/admin/src/pages/UploadReward/UploadReward.jsx b/admin/src/pages/UploadReward/UploadReward.jsx index 5a4cc81..1742c80 100644 --- a/admin/src/pages/UploadReward/UploadReward.jsx +++ b/admin/src/pages/UploadReward/UploadReward.jsx @@ -18,6 +18,7 @@ function UploadReward() { const [processMessage, setProcessMessage] = useState( '폴더 안에 들어가서 파일만을 선택하여 압축한 zip 파일을 업로드해주세요.', ); + const [modified, setModified] = useState(false); const totalReward = 500; const createFormData = useFormData(); @@ -26,8 +27,8 @@ function UploadReward() { unsavedChangesModal, handleConfirmNavigation, handleCancelNavigation, - } = useNavigationBlocker(selectedFile, () => { - setSelectedFile(null); + } = useNavigationBlocker(modified, () => { + setModified(false); }); const handleClick = () => { @@ -43,24 +44,28 @@ function UploadReward() { file: selectedFile, quizDate: dateInfo, }); + console.log(body); try { setIsLoading(true); const response = await postQuizReward(body); + console.log(response); setOpenModal(false); if (response.message === 'success') { setProcessMessage('파일 업로드를 완료했습니다.'); } else { - setErrorMessage('파일 업로드에 실패했습니다.'); + setErrorMessage(`${response.message}`); } } catch (error) { setErrorMessage('파일 업로드 중 오류가 발생했습니다.'); } finally { setIsLoading(false); + setModified(false); } }; const handleFileChange = async files => { if (!files.length) return; + setModified(true); setErrorMessage(''); setIsLoading(true); From 3566589157d8f6f81b97f21fd5de79d086bde83f Mon Sep 17 00:00:00 2001 From: yoonc01 Date: Tue, 20 Aug 2024 17:01:37 +0900 Subject: [PATCH 5/8] fix bug then doesnt close openChangeModal --- admin/src/pages/UploadPrize/UploadPrize.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/admin/src/pages/UploadPrize/UploadPrize.jsx b/admin/src/pages/UploadPrize/UploadPrize.jsx index 30b0674..016835e 100644 --- a/admin/src/pages/UploadPrize/UploadPrize.jsx +++ b/admin/src/pages/UploadPrize/UploadPrize.jsx @@ -79,6 +79,7 @@ function UploadPrize() { file: selectedFile, ranking: rank, }); + try { setIsLoading(true); const response = await postPrize(body); @@ -230,7 +231,7 @@ function UploadPrize() { {openChangeModal && ( setOpenSubmitModal(false)} + onClickNo={() => setOpenChangeModal(false)} onClickYes={() => handleMove()} /> )} From 1f7b0d357e33cbdee447a925fec6515d8c4edf54 Mon Sep 17 00:00:00 2001 From: yoonc01 Date: Tue, 20 Aug 2024 17:23:38 +0900 Subject: [PATCH 6/8] add DrawCasper --- admin/src/api/DrawCasper/index.js | 5 +++ admin/src/components/header/TabHeader.jsx | 1 + admin/src/pages/drawCasper/DrawCasper.jsx | 46 +++++++++++++++++++++++ admin/src/router.jsx | 7 +++- 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 admin/src/api/DrawCasper/index.js create mode 100644 admin/src/pages/drawCasper/DrawCasper.jsx diff --git a/admin/src/api/DrawCasper/index.js b/admin/src/api/DrawCasper/index.js new file mode 100644 index 0000000..dded143 --- /dev/null +++ b/admin/src/api/DrawCasper/index.js @@ -0,0 +1,5 @@ +import { get } from '@/api/index'; + +const draw = () => get('/admin/topPrizeWinner'); + +export { draw }; diff --git a/admin/src/components/header/TabHeader.jsx b/admin/src/components/header/TabHeader.jsx index 0a22f6c..d4d78fd 100644 --- a/admin/src/components/header/TabHeader.jsx +++ b/admin/src/components/header/TabHeader.jsx @@ -13,6 +13,7 @@ function TabHeader() { + ); } diff --git a/admin/src/pages/drawCasper/DrawCasper.jsx b/admin/src/pages/drawCasper/DrawCasper.jsx new file mode 100644 index 0000000..f8f17a2 --- /dev/null +++ b/admin/src/pages/drawCasper/DrawCasper.jsx @@ -0,0 +1,46 @@ +import React, { useState } from 'react'; +import AdminEditHeader from '@/components/header/AdminEditHeader'; +import BlackButton from '@/components/buttons/BlackButton'; +import ModalFrame from '@/components/modal/ModalFrame'; +import { draw } from '@/api/DrawCasper/index'; + +function DrawCasper() { + const [openSubmitModal, setOpenSubmitModal] = useState(false); + const [winner, setWinner] = useState(''); + + const handleSubmit = async () => { + try { + const response = await draw(); + setWinner(response.phoneNumber); + } catch (error) { + console.error(error); + } finally { + setOpenSubmitModal(false); + } + }; + + return ( +
+ +
+ {winner === '' ? ( + setOpenSubmitModal(true)} + /> + ) : ( +
{winner}
+ )} +
+ {openSubmitModal && ( + setOpenSubmitModal(false)} + onClickYes={() => handleSubmit()} + /> + )} +
+ ); +} + +export default DrawCasper; diff --git a/admin/src/router.jsx b/admin/src/router.jsx index 33843f4..f2c89e8 100644 --- a/admin/src/router.jsx +++ b/admin/src/router.jsx @@ -13,6 +13,7 @@ import Login from '@/pages/login/Login'; import ProtectedRoute from '@/pages/ProtectedRoute'; import ErrorPage from '@/pages/ErrorPage'; import Indicator from '@/pages/Indicator/Indicator'; +import DrawCasper from '@/pages/drawCasper/DrawCasper'; const router = createBrowserRouter([ { @@ -66,9 +67,13 @@ const router = createBrowserRouter([ element: , }, { - path: 'Indicator', + path: 'indicator', element: , }, + { + path: 'drawCasper', + element: , + }, ], }, ], From 4c08de882fa12ecb19d33be4cd94474ce27244ab Mon Sep 17 00:00:00 2001 From: yoonc01 Date: Tue, 20 Aug 2024 17:35:26 +0900 Subject: [PATCH 7/8] changed carousel again --- service/src/pages/newCarIntro/NewCarCarousel.jsx | 1 + service/src/styles/newCarCarousel.css | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/service/src/pages/newCarIntro/NewCarCarousel.jsx b/service/src/pages/newCarIntro/NewCarCarousel.jsx index 84f1b00..69929e0 100644 --- a/service/src/pages/newCarIntro/NewCarCarousel.jsx +++ b/service/src/pages/newCarIntro/NewCarCarousel.jsx @@ -72,6 +72,7 @@ function NewCarCarousel() { src={item.imageSrc} alt={`Car Image ${item.id}`} className="object-cover w-full h-full" + onClick={() => setCurrentIndex(idx)} /> ))} diff --git a/service/src/styles/newCarCarousel.css b/service/src/styles/newCarCarousel.css index 2760aa6..1e51aa0 100644 --- a/service/src/styles/newCarCarousel.css +++ b/service/src/styles/newCarCarousel.css @@ -12,6 +12,7 @@ } .slider-item { + cursor: pointer; width: 1200px; height: 500px; position: absolute; @@ -27,11 +28,6 @@ z-index: 4; } -.s1:hover { - transition: transform 0.2s; - transform: translate(-50%, -50%) translateX(0) translateZ(0) scale(1.05); -} - .s2 { transform: translate(-50%, -50%) translateX(330px) translateZ(-100px); z-index: 3; From 085addea60ca357ac8b7d631e2afbb8a509da43e Mon Sep 17 00:00:00 2001 From: yoonc01 Date: Tue, 20 Aug 2024 18:26:04 +0900 Subject: [PATCH 8/8] only admin user can access --- admin/package.json | 1 + admin/src/components/header/AdminHeader.jsx | 37 ++++++++++++++++----- admin/src/hooks/useFetch.js | 8 +---- admin/yarn.lock | 6 ++++ 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/admin/package.json b/admin/package.json index a26e3d2..78c0de1 100644 --- a/admin/package.json +++ b/admin/package.json @@ -19,6 +19,7 @@ "eslint-plugin-jsx-a11y": "^6.5.1", "json-server": "^1.0.0-beta.1", "jszip": "^3.10.1", + "jwt-decode": "^4.0.0", "micro-slider": "^1.1.0", "postcss": "^8.4.39", "prop-types": "^15.8.1", diff --git a/admin/src/components/header/AdminHeader.jsx b/admin/src/components/header/AdminHeader.jsx index 6e19224..ef7ee77 100644 --- a/admin/src/components/header/AdminHeader.jsx +++ b/admin/src/components/header/AdminHeader.jsx @@ -8,20 +8,41 @@ import { putEventSchedules, getEventSchedules } from '@/api/header/index'; function AdminHeader() { const location = useLocation(); - const navigator = useNavigate(); + const navigate = useNavigate(); const { dateInfo } = useContext(DateContext); const [isNextDayDisabled, setIsNextDayDisabled] = useState(false); const [isPreviousDayDisabled, setIsPreviousDayDisabled] = useState(false); const [selectedDate, setSelectedDate] = useState(''); useEffect(() => { + const token = sessionStorage.getItem('token'); + if (token) { + try { + const decodedToken = jwtDecode(token); + + if (decodedToken && decodedToken.role === 'ADMIN') { + // Do Nothing + } else { + navigate('/error'); + } + } catch (error) { + console.error(error); + navigate('/error'); + } + } else { + navigate('/login'); + } const getDate = async () => { const response = await getEventSchedules(); - const startDate = new Date(response[0].date); - const finishDate = new Date(response[13].date); - const currentDate = new Date(dateInfo); - setIsPreviousDayDisabled(currentDate.getTime() === startDate.getTime()); - setIsNextDayDisabled(currentDate.getTime() === finishDate.getTime()); + if (response.code === 'UNAUTHORIZED') { + navigate('/error'); + } else { + const startDate = new Date(response[0].date); + const finishDate = new Date(response[13].date); + const currentDate = new Date(dateInfo); + setIsPreviousDayDisabled(currentDate.getTime() === startDate.getTime()); + setIsNextDayDisabled(currentDate.getTime() === finishDate.getTime()); + } }; getDate(); }, [dateInfo]); @@ -36,7 +57,7 @@ function AdminHeader() { previousDay.setDate(previousDay.getDate() - 1); const pathSegments = location.pathname.split('/'); const tabName = pathSegments[2]; - navigator( + navigate( `/${dateFormatting(previousDay)}${tabName !== undefined ? `/${tabName}` : ''}`, ); } @@ -48,7 +69,7 @@ function AdminHeader() { nextDay.setDate(nextDay.getDate() + 1); const pathSegments = location.pathname.split('/'); const tabName = pathSegments[2]; - navigator( + navigate( `/${dateFormatting(nextDay)}${tabName !== undefined ? `/${tabName}` : ''}`, ); } diff --git a/admin/src/hooks/useFetch.js b/admin/src/hooks/useFetch.js index 725d0ce..db0f679 100644 --- a/admin/src/hooks/useFetch.js +++ b/admin/src/hooks/useFetch.js @@ -1,8 +1,6 @@ import { useState, useEffect, useCallback } from 'react'; -import { useNavigate } from 'react-router-dom'; function useFetch(api, params) { - const navigate = useNavigate(); const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); @@ -11,11 +9,7 @@ function useFetch(api, params) { try { const response = await api(params); if (typeof response === 'object') { - if (response.code === 'UNAUTHORIZED') { - navigate('/error'); - } else { - setData(response); - } + setData(response); } else if (typeof response === 'string') { setData({ message: response }); } else { diff --git a/admin/yarn.lock b/admin/yarn.lock index 4aae6be..59e2c2c 100644 --- a/admin/yarn.lock +++ b/admin/yarn.lock @@ -3553,6 +3553,11 @@ jszip@^3.10.1: readable-stream "~2.3.6" setimmediate "^1.0.5" +jwt-decode@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-4.0.0.tgz#2270352425fd413785b2faf11f6e755c5151bd4b" + integrity sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA== + keyv@^4.5.3: version "4.5.4" resolved "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz" @@ -4684,6 +4689,7 @@ tailwindcss@^3.4.6: resolve "^1.22.2" sucrase "^3.32.0" + tar@^7.4.3: version "7.4.3" resolved "https://registry.yarnpkg.com/tar/-/tar-7.4.3.tgz#88bbe9286a3fcd900e94592cda7a22b192e80571"