Skip to content

Commit

Permalink
Add.
Browse files Browse the repository at this point in the history
  • Loading branch information
jee-eun-k committed Aug 11, 2024
1 parent d7bd13a commit 6df8616
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
3 changes: 0 additions & 3 deletions src/api/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,11 @@ export const getInstance = (isLoading = true, params?: any): AxiosInstance => {
return response.data;
},
async (error: any): Promise<any> => {
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 = {
Expand Down
1 change: 0 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
44 changes: 28 additions & 16 deletions src/pages/settings/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import {
ListSubheader,
Typography,
} from '@mui/material';
import { useEffect } from 'react';
import { useEffect, useState } from 'react';

import ChevronRightIcon from '@mui/icons-material/ChevronRight';

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';
Expand All @@ -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();
Expand All @@ -39,7 +37,29 @@ const SettingPage = () => {
const userInfo = useRecoilValue(currentUserInfo);
const [modalInfo, setModalInfo] = useRecoilState(modalState);
const setCategoryMode = useSetRecoilState<CategoryViewType>(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
Expand Down Expand Up @@ -85,7 +105,7 @@ const SettingPage = () => {
if (response.status === 'SUCCESS') {
closeModal(event, reason);
removeTokenCookie();
navigation('/login');
resetUserInfo();
} else {
closeModal(event, reason);
}
Expand All @@ -106,6 +126,7 @@ const SettingPage = () => {
if (response.status === 'SUCCESS') {
closeModal(event, reason);
removeTokenCookie();
resetUserInfo();
navigation('/login');
}
})
Expand All @@ -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);
Expand Down Expand Up @@ -160,7 +172,7 @@ const SettingPage = () => {
align="left"
sx={{ fontSize: '16px', fontWeight: '600' }}
>
{getUserNickname()}
{userNickname}
</Typography>
<Typography
align="left"
Expand Down
2 changes: 1 addition & 1 deletion src/store/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const currentUserInfo = atom<UserData>({
nickname: '',
role: '',
status: '',
authProviderType: '',
authProviderType: undefined,
templateType: 'NONE',
startDay: '',
startTime: '',
Expand Down

0 comments on commit 6df8616

Please sign in to comment.