mirror of
https://github.com/vercel/commerce.git
synced 2025-03-31 09:15: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>
36 lines
894 B
TypeScript
36 lines
894 B
TypeScript
import type { GetAddressesHook } from '@commerce/types/customer/address'
|
|
|
|
import { useMemo } from 'react'
|
|
import { SWRHook } from '@commerce/utils/types'
|
|
import useAddresses, {
|
|
UseAddresses,
|
|
} from '@commerce/customer/address/use-addresses'
|
|
|
|
export default useAddresses as UseAddresses<typeof handler>
|
|
|
|
export const handler: SWRHook<GetAddressesHook> = {
|
|
fetchOptions: {
|
|
url: '/api/customer/address',
|
|
method: 'GET',
|
|
},
|
|
useHook: ({ useData }) =>
|
|
function useHook(input) {
|
|
const response = useData({
|
|
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
|
|
})
|
|
|
|
return useMemo(
|
|
() =>
|
|
Object.create(response, {
|
|
isEmpty: {
|
|
get() {
|
|
return (response.data?.length ?? 0) <= 0
|
|
},
|
|
enumerable: true,
|
|
},
|
|
}),
|
|
[response]
|
|
)
|
|
},
|
|
}
|