diff --git a/donutshop_ecommerce/src/app/orders/[id]/page.js b/donutshop_ecommerce/src/app/orders/[id]/page.js index a284c52..024cfa7 100644 --- a/donutshop_ecommerce/src/app/orders/[id]/page.js +++ b/donutshop_ecommerce/src/app/orders/[id]/page.js @@ -1,10 +1,14 @@ "use client" import Image from 'next/image' -import React, { useContext, useEffect } from 'react' -import { CartContext } from '../../../components/AppContext' +import React, { useContext, useEffect, useState } from 'react' +import { CartContext, productTotal } from '../../../components/AppContext' +import { useParams } from 'next/navigation' +import AddressInfo from '../../../components/layout/AddressInfo' const OrdersPage = () => { - const {clearCart} = useContext(CartContext); + const {clearCart, cartProducts} = useContext(CartContext); + const {id} = useParams(); + const [order, setOrder] = useState(); useEffect(() => { if(typeof window !== 'undefined'){ @@ -12,19 +16,81 @@ const OrdersPage = () => { clearCart(); } } + if(id){ + fetch('/api/orders?_id='+id).then(res => { + res.json().then(orderData => { + setOrder(orderData); + }) + }) + } }, []) + let subtotal = 0 + if(order?.cartProducts){ + for(const product of order?.cartProducts){ + subtotal += productTotal(product) + } + } + + return (
Thank you
Your order is confirmed
-We will be sending you an email confirmation to your email shortly
+Order Summary
+ {order.cartProducts.map(product => ( +{product.itemName}
+ {product.size && ( +${productTotal(product)}
+Subtotal:
+${subtotal.toFixed(2)}
+Delivery:
+$4.99
+Order total:
+${(subtotal + 4.99).toFixed(2)}
+Delivery Address
+