Fix build errors

This commit is contained in:
cond0r
2021-05-13 16:10:09 +03:00
parent e7d0f56e85
commit bff94e73ae
22 changed files with 87 additions and 458 deletions

View File

@@ -1,27 +1,37 @@
import useCart, { UseCart } from '@commerce/cart/use-cart'
import { Cart } from '@commerce/types'
import { SWRHook } from '@commerce/utils/types'
import { useMemo } from 'react'
import { normalizeCart } from '../utils/normalize'
import { checkoutCreate, checkoutToCart } from './utils'
export default useCart as UseCart<typeof handler>
export const handler: SWRHook<Cart | null> = {
export const handler: SWRHook<Cart | null, {}, any, { isEmpty?: boolean }> = {
fetchOptions: {
query: 'cart',
method: 'get',
},
async fetcher({ options, fetch }) {
async fetcher({ fetch }) {
const cart = await checkoutCreate(fetch)
return cart ? normalizeCart(cart) : null
},
useHook: ({ useData }) => (input) => {
return useData({
swrOptions: {
revalidateOnFocus: false,
...input?.swrOptions,
},
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]
)
},
}

View File

@@ -47,7 +47,7 @@ export const handler = {
}
const response = await fetch({
...options,
variables: [item.itemId, { quantity: item.quantity }],
variables: [itemId, { quantity: item.quantity }],
})
return checkoutToCart(response)
@@ -79,7 +79,6 @@ export const handler = {
const data = await fetch({
input: {
item: {
itemId,
productId,
variantId,
quantity: input.quantity,

View File

@@ -1,5 +1,5 @@
import { Cart } from '../../types'
import { CommerceError, ValidationError } from '@commerce/utils/errors'
import { CommerceError } from '@commerce/utils/errors'
import {
CheckoutLineItemsAddPayload,
@@ -20,8 +20,7 @@ const checkoutToCart = (checkoutPayload?: Maybe<CheckoutPayload>): Cart => {
message: 'Invalid response from Swell',
})
}
return normalizeCart(checkoutPayload)
return normalizeCart(checkoutPayload as any)
}
export default checkoutToCart