-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
200 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,61 @@ | ||
import clsx from 'clsx'; | ||
|
||
import { useAxios } from 'hooks/useAxios'; | ||
import { formatNumberWithComma, formatNumberWithUnit } from 'utils/format'; | ||
|
||
import { CartItem } from 'types/cart'; | ||
|
||
import styles from './index.module.scss'; | ||
|
||
const data = { | ||
cartId: 1, | ||
productId: 101, | ||
optionId: 201, | ||
optionDetailId: 301, | ||
productName: | ||
'"독일 명품 비타민" 오쏘몰 이뮨 멀티비타민&미네랄 7입 - 단독 카톤박스 배송', | ||
brandName: '오쏘몰', | ||
quantity: 2, | ||
productPrice: 38000, | ||
imageUrl: | ||
'https://img1.kakaocdn.net/thumb/[email protected]/?fname=https%3A%2F%2Fst.kakaocdn.net%2Fproduct%2Fgift%2Fproduct%2F20240605140558_d7afcc696ee4488abe48fdb21864c1f9.jpg', | ||
optionName: 'dd', | ||
optionDetailName: '', | ||
totalPrice: 76000, | ||
type CartBoxItemProps = { | ||
refetch: () => void; | ||
item: CartItem; | ||
handleSelect: (productId: number) => void; | ||
isSelected: boolean; | ||
}; | ||
const hasOption = true; | ||
const isSelect = true; | ||
const CartBoxItem = () => { | ||
|
||
const CartBoxItem = ({ | ||
refetch, | ||
item, | ||
handleSelect, | ||
isSelected, | ||
}: CartBoxItemProps) => { | ||
const { sendRequest } = useAxios({ | ||
method: 'delete', | ||
url: `cart/${item.productId}`, | ||
}); | ||
|
||
const handleDelete = async () => { | ||
await sendRequest(); | ||
refetch(); | ||
}; | ||
|
||
return ( | ||
<div className={styles.wrapper_item}> | ||
<div className={styles.wrapper_icons}> | ||
<div | ||
className={styles.wrapper_icons} | ||
onClick={() => handleSelect(item.productId)} | ||
> | ||
<input type="checkbox" className={styles.btn_input} id="checkbox" /> | ||
<span | ||
id="checkbox" | ||
className={clsx(styles.ico_input, { [styles.on]: isSelect })} | ||
className={clsx(styles.ico_input, { [styles.on]: isSelected })} | ||
/> | ||
|
||
<span className={styles.ico_delete} /> | ||
<span className={styles.ico_delete} onClick={handleDelete} /> | ||
</div> | ||
<div className={styles.wrapper_prod}> | ||
<img | ||
alt={`${data.productName}상품이미지`} | ||
src={data.imageUrl} | ||
alt={`${item.productName}상품이미지`} | ||
src={item.imageUrl} | ||
className={styles.thumb_prod} | ||
/> | ||
<div> | ||
<p className={styles.txt_brand}>{data.brandName}</p> | ||
<strong className={styles.txt_prod}>{data.productName}</strong> | ||
{hasOption && ( | ||
<p className={styles.txt_brand}>{item.brandName}</p> | ||
<strong className={styles.txt_prod}>{item.productName}</strong> | ||
{item.optionName && ( | ||
<p className={styles.txt_option}> | ||
<span className={styles.ico_option} /> | ||
{data.optionName} | ||
{item.optionDetailName} | ||
</p> | ||
)} | ||
</div> | ||
|
@@ -55,11 +64,11 @@ const CartBoxItem = () => { | |
<div className={styles.wrapper_box}> | ||
<p className={styles.txt_info}> | ||
상품금액 | ||
<span>{formatNumberWithUnit(data.productPrice)}</span> | ||
<span>{formatNumberWithUnit(item.productPrice)}</span> | ||
</p> | ||
<p className={styles.txt_info}> | ||
선택수량 | ||
<span>x {data.quantity}개</span> | ||
<span>x {item.quantity}개</span> | ||
</p> | ||
<p className={styles.txt_info}> | ||
수신인원 | ||
|
@@ -71,7 +80,7 @@ const CartBoxItem = () => { | |
결제금액 | ||
<span className={styles.txt_unit}> | ||
<span className={styles.num_info}> | ||
{formatNumberWithComma(data.productPrice)} | ||
{formatNumberWithComma(item.productPrice * item.quantity)} | ||
</span> | ||
원 | ||
</span> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.