From ca38eb7086620c7724e905d201ad01f4b04b48d9 Mon Sep 17 00:00:00 2001 From: Ashelyn Dawn Date: Fri, 18 Jun 2021 22:57:02 -0600 Subject: [PATCH] Preorder: Updates user and admin UIs to reflect pre-order status --- components/orderSummary/orderSummary.js | 13 +++++++++++ pages/account/index.js | 16 ++++++++++++++ pages/admin/orders/index.js | 29 ++++++++++++++++++++++--- pages/store/checkout/complete.js | 6 ++--- 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/components/orderSummary/orderSummary.js b/components/orderSummary/orderSummary.js index 4705611..b7ecc03 100644 --- a/components/orderSummary/orderSummary.js +++ b/components/orderSummary/orderSummary.js @@ -84,6 +84,19 @@ function formatTime(time){ } function ShippingStatus({order, totalShipping, delivery, isAdmin}) { + const preorderDates = order.transactions.filter(t => t.has_preorder).map(t => DateTime.fromISO(t.preorder_fulfill_date)) + preorderDates.sort((b, a) => a < b ? -1 : a > b ? 1 : 0) + const latestPreorder = preorderDates[0]?.toLocaleString(DateTime.DATE_FULL) + + if(!delivery && latestPreorder) + return ( + <> + {isAdmin && (

{formatMoney(totalShipping)} charged to customer

)} +

Preorder - awaiting stock.

+

Expected to be in stock {latestPreorder}

+ + ) + if(!delivery) return ( <> diff --git a/pages/account/index.js b/pages/account/index.js index 24e6576..a434da4 100644 --- a/pages/account/index.js +++ b/pages/account/index.js @@ -61,6 +61,7 @@ export default function AccountPage({orders}) { {name: 'Item Price', extractor: getItemPrice}, {name: 'Shipping', extractor: getShippingEstimate}, {name: 'Total', extractor: getAmountPaid}, + {name: 'Status', extractor: getStatus}, {name: '', extractor: order => } @@ -104,6 +105,21 @@ function getAmountPaid(order){ .reduce((a,b)=>(a+b))) } +function getStatus(order) { + if (order.delivery && order.delivery.type == "hand_delivered") + return 'Delivered in person' + + if (order.delivery) + return `Shipped ${DateTime.fromISO(order.delivery.date_shipped).toLocaleString(DateTime.DATE_SHORT)}` + + const hasPreorder = order.transactions.some(t => t.has_preorder && !t.preorder_ready_to_ship) + + if (!hasPreorder) + return 'Awaiting Shipment' + + return 'Preorder' +} + function parsePaymentTime({payments}){ for(const payment of payments) { if(typeof payment.time === 'string') diff --git a/pages/admin/orders/index.js b/pages/admin/orders/index.js index cde3d5c..e0d431e 100644 --- a/pages/admin/orders/index.js +++ b/pages/admin/orders/index.js @@ -10,7 +10,8 @@ Orders.getInitialProps = async ({ctx}) => { } export default function Orders({orders}){ - const unshippedOrders = orders.filter(order => !order.delivery) + const unshippedPreOrders = orders.filter(order => !order.delivery && order.transactions.some(t => t.has_preorder && !t.preorder_ready_to_ship)) + const unshippedAndShippableOrders = orders.filter(order => !order.delivery && !order.transactions.some(t => t.has_preorder && !t.preorder_ready_to_ship)) const shippedOrders = orders.filter(order => order.delivery).reverse() return ( @@ -18,7 +19,7 @@ export default function Orders({orders}){ -

Unsent:

+

Unsent (sendable):

Router.push(`/admin/orders/${row.id}`)}>Details } ]} - rows={unshippedOrders.map(order => ({id: order.uuid, ...order}))} + rows={unshippedAndShippableOrders.map(order => ({id: order.uuid, ...order}))} + /> + +

Unsent (pre-orders):

+
+ + } + ]} + rows={unshippedPreOrders.map(order => ({id: order.uuid, ...order}))} />

Sent:

@@ -88,6 +105,12 @@ function getAmountPaid(order){ .reduce((a,b)=>(a+b), 0)) } +function getPreorderEstimate(order) { + const preorderDates = order.transactions.filter(t => t.has_preorder).map(t => DateTime.fromISO(t.preorder_fulfill_date)) + preorderDates.sort((b, a) => a < b ? -1 : a > b ? 1 : 0) + return preorderDates[0]?.toLocaleString(DateTime.DATE_FULL) +} + function parsePaymentTime({payments}){ for(const payment of payments) { if(typeof payment.time === 'string') diff --git a/pages/store/checkout/complete.js b/pages/store/checkout/complete.js index 1b28fd6..f662d6c 100644 --- a/pages/store/checkout/complete.js +++ b/pages/store/checkout/complete.js @@ -16,9 +16,9 @@ export default function CheckoutComplete({order}){ const items = order.transactions.map(transaction => transaction.cart.items).flat() const latestTransaction = order.transactions.sort(sortTransactions)[0] - const preorderItems = items.filter(({item}) => item.number_in_stock < 0 && item.preorder_availability_date).map(({item}) => DateTime.fromISO(item.preorder_availability_date)) || [] - preorderItems.sort((b, a) => a < b ? -1 : a > b ? 1 : 0) - const latestPreorder = preorderItems[0]?.toLocaleString(DateTime.DATE_FULL) + const preorderDates = order.transactions.filter(t => t.has_preorder).map(t => DateTime.fromISO(t.preorder_fulfill_date)) + preorderDates.sort((b, a) => a < b ? -1 : a > b ? 1 : 0) + const latestPreorder = preorderDates[0]?.toLocaleString(DateTime.DATE_FULL) let shippingEstimate = 'Orders typically are shipped within 3-5 business days of purchase.'