mirror of
https://github.com/vercel/commerce.git
synced 2025-07-24 10:41:23 +00:00
Implements custom checkout along with ordercloud provider
This commit is contained in:
33
framework/ordercloud/checkout/use-get-checkout.tsx
Normal file
33
framework/ordercloud/checkout/use-get-checkout.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { GetCheckoutHook } from '@commerce/types/checkout'
|
||||
|
||||
import { useMemo } from 'react'
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useGetCheckout, { UseGetCheckout } from '@commerce/checkout/use-get-checkout'
|
||||
|
||||
export default useGetCheckout as UseGetCheckout<typeof handler>
|
||||
|
||||
export const handler: SWRHook<GetCheckoutHook> = {
|
||||
fetchOptions: {
|
||||
url: '/api/checkout',
|
||||
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?.lineItems?.length ?? 0) <= 0
|
||||
},
|
||||
enumerable: true,
|
||||
},
|
||||
}),
|
||||
[response]
|
||||
)
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user