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

Bug/333 #368

Merged
merged 22 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d21ac20
Merge branch 'dev' into feat/261
devkyoung2 Jun 14, 2024
da98c5d
[fix]: 펀딩목표금액을 0원으로 등록하는 것을 막음(#333)
devkyoung2 Jun 14, 2024
234ec14
[refactor]: 빈 객체 체크 유틸함수로 분리(#333)
devkyoung2 Jun 14, 2024
4c7dd49
[refactor]: 진행중인 펀딩 아이템이 있을 경우 펀딩을 막음(#333)
devkyoung2 Jun 14, 2024
a8805c1
[refactor]: 나의 위시리스트 조회 응답 타입 수정 (#306)
uraflower May 28, 2024
0f1a5a9
[feat]: 친구의 위시리스트 조회 API 연동 (#306)
uraflower May 28, 2024
23dbe52
[feat]: 나의 위시리스트 페이징 조회 적용 (#306)
uraflower May 28, 2024
87fcb52
[feat]: 장바구니 버튼 핸들러 구현 (#355)
uraflower Jun 10, 2024
f7a132d
[feat]: 상품 상세 조회 페이지 장바구니 등록 버튼 핸들러 구현 (#355)
uraflower Jun 10, 2024
f92cd4d
[feat]: 장바구니 담기 전 로그인/옵션선택 여부 확인 (#355)
uraflower Jun 10, 2024
3309291
[fix]: 잘못된 변수 참조 변경 (#355)
uraflower Jun 13, 2024
ad8ee50
[refactor]: checkLoginBeforeAction 함수 추출 (#361)
uraflower Jun 10, 2024
8d30b22
[feat]: 상품 상세조회 api 응답 타입 수정(#334)
devkyoung2 Jun 7, 2024
2b01183
[feat]: 위시 클릭시 위시 색상 변경(#334)
devkyoung2 Jun 7, 2024
0f615c4
[refactor]: 의미없는 코드 삭제(#334)
devkyoung2 Jun 10, 2024
20523a0
[refactor]: 변수명을 직관적으로 변경(#334)
devkyoung2 Jun 10, 2024
79b28a4
[fix]: 펀딩목표금액을 0원으로 등록하는 것을 막음(#333)
devkyoung2 Jun 14, 2024
054788a
[refactor]: 빈 객체 체크 유틸함수로 분리(#333)
devkyoung2 Jun 14, 2024
31ad7ad
[refactor]: 진행중인 펀딩 아이템이 있을 경우 펀딩을 막음(#333)
devkyoung2 Jun 14, 2024
02167ba
Merge branch 'bug/333' of https://github.com/KakaoFunding/front-end i…
devkyoung2 Jun 14, 2024
6991f20
Merge branch 'dev' into bug/333
devkyoung2 Jun 17, 2024
ae9b7de
Merge branch 'dev' into bug/333
devkyoung2 Jun 18, 2024
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
5 changes: 5 additions & 0 deletions src/components/ui/Modal/FundingModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
});

const handleAddFunding = async () => {
if (formatCommaToNumber(goalAmount) === 0) {
alert('목표 금액은 0원일 수 없습니다.');

Check warning on line 49 in src/components/ui/Modal/FundingModal/index.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected alert

return;
}
await sendRequest();
close();
};
Expand Down
37 changes: 19 additions & 18 deletions src/layouts/MyPage/Funding/FundingItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,31 @@ import FundingCancelModal from 'components/ui/Modal/FundingCancelModal';
import { useModal } from 'hooks/useModal';
import { formatNumberWithUnit } from 'utils/format';

import { MyInProgressFunding } from 'types/funding';

import styles from './index.module.scss';

// TODO : 펀딩 API 확인후 분리 예정
type FundingItemProps = {
fundingId: number;
imgUrl: string;
price: number;
productName: string;
productId: number;
brandName: string;
brandId: number;
brandThumbnail: string;
};
type FundingItemProps = Pick<
MyInProgressFunding,
| 'fundingId'
| 'productPhoto'
| 'goalAmount'
| 'productName'
| 'productId'
| 'brandName'
| 'brandPhoto'
| 'brandId'
>;

const FundingItem = ({
fundingId,
imgUrl,
price,
productPhoto,
goalAmount,
productName,
productId,
brandName,
brandPhoto,
brandId,
brandThumbnail,
}: FundingItemProps) => {
const { open, isOpen, close, scrollPos } = useModal();

Expand All @@ -41,10 +43,9 @@ const FundingItem = ({
scrollPos={scrollPos}
/>
<Link to={`/product/${productId}`}>
{/* TODO : Thumbnail 리팩토링시 교체 */}
<img
className={styles.img_product}
src={imgUrl}
src={productPhoto}
alt={`${productName}상품이미지`}
/>
</Link>
Expand All @@ -57,7 +58,7 @@ const FundingItem = ({
<div className={styles.wrapper_brand}>
<span className={styles.txt_brand}>
<img
src={brandThumbnail}
src={brandPhoto}
alt={`${brandName}로고이미지`}
className={styles.img_brand}
/>
Expand All @@ -67,7 +68,7 @@ const FundingItem = ({
</div>
</Link>
<p className={styles.txt_price}>
목표금액<span>{formatNumberWithUnit(price)}</span>
목표금액<span>{formatNumberWithUnit(goalAmount)}</span>
</p>
</div>
<div className={styles.wrapper_button}>
Expand Down
33 changes: 20 additions & 13 deletions src/layouts/MyPage/Funding/FundingProgress/index.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
import ProgressBar from 'components/ui/ProgressBar';

import { formatNumberToPercent, formatNumberWithUnit } from 'utils/format';

import { MyInProgressFunding } from 'types/funding';

import styles from './index.module.scss';

const data = {
current: 123456,
target: 990000,
};
type FundingProgressProps = Pick<
MyInProgressFunding,
'remainAmount' | 'goalAmount' | 'accumulateAmount'
>;

const FundingProgress = () => {
const FundingProgress = ({
remainAmount,
goalAmount,
accumulateAmount,
}: FundingProgressProps) => {
return (
<section className={styles.area_progress}>
<p className={styles.txt_title}>
펀딩{' '}
<span className={styles.txt_point}>
{formatNumberToPercent(data.current, data.target)}
{formatNumberToPercent(accumulateAmount, goalAmount)}
</span>{' '}
완료
</p>
<p className={styles.txt_sub_title}>
목표 달성까지{' '}
<span className={styles.txt_point}>
{formatNumberWithUnit(data.target - data.current)}
{formatNumberWithUnit(remainAmount)}
</span>{' '}
남았어요
</p>
{/* TODO : 프로그레스바 삽입 예정 */}
<div style={{ backgroundColor: `blue`, margin: '20px 0' }}>
프로그레스바
<div>
<ProgressBar denominator={goalAmount} numerator={accumulateAmount} />
</div>
<p className={styles.txt_dec}>
목표 금액
<span className={styles.txt_price}>
{formatNumberWithUnit(data.target)}
{formatNumberWithUnit(goalAmount)}
</span>
</p>
<p className={styles.txt_dec}>
모인 금액
<span className={styles.txt_price}>
{formatNumberWithUnit(data.current)}
{formatNumberWithUnit(accumulateAmount)}
</span>
</p>
<p className={styles.txt_dec}>
잔여 금액
<span className={styles.txt_price}>
{formatNumberWithUnit(data.target - data.current)}
{formatNumberWithUnit(remainAmount)}
</span>
</p>
</section>
Expand Down
6 changes: 3 additions & 3 deletions src/layouts/MyPage/FundingBox/FundingTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import EmptyItem from 'components/feature/EmptyItem';
import Spinner from 'components/ui/Spinner';

import { useInfinityScroll } from 'hooks/useInfinityScroll';
import { getMyFundingItems } from 'services/api/v1/funding';
import { getMyFundingBoxItems } from 'services/api/v1/funding';

import { MyFundingItemType } from 'types/funding';

Expand All @@ -24,8 +24,8 @@ const FundingTab = ({ status }: FundingTabProps) => {
const [page, setPage] = useState<number>(0);

const { data, isLoading, refetch } = useQuery({
queryKey: ['fundingItem', status],
queryFn: () => getMyFundingItems(status),
queryKey: ['fundingBoxItems', status],
queryFn: () => getMyFundingBoxItems(status),
});

const observingTarget = useInfinityScroll(() => {
Expand Down
14 changes: 14 additions & 0 deletions src/layouts/Product/BuyInfo/ButtonBundles/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useQuery } from '@tanstack/react-query';

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

Expand All @@ -11,7 +13,9 @@
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';
Expand Down Expand Up @@ -48,6 +52,11 @@
useSelectedFriendsStore();
const { openKakaoPicker } = useKakaoPicker();

const { data } = useQuery({
queryKey: ['myFundingItem'],
queryFn: () => getMyFundingItem(),
});

const {
isOpen: isFundingOpen,
open: openFundingModal,
Expand Down Expand Up @@ -95,7 +104,7 @@
// 옵션 선택 여부 확인
const checkOptionBeforeAction = (action: () => void) => {
if (hasOption && !selectedOption) {
alert('옵션을 선택해주세요');

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

View workflow job for this annotation

GitHub Actions / build

Unexpected alert
return;
}
action();
Expand All @@ -104,6 +113,11 @@
// 펀딩 등록 버튼 핸들러
const handleClickFunding = () => {
checkLoginBeforeAction(() => {
if (!isEmptyObject(data!)) {
alert('이미 등록된 펀딩 아이템이 있습니다.');

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

View workflow job for this annotation

GitHub Actions / build

Unexpected alert
return;
}

checkOptionBeforeAction(openFundingModal);
});
};
Expand Down Expand Up @@ -135,7 +149,7 @@
} else if (selectedFriends.length === 1) {
navigate('/bill/gift', { state: { orderInfos, giftFor: 'friends' } });
} else {
alert('지금은 한 번에 한 명에게만 선물할 수 있어요.');

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

View workflow job for this annotation

GitHub Actions / build

Unexpected alert
}
});
};
Expand Down
58 changes: 30 additions & 28 deletions src/pages/MyPage/Funding/index.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
import { useQuery } from '@tanstack/react-query';

import EmptyItem from 'components/feature/EmptyItem';
import Spinner from 'components/ui/Spinner';
import FundingItem from 'layouts/MyPage/Funding/FundingItem';
import FundingProgress from 'layouts/MyPage/Funding/FundingProgress';

import { useUserStore } from 'store/useUserStore';

import styles from './index.module.scss';
import { getMyFundingItem } from 'services/api/v1/funding';
import { isEmptyObject } from 'utils/validate';

// 목데이터
const data = {
hasFunding: true,
userName: '보경',
fundingId: 1,
imgUrl:
'https://img1.kakaocdn.net/thumb/[email protected]/?fname=https%3A%2F%2Fst.kakaocdn.net%2Fproduct%2Fgift%2Fproduct%2F20240412000831_223be6cfd2eb40e3bbaf238fca8a56e9',
fundingItemName: '참이 포함된 트레이드마크 체인 팔찌',
fundingItemProductId: 9632965,
fundingItemBrandName: '구찌',
fundingItemBrandThumbnail:
'https://img1.kakaocdn.net/thumb/[email protected]/?fname=https%3A%2F%2Fst.kakaocdn.net%2Fproduct%2Fgift%2Fgift_brand%2F20240402164826_a474afeeff5e42d9bfd4d64025303e32.png',
fundingPrice: 600000,
brandId: 11481,
};
import styles from './index.module.scss';

const Funding = () => {
const { name } = useUserStore();
const { data, isFetched, isLoading } = useQuery({
queryKey: ['myFundingItem'],
queryFn: () => getMyFundingItem(),
});

return (
<>
<div className={styles.title}>{`${name}님의 \n펀딩아이템`}</div>
{data.hasFunding ? (
<FundingItem
fundingId={data.fundingId}
imgUrl={data.imgUrl}
price={data.fundingPrice}
productName={data.fundingItemName}
productId={data.fundingItemProductId}
brandName={data.fundingItemBrandName}
brandThumbnail={data.fundingItemBrandThumbnail}
brandId={data.brandId}
/>
{isFetched && data && !isEmptyObject(data) ? (
<>
<FundingItem
fundingId={data.fundingId}
productPhoto={data.productPhoto}
goalAmount={data.goalAmount}
productName={data.productName}
productId={data.productId}
brandName={data.brandName}
brandPhoto={data.brandPhoto}
brandId={data.brandId}
/>
<FundingProgress
remainAmount={data.remainAmount}
goalAmount={data.goalAmount}
accumulateAmount={data.accumulateAmount}
/>
</>
) : (
<EmptyItem type="funding" />
)}
<div>펀딩 아이템 추천 영역</div>
{isLoading && <Spinner />}
</>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/pages/MyPage/FundingBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Spinner from 'components/ui/Spinner';
import Tabs from 'components/ui/Tabs';
import FundingTab from 'layouts/MyPage/FundingBox/FundingTab';

import { getMyFundingItems } from 'services/api/v1/funding';
import { getMyFundingBoxItems } from 'services/api/v1/funding';

import { Tab } from 'types/tab';

Expand All @@ -13,7 +13,7 @@ import styles from './index.module.scss';
const FundingBox = () => {
const { data, isLoading } = useQuery({
queryKey: ['fundingItem'],
queryFn: () => getMyFundingItems(),
queryFn: () => getMyFundingBoxItems(),
});

const tabs: Tab[] = [
Expand Down
10 changes: 8 additions & 2 deletions src/services/api/v1/funding.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PaginationResponse } from 'types/PaginationResponse';
import { MyFundingItemType } from 'types/funding';
import { MyFundingItemType, MyInProgressFunding } from 'types/funding';

import { apiV1 } from '.';

export const getMyFundingItems = async (status?: string) => {
export const getMyFundingBoxItems = async (status?: string) => {
const baseUrl = `/funding/gift`;

if (status) {
Expand All @@ -16,3 +16,9 @@ export const getMyFundingItems = async (status?: string) => {

return myFundingItems.data as PaginationResponse<MyFundingItemType>;
};

export const getMyFundingItem = async () => {
const myFundingItem = await apiV1.get('/funding/myItem');

return myFundingItem.data as MyInProgressFunding;
};
18 changes: 18 additions & 0 deletions src/types/funding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ export type MyFundingItemType = {
quantity: number;
receivedDate: string;
};

type EmptyObject = Record<string, never>;

export type MyInProgressFunding =
| {
fundingId: number;
progressRate: number;
remainAmount: number;
goalAmount: number;
accumulateAmount: number;
productId: number;
brandId: number;
brandPhoto: string;
productPhoto: string;
brandName: string;
productName: string;
}
| EmptyObject;
4 changes: 4 additions & 0 deletions src/utils/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Loading