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

[feat]: 장바구니 상품 삭제 api 연동(#357) #371

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
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 @@ -81,6 +82,7 @@ const Cart = () => {
{cartItems!.map((item) => (
<li key={item.cartId}>
<CartBoxItem
refetch={refetch}
item={item}
handleSelect={handleSelect}
isSelected={selectedItems.some(
Expand Down