diff --git a/components/orderSummary/orderSummary.js b/components/orderSummary/orderSummary.js
new file mode 100644
index 0000000..d48544c
--- /dev/null
+++ b/components/orderSummary/orderSummary.js
@@ -0,0 +1,137 @@
+import React, {useMemo} from 'react'
+import {DateTime} from 'luxon'
+
+import styles from './style.module.css'
+
+export default function OrderSummary({order, isAdmin}) {
+ const items = useMemo(() => coalesceItems(order), [order])
+ const totalShipping = useMemo(() => sumShippingPrice(order), [order])
+
+ return (
+ <>
+ Contents:
+
+ {items.map(({count, item}) => (
+
+ Address:
+
+ {order.address.name || order.address.company}
+
+ {order.address.street1}
+ {order.address.street2 && (<>{order.address.street2}
>)}
+ {order.address.city}, {order.address.state}, {order.address.zip}
+ {order.address.country !== 'US' && order.address.country}
+ Shipping:
+
{formatMoney(totalShipping)} charged to customer
)} +Not yet shipped
+ > + ) + + switch (delivery.type) { + case 'easypost': + case 'hand_shipped': + return ( + <> + {isAdmin && ( +
+ {formatMoney(totalShipping)} charged to customer
+ {delivery.easypost && (<>{formatMoney(parseFloat(delivery.easypost.selected_rate.rate) * 100)} paid to EasyPost>)}
+
+ Shipped + {isAdmin && delivery.type === 'hand_shipped' && ' by hand '} + {' '} on {formatTime(delivery.date_shipped)} +
+ +
+ Tracking number:
+ {delivery.tracking_number}
+
Delivered {isAdmin && ' in person '} on {formatTime(delivery.date_delivered)}
+ {isAdmin && ( + <> ++ {delivery.description} ++ > + )} + > + ) + + default: + return
Error displaying shipment information
+ } +} diff --git a/components/orderSummary/style.module.css b/components/orderSummary/style.module.css new file mode 100644 index 0000000..7ebfa35 --- /dev/null +++ b/components/orderSummary/style.module.css @@ -0,0 +1,23 @@ +.summaryRow { + display: flex; + flex-direction: row; + justify-content: space-around; +} + +.summaryRowSection { + margin: 8px; + flex: 1; +} + +.summaryRowSection > h3, .summaryRowSection h4 { + margin: 4px 0; +} + +.summaryRowSection > section pre { + margin: 0; + padding: 16px; + background: white; + display: inline-block; + box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); + white-space: normal; +} diff --git a/pages/account/index.js b/pages/account/index.js index a99f360..88e1bc4 100644 --- a/pages/account/index.js +++ b/pages/account/index.js @@ -51,7 +51,7 @@ export default function AccountPage({orders}) { {name: 'Shipping', extractor: getShippingEstimate}, {name: 'Total', extractor: getAmountPaid}, {name: '', extractor: order => - + } ]} rows={orders} diff --git a/pages/account/orders/[orderNum].js b/pages/account/orders/[orderNum].js new file mode 100644 index 0000000..9e71421 --- /dev/null +++ b/pages/account/orders/[orderNum].js @@ -0,0 +1,42 @@ +import {DateTime} from 'luxon' + +import redirect from '~/utils/redirectGetInitialProps' +import OrderSummary from '~/components/orderSummary' + +OrderDetails.getInitialProps = async function({ctx, user}) { + const {axios, query: {orderNum}} = ctx; + + if(!user) + return redirect(ctx, 302, '/login') + + if(!user.email_confirmed) + return redirect(ctx, 302, '/account/email/confirm') + + const {data: orders} = await axios.get(`/api/orders`) + + const order = orders.find(({number}) => number === parseInt(orderNum, 10)) + return {order} +} + +export default function OrderDetails({order}) { + const lastTransaction = getLastTransaction(order) + + return ( + <> +{JSON.stringify(order, null, 2)}+