mirror of
https://github.com/vercel/commerce.git
synced 2025-03-15 06:52:32 +00:00
Updated defaults in all hooks
This commit is contained in:
parent
d98897a7e3
commit
2804627aef
@ -26,8 +26,8 @@ export const fetcher: HookFetcher<Cart, AddItemBody> = (
|
||||
}
|
||||
|
||||
return fetch({
|
||||
url: options?.url ?? defaultOpts.url,
|
||||
method: options?.method ?? defaultOpts.method,
|
||||
...defaultOpts,
|
||||
...options,
|
||||
body: { item },
|
||||
})
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import type { Cart } from '../api/cart'
|
||||
|
||||
const defaultOpts = {
|
||||
url: '/api/bigcommerce/cart',
|
||||
method: 'GET',
|
||||
}
|
||||
|
||||
export type { Cart }
|
||||
@ -14,7 +15,7 @@ export const fetcher: HookFetcher<Cart | null, CartInput> = (
|
||||
{ cartId },
|
||||
fetch
|
||||
) => {
|
||||
return cartId ? fetch({ ...options }) : null
|
||||
return cartId ? fetch({ ...defaultOpts, ...options }) : null
|
||||
}
|
||||
|
||||
export function extendHook(
|
||||
|
@ -19,8 +19,8 @@ export const fetcher: HookFetcher<Cart | null, RemoveItemBody> = (
|
||||
fetch
|
||||
) => {
|
||||
return fetch({
|
||||
url: options?.url ?? defaultOpts.url,
|
||||
method: options?.method ?? defaultOpts.method,
|
||||
...defaultOpts,
|
||||
...options,
|
||||
body: { itemId },
|
||||
})
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ export const fetcher: HookFetcher<Cart | null, UpdateItemBody> = (
|
||||
}
|
||||
|
||||
return fetch({
|
||||
url: options?.url ?? defaultOpts.url,
|
||||
method: options?.method ?? defaultOpts.method,
|
||||
...defaultOpts,
|
||||
...options,
|
||||
body: { itemId, item },
|
||||
})
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import type { Customer, CustomerData } from './api/customers'
|
||||
|
||||
const defaultOpts = {
|
||||
url: '/api/bigcommerce/customer',
|
||||
method: 'GET',
|
||||
}
|
||||
|
||||
export type { Customer }
|
||||
@ -14,7 +15,7 @@ export const fetcher: HookFetcher<CustomerData | null, CustomerInput> = (
|
||||
{ cartId },
|
||||
fetch
|
||||
) => {
|
||||
return cartId ? fetch({ ...options }) : null
|
||||
return cartId ? fetch({ ...defaultOpts, ...options }) : null
|
||||
}
|
||||
|
||||
export function extendHook(
|
||||
|
@ -22,8 +22,8 @@ export const fetcher: HookFetcher<null, LoginBody> = (
|
||||
}
|
||||
|
||||
return fetch({
|
||||
url: options?.url ?? defaultOpts.url,
|
||||
method: options?.method ?? defaultOpts.method,
|
||||
...defaultOpts,
|
||||
...options,
|
||||
body: { email, password },
|
||||
})
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ export const fetcher: HookFetcher<null, SignupBody> = (
|
||||
}
|
||||
|
||||
return fetch({
|
||||
url: options?.url ?? defaultOpts.url,
|
||||
method: options?.method ?? defaultOpts.method,
|
||||
...defaultOpts,
|
||||
...options,
|
||||
body: { firstName, lastName, email, password },
|
||||
})
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ export const fetcher: HookFetcher<Wishlist, AddItemBody> = (
|
||||
fetch
|
||||
) => {
|
||||
return fetch({
|
||||
url: options?.url ?? defaultOpts.url,
|
||||
method: options?.method ?? defaultOpts.method,
|
||||
...defaultOpts,
|
||||
...options,
|
||||
body: { wishlistId, item },
|
||||
})
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ export const fetcher: HookFetcher<Wishlist | null, RemoveItemBody> = (
|
||||
fetch
|
||||
) => {
|
||||
return fetch({
|
||||
url: options?.url ?? defaultOpts.url,
|
||||
method: options?.method ?? defaultOpts.method,
|
||||
...defaultOpts,
|
||||
...options,
|
||||
body: { wishlistId, itemId },
|
||||
})
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import type { Wishlist } from '../api/wishlist'
|
||||
|
||||
const defaultOpts = {
|
||||
url: '/api/bigcommerce/wishlists',
|
||||
method: 'GET',
|
||||
}
|
||||
|
||||
export type { Wishlist }
|
||||
@ -18,7 +19,8 @@ export const fetcher: HookFetcher<Wishlist | null, WishlistInput> = (
|
||||
fetch
|
||||
) => {
|
||||
return fetch({
|
||||
url: options?.url,
|
||||
...defaultOpts,
|
||||
...options,
|
||||
body: { wishlistId },
|
||||
})
|
||||
}
|
||||
|
@ -9,9 +9,14 @@ export default function useData<T, Input = any>(
|
||||
swrOptions?: ConfigInterface<T>
|
||||
) {
|
||||
const { fetcherRef } = useCommerce()
|
||||
const fetcher = (url?: string, query?: string, ...args: any[]) => {
|
||||
const fetcher = (
|
||||
url?: string,
|
||||
query?: string,
|
||||
method?: string,
|
||||
...args: any[]
|
||||
) => {
|
||||
return fetcherFn(
|
||||
{ url, query },
|
||||
{ url, query, method },
|
||||
// Transform the input array into an object
|
||||
args.reduce((obj, val, i) => {
|
||||
obj[input[i][0]!] = val
|
||||
@ -24,7 +29,9 @@ export default function useData<T, Input = any>(
|
||||
const response = useSWR(
|
||||
() => {
|
||||
const opts = typeof options === 'function' ? options() : options
|
||||
return opts ? [opts.url, opts.query, ...input.map((e) => e[1])] : null
|
||||
return opts
|
||||
? [opts.url, opts.query, opts.method, ...input.map((e) => e[1])]
|
||||
: null
|
||||
},
|
||||
fetcher,
|
||||
swrOptions
|
||||
|
Loading…
x
Reference in New Issue
Block a user