-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCartItem.jsx
More file actions
75 lines (71 loc) · 2.2 KB
/
CartItem.jsx
File metadata and controls
75 lines (71 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { formatPrice, generateAmountOptions } from '../utils';
import { removeItem, editItem } from '../features/cart/cartSlice';
import { useDispatch } from 'react-redux';
const CartItem = ({ cartItem }) => {
const dispatch = useDispatch();
const removeItemFromTheCart = () => {
dispatch(removeItem({ cartID }));
};
const handleAmount = (e) => {
dispatch(editItem({ cartID, amount: parseInt(e.target.value) }));
};
const { cartID, title, price, image, amount, company, productColor } =
cartItem;
return (
<article
key={cartID}
className='mb-12 flex flex-col gap-y-4 sm:flex-row flex-wrap border-b border-base-300 pb-6 last:border-b-0'
>
{/* IMAGE */}
<img
src={image}
alt={title}
className='h-24 w-24 rounded-lg sm:h-32 sm:w-32 object-cover'
/>
{/* INFO */}
<div className='sm:ml-16 sm:w-48'>
{/* TITLE */}
<h3 className='capitalize font-medium'>{title}</h3>
{/* COMPANY */}
<h4 className='mt-2 capitalize text-sm text-neutral-content'>
{company}
</h4>
{/* COLOR */}
<p className='mt-4 text-sm capitalize flex items-center gap-x-2'>
color :
<span
className='badge badge-sm'
style={{ backgroundColor: productColor }}
></span>
</p>
</div>
<div className='sm:ml-12'>
{/* AMOUNT */}
<div className='form-control max-w-xs'>
<label htmlFor='amount' className='label p-0'>
<span className='label-text'>Amount</span>
</label>
<select
name='amount'
id='amount'
className='mt-2 select select-base select-bordered select-xs'
value={amount}
onChange={handleAmount}
>
{generateAmountOptions(amount + 5)}
</select>
</div>
{/* REMOVE */}
<button
className='mt-2 link link-primary link-hover text-sm'
onClick={removeItemFromTheCart}
>
remove
</button>
</div>
{/* PRICE */}
<p className='font-medium sm:ml-auto'>{formatPrice(price)}</p>
</article>
);
};
export default CartItem;