Merge pull request #8 from ramyareye/main

main to woocommerce
This commit is contained in:
Reza Babaei
2021-09-26 17:24:06 +03:00
committed by GitHub
91 changed files with 1542 additions and 302 deletions

View File

@@ -85,25 +85,29 @@ const CartItem = ({
<div className="flex flex-row py-4 space-x-4"> <div className="flex flex-row py-4 space-x-4">
<div className="relative z-0 w-16 h-16 overflow-hidden cursor-pointer bg-violet"> <div className="relative z-0 w-16 h-16 overflow-hidden cursor-pointer bg-violet">
<Link href={`/product/${item.path}`}> <Link href={`/product/${item.path}`}>
<Image <a>
onClick={() => closeSidebarIfPresent()} <Image
className={s.productImage} onClick={() => closeSidebarIfPresent()}
width={150} className={s.productImage}
height={150} width={150}
src={item.variant.image!.url} height={150}
alt={item.variant.image!.altText} src={item.variant.image!.url}
unoptimized alt={item.variant.image!.altText}
/> unoptimized
/>
</a>
</Link> </Link>
</div> </div>
<div className="flex flex-col flex-1 text-base"> <div className="flex flex-col flex-1 text-base">
<Link href={`/product/${item.path}`}> <Link href={`/product/${item.path}`}>
<span <a>
className={s.productName} <span
onClick={() => closeSidebarIfPresent()} className={s.productName}
> onClick={() => closeSidebarIfPresent()}
{item.name} >
</span> {item.name}
</span>
</a>
</Link> </Link>
{options && options.length > 0 && ( {options && options.length > 0 && (
<div className="flex items-center pb-1"> <div className="flex items-center pb-1">

View File

@@ -26,13 +26,106 @@ const CartSidebarView: FC = () => {
// currencyCode: data.currency.code, // currencyCode: data.currency.code,
// } // }
// ) // )
// const handleClose = () => closeSidebar() const handleClose = () => closeSidebar()
// const goToCheckout = () => setSidebarView('CHECKOUT_VIEW') // const goToCheckout = () => setSidebarView('CHECKOUT_VIEW')
// const error = null // const error = null
// const success = null // const success = null
return <div /> return (
<SidebarLayout
// className={cn({
// [s.empty]: error || success || isLoading || isEmpty,
// })}
handleClose={handleClose}
>
{/* {isLoading || isEmpty ? (
<div className="flex flex-col items-center justify-center flex-1 px-4">
<span className="flex items-center justify-center w-16 h-16 p-12 border border-dashed rounded-full border-primary bg-secondary text-secondary">
<Bag className="absolute" />
</span>
<h2 className="pt-6 text-2xl font-bold tracking-wide text-center">
Your cart is empty
</h2>
<p className="px-10 pt-2 text-center text-accent-3">
Biscuit oat cake wafer icing ice cream tiramisu pudding cupcake.
</p>
</div>
) : error ? (
<div className="flex flex-col items-center justify-center flex-1 px-4">
<span className="flex items-center justify-center w-16 h-16 border border-white rounded-full">
<Cross width={24} height={24} />
</span>
<h2 className="pt-6 text-xl font-light text-center">
We couldnt process the purchase. Please check your card information
and try again.
</h2>
</div>
) : success ? (
<div className="flex flex-col items-center justify-center flex-1 px-4">
<span className="flex items-center justify-center w-16 h-16 border border-white rounded-full">
<Check />
</span>
<h2 className="pt-6 text-xl font-light text-center">
Thank you for your order.
</h2>
</div>
) : (
<>
<div className="flex-1 px-4 sm:px-6">
<Link href="/cart">
<a>
<Text variant="sectionHeading" onClick={handleClose}>
My Cart
</Text>
</a>
</Link>
<ul className={s.lineItemsList}>
{data!.lineItems.map((item: any) => (
<CartItem
key={item.id}
item={item}
currencyCode={data!.currency.code}
/>
))}
</ul>
</div>
<div className="sticky bottom-0 left-0 right-0 z-20 flex-shrink-0 w-full px-6 py-6 text-sm border-t sm:px-6 bg-accent-0">
<ul className="pb-2">
<li className="flex justify-between py-1">
<span>Subtotal</span>
<span>{subTotal}</span>
</li>
<li className="flex justify-between py-1">
<span>Taxes</span>
<span>Calculated at checkout</span>
</li>
<li className="flex justify-between py-1">
<span>Shipping</span>
<span className="font-bold tracking-wide">FREE</span>
</li>
</ul>
<div className="flex justify-between py-3 mb-2 font-bold border-t border-accent-2">
<span>Total</span>
<span>{total}</span>
</div>
<div>
{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>
</>
)} */}
</SidebarLayout>
)
} }
export default CartSidebarView export default CartSidebarView

View File

@@ -1,30 +1,39 @@
import cn from 'classnames'
import Link from 'next/link' import Link from 'next/link'
import { FC } from 'react' import { FC } from 'react'
import CartItem from '@components/cart/CartItem' import CartItem from '@components/cart/CartItem'
import { Button, Text } from '@components/ui' import { Button, Text } from '@components/ui'
import { useUI } from '@components/ui/context' import { useUI } from '@components/ui/context'
import SidebarLayout from '@components/common/SidebarLayout'
// import useCart from '@framework/cart/use-cart' // import useCart from '@framework/cart/use-cart'
// import usePrice from '@framework/product/use-price' // import usePrice from '@framework/product/use-price'
// import useCheckout from '@framework/checkout/use-checkout'
import ShippingWidget from '../ShippingWidget' import ShippingWidget from '../ShippingWidget'
import PaymentWidget from '../PaymentWidget' import PaymentWidget from '../PaymentWidget'
import SidebarLayout from '@components/common/SidebarLayout'
import s from './CheckoutSidebarView.module.css' import s from './CheckoutSidebarView.module.css'
const CheckoutSidebarView: FC = () => { const CheckoutSidebarView: FC = () => {
const { setSidebarView } = useUI() const { setSidebarView, closeSidebar } = useUI()
// const { data } = useCart() // const { data: cartData } = useCart()
// const { data: checkoutData, submit: onCheckout } = useCheckout()
// async function handleSubmit(event: React.ChangeEvent<HTMLFormElement>) {
// event.preventDefault()
// await onCheckout()
// closeSidebar()
// }
// const { price: subTotal } = usePrice( // const { price: subTotal } = usePrice(
// data && { // cartData && {
// amount: Number(data.subtotalPrice), // amount: Number(cartData.subtotalPrice),
// currencyCode: data.currency.code, // currencyCode: cartData.currency.code,
// } // }
// ) // )
// const { price: total } = usePrice( // const { price: total } = usePrice(
// data && { // cartData && {
// amount: Number(data.totalPrice), // amount: Number(cartData.totalPrice),
// currencyCode: data.currency.code, // currencyCode: cartData.currency.code,
// } // }
// ) // )
@@ -35,25 +44,36 @@ const CheckoutSidebarView: FC = () => {
> >
<div className="flex-1 px-4 sm:px-6"> <div className="flex-1 px-4 sm:px-6">
<Link href="/cart"> <Link href="/cart">
<Text variant="sectionHeading">Checkout</Text> <a>
<Text variant="sectionHeading">Checkout</Text>
</a>
</Link> </Link>
<PaymentWidget onClick={() => setSidebarView('PAYMENT_VIEW')} /> {/* <PaymentWidget
<ShippingWidget onClick={() => setSidebarView('SHIPPING_VIEW')} /> isValid={checkoutData?.hasPayment}
onClick={() => setSidebarView('PAYMENT_VIEW')}
/>
<ShippingWidget
isValid={checkoutData?.hasShipping}
onClick={() => setSidebarView('SHIPPING_VIEW')}
/> */}
<ul className={s.lineItemsList}> <ul className={s.lineItemsList}>
{/* {data!.lineItems.map((item: any) => ( {/* {cartData!.lineItems.map((item: any) => (
<CartItem <CartItem
key={item.id} key={item.id}
item={item} item={item}
currencyCode={data!.currency.code} currencyCode={cartData!.currency.code}
variant="display" variant="display"
/> />
))} */} ))} */}
</ul> </ul>
</div> </div>
<div className="sticky bottom-0 left-0 right-0 z-20 flex-shrink-0 w-full px-6 py-6 text-sm border-t sm:px-6 bg-accent-0"> <form
// onSubmit={handleSubmit}
className="sticky bottom-0 left-0 right-0 z-20 flex-shrink-0 w-full px-6 py-6 text-sm border-t sm:px-6 bg-accent-0"
>
<ul className="pb-2"> <ul className="pb-2">
<li className="flex justify-between py-1"> <li className="flex justify-between py-1">
<span>Subtotal</span> <span>Subtotal</span>
@@ -74,14 +94,15 @@ const CheckoutSidebarView: FC = () => {
</div> </div>
<div> <div>
{/* Once data is correcly filled */} {/* Once data is correcly filled */}
{/* <Button Component="a" width="100%"> <Button
Confirm Purchase type="submit"
</Button> */} width="100%"
<Button Component="a" width="100%" variant="ghost" disabled> // disabled={!checkoutData?.hasPayment || !checkoutData?.hasShipping}
Continue >
Confirm Purchase
</Button> </Button>
</div> </div>
</div> </form>
</SidebarLayout> </SidebarLayout>
) )
} }

View File

@@ -1,83 +1,129 @@
import { FC } from 'react' import { FC } from 'react'
import cn from 'classnames' import cn from 'classnames'
import useAddCard from '@framework/customer/card/use-add-item'
import { Button, Text } from '@components/ui' import { Button, Text } from '@components/ui'
import { useUI } from '@components/ui/context' import { useUI } from '@components/ui/context'
import s from './PaymentMethodView.module.css'
import SidebarLayout from '@components/common/SidebarLayout' import SidebarLayout from '@components/common/SidebarLayout'
import s from './PaymentMethodView.module.css'
interface Form extends HTMLFormElement {
cardHolder: HTMLInputElement
cardNumber: HTMLInputElement
cardExpireDate: HTMLInputElement
cardCvc: HTMLInputElement
firstName: HTMLInputElement
lastName: HTMLInputElement
company: HTMLInputElement
streetNumber: HTMLInputElement
zipCode: HTMLInputElement
city: HTMLInputElement
country: HTMLSelectElement
}
const PaymentMethodView: FC = () => { const PaymentMethodView: FC = () => {
const { setSidebarView } = useUI() const { setSidebarView } = useUI()
const addCard = useAddCard()
async function handleSubmit(event: React.ChangeEvent<Form>) {
event.preventDefault()
await addCard({
cardHolder: event.target.cardHolder.value,
cardNumber: event.target.cardNumber.value,
cardExpireDate: event.target.cardExpireDate.value,
cardCvc: event.target.cardCvc.value,
firstName: event.target.firstName.value,
lastName: event.target.lastName.value,
company: event.target.company.value,
streetNumber: event.target.streetNumber.value,
zipCode: event.target.zipCode.value,
city: event.target.city.value,
country: event.target.country.value,
})
setSidebarView('CHECKOUT_VIEW')
}
return ( return (
<SidebarLayout handleBack={() => setSidebarView('CHECKOUT_VIEW')}> <form className="h-full" onSubmit={handleSubmit}>
<div className="px-4 sm:px-6 flex-1"> <SidebarLayout handleBack={() => setSidebarView('CHECKOUT_VIEW')}>
<Text variant="sectionHeading"> Payment Method</Text> <div className="px-4 sm:px-6 flex-1">
<div> <Text variant="sectionHeading"> Payment Method</Text>
<div className={s.fieldset}> <div>
<label className={s.label}>Cardholder Name</label> <div className={s.fieldset}>
<input className={s.input} /> <label className={s.label}>Cardholder Name</label>
</div> <input name="cardHolder" className={s.input} />
<div className="grid gap-3 grid-flow-row grid-cols-12">
<div className={cn(s.fieldset, 'col-span-7')}>
<label className={s.label}>Card Number</label>
<input className={s.input} />
</div> </div>
<div className={cn(s.fieldset, 'col-span-3')}> <div className="grid gap-3 grid-flow-row grid-cols-12">
<label className={s.label}>Expires</label> <div className={cn(s.fieldset, 'col-span-7')}>
<input className={s.input} placeholder="MM/YY" /> <label className={s.label}>Card Number</label>
<input name="cardNumber" className={s.input} />
</div>
<div className={cn(s.fieldset, 'col-span-3')}>
<label className={s.label}>Expires</label>
<input
name="cardExpireDate"
className={s.input}
placeholder="MM/YY"
/>
</div>
<div className={cn(s.fieldset, 'col-span-2')}>
<label className={s.label}>CVC</label>
<input name="cardCvc" className={s.input} />
</div>
</div> </div>
<div className={cn(s.fieldset, 'col-span-2')}> <hr className="border-accent-2 my-6" />
<label className={s.label}>CVC</label> <div className="grid gap-3 grid-flow-row grid-cols-12">
<input className={s.input} /> <div className={cn(s.fieldset, 'col-span-6')}>
<label className={s.label}>First Name</label>
<input name="firstName" className={s.input} />
</div>
<div className={cn(s.fieldset, 'col-span-6')}>
<label className={s.label}>Last Name</label>
<input name="lastName" className={s.input} />
</div>
</div> </div>
</div> <div className={s.fieldset}>
<hr className="border-accent-2 my-6" /> <label className={s.label}>Company (Optional)</label>
<div className="grid gap-3 grid-flow-row grid-cols-12"> <input name="company" className={s.input} />
<div className={cn(s.fieldset, 'col-span-6')}>
<label className={s.label}>First Name</label>
<input className={s.input} />
</div> </div>
<div className={cn(s.fieldset, 'col-span-6')}> <div className={s.fieldset}>
<label className={s.label}>Last Name</label> <label className={s.label}>Street and House Number</label>
<input className={s.input} /> <input name="streetNumber" className={s.input} />
</div> </div>
</div> <div className={s.fieldset}>
<div className={s.fieldset}> <label className={s.label}>
<label className={s.label}>Company (Optional)</label> Apartment, Suite, Etc. (Optional)
<input className={s.input} /> </label>
</div> <input className={s.input} name="apartment" />
<div className={s.fieldset}>
<label className={s.label}>Street and House Number</label>
<input className={s.input} />
</div>
<div className={s.fieldset}>
<label className={s.label}>Apartment, Suite, Etc. (Optional)</label>
<input className={s.input} />
</div>
<div className="grid gap-3 grid-flow-row grid-cols-12">
<div className={cn(s.fieldset, 'col-span-6')}>
<label className={s.label}>Postal Code</label>
<input className={s.input} />
</div> </div>
<div className={cn(s.fieldset, 'col-span-6')}> <div className="grid gap-3 grid-flow-row grid-cols-12">
<label className={s.label}>City</label> <div className={cn(s.fieldset, 'col-span-6')}>
<input className={s.input} /> <label className={s.label}>Postal Code</label>
<input name="zipCode" className={s.input} />
</div>
<div className={cn(s.fieldset, 'col-span-6')}>
<label className={s.label}>City</label>
<input name="city" className={s.input} />
</div>
</div>
<div className={s.fieldset}>
<label className={s.label}>Country/Region</label>
<select name="country" className={s.select}>
<option>Hong Kong</option>
</select>
</div> </div>
</div>
<div className={s.fieldset}>
<label className={s.label}>Country/Region</label>
<select className={s.select}>
<option>Hong Kong</option>
</select>
</div> </div>
</div> </div>
</div> <div className="sticky z-20 bottom-0 w-full right-0 left-0 py-12 bg-accent-0 border-t border-accent-2 px-6">
<div className="sticky z-20 bottom-0 w-full right-0 left-0 py-12 bg-accent-0 border-t border-accent-2 px-6"> <Button type="submit" width="100%" variant="ghost">
<Button Component="a" width="100%" variant="ghost"> Continue
Continue </Button>
</Button> </div>
</div> </SidebarLayout>
</SidebarLayout> </form>
) )
} }

View File

@@ -1,14 +1,15 @@
import { FC } from 'react' import { FC } from 'react'
import s from './PaymentWidget.module.css' import s from './PaymentWidget.module.css'
import { ChevronRight, CreditCard } from '@components/icons' import { ChevronRight, CreditCard, Check } from '@components/icons'
interface ComponentProps { interface ComponentProps {
onClick?: () => any onClick?: () => any
isValid?: boolean
} }
const PaymentWidget: FC<ComponentProps> = ({ onClick }) => { const PaymentWidget: FC<ComponentProps> = ({ onClick, isValid }) => {
/* Shipping Address /* Shipping Address
Only available with checkout set to true - Only available with checkout set to true -
This means that the provider does offer checkout functionality. */ This means that the provider does offer checkout functionality. */
return ( return (
<div onClick={onClick} className={s.root}> <div onClick={onClick} className={s.root}>
@@ -19,9 +20,7 @@ const PaymentWidget: FC<ComponentProps> = ({ onClick }) => {
</span> </span>
{/* <span>VISA #### #### #### 2345</span> */} {/* <span>VISA #### #### #### 2345</span> */}
</div> </div>
<div> <div>{isValid ? <Check /> : <ChevronRight />}</div>
<ChevronRight />
</div>
</div> </div>
) )
} }

View File

@@ -1,77 +1,117 @@
import { FC } from 'react' import { FC } from 'react'
import cn from 'classnames' import cn from 'classnames'
import s from './ShippingView.module.css'
import Button from '@components/ui/Button' import Button from '@components/ui/Button'
import { useUI } from '@components/ui/context' import { useUI } from '@components/ui/context'
import SidebarLayout from '@components/common/SidebarLayout' import SidebarLayout from '@components/common/SidebarLayout'
import useAddAddress from '@framework/customer/address/use-add-item'
import s from './ShippingView.module.css'
interface Form extends HTMLFormElement {
cardHolder: HTMLInputElement
cardNumber: HTMLInputElement
cardExpireDate: HTMLInputElement
cardCvc: HTMLInputElement
firstName: HTMLInputElement
lastName: HTMLInputElement
company: HTMLInputElement
streetNumber: HTMLInputElement
zipCode: HTMLInputElement
city: HTMLInputElement
country: HTMLSelectElement
}
const PaymentMethodView: FC = () => { const PaymentMethodView: FC = () => {
const { setSidebarView } = useUI() const { setSidebarView } = useUI()
const addAddress = useAddAddress()
async function handleSubmit(event: React.ChangeEvent<Form>) {
event.preventDefault()
await addAddress({
type: event.target.type.value,
firstName: event.target.firstName.value,
lastName: event.target.lastName.value,
company: event.target.company.value,
streetNumber: event.target.streetNumber.value,
apartments: event.target.streetNumber.value,
zipCode: event.target.zipCode.value,
city: event.target.city.value,
country: event.target.country.value,
})
setSidebarView('CHECKOUT_VIEW')
}
return ( return (
<SidebarLayout handleBack={() => setSidebarView('CHECKOUT_VIEW')}> <form className="h-full" onSubmit={handleSubmit}>
<div className="px-4 sm:px-6 flex-1"> <SidebarLayout handleBack={() => setSidebarView('CHECKOUT_VIEW')}>
<h2 className="pt-1 pb-8 text-2xl font-semibold tracking-wide cursor-pointer inline-block"> <div className="px-4 sm:px-6 flex-1">
Shipping <h2 className="pt-1 pb-8 text-2xl font-semibold tracking-wide cursor-pointer inline-block">
</h2> Shipping
<div> </h2>
<div className="flex flex-row my-3 items-center"> <div>
<input className={s.radio} type="radio" /> <div className="flex flex-row my-3 items-center">
<span className="ml-3 text-sm">Same as billing address</span> <input name="type" className={s.radio} type="radio" />
</div> <span className="ml-3 text-sm">Same as billing address</span>
<div className="flex flex-row my-3 items-center">
<input className={s.radio} type="radio" />
<span className="ml-3 text-sm">
Use a different shipping address
</span>
</div>
<hr className="border-accent-2 my-6" />
<div className="grid gap-3 grid-flow-row grid-cols-12">
<div className={cn(s.fieldset, 'col-span-6')}>
<label className={s.label}>First Name</label>
<input className={s.input} />
</div> </div>
<div className={cn(s.fieldset, 'col-span-6')}> <div className="flex flex-row my-3 items-center">
<label className={s.label}>Last Name</label> <input name="type" className={s.radio} type="radio" />
<input className={s.input} /> <span className="ml-3 text-sm">
Use a different shipping address
</span>
</div> </div>
</div> <hr className="border-accent-2 my-6" />
<div className={s.fieldset}> <div className="grid gap-3 grid-flow-row grid-cols-12">
<label className={s.label}>Company (Optional)</label> <div className={cn(s.fieldset, 'col-span-6')}>
<input className={s.input} /> <label className={s.label}>First Name</label>
</div> <input name="firstName" className={s.input} />
<div className={s.fieldset}> </div>
<label className={s.label}>Street and House Number</label> <div className={cn(s.fieldset, 'col-span-6')}>
<input className={s.input} /> <label className={s.label}>Last Name</label>
</div> <input name="lastName" className={s.input} />
<div className={s.fieldset}> </div>
<label className={s.label}>Apartment, Suite, Etc. (Optional)</label>
<input className={s.input} />
</div>
<div className="grid gap-3 grid-flow-row grid-cols-12">
<div className={cn(s.fieldset, 'col-span-6')}>
<label className={s.label}>Postal Code</label>
<input className={s.input} />
</div> </div>
<div className={cn(s.fieldset, 'col-span-6')}> <div className={s.fieldset}>
<label className={s.label}>City</label> <label className={s.label}>Company (Optional)</label>
<input className={s.input} /> <input name="company" className={s.input} />
</div>
<div className={s.fieldset}>
<label className={s.label}>Street and House Number</label>
<input name="streetNumber" className={s.input} />
</div>
<div className={s.fieldset}>
<label className={s.label}>
Apartment, Suite, Etc. (Optional)
</label>
<input name="apartments" className={s.input} />
</div>
<div className="grid gap-3 grid-flow-row grid-cols-12">
<div className={cn(s.fieldset, 'col-span-6')}>
<label className={s.label}>Postal Code</label>
<input name="zipCode" className={s.input} />
</div>
<div className={cn(s.fieldset, 'col-span-6')}>
<label className={s.label}>City</label>
<input name="city" className={s.input} />
</div>
</div>
<div className={s.fieldset}>
<label className={s.label}>Country/Region</label>
<select name="country" className={s.select}>
<option>Hong Kong</option>
</select>
</div> </div>
</div>
<div className={s.fieldset}>
<label className={s.label}>Country/Region</label>
<select className={s.select}>
<option>Hong Kong</option>
</select>
</div> </div>
</div> </div>
</div> <div className="sticky z-20 bottom-0 w-full right-0 left-0 py-12 bg-accent-0 border-t border-accent-2 px-6">
<div className="sticky z-20 bottom-0 w-full right-0 left-0 py-12 bg-accent-0 border-t border-accent-2 px-6"> <Button type="submit" width="100%" variant="ghost">
<Button Component="a" width="100%" variant="ghost"> Continue
Continue </Button>
</Button> </div>
</div> </SidebarLayout>
</SidebarLayout> </form>
) )
} }

View File

@@ -1,15 +1,16 @@
import { FC } from 'react' import { FC } from 'react'
import s from './ShippingWidget.module.css' import s from './ShippingWidget.module.css'
import { ChevronRight, MapPin } from '@components/icons' import { ChevronRight, MapPin, Check } from '@components/icons'
import cn from 'classnames' import cn from 'classnames'
interface ComponentProps { interface ComponentProps {
onClick?: () => any onClick?: () => any
isValid?: boolean
} }
const ShippingWidget: FC<ComponentProps> = ({ onClick }) => { const ShippingWidget: FC<ComponentProps> = ({ onClick, isValid }) => {
/* Shipping Address /* Shipping Address
Only available with checkout set to true - Only available with checkout set to true -
This means that the provider does offer checkout functionality. */ This means that the provider does offer checkout functionality. */
return ( return (
<div onClick={onClick} className={s.root}> <div onClick={onClick} className={s.root}>
@@ -23,9 +24,7 @@ const ShippingWidget: FC<ComponentProps> = ({ onClick }) => {
San Franssisco, California San Franssisco, California
</span> */} </span> */}
</div> </div>
<div> <div>{isValid ? <Check /> : <ChevronRight />}</div>
<ChevronRight />
</div>
</div> </div>
) )
} }

View File

@@ -58,7 +58,7 @@ const ProductView: FC<ProductViewProps> = ({ product, relatedProducts }) => {
)} )}
</div> </div>
<ProductSidebar product={product} className={s.sidebar} /> <ProductSidebar key={product.id} product={product} className={s.sidebar} />
</div> </div>
<hr className="mt-7 border-accent-2" /> <hr className="mt-7 border-accent-2" />
<section className="px-6 py-12 mb-10"> <section className="px-6 py-12 mb-10">

View File

@@ -13,3 +13,64 @@
.sectionHeading { .sectionHeading {
@apply pt-1 pb-2 text-2xl font-bold tracking-wide cursor-pointer mb-2; @apply pt-1 pb-2 text-2xl font-bold tracking-wide cursor-pointer mb-2;
} }
/* Apply base font sizes and styles for typography markup (h2, h2, ul, p, etc.).
A helpful addition for whenn page content is consumed from a source managed through a wysiwyg editor. */
.body :is(h1, h2, h3, h4, h5, h6, p, ul, ol) {
@apply mb-4;
}
.body :is(h1, h2, h3, h4, h5, h6):not(:first-child) {
@apply mt-8;
}
.body :is(h1, h2, h3, h4, h5, h6) {
@apply font-semibold tracking-wide;
}
.body h1 {
@apply text-5xl;
}
.body h2 {
@apply text-4xl;
}
.body h3 {
@apply text-3xl;
}
.body h4 {
@apply text-2xl;
}
.body h5 {
@apply text-xl;
}
.body h6 {
@apply text-lg;
}
.body ul,
.body ol {
@apply pl-6;
}
.body ul {
@apply list-disc;
}
.body ol {
@apply list-decimal;
}
.body a {
@apply underline;
}
.body a:hover {
@apply no-underline;
}

View File

@@ -5,7 +5,7 @@ import { uuid } from 'uuidv4'
const fullCheckout = true const fullCheckout = true
const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
req, req,
res, res,
config, config,
@@ -87,4 +87,4 @@ const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({
res.end() res.end()
} }
export default checkout export default getCheckout

View File

@@ -2,13 +2,13 @@ import { GetAPISchema, createEndpoint } from '@commerce/api'
import checkoutEndpoint from '@commerce/api/endpoints/checkout' import checkoutEndpoint from '@commerce/api/endpoints/checkout'
import type { CheckoutSchema } from '../../../types/checkout' import type { CheckoutSchema } from '../../../types/checkout'
import type { BigcommerceAPI } from '../..' import type { BigcommerceAPI } from '../..'
import checkout from './checkout' import getCheckout from './get-checkout'
export type CheckoutAPI = GetAPISchema<BigcommerceAPI, CheckoutSchema> export type CheckoutAPI = GetAPISchema<BigcommerceAPI, CheckoutSchema>
export type CheckoutEndpoint = CheckoutAPI['endpoint'] export type CheckoutEndpoint = CheckoutAPI['endpoint']
export const handlers: CheckoutEndpoint['handlers'] = { checkout } export const handlers: CheckoutEndpoint['handlers'] = { getCheckout }
const checkoutApi = createEndpoint<CheckoutAPI>({ const checkoutApi = createEndpoint<CheckoutAPI>({
handler: checkoutEndpoint, handler: checkoutEndpoint,

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -53,7 +53,7 @@ export default function getCustomerWishlistOperation({
if (ids?.length) { if (ids?.length) {
const graphqlData = await commerce.getAllProducts({ const graphqlData = await commerce.getAllProducts({
variables: { first: 100, ids }, variables: { first: 50, ids },
config, config,
}) })
// Put the products in an object that we can use to get them by id // Put the products in an object that we can use to get them by id

View File

@@ -41,4 +41,4 @@ export const handler: MutationHook<AddItemHook> = {
[fetch, mutate] [fetch, mutate]
) )
}, },
} }

View File

@@ -0,0 +1,14 @@
import { SWRHook } from '@commerce/utils/types'
import useCheckout, { UseCheckout } from '@commerce/checkout/use-checkout'
export default useCheckout as UseCheckout<typeof handler>
export const handler: SWRHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ useData }) =>
async (input) => ({}),
}

View File

@@ -0,0 +1,15 @@
import useAddItem, { UseAddItem } from '@commerce/customer/address/use-add-item'
import { MutationHook } from '@commerce/utils/types'
export default useAddItem as UseAddItem<typeof handler>
export const handler: MutationHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ fetch }) =>
() =>
async () => ({}),
}

View File

@@ -0,0 +1,15 @@
import useAddItem, { UseAddItem } from '@commerce/customer/card/use-add-item'
import { MutationHook } from '@commerce/utils/types'
export default useAddItem as UseAddItem<typeof handler>
export const handler: MutationHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ fetch }) =>
() =>
async () => ({}),
}

View File

@@ -91,7 +91,10 @@ export function normalizeCart(data: BigcommerceCart): Cart {
createdAt: data.created_time, createdAt: data.created_time,
currency: data.currency, currency: data.currency,
taxesIncluded: data.tax_included, taxesIncluded: data.tax_included,
lineItems: data.line_items.physical_items.map(normalizeLineItem), lineItems: [
...data.line_items.physical_items.map(normalizeLineItem),
...data.line_items.digital_items.map(normalizeLineItem),
],
lineItemsSubtotalPrice: data.base_amount, lineItemsSubtotalPrice: data.base_amount,
subtotalPrice: data.base_amount + data.discount_amount, subtotalPrice: data.base_amount + data.discount_amount,
totalPrice: data.cart_amount, totalPrice: data.cart_amount,

View File

@@ -1,25 +1,39 @@
import type { CheckoutSchema } from '../../types/checkout' import type { CheckoutSchema } from '../../types/checkout'
import type { GetAPISchema } from '..'
import { CommerceAPIError } from '../utils/errors' import { CommerceAPIError } from '../utils/errors'
import isAllowedOperation from '../utils/is-allowed-operation' import isAllowedOperation from '../utils/is-allowed-operation'
import type { GetAPISchema } from '..'
const checkoutEndpoint: GetAPISchema< const checkoutEndpoint: GetAPISchema<
any, any,
CheckoutSchema CheckoutSchema
>['endpoint']['handler'] = async (ctx) => { >['endpoint']['handler'] = async (ctx) => {
const { req, res, handlers } = ctx const { req, res, handlers, config } = ctx
if ( if (
!isAllowedOperation(req, res, { !isAllowedOperation(req, res, {
GET: handlers['checkout'], GET: handlers['getCheckout'],
POST: handlers['submitCheckout'],
}) })
) { ) {
return return
} }
const { cookies } = req
const cartId = cookies[config.cartCookie]
try { try {
const body = null // Create checkout
return await handlers['checkout']({ ...ctx, body }) if (req.method === 'GET') {
const body = { ...req.body, cartId }
return await handlers['getCheckout']({ ...ctx, body })
}
// Create checkout
if (req.method === 'POST' && handlers['submitCheckout']) {
const body = { ...req.body, cartId }
return await handlers['submitCheckout']({ ...ctx, body })
}
} catch (error) { } catch (error) {
console.error(error) console.error(error)

View File

@@ -0,0 +1,65 @@
import type { CustomerAddressSchema } from '../../../types/customer/address'
import type { GetAPISchema } from '../..'
import { CommerceAPIError } from '../../utils/errors'
import isAllowedOperation from '../../utils/is-allowed-operation'
const customerShippingEndpoint: GetAPISchema<
any,
CustomerAddressSchema
>['endpoint']['handler'] = async (ctx) => {
const { req, res, handlers, config } = ctx
if (
!isAllowedOperation(req, res, {
GET: handlers['getAddresses'],
POST: handlers['addItem'],
PUT: handlers['updateItem'],
DELETE: handlers['removeItem'],
})
) {
return
}
const { cookies } = req
// Cart id might be usefull for anonymous shopping
const cartId = cookies[config.cartCookie]
try {
// Return customer addresses
if (req.method === 'GET') {
const body = { cartId }
return await handlers['getAddresses']({ ...ctx, body })
}
// Create or add an item to customer addresses list
if (req.method === 'POST') {
const body = { ...req.body, cartId }
return await handlers['addItem']({ ...ctx, body })
}
// Update item in customer addresses list
if (req.method === 'PUT') {
const body = { ...req.body, cartId }
return await handlers['updateItem']({ ...ctx, body })
}
// Remove an item from customer addresses list
if (req.method === 'DELETE') {
const body = { ...req.body, cartId }
return await handlers['removeItem']({ ...ctx, body })
}
} catch (error) {
console.error(error)
const message =
error instanceof CommerceAPIError
? 'An unexpected error ocurred with the Commerce API'
: 'An unexpected error ocurred'
res.status(500).json({ data: null, errors: [{ message }] })
}
}
export default customerShippingEndpoint

View File

@@ -0,0 +1,65 @@
import type { CustomerCardSchema } from '../../../types/customer/card'
import type { GetAPISchema } from '../..'
import { CommerceAPIError } from '../../utils/errors'
import isAllowedOperation from '../../utils/is-allowed-operation'
const customerCardEndpoint: GetAPISchema<
any,
CustomerCardSchema
>['endpoint']['handler'] = async (ctx) => {
const { req, res, handlers, config } = ctx
if (
!isAllowedOperation(req, res, {
GET: handlers['getCards'],
POST: handlers['addItem'],
PUT: handlers['updateItem'],
DELETE: handlers['removeItem'],
})
) {
return
}
const { cookies } = req
// Cart id might be usefull for anonymous shopping
const cartId = cookies[config.cartCookie]
try {
// Create or add a card
if (req.method === 'GET') {
const body = { ...req.body }
return await handlers['getCards']({ ...ctx, body })
}
// Create or add an item to customer cards
if (req.method === 'POST') {
const body = { ...req.body, cartId }
return await handlers['addItem']({ ...ctx, body })
}
// Update item in customer cards
if (req.method === 'PUT') {
const body = { ...req.body, cartId }
return await handlers['updateItem']({ ...ctx, body })
}
// Remove an item from customer cards
if (req.method === 'DELETE') {
const body = { ...req.body, cartId }
return await handlers['removeItem']({ ...ctx, body })
}
} catch (error) {
console.error(error)
const message =
error instanceof CommerceAPIError
? 'An unexpected error ocurred with the Commerce API'
: 'An unexpected error ocurred'
res.status(500).json({ data: null, errors: [{ message }] })
}
}
export default customerCardEndpoint

View File

@@ -1,7 +1,8 @@
import type { CustomerSchema } from '../../types/customer' import type { CustomerSchema } from '../../../types/customer'
import { CommerceAPIError } from '../utils/errors' import type { GetAPISchema } from '../..'
import isAllowedOperation from '../utils/is-allowed-operation'
import type { GetAPISchema } from '..' import { CommerceAPIError } from '../../utils/errors'
import isAllowedOperation from '../../utils/is-allowed-operation'
const customerEndpoint: GetAPISchema< const customerEndpoint: GetAPISchema<
any, any,

View File

@@ -9,6 +9,8 @@ import type { SignupSchema } from '../types/signup'
import type { ProductsSchema } from '../types/product' import type { ProductsSchema } from '../types/product'
import type { WishlistSchema } from '../types/wishlist' import type { WishlistSchema } from '../types/wishlist'
import type { CheckoutSchema } from '../types/checkout' import type { CheckoutSchema } from '../types/checkout'
import type { CustomerCardSchema } from '../types/customer/card'
import type { CustomerAddressSchema } from '../types/customer/address'
import { import {
defaultOperations, defaultOperations,
OPERATIONS, OPERATIONS,
@@ -25,6 +27,8 @@ export type APISchemas =
| ProductsSchema | ProductsSchema
| WishlistSchema | WishlistSchema
| CheckoutSchema | CheckoutSchema
| CustomerCardSchema
| CustomerAddressSchema
export type GetAPISchema< export type GetAPISchema<
C extends CommerceAPI<any>, C extends CommerceAPI<any>,

View File

@@ -0,0 +1,34 @@
import type { SWRHook, HookFetcherFn } from '../utils/types'
import type { GetCheckoutHook } from '../types/checkout'
import Cookies from 'js-cookie'
import { useHook, useSWRHook } from '../utils/use-hook'
import { Provider, useCommerce } from '..'
export type UseCheckout<
H extends SWRHook<GetCheckoutHook<any>> = SWRHook<GetCheckoutHook>
> = ReturnType<H['useHook']>
export const fetcher: HookFetcherFn<GetCheckoutHook> = async ({
options,
input: { cartId },
fetch,
}) => {
return cartId ? await fetch(options) : null
}
const fn = (provider: Provider) => provider.checkout?.useCheckout!
const useCheckout: UseCheckout = (input) => {
const hook = useHook(fn)
const { cartCookie } = useCommerce()
const fetcherFn = hook.fetcher ?? fetcher
const wrapper: typeof fetcher = (context) => {
context.input.cartId = Cookies.get(cartCookie)
return fetcherFn(context)
}
return useSWRHook({ ...hook, fetcher: wrapper })(input)
}
export default useCheckout

View File

@@ -0,0 +1,23 @@
import type { HookFetcherFn, MutationHook } from '../utils/types'
import type { SubmitCheckoutHook } from '../types/checkout'
import type { Provider } from '..'
import { useHook, useMutationHook } from '../utils/use-hook'
import { mutationFetcher } from '../utils/default-fetcher'
export type UseSubmitCheckout<
H extends MutationHook<
SubmitCheckoutHook<any>
> = MutationHook<SubmitCheckoutHook>
> = ReturnType<H['useHook']>
export const fetcher: HookFetcherFn<SubmitCheckoutHook> = mutationFetcher
const fn = (provider: Provider) => provider.checkout?.useSubmitCheckout!
const useSubmitCheckout: UseSubmitCheckout = (...args) => {
const hook = useHook(fn)
return useMutationHook({ fetcher, ...hook })(...args)
}
export default useSubmitCheckout

View File

@@ -0,0 +1,21 @@
import type { HookFetcherFn, MutationHook } from '../../utils/types'
import type { AddItemHook } from '../../types/customer/address'
import type { Provider } from '../..'
import { useHook, useMutationHook } from '../../utils/use-hook'
import { mutationFetcher } from '../../utils/default-fetcher'
export type UseAddItem<
H extends MutationHook<AddItemHook<any>> = MutationHook<AddItemHook>
> = ReturnType<H['useHook']>
export const fetcher: HookFetcherFn<AddItemHook> = mutationFetcher
const fn = (provider: Provider) => provider.customer?.address?.useAddItem!
const useAddItem: UseAddItem = (...args) => {
const hook = useHook(fn)
return useMutationHook({ fetcher, ...hook })(...args)
}
export default useAddItem

View File

@@ -0,0 +1,34 @@
import type { SWRHook, HookFetcherFn } from '../../utils/types'
import type { GetAddressesHook } from '../../types/customer/address'
import Cookies from 'js-cookie'
import { useHook, useSWRHook } from '../../utils/use-hook'
import { Provider, useCommerce } from '../..'
export type UseAddresses<
H extends SWRHook<GetAddressesHook<any>> = SWRHook<GetAddressesHook>
> = ReturnType<H['useHook']>
export const fetcher: HookFetcherFn<GetAddressesHook> = async ({
options,
input: { cartId },
fetch,
}) => {
return cartId ? await fetch(options) : null
}
const fn = (provider: Provider) => provider.customer?.address?.useAddresses!
const useAddresses: UseAddresses = (input) => {
const hook = useHook(fn)
const { cartCookie } = useCommerce()
const fetcherFn = hook.fetcher ?? fetcher
const wrapper: typeof fetcher = (context) => {
context.input.cartId = Cookies.get(cartCookie)
return fetcherFn(context)
}
return useSWRHook({ ...hook, fetcher: wrapper })(input)
}
export default useAddresses

View File

@@ -0,0 +1,21 @@
import type { HookFetcherFn, MutationHook } from '../../utils/types'
import type { RemoveItemHook } from '../../types/customer/address'
import type { Provider } from '../..'
import { useHook, useMutationHook } from '../../utils/use-hook'
import { mutationFetcher } from '../../utils/default-fetcher'
export type UseRemoveItem<
H extends MutationHook<RemoveItemHook<any>> = MutationHook<RemoveItemHook>
> = ReturnType<H['useHook']>
export const fetcher: HookFetcherFn<RemoveItemHook> = mutationFetcher
const fn = (provider: Provider) => provider.customer?.address?.useRemoveItem!
const useRemoveItem: UseRemoveItem = (input) => {
const hook = useHook(fn)
return useMutationHook({ fetcher, ...hook })(input)
}
export default useRemoveItem

View File

@@ -0,0 +1,21 @@
import type { HookFetcherFn, MutationHook } from '../../utils/types'
import type { UpdateItemHook } from '../../types/customer/address'
import type { Provider } from '../..'
import { useHook, useMutationHook } from '../../utils/use-hook'
import { mutationFetcher } from '../../utils/default-fetcher'
export type UseUpdateItem<
H extends MutationHook<UpdateItemHook<any>> = MutationHook<UpdateItemHook>
> = ReturnType<H['useHook']>
export const fetcher: HookFetcherFn<UpdateItemHook> = mutationFetcher
const fn = (provider: Provider) => provider.customer?.address?.useUpdateItem!
const useUpdateItem: UseUpdateItem = (input) => {
const hook = useHook(fn)
return useMutationHook({ fetcher, ...hook })(input)
}
export default useUpdateItem

View File

@@ -0,0 +1,21 @@
import type { HookFetcherFn, MutationHook } from '../../utils/types'
import type { AddItemHook } from '../../types/customer/card'
import type { Provider } from '../..'
import { useHook, useMutationHook } from '../../utils/use-hook'
import { mutationFetcher } from '../../utils/default-fetcher'
export type UseAddItem<
H extends MutationHook<AddItemHook<any>> = MutationHook<AddItemHook>
> = ReturnType<H['useHook']>
export const fetcher: HookFetcherFn<AddItemHook> = mutationFetcher
const fn = (provider: Provider) => provider.customer?.card?.useAddItem!
const useAddItem: UseAddItem = (...args) => {
const hook = useHook(fn)
return useMutationHook({ fetcher, ...hook })(...args)
}
export default useAddItem

View File

@@ -0,0 +1,34 @@
import type { SWRHook, HookFetcherFn } from '../../utils/types'
import type { GetCardsHook } from '../../types/customer/card'
import Cookies from 'js-cookie'
import { useHook, useSWRHook } from '../../utils/use-hook'
import { Provider, useCommerce } from '../..'
export type UseCards<
H extends SWRHook<GetCardsHook<any>> = SWRHook<GetCardsHook>
> = ReturnType<H['useHook']>
export const fetcher: HookFetcherFn<GetCardsHook> = async ({
options,
input: { cartId },
fetch,
}) => {
return cartId ? await fetch(options) : null
}
const fn = (provider: Provider) => provider.customer?.card?.useCards!
const useCards: UseCards = (input) => {
const hook = useHook(fn)
const { cartCookie } = useCommerce()
const fetcherFn = hook.fetcher ?? fetcher
const wrapper: typeof fetcher = (context) => {
context.input.cartId = Cookies.get(cartCookie)
return fetcherFn(context)
}
return useSWRHook({ ...hook, fetcher: wrapper })(input)
}
export default useCards

View File

@@ -0,0 +1,21 @@
import type { HookFetcherFn, MutationHook } from '../../utils/types'
import type { RemoveItemHook } from '../../types/customer/card'
import type { Provider } from '../..'
import { useHook, useMutationHook } from '../../utils/use-hook'
import { mutationFetcher } from '../../utils/default-fetcher'
export type UseRemoveItem<
H extends MutationHook<RemoveItemHook<any>> = MutationHook<RemoveItemHook>
> = ReturnType<H['useHook']>
export const fetcher: HookFetcherFn<RemoveItemHook> = mutationFetcher
const fn = (provider: Provider) => provider.customer?.card?.useRemoveItem!
const useRemoveItem: UseRemoveItem = (input) => {
const hook = useHook(fn)
return useMutationHook({ fetcher, ...hook })(input)
}
export default useRemoveItem

View File

@@ -0,0 +1,21 @@
import type { HookFetcherFn, MutationHook } from '../../utils/types'
import type { UpdateItemHook } from '../../types/customer/card'
import type { Provider } from '../..'
import { useHook, useMutationHook } from '../../utils/use-hook'
import { mutationFetcher } from '../../utils/default-fetcher'
export type UseUpdateItem<
H extends MutationHook<UpdateItemHook<any>> = MutationHook<UpdateItemHook>
> = ReturnType<H['useHook']>
export const fetcher: HookFetcherFn<UpdateItemHook> = mutationFetcher
const fn = (provider: Provider) => provider?.customer?.card?.useUpdateItem!
const useUpdateItem: UseUpdateItem = (input) => {
const hook = useHook(fn)
return useMutationHook({ fetcher, ...hook })(input)
}
export default useUpdateItem

View File

@@ -15,6 +15,7 @@ import type {
Signup, Signup,
Login, Login,
Logout, Logout,
Checkout,
} from '@commerce/types' } from '@commerce/types'
import type { Fetcher, SWRHook, MutationHook } from './utils/types' import type { Fetcher, SWRHook, MutationHook } from './utils/types'
@@ -29,6 +30,10 @@ export type Provider = CommerceConfig & {
useUpdateItem?: MutationHook<Cart.UpdateItemHook> useUpdateItem?: MutationHook<Cart.UpdateItemHook>
useRemoveItem?: MutationHook<Cart.RemoveItemHook> useRemoveItem?: MutationHook<Cart.RemoveItemHook>
} }
checkout?: {
useCheckout?: SWRHook<Checkout.GetCheckoutHook>
useSubmitCheckout?: MutationHook<Checkout.SubmitCheckoutHook>
}
wishlist?: { wishlist?: {
useWishlist?: SWRHook<Wishlist.GetWishlistHook> useWishlist?: SWRHook<Wishlist.GetWishlistHook>
useAddItem?: MutationHook<Wishlist.AddItemHook> useAddItem?: MutationHook<Wishlist.AddItemHook>
@@ -36,6 +41,18 @@ export type Provider = CommerceConfig & {
} }
customer?: { customer?: {
useCustomer?: SWRHook<Customer.CustomerHook> useCustomer?: SWRHook<Customer.CustomerHook>
card?: {
useCards?: SWRHook<Customer.Card.GetCardsHook>
useAddItem?: MutationHook<Customer.Card.AddItemHook>
useUpdateItem?: MutationHook<Customer.Card.UpdateItemHook>
useRemoveItem?: MutationHook<Customer.Card.RemoveItemHook>
}
address?: {
useAddresses?: SWRHook<Customer.Address.GetAddressesHook>
useAddItem?: MutationHook<Customer.Address.AddItemHook>
useUpdateItem?: MutationHook<Customer.Address.UpdateItemHook>
useRemoveItem?: MutationHook<Customer.Address.RemoveItemHook>
}
} }
products?: { products?: {
useSearch?: SWRHook<Product.SearchProductsHook> useSearch?: SWRHook<Product.SearchProductsHook>

View File

@@ -1,10 +1,57 @@
export type CheckoutSchema = { import type { UseSubmitCheckout } from '../checkout/use-submit-checkout'
import type { Address } from './customer/address'
import type { Card } from './customer/card'
// Index
export type Checkout = any
export type CheckoutTypes = {
card?: Card
address?: Address
checkout?: Checkout
hasPayment?: boolean
hasShipping?: boolean
}
export type SubmitCheckoutHook<T extends CheckoutTypes = CheckoutTypes> = {
data: T
input?: T
fetcherInput: T
body: { item: T }
actionInput: T
}
export type GetCheckoutHook<T extends CheckoutTypes = CheckoutTypes> = {
data: T['checkout'] | null
input: {}
fetcherInput: { cartId?: string }
swrState: { isEmpty: boolean }
mutations: { submit: UseSubmitCheckout }
}
export type CheckoutHooks<T extends CheckoutTypes = CheckoutTypes> = {
submitCheckout: SubmitCheckoutHook<T>
getCheckout: GetCheckoutHook<T>
}
export type GetCheckoutHandler<T extends CheckoutTypes = CheckoutTypes> =
GetCheckoutHook<T> & {
body: { cartId: string }
}
export type SubmitCheckoutHandler<T extends CheckoutTypes = CheckoutTypes> =
SubmitCheckoutHook<T> & {
body: { cartId: string }
}
export type CheckoutHandlers<T extends CheckoutTypes = CheckoutTypes> = {
getCheckout: GetCheckoutHandler<T>
submitCheckout?: SubmitCheckoutHandler<T>
}
export type CheckoutSchema<T extends CheckoutTypes = CheckoutTypes> = {
endpoint: { endpoint: {
options: {} options: {}
handlers: { handlers: CheckoutHandlers<T>
checkout: {
data: null
}
}
} }
} }

View File

@@ -0,0 +1,93 @@
export interface Address {
id: string;
mask: string;
}
export interface AddressFields {
type: string;
firstName: string;
lastName: string;
company: string;
streetNumber: string;
apartments: string;
zipCode: string;
city: string;
country: string;
}
export type CustomerAddressTypes = {
address?: Address;
fields: AddressFields;
}
export type GetAddressesHook<T extends CustomerAddressTypes = CustomerAddressTypes> = {
data: T['address'] | null
input: {}
fetcherInput: { cartId?: string }
swrState: { isEmpty: boolean }
}
export type AddItemHook<T extends CustomerAddressTypes = CustomerAddressTypes> = {
data: T['address']
input?: T['fields']
fetcherInput: T['fields']
body: { item: T['fields'] }
actionInput: T['fields']
}
export type UpdateItemHook<T extends CustomerAddressTypes = CustomerAddressTypes> = {
data: T['address'] | null
input: { item?: T['fields']; wait?: number }
fetcherInput: { itemId: string; item: T['fields'] }
body: { itemId: string; item: T['fields'] }
actionInput: T['fields'] & { id: string }
}
export type RemoveItemHook<T extends CustomerAddressTypes = CustomerAddressTypes> = {
data: T['address'] | null
input: { item?: T['fields'] }
fetcherInput: { itemId: string }
body: { itemId: string }
actionInput: { id: string }
}
export type CustomerAddressHooks<T extends CustomerAddressTypes = CustomerAddressTypes> = {
getAddresses: GetAddressesHook<T>
addItem: AddItemHook<T>
updateItem: UpdateItemHook<T>
removeItem: RemoveItemHook<T>
}
export type AddresssHandler<T extends CustomerAddressTypes = CustomerAddressTypes> = GetAddressesHook<T> & {
body: { cartId?: string }
}
export type AddItemHandler<T extends CustomerAddressTypes = CustomerAddressTypes> = AddItemHook<T> & {
body: { cartId: string }
}
export type UpdateItemHandler<T extends CustomerAddressTypes = CustomerAddressTypes> =
UpdateItemHook<T> & {
data: T['address']
body: { cartId: string }
}
export type RemoveItemHandler<T extends CustomerAddressTypes = CustomerAddressTypes> =
RemoveItemHook<T> & {
body: { cartId: string }
}
export type CustomerAddressHandlers<T extends CustomerAddressTypes = CustomerAddressTypes> = {
getAddresses: GetAddressesHook<T>
addItem: AddItemHandler<T>
updateItem: UpdateItemHandler<T>
removeItem: RemoveItemHandler<T>
}
export type CustomerAddressSchema<T extends CustomerAddressTypes = CustomerAddressTypes> = {
endpoint: {
options: {}
handlers: CustomerAddressHandlers<T>
}
}

View File

@@ -0,0 +1,96 @@
export interface Card {
id: string;
mask: string;
provider: string;
}
export interface CardFields {
cardHolder: string;
cardNumber: string;
cardExpireDate: string;
cardCvc: string;
firstName: string;
lastName: string;
company: string;
streetNumber: string;
zipCode: string;
city: string;
country: string;
}
export type CustomerCardTypes = {
card?: Card;
fields: CardFields;
}
export type GetCardsHook<T extends CustomerCardTypes = CustomerCardTypes> = {
data: T['card'] | null
input: {}
fetcherInput: { cartId?: string }
swrState: { isEmpty: boolean }
}
export type AddItemHook<T extends CustomerCardTypes = CustomerCardTypes> = {
data: T['card']
input?: T['fields']
fetcherInput: T['fields']
body: { item: T['fields'] }
actionInput: T['fields']
}
export type UpdateItemHook<T extends CustomerCardTypes = CustomerCardTypes> = {
data: T['card'] | null
input: { item?: T['fields']; wait?: number }
fetcherInput: { itemId: string; item: T['fields'] }
body: { itemId: string; item: T['fields'] }
actionInput: T['fields'] & { id: string }
}
export type RemoveItemHook<T extends CustomerCardTypes = CustomerCardTypes> = {
data: T['card'] | null
input: { item?: T['fields'] }
fetcherInput: { itemId: string }
body: { itemId: string }
actionInput: { id: string }
}
export type CustomerCardHooks<T extends CustomerCardTypes = CustomerCardTypes> = {
getCards: GetCardsHook<T>
addItem: AddItemHook<T>
updateItem: UpdateItemHook<T>
removeItem: RemoveItemHook<T>
}
export type CardsHandler<T extends CustomerCardTypes = CustomerCardTypes> = GetCardsHook<T> & {
body: { cartId?: string }
}
export type AddItemHandler<T extends CustomerCardTypes = CustomerCardTypes> = AddItemHook<T> & {
body: { cartId: string }
}
export type UpdateItemHandler<T extends CustomerCardTypes = CustomerCardTypes> =
UpdateItemHook<T> & {
data: T['card']
body: { cartId: string }
}
export type RemoveItemHandler<T extends CustomerCardTypes = CustomerCardTypes> =
RemoveItemHook<T> & {
body: { cartId: string }
}
export type CustomerCardHandlers<T extends CustomerCardTypes = CustomerCardTypes> = {
getCards: GetCardsHook<T>
addItem: AddItemHandler<T>
updateItem: UpdateItemHandler<T>
removeItem: RemoveItemHandler<T>
}
export type CustomerCardSchema<T extends CustomerCardTypes = CustomerCardTypes> = {
endpoint: {
options: {}
handlers: CustomerCardHandlers<T>
}
}

View File

@@ -1,3 +1,6 @@
export * as Card from "./card"
export * as Address from "./address"
// TODO: define this type // TODO: define this type
export type Customer = any export type Customer = any

View File

@@ -87,6 +87,8 @@ export type HookSchemaBase = {
export type SWRHookSchemaBase = HookSchemaBase & { export type SWRHookSchemaBase = HookSchemaBase & {
// Custom state added to the response object of SWR // Custom state added to the response object of SWR
swrState?: {} swrState?: {}
// Instances of MutationSchemaBase that the hook returns for better DX
mutations?: Record<string, ReturnType<MutationHook<any>['useHook']>>
} }
export type MutationSchemaBase = HookSchemaBase & { export type MutationSchemaBase = HookSchemaBase & {
@@ -102,7 +104,7 @@ export type SWRHook<H extends SWRHookSchemaBase> = {
context: SWRHookContext<H> context: SWRHookContext<H>
): HookFunction< ): HookFunction<
H['input'] & { swrOptions?: SwrOptions<H['data'], H['fetcherInput']> }, H['input'] & { swrOptions?: SwrOptions<H['data'], H['fetcherInput']> },
ResponseState<H['data']> & H['swrState'] ResponseState<H['data']> & H['swrState'] & H['mutations']
> >
fetchOptions: HookFetcherOptions fetchOptions: HookFetcherOptions
fetcher?: HookFetcherFn<H> fetcher?: HookFetcherFn<H>

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -0,0 +1,14 @@
import { SWRHook } from '@commerce/utils/types'
import useCheckout, { UseCheckout } from '@commerce/checkout/use-checkout'
export default useCheckout as UseCheckout<typeof handler>
export const handler: SWRHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ useData }) =>
async (input) => ({}),
}

View File

@@ -0,0 +1,15 @@
import useAddItem, { UseAddItem } from '@commerce/customer/address/use-add-item'
import { MutationHook } from '@commerce/utils/types'
export default useAddItem as UseAddItem<typeof handler>
export const handler: MutationHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ fetch }) =>
() =>
async () => ({}),
}

View File

@@ -0,0 +1,15 @@
import useAddItem, { UseAddItem } from '@commerce/customer/card/use-add-item'
import { MutationHook } from '@commerce/utils/types'
export default useAddItem as UseAddItem<typeof handler>
export const handler: MutationHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ fetch }) =>
() =>
async () => ({}),
}

View File

@@ -6,11 +6,7 @@ export type CheckoutAPI = GetAPISchema<CommerceAPI, CheckoutSchema>
export type CheckoutEndpoint = CheckoutAPI['endpoint'] export type CheckoutEndpoint = CheckoutAPI['endpoint']
const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({ req, res, config }) => {
req,
res,
config,
}) => {
try { try {
const html = ` const html = `
<!DOCTYPE html> <!DOCTYPE html>
@@ -47,7 +43,7 @@ const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({
} }
} }
export const handlers: CheckoutEndpoint['handlers'] = { checkout } export const handlers: CheckoutEndpoint['handlers'] = { getCheckout }
const checkoutApi = createEndpoint<CheckoutAPI>({ const checkoutApi = createEndpoint<CheckoutAPI>({
handler: checkoutEndpoint, handler: checkoutEndpoint,

View File

@@ -1 +0,0 @@
export default function (_commerce: any) {}

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -0,0 +1,14 @@
import { SWRHook } from '@commerce/utils/types'
import useCheckout, { UseCheckout } from '@commerce/checkout/use-checkout'
export default useCheckout as UseCheckout<typeof handler>
export const handler: SWRHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ useData }) =>
async (input) => ({}),
}

View File

@@ -1,7 +1,6 @@
{ {
"provider": "saleor", "provider": "saleor",
"features": { "features": {
"wishlist": false, "wishlist": false
"customCheckout": true
} }
} }

View File

@@ -0,0 +1,15 @@
import useAddItem, { UseAddItem } from '@commerce/customer/address/use-add-item'
import { MutationHook } from '@commerce/utils/types'
export default useAddItem as UseAddItem<typeof handler>
export const handler: MutationHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ fetch }) =>
() =>
async () => ({}),
}

View File

@@ -0,0 +1,15 @@
import useAddItem, { UseAddItem } from '@commerce/customer/card/use-add-item'
import { MutationHook } from '@commerce/utils/types'
export default useAddItem as UseAddItem<typeof handler>
export const handler: MutationHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ fetch }) =>
() =>
async () => ({}),
}

View File

@@ -2,7 +2,7 @@
**Demo:** https://shopify.demo.vercel.store/ **Demo:** https://shopify.demo.vercel.store/
Before getting starter, a [Shopify](https://www.shopify.com/) account and store is required before using the provider. Before getting started, a [Shopify](https://www.shopify.com/) account and store is required before using the provider.
Next, copy the `.env.template` file in this directory to `.env.local` in the main directory (which will be ignored by Git): Next, copy the `.env.template` file in this directory to `.env.local` in the main directory (which will be ignored by Git):

View File

@@ -6,7 +6,7 @@ import {
import associateCustomerWithCheckoutMutation from '../../../utils/mutations/associate-customer-with-checkout' import associateCustomerWithCheckoutMutation from '../../../utils/mutations/associate-customer-with-checkout'
import type { CheckoutEndpoint } from '.' import type { CheckoutEndpoint } from '.'
const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
req, req,
res, res,
config, config,
@@ -35,4 +35,4 @@ const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({
} }
} }
export default checkout export default getCheckout

View File

@@ -2,13 +2,13 @@ import { GetAPISchema, createEndpoint } from '@commerce/api'
import checkoutEndpoint from '@commerce/api/endpoints/checkout' import checkoutEndpoint from '@commerce/api/endpoints/checkout'
import type { CheckoutSchema } from '../../../types/checkout' import type { CheckoutSchema } from '../../../types/checkout'
import type { ShopifyAPI } from '../..' import type { ShopifyAPI } from '../..'
import checkout from './checkout' import getCheckout from './get-checkout'
export type CheckoutAPI = GetAPISchema<ShopifyAPI, CheckoutSchema> export type CheckoutAPI = GetAPISchema<ShopifyAPI, CheckoutSchema>
export type CheckoutEndpoint = CheckoutAPI['endpoint'] export type CheckoutEndpoint = CheckoutAPI['endpoint']
export const handlers: CheckoutEndpoint['handlers'] = { checkout } export const handlers: CheckoutEndpoint['handlers'] = { getCheckout }
const checkoutApi = createEndpoint<CheckoutAPI>({ const checkoutApi = createEndpoint<CheckoutAPI>({
handler: checkoutEndpoint, handler: checkoutEndpoint,

View File

@@ -1 +0,0 @@
export default function (_commerce: any) {}

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -9,6 +9,7 @@ import {
checkoutLineItemAddMutation, checkoutLineItemAddMutation,
getCheckoutId, getCheckoutId,
checkoutToCart, checkoutToCart,
checkoutCreate,
} from '../utils' } from '../utils'
import { Mutation, MutationCheckoutLineItemsAddArgs } from '../schema' import { Mutation, MutationCheckoutLineItemsAddArgs } from '../schema'
@@ -28,34 +29,42 @@ export const handler: MutationHook<AddItemHook> = {
}) })
} }
const { checkoutLineItemsAdd } = await fetch< const lineItems = [
Mutation, {
MutationCheckoutLineItemsAddArgs variantId: item.variantId,
>({ quantity: item.quantity ?? 1,
...options,
variables: {
checkoutId: getCheckoutId(),
lineItems: [
{
variantId: item.variantId,
quantity: item.quantity ?? 1,
},
],
}, },
}) ]
return checkoutToCart(checkoutLineItemsAdd) let checkoutId = getCheckoutId()
},
useHook: ({ fetch }) => () => {
const { mutate } = useCart()
return useCallback( if (!checkoutId) {
async function addItem(input) { return checkoutToCart(await checkoutCreate(fetch, lineItems))
const data = await fetch({ input }) } else {
await mutate(data, false) const { checkoutLineItemsAdd } = await fetch<
return data Mutation,
}, MutationCheckoutLineItemsAddArgs
[fetch, mutate] >({
) ...options,
variables: {
checkoutId,
lineItems,
},
})
return checkoutToCart(checkoutLineItemsAdd)
}
}, },
useHook:
({ fetch }) =>
() => {
const { mutate } = useCart()
return useCallback(
async function addItem(input) {
const data = await fetch({ input })
await mutate(data, false)
return data
},
[fetch, mutate]
)
},
} }

View File

@@ -2,15 +2,15 @@ import { useMemo } from 'react'
import useCommerceCart, { UseCart } from '@commerce/cart/use-cart' import useCommerceCart, { UseCart } from '@commerce/cart/use-cart'
import { SWRHook } from '@commerce/utils/types' import { SWRHook } from '@commerce/utils/types'
import { checkoutCreate, checkoutToCart } from '../utils' import { checkoutToCart } from '../utils'
import getCheckoutQuery from '../utils/queries/get-checkout-query' import getCheckoutQuery from '../utils/queries/get-checkout-query'
import { GetCartHook } from '../types/cart' import { GetCartHook } from '../types/cart'
import Cookies from 'js-cookie'
import { import {
GetCheckoutQuery, SHOPIFY_CHECKOUT_ID_COOKIE,
GetCheckoutQueryVariables, SHOPIFY_CHECKOUT_URL_COOKIE,
CheckoutDetailsFragment, } from '../const'
} from '../schema'
export default useCommerceCart as UseCart<typeof handler> export default useCommerceCart as UseCart<typeof handler>
@@ -18,40 +18,43 @@ export const handler: SWRHook<GetCartHook> = {
fetchOptions: { fetchOptions: {
query: getCheckoutQuery, query: getCheckoutQuery,
}, },
async fetcher({ input: { cartId: checkoutId }, options, fetch }) { async fetcher({ input: { cartId }, options, fetch }) {
let checkout if (cartId) {
const { node: checkout } = await fetch({
if (checkoutId) {
const data = await fetch({
...options, ...options,
variables: { variables: {
checkoutId: checkoutId, checkoutId: cartId,
}, },
}) })
checkout = data.node if (checkout?.completedAt) {
Cookies.remove(SHOPIFY_CHECKOUT_ID_COOKIE)
Cookies.remove(SHOPIFY_CHECKOUT_URL_COOKIE)
return null
} else {
return checkoutToCart({
checkout,
})
}
} }
return null
if (checkout?.completedAt || !checkoutId) {
checkout = await checkoutCreate(fetch)
}
return checkoutToCart({ checkout })
}, },
useHook: ({ useData }) => (input) => { useHook:
const response = useData({ ({ useData }) =>
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions }, (input) => {
}) const response = useData({
return useMemo( swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
() => })
Object.create(response, { return useMemo(
isEmpty: { () =>
get() { Object.create(response, {
return (response.data?.lineItems.length ?? 0) <= 0 isEmpty: {
get() {
return (response.data?.lineItems.length ?? 0) <= 0
},
enumerable: true,
}, },
enumerable: true, }),
}, [response]
}), )
[response] },
)
},
} }

View File

@@ -0,0 +1,14 @@
import { SWRHook } from '@commerce/utils/types'
import useCheckout, { UseCheckout } from '@commerce/checkout/use-checkout'
export default useCheckout as UseCheckout<typeof handler>
export const handler: SWRHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ useData }) =>
async (input) => ({}),
}

View File

@@ -1,6 +1,7 @@
{ {
"provider": "shopify", "provider": "shopify",
"features": { "features": {
"wishlist": false "wishlist": false,
"customerAuth": true
} }
} }

View File

@@ -8,6 +8,6 @@ export const STORE_DOMAIN = process.env.NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN
export const SHOPIFY_COOKIE_EXPIRE = 30 export const SHOPIFY_COOKIE_EXPIRE = 30
export const API_URL = `https://${STORE_DOMAIN}/api/2021-01/graphql.json` export const API_URL = `https://${STORE_DOMAIN}/api/2021-07/graphql.json`
export const API_TOKEN = process.env.NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN export const API_TOKEN = process.env.NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN

View File

@@ -0,0 +1,15 @@
import useAddItem, { UseAddItem } from '@commerce/customer/address/use-add-item'
import { MutationHook } from '@commerce/utils/types'
export default useAddItem as UseAddItem<typeof handler>
export const handler: MutationHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ fetch }) =>
() =>
async () => ({}),
}

View File

@@ -0,0 +1,15 @@
import useAddItem, { UseAddItem } from '@commerce/customer/card/use-add-item'
import { MutationHook } from '@commerce/utils/types'
export default useAddItem as UseAddItem<typeof handler>
export const handler: MutationHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ fetch }) =>
() =>
async () => ({}),
}

View File

@@ -7,27 +7,39 @@ import {
} from '../const' } from '../const'
import checkoutCreateMutation from './mutations/checkout-create' import checkoutCreateMutation from './mutations/checkout-create'
import { CheckoutCreatePayload } from '../schema' import {
CheckoutCreatePayload,
CheckoutLineItemInput,
Mutation,
MutationCheckoutCreateArgs,
} from '../schema'
import { FetcherOptions } from '@commerce/utils/types'
export const checkoutCreate = async ( export const checkoutCreate = async (
fetch: any fetch: <T = any, B = Body>(options: FetcherOptions<B>) => Promise<T>,
lineItems: CheckoutLineItemInput[]
): Promise<CheckoutCreatePayload> => { ): Promise<CheckoutCreatePayload> => {
const data = await fetch({ const { checkoutCreate } = await fetch<Mutation, MutationCheckoutCreateArgs>({
query: checkoutCreateMutation, query: checkoutCreateMutation,
variables: {
input: { lineItems },
},
}) })
const checkout = data.checkoutCreate?.checkout const checkout = checkoutCreate?.checkout
const checkoutId = checkout?.id
if (checkoutId) { if (checkout) {
const checkoutId = checkout?.id
const options = { const options = {
expires: SHOPIFY_COOKIE_EXPIRE, expires: SHOPIFY_COOKIE_EXPIRE,
} }
Cookies.set(SHOPIFY_CHECKOUT_ID_COOKIE, checkoutId, options) Cookies.set(SHOPIFY_CHECKOUT_ID_COOKIE, checkoutId, options)
Cookies.set(SHOPIFY_CHECKOUT_URL_COOKIE, checkout.webUrl, options) if (checkout?.webUrl) {
Cookies.set(SHOPIFY_CHECKOUT_URL_COOKIE, checkout.webUrl, options)
}
} }
return checkout return checkoutCreate!
} }
export default checkoutCreate export default checkoutCreate

View File

@@ -27,16 +27,15 @@ export type CheckoutPayload =
| CheckoutQuery | CheckoutQuery
const checkoutToCart = (checkoutPayload?: Maybe<CheckoutPayload>): Cart => { const checkoutToCart = (checkoutPayload?: Maybe<CheckoutPayload>): Cart => {
const checkout = checkoutPayload?.checkout
throwUserErrors(checkoutPayload?.checkoutUserErrors) throwUserErrors(checkoutPayload?.checkoutUserErrors)
if (!checkout) { if (!checkoutPayload?.checkout) {
throw new CommerceError({ throw new CommerceError({
message: 'Missing checkout object from response', message: 'Missing checkout object from response',
}) })
} }
return normalizeCart(checkout) return normalizeCart(checkoutPayload?.checkout)
} }
export default checkoutToCart export default checkoutToCart

View File

@@ -3,7 +3,7 @@ import { CheckoutSchema } from '@commerce/types/checkout'
import { SWELL_CHECKOUT_URL_COOKIE } from '../../../const' import { SWELL_CHECKOUT_URL_COOKIE } from '../../../const'
import checkoutEndpoint from '@commerce/api/endpoints/checkout' import checkoutEndpoint from '@commerce/api/endpoints/checkout'
const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
req, req,
res, res,
config, config,
@@ -17,7 +17,7 @@ const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({
res.redirect('/cart') res.redirect('/cart')
} }
} }
export const handlers: CheckoutEndpoint['handlers'] = { checkout } export const handlers: CheckoutEndpoint['handlers'] = { getCheckout }
export type CheckoutAPI = GetAPISchema<CommerceAPI, CheckoutSchema> export type CheckoutAPI = GetAPISchema<CommerceAPI, CheckoutSchema>
export type CheckoutEndpoint = CheckoutAPI['endpoint'] export type CheckoutEndpoint = CheckoutAPI['endpoint']

View File

@@ -1 +0,0 @@
export default function (_commerce: any) {}

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -0,0 +1,14 @@
import { SWRHook } from '@commerce/utils/types'
import useCheckout, { UseCheckout } from '@commerce/checkout/use-checkout'
export default useCheckout as UseCheckout<typeof handler>
export const handler: SWRHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ useData }) =>
async (input) => ({}),
}

View File

@@ -0,0 +1,15 @@
import useAddItem, { UseAddItem } from '@commerce/customer/address/use-add-item'
import { MutationHook } from '@commerce/utils/types'
export default useAddItem as UseAddItem<typeof handler>
export const handler: MutationHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ fetch }) =>
() =>
async () => ({}),
}

View File

@@ -0,0 +1,15 @@
import useAddItem, { UseAddItem } from '@commerce/customer/card/use-add-item'
import { MutationHook } from '@commerce/utils/types'
export default useAddItem as UseAddItem<typeof handler>
export const handler: MutationHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ fetch }) =>
() =>
async () => ({}),
}

View File

@@ -3,7 +3,7 @@ import { CommerceAPI, createEndpoint, GetAPISchema } from '@commerce/api'
import { CheckoutSchema } from '@commerce/types/checkout' import { CheckoutSchema } from '@commerce/types/checkout'
import checkoutEndpoint from '@commerce/api/endpoints/checkout' import checkoutEndpoint from '@commerce/api/endpoints/checkout'
const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
req, req,
res, res,
config, config,
@@ -48,7 +48,7 @@ export type CheckoutAPI = GetAPISchema<CommerceAPI, CheckoutSchema>
export type CheckoutEndpoint = CheckoutAPI['endpoint'] export type CheckoutEndpoint = CheckoutAPI['endpoint']
export const handlers: CheckoutEndpoint['handlers'] = { checkout } export const handlers: CheckoutEndpoint['handlers'] = { getCheckout }
const checkoutApi = createEndpoint<CheckoutAPI>({ const checkoutApi = createEndpoint<CheckoutAPI>({
handler: checkoutEndpoint, handler: checkoutEndpoint,

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -0,0 +1 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -0,0 +1,14 @@
import { SWRHook } from '@commerce/utils/types'
import useCheckout, { UseCheckout } from '@commerce/checkout/use-checkout'
export default useCheckout as UseCheckout<typeof handler>
export const handler: SWRHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ useData }) =>
async (input) => ({}),
}

View File

@@ -0,0 +1,15 @@
import useAddItem, { UseAddItem } from '@commerce/customer/address/use-add-item'
import { MutationHook } from '@commerce/utils/types'
export default useAddItem as UseAddItem<typeof handler>
export const handler: MutationHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ fetch }) =>
() =>
async () => ({}),
}

View File

@@ -0,0 +1,15 @@
import useAddItem, { UseAddItem } from '@commerce/customer/card/use-add-item'
import { MutationHook } from '@commerce/utils/types'
export default useAddItem as UseAddItem<typeof handler>
export const handler: MutationHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {},
useHook:
({ fetch }) =>
() =>
async () => ({}),
}

View File

@@ -41,11 +41,13 @@ export const fetcher: Fetcher = async ({
headers, headers,
credentials: 'include', credentials: 'include',
}) })
if (res.ok) { if (res.ok) {
const { data } = await res.json() const { data, errors } = await res.json()
if (errors) {
throw await new FetcherError({ status: res.status, errors })
}
return data return data
} }
throw await getError(res) throw await getError(res)
} }

View File

@@ -3,7 +3,6 @@ export const searchResultFragment = /* GraphQL */ `
productId productId
productName productName
description description
description
slug slug
sku sku
currencyCode currencyCode

View File

@@ -23,7 +23,7 @@ module.exports = withCommerceConfig({
}, },
rewrites() { rewrites() {
return [ return [
(isBC || isShopify || isSwell || isVendure) && { (isBC || isShopify || isSwell || isVendure || isSaleor) && {
source: '/checkout', source: '/checkout',
destination: '/api/checkout', destination: '/api/checkout',
}, },

View File

@@ -0,0 +1,4 @@
import customerAddressApi from '@framework/api/endpoints/customer/address'
import commerce from '@lib/api/commerce'
export default customerAddressApi(commerce)

View File

@@ -0,0 +1,4 @@
import customerCardApi from '@framework/api/endpoints/customer/card'
import commerce from '@lib/api/commerce'
export default customerCardApi(commerce)

View File

@@ -2,10 +2,12 @@
// import commerce from '@lib/api/commerce' // import commerce from '@lib/api/commerce'
// import { Heart } from '@components/icons' // import { Heart } from '@components/icons'
import { Layout } from '@components/common' import { Layout } from '@components/common'
import { Text, Container } from '@components/ui'
import { Text, Container, Skeleton } from '@components/ui'
// import { useCustomer } from '@framework/customer' // import { useCustomer } from '@framework/customer'
// import { WishlistCard } from '@components/wishlist' // import { WishlistCard } from '@components/wishlist'
// import useWishlist from '@framework/wishlist/use-wishlist' // import useWishlist from '@framework/wishlist/use-wishlist'
import rangeMap from '@lib/range-map'
// export async function getStaticProps({ // export async function getStaticProps({
// preview, // preview,
@@ -43,7 +45,15 @@ export default function Wishlist() {
<div className="mt-3 mb-20"> <div className="mt-3 mb-20">
<Text variant="pageHeading">My Wishlist</Text> <Text variant="pageHeading">My Wishlist</Text>
<div className="flex flex-col group"> <div className="flex flex-col group">
{/* {isLoading || isEmpty ? ( {/* {isLoading ? (
<div className="grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3">
{rangeMap(12, (i) => (
<Skeleton key={i}>
<div className="w-60 h-60" />
</Skeleton>
))}
</div>
) : isEmpty ? (
<div className="flex flex-col items-center justify-center flex-1 px-12 py-24 "> <div className="flex flex-col items-center justify-center flex-1 px-12 py-24 ">
<span className="flex items-center justify-center w-16 h-16 p-12 border border-dashed rounded-lg border-secondary bg-primary text-primary"> <span className="flex items-center justify-center w-16 h-16 p-12 border border-dashed rounded-lg border-secondary bg-primary text-primary">
<Heart className="absolute" /> <Heart className="absolute" />
@@ -56,12 +66,14 @@ export default function Wishlist() {
</p> </p>
</div> </div>
) : ( ) : (
data && <div className="grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3">
// @ts-ignore Shopify - Fix this types {data &&
data.items?.map((item) => ( // @ts-ignore Shopify - Fix this types
<WishlistCard key={item.id} product={item.product! as any} /> data.items?.map((item) => (
)) <WishlistCard key={item.id} product={item.product! as any} />
)} */} ))}
</div>
)}*/}
</div> </div>
</div> </div>
</Container> </Container>