import Link from 'next/link'; import { FC, useState } from 'react'; import CartItem from '@components/cart/CartItem'; import { Button, Text } from '@components/ui'; import { useUI } from '@components/ui/context'; import SidebarLayout from '@components/common/SidebarLayout'; import useCart from '@framework/cart/use-cart'; import usePrice from '@framework/product/use-price'; import useCheckout from '@framework/checkout/use-checkout'; import ShippingWidget from '../ShippingWidget'; import PaymentWidget from '../PaymentWidget'; import s from './CheckoutSidebarView.module.css'; import { useCheckoutContext } from '../context'; const CheckoutSidebarView: FC = () => { const [loadingSubmit, setLoadingSubmit] = useState(false); const { setSidebarView, closeSidebar } = useUI(); const { data: cartData, mutate: refreshCart } = useCart(); const { data: checkoutData, submit: onCheckout } = useCheckout(); const { clearCheckoutFields } = useCheckoutContext(); async function handleSubmit(event: React.ChangeEvent) { try { setLoadingSubmit(true); event.preventDefault(); await onCheckout(); clearCheckoutFields(); setLoadingSubmit(false); refreshCart(); closeSidebar(); } catch { // TODO - handle error UI here. setLoadingSubmit(false); } } const { price: subTotal } = usePrice( cartData && { amount: Number(cartData.subtotalPrice), currencyCode: cartData.currency.code, } ); const { price: total } = usePrice( cartData && { amount: Number(cartData.totalPrice), currencyCode: cartData.currency.code, } ); return ( setSidebarView('CART_VIEW')} >
Checkout setSidebarView('PAYMENT_VIEW')} /> setSidebarView('SHIPPING_VIEW')} />
    {cartData!.lineItems.map((item: any) => ( ))}
  • Subtotal {subTotal}
  • Taxes Calculated at checkout
  • Shipping FREE
Total {total}
{/* Once data is correctly filled */}
); }; export default CheckoutSidebarView;