MCPcopy Create free account
hub / github.com/GreatStackDev/gocart / OrderSummary

Function OrderSummary

components/OrderSummary.jsx:8–110  ·  view source on GitHub ↗
({ totalPrice, items })

Source from the content-addressed store, hash-verified

6import { useRouter } from 'next/navigation';
7
8const OrderSummary = ({ totalPrice, items }) => {
9
10 const currency = process.env.NEXT_PUBLIC_CURRENCY_SYMBOL || '$';
11
12 const router = useRouter();
13
14 const addressList = useSelector(state => state.address.list);
15
16 const [paymentMethod, setPaymentMethod] = useState('COD');
17 const [selectedAddress, setSelectedAddress] = useState(null);
18 const [showAddressModal, setShowAddressModal] = useState(false);
19 const [couponCodeInput, setCouponCodeInput] = useState('');
20 const [coupon, setCoupon] = useState('');
21
22 const handleCouponCode = async (event) => {
23 event.preventDefault();
24
25 }
26
27 const handlePlaceOrder = async (e) => {
28 e.preventDefault();
29
30 router.push('/orders')
31 }
32
33 return (
34 <div className='w-full max-w-lg lg:max-w-[340px] bg-slate-50/30 border border-slate-200 text-slate-500 text-sm rounded-xl p-7'>
35 <h2 className='text-xl font-medium text-slate-600'>Payment Summary</h2>
36 <p className='text-slate-400 text-xs my-4'>Payment Method</p>
37 <div className='flex gap-2 items-center'>
38 <input type="radio" id="COD" onChange={() => setPaymentMethod('COD')} checked={paymentMethod === 'COD'} className='accent-gray-500' />
39 <label htmlFor="COD" className='cursor-pointer'>COD</label>
40 </div>
41 <div className='flex gap-2 items-center mt-1'>
42 <input type="radio" id="STRIPE" name='payment' onChange={() => setPaymentMethod('STRIPE')} checked={paymentMethod === 'STRIPE'} className='accent-gray-500' />
43 <label htmlFor="STRIPE" className='cursor-pointer'>Stripe Payment</label>
44 </div>
45 <div className='my-4 py-4 border-y border-slate-200 text-slate-400'>
46 <p>Address</p>
47 {
48 selectedAddress ? (
49 <div className='flex gap-2 items-center'>
50 <p>{selectedAddress.name}, {selectedAddress.city}, {selectedAddress.state}, {selectedAddress.zip}</p>
51 <SquarePenIcon onClick={() => setSelectedAddress(null)} className='cursor-pointer' size={18} />
52 </div>
53 ) : (
54 <div>
55 {
56 addressList.length > 0 && (
57 <select className='border border-slate-400 p-2 w-full my-3 outline-none rounded' onChange={(e) => setSelectedAddress(addressList[e.target.value])} >
58 <option value="">Select Address</option>
59 {
60 addressList.map((address, index) => (
61 <option key={index} value={index}>{address.name}, {address.city}, {address.state}, {address.zip}</option>
62 ))
63 }
64 </select>
65 )

Callers

nothing calls this directly

Calls 2

handleCouponCodeFunction · 0.85
handlePlaceOrderFunction · 0.85

Tested by

no test coverage detected