From ce0892498673042c3a4b9a6b21298cff335e2629 Mon Sep 17 00:00:00 2001 From: sayyyho <323psh@naver.com> Date: Wed, 13 Nov 2024 17:47:31 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[Fix]=20#41=20-=20=EB=88=84=EA=B5=AC?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=B6=84=EA=B8=B0=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/navigateBar/NavigateBar.jsx | 17 +++++++---------- src/pages/nugu/_hooks/useNuguInfo.js | 4 +++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/components/common/navigateBar/NavigateBar.jsx b/src/components/common/navigateBar/NavigateBar.jsx index 3deff44..3ab8cf1 100644 --- a/src/components/common/navigateBar/NavigateBar.jsx +++ b/src/components/common/navigateBar/NavigateBar.jsx @@ -1,18 +1,20 @@ import * as S from "./styled"; import { useNavigate, useLocation } from "react-router-dom"; import { NAVIGATE_TITLE } from "@constants/navigatebar"; +import Cookies from "js-cookie"; + export const NavigateBar = () => { const navigate = useNavigate(); const location = useLocation(); - const isTokenAvailable = true; + const isTokenAvailable = Cookies.get("access_token") ? true : false; const handleMovePage = (value) => { let path; switch (value) { case 1: - path = isTokenAvailable ? "/login" : "/login"; + path = `/nugu/${Cookies.get("uuid")}`; break; case 2: - path = "/intro"; + path = `/intro/${Cookies.get("uuid")}`; break; case 3: path = isTokenAvailable ? "/test" : "/challenge"; @@ -24,7 +26,6 @@ export const NavigateBar = () => { navigate(path); }; const isActive = (path) => location.pathname === path; - console.log(isActive); return ( {NAVIGATE_TITLE.map((item) => ( @@ -33,13 +34,9 @@ export const NavigateBar = () => { className={ isActive( item.value === 1 - ? isTokenAvailable - ? "/dashboard" - : "/login" + ? `/nugu/${Cookies.get("uuid")}` : item.value === 2 - ? isTokenAvailable - ? "/intro" - : "/intro" + ? `/intro/${Cookies.get("uuid")}` : isTokenAvailable ? "/test" : "/challenge" diff --git a/src/pages/nugu/_hooks/useNuguInfo.js b/src/pages/nugu/_hooks/useNuguInfo.js index de152b2..91b805d 100644 --- a/src/pages/nugu/_hooks/useNuguInfo.js +++ b/src/pages/nugu/_hooks/useNuguInfo.js @@ -15,7 +15,9 @@ export const useNuguInfo = (uuid) => { const [isAdmin, setIsAdmin] = useState(false); useEffect(() => { - if (!uuid) return; + if (!Cookies.get("uuid")) { + Cookies.set("uuid", uuid); + } if (Cookies.get("access_token")) { setIsAdmin(true); } From 26cdc8f0b48d75c062906b7b71044430844d4d56 Mon Sep 17 00:00:00 2001 From: sayyyho <323psh@naver.com> Date: Wed, 13 Nov 2024 18:03:27 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[Feature]=20#41=20-=20=EB=88=84=EA=B5=AC?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=83=9D=EC=84=B1=20=EC=9C=A0?= =?UTF-8?q?=EB=AC=B4=20API=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/nuguTest.js | 15 +++++++++++++++ src/pages/nugu/_hooks/useNuguInfo.js | 5 ++++- src/pages/nuguTest/NuguTest.jsx | 10 +++++++--- src/router.jsx | 4 ++-- 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 src/apis/nuguTest.js diff --git a/src/apis/nuguTest.js b/src/apis/nuguTest.js new file mode 100644 index 0000000..3ab36b7 --- /dev/null +++ b/src/apis/nuguTest.js @@ -0,0 +1,15 @@ +import { instance } from "./instance"; + +export const getNuguTestStatus = async () => { + try { + const response = await instance.get("/tests/status"); + console.log(response); + if (response.data.hasTest) { + // TODO 수행한 인원 및 기타 작업 + return true; + } + return false; + } catch (err) { + throw err; + } +}; diff --git a/src/pages/nugu/_hooks/useNuguInfo.js b/src/pages/nugu/_hooks/useNuguInfo.js index 91b805d..b92566d 100644 --- a/src/pages/nugu/_hooks/useNuguInfo.js +++ b/src/pages/nugu/_hooks/useNuguInfo.js @@ -18,6 +18,7 @@ export const useNuguInfo = (uuid) => { if (!Cookies.get("uuid")) { Cookies.set("uuid", uuid); } + if (Cookies.get("access_token")) { setIsAdmin(true); } @@ -35,7 +36,9 @@ export const useNuguInfo = (uuid) => { keyword2, keyword3, } = response; - + if (!Cookies.get("nickname")) { + Cookies.set("nickname", nickname); + } setData({ nickname, mbti, diff --git a/src/pages/nuguTest/NuguTest.jsx b/src/pages/nuguTest/NuguTest.jsx index d53dc0e..cc06656 100644 --- a/src/pages/nuguTest/NuguTest.jsx +++ b/src/pages/nuguTest/NuguTest.jsx @@ -10,6 +10,10 @@ import { Button } from "@components/common/button/Button"; import { NuguTestTrue } from "@components/nuguTest/NuguTestTrue"; import { isMakeTestOwner } from "@atoms/nuguTestState"; import { useRecoilState } from "recoil"; + +import { getNuguTestStatus } from "@apis/nuguTest"; +import Cookies from "js-cookie"; + //토큰 여부로 워딩 다르게 표현 export const NuguTestPage = () => { const [isMakeTest, setIsMakeTest] = useRecoilState(isMakeTestOwner); @@ -18,7 +22,7 @@ export const NuguTestPage = () => { useEffect(() => { const fetchTestStatus = async () => { try { - const hasTest = false; + const hasTest = await getNuguTestStatus(); //누구 테스트 사용자-get setIsMakeTest(hasTest); } catch (error) { @@ -62,11 +66,11 @@ export const NuguTestPage = () => { array.length === 0 ? ( ) : ( - + ) ) : ( <> - + diff --git a/src/router.jsx b/src/router.jsx index dec7041..0750aa1 100644 --- a/src/router.jsx +++ b/src/router.jsx @@ -57,12 +57,12 @@ const router = createBrowserRouter([ }, { //접속자뷰 누구테스트홈 - path: "/challenge", + path: "/challenge/:uuid", element: , }, { // - path: "/challenge/test", + path: "/challenge/test/:uuid", element: , }, {