mirror of
https://github.com/vercel/commerce.git
synced 2025-03-28 08:15:54 +00:00
* Add ordercloud provider * Fix provider errors * Make submit checkout optional * Make submit checkout optional * Remove nullables when creating endpoint type * Update readme * Log checkout error * Log error * Save token to cookie * Update fetch rest * Use token at checkout Co-authored-by: Luis Alvarez <luis@vercel.com>
39 lines
943 B
TypeScript
39 lines
943 B
TypeScript
import type { AddItemHook } from '@commerce/types/customer/address'
|
|
import type { MutationHook } from '@commerce/utils/types'
|
|
|
|
import { useCallback } from 'react'
|
|
import useAddItem, { UseAddItem } from '@commerce/customer/address/use-add-item'
|
|
import useAddresses from './use-addresses'
|
|
|
|
export default useAddItem as UseAddItem<typeof handler>
|
|
|
|
export const handler: MutationHook<AddItemHook> = {
|
|
fetchOptions: {
|
|
url: '/api/customer/address',
|
|
method: 'POST',
|
|
},
|
|
async fetcher({ input: item, options, fetch }) {
|
|
const data = await fetch({
|
|
...options,
|
|
body: { item },
|
|
})
|
|
|
|
return data
|
|
},
|
|
useHook: ({ fetch }) =>
|
|
function useHook() {
|
|
const { mutate } = useAddresses()
|
|
|
|
return useCallback(
|
|
async function addItem(input) {
|
|
const data = await fetch({ input })
|
|
|
|
await mutate([data], false)
|
|
|
|
return data
|
|
},
|
|
[fetch, mutate]
|
|
)
|
|
},
|
|
}
|