mirror of
https://github.com/vercel/commerce.git
synced 2025-08-22 16:51:22 +00:00
.vscode
framework
bigcommerce
commercejs
kibocommerce
ordercloud
api
auth
cart
checkout
index.ts
use-checkout.tsx
use-submit-checkout.tsx
customer
product
types
utils
wishlist
.env.template
README.md
commerce.config.json
constants.ts
fetcher.ts
index.tsx
next.config.js
provider.ts
saleor
shopify
spree
swell
vendure
packages
site
.editorconfig
.eslintrc
.gitignore
.prettierignore
.prettierrc
README.md
license.md
package-copy.json
package-lock.json
package.json
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import type { GetCheckoutHook } from '@commerce/types/checkout'
|
|
|
|
import { useMemo } from 'react'
|
|
import { SWRHook } from '@commerce/utils/types'
|
|
import useCheckout, { UseCheckout } from '@commerce/checkout/use-checkout'
|
|
import useSubmitCheckout from './use-submit-checkout'
|
|
|
|
export default useCheckout as UseCheckout<typeof handler>
|
|
|
|
export const handler: SWRHook<GetCheckoutHook> = {
|
|
fetchOptions: {
|
|
url: '/api/checkout',
|
|
method: 'GET',
|
|
},
|
|
useHook: ({ useData }) =>
|
|
function useHook(input) {
|
|
const submit = useSubmitCheckout()
|
|
const response = useData({
|
|
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
|
|
})
|
|
|
|
return useMemo(
|
|
() =>
|
|
Object.create(response, {
|
|
isEmpty: {
|
|
get() {
|
|
return (response.data?.lineItems?.length ?? 0) <= 0
|
|
},
|
|
enumerable: true,
|
|
},
|
|
submit: {
|
|
get() {
|
|
return submit
|
|
},
|
|
enumerable: true,
|
|
},
|
|
}),
|
|
[response, submit]
|
|
)
|
|
},
|
|
}
|