Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[마이페이지] 로그아웃 버튼 클릭 시 모달 나타내기 #474

Merged
merged 9 commits into from
Mar 11, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const GiftAddPageLayout = ({
setIsModalOpen={setIsModalOpen}
onClickDelete={handleClickConfirmDeleteBtn}
clickedItem={clickedItem}
okButtonText='네, 삭제할게요'
>
정말 상품을 삭제하시겠어요?
</DeleteModal>
Expand Down
16 changes: 3 additions & 13 deletions src/components/common/Button/Logout/BtnLogout.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
import { ButtonHTMLAttributes } from 'react';
import * as S from './BtnLogout.style';
import { logOutInstance } from '../../../../apis/client';
import { useNavigate } from 'react-router';

type BtnLogoutProps = ButtonHTMLAttributes<HTMLButtonElement> & {
disabled?: boolean;
children: React.ReactNode;
customStyle?: React.CSSProperties;
handleButtonClick: VoidFunction;
};

const BtnLogout = ({ disabled, children, customStyle }: BtnLogoutProps) => {
const navigate = useNavigate();
const fetchAuth = async () => logOutInstance.post(`/oauth/logout`);
const handleClick = () => {
fetchAuth().then((response: any) => {
console.log(response);
});
localStorage.clear();
navigate('/');
};
const BtnLogout = ({ disabled, children, customStyle, handleButtonClick }: BtnLogoutProps) => {
return (
<S.Wrapper disabled={disabled} style={customStyle} onClick={handleClick}>
<S.Wrapper disabled={disabled} style={customStyle} onClick={handleButtonClick}>
{children}
</S.Wrapper>
);
Expand Down
6 changes: 4 additions & 2 deletions src/components/common/Modal/DeleteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ interface DeleteModalProps {
onClickDelete: (giftId?: number) => void;
setIsModalOpen: React.Dispatch<React.SetStateAction<boolean>>;
clickedItem?: number | undefined;
okButtonText: string;
}

const DeleteModal = ({
children,
onClickDelete,
setIsModalOpen,
clickedItem,
okButtonText,
}: DeleteModalProps) => {
const onClickCancel = () => {
setIsModalOpen(false);
Expand All @@ -39,9 +41,9 @@ const DeleteModal = ({
backgroundColor: 'white',
color: 'black',
}}
onClick={() => (clickedItem ? onClickDelete(clickedItem) : onClickCancel())}
onClick={() => (clickedItem ? onClickDelete(clickedItem) : onClickDelete())}
>
네, 삭제할게요
{okButtonText}
</BtnDeleteMedium>
<BtnMedium customStyle={{ width: '12rem' }} onClick={onClickCancel}>
아니오
Expand Down
59 changes: 43 additions & 16 deletions src/pages/MyPage/MyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import useGetMyPage from '../../hooks/queries/member/useGetMypage';
import { MyPageType } from '../../types/member';
import * as S from './MyPage.style';
import { useNavigate } from 'react-router';
import { useState } from 'react';
import DeleteModal from '../../components/common/Modal/DeleteModal';
import { logOutInstance } from '../../apis/client';
interface MyPage {
memberData: MyPageType;
}
Expand All @@ -15,6 +18,8 @@ const MAX_USERNAME_LENGTH = 5;

const MyPage = () => {
const navigate = useNavigate();
const [isModalOpen, setIsModalOpen] = useState(false);
const fetchAuth = async () => logOutInstance.post(`/oauth/logout`);

const memberData = useGetMyPage();

Expand All @@ -35,6 +40,17 @@ const MyPage = () => {
);
};

const isLogout = () => {
fetchAuth().then((response: any) => {
console.log(response);
});
localStorage.clear();
navigate('/');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저희 리팩토링 때 같이 navigate 좀 더 안전하게 사용하는 법 연구해봐요!!

노션에 적어두겠습니다잇!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정말 맞아요 !!! 따로 빼야 좋은데 좋은 리마인드 감사합니다 !!

};
const handleButtonClick = () => {
setIsModalOpen(true);
};

const renderUserName = () => {
const userName = memberData?.data?.memberInfo.nickname;
const translatedUserName =
Expand All @@ -49,22 +65,33 @@ const MyPage = () => {
};

return (
<S.MyPageWrapper>
<S.TopImage />
<S.ProfileWrapper>
<S.UserButtonWrapper>
<S.UserWrapper>
<ProfileImage image={memberData?.data?.memberInfo.profileImage} />
{renderUserName()}
</S.UserWrapper>
<BtnLogout>로그아웃</BtnLogout>
</S.UserButtonWrapper>
<BtnFill onClick={goOnboarding} customStyle={{ width: '30.3rem', height: '5.2rem' }}>
새로운 선물 준비하기
</BtnFill>
</S.ProfileWrapper>
{renderGiftRoom()}
</S.MyPageWrapper>
<>
{isModalOpen && (
<DeleteModal
setIsModalOpen={setIsModalOpen}
onClickDelete={isLogout}
okButtonText='네, 할게요.'
>
정말 로그아웃하시겠어요?
Comment on lines +70 to +75
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

재사용성 👍👍👍

</DeleteModal>
)}
<S.MyPageWrapper>
<S.TopImage />
<S.ProfileWrapper>
<S.UserButtonWrapper>
<S.UserWrapper>
<ProfileImage image={memberData?.data?.memberInfo.profileImage} />
{renderUserName()}
</S.UserWrapper>
<BtnLogout handleButtonClick={handleButtonClick}>로그아웃</BtnLogout>
</S.UserButtonWrapper>
<BtnFill onClick={goOnboarding} customStyle={{ width: '30.3rem', height: '5.2rem' }}>
새로운 선물 준비하기
</BtnFill>
</S.ProfileWrapper>
{renderGiftRoom()}
</S.MyPageWrapper>
</>
);
};

Expand Down