상품금액
- {formatNumberWithUnit(data.productPrice)}
+ {formatNumberWithUnit(item.productPrice)}
선택수량
- x {data.quantity}개
+ x {item.quantity}개
수신인원
@@ -71,7 +80,7 @@ const CartBoxItem = () => {
결제금액
- {formatNumberWithComma(data.productPrice)}
+ {formatNumberWithComma(item.productPrice * item.quantity)}
원
diff --git a/src/layouts/Cart/CartPay/BillItem/index.tsx b/src/layouts/Cart/CartPay/BillItem/index.tsx
index 4f5cae46..fda27fdb 100644
--- a/src/layouts/Cart/CartPay/BillItem/index.tsx
+++ b/src/layouts/Cart/CartPay/BillItem/index.tsx
@@ -1,27 +1,24 @@
import { formatNumberWithUnit } from 'utils/format';
+import { CartItem } from 'types/cart';
+
import styles from './index.module.scss';
-const prod = {
- title:
- '"선물제격" 보르딘 콜드브루 더치커피 알록달록 앰플 12종 커피 선물세트 (25ml*12개)',
- quantity: 1,
- price: 19900,
- receiver: 1,
-};
+type BillItemProps = { item: CartItem };
-const BillItem = () => {
+const BillItem = ({ item }: BillItemProps) => {
+ const { productName, quantity, totalPrice } = item;
return (
-
{prod.title}
+
{productName}
상품금액
- {formatNumberWithUnit(prod.price)}
+ {formatNumberWithUnit(totalPrice)}
수량
- x {prod.quantity}개
+ x {quantity}개
수신인원
@@ -30,7 +27,7 @@ const BillItem = () => {
상품 결제 금액
- {formatNumberWithUnit(prod.price * prod.quantity)}
+ {formatNumberWithUnit(totalPrice)}
);
diff --git a/src/layouts/Cart/CartPay/index.tsx b/src/layouts/Cart/CartPay/index.tsx
index 5e79365d..f98e439a 100644
--- a/src/layouts/Cart/CartPay/index.tsx
+++ b/src/layouts/Cart/CartPay/index.tsx
@@ -8,8 +8,9 @@ import { useSelectedFriendsStore } from 'store/useSelectedFriendsStore';
import { useKakaoPicker } from 'hooks/useKakaoPicker';
import { useLogin } from 'hooks/useLogin';
+import { formatNumberWithUnit } from 'utils/format';
-import { RequestOrderPreview } from 'types/payment';
+import { CartItem } from 'types/cart';
import DefaultProfileImage from 'assets/profile_noimg.png';
@@ -17,37 +18,37 @@ import BillItem from './BillItem';
import styles from './index.module.scss';
-// TODO : 가짜 상품데이터
-const prod = [1, 2, 3];
-const CartPay = () => {
+type CartPayProps = {
+ selectedItems: CartItem[];
+ totalPayment: number;
+};
+
+const CartPay = ({ selectedItems, totalPayment }: CartPayProps) => {
const [isToggled, handleToggle] = useReducer((prev) => !prev, false);
- const navigate = useNavigate();
- const { isLoggedIn, login, confirmLogin } = useLogin();
+ const { checkLoginBeforeAction } = useLogin();
+ const { openKakaoPicker } = useKakaoPicker();
const { isSelected, isSelfSelected, selectedFriends, getImgUrl } =
useSelectedFriendsStore();
- const { openKakaoPicker } = useKakaoPicker();
+ const navigate = useNavigate();
- // 로그인 여부 확인
- const checkLoginBeforeAction = (action: () => void) => {
- if (isLoggedIn) action();
- else {
- const result = confirmLogin();
- if (result) login();
- }
- };
+ const getOrderInfo = () => {
+ const orderInfos = selectedItems.map((item) => {
+ return {
+ productId: item.productId,
+ quantity: item.quantity,
+ options: [{ id: item.optionId, detailId: item.optionDetailId }],
+ };
+ });
- const orderInfos: RequestOrderPreview = [
- {
- productId: 1361966,
- quantity: 1,
- options: [],
- },
- ];
+ return orderInfos;
+ };
// 나에게 선물하기 버튼 핸들러
const handleClickGiftForMe = () => {
checkLoginBeforeAction(() => {
- navigate('/bill/gift', { state: { orderInfos, giftFor: 'me' } });
+ navigate('/bill/gift', {
+ state: { orderInfos: getOrderInfo(), giftFor: 'me' },
+ });
});
};
@@ -60,9 +61,13 @@ const CartPay = () => {
}
if (isSelfSelected) {
- navigate('/bill/gift', { state: { orderInfos, giftFor: 'me' } });
+ navigate('/bill/gift', {
+ state: { orderInfos: getOrderInfo(), giftFor: 'me' },
+ });
} else if (selectedFriends.length === 1) {
- navigate('/bill/gift', { state: { orderInfos, giftFor: 'friends' } });
+ navigate('/bill/gift', {
+ state: { orderInfos: getOrderInfo(), giftFor: 'friends' },
+ });
} else {
alert('지금은 한 번에 한 명에게만 선물할 수 있어요.');
}
@@ -84,9 +89,9 @@ const CartPay = () => {
>
{isToggled && (
- {prod.map((it) => (
- -
-
+ {selectedItems.map((item) => (
+
-
+
))}
@@ -95,7 +100,7 @@ const CartPay = () => {