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

[feat]: 위시 취소 로직 추가 및 위시 등록 시 상태 변경 (#380) #381

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/layouts/Product/BuyInfo/ButtonBundles/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useQuery } from '@tanstack/react-query';

import clsx from 'clsx';
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';

import { Button } from 'components/ui/Button';
Expand All @@ -13,6 +14,7 @@
import { useKakaoPicker } from 'hooks/useKakaoPicker';
import { useLogin } from 'hooks/useLogin';
import { useModal } from 'hooks/useModal';
import { useDeleteWish } from 'hooks/useWish';
import { getMyFundingItem } from 'services/api/v1/funding';
import { formatNumberWithPlus } from 'utils/format';
import { isEmptyObject } from 'utils/validate';
Expand Down Expand Up @@ -44,13 +46,15 @@
productThumbnails,
options,
wishCount,
wish: isWished,
wish: isWishedProp,
} = productDescription;
const navigate = useNavigate();
const { checkLoginBeforeAction } = useLogin();
const { isSelected, isSelfSelected, selectedFriends, getImgUrl } =
useSelectedFriendsStore();
const { openKakaoPicker } = useKakaoPicker();
const [isWished, setIsWished] = useState<boolean>(isWishedProp);
const { deleteWishData, deleteWish } = useDeleteWish(productId);

const { data } = useQuery({
queryKey: ['myFundingItem'],
Expand Down Expand Up @@ -104,7 +108,7 @@
// 옵션 선택 여부 확인
const checkOptionBeforeAction = (action: () => void) => {
if (hasOption && !selectedOption) {
alert('옵션을 선택해주세요');

Check warning on line 111 in src/layouts/Product/BuyInfo/ButtonBundles/index.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected alert
return;
}
action();
Expand All @@ -114,7 +118,7 @@
const handleClickFunding = () => {
checkLoginBeforeAction(() => {
if (!isEmptyObject(data!)) {
alert('이미 등록된 펀딩 아이템이 있습니다.');

Check warning on line 121 in src/layouts/Product/BuyInfo/ButtonBundles/index.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected alert
return;
}

Expand All @@ -124,9 +128,16 @@

// 위시 버튼 핸들러
const handleClickWish = () => {
checkLoginBeforeAction(openWishModal);
checkLoginBeforeAction(() => {
if (isWished) deleteWish();
else openWishModal();
});
};

useEffect(() => {
if (deleteWishData) setIsWished(false);
}, [deleteWishData]);

// 나에게 선물하기 버튼 핸들러
const handleClickGiftForMe = () => {
checkLoginBeforeAction(() => {
Expand All @@ -149,7 +160,7 @@
} else if (selectedFriends.length === 1) {
navigate('/bill/gift', { state: { orderInfos, giftFor: 'friends' } });
} else {
alert('지금은 한 번에 한 명에게만 선물할 수 있어요.');

Check warning on line 163 in src/layouts/Product/BuyInfo/ButtonBundles/index.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected alert
}
});
};
Expand Down Expand Up @@ -184,6 +195,7 @@
isOpen={isWishOpen}
scrollPos={scrollWishPos}
productId={productId}
onWishAdded={() => setIsWished(true)}
/>
{/* TODO : 로그인 되었을 때만 보이게 */}
<Button
Expand Down
Loading