import { Box, Button, Container, Grid, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Typography, } from '@mui/material' import React from 'react' import { useDispatch, useSelector } from 'react-redux' import { clearCart, selectCartSubtotal } from '../../../redux-store/CartStore/ducs' import Axios from '../../../axios' import { isAutheticated } from '../../../auth' import Swal from 'sweetalert2' const ReviewOrder = ({ orderId, billTo, shipTo, paymentMode, cartItem, handleTabChange, setOrderId, }) => { const subtotal = useSelector(selectCartSubtotal) const token = isAutheticated() const dispatch = useDispatch() // Calculate total GST for the entire cart const totalGST = cartItem.reduce((acc, item) => { // console.log(item) const gstAmount = (item.price * item.GST) / 100 return acc + gstAmount * item.count }, 0) const handleConfirmOrder = async (e) => { e.preventDefault() if (!billTo || !shipTo || !paymentMode || !cartItem || !subtotal || !totalGST) { Swal.fire('All fields are required ') } try { const res = await Axios.post( '/api/order-place', { billTo, shipTo, paymentMode, grandTotal: subtotal + totalGST, gstTotal: totalGST, subtotal: subtotal, orderItems: cartItem, }, { headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', }, }, ) if (res.status === 201) { setOrderId(res?.data?.placedOrder?.uniqueId) Swal.fire('Success!', 'Your order has been placed successfully.', 'success') handleTabChange(e, 3) } } catch (error) { Swal.fire('Something went wrong', error.message, 'error') } } return ( Bill Address {billTo} Ship Address {shipTo} Payment mode : {paymentMode} Product Category Brand SKU Quantity Price GST Subtotal {cartItem.map((row, index) => { const gstAmount = (row.price * row.GST) / 100 return ( {/* {row.product.name} */} {row.name} {row.category.categoryName} {row.brand.brandName} {row.SKU} {row.count} ₹{row.price} ₹{gstAmount} ₹{row.price * row.count} ) })} Subtotal: ₹ {subtotal} Total GST: ₹ {totalGST.toFixed(2)} Grand Total: ₹ {subtotal + totalGST}
) } export default ReviewOrder