update swell consts, cleanup cart types

This commit is contained in:
Greg Hoskin
2021-05-11 14:28:46 -05:00
parent 7786d6445d
commit 9675be1546
6 changed files with 15 additions and 23 deletions

View File

@@ -5,7 +5,6 @@ import useCart from './use-cart'
import { Cart, CartItemBody } from '../types'
import { checkoutToCart } from './utils'
import { getCheckoutId } from '../utils'
import { Mutation, MutationCheckoutLineItemsAddArgs } from '../schema'
import { useCallback } from 'react'
export default useAddItem as UseAddItem<typeof handler>
@@ -38,7 +37,7 @@ export const handler: MutationHook<Cart, {}, CartItemBody> = {
variables.variant_id = item.variantId
}
const response = await fetch<Mutation, MutationCheckoutLineItemsAddArgs>({
const response = await fetch({
...options,
variables,
})

View File

@@ -13,10 +13,8 @@ import useRemoveItem, {
} from '@commerce/cart/use-remove-item'
import useCart from './use-cart'
import { checkoutLineItemRemoveMutation, getCheckoutId } from '../utils'
import { checkoutToCart } from './utils'
import { Cart, LineItem } from '../types'
import { Mutation, MutationCheckoutLineItemsRemoveArgs } from '../schema'
import { RemoveCartItemBody } from '@commerce/types'
export type RemoveItemFn<T = any> = T extends LineItem
@@ -39,12 +37,10 @@ export const handler = {
options,
fetch,
}: HookFetcherContext<RemoveCartItemBody>) {
const response = await fetch<Mutation, MutationCheckoutLineItemsRemoveArgs>(
{
...options,
variables: [itemId],
}
)
const response = await fetch({
...options,
variables: [itemId],
})
return checkoutToCart(response)
},
useHook: ({
@@ -52,9 +48,9 @@ export const handler = {
}: MutationHookContext<Cart | null, RemoveCartItemBody>) => <
T extends LineItem | undefined = undefined
>(
item
ctx: { item?: T } = {}
) => {
// const { item } = ctx
const { item } = ctx
const { mutate } = useCart()
const removeItem: RemoveItemFn<LineItem> = async (input) => {
const itemId = input?.id ?? item?.id

View File

@@ -14,7 +14,6 @@ import useCart from './use-cart'
import { handler as removeItemHandler } from './use-remove-item'
import type { Cart, LineItem, UpdateCartItemBody } from '../types'
import { checkoutToCart } from './utils'
import { Mutation, MutationCheckoutLineItemsUpdateArgs } from '../schema'
export type UpdateItemInput<T = any> = T extends LineItem
? Partial<UpdateItemInputBase<LineItem>>
@@ -46,12 +45,10 @@ export const handler = {
message: 'The item quantity has to be a valid integer',
})
}
const response = await fetch<Mutation, MutationCheckoutLineItemsUpdateArgs>(
{
...options,
variables: [item.itemId, { quantity: item.quantity }],
}
)
const response = await fetch({
...options,
variables: [item.itemId, { quantity: item.quantity }],
})
return checkoutToCart(response)
},