Skip to content

Commit

Permalink
Merge pull request #381 from KakaoFunding/feat/380
Browse files Browse the repository at this point in the history
[feat]: 위시 취소 로직 추가 및 위시 등록 시 상태 변경 (#380)
  • Loading branch information
uraflower authored Jun 25, 2024
2 parents d4bb0d6 + c4345fa commit ea6a2fe
Showing 1 changed file with 14 additions and 2 deletions.
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 { useAxios } from 'hooks/useAxios';
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 @@ const ButtonBundles = ({
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 @@ -124,9 +128,16 @@ const ButtonBundles = ({

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

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

// 나에게 선물하기 버튼 핸들러
const handleClickGiftForMe = () => {
checkLoginBeforeAction(() => {
Expand Down Expand Up @@ -184,6 +195,7 @@ const ButtonBundles = ({
isOpen={isWishOpen}
scrollPos={scrollWishPos}
productId={productId}
onWishAdded={() => setIsWished(true)}
/>
{/* TODO : 로그인 되었을 때만 보이게 */}
<Button
Expand Down

0 comments on commit ea6a2fe

Please sign in to comment.