Skip to content

Commit

Permalink
Feat/#465 logout (#467)
Browse files Browse the repository at this point in the history
* feat: ๋ฒ„ํŠผ ui ๊ตฌํ˜„

* feat: ๋กœ๊ทธ์•„์›ƒ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ ๊ตฌํ˜„

* refactor: ์ปจ๋ฒค์…˜ ์ˆ˜์ •
  • Loading branch information
jiwonh423 authored Sep 20, 2023
1 parent dfc723d commit 9758375
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions frontend/src/components/MyInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,42 @@ import Space from '../common/Space';
import { useState } from 'react';
import { ProfileProps } from '../../types/Profile';
import UpdateMyInfo from './UpdateMyInfo';
import Button from '../common/Button';
import useToast from '../../hooks/useToast';
import { postApi } from '../../apis/postApi';

const user = JSON.parse(localStorage.getItem('user') || '{}');
const accessToken = localStorage.getItem('userToken');

const MyInfo = () => {
const { showToast } = useToast();

const [isThereImg, setIsThereImg] = useState<boolean>(true);
const [isModifyMyInfo, setIsModifyMyInfo] = useState<boolean>(false);
const [myInfoNameAndEmail, setMyInfoNameAndEmail] = useState<ProfileProps>({
name: user.nickName,
email: user.email,
});

const onClickLogout = async (e: React.MouseEvent<HTMLButtonElement>) => {
try {
await postApi(
`/logout`,
{
accessToken: accessToken,
},
'x-www-form-urlencoded',
);

localStorage.removeItem('user');
localStorage.removeItem('userToken');
window.location.href = '/';
showToast('info', '๋กœ๊ทธ์•„์›ƒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.');
} catch {
showToast('error', '๋กœ๊ทธ์•„์›ƒ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค');
}
};

if (isModifyMyInfo) {
return (
<UpdateMyInfo
Expand All @@ -39,9 +64,14 @@ const MyInfo = () => {
<MyInfoImg src={user.imageUrl} />
<Space size={5} />
<Box>
<Text color="black" $fontSize="medium" $fontWeight="bold">
{user.nickName}
</Text>
<Flex $justifyContent="space-between" $alignItems="center">
<Text color="black" $fontSize="medium" $fontWeight="bold">
{user.nickName}
</Text>
<Button variant="primary" onClick={onClickLogout}>
๋กœ๊ทธ์•„์›ƒ
</Button>
</Flex>
<Text color="black" $fontSize="small" $fontWeight="normal">
{user.email}
</Text>
Expand Down

0 comments on commit 9758375

Please sign in to comment.