mirror of
https://github.com/vercel/commerce.git
synced 2025-05-06 09:47:51 +00:00
Add checkout button
This commit is contained in:
parent
a92dcb851b
commit
2030255c5e
@ -6,10 +6,11 @@ import { ArrowLeft, Bag, Cross, Check } from '@components/icon'
|
|||||||
import { useUI } from '@components/ui/context'
|
import { useUI } from '@components/ui/context'
|
||||||
import useCart from '@lib/bigcommerce/cart/use-cart'
|
import useCart from '@lib/bigcommerce/cart/use-cart'
|
||||||
import CartItem from '../CartItem'
|
import CartItem from '../CartItem'
|
||||||
import Link from '@components/ui/Link'
|
import useOpenCheckout from '@lib/bigcommerce/cart/use-open-checkout'
|
||||||
|
|
||||||
const CartSidebarView: FC = () => {
|
const CartSidebarView: FC = () => {
|
||||||
const { data, isEmpty } = useCart()
|
const { data, isEmpty } = useCart()
|
||||||
|
const openCheckout = useOpenCheckout()
|
||||||
const { closeSidebar } = useUI()
|
const { closeSidebar } = useUI()
|
||||||
const items = data?.line_items.physical_items ?? []
|
const items = data?.line_items.physical_items ?? []
|
||||||
const handleClose = () => closeSidebar()
|
const handleClose = () => closeSidebar()
|
||||||
@ -90,7 +91,12 @@ const CartSidebarView: FC = () => {
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-shrink-0 px-4 border-t border-gray-200 py-5 sm:px-6">
|
<div className="flex-shrink-0 px-4 border-t border-gray-200 py-5 sm:px-6">
|
||||||
<Button href="/checkout" Component={Link} width="100%">
|
<Button
|
||||||
|
width="100%"
|
||||||
|
onClick={() => {
|
||||||
|
openCheckout()
|
||||||
|
}}
|
||||||
|
>
|
||||||
Proceed to Checkout
|
Proceed to Checkout
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -35,7 +35,7 @@ const Button: React.FC<ButtonProps> = forwardRef((props, buttonRef) => {
|
|||||||
const ref = useRef<typeof Component>(null)
|
const ref = useRef<typeof Component>(null)
|
||||||
const { buttonProps, isPressed } = useButton(
|
const { buttonProps, isPressed } = useButton(
|
||||||
{
|
{
|
||||||
...props,
|
...rest,
|
||||||
// @ts-ignore onClick === onPress for our purposes
|
// @ts-ignore onClick === onPress for our purposes
|
||||||
onPress: onClick,
|
onPress: onClick,
|
||||||
isDisabled: disabled,
|
isDisabled: disabled,
|
||||||
@ -59,7 +59,6 @@ const Button: React.FC<ButtonProps> = forwardRef((props, buttonRef) => {
|
|||||||
aria-pressed={active}
|
aria-pressed={active}
|
||||||
data-variant={variant}
|
data-variant={variant}
|
||||||
ref={mergeRefs([ref, buttonRef])}
|
ref={mergeRefs([ref, buttonRef])}
|
||||||
{...rest}
|
|
||||||
{...buttonProps}
|
{...buttonProps}
|
||||||
style={{
|
style={{
|
||||||
width,
|
width,
|
||||||
|
12
lib/bigcommerce/cart/use-open-checkout.tsx
Normal file
12
lib/bigcommerce/cart/use-open-checkout.tsx
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import useCart from './use-cart'
|
||||||
|
|
||||||
|
export default function useOpenCheckout() {
|
||||||
|
const { data, mutate } = useCart()
|
||||||
|
|
||||||
|
return async function openCheckout() {
|
||||||
|
window.open(data?.redirect_urls.checkout_url)
|
||||||
|
console.log('URL1', data?.redirect_urls.checkout_url)
|
||||||
|
// Get new redirect urls
|
||||||
|
await mutate()
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user