mirror of
https://github.com/vercel/commerce.git
synced 2025-07-29 13:11:22 +00:00
Add ordercloud provider (#500)
* 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>
This commit is contained in:
52
framework/ordercloud/customer/card/use-update-item.tsx
Normal file
52
framework/ordercloud/customer/card/use-update-item.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
import type {
|
||||
HookFetcherContext,
|
||||
MutationHookContext,
|
||||
} from '@commerce/utils/types'
|
||||
import type { UpdateItemHook, Card } from '@commerce/types/customer/card'
|
||||
|
||||
import { useCallback } from 'react'
|
||||
|
||||
import { MutationHook } from '@commerce/utils/types'
|
||||
import useUpdateItem, {
|
||||
UseUpdateItem,
|
||||
} from '@commerce/customer/card/use-update-item'
|
||||
|
||||
import useCards from './use-cards'
|
||||
|
||||
export type UpdateItemActionInput<T = any> = T extends Card
|
||||
? Partial<UpdateItemHook['actionInput']>
|
||||
: UpdateItemHook['actionInput']
|
||||
|
||||
export default useUpdateItem as UseUpdateItem<any>
|
||||
|
||||
export const handler: MutationHook<any> = {
|
||||
fetchOptions: {
|
||||
url: '/api/customer/card',
|
||||
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 } = useCards()
|
||||
|
||||
return useCallback(
|
||||
async function updateItem(input) {
|
||||
const data = await fetch({ input })
|
||||
|
||||
await mutate([], false)
|
||||
|
||||
return data
|
||||
},
|
||||
[fetch, mutate]
|
||||
)
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user