import Link from 'next/link' import Router from 'next/router' import styles from './style.module.css' import {Icon} from '@rmwc/icon' import {Input, Button} from '~/components/form' import useUser from '~/hooks/useUser' // TODO: Load previous addresses CheckoutSummary.getInitialProps = async function({ctx: {axios}}){ const {data: order} = await axios.get(`/api/orders/current`) return {order} } export default function CheckoutSummary({order}){ const user = useUser(); const currentTransaction = order .transactions.find(transaction => ( transaction.payment_state === 'started' )) const {item_total_price, shipping_price, tax_price, coupon_effective_discount} = currentTransaction console.log(tax_price) const formatMoney = money => { if (money === undefined || money === null) return null; return '$' + (money / 100).toFixed(2) } const total_price = (item_total_price && shipping_price && tax_price) ? item_total_price + shipping_price + tax_price - (coupon_effective_discount || 0) : null return ( <>

Checkout

Address

{ order.address ? (

{order.address.name}

{order.address.street1}

{order.address.street2}

{order.address.city}, {order.address.state}, {order.address.zip}

(Edit Address)

) : ( user ?(

TODO: Load previous addresses

):( <>

Log in to use your
saved addresses

OR
) ) }

Coupon (optional)

Total

{currentTransaction.cart.items.map(({uuid, count, item}) => ( ))} {tax_price && ( )}
{item.name} {count > 1 ? `(${count})` : ''}: {formatMoney(count * item.price_cents)}
Shipping: {formatMoney(shipping_price) || '-'}
Sales tax: {formatMoney(tax_price)}
Total: {formatMoney(total_price) || '-'}
{ total_price ? ( <> ) : (
) }
) }