import { Button, Typography } from '@mui/material'; import { Box } from '@mui/system'; import { useRouter } from 'next/router'; import { destroyCookie } from 'nookies'; import { useEffect, useState } from 'react'; import { postOrder } from '../../requests/products/postOrderRequest'; import { useStoreUpdate } from '../../store/cart-context'; import { useCheckoutDataUpdate } from '../../store/checkout-context'; import StepTitle from '../layout/steps-title/StepTitle'; let initialRender = true; const ReviewContent = () => { const { parseCheckoutValue, clearCheckout } = useCheckoutDataUpdate(); const { clearCart } = useStoreUpdate(); // eslint-disable-next-line no-unused-vars const [orderData, setOrderData] = useState(parseCheckoutValue()); const router = useRouter(); useEffect(() => { if (initialRender) { postOrder(orderData); initialRender = false; return () => { clearCheckout(); clearCart(); destroyCookie(null, 'checkout-session', { path: '/', }); destroyCookie(null, 'shipping-session', { path: '/', }); destroyCookie(null, 'review-session', { path: '/', }); }; } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return ( ORDER COMPLETE SUCCESSFULLY Thank you for placing your order with us. We wll get to work on sending your order as soon as possible Order Summary Order placed on: {orderData.time} Email: {orderData?.shippingAddress?.email} Total: ${orderData?.totalPrice} Shipping Address: {orderData?.shippingAddress?.address},{' '} {orderData?.shippingAddress?.city},{' '} {orderData?.shippingAddress?.country},{' '} {orderData?.shippingAddress?.postcode} ); }; export default ReviewContent;