task: prettier

This commit is contained in:
Zaiste
2021-05-18 14:20:07 +02:00
parent bf68f6aff7
commit 4a652a9b6a
56 changed files with 635 additions and 1480 deletions

View File

@@ -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]
)
},
}