From 6df8616c1600c2abf15329f9fd81027d80429802 Mon Sep 17 00:00:00 2001 From: choba Date: Sun, 11 Aug 2024 17:47:06 +0900 Subject: [PATCH] Add. --- src/api/http.ts | 3 -- src/index.tsx | 1 - src/pages/settings/SettingsPage.tsx | 44 ++++++++++++++++++----------- src/store/info.ts | 2 +- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/api/http.ts b/src/api/http.ts index 65cf4a2..dea9a58 100644 --- a/src/api/http.ts +++ b/src/api/http.ts @@ -93,14 +93,11 @@ export const getInstance = (isLoading = true, params?: any): AxiosInstance => { return response.data; }, async (error: any): Promise => { - console.log(error) // invalid token error (expired token) const errorStatusCode = error.response.status; if (errorStatusCode === 401) { removeTokenCookie(); window.location.href = '/login'; - } else if (errorStatusCode === 400) { - window.location.href = '/login'; } const unknownError: CommonResponse = { diff --git a/src/index.tsx b/src/index.tsx index 0f43b09..cdf7ca9 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -4,7 +4,6 @@ import { RecoilRoot } from 'recoil'; import App from './App'; import './index.css'; -import { useLoaderData } from 'react-router-dom'; const root = ReactDOM.createRoot( document.getElementById('root') as HTMLElement, diff --git a/src/pages/settings/SettingsPage.tsx b/src/pages/settings/SettingsPage.tsx index 239bb14..4c50544 100644 --- a/src/pages/settings/SettingsPage.tsx +++ b/src/pages/settings/SettingsPage.tsx @@ -9,7 +9,7 @@ import { ListSubheader, Typography, } from '@mui/material'; -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; import ChevronRightIcon from '@mui/icons-material/ChevronRight'; @@ -17,8 +17,7 @@ import ListIcon from '@/components/settings/ListIcon'; import UserAvatar from '@/components/settings/UserAvatar'; import { bottomNavigation, stepIndex } from '@/store/common'; import { useNavigate } from 'react-router-dom'; -import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil'; -import SettingWrapper from '../auth/common/Wrapper'; +import { useRecoilState, useRecoilValue, useResetRecoilState, useSetRecoilState } from 'recoil'; import { deleteUser, signOut } from '@/api/auth'; import CommonResponse, { removeTokenCookie } from '@/api/http'; import { modalState } from '@/store/modal'; @@ -28,7 +27,6 @@ import { useModalCommon } from '@/hooks/modalCommon'; import Wrapper from '../auth/common/Wrapper'; import { currentUserInfo } from '@/store/info'; import { UserModeList } from '../category/CategoryPage'; -import CommonHeader from '@/components/layout/CommonHeader'; const SettingPage = () => { const navigation = useNavigate(); @@ -39,7 +37,29 @@ const SettingPage = () => { const userInfo = useRecoilValue(currentUserInfo); const [modalInfo, setModalInfo] = useRecoilState(modalState); const setCategoryMode = useSetRecoilState(categoryViewMode); + const resetUserInfo = useResetRecoilState(currentUserInfo); + const [userNickname, setUserNickname] = useState('TEST ACCOUNT 님'); + + useEffect(() => { + const type = + UserModeList.filter((mode) => mode.type === userInfo.templateType)[0] + ?.name || 'TEST ACCOUNT'; + setUserNickname(`#${type} ${userInfo.nickname}님`); + }, [userInfo]); + + + + /** + * get user mode & nickname + * @returns + */ + // const getUserNickname = () => { + // const type = + // UserModeList.filter((mode) => mode.type === userInfo.templateType)[0] + // ?.name || 'TEST ACCOUNT'; + // return `#${type} ${userInfo.nickname}님`; + // }; /** * get list sub header * @param text test @@ -85,7 +105,7 @@ const SettingPage = () => { if (response.status === 'SUCCESS') { closeModal(event, reason); removeTokenCookie(); - navigation('/login'); + resetUserInfo(); } else { closeModal(event, reason); } @@ -106,6 +126,7 @@ const SettingPage = () => { if (response.status === 'SUCCESS') { closeModal(event, reason); removeTokenCookie(); + resetUserInfo(); navigation('/login'); } }) @@ -114,16 +135,7 @@ const SettingPage = () => { }); }; - /** - * get user mode & nickname - * @returns - */ - const getUserNickname = () => { - const type = - UserModeList.filter((mode) => mode.type === userInfo.templateType)[0] - ?.name || 'TEST ACCOUNT'; - return `#${type} ${userInfo.nickname}님`; - }; + useEffect(() => { setNavPage(2); @@ -160,7 +172,7 @@ const SettingPage = () => { align="left" sx={{ fontSize: '16px', fontWeight: '600' }} > - {getUserNickname()} + {userNickname} ({ nickname: '', role: '', status: '', - authProviderType: '', + authProviderType: undefined, templateType: 'NONE', startDay: '', startTime: '',