From b5ee7feb46617c6273f9c39511f8227d8f6e6e37 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Fri, 9 Oct 2020 11:17:54 -0500 Subject: [PATCH] Fixed commerce config types --- lib/bigcommerce/cart/use-update-item.tsx | 8 ++++---- lib/commerce/index.tsx | 13 +++++++++---- lib/commerce/utils/types.ts | 5 ----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/bigcommerce/cart/use-update-item.tsx b/lib/bigcommerce/cart/use-update-item.tsx index bf739dfda..7c153b18b 100644 --- a/lib/bigcommerce/cart/use-update-item.tsx +++ b/lib/bigcommerce/cart/use-update-item.tsx @@ -6,7 +6,7 @@ import type { ItemBody, UpdateItemBody } from '../api/cart' import { fetcher as removeFetcher } from './use-remove-item' import { Cart, useCart } from '.' -const defualtOpts = { +const defaultOpts = { url: '/api/bigcommerce/cart', method: 'PUT', } @@ -28,8 +28,8 @@ export const fetcher: HookFetcher = ( } return fetch({ - url: options?.url ?? defualtOpts.url, - method: options?.method ?? defualtOpts.method, + url: options?.url ?? defaultOpts.url, + method: options?.method ?? defaultOpts.method, body: { itemId, item }, }) } @@ -38,7 +38,7 @@ function extend(customFetcher: typeof fetcher, cfg?: { wait?: number }) { const useUpdateItem = (item?: any) => { const { mutate } = useCart() const fn = useCartUpdateItem( - defualtOpts, + defaultOpts, customFetcher ) diff --git a/lib/commerce/index.tsx b/lib/commerce/index.tsx index 7d0fefbde..adb0fc37a 100644 --- a/lib/commerce/index.tsx +++ b/lib/commerce/index.tsx @@ -8,14 +8,19 @@ import { } from 'react' import { Fetcher } from './utils/types' -const Commerce = createContext(null) +const Commerce = createContext(null) export type CommerceProps = { children?: ReactNode - config: { fetcher: Fetcher } & CommerceConfig + config: CommerceConfig } -export type CommerceConfig = { +export type CommerceConfig = { fetcher: Fetcher } & Omit< + CommerceContextValue, + 'fetcherRef' +> + +export type CommerceContextValue = { fetcherRef: MutableRefObject locale: string cartCookie: string @@ -41,6 +46,6 @@ export function CommerceProvider({ children, config }: CommerceProps) { return {children} } -export function useCommerce() { +export function useCommerce() { return useContext(Commerce) as T } diff --git a/lib/commerce/utils/types.ts b/lib/commerce/utils/types.ts index aded044a6..0c1269ad8 100644 --- a/lib/commerce/utils/types.ts +++ b/lib/commerce/utils/types.ts @@ -15,11 +15,6 @@ export type HookFetcher = ( fetch: Fetcher ) => T | Promise -// export type HookFetcher = ( -// options: FetcherOptions, -// fetch: Fetcher -// ) => T | Promise - export type HookFetcherOptions = { query?: string url?: string