mirror of
https://github.com/vercel/commerce.git
synced 2025-07-25 19:21:23 +00:00
Fix provider errors
This commit is contained in:
@@ -2,20 +2,22 @@ import type {
|
||||
MutationHookContext,
|
||||
HookFetcherContext,
|
||||
} from '@commerce/utils/types'
|
||||
import type { Cart, LineItem, RemoveItemHook } from '@commerce/types/customer/card'
|
||||
import type { Card, RemoveItemHook } from '@commerce/types/customer/card'
|
||||
|
||||
import { useCallback } from 'react'
|
||||
|
||||
import { ValidationError } from '@commerce/utils/errors'
|
||||
import useRemoveItem, { UseRemoveItem } from '@commerce/customer/card/use-remove-item'
|
||||
import useRemoveItem, {
|
||||
UseRemoveItem,
|
||||
} from '@commerce/customer/card/use-remove-item'
|
||||
|
||||
import useCards from './use-cards'
|
||||
|
||||
export type RemoveItemFn<T = any> = T extends LineItem
|
||||
? (input?: RemoveItemActionInput<T>) => Promise<Cart | null | undefined>
|
||||
: (input: RemoveItemActionInput<T>) => Promise<Cart | null>
|
||||
export type RemoveItemFn<T = any> = T extends Card
|
||||
? (input?: RemoveItemActionInput<T>) => Promise<Card | null | undefined>
|
||||
: (input: RemoveItemActionInput<T>) => Promise<Card | null>
|
||||
|
||||
export type RemoveItemActionInput<T = any> = T extends LineItem
|
||||
export type RemoveItemActionInput<T = any> = T extends Card
|
||||
? Partial<RemoveItemHook['actionInput']>
|
||||
: RemoveItemHook['actionInput']
|
||||
|
||||
@@ -34,12 +36,12 @@ export const handler = {
|
||||
return await fetch({ ...options, body: { itemId } })
|
||||
},
|
||||
useHook: ({ fetch }: MutationHookContext<RemoveItemHook>) =>
|
||||
function useHook<T extends LineItem | undefined = undefined>(
|
||||
function useHook<T extends Card | undefined = undefined>(
|
||||
ctx: { item?: T } = {}
|
||||
) {
|
||||
const { item } = ctx
|
||||
const { mutate } = useCards()
|
||||
const removeItem: RemoveItemFn<LineItem> = async (input) => {
|
||||
const removeItem: RemoveItemFn<Card> = async (input) => {
|
||||
const itemId = input?.id ?? item?.id
|
||||
|
||||
if (!itemId) {
|
||||
@@ -50,7 +52,7 @@ export const handler = {
|
||||
|
||||
const data = await fetch({ input: { itemId } })
|
||||
|
||||
await mutate(data, false)
|
||||
await mutate([], false)
|
||||
|
||||
return data
|
||||
}
|
||||
|
Reference in New Issue
Block a user