fixes after upstream changes

This commit is contained in:
cond0r
2021-02-15 14:23:47 +02:00
parent af201cccdc
commit 1b9ae58d37
4 changed files with 87 additions and 118 deletions

View File

@@ -1,40 +1,4 @@
import type { HookFetcher } from '@commerce/utils/types'
import type { SwrOptions } from '@commerce/utils/use-data'
import useCommerceCustomer from '@commerce/use-customer'
import getCustomerQuery from '@framework/utils/queries/get-customer-query'
import { getCustomerToken } from '@framework/utils/customer-token'
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
import type { ShopifyProvider } from '..'
const defaultOpts = {
query: getCustomerQuery,
}
export const fetcher: HookFetcher<any | null> = async (options, _, fetch) => {
const customerAccessToken = getCustomerToken()
if (customerAccessToken) {
const data = await fetch<any | null>({
...defaultOpts,
...options,
variables: { customerAccessToken },
})
return data?.customer ?? null
}
return null
}
export function extendHook(
customFetcher: typeof fetcher,
swrOptions?: SwrOptions<any | null>
) {
const useCustomer = () => {
return useCommerceCustomer(defaultOpts, [], customFetcher, {
revalidateOnFocus: false,
...swrOptions,
})
}
useCustomer.extend = extendHook
return useCustomer
}
export default extendHook(fetcher)
export default useCustomer as UseCustomer<ShopifyProvider>