mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
task: prettier
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
import { useMemo } from 'react'
|
||||
import useCommerceCart, {
|
||||
FetchCartInput,
|
||||
UseCart,
|
||||
} from '@commerce/cart/use-cart'
|
||||
import useCommerceCart, { FetchCartInput, UseCart } from '@commerce/cart/use-cart'
|
||||
|
||||
import { Cart } from '../types'
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
@@ -11,12 +8,7 @@ import * as query from '../utils/queries'
|
||||
|
||||
export default useCommerceCart as UseCart<typeof handler>
|
||||
|
||||
export const handler: SWRHook<
|
||||
Cart | null,
|
||||
{},
|
||||
FetchCartInput,
|
||||
{ isEmpty?: boolean }
|
||||
> = {
|
||||
export const handler: SWRHook<Cart | null, {}, FetchCartInput, { isEmpty?: boolean }> = {
|
||||
fetchOptions: {
|
||||
query: query.CheckoutOne,
|
||||
},
|
||||
@@ -24,36 +16,38 @@ export const handler: SWRHook<
|
||||
let checkout
|
||||
|
||||
if (checkoutId) {
|
||||
const checkoutId = getCheckoutId().checkoutToken;
|
||||
const checkoutId = getCheckoutId().checkoutToken
|
||||
const data = await fetch({
|
||||
...options,
|
||||
variables: { checkoutId },
|
||||
})
|
||||
|
||||
checkout = data;
|
||||
checkout = data
|
||||
}
|
||||
|
||||
if (checkout?.completedAt || !checkoutId) {
|
||||
checkout = await checkoutCreate(fetch)
|
||||
}
|
||||
|
||||
return checkoutToCart(checkout);
|
||||
return checkoutToCart(checkout)
|
||||
},
|
||||
useHook: ({ useData }) => (input) => {
|
||||
const response = useData({
|
||||
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
|
||||
})
|
||||
return useMemo(
|
||||
() =>
|
||||
Object.create(response, {
|
||||
isEmpty: {
|
||||
get() {
|
||||
return (response.data?.lineItems.length ?? 0) <= 0
|
||||
useHook:
|
||||
({ useData }) =>
|
||||
(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,
|
||||
},
|
||||
enumerable: true,
|
||||
},
|
||||
}),
|
||||
[response]
|
||||
)
|
||||
},
|
||||
}),
|
||||
[response]
|
||||
)
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user