diff --git a/framework/bigcommerce/cart/use-add-item.tsx b/framework/bigcommerce/cart/use-add-item.tsx index d74c23567..525fa98a3 100644 --- a/framework/bigcommerce/cart/use-add-item.tsx +++ b/framework/bigcommerce/cart/use-add-item.tsx @@ -3,17 +3,13 @@ import type { MutationHook } from '@commerce/utils/types' import { CommerceError } from '@commerce/utils/errors' import useAddItem, { UseAddItem } from '@commerce/cart/use-add-item' import { normalizeCart } from '../lib/normalize' -import type { - Cart, - BigcommerceCart, - CartItemBody, - AddCartItemBody, -} from '../types' +import type { BigcommerceCart, AddItemHook } from '../types/cart' import useCart from './use-cart' export default useAddItem as UseAddItem -export const handler: MutationHook = { +// export const handler: MutationHook = { +export const handler: MutationHook = { fetchOptions: { url: '/api/bigcommerce/cart', method: 'POST', @@ -28,7 +24,7 @@ export const handler: MutationHook = { }) } - const data = await fetch({ + const data = await fetch({ ...options, body: { item }, }) diff --git a/framework/bigcommerce/types/cart.ts b/framework/bigcommerce/types/cart.ts index da2f13da9..d73c5b7e4 100644 --- a/framework/bigcommerce/types/cart.ts +++ b/framework/bigcommerce/types/cart.ts @@ -45,7 +45,13 @@ export type CartItemBody = Core.CartItemBody & { export type CartHooks = Core.CartHooks & { getCart: { data: Cart | null } - addItem: { data: Cart; body: { item: CartItemBody } } + addItem: { + data: Cart + body: { item: CartItemBody } + input: CartItemBody + fetchInput: CartItemBody + actionInput: CartItemBody + } updateItem: { data: Cart; body: { item: CartItemBody } } removeItem: { data: Cart | null } } diff --git a/framework/commerce/cart/use-add-item.tsx b/framework/commerce/cart/use-add-item.tsx index 072e68674..ab95979fc 100644 --- a/framework/commerce/cart/use-add-item.tsx +++ b/framework/commerce/cart/use-add-item.tsx @@ -5,7 +5,7 @@ import type { AddItemHook } from '../types/cart' import type { Provider } from '..' export type UseAddItem< - H extends MutationHook = MutationHook + H extends MutationHook = MutationHook > = ReturnType export const fetcher: HookFetcherFn = mutationFetcher diff --git a/framework/commerce/types/cart.ts b/framework/commerce/types/cart.ts index 91cd3819c..24f649b1a 100644 --- a/framework/commerce/types/cart.ts +++ b/framework/commerce/types/cart.ts @@ -103,7 +103,8 @@ export type AddItemHook = { data: Cart body: { item: CartItemBody } input: CartItemBody - fetchInput: { item: CartItemBody } + fetchInput: CartItemBody + actionInput: CartItemBody } export type UpdateItemHook = { diff --git a/framework/commerce/utils/types.ts b/framework/commerce/utils/types.ts index 865f7279d..9f9f8fd8a 100644 --- a/framework/commerce/utils/types.ts +++ b/framework/commerce/utils/types.ts @@ -39,7 +39,7 @@ export type HookFetcher = ( export type HookFetcherFn< H extends HookSchemaBase, Result = any, - Body = any + Body = H['body'] > = ( context: HookFetcherContext ) => H['data'] | Promise @@ -77,6 +77,8 @@ export type HookSchemaBase = { input: {} // Input expected before doing a fetch operation fetchInput?: {} + // Data expected by the fetch operation + body?: {} } export type SWRHookSchemaBase = HookSchemaBase & { @@ -123,7 +125,7 @@ export type MutationHook = { HookFunction> > fetchOptions: HookFetcherOptions - fetcher?: HookFetcherFn + fetcher?: HookFetcherFn } export type MutationHookContext = {