4
0
forked from crowetic/commerce

Type changes

This commit is contained in:
Luis Alvarez
2020-10-07 15:27:22 -05:00
parent fe66a8d746
commit e874f43abc
5 changed files with 17 additions and 17 deletions

View File

@@ -1,9 +1,11 @@
import type { Fetcher } from '@lib/commerce'
import { default as useCartRemoveItem } from '@lib/commerce/cart/use-remove-item'
import type { ItemBody, RemoveItemBody } from '../api/cart'
import type { RemoveItemBody } from '../api/cart'
import { Cart, useCart } from '.'
export type { ItemBody, RemoveItemBody }
export type RemoveItemInput = {
id: string
}
export function fetcher(
fetch: Fetcher<Cart | null>,
@@ -16,11 +18,11 @@ export function fetcher(
})
}
export default function useRemoveItem() {
export default function useRemoveItem(item?: any) {
const { mutate } = useCart()
const fn = useCartRemoveItem<Cart | null, RemoveItemBody>(fetcher)
const removeItem: typeof fn = async (input) => {
const data = await fn(input)
const removeItem = async (input: RemoveItemInput) => {
const data = await fn({ itemId: input.id ?? item?.id })
await mutate(data, false)
return data
}