Skip to content

Commit

Permalink
[๐Ÿฅ : feat] ํšŒ์› ํƒˆํ‡ด (#21)
Browse files Browse the repository at this point in the history
- ํ”„๋กœํ•„ ์ˆ˜์ • ๋ฒ„ํŠผ๊ณผ ๋™์ผํ•˜๊ฒŒ ๋กœ๊ทธ์ธ ์œ ์ €์—๊ฒŒ๋งŒ ํšŒ์› ํƒˆํ‡ด ๋ฒ„ํŠผ ๋…ธ์ถœ
- ํšŒ์› ํƒˆํ‡ด ์‹œ auth, firestore์˜ users์ปฌ๋ ‰์…˜ ๋ฌธ์„œ, storage์˜ avatar ์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ ์ผ๊ด„ ์‚ญ์ œ ์ง„ํ–‰ ํ›„ /auth๋กœ ์ด๋™
  • Loading branch information
sryung1225 committed Jan 10, 2024
1 parent e33e4bd commit c438e20
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
58 changes: 54 additions & 4 deletions src/components/profile/user-profile.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { useState } from 'react';
import { useRecoilValue } from 'recoil';
import { useNavigate } from 'react-router-dom';
import { useRecoilState } from 'recoil';
import { deleteUser } from 'firebase/auth';
import { deleteDoc, doc } from 'firebase/firestore';
import { deleteObject, ref } from 'firebase/storage';
import { auth, db, storage } from '@/firebase.ts';
import currentUserAtom from '@atom/current-user.tsx';
import IUser from '@type/IUser.ts';
import EditProfileForm from '@compo/profile/edit-profile-form.tsx';
Expand All @@ -12,11 +17,35 @@ interface IUserProfile {
}

export default function UserProfile({ user }: IUserProfile) {
const navigate = useNavigate();
const [currentUser, setCurrentUser] = useRecoilState(currentUserAtom);
const [editPopup, setEditPopup] = useState(false);
const currentUser = useRecoilValue(currentUserAtom);
const [withdrawPopup, setWithdrawPopup] = useState(false);
const toggleEditPopup = () => {
setEditPopup(!editPopup);
};
const toggleWithdrawPopup = () => {
setWithdrawPopup(!withdrawPopup);
};
const withdrawAccount = async () => {
const authCurrentUser = auth.currentUser;
if (!authCurrentUser) return;
try {
await deleteDoc(doc(db, 'users', authCurrentUser.uid));
const photoRef = ref(storage, `avatars/${authCurrentUser.uid}`);
await deleteObject(photoRef);
await deleteUser(authCurrentUser);
} catch (error) {
console.log(error);
} finally {
setCurrentUser({
userId: '',
userAvatar: '',
userName: '',
});
navigate('/auth');
}
};
return (
<S.Profile>
<S.Avatar>
Expand All @@ -33,7 +62,7 @@ export default function UserProfile({ user }: IUserProfile) {
</S.Avatar>
<S.Name>{user.userName}</S.Name>
{user.userId === currentUser.userId && (
<>
<S.Buttons>
<S.EditButton onClick={toggleEditPopup} type="button">
ํ”„๋กœํ•„ ์ˆ˜์ •
</S.EditButton>
Expand All @@ -45,7 +74,28 @@ export default function UserProfile({ user }: IUserProfile) {
</P.Popup>
</P.PopupWrapper>
)}
</>
<S.WithdrawButton onClick={toggleWithdrawPopup} type="button">
ํšŒ์› ํƒˆํ‡ด
</S.WithdrawButton>
{withdrawPopup && (
<P.PopupWrapper>
<P.MiniPopup>
<P.CloseButton onClick={toggleWithdrawPopup} type="button" />
<P.Text>
์ •๋ง <span>ํƒˆํ‡ด</span>ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?
</P.Text>
<P.ButtonWrapper>
<P.Button onClick={withdrawAccount} type="button">
์˜ˆ
</P.Button>
<P.Button onClick={toggleWithdrawPopup} type="button">
์•„๋‹ˆ์š”
</P.Button>
</P.ButtonWrapper>
</P.MiniPopup>
</P.PopupWrapper>
)}
</S.Buttons>
)}
</S.Profile>
);
Expand Down
3 changes: 3 additions & 0 deletions src/styles/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export const Text = styled.p`
font-size: 18px;
line-height: 30px;
text-align: center;
span {
color: ${primaryColor};
}
`;

export const ButtonWrapper = styled.div`
Expand Down
15 changes: 12 additions & 3 deletions src/styles/profile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { styled } from 'styled-components';
import { grayColor } from '@style/global.ts';
import { LineButton } from '@style/button.ts';
import { LineButton, SolidButton } from '@style/button.ts';

export const Profile = styled.article`
position: relative;
Expand Down Expand Up @@ -60,7 +60,16 @@ export const Name = styled.h2`
font-size: 30px;
`;

export const EditButton = styled(LineButton)`
export const Buttons = styled.div`
display: inline-block;
`;

export const EditButton = styled(SolidButton)`
width: auto;
margin: 0 5px;
`;

export const WithdrawButton = styled(LineButton)`
width: auto;
margin: 0;
margin: 0 5px;
`;

0 comments on commit c438e20

Please sign in to comment.