From c2c609f066e4d615ce35421ea9072f7e9b37ee29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Thu, 28 Mar 2024 01:58:29 +0900 Subject: [PATCH 01/24] =?UTF-8?q?fix:=20=EC=9A=A9=EC=96=B4=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20store=20>=20shop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 2 +- src/layout/DefaultLayout/index.tsx | 4 ++-- src/page/MyShopPage/index.tsx | 2 +- src/query/auth.ts | 2 +- src/store/path.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 38170254..dcc5cc3c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -20,7 +20,7 @@ function App() { }> } /> - } /> + } /> } /> } /> } /> diff --git a/src/layout/DefaultLayout/index.tsx b/src/layout/DefaultLayout/index.tsx index 40c0298c..8995200a 100644 --- a/src/layout/DefaultLayout/index.tsx +++ b/src/layout/DefaultLayout/index.tsx @@ -18,7 +18,7 @@ export default function DefaultLayout() { setUser() .catch(handleErrorBoundary) .catch(() => { - setPrevPath('/store-registration'); + setPrevPath('/shop-registration'); navigate('/login', { replace: true }); }); } @@ -28,7 +28,7 @@ export default function DefaultLayout() {
{user && ( <> - {location.pathname !== '/store-registration' &&
} + {location.pathname !== '/shop-registration' &&
} diff --git a/src/page/MyShopPage/index.tsx b/src/page/MyShopPage/index.tsx index 170654e9..35f464db 100644 --- a/src/page/MyShopPage/index.tsx +++ b/src/page/MyShopPage/index.tsx @@ -38,7 +38,7 @@ export default function MyShopPage() { useEffect(() => { if (!shopData && !isLoading) { - navigate('/store-registration'); + navigate('/shop-registration'); } }, [shopData, navigate, isLoading]); diff --git a/src/query/auth.ts b/src/query/auth.ts index d7d2179c..5550b79e 100644 --- a/src/query/auth.ts +++ b/src/query/auth.ts @@ -51,7 +51,7 @@ export const useLogin = () => { setPrevPath('/'); navigate('/'); } else { - navigate('/store-registration'); + navigate('/shop-registration'); } }, onError: (err: AxiosError) => { diff --git a/src/store/path.ts b/src/store/path.ts index 04805653..e57b7706 100644 --- a/src/store/path.ts +++ b/src/store/path.ts @@ -6,7 +6,7 @@ interface PrevPathStore { } const usePrevPathStore = create((set) => ({ - prevPath: '/store-registration', + prevPath: '/shop-registration', setPrevPath: (prevPath) => { set(() => ({ prevPath })); }, })); From fc2afced6c73a71afa429656d573780dddb5be37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Fri, 29 Mar 2024 16:48:00 +0900 Subject: [PATCH 02/24] =?UTF-8?q?feat:=20userType=20=EC=A0=84=EC=97=AD=20?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/auth/index.ts | 8 +++++++- src/query/auth.ts | 4 ++++ src/store/userType.ts | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/store/userType.ts diff --git a/src/model/auth/index.ts b/src/model/auth/index.ts index e54cd841..3e4999f6 100644 --- a/src/model/auth/index.ts +++ b/src/model/auth/index.ts @@ -7,10 +7,16 @@ export const LoginParams = z.object({ export type LoginParams = z.infer; +export enum UserType { + STUDENT = 'STUDENT', + COOP = 'COOP', + OWNER = 'OWNER', +} + export const LoginResponse = z.object({ refresh_token: z.string(), token: z.string(), - user_type: z.string(), + user_type: z.nativeEnum(UserType), }); export type LoginResponse = z.infer; diff --git a/src/query/auth.ts b/src/query/auth.ts index 5550b79e..dbb6e6f0 100644 --- a/src/query/auth.ts +++ b/src/query/auth.ts @@ -9,6 +9,7 @@ import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useErrorMessageStore } from 'store/errorMessageStore'; import usePrevPathStore from 'store/path'; +import useUserTypeStore from 'store/userType'; interface VerifyInput { email: string; @@ -34,6 +35,7 @@ export const useLogin = () => { const navigate = useNavigate(); const { setPrevPath } = usePrevPathStore((state) => state); const { setLoginError } = useErrorMessageStore(); + const { setUserType } = useUserTypeStore(); const { mutate, error, isError } = useMutation({ mutationFn: (variables: LoginForm) => postLogin({ @@ -46,6 +48,8 @@ export const useLogin = () => { localStorage.setItem('refresh_token', data.refresh_token); } + setUserType(data.user_type); + const myShopData = await getMyShopList(); if (myShopData.count > 0) { setPrevPath('/'); diff --git a/src/store/userType.ts b/src/store/userType.ts new file mode 100644 index 00000000..5d5f2ead --- /dev/null +++ b/src/store/userType.ts @@ -0,0 +1,14 @@ +import { UserType } from 'model/auth'; +import { create } from 'zustand'; + +interface UserTypeStore { + userType: UserType; + setUserType: (type: UserType) => void; +} + +const useUserTypeStore = create((set) => ({ + userType: 'NOT_LOGGED_IN', + setUserType: (userType) => set({ userType }), +})); + +export default useUserTypeStore; From a7733c1dad84b83e72be1e06abd2a4269440e418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Fri, 29 Mar 2024 19:47:29 +0900 Subject: [PATCH 03/24] =?UTF-8?q?feat:=20coop=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - userType에 따라 다른 뷰 출력 --- src/App.tsx | 52 +++++++++++++++----- src/layout/CoopLayout/CoopLayout.module.scss | 0 src/layout/CoopLayout/index.tsx | 7 +++ src/model/auth/index.ts | 1 + "src/page/\bCoopPage/\bCoopPage.module.scss" | 0 "src/page/\bCoopPage/index.tsx" | 7 +++ src/store/userType.ts | 2 +- 7 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 src/layout/CoopLayout/CoopLayout.module.scss create mode 100644 src/layout/CoopLayout/index.tsx create mode 100644 "src/page/\bCoopPage/\bCoopPage.module.scss" create mode 100644 "src/page/\bCoopPage/index.tsx" diff --git a/src/App.tsx b/src/App.tsx index dcc5cc3c..4e840a68 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,6 @@ -import { Routes, Route } from 'react-router-dom'; +import { + Routes, Route, Navigate, Outlet, +} from 'react-router-dom'; import DefaultLayout from 'layout/DefaultLayout'; import Login from 'page/Auth/Login'; import Signup from 'page/Auth/Signup'; @@ -13,22 +15,50 @@ import PageNotFound from 'page/Error/PageNotFound'; import ModifyMenu from 'page/ModifyMenu'; import { Suspense } from 'react'; import Toast from 'component/common/Toast'; +import { UserType } from 'model/auth'; +import useUserTypeStore from 'store/userType'; +import CoopLayout from 'layout/CoopLayout'; +import CoopPage from 'page/\bCoopPage'; + +interface ProtectedRouteProps { + userTypeRequired: UserType; +} + +function ProtectedRoute({ userTypeRequired }: ProtectedRouteProps) { + const { userType } = useUserTypeStore(); + + if (userType !== userTypeRequired) { + return ; + } + + return ; +} function App() { return ( }> - }> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> + }> + }> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + + }> + }> + } /> + } /> + {/* CoopPage1, CoopPage2는 예시 경로임 */} + + + }> } /> } /> diff --git a/src/layout/CoopLayout/CoopLayout.module.scss b/src/layout/CoopLayout/CoopLayout.module.scss new file mode 100644 index 00000000..e69de29b diff --git a/src/layout/CoopLayout/index.tsx b/src/layout/CoopLayout/index.tsx new file mode 100644 index 00000000..ae861cd0 --- /dev/null +++ b/src/layout/CoopLayout/index.tsx @@ -0,0 +1,7 @@ +export default function CoopLayout() { + return ( + <> + coop layout + + ); +} diff --git a/src/model/auth/index.ts b/src/model/auth/index.ts index 3e4999f6..97e0fa37 100644 --- a/src/model/auth/index.ts +++ b/src/model/auth/index.ts @@ -8,6 +8,7 @@ export const LoginParams = z.object({ export type LoginParams = z.infer; export enum UserType { + NOT_LOGGED_IN = 'NOT_LOGGED_IN', STUDENT = 'STUDENT', COOP = 'COOP', OWNER = 'OWNER', diff --git "a/src/page/\bCoopPage/\bCoopPage.module.scss" "b/src/page/\bCoopPage/\bCoopPage.module.scss" new file mode 100644 index 00000000..e69de29b diff --git "a/src/page/\bCoopPage/index.tsx" "b/src/page/\bCoopPage/index.tsx" new file mode 100644 index 00000000..377ccc37 --- /dev/null +++ "b/src/page/\bCoopPage/index.tsx" @@ -0,0 +1,7 @@ +export default function CoopPage() { + return ( + <> + coop page + + ); +} diff --git a/src/store/userType.ts b/src/store/userType.ts index 5d5f2ead..24882240 100644 --- a/src/store/userType.ts +++ b/src/store/userType.ts @@ -7,7 +7,7 @@ interface UserTypeStore { } const useUserTypeStore = create((set) => ({ - userType: 'NOT_LOGGED_IN', + userType: UserType.NOT_LOGGED_IN, setUserType: (userType) => set({ userType }), })); From 8162d253a13834bf75c19eddb6fd4ca0e8d08041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Fri, 29 Mar 2024 20:51:35 +0900 Subject: [PATCH 04/24] =?UTF-8?q?feat:=20enum=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=EC=9D=84=20literal=20=ED=83=80=EC=9E=85=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 4 ++-- src/model/auth/index.ts | 13 ++++++------- src/store/userType.ts | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 4e840a68..d2aa4436 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -38,7 +38,7 @@ function App() { return ( }> - }> + }> }> } /> } /> @@ -51,7 +51,7 @@ function App() { } /> - }> + }> }> } /> } /> diff --git a/src/model/auth/index.ts b/src/model/auth/index.ts index 97e0fa37..5998b442 100644 --- a/src/model/auth/index.ts +++ b/src/model/auth/index.ts @@ -7,17 +7,16 @@ export const LoginParams = z.object({ export type LoginParams = z.infer; -export enum UserType { - NOT_LOGGED_IN = 'NOT_LOGGED_IN', - STUDENT = 'STUDENT', - COOP = 'COOP', - OWNER = 'OWNER', -} +export type UserType = 'NOT_LOGGED_IN' | 'COOP' | 'OWNER'; export const LoginResponse = z.object({ refresh_token: z.string(), token: z.string(), - user_type: z.nativeEnum(UserType), + user_type: z.union([ + z.literal('NOT_LOGGED_IN'), + z.literal('COOP'), + z.literal('OWNER'), + ]), }); export type LoginResponse = z.infer; diff --git a/src/store/userType.ts b/src/store/userType.ts index 24882240..5d5f2ead 100644 --- a/src/store/userType.ts +++ b/src/store/userType.ts @@ -7,7 +7,7 @@ interface UserTypeStore { } const useUserTypeStore = create((set) => ({ - userType: UserType.NOT_LOGGED_IN, + userType: 'NOT_LOGGED_IN', setUserType: (userType) => set({ userType }), })); From 6ce988f4dc27d394e0ba1469d9e988829c426688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Fri, 29 Mar 2024 21:04:36 +0900 Subject: [PATCH 05/24] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=8B=9C=20owner,=20coop=EC=97=90=20=EB=94=B0=EB=9D=BC=20?= =?UTF-8?q?=EB=B6=84=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/query/auth.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/query/auth.ts b/src/query/auth.ts index dbb6e6f0..8d7d9192 100644 --- a/src/query/auth.ts +++ b/src/query/auth.ts @@ -50,13 +50,17 @@ export const useLogin = () => { setUserType(data.user_type); - const myShopData = await getMyShopList(); - if (myShopData.count > 0) { - setPrevPath('/'); - navigate('/'); - } else { - navigate('/shop-registration'); - } + if (data.user_type === 'OWNER') { + const myShopData = await getMyShopList(); + if (myShopData.count > 0) { + setPrevPath('/'); + navigate('/'); + } else { + navigate('/shop-registration'); + } + } else if (data.user_type === 'COOP') { + navigate('/coop'); + } else; }, onError: (err: AxiosError) => { sessionStorage.removeItem('access_token'); From 3b9d498659634528312cbfa24710c689e2876679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Sat, 30 Mar 2024 14:47:13 +0900 Subject: [PATCH 06/24] =?UTF-8?q?fix:=20lint=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/CoopLayout/CoopLayout.module.scss | 0 "src/page/\bCoopPage/\bCoopPage.module.scss" | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/layout/CoopLayout/CoopLayout.module.scss delete mode 100644 "src/page/\bCoopPage/\bCoopPage.module.scss" diff --git a/src/layout/CoopLayout/CoopLayout.module.scss b/src/layout/CoopLayout/CoopLayout.module.scss deleted file mode 100644 index e69de29b..00000000 diff --git "a/src/page/\bCoopPage/\bCoopPage.module.scss" "b/src/page/\bCoopPage/\bCoopPage.module.scss" deleted file mode 100644 index e69de29b..00000000 From 0135ea869a686a9222a40f1c02291d3553e2d3e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Sat, 30 Mar 2024 16:26:04 +0900 Subject: [PATCH 07/24] =?UTF-8?q?fix:=20=ED=8C=8C=EC=9D=BC=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 2 +- "src/page/\bCoopPage/index.tsx" => src/page/CoopPage/index.tsx | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename "src/page/\bCoopPage/index.tsx" => src/page/CoopPage/index.tsx (100%) diff --git a/src/App.tsx b/src/App.tsx index d2aa4436..89e61d4c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -18,7 +18,7 @@ import Toast from 'component/common/Toast'; import { UserType } from 'model/auth'; import useUserTypeStore from 'store/userType'; import CoopLayout from 'layout/CoopLayout'; -import CoopPage from 'page/\bCoopPage'; +import CoopPage from 'page/CoopPage'; interface ProtectedRouteProps { userTypeRequired: UserType; diff --git "a/src/page/\bCoopPage/index.tsx" b/src/page/CoopPage/index.tsx similarity index 100% rename from "src/page/\bCoopPage/index.tsx" rename to src/page/CoopPage/index.tsx From e434a5010faf899de5e08158fa1155031f13079e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Tue, 2 Apr 2024 14:12:20 +0900 Subject: [PATCH 08/24] =?UTF-8?q?refactor:=20=EB=A6=AC=EB=8B=A4=EC=9D=B4?= =?UTF-8?q?=EB=A0=89=ED=8A=B8=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 89e61d4c..af60f79a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -28,7 +28,15 @@ function ProtectedRoute({ userTypeRequired }: ProtectedRouteProps) { const { userType } = useUserTypeStore(); if (userType !== userTypeRequired) { - return ; + if (userType === 'NOT_LOGGED_IN') { + return ; + } + if (userType === 'OWNER') { + return ; + } + if (userType === 'COOP') { + return ; + } } return ; @@ -60,10 +68,12 @@ function App() { }> - } /> - } /> - } /> - } /> + }> + } /> + } /> + } /> + } /> + } /> } /> From 1de568d5189cb2c8ef47ab3d3ffa6c79bf70a595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Wed, 3 Apr 2024 16:38:12 +0900 Subject: [PATCH 09/24] =?UTF-8?q?feat:=20=EC=82=AC=EC=9E=A5=EB=8B=98=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20url=20=EA=B2=BD=EB=A1=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 25 ++++++++++--------- src/component/common/Header/index.tsx | 10 ++++---- src/layout/AuthLayout/index.tsx | 2 +- src/layout/DefaultLayout/index.tsx | 4 +-- src/page/AddMenu/index.tsx | 2 +- src/page/Error/PageNotFound/index.tsx | 2 +- src/page/ModifyMenu/index.tsx | 2 +- .../components/CatagoryMenuList/index.tsx | 2 +- src/page/MyShopPage/index.tsx | 4 +-- src/query/auth.ts | 6 ++--- src/store/path.ts | 2 +- src/utils/constant/category.ts | 10 ++++---- 12 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index af60f79a..a8bdc4e8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -32,7 +32,7 @@ function ProtectedRoute({ userTypeRequired }: ProtectedRouteProps) { return ; } if (userType === 'OWNER') { - return ; + return ; } if (userType === 'COOP') { return ; @@ -46,17 +46,18 @@ function App() { return ( }> + } /> }> - }> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> + }> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> }> @@ -68,8 +69,8 @@ function App() { }> + } /> }> - } /> } /> } /> } /> diff --git a/src/component/common/Header/index.tsx b/src/component/common/Header/index.tsx index 88441938..5958d137 100644 --- a/src/component/common/Header/index.tsx +++ b/src/component/common/Header/index.tsx @@ -46,7 +46,7 @@ function Header() { }); }; - if ((pathname === '/add-menu' || pathname.startsWith('/modify-menu/')) && isMobile) { + if ((pathname === '/owner/add-menu' || pathname.startsWith('/owner/modify-menu/')) && isMobile) { return (
-
{pathname === '/add-menu' ? '메뉴추가' : '메뉴수정'}
+
{pathname === '/owner/add-menu' ? '메뉴추가' : '메뉴수정'}
); } @@ -86,7 +86,7 @@ function Header() { )} - {pathname === '/' ? ( + {pathname === '/owner' ? ( ) : (CATEGORY .flatMap((categoryValue) => categoryValue.submenu) @@ -128,7 +128,7 @@ function Header() {
  • - + 내 정보
  • @@ -245,7 +245,7 @@ function Header() {
      {/* Auth 완료시 수정 필요 */}
    • - + 정보수정
    • diff --git a/src/layout/AuthLayout/index.tsx b/src/layout/AuthLayout/index.tsx index 50489493..88001f01 100644 --- a/src/layout/AuthLayout/index.tsx +++ b/src/layout/AuthLayout/index.tsx @@ -13,7 +13,7 @@ export default function AuthLayout() { // @ChoiWonBeen 토큰없음 에러제거. TODO: setUser가 에러를 다루는 문제 제거 setUser().catch(() => {}); if (user) { - navigate('/', { replace: true }); + navigate('/owner', { replace: true }); } }, [setUser, user, navigate]); diff --git a/src/layout/DefaultLayout/index.tsx b/src/layout/DefaultLayout/index.tsx index 8995200a..bf20f098 100644 --- a/src/layout/DefaultLayout/index.tsx +++ b/src/layout/DefaultLayout/index.tsx @@ -18,7 +18,7 @@ export default function DefaultLayout() { setUser() .catch(handleErrorBoundary) .catch(() => { - setPrevPath('/shop-registration'); + setPrevPath('/owner/shop-registration'); navigate('/login', { replace: true }); }); } @@ -28,7 +28,7 @@ export default function DefaultLayout() {
      {user && ( <> - {location.pathname !== '/shop-registration' &&
      } + {location.pathname !== '/owner/shop-registration' &&
      } diff --git a/src/page/AddMenu/index.tsx b/src/page/AddMenu/index.tsx index 8a6d4f4c..ff342551 100644 --- a/src/page/AddMenu/index.tsx +++ b/src/page/AddMenu/index.tsx @@ -24,7 +24,7 @@ export default function AddMenu() { const { resetMenuName, resetCategoryIds } = useAddMenuStore(); const { setMenuError, setCategoryError } = useErrorMessageStore(); const goMyShop = () => { - navigate('/'); + navigate('/owner'); }; const { value: isGoMyShopModal, diff --git a/src/page/Error/PageNotFound/index.tsx b/src/page/Error/PageNotFound/index.tsx index eee84637..1779778d 100644 --- a/src/page/Error/PageNotFound/index.tsx +++ b/src/page/Error/PageNotFound/index.tsx @@ -20,7 +20,7 @@ export default function PageNotFound() { diff --git a/src/page/ModifyMenu/index.tsx b/src/page/ModifyMenu/index.tsx index 3938ab23..67059b73 100644 --- a/src/page/ModifyMenu/index.tsx +++ b/src/page/ModifyMenu/index.tsx @@ -26,7 +26,7 @@ export default function ModifyMenu() { const { menuData, modifyMenuMutation } = useMenuInfo(Number(menuId)); const goMyShop = () => { - navigate('/'); + navigate('/owner'); }; const toggleConfirmClick = () => { diff --git a/src/page/MyShopPage/components/CatagoryMenuList/index.tsx b/src/page/MyShopPage/components/CatagoryMenuList/index.tsx index 6717abab..4a9fd1da 100644 --- a/src/page/MyShopPage/components/CatagoryMenuList/index.tsx +++ b/src/page/MyShopPage/components/CatagoryMenuList/index.tsx @@ -7,7 +7,7 @@ import styles from './CatagoryMenuList.module.scss'; export default function CatagoryMenuList({ menuCategory }: { menuCategory: MenuCategory }) { const navigate = useNavigate(); const handleMenuClick = (menuId: number) => { - navigate(`/modify-menu/${menuId}`); + navigate(`/owner/modify-menu/${menuId}`); }; return (
      diff --git a/src/page/MyShopPage/index.tsx b/src/page/MyShopPage/index.tsx index 35f464db..dae4b800 100644 --- a/src/page/MyShopPage/index.tsx +++ b/src/page/MyShopPage/index.tsx @@ -63,7 +63,7 @@ export default function MyShopPage() { <>

      가게정보

      - + @@ -250,7 +251,7 @@ function Header() {
    • -
    • diff --git a/src/query/auth.ts b/src/query/auth.ts index 14c1c905..2c657204 100644 --- a/src/query/auth.ts +++ b/src/query/auth.ts @@ -1,17 +1,15 @@ import { useMutation } from '@tanstack/react-query'; import { - postLogin, findPasswordVerify, findPassword, newPassword, + postLogin, postLogout, findPasswordVerify, findPassword, newPassword, } from 'api/auth'; -import { getMyShopList } from 'api/shop'; import axios, { AxiosError } from 'axios'; import { LoginForm } from 'model/auth'; import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useErrorMessageStore } from 'store/errorMessageStore'; -import usePrevPathStore from 'store/path'; import useUserTypeStore from 'store/userType'; import { isKoinError } from 'utils/ts/isKoinError'; -import useStepStore from 'store/useStepStore'; +import useUserStore from 'store/user'; interface VerifyInput { email: string; @@ -34,11 +32,8 @@ export interface ErrorResponse { } export const useLogin = () => { - const navigate = useNavigate(); - const { setPrevPath } = usePrevPathStore((state) => state); - const { setUserType } = useUserTypeStore(); + const { setUserType, setIsAuth } = useUserTypeStore(); const { setLoginError, setLoginErrorCode } = useErrorMessageStore(); - const setStep = useStepStore((state) => state.setStep); const { mutate, error, isError } = useMutation({ mutationFn: (variables: LoginForm) => postLogin({ @@ -80,6 +75,26 @@ export const useLogin = () => { return { login: mutate, error, isError }; }; +export const useLogout = () => { + const { setUserType, setIsAuth } = useUserTypeStore(); + const { removeUser } = useUserStore(); + + const { mutate, error, isError } = useMutation({ + mutationFn: async () => { + await postLogout() + .then(() => { + sessionStorage.removeItem('access_token'); + localStorage.removeItem('refresh_token'); + removeUser(); + setUserType('NOT_LOGGED_IN'); + setIsAuth(false); + }); + }, + }); + + return { logout: mutate, error, isError }; +}; + export const useVerifyEmail = () => { const [errorMessage, setErrorMessage] = useState(''); const { mutate, isPending, isSuccess } = useMutation({ From 861cba66771a37277c8b166afd03fbc63aa85bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Fri, 5 Apr 2024 09:45:07 +0900 Subject: [PATCH 12/24] =?UTF-8?q?feat:=20isAuth=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/userType.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/store/userType.ts b/src/store/userType.ts index 5d5f2ead..21a273c6 100644 --- a/src/store/userType.ts +++ b/src/store/userType.ts @@ -3,12 +3,16 @@ import { create } from 'zustand'; interface UserTypeStore { userType: UserType; + isAuth: boolean; setUserType: (type: UserType) => void; + setIsAuth: (auth: boolean) => void; } const useUserTypeStore = create((set) => ({ userType: 'NOT_LOGGED_IN', + isAuth: false, setUserType: (userType) => set({ userType }), + setIsAuth: (isAuth) => set({ isAuth }), })); export default useUserTypeStore; From 753742ac5b93bb972edfbee8b4d49e5ac37e07bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Fri, 5 Apr 2024 10:58:52 +0900 Subject: [PATCH 13/24] =?UTF-8?q?refactor:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=20=EC=84=B1=EA=B3=B5=20=EC=8B=9C=20=EB=A6=AC=EB=8B=A4=EC=9D=B4?= =?UTF-8?q?=EB=A0=89=ED=8A=B8=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - getMyShopList 처리 위치, 조건 변경 --- src/page/Auth/Login/index.tsx | 34 +++++++++++++++++++++++++++++++--- src/query/auth.ts | 22 +++++++--------------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/page/Auth/Login/index.tsx b/src/page/Auth/Login/index.tsx index 668242a5..617d1f63 100644 --- a/src/page/Auth/Login/index.tsx +++ b/src/page/Auth/Login/index.tsx @@ -10,9 +10,13 @@ import { useLogin } from 'query/auth'; import { FieldErrors, SubmitHandler, useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { LoginParams } from 'model/auth'; -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import sha256 from 'utils/ts/SHA-256'; import { useErrorMessageStore } from 'store/errorMessageStore'; +import usePrevPathStore from 'store/path'; +import useStepStore from 'store/useStepStore'; +import { getMyShopList } from 'api/shop'; +import useUserTypeStore from 'store/userType'; import styles from './Login.module.scss'; import OPTION from './static/option'; import ApprovalModal from './ApprovalModal'; @@ -21,14 +25,16 @@ export default function Login() { const { value: isBlind, changeValue: changeIsBlind } = useBooleanState(); const { value: isAutoLogin, changeValue: changeIsAutoLogin } = useBooleanState(true); const { isMobile } = useMediaQuery(); - const { login, isError: isServerError } = useLogin(); + const { login, isError: isServerError, isSuccess } = useLogin(); const [isFormError, setIsFormError] = useState(false); const navigate = useNavigate(); const { loginError, loginErrorCode } = useErrorMessageStore(); const [emailError, setEmailError] = useState(''); const { value: isModalOpen, changeValue: toggle } = useBooleanState(false); - + const { setPrevPath } = usePrevPathStore((state) => state); + const setStep = useStepStore((state) => state.setStep); const isError = isServerError || isFormError; + const { userType } = useUserTypeStore(); const { register, @@ -37,6 +43,28 @@ export default function Login() { resolver: zodResolver(LoginParams), }); + useEffect(() => { + const fetchShopList = async () => { + if (userType === 'OWNER') { + const myShopData = await getMyShopList(); + if (myShopData.count > 0) { + setPrevPath('/owner'); + navigate('/owner'); + } else { + setStep(0); + navigate('/owner/shop-registration'); + } + } + if (userType === 'COOP') { + navigate('/coop'); + } + }; + + if (isSuccess) { + fetchShopList(); + } + }, [isSuccess, userType, navigate, setPrevPath, setStep]); + const onSubmit: SubmitHandler = async (data) => { const hashedPassword = await sha256(data.password); login({ email: data.email, password: hashedPassword, isAutoLogin }); diff --git a/src/query/auth.ts b/src/query/auth.ts index 2c657204..f6d3a322 100644 --- a/src/query/auth.ts +++ b/src/query/auth.ts @@ -35,7 +35,9 @@ export const useLogin = () => { const { setUserType, setIsAuth } = useUserTypeStore(); const { setLoginError, setLoginErrorCode } = useErrorMessageStore(); - const { mutate, error, isError } = useMutation({ + const { + mutate, error, isError, isSuccess, + } = useMutation({ mutationFn: (variables: LoginForm) => postLogin({ email: variables.email, password: variables.password, }), @@ -47,19 +49,7 @@ export const useLogin = () => { } setUserType(data.user_type); - - if (data.user_type === 'OWNER') { - const myShopData = await getMyShopList(); - if (myShopData.count > 0) { - setPrevPath('/owner'); - navigate('/owner'); - } else { - setStep(0); - navigate('/owner/shop-registration'); - } - } else if (data.user_type === 'COOP') { - navigate('/coop'); - } else; + setIsAuth(true); }, onError: (err: unknown) => { if (isKoinError(err)) { @@ -72,7 +62,9 @@ export const useLogin = () => { }, }); - return { login: mutate, error, isError }; + return { + login: mutate, error, isError, isSuccess, + }; }; export const useLogout = () => { From 6445a3253e3fb068bff5af2fc73b3bc99902f00c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Fri, 5 Apr 2024 17:23:13 +0900 Subject: [PATCH 14/24] =?UTF-8?q?refactor:=20logout=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EA=B0=9C=ED=8E=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/component/common/Header/index.tsx | 10 +++++++--- src/query/auth.ts | 28 ++++++++++++++++++--------- src/store/errorMessageStore.ts | 8 ++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/component/common/Header/index.tsx b/src/component/common/Header/index.tsx index fb042574..c392f536 100644 --- a/src/component/common/Header/index.tsx +++ b/src/component/common/Header/index.tsx @@ -42,9 +42,13 @@ function Header() { const { setPrevPath } = usePrevPathStore((state) => state); const handleLogout = () => { - logout(); - setPrevPath('/login'); - navigate('/login'); + console.log('logout시도'); + logout(undefined, { + onSettled: () => { + setPrevPath('/login'); + navigate('/login'); + }, + }); }; if ((pathname === '/owner/add-menu' || pathname.startsWith('/owner/modify-menu/')) && isMobile) { diff --git a/src/query/auth.ts b/src/query/auth.ts index f6d3a322..333b5934 100644 --- a/src/query/auth.ts +++ b/src/query/auth.ts @@ -68,19 +68,29 @@ export const useLogin = () => { }; export const useLogout = () => { - const { setUserType, setIsAuth } = useUserTypeStore(); + const { setUserType } = useUserTypeStore(); const { removeUser } = useUserStore(); + const { setLogoutError, setLogoutErrorCode } = useErrorMessageStore(); const { mutate, error, isError } = useMutation({ mutationFn: async () => { - await postLogout() - .then(() => { - sessionStorage.removeItem('access_token'); - localStorage.removeItem('refresh_token'); - removeUser(); - setUserType('NOT_LOGGED_IN'); - setIsAuth(false); - }); + const response = await postLogout(); + if (response) { + return true; + } + throw new Error('로그아웃 실패'); + }, + onSuccess: () => { + sessionStorage.removeItem('access_token'); + localStorage.removeItem('refresh_token'); + removeUser(); + setUserType('NOT_LOGGED_IN'); + }, + onError: (err: unknown) => { + if (isKoinError(err)) { + setLogoutError(err.message || '로그아웃을 실패했습니다.'); + setLogoutErrorCode(err.code); + } }, }); diff --git a/src/store/errorMessageStore.ts b/src/store/errorMessageStore.ts index 648d0040..c03d8ae7 100644 --- a/src/store/errorMessageStore.ts +++ b/src/store/errorMessageStore.ts @@ -9,6 +9,10 @@ interface ErrorMessageStore { setLoginError: (error: string) => void; loginErrorCode: number; setLoginErrorCode: (error: number) => void; + logoutError: string; + setLogoutError: (error: string) => void; + logoutErrorCode: number; + setLogoutErrorCode: (error: number) => void; } export const useErrorMessageStore = create((set) => ({ @@ -20,4 +24,8 @@ export const useErrorMessageStore = create((set) => ({ setLoginError: (error) => set({ loginError: error }), loginErrorCode: 0, setLoginErrorCode: (error) => set({ loginErrorCode: error }), + logoutError: '', + setLogoutError: (error) => set({ loginError: error }), + logoutErrorCode: 0, + setLogoutErrorCode: (error) => set({ loginErrorCode: error }), })); From bd14d97e9fdd22aad91346b9f8569596fb2ed464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Fri, 5 Apr 2024 17:23:25 +0900 Subject: [PATCH 15/24] =?UTF-8?q?refactor:=20=EB=A6=AC=EB=8B=A4=EC=9D=B4?= =?UTF-8?q?=EB=A0=89=ED=8A=B8=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - isAuth 삭제 --- src/App.tsx | 30 ++++++++++++++------------- src/component/common/Header/index.tsx | 1 - src/query/auth.ts | 3 +-- src/store/userType.ts | 3 --- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index f780311b..ff9bd78e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import { - Routes, Route, Navigate, Outlet, useNavigate, + Routes, Route, Navigate, Outlet, useNavigate, useLocation, } from 'react-router-dom'; import DefaultLayout from 'layout/DefaultLayout'; import Login from 'page/Auth/Login'; @@ -13,7 +13,7 @@ import ShopRegistration from 'page/ShopRegistration'; import AddMenu from 'page/AddMenu'; import PageNotFound from 'page/Error/PageNotFound'; import ModifyMenu from 'page/ModifyMenu'; -import { Suspense } from 'react'; +import { Suspense, useEffect } from 'react'; import Toast from 'component/common/Toast'; import { UserType } from 'model/auth'; import useUserTypeStore from 'store/userType'; @@ -25,21 +25,23 @@ interface ProtectedRouteProps { } function ProtectedRoute({ userTypeRequired }: ProtectedRouteProps) { - const { userType, isAuth } = useUserTypeStore(); + const { userType } = useUserTypeStore(); + const location = useLocation(); const navigate = useNavigate(); - if (!isAuth) { - navigate('/login', { replace: true }); - } - - if (userType !== userTypeRequired) { - if (userTypeRequired === 'OWNER') { - navigate('/owner', { replace: true }); - } - if (userTypeRequired === 'COOP') { - navigate('/coop', { replace: true }); + useEffect(() => { + if (userType !== userTypeRequired) { + if (userType === 'OWNER') { + navigate('/owner', { replace: true }); + } + if (userType === 'COOP') { + navigate('/coop', { replace: true }); + } + if (userType === 'NOT_LOGGED_IN') { + navigate('/login', { replace: true }); + } } - } + }, [location, userType, userTypeRequired, navigate]); return ; } diff --git a/src/component/common/Header/index.tsx b/src/component/common/Header/index.tsx index c392f536..88756627 100644 --- a/src/component/common/Header/index.tsx +++ b/src/component/common/Header/index.tsx @@ -42,7 +42,6 @@ function Header() { const { setPrevPath } = usePrevPathStore((state) => state); const handleLogout = () => { - console.log('logout시도'); logout(undefined, { onSettled: () => { setPrevPath('/login'); diff --git a/src/query/auth.ts b/src/query/auth.ts index 333b5934..a7ee2f0c 100644 --- a/src/query/auth.ts +++ b/src/query/auth.ts @@ -32,7 +32,7 @@ export interface ErrorResponse { } export const useLogin = () => { - const { setUserType, setIsAuth } = useUserTypeStore(); + const { setUserType } = useUserTypeStore(); const { setLoginError, setLoginErrorCode } = useErrorMessageStore(); const { @@ -49,7 +49,6 @@ export const useLogin = () => { } setUserType(data.user_type); - setIsAuth(true); }, onError: (err: unknown) => { if (isKoinError(err)) { diff --git a/src/store/userType.ts b/src/store/userType.ts index 21a273c6..00d14d37 100644 --- a/src/store/userType.ts +++ b/src/store/userType.ts @@ -3,16 +3,13 @@ import { create } from 'zustand'; interface UserTypeStore { userType: UserType; - isAuth: boolean; setUserType: (type: UserType) => void; - setIsAuth: (auth: boolean) => void; } const useUserTypeStore = create((set) => ({ userType: 'NOT_LOGGED_IN', isAuth: false, setUserType: (userType) => set({ userType }), - setIsAuth: (isAuth) => set({ isAuth }), })); export default useUserTypeStore; From 470520280850cb78ea53a6c077898ad3e64ea56c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Fri, 5 Apr 2024 17:29:59 +0900 Subject: [PATCH 16/24] =?UTF-8?q?feat:=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B3=80=EA=B2=BD=20=EB=A3=A8=ED=8A=B8=20=EC=A0=91?= =?UTF-8?q?=EA=B7=BC=20=EC=82=AC=EC=9E=A5=EB=8B=98=20=EA=B3=84=EC=A0=95?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=A0=9C=ED=95=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index ff9bd78e..e5c24753 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -79,8 +79,10 @@ function App() { } /> } /> - } /> - } /> + }> + } /> + } /> + From a7bf572432c8ca3787ed9bf181c9be5bc072df92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Sat, 6 Apr 2024 23:57:21 +0900 Subject: [PATCH 17/24] =?UTF-8?q?refactor:=20=EB=AF=B8=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=20=ED=9B=85=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - api 파일 이름 변경 --- src/App.tsx | 5 ++--- src/api/uploadFile/{Uploadfile.ts => index.ts} | 0 src/query/upload.ts | 2 +- src/utils/hooks/useImageUpload.ts | 2 +- src/utils/hooks/useImagesUpload.ts | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) rename src/api/uploadFile/{Uploadfile.ts => index.ts} (100%) diff --git a/src/App.tsx b/src/App.tsx index e5c24753..dc8e1602 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import { - Routes, Route, Navigate, Outlet, useNavigate, useLocation, + Routes, Route, Navigate, Outlet, useNavigate, } from 'react-router-dom'; import DefaultLayout from 'layout/DefaultLayout'; import Login from 'page/Auth/Login'; @@ -26,7 +26,6 @@ interface ProtectedRouteProps { function ProtectedRoute({ userTypeRequired }: ProtectedRouteProps) { const { userType } = useUserTypeStore(); - const location = useLocation(); const navigate = useNavigate(); useEffect(() => { @@ -41,7 +40,7 @@ function ProtectedRoute({ userTypeRequired }: ProtectedRouteProps) { navigate('/login', { replace: true }); } } - }, [location, userType, userTypeRequired, navigate]); + }, [userType, userTypeRequired, navigate]); return ; } diff --git a/src/api/uploadFile/Uploadfile.ts b/src/api/uploadFile/index.ts similarity index 100% rename from src/api/uploadFile/Uploadfile.ts rename to src/api/uploadFile/index.ts diff --git a/src/query/upload.ts b/src/query/upload.ts index a6b0c160..666adc20 100644 --- a/src/query/upload.ts +++ b/src/query/upload.ts @@ -1,5 +1,5 @@ import { useMutation } from '@tanstack/react-query'; -import { uploadFile, uploadFiles } from 'api/uploadFile/Uploadfile'; +import { uploadFile, uploadFiles } from 'api/uploadFile'; const useUploadFile = () => { const uploadFileMutation = useMutation({ diff --git a/src/utils/hooks/useImageUpload.ts b/src/utils/hooks/useImageUpload.ts index 14bd46bc..ee5f1f66 100644 --- a/src/utils/hooks/useImageUpload.ts +++ b/src/utils/hooks/useImageUpload.ts @@ -1,4 +1,4 @@ -import { uploadFile } from 'api/uploadFile/Uploadfile'; +import { uploadFile } from 'api/uploadFile'; import { useRef, useState } from 'react'; export default function useImageUpload() { diff --git a/src/utils/hooks/useImagesUpload.ts b/src/utils/hooks/useImagesUpload.ts index bb332c3b..cb95d187 100644 --- a/src/utils/hooks/useImagesUpload.ts +++ b/src/utils/hooks/useImagesUpload.ts @@ -1,4 +1,4 @@ -import { uploadFile } from 'api/uploadFile/Uploadfile'; +import { uploadFile } from 'api/uploadFile'; import { useRef, useState } from 'react'; import showToast from 'utils/ts/showToast'; From 776be9a1580b1ee8abd5b105f61c8b99b96d80e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Sun, 7 Apr 2024 00:38:44 +0900 Subject: [PATCH 18/24] =?UTF-8?q?feat:=20userType=20api=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/auth/index.ts | 14 +++++++++----- src/model/auth/index.ts | 15 ++++++++++++--- src/store/user.ts | 4 ++-- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/api/auth/index.ts b/src/api/auth/index.ts index 43e4d79d..2d8f3493 100644 --- a/src/api/auth/index.ts +++ b/src/api/auth/index.ts @@ -1,8 +1,7 @@ import { accessClient, client } from 'api'; -import { LoginParams, LoginResponse, UserResponse } from 'model/auth'; -// import { -// LoginParams, LoginResponse, UserResponse, -// } from 'api/auth/model'; +import { + LoginParams, LoginResponse, UserResponse, UserTypeResponse, +} from 'model/auth'; export const postLogin = async (param: LoginParams) => { const { data } = await client.post('/user/login', param); @@ -11,7 +10,12 @@ export const postLogin = async (param: LoginParams) => { export const postLogout = () => accessClient.post('/user/logout'); -export const getMe = async () => { +export const getUserType = async () => { + const { data } = await accessClient.get('/user/auth'); + return UserTypeResponse.parse(data); +}; + +export const getOwnerInfo = async () => { const { data } = await accessClient.get('/owner'); return UserResponse.parse(data); }; diff --git a/src/model/auth/index.ts b/src/model/auth/index.ts index 5998b442..7b4f1731 100644 --- a/src/model/auth/index.ts +++ b/src/model/auth/index.ts @@ -7,15 +7,13 @@ export const LoginParams = z.object({ export type LoginParams = z.infer; -export type UserType = 'NOT_LOGGED_IN' | 'COOP' | 'OWNER'; - export const LoginResponse = z.object({ refresh_token: z.string(), token: z.string(), user_type: z.union([ z.literal('NOT_LOGGED_IN'), - z.literal('COOP'), z.literal('OWNER'), + z.literal('COOP'), ]), }); @@ -63,6 +61,17 @@ export type UserResponse = z.infer; export const User = z.nullable(UserResponse); +export const UserTypeResponse = z.object({ + user_type: z.union([ + z.literal('OWNER'), + z.literal('COOP'), + ]), +}); + +export type UserTypeResponse = z.infer; + +export type UserType = 'NOT_LOGGED_IN' | 'OWNER' | 'COOP'; + export type User = z.infer; export interface LoginForm extends LoginParams { diff --git a/src/store/user.ts b/src/store/user.ts index e70066b5..09ae0e9f 100644 --- a/src/store/user.ts +++ b/src/store/user.ts @@ -1,4 +1,4 @@ -import { getMe } from 'api/auth'; +import { getOwnerInfo } from 'api/auth'; import { User } from 'model/auth'; import { create } from 'zustand'; @@ -11,7 +11,7 @@ interface UserStore { const useUserStore = create((set) => ({ user: null, setUser: async () => { - const user = await getMe(); + const user = await getOwnerInfo(); set(() => ({ user })); }, removeUser: () => { From 8d5b3d5c077ef5c2ec8b991545c0e9213324fb2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Sun, 7 Apr 2024 13:01:01 +0900 Subject: [PATCH 19/24] =?UTF-8?q?feat:=20useUserType=20=ED=9B=85=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 4 ++-- src/page/Auth/Login/index.tsx | 5 ++--- src/query/auth.ts | 20 +++++++++++++++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index dc8e1602..63c7337d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -16,7 +16,7 @@ import ModifyMenu from 'page/ModifyMenu'; import { Suspense, useEffect } from 'react'; import Toast from 'component/common/Toast'; import { UserType } from 'model/auth'; -import useUserTypeStore from 'store/userType'; +import { useUserType } from 'query/auth'; import CoopLayout from 'layout/CoopLayout'; import CoopPage from 'page/CoopPage'; @@ -25,7 +25,7 @@ interface ProtectedRouteProps { } function ProtectedRoute({ userTypeRequired }: ProtectedRouteProps) { - const { userType } = useUserTypeStore(); + const { userType } = useUserType(); const navigate = useNavigate(); useEffect(() => { diff --git a/src/page/Auth/Login/index.tsx b/src/page/Auth/Login/index.tsx index 617d1f63..8093c754 100644 --- a/src/page/Auth/Login/index.tsx +++ b/src/page/Auth/Login/index.tsx @@ -6,7 +6,7 @@ import { ReactComponent as Logo } from 'assets/svg/auth/koin-logo.svg'; import { ReactComponent as ShowIcon } from 'assets/svg/auth/show.svg'; import { ReactComponent as BlindIcon } from 'assets/svg/auth/blind.svg'; import { ReactComponent as LockIcon } from 'assets/svg/auth/lock.svg'; -import { useLogin } from 'query/auth'; +import { useLogin, useUserType } from 'query/auth'; import { FieldErrors, SubmitHandler, useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { LoginParams } from 'model/auth'; @@ -16,7 +16,6 @@ import { useErrorMessageStore } from 'store/errorMessageStore'; import usePrevPathStore from 'store/path'; import useStepStore from 'store/useStepStore'; import { getMyShopList } from 'api/shop'; -import useUserTypeStore from 'store/userType'; import styles from './Login.module.scss'; import OPTION from './static/option'; import ApprovalModal from './ApprovalModal'; @@ -34,7 +33,7 @@ export default function Login() { const { setPrevPath } = usePrevPathStore((state) => state); const setStep = useStepStore((state) => state.setStep); const isError = isServerError || isFormError; - const { userType } = useUserTypeStore(); + const { userType } = useUserType(); const { register, diff --git a/src/query/auth.ts b/src/query/auth.ts index a7ee2f0c..fdfcf8c4 100644 --- a/src/query/auth.ts +++ b/src/query/auth.ts @@ -1,6 +1,6 @@ import { useMutation } from '@tanstack/react-query'; import { - postLogin, postLogout, findPasswordVerify, findPassword, newPassword, + postLogin, postLogout, findPasswordVerify, findPassword, newPassword, getUserType, } from 'api/auth'; import axios, { AxiosError } from 'axios'; import { LoginForm } from 'model/auth'; @@ -31,6 +31,24 @@ export interface ErrorResponse { message: string; } +export const useUserType = () => { + const { userType, setUserType } = useUserTypeStore(); + + const { mutate, error, isError } = useMutation({ + mutationFn: async () => { + const response = await getUserType(); + return response.user_type; + }, + onSuccess: (result) => { + setUserType(result || 'NOT_LOGGED_IN'); + }, + }); + + return { + checkUserType: mutate, userType, error, isError, + }; +}; + export const useLogin = () => { const { setUserType } = useUserTypeStore(); const { setLoginError, setLoginErrorCode } = useErrorMessageStore(); From ad96423b890d6ff894e4b541e79f710ae310274d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Sun, 7 Apr 2024 13:19:32 +0900 Subject: [PATCH 20/24] =?UTF-8?q?refactor:=20userTypeStore=EC=97=90=20?= =?UTF-8?q?=ED=9B=85=EC=9D=84=20=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 4 ++-- src/page/Auth/Login/index.tsx | 5 +++-- src/query/auth.ts | 20 +------------------- src/store/userType.ts | 7 +++++-- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 63c7337d..ae3171ef 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -16,16 +16,16 @@ import ModifyMenu from 'page/ModifyMenu'; import { Suspense, useEffect } from 'react'; import Toast from 'component/common/Toast'; import { UserType } from 'model/auth'; -import { useUserType } from 'query/auth'; import CoopLayout from 'layout/CoopLayout'; import CoopPage from 'page/CoopPage'; +import useUserTypeStore from 'store/userType'; interface ProtectedRouteProps { userTypeRequired: UserType; } function ProtectedRoute({ userTypeRequired }: ProtectedRouteProps) { - const { userType } = useUserType(); + const { userType } = useUserTypeStore(); const navigate = useNavigate(); useEffect(() => { diff --git a/src/page/Auth/Login/index.tsx b/src/page/Auth/Login/index.tsx index 8093c754..617d1f63 100644 --- a/src/page/Auth/Login/index.tsx +++ b/src/page/Auth/Login/index.tsx @@ -6,7 +6,7 @@ import { ReactComponent as Logo } from 'assets/svg/auth/koin-logo.svg'; import { ReactComponent as ShowIcon } from 'assets/svg/auth/show.svg'; import { ReactComponent as BlindIcon } from 'assets/svg/auth/blind.svg'; import { ReactComponent as LockIcon } from 'assets/svg/auth/lock.svg'; -import { useLogin, useUserType } from 'query/auth'; +import { useLogin } from 'query/auth'; import { FieldErrors, SubmitHandler, useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { LoginParams } from 'model/auth'; @@ -16,6 +16,7 @@ import { useErrorMessageStore } from 'store/errorMessageStore'; import usePrevPathStore from 'store/path'; import useStepStore from 'store/useStepStore'; import { getMyShopList } from 'api/shop'; +import useUserTypeStore from 'store/userType'; import styles from './Login.module.scss'; import OPTION from './static/option'; import ApprovalModal from './ApprovalModal'; @@ -33,7 +34,7 @@ export default function Login() { const { setPrevPath } = usePrevPathStore((state) => state); const setStep = useStepStore((state) => state.setStep); const isError = isServerError || isFormError; - const { userType } = useUserType(); + const { userType } = useUserTypeStore(); const { register, diff --git a/src/query/auth.ts b/src/query/auth.ts index fdfcf8c4..a7ee2f0c 100644 --- a/src/query/auth.ts +++ b/src/query/auth.ts @@ -1,6 +1,6 @@ import { useMutation } from '@tanstack/react-query'; import { - postLogin, postLogout, findPasswordVerify, findPassword, newPassword, getUserType, + postLogin, postLogout, findPasswordVerify, findPassword, newPassword, } from 'api/auth'; import axios, { AxiosError } from 'axios'; import { LoginForm } from 'model/auth'; @@ -31,24 +31,6 @@ export interface ErrorResponse { message: string; } -export const useUserType = () => { - const { userType, setUserType } = useUserTypeStore(); - - const { mutate, error, isError } = useMutation({ - mutationFn: async () => { - const response = await getUserType(); - return response.user_type; - }, - onSuccess: (result) => { - setUserType(result || 'NOT_LOGGED_IN'); - }, - }); - - return { - checkUserType: mutate, userType, error, isError, - }; -}; - export const useLogin = () => { const { setUserType } = useUserTypeStore(); const { setLoginError, setLoginErrorCode } = useErrorMessageStore(); diff --git a/src/store/userType.ts b/src/store/userType.ts index 00d14d37..64c9936d 100644 --- a/src/store/userType.ts +++ b/src/store/userType.ts @@ -1,3 +1,4 @@ +import { getUserType } from 'api/auth'; import { UserType } from 'model/auth'; import { create } from 'zustand'; @@ -8,8 +9,10 @@ interface UserTypeStore { const useUserTypeStore = create((set) => ({ userType: 'NOT_LOGGED_IN', - isAuth: false, - setUserType: (userType) => set({ userType }), + setUserType: async () => { + const response = await getUserType(); + set({ userType: response ? response.user_type : 'NOT_LOGGED_IN' }); + }, })); export default useUserTypeStore; From ba113c0a925a9511b64d3840bed3adaaa8f68c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Sun, 7 Apr 2024 14:25:06 +0900 Subject: [PATCH 21/24] =?UTF-8?q?refactor:=20=EB=A0=88=EC=9D=B4=EC=95=84?= =?UTF-8?q?=EC=9B=83=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 3 ++- src/layout/AuthLayout/index.tsx | 20 ++------------------ src/layout/DefaultLayout/index.tsx | 1 - src/query/auth.ts | 4 ++-- src/store/userType.ts | 2 +- 5 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index ae3171ef..56147d73 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -25,9 +25,10 @@ interface ProtectedRouteProps { } function ProtectedRoute({ userTypeRequired }: ProtectedRouteProps) { - const { userType } = useUserTypeStore(); + const { userType, setUserType } = useUserTypeStore(); const navigate = useNavigate(); + setUserType(); useEffect(() => { if (userType !== userTypeRequired) { if (userType === 'OWNER') { diff --git a/src/layout/AuthLayout/index.tsx b/src/layout/AuthLayout/index.tsx index 88001f01..ac03160f 100644 --- a/src/layout/AuthLayout/index.tsx +++ b/src/layout/AuthLayout/index.tsx @@ -1,27 +1,11 @@ -import { Outlet, useNavigate } from 'react-router-dom'; -import ErrorBoundary from 'component/common/ErrorBoundary'; +import { Outlet } from 'react-router-dom'; import Copyright from 'component/common/Copyright'; -import useUserStore from 'store/user'; -import { useEffect } from 'react'; import styles from './AuthLayout.module.scss'; export default function AuthLayout() { - const navigate = useNavigate(); - const { user, setUser } = useUserStore(); - - useEffect(() => { - // @ChoiWonBeen 토큰없음 에러제거. TODO: setUser가 에러를 다루는 문제 제거 - setUser().catch(() => {}); - if (user) { - navigate('/owner', { replace: true }); - } - }, [setUser, user, navigate]); - return (
      - - - +
      ); diff --git a/src/layout/DefaultLayout/index.tsx b/src/layout/DefaultLayout/index.tsx index bf20f098..0ef335e7 100644 --- a/src/layout/DefaultLayout/index.tsx +++ b/src/layout/DefaultLayout/index.tsx @@ -19,7 +19,6 @@ export default function DefaultLayout() { .catch(handleErrorBoundary) .catch(() => { setPrevPath('/owner/shop-registration'); - navigate('/login', { replace: true }); }); } }, [handleErrorBoundary, setUser, setPrevPath, navigate, user]); diff --git a/src/query/auth.ts b/src/query/auth.ts index a7ee2f0c..3ca6bbf3 100644 --- a/src/query/auth.ts +++ b/src/query/auth.ts @@ -48,7 +48,7 @@ export const useLogin = () => { localStorage.setItem('refresh_token', data.refresh_token); } - setUserType(data.user_type); + setUserType(); }, onError: (err: unknown) => { if (isKoinError(err)) { @@ -83,7 +83,7 @@ export const useLogout = () => { sessionStorage.removeItem('access_token'); localStorage.removeItem('refresh_token'); removeUser(); - setUserType('NOT_LOGGED_IN'); + setUserType(); }, onError: (err: unknown) => { if (isKoinError(err)) { diff --git a/src/store/userType.ts b/src/store/userType.ts index 64c9936d..7c013a58 100644 --- a/src/store/userType.ts +++ b/src/store/userType.ts @@ -4,7 +4,7 @@ import { create } from 'zustand'; interface UserTypeStore { userType: UserType; - setUserType: (type: UserType) => void; + setUserType: () => void; } const useUserTypeStore = create((set) => ({ From 1de8704fac6db78f5baa12258bffccd6218991a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Mon, 8 Apr 2024 21:33:10 +0900 Subject: [PATCH 22/24] =?UTF-8?q?refactor:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9D=80=20=EC=83=81=ED=83=9C?= =?UTF-8?q?=EB=A5=BC=20null=EB=A1=9C=20=ED=91=9C=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 31 +++++++++++++--------------- src/layout/DefaultLayout/index.tsx | 1 + src/model/auth/index.ts | 4 ++-- src/page/Auth/Login/index.tsx | 33 ++---------------------------- src/store/userType.ts | 16 ++++++++++++--- 5 files changed, 32 insertions(+), 53 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 56147d73..0d710cd2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import { - Routes, Route, Navigate, Outlet, useNavigate, + Routes, Route, Navigate, Outlet, } from 'react-router-dom'; import DefaultLayout from 'layout/DefaultLayout'; import Login from 'page/Auth/Login'; @@ -13,7 +13,7 @@ import ShopRegistration from 'page/ShopRegistration'; import AddMenu from 'page/AddMenu'; import PageNotFound from 'page/Error/PageNotFound'; import ModifyMenu from 'page/ModifyMenu'; -import { Suspense, useEffect } from 'react'; +import { Suspense } from 'react'; import Toast from 'component/common/Toast'; import { UserType } from 'model/auth'; import CoopLayout from 'layout/CoopLayout'; @@ -26,22 +26,19 @@ interface ProtectedRouteProps { function ProtectedRoute({ userTypeRequired }: ProtectedRouteProps) { const { userType, setUserType } = useUserTypeStore(); - const navigate = useNavigate(); - setUserType(); - useEffect(() => { - if (userType !== userTypeRequired) { - if (userType === 'OWNER') { - navigate('/owner', { replace: true }); - } - if (userType === 'COOP') { - navigate('/coop', { replace: true }); - } - if (userType === 'NOT_LOGGED_IN') { - navigate('/login', { replace: true }); - } + + if (userType !== userTypeRequired) { + if (userType === 'OWNER') { + return ; + } + if (userType === 'COOP') { + return ; + } + if (userType === null) { + return ; } - }, [userType, userTypeRequired, navigate]); + } return ; } @@ -73,7 +70,7 @@ function App() {
      }> - }> + }> } /> } /> } /> diff --git a/src/layout/DefaultLayout/index.tsx b/src/layout/DefaultLayout/index.tsx index 0ef335e7..5f78262e 100644 --- a/src/layout/DefaultLayout/index.tsx +++ b/src/layout/DefaultLayout/index.tsx @@ -19,6 +19,7 @@ export default function DefaultLayout() { .catch(handleErrorBoundary) .catch(() => { setPrevPath('/owner/shop-registration'); + navigate('/owner/shop-registration'); }); } }, [handleErrorBoundary, setUser, setPrevPath, navigate, user]); diff --git a/src/model/auth/index.ts b/src/model/auth/index.ts index 7b4f1731..db3d8169 100644 --- a/src/model/auth/index.ts +++ b/src/model/auth/index.ts @@ -11,9 +11,9 @@ export const LoginResponse = z.object({ refresh_token: z.string(), token: z.string(), user_type: z.union([ - z.literal('NOT_LOGGED_IN'), z.literal('OWNER'), z.literal('COOP'), + z.null(), ]), }); @@ -70,7 +70,7 @@ export const UserTypeResponse = z.object({ export type UserTypeResponse = z.infer; -export type UserType = 'NOT_LOGGED_IN' | 'OWNER' | 'COOP'; +export type UserType = 'OWNER' | 'COOP' | null; export type User = z.infer; diff --git a/src/page/Auth/Login/index.tsx b/src/page/Auth/Login/index.tsx index 617d1f63..4b2aa983 100644 --- a/src/page/Auth/Login/index.tsx +++ b/src/page/Auth/Login/index.tsx @@ -10,13 +10,9 @@ import { useLogin } from 'query/auth'; import { FieldErrors, SubmitHandler, useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { LoginParams } from 'model/auth'; -import { useEffect, useState } from 'react'; +import { useState } from 'react'; import sha256 from 'utils/ts/SHA-256'; import { useErrorMessageStore } from 'store/errorMessageStore'; -import usePrevPathStore from 'store/path'; -import useStepStore from 'store/useStepStore'; -import { getMyShopList } from 'api/shop'; -import useUserTypeStore from 'store/userType'; import styles from './Login.module.scss'; import OPTION from './static/option'; import ApprovalModal from './ApprovalModal'; @@ -25,16 +21,13 @@ export default function Login() { const { value: isBlind, changeValue: changeIsBlind } = useBooleanState(); const { value: isAutoLogin, changeValue: changeIsAutoLogin } = useBooleanState(true); const { isMobile } = useMediaQuery(); - const { login, isError: isServerError, isSuccess } = useLogin(); + const { login, isError: isServerError } = useLogin(); const [isFormError, setIsFormError] = useState(false); const navigate = useNavigate(); const { loginError, loginErrorCode } = useErrorMessageStore(); const [emailError, setEmailError] = useState(''); const { value: isModalOpen, changeValue: toggle } = useBooleanState(false); - const { setPrevPath } = usePrevPathStore((state) => state); - const setStep = useStepStore((state) => state.setStep); const isError = isServerError || isFormError; - const { userType } = useUserTypeStore(); const { register, @@ -43,28 +36,6 @@ export default function Login() { resolver: zodResolver(LoginParams), }); - useEffect(() => { - const fetchShopList = async () => { - if (userType === 'OWNER') { - const myShopData = await getMyShopList(); - if (myShopData.count > 0) { - setPrevPath('/owner'); - navigate('/owner'); - } else { - setStep(0); - navigate('/owner/shop-registration'); - } - } - if (userType === 'COOP') { - navigate('/coop'); - } - }; - - if (isSuccess) { - fetchShopList(); - } - }, [isSuccess, userType, navigate, setPrevPath, setStep]); - const onSubmit: SubmitHandler = async (data) => { const hashedPassword = await sha256(data.password); login({ email: data.email, password: hashedPassword, isAutoLogin }); diff --git a/src/store/userType.ts b/src/store/userType.ts index 7c013a58..94d1ff97 100644 --- a/src/store/userType.ts +++ b/src/store/userType.ts @@ -8,10 +8,20 @@ interface UserTypeStore { } const useUserTypeStore = create((set) => ({ - userType: 'NOT_LOGGED_IN', + userType: null, setUserType: async () => { - const response = await getUserType(); - set({ userType: response ? response.user_type : 'NOT_LOGGED_IN' }); + try { + const response = await getUserType(); + const newUserType = response.user_type; + set((state) => { + if (newUserType !== state.userType) { + return { userType: newUserType }; + } + return state; + }); + } catch { + set((state) => (state.userType !== null ? { userType: null } : state)); + } }, })); From 70a29628f59d5b2bc8ac813f7643badd45db78d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Tue, 9 Apr 2024 15:13:09 +0900 Subject: [PATCH 23/24] =?UTF-8?q?refactor:=20=EB=A0=88=EC=9D=B4=EC=95=84?= =?UTF-8?q?=EC=9B=83=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 9 ++++++--- src/layout/CoopLayout/index.tsx | 10 +++++++--- .../{DefaultLayout => OwnerLayout}/index.tsx | 2 +- src/page/Coop/index.tsx | 14 +++++++++----- 4 files changed, 23 insertions(+), 12 deletions(-) rename src/layout/{DefaultLayout => OwnerLayout}/index.tsx (96%) diff --git a/src/App.tsx b/src/App.tsx index 56b779cc..01ff07ea 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,8 @@ import { Routes, Route, Navigate, Outlet, } from 'react-router-dom'; -import DefaultLayout from 'layout/DefaultLayout'; +import OwnerLayout from 'layout/OwnerLayout'; +import CoopLayout from 'layout/CoopLayout'; import Login from 'page/Auth/Login'; import Signup from 'page/Auth/Signup'; import FindPassword from 'page/Auth/FindPassword/SendAuthNumber'; @@ -48,7 +49,7 @@ function App() { } /> }> - }> + }> } /> } /> } /> @@ -61,7 +62,9 @@ function App() { }> - } /> + }> + } /> + }> diff --git a/src/layout/CoopLayout/index.tsx b/src/layout/CoopLayout/index.tsx index ae861cd0..48521acd 100644 --- a/src/layout/CoopLayout/index.tsx +++ b/src/layout/CoopLayout/index.tsx @@ -1,7 +1,11 @@ +import { Outlet } from 'react-router-dom'; +import Header from 'component/common/Header'; + export default function CoopLayout() { return ( - <> - coop layout - +
      +
      + +
      ); } diff --git a/src/layout/DefaultLayout/index.tsx b/src/layout/OwnerLayout/index.tsx similarity index 96% rename from src/layout/DefaultLayout/index.tsx rename to src/layout/OwnerLayout/index.tsx index 5f78262e..9bdd4796 100644 --- a/src/layout/DefaultLayout/index.tsx +++ b/src/layout/OwnerLayout/index.tsx @@ -6,7 +6,7 @@ import usePrevPathStore from 'store/path'; import useUserStore from 'store/user'; import useErrorBoundary from 'utils/hooks/useErrorBoundary'; -export default function DefaultLayout() { +export default function OwnerLayout() { const navigate = useNavigate(); const { user, setUser } = useUserStore((state) => state); const setPrevPath = usePrevPathStore((state) => state.setPrevPath); diff --git a/src/page/Coop/index.tsx b/src/page/Coop/index.tsx index 88a0e2e2..f02e4edf 100644 --- a/src/page/Coop/index.tsx +++ b/src/page/Coop/index.tsx @@ -1,5 +1,6 @@ import { useState } from 'react'; import { Menus } from 'model/Coop'; +import Header from 'component/common/Header'; import MenuCard from './components/MenuCard'; import MenuType from './components/MenuType'; import styles from './Coop.module.scss'; @@ -7,11 +8,14 @@ import styles from './Coop.module.scss'; export default function Coop() { const [selectedMenuType, setSelectedMenuType] = useState('아침'); return ( -
      -
      - - + <> +
      +
      +
      + + +
      -
      + ); } From dac525a09ebf9ebf97c5e6aeb11af499b3376f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=92=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC?= Date: Tue, 9 Apr 2024 15:40:35 +0900 Subject: [PATCH 24/24] =?UTF-8?q?refactor:=20=EB=A0=88=EC=9D=B4=EC=95=84?= =?UTF-8?q?=EC=9B=83=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 2 +- src/page/Coop/index.tsx | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 01ff07ea..298782c8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -62,7 +62,7 @@ function App() { }> - }> + }> } /> diff --git a/src/page/Coop/index.tsx b/src/page/Coop/index.tsx index f02e4edf..88a0e2e2 100644 --- a/src/page/Coop/index.tsx +++ b/src/page/Coop/index.tsx @@ -1,6 +1,5 @@ import { useState } from 'react'; import { Menus } from 'model/Coop'; -import Header from 'component/common/Header'; import MenuCard from './components/MenuCard'; import MenuType from './components/MenuType'; import styles from './Coop.module.scss'; @@ -8,14 +7,11 @@ import styles from './Coop.module.scss'; export default function Coop() { const [selectedMenuType, setSelectedMenuType] = useState('아침'); return ( - <> -
      -
      -
      - - -
      +
      +
      + +
      - +
      ); }