Updated swell

This commit is contained in:
Luis Alvarez 2021-08-27 14:53:02 -05:00
parent 047da49e76
commit 32bb9ce381
3 changed files with 14 additions and 48 deletions

View File

@ -4,8 +4,6 @@ export const SWELL_CHECKOUT_URL_COOKIE = 'swell_checkoutUrl'
export const SWELL_CUSTOMER_TOKEN_COOKIE = 'swell_customerToken'
export const STORE_DOMAIN = process.env.NEXT_PUBLIC_SWELL_STORE_DOMAIN
export const SWELL_COOKIE_EXPIRE = 30
export const SWELL_STORE_ID = process.env.NEXT_PUBLIC_SWELL_STORE_ID

View File

@ -1,47 +1,9 @@
import * as React from 'react'
import swell from 'swell-js'
import { ReactNode } from 'react'
import {
CommerceConfig,
CommerceProvider as CoreCommerceProvider,
useCommerce as useCoreCommerce,
} from '@commerce'
import { getCommerceProvider, useCommerce as useCoreCommerce } from '@commerce'
import { swellProvider, SwellProvider } from './provider'
import {
SWELL_CHECKOUT_ID_COOKIE,
SWELL_STORE_ID,
SWELL_PUBLIC_KEY,
} from './const'
swell.init(SWELL_STORE_ID, SWELL_PUBLIC_KEY)
export { swellProvider }
export type { SwellProvider }
export const swellConfig: any = {
locale: 'en-us',
cartCookie: SWELL_CHECKOUT_ID_COOKIE,
swell,
}
export const CommerceProvider = getCommerceProvider(swellProvider)
export type SwellConfig = Partial<CommerceConfig>
export type SwellProps = {
children?: ReactNode
locale: string
} & SwellConfig
export function CommerceProvider({ children, ...config }: SwellProps) {
return (
<CoreCommerceProvider
// TODO: Fix this type
provider={swellProvider as any}
config={{ ...swellConfig, ...config }}
>
{children}
</CoreCommerceProvider>
)
}
export const useCommerce = () => useCoreCommerce()
export const useCommerce = () => useCoreCommerce<SwellProvider>()

View File

@ -1,6 +1,10 @@
import swell from 'swell-js'
import { Provider } from '@commerce'
import { SWELL_CHECKOUT_URL_COOKIE, STORE_DOMAIN } from './const'
import {
SWELL_CHECKOUT_ID_COOKIE,
SWELL_STORE_ID,
SWELL_PUBLIC_KEY,
} from './const'
import { handler as useCart } from './cart/use-cart'
import { handler as useAddItem } from './cart/use-add-item'
@ -16,10 +20,12 @@ import { handler as useSignup } from './auth/use-signup'
import fetcher from './fetcher'
export const swellProvider: Provider = {
swell.init(SWELL_STORE_ID, SWELL_PUBLIC_KEY)
export const swellProvider: Provider & { swell: any } = {
locale: 'en-us',
cartCookie: SWELL_CHECKOUT_URL_COOKIE,
// storeDomain: STORE_DOMAIN,
cartCookie: SWELL_CHECKOUT_ID_COOKIE,
swell,
fetcher,
cart: { useCart, useAddItem, useUpdateItem, useRemoveItem },
customer: { useCustomer },