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}){