forked from crowetic/commerce
Fixed commerce config types
This commit is contained in:
parent
eb3f29fa95
commit
b5ee7feb46
@ -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<Cart | null, UpdateItemBody> = (
|
||||
}
|
||||
|
||||
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<Cart | null, UpdateItemBody>(
|
||||
defualtOpts,
|
||||
defaultOpts,
|
||||
customFetcher
|
||||
)
|
||||
|
||||
|
@ -8,14 +8,19 @@ import {
|
||||
} from 'react'
|
||||
import { Fetcher } from './utils/types'
|
||||
|
||||
const Commerce = createContext<CommerceConfig | null>(null)
|
||||
const Commerce = createContext<CommerceContextValue | null>(null)
|
||||
|
||||
export type CommerceProps = {
|
||||
children?: ReactNode
|
||||
config: { fetcher: Fetcher<any> } & CommerceConfig
|
||||
config: CommerceConfig
|
||||
}
|
||||
|
||||
export type CommerceConfig = {
|
||||
export type CommerceConfig = { fetcher: Fetcher<any> } & Omit<
|
||||
CommerceContextValue,
|
||||
'fetcherRef'
|
||||
>
|
||||
|
||||
export type CommerceContextValue = {
|
||||
fetcherRef: MutableRefObject<any>
|
||||
locale: string
|
||||
cartCookie: string
|
||||
@ -41,6 +46,6 @@ export function CommerceProvider({ children, config }: CommerceProps) {
|
||||
return <Commerce.Provider value={cfg}>{children}</Commerce.Provider>
|
||||
}
|
||||
|
||||
export function useCommerce<T extends CommerceConfig>() {
|
||||
export function useCommerce<T extends CommerceContextValue>() {
|
||||
return useContext(Commerce) as T
|
||||
}
|
||||
|
@ -15,11 +15,6 @@ export type HookFetcher<T, Input> = (
|
||||
fetch: Fetcher<T>
|
||||
) => T | Promise<T>
|
||||
|
||||
// export type HookFetcher<T> = (
|
||||
// options: FetcherOptions,
|
||||
// fetch: Fetcher<T>
|
||||
// ) => T | Promise<T>
|
||||
|
||||
export type HookFetcherOptions = {
|
||||
query?: string
|
||||
url?: string
|
||||
|
Loading…
x
Reference in New Issue
Block a user