|
|
|
@ -12,13 +12,13 @@ const { publicRuntimeConfig: {STRIPE_PUBLIC_KEY} } = getConfig()
|
|
|
|
|
const stripePromise = loadStripe(STRIPE_PUBLIC_KEY);
|
|
|
|
|
import PaypalIcon from '../../../images/icons/paypal.svg'
|
|
|
|
|
|
|
|
|
|
// TODO: Load previous addresses
|
|
|
|
|
CheckoutSummary.getInitialProps = async function({ctx: {axios}}){
|
|
|
|
|
const {data: addresses} = await axios.get(`/api/orders/addresses`)
|
|
|
|
|
const {data: order} = await axios.get(`/api/orders/current`)
|
|
|
|
|
return {order}
|
|
|
|
|
return {order, addresses}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function CheckoutSummary({order: _order}){
|
|
|
|
|
export default function CheckoutSummary({order: _order, addresses}){
|
|
|
|
|
const user = useUser();
|
|
|
|
|
const [order, updateOrder] = useState(_order)
|
|
|
|
|
const [couponError, setCouponError] = useState(null)
|
|
|
|
@ -52,7 +52,6 @@ export default function CheckoutSummary({order: _order}){
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const {data: updatedOrder} = await axios.post(`/api/orders/current/coupon`, {code})
|
|
|
|
|
console.log(order, updatedOrder)
|
|
|
|
|
updateOrder(updatedOrder)
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.log(err.response.data.errors)
|
|
|
|
@ -64,6 +63,14 @@ export default function CheckoutSummary({order: _order}){
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For address selection
|
|
|
|
|
const onAddressSelect = uuid => async ev => {
|
|
|
|
|
if(ev) ev.preventDefault()
|
|
|
|
|
|
|
|
|
|
const {data: updatedOrder} = await axios.post(`/api/orders/current/address/${uuid}`)
|
|
|
|
|
updateOrder(updatedOrder)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For Stripe checkout
|
|
|
|
|
const handleStripeButton = async ev => {
|
|
|
|
|
if(ev) ev.preventDefault()
|
|
|
|
@ -90,6 +97,7 @@ export default function CheckoutSummary({order: _order}){
|
|
|
|
|
order.address
|
|
|
|
|
? (
|
|
|
|
|
<div>
|
|
|
|
|
<p style={{marginTop: 0, fontWeight: 'bold'}}>Shipping To:</p>
|
|
|
|
|
<p style={{margin: 0}}>{order.address.name}</p>
|
|
|
|
|
<p style={{margin: 0}}>{order.address.street1}</p>
|
|
|
|
|
<p style={{margin: 0}}>{order.address.street2}</p>
|
|
|
|
@ -99,22 +107,42 @@ export default function CheckoutSummary({order: _order}){
|
|
|
|
|
)
|
|
|
|
|
: (
|
|
|
|
|
<>
|
|
|
|
|
{user ? (
|
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
|
|
|
<p>
|
|
|
|
|
TODO: Load previous addresses
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
):(
|
|
|
|
|
{!user && (
|
|
|
|
|
<>
|
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
|
|
|
<p>
|
|
|
|
|
<Link href="/login"><a>Log in</a></Link> to use your<br/>saved addresses
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<span className={styles.horizDivider}>
|
|
|
|
|
OR
|
|
|
|
|
</span>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{user && addresses && addresses.length && (
|
|
|
|
|
<>
|
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
|
|
|
<span>Select a previous address:</span>
|
|
|
|
|
{addresses.map(address => (
|
|
|
|
|
<div className={styles.addressCard}>
|
|
|
|
|
<span>
|
|
|
|
|
{address.name || address.company} / {address.street1}<br/>
|
|
|
|
|
{address.street2 && <> {address.street2} <br/> </>}
|
|
|
|
|
{address.city} / {address.state} / {address.zip}
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
<button style={{textAlign: 'center'}} className="buttonLink" onClick={onAddressSelect(address.uuid)}>
|
|
|
|
|
Use this address
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
<span className={styles.horizDivider}>
|
|
|
|
|
OR
|
|
|
|
|
</span>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<Button style={{width: '100px'}} onClick={()=>Router.push('/store/checkout/address')}>Input Address</Button>
|
|
|
|
|
</div>
|
|
|
|
|