Skip to content

Commit

Permalink
Merge pull request #371 from KakaoFunding/feat/357
Browse files Browse the repository at this point in the history
[feat]: 장바구니 상품 삭제 api 연동(#357)
  • Loading branch information
devkyoung2 authored Jun 18, 2024
2 parents 32b8bf0 + c71f06c commit b6ff9c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/layouts/Cart/CartBoxItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
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';

type CartBoxItemProps = {
refetch: () => void;
item: CartItem;
handleSelect: (productId: number) => void;
isSelected: boolean;
};

const CartBoxItem = ({ item, handleSelect, isSelected }: CartBoxItemProps) => {
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
Expand All @@ -24,8 +41,7 @@ const CartBoxItem = ({ item, handleSelect, isSelected }: CartBoxItemProps) => {
id="checkbox"
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
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Cart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Cart = () => {
data: cartItems,
isFetched,
isLoading,
refetch,
} = useQuery({
queryKey: ['cart'],
queryFn: () => getCartItems(),
Expand Down Expand Up @@ -80,6 +81,7 @@ const Cart = () => {
{cartItems!.map((item) => (
<li key={item.cartId}>
<CartBoxItem
refetch={refetch}
item={item}
handleSelect={handleSelect}
isSelected={selectedItems.some(
Expand Down

0 comments on commit b6ff9c3

Please sign in to comment.