build changes

This commit is contained in:
Belen Curcio
2020-10-02 12:59:50 -03:00
parent c5e5cbaa68
commit f536dab1a2
13 changed files with 63 additions and 97 deletions

View File

@@ -2,13 +2,20 @@ import {
CartProvider as CommerceCartProvider,
useCart as useCommerceCart,
} from 'lib/commerce/cart'
import { FunctionComponent } from 'react'
export type Cart = any
export function CartProvider({ children }) {
interface Props {
children?: any
}
function useCart() {
return useCommerceCart<Cart>()
}
const CartProvider: FunctionComponent<Props> = ({ children }) => {
return <CommerceCartProvider>{children}</CommerceCartProvider>
}
export function useCart() {
return useCommerceCart<Cart>()
}
export { CartProvider, useCart }

View File

@@ -3,6 +3,7 @@ import {
Connector,
useCommerce as useCoreCommerce,
} from 'lib/commerce'
import { ReactNode } from 'react'
async function getText(res: Response) {
try {
@@ -35,8 +36,12 @@ export const bigcommerce: Connector = {
fetcher,
}
interface Props {
children?: ReactNode | any
}
// TODO: The connector should be extendable when a developer is using it
export function CommerceProvider({ children }) {
export function CommerceProvider({ children }: Props) {
return (
<CoreCommerceProvider connector={bigcommerce}>
{children}

View File

@@ -1,6 +1,9 @@
import { createContext, useContext } from 'react'
import { createContext, useContext, FunctionComponent } from 'react'
import useSWR, { responseInterface } from 'swr'
import { useCommerce } from '.'
interface Props {
children?: any
}
export type Cart = any
@@ -8,14 +11,14 @@ export type CartResponse<C extends Cart> = responseInterface<C, Error> & {
isEmpty: boolean
}
const CartContext = createContext<CartResponse<Cart>>(null)
const CartContext = createContext<CartResponse<Cart> | any>(null)
function getCartCookie() {
// TODO: Figure how the cart should be persisted
return null
}
export function CartProvider({ children }) {
const CartProvider: FunctionComponent<Props> = ({ children }) => {
const { hooks, fetcher } = useCommerce<Cart>()
const { useCart } = hooks
const cartId = getCartCookie()
@@ -32,6 +35,8 @@ export function CartProvider({ children }) {
)
}
export function useCart<C extends Cart>() {
function useCart<C extends Cart>() {
return useContext(CartContext) as CartResponse<C>
}
export { CartProvider, useCart }

View File

@@ -1,9 +1,9 @@
import { createContext, ReactNode, useContext } from 'react'
const Commerce = createContext<Connector>(null)
const Commerce = createContext<Connector | any>(null)
export type CommerceProps = {
children?: ReactNode
children?: ReactNode | any
connector: Connector
}