diff --git a/src/components/ui/Modal/FundingModal/index.tsx b/src/components/ui/Modal/FundingModal/index.tsx index b8224fb2..0774ba10 100644 --- a/src/components/ui/Modal/FundingModal/index.tsx +++ b/src/components/ui/Modal/FundingModal/index.tsx @@ -45,6 +45,11 @@ const FundingModal = ({ }); const handleAddFunding = async () => { + if (formatCommaToNumber(goalAmount) === 0) { + alert('목표 금액은 0원일 수 없습니다.'); + + return; + } await sendRequest(); close(); }; diff --git a/src/layouts/Product/BuyInfo/ButtonBundles/index.tsx b/src/layouts/Product/BuyInfo/ButtonBundles/index.tsx index 417c7541..8fd17bf9 100644 --- a/src/layouts/Product/BuyInfo/ButtonBundles/index.tsx +++ b/src/layouts/Product/BuyInfo/ButtonBundles/index.tsx @@ -1,3 +1,5 @@ +import { useQuery } from '@tanstack/react-query'; + import clsx from 'clsx'; import { useNavigate } from 'react-router-dom'; @@ -11,7 +13,9 @@ import { useAxios } from 'hooks/useAxios'; import { useKakaoPicker } from 'hooks/useKakaoPicker'; import { useLogin } from 'hooks/useLogin'; import { useModal } from 'hooks/useModal'; +import { getMyFundingItem } from 'services/api/v1/funding'; import { formatNumberWithPlus } from 'utils/format'; +import { isEmptyObject } from 'utils/validate'; import { RequestOrderPreview } from 'types/payment'; import { OptionDetail, ProductDescriptionResponse } from 'types/product'; @@ -48,6 +52,11 @@ const ButtonBundles = ({ useSelectedFriendsStore(); const { openKakaoPicker } = useKakaoPicker(); + const { data } = useQuery({ + queryKey: ['myFundingItem'], + queryFn: () => getMyFundingItem(), + }); + const { isOpen: isFundingOpen, open: openFundingModal, @@ -104,6 +113,11 @@ const ButtonBundles = ({ // 펀딩 등록 버튼 핸들러 const handleClickFunding = () => { checkLoginBeforeAction(() => { + if (!isEmptyObject(data!)) { + alert('이미 등록된 펀딩 아이템이 있습니다.'); + return; + } + checkOptionBeforeAction(openFundingModal); }); }; diff --git a/src/pages/MyPage/Funding/index.tsx b/src/pages/MyPage/Funding/index.tsx index a63ee125..ac4c24b7 100644 --- a/src/pages/MyPage/Funding/index.tsx +++ b/src/pages/MyPage/Funding/index.tsx @@ -8,13 +8,10 @@ import FundingProgress from 'layouts/MyPage/Funding/FundingProgress'; import { useUserStore } from 'store/useUserStore'; import { getMyFundingItem } from 'services/api/v1/funding'; +import { isEmptyObject } from 'utils/validate'; import styles from './index.module.scss'; -const isEmptyObject = (obj: object): boolean => { - return Object.keys(obj).length === 0; -}; - const Funding = () => { const { name } = useUserStore(); const { data, isFetched, isLoading } = useQuery({ diff --git a/src/utils/validate.ts b/src/utils/validate.ts index 853e2993..023d64f7 100644 --- a/src/utils/validate.ts +++ b/src/utils/validate.ts @@ -19,3 +19,7 @@ export const isValidQuantity = (quantity: string) => { export const isValidPrice = (price: string) => { return isPositiveInteger(price) || isZero(price); }; + +export const isEmptyObject = (obj: object): boolean => { + return Object.keys(obj).length === 0; +};