Type fixes

This commit is contained in:
Luis Alvarez 2020-10-11 02:04:26 -05:00
parent f1b9ea605e
commit 6595b3de96
6 changed files with 22 additions and 8 deletions

View File

@ -35,6 +35,11 @@ export type Cart = {
base_amount: number
discount_amount: number
cart_amount: number
redirect_urls: {
cart_url: string
checkout_url: string
embedded_checkout_url: string
}
line_items: {
custom_items: any[]
digital_items: any[]

View File

@ -5,8 +5,16 @@ import createApiHandler, {
import isAllowedMethod from './utils/is-allowed-method'
import { BigcommerceApiError } from './utils/errors'
type Body<T> = Partial<T> | undefined
export type Customer = any
export type AddCustomerBody = { item: any }
export type CartHandlers = {
addItem: BigcommerceHandler<Customer, { cartId?: string } & Body<any>>
}
const METHODS = ['POST']
const customersApi: BigcommerceApiHandler<Customer> = async (

View File

@ -1,5 +1,5 @@
import { useCallback } from 'react'
import { HookFetcher, HookFetcherOptions } from '../utils/types'
import type { HookFetcher, HookFetcherOptions } from '../utils/types'
import { useCommerce } from '..'
export default function useAddItem<T, Input>(

View File

@ -1,4 +1,4 @@
import type { Fetcher } from '..'
import type { HookFetcher, HookFetcherOptions } from '../utils/types'
import useAddItem from './use-add-item'
import useRemoveItem from './use-remove-item'
import useUpdateItem from './use-update-item'
@ -6,11 +6,12 @@ import useUpdateItem from './use-update-item'
// This hook is probably not going to be used, but it's here
// to show how a commerce should be structuring it
export default function useCartActions<T, Input>(
fetcher: (fetch: Fetcher<T>, input: Input) => T | Promise<T>
options: HookFetcherOptions,
fetcher: HookFetcher<T, Input>
) {
const addItem = useAddItem<T, Input>(fetcher)
const updateItem = useUpdateItem<T, Input>(fetcher)
const removeItem = useRemoveItem<T, Input>(fetcher)
const addItem = useAddItem<T, Input>(options, fetcher)
const updateItem = useUpdateItem<T, Input>(options, fetcher)
const removeItem = useRemoveItem<T, Input>(options, fetcher)
return { addItem, updateItem, removeItem }
}

View File

@ -1,5 +1,5 @@
import { useCallback } from 'react'
import { HookFetcher, HookFetcherOptions } from '../utils/types'
import type { HookFetcher, HookFetcherOptions } from '../utils/types'
import { useCommerce } from '..'
export default function useRemoveItem<T, Input>(

View File

@ -1,5 +1,5 @@
import { useCallback } from 'react'
import { HookFetcher, HookFetcherOptions } from '../utils/types'
import type { HookFetcher, HookFetcherOptions } from '../utils/types'
import { useCommerce } from '..'
export default function useUpdateItem<T, Input>(