This commit is contained in:
cond0r
2021-02-08 09:15:20 +02:00
parent 1384a88440
commit 0dad4ddedb
14 changed files with 75 additions and 95 deletions

View File

@@ -1,5 +1,4 @@
import { useCallback } from 'react'
import { CommerceError } from '@commerce/utils/errors'
import useCart from './use-cart'
import useCartAddItem, {
AddItemInput as UseAddItemInput,
@@ -47,7 +46,7 @@ export function extendHook(customFetcher: typeof fetcher) {
quantity: input.quantity ?? 1,
},
],
checkoutId: getCheckoutId(cart?.id),
checkoutId: getCheckoutId(cart?.id)!,
})
await mutate(data, false)
return data

View File

@@ -44,7 +44,7 @@ export function extendHook(
) {
const useCart = () => {
const response = useCommerceCart(defaultOpts, [], customFetcher, {
revalidateOnFocus: false,
revalidateOnFocus: true,
...swrOptions,
})
const res = useResponse(response, {

View File

@@ -1,7 +1,7 @@
import {
SHOPIFY_CHECKOUT_ID_COOKIE,
SHOPIFY_CHECKOUT_URL_COOKIE,
} from '@framework/const'
} from '@framework/config'
import checkoutCreateMutation from '@framework/utils/mutations/checkout-create'
import Cookies from 'js-cookie'

View File

@@ -7,13 +7,8 @@ const checkoutToCart = (checkoutResponse?: {
checkout: Checkout
userErrors?: UserError[]
}): Maybe<Cart> => {
if (!checkoutResponse) {
throw new CommerceError({
message: 'Missing checkout details from response cart Response',
})
}
const { checkout, userErrors } = checkoutResponse
const checkout = checkoutResponse?.checkout
const userErrors = checkoutResponse?.userErrors
if (userErrors && userErrors.length) {
throw new ValidationError({
@@ -22,7 +17,7 @@ const checkoutToCart = (checkoutResponse?: {
}
if (!checkout) {
throw new ValidationError({
throw new CommerceError({
message: 'Missing checkout details from response cart Response',
})
}