mirror of
https://github.com/vercel/commerce.git
synced 2025-03-28 16:25:53 +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>
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import type {
|
|
HookFetcherContext,
|
|
MutationHookContext,
|
|
} from '@commerce/utils/types'
|
|
import type { UpdateItemHook, Address } from '@commerce/types/customer/address'
|
|
|
|
import { useCallback } from 'react'
|
|
|
|
import { MutationHook } from '@commerce/utils/types'
|
|
import useUpdateItem, {
|
|
UseUpdateItem,
|
|
} from '@commerce/customer/address/use-update-item'
|
|
|
|
import useAddresses from './use-addresses'
|
|
|
|
export type UpdateItemActionInput<T = any> = T extends Address
|
|
? Partial<UpdateItemHook['actionInput']>
|
|
: UpdateItemHook['actionInput']
|
|
|
|
export default useUpdateItem as UseUpdateItem<any>
|
|
|
|
export const handler: MutationHook<any> = {
|
|
fetchOptions: {
|
|
url: '/api/customer/address',
|
|
method: 'PUT',
|
|
},
|
|
async fetcher({
|
|
input: { itemId, item },
|
|
options,
|
|
fetch,
|
|
}: HookFetcherContext<UpdateItemHook>) {
|
|
return await fetch({
|
|
...options,
|
|
body: { itemId, item },
|
|
})
|
|
},
|
|
useHook: ({ fetch }: MutationHookContext<UpdateItemHook>) =>
|
|
function useHook() {
|
|
const { mutate } = useAddresses()
|
|
|
|
return useCallback(
|
|
async function updateItem(input) {
|
|
const data = await fetch({ input })
|
|
|
|
await mutate([], false)
|
|
|
|
return data
|
|
},
|
|
[fetch, mutate]
|
|
)
|
|
},
|
|
}
|