Skip to content

Commit

Permalink
feat: add delete info modal
Browse files Browse the repository at this point in the history
  • Loading branch information
ooooorobo committed Sep 19, 2024
1 parent d7ecdd7 commit d07ab57
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/pages/profile/ProfilePage.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@
color: var(--color-neutral-60) !important;
}

.DeleteModal {
display: flex;
flex-direction: column;
gap: 24px;
text-align: left;
width: 100%;
padding: 24px
}

.DeleteModalBody {
padding-top: 10px;
width: 100%;
display: flex;
flex-direction: column;
gap: 8px;
}

.DeleteModalFooter {
display: grid;
grid-template-columns: 1fr 1.5fr;
gap: 8px;
width: 100%;
}

.Body {
flex-grow: 1;
overflow: hidden;
Expand Down
37 changes: 36 additions & 1 deletion src/pages/profile/components/ProfilePageHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link } from '@remix-run/react';
import { Link, useNavigate } from '@remix-run/react';
import { ArrowLeft, Delete, Edit, Menu, Share } from 'src/shared/ui/icons';
import { Theme } from 'src/shared/styles/constants';
import styles from 'src/pages/profile/ProfilePage.module.css';
Expand All @@ -10,6 +10,10 @@ import { MyProfile } from 'src/entities/profile/model/myProfileStore';
import { useTranslation } from 'react-i18next';
import { ProfileShareBottomSheet } from 'src/features/ProfileShare/ProfileShareBottomSheet';
import { calculateAge, convertDateObjectToDate } from 'src/shared/vo/date';
import { Modal } from 'src/shared/ui/Modal/Modal';
import { useMutation } from '@tanstack/react-query';
import { deleteInfo } from 'src/types';
import toast from 'react-hot-toast';

export const ProfilePageHeader = ({
profile,
Expand All @@ -20,11 +24,23 @@ export const ProfilePageHeader = ({
profile: MyProfile;
showTitle: boolean;
}) => {
const navigate = useNavigate();
const { t } = useTranslation();
const [isShareOpen, setShareOpen] = useState(false);
const [isDeleteModalOpen, setDeleteModalOpen] = useState(false);

const age = calculateAge(convertDateObjectToDate(profile.birthDate));

const { mutateAsync: deleteMutation } = useMutation({
mutationFn: deleteInfo,
});

const onClickDelete = async () => {
await deleteMutation(infoId);
navigate('/');
toast.success('정보가 삭제되었습니다.', { icon: null });
};

return (
<>
<Header
Expand Down Expand Up @@ -62,6 +78,7 @@ export const ProfilePageHeader = ({
color={'neutral'}
prefixSlot={<Delete color={Theme.color.neutral60} />}
className={styles.DeleteButton}
onClick={() => setDeleteModalOpen(true)}
>
삭제하기
</Button>
Expand All @@ -80,6 +97,24 @@ export const ProfilePageHeader = ({
)}
</Header>
<ProfileShareBottomSheet isOpen={isShareOpen} onClose={() => setShareOpen(false)} infoId={infoId} />
<Modal
wrapperClassName={styles.DeleteModal}
showModal={isDeleteModalOpen}
closeModal={() => setDeleteModalOpen(false)}
>
<div className={styles.DeleteModalBody}>
<h2>{profile.name}님의 정보를 삭제할까요?</h2>
<p>삭제한 이후 복구할 수 없습니다.</p>
</div>
<div className={styles.DeleteModalFooter}>
<Button variant={'outline'} widthType={'fill'} color={'neutral'} onClick={() => setDeleteModalOpen(false)}>
취소
</Button>
<Button variant={'filled'} widthType={'fill'} color={'primary'} onClick={onClickDelete}>
삭제
</Button>
</div>
</Modal>
</>
);
};
Expand Down

0 comments on commit d07ab57

Please sign in to comment.