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 ( <>
{items.length && (

Contents:

    {items.map(({count, item}) => (
  • {count}x - {item.name}
  • ))}
)} {order.address && (

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:

) } function coalesceItems(order) { const {transactions} = order let items = {} for(const trans of transactions) for(const {count, item} of trans.cart.items) { if(!items[item.uuid]) items[item.uuid] = { count, item } else items[item.uuid].count += count } return Object.values(items) } function sumShippingPrice(order) { return order.transactions.map(trans => trans.shipping_price).reduce((a,b) => (b+a), 0) } const formatMoney = money => { if (money === undefined || money === null) return null; return '$' + (money / 100).toFixed(2) } function formatTime(time){ return DateTime.fromISO(time).setZone('local').toFormat('LLLL dd') } function ShippingStatus({totalShipping, delivery, isAdmin}) { if(!delivery) return ( <> {isAdmin && (

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

) case 'hand_delivered': return ( <>

Delivered {isAdmin && ' in person '} on {formatTime(delivery.date_delivered)}

{isAdmin && ( <>

Note:

                {delivery.description}
              
)} ) default: return

Error displaying shipment information

} }