1
0
mirror of https://github.com/vercel/commerce.git synced 2025-10-08 15:12:40 +00:00
Files
.vscode
assets
components
config
framework
bigcommerce
commerce
local
module-data
saleor
shopify
swell
api
auth
cart
customer
product
types
utils
wishlist
.env.template
commerce.config.json
const.ts
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
types.ts
vendure
lib
pages
pagesBAK
public
.editorconfig
.env.template
.gitignore
.prettierignore
.prettierrc
README.md
codegen.bigcommerce.json
codegen.json
commerce.config.json
global.d.ts
jsconfig.json
license.md
next-env.d.ts
next.config.js
package.json
postcss.config.js
swell-js.d.ts
tailwind.config.js
tsconfig.js
tsconfig.json
yarn.lock
commerce/framework/swell/index.tsx
2021-04-25 16:34:29 -05:00

48 lines
1.0 KiB
TypeScript

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 { 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 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()