Skip to content

Commit

Permalink
Replace button custom checkout enabled on /cart (vercel#535)
Browse files Browse the repository at this point in the history
Co-authored-by: Gonzalo Pozzo <[email protected]>
  • Loading branch information
Florian-crg and goncy authored Nov 23, 2021
1 parent 94c2d2d commit d4d22a3
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions pages/cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Layout } from '@components/common'
import { Button, Text } from '@components/ui'
import { Bag, Cross, Check, MapPin, CreditCard } from '@components/icons'
import { CartItem } from '@components/cart'
import { useUI } from '@components/ui/context'

export async function getStaticProps({
preview,
Expand All @@ -26,6 +27,7 @@ export default function Cart() {
const error = null
const success = null
const { data, isLoading, isEmpty } = useCart()
const { openSidebar, setSidebarView } = useUI()

const { price: subTotal } = usePrice(
data && {
Expand All @@ -40,6 +42,11 @@ export default function Cart() {
}
)

const goToCheckout = () => {
openSidebar()
setSidebarView('CHECKOUT_VIEW')
}

return (
<div className="grid lg:grid-cols-12 w-full max-w-7xl mx-auto">
<div className="lg:col-span-8">
Expand Down Expand Up @@ -162,9 +169,17 @@ export default function Cart() {
Continue Shopping
</Button>
) : (
<Button href="/checkout" Component="a" width="100%">
Proceed to Checkout
</Button>
<>
{process.env.COMMERCE_CUSTOMCHECKOUT_ENABLED ? (
<Button Component="a" width="100%" onClick={goToCheckout}>
Proceed to Checkout ({total})
</Button>
) : (
<Button href="/checkout" Component="a" width="100%">
Proceed to Checkout
</Button>
)}
</>
)}
</div>
</div>
Expand Down

0 comments on commit d4d22a3

Please sign in to comment.