From ddf3a2a8b4b3cf64f7da437074cb091955c3783d Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Wed, 14 Oct 2020 19:23:42 -0500 Subject: [PATCH] Add /checkout --- components/cart/CartSidebarView/CartSidebarView.tsx | 2 +- components/product/ProductView/ProductView.tsx | 3 +-- components/ui/Button/Button.tsx | 3 +-- lib/bigcommerce/api/checkout.ts | 10 +++++++++- next.config.js | 4 ++++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/components/cart/CartSidebarView/CartSidebarView.tsx b/components/cart/CartSidebarView/CartSidebarView.tsx index b63471c38..578e3b964 100644 --- a/components/cart/CartSidebarView/CartSidebarView.tsx +++ b/components/cart/CartSidebarView/CartSidebarView.tsx @@ -129,7 +129,7 @@ const CartSidebarView: FC = () => { {total} - diff --git a/components/product/ProductView/ProductView.tsx b/components/product/ProductView/ProductView.tsx index 2348258df..46614bfa6 100644 --- a/components/product/ProductView/ProductView.tsx +++ b/components/product/ProductView/ProductView.tsx @@ -1,10 +1,9 @@ -import cn from 'classnames' import { NextSeo } from 'next-seo' import { FC, useState } from 'react' import s from './ProductView.module.css' import { Colors } from '@components/ui/types' import { useUI } from '@components/ui/context' -import { Button, Container, LoadingDots } from '@components/ui' +import { Button, Container } from '@components/ui' import { Swatch, ProductSlider } from '@components/product' import useAddItem from '@lib/bigcommerce/cart/use-add-item' import type { Product } from '@lib/bigcommerce/api/operations/get-product' diff --git a/components/ui/Button/Button.tsx b/components/ui/Button/Button.tsx index c453aaf1d..92fe93eb3 100644 --- a/components/ui/Button/Button.tsx +++ b/components/ui/Button/Button.tsx @@ -9,6 +9,7 @@ import mergeRefs from 'react-merge-refs' import { useButton } from 'react-aria' import s from './Button.module.css' import { LoadingDots } from '@components/ui' + export interface ButtonProps extends ButtonHTMLAttributes { href?: string className?: string @@ -25,7 +26,6 @@ const Button: React.FC = forwardRef((props, buttonRef) => { className, variant = 'filled', children, - href, active, onClick, disabled, @@ -57,7 +57,6 @@ const Button: React.FC = forwardRef((props, buttonRef) => { return ( = async (req, res, config) => { @@ -24,6 +25,13 @@ const checkoutApi: BigcommerceApiHandler = async (req, res, config) => { method: 'POST', } ) + + if (fullCheckout) { + res.redirect(data.checkout_url) + return + } + + // TODO: make the embedded checkout work too! const html = ` @@ -48,7 +56,7 @@ const checkoutApi: BigcommerceApiHandler = async (req, res, config) => {
- ` + ` res.status(200) res.setHeader('Content-Type', 'text/html') diff --git a/next.config.js b/next.config.js index 980e7284d..b487800af 100644 --- a/next.config.js +++ b/next.config.js @@ -14,6 +14,10 @@ module.exports = { source: '/search/:category', destination: '/search', }, + { + source: '/checkout', + destination: '/api/bigcommerce/checkout', + }, ] }, }