From 4e66c671fdd8e9cdb5d1a9a9305c81d85e08f714 Mon Sep 17 00:00:00 2001 From: Park Nayoung <139189221+im-na0@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:44:23 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=A6=AC=EB=8B=A4=EC=9D=B4=EB=A0=89?= =?UTF-8?q?=ED=8A=B8=20=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/redirect/Redirect.tsx | 25 + src/hooks/api/useUserInfoQuery.ts | 2 +- src/main.tsx | 7 +- .../verificationPage/VerificationPage.tsx | 2 +- src/routes/router.tsx | 706 +++++++++--------- 5 files changed, 386 insertions(+), 356 deletions(-) create mode 100644 src/components/redirect/Redirect.tsx diff --git a/src/components/redirect/Redirect.tsx b/src/components/redirect/Redirect.tsx new file mode 100644 index 00000000..b4a20f7b --- /dev/null +++ b/src/components/redirect/Redirect.tsx @@ -0,0 +1,25 @@ +import { PATH } from "@/constants/path"; +import useAuthStore from "@/store/authStore"; +import { useUserInfoStore } from "@/store/store"; +import { useEffect } from "react"; +import { useNavigate } from "react-router-dom"; + +interface RedirectProps { + children: React.ReactNode; +} + +const Redirect = ({ children }: RedirectProps) => { + const isLoggedIn = useAuthStore((state) => state.isLoggedIn); + const userInfo = useUserInfoStore((state) => state.userInfo); + const navigate = useNavigate(); + + useEffect(() => { + if (!isLoggedIn || !userInfo || userInfo.linkedToYanolja) { + navigate(PATH.ROOT); + } + }, [isLoggedIn, userInfo, navigate]); + + return <>{children}; +}; + +export default Redirect; diff --git a/src/hooks/api/useUserInfoQuery.ts b/src/hooks/api/useUserInfoQuery.ts index dd693a75..39a2adfd 100644 --- a/src/hooks/api/useUserInfoQuery.ts +++ b/src/hooks/api/useUserInfoQuery.ts @@ -10,7 +10,7 @@ interface AccountQueryProps { export const useAccountQuery = () => { const accountQuery = useSuspenseQuery({ - queryKey: ["myProfile"], + queryKey: ["userInfo", "account"], queryFn: async () => await fetchUserInfo(), refetchOnWindowFocus: false, refetchOnReconnect: false, diff --git a/src/main.tsx b/src/main.tsx index 885a51ed..422f373f 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -10,7 +10,12 @@ import { hydrate } from "react-dom"; const queryClient = new QueryClient({ defaultOptions: { queries: { - retry: 0, + retry: 1, + throwOnError: true, + }, + mutations: { + retry: 1, + throwOnError: true, }, }, }); diff --git a/src/pages/connectYanoljaPage/verificationPage/VerificationPage.tsx b/src/pages/connectYanoljaPage/verificationPage/VerificationPage.tsx index 8689c259..155ce99c 100644 --- a/src/pages/connectYanoljaPage/verificationPage/VerificationPage.tsx +++ b/src/pages/connectYanoljaPage/verificationPage/VerificationPage.tsx @@ -4,7 +4,7 @@ import TermsAgreementSection from "@pages/connectYanoljaPage/verificationPage/co import VerificationSection from "@pages/connectYanoljaPage/verificationPage/components/verificationSection/VerificationSection"; import { FormProvider, useForm } from "react-hook-form"; -import * as S from "./VerificationPage.style.ts"; +import * as S from "./VerificationPage.style"; const VerificationPage = () => { const methods = useForm({ diff --git a/src/routes/router.tsx b/src/routes/router.tsx index 818e89f2..e867b401 100644 --- a/src/routes/router.tsx +++ b/src/routes/router.tsx @@ -1,9 +1,7 @@ import { Suspense } from "react"; import { createBrowserRouter, Outlet, RouterProvider } from "react-router-dom"; import { HelmetTag } from "@/components/Helmet/Helmet.tsx"; - import { PATH } from "@/constants/path"; - import App from "@/App"; import Home from "@/pages/homePage/Home"; import NotFound from "@/pages/notFoundPage"; @@ -34,360 +32,362 @@ import Layout from "@components/layout/Layout"; import IntroPage from "@pages/connectYanoljaPage/IntroPage/IntroPage.tsx"; import SuccessPage from "@pages/connectYanoljaPage/successPage/SuccessPage.tsx"; import VerificationPage from "@pages/connectYanoljaPage/verificationPage/VerificationPage"; +import Redirect from "@/components/redirect/Redirect"; -const routes = createBrowserRouter([ - { - path: PATH.ROOT, - element: , - errorElement: ( - - - - ), - children: [ - { - path: "", - element: ( - - - - }> - - - - - ), - }, - { - path: PATH.LOGIN, - element: ( - - - - }> - - - - - ), - }, - { - path: PATH.SIGNUP, - element: ( - - - - }> - - - - - ), - }, - { - path: PATH.PASSWORD_RESET, - element: ( - - - - }> - - - - - ), - }, - { - path: PATH.SEARCHLIST, - element: ( - - - - }> - - - - - ), - }, - { - path: PATH.SEARCH_FILTER, - element: ( - - - - }> - - - - - ), - }, - { - path: PATH.WRITE_TRANSFER, - element: ( - - - }> - - - - - ), - }, - { - path: PATH.WRITE_TRANSFER, - element: ( - - - - }> - - - - - ), - }, - { - path: PATH.WRITE_TRANSFER_PRICE + `/:id`, - element: ( - - - - }> - - - - - ), - }, - { - path: PATH.WRITE_TRANSFER_SUCCESS, - element: ( - - - - }> - - - - - ), - }, - { - path: PATH.MY_PAGE, - element: ( - - - - }> - - - - - ), - children: [ - { - index: true, - element: ( - <> - - - - ), - }, +const AppRouter = () => { + const routes = createBrowserRouter([ + { + path: PATH.ROOT, + element: , + errorElement: ( + + + + ), + children: [ + { + path: "", + element: ( + + + + }> + + + + + ), + }, + { + path: PATH.LOGIN, + element: ( + + + + }> + + + + + ), + }, + { + path: PATH.SIGNUP, + element: ( + + + + }> + + + + + ), + }, + { + path: PATH.PASSWORD_RESET, + element: ( + + + + }> + + + + + ), + }, + { + path: PATH.SEARCHLIST, + element: ( + + + + }> + + + + + ), + }, + { + path: PATH.SEARCH_FILTER, + element: ( + + + + }> + + + + + ), + }, + { + path: PATH.WRITE_TRANSFER, + element: ( + + + }> + + + + + ), + }, + { + path: PATH.WRITE_TRANSFER, + element: ( + + + + }> + + + + + ), + }, + { + path: PATH.WRITE_TRANSFER_PRICE + `/:id`, + element: ( + + + + }> + + + + + ), + }, + { + path: PATH.WRITE_TRANSFER_SUCCESS, + element: ( + + + + }> + + + + + ), + }, + { + path: PATH.MY_PAGE, + element: ( + + + + }> + + + + + ), + children: [ + { + index: true, + element: ( + <> + + + + ), + }, - { - path: PATH.SALE_LIST, - element: ( - <> - - - - ), - }, - ], - }, - { - path: PATH.SETTING, - element: ( - - - }> - - - - - ), - }, - { - path: PATH.MANAGE_PROFILE, - element: ( - - - }> - - - - - ), - }, - { - path: PATH.MANAGE_ACCOUNT, - element: ( - - - }> - - - - - ), - }, - { - path: PATH.ACCOUNT_EDIT, - element: ( - - - }> - - - - - ), - }, - { - path: PATH.DETAIL_ROOM(":productId"), - element: ( - - - }> - - - - - ), - }, - { - path: PATH.ALARM, - element: ( - - - - }> - - - - - ), - }, - { - path: PATH.PURCAHSE_DETAIL, - element: ( - - - - }> - - - - - ), - }, - { - path: PATH.SALE_DETAIL + "/:saleId", - element: ( - - - - }> - - - - - ), - }, - { - path: PATH.YANOLJA_ACCOUNT, - element: ( - - - - }> - - - - - ), - }, - { - path: PATH.YANOLJA_ACCOUNT_VERIFICATION, - element: ( - - - - - }> - - - - - ), - }, - { - path: PATH.YANOLJA_ACCOUNT_VERIFICATION_SUCCESS, - element: ( - - - - }> - - - - - ), - }, - { - path: PATH.PAYMENT(":productId"), - element: ( - - - - }> - - - - - ), - children: [ - { - path: "", - element: , - }, - { - path: "success", - element: ( - <> - - - - ), - }, - { - path: "ready", - element: , - }, - { - path: "cancel", - element: , - }, - ], - }, - ], - }, -]); + { + path: PATH.SALE_LIST, + element: ( + <> + + + + ), + }, + ], + }, + { + path: PATH.SETTING, + element: ( + + + }> + + + + + ), + }, + { + path: PATH.MANAGE_PROFILE, + element: ( + + + }> + + + + + ), + }, + { + path: PATH.MANAGE_ACCOUNT, + element: ( + + + }> + + + + + ), + }, + { + path: PATH.ACCOUNT_EDIT, + element: ( + + + }> + + + + + ), + }, + { + path: PATH.DETAIL_ROOM(":productId"), + element: ( + + + }> + + + + + ), + }, + { + path: PATH.ALARM, + element: ( + + + + }> + + + + + ), + }, + { + path: PATH.PURCAHSE_DETAIL, + element: ( + + + + }> + + + + + ), + }, + { + path: PATH.SALE_DETAIL + "/:saleId", + element: ( + + + + }> + + + + + ), + }, + { + path: PATH.YANOLJA_ACCOUNT, + element: ( + + + + }> + + + + + ), + }, + { + path: PATH.YANOLJA_ACCOUNT_VERIFICATION, + element: ( + + + + + }> + + + + + + ), + }, + { + path: PATH.YANOLJA_ACCOUNT_VERIFICATION_SUCCESS, + element: ( + + + + }> + + + + + ), + }, + { + path: PATH.PAYMENT(":productId"), + element: ( + + + + }> + + + + + ), + children: [ + { + path: "", + element: , + }, + { + path: "success", + element: ( + <> + + + + ), + }, + { + path: "ready", + element: , + }, + { + path: "cancel", + element: , + }, + ], + }, + ], + }, + ]); -const AppRouter = () => { return ; };