diff --git a/framework/bigcommerce/customer/use-customer.tsx b/framework/bigcommerce/customer/use-customer.tsx index 093007824..238b1229b 100644 --- a/framework/bigcommerce/customer/use-customer.tsx +++ b/framework/bigcommerce/customer/use-customer.tsx @@ -1,16 +1,16 @@ import { SWRHook } from '@commerce/utils/types' import useCustomer, { UseCustomer } from '@commerce/customer/use-customer' -import type { Customer, CustomerData } from '../api/customers' +import type { CustomerHook } from '../types/customer' export default useCustomer as UseCustomer -export const handler: SWRHook = { +export const handler: SWRHook = { fetchOptions: { - url: '/api/bigcommerce/customers', + url: '/api/customer', method: 'GET', }, async fetcher({ options, fetch }) { - const data = await fetch(options) + const data = await fetch(options) return data?.customer ?? null }, useHook: ({ useData }) => (input) => { diff --git a/framework/commerce/customer/use-customer.tsx b/framework/commerce/customer/use-customer.tsx index 5d6416a4b..bbeeb3269 100644 --- a/framework/commerce/customer/use-customer.tsx +++ b/framework/commerce/customer/use-customer.tsx @@ -1,14 +1,14 @@ import { useHook, useSWRHook } from '../utils/use-hook' import { SWRFetcher } from '../utils/default-fetcher' +import type { CustomerHook } from '../types/customer' import type { HookFetcherFn, SWRHook } from '../utils/types' -import type { Customer } from '../types' -import { Provider } from '..' +import type { Provider } from '..' export type UseCustomer< - H extends SWRHook = SWRHook + H extends SWRHook> = SWRHook > = ReturnType -export const fetcher: HookFetcherFn = SWRFetcher +export const fetcher: HookFetcherFn = SWRFetcher const fn = (provider: Provider) => provider.customer?.useCustomer! diff --git a/framework/commerce/types/customer.ts b/framework/commerce/types/customer.ts index 46c415f0a..4df0fade3 100644 --- a/framework/commerce/types/customer.ts +++ b/framework/commerce/types/customer.ts @@ -5,6 +5,13 @@ export type CustomerTypes = { customer: Customer } +export type CustomerHook = { + data: T['customer'] | null + fetchData: { customer: T['customer'] } | null + // actionInput: T['body'] + // fetchInput: T['body'] +} + export type CustomerSchema = { endpoint: { options: {} diff --git a/framework/commerce/utils/types.ts b/framework/commerce/utils/types.ts index 736ef60f3..e842df58c 100644 --- a/framework/commerce/utils/types.ts +++ b/framework/commerce/utils/types.ts @@ -43,7 +43,12 @@ export type HookFetcherFn = ( export type HookFetcherContext = { options: HookFetcherOptions input: H['fetchInput'] - fetch: (options: FetcherOptions) => Promise + fetch: { + ( + options: FetcherOptions + ): Promise + (options: FetcherOptions): Promise + } } export type HookFetcherOptions = { method?: string } & ( @@ -67,19 +72,21 @@ export type HookFunction< : (input: Input) => T export type HookSchemaBase = { - // Data obj returned by the hook and fetch operation + // Data obj returned by the hook data: any // Input expected by the hook input?: {} // Input expected before doing a fetch operation (aka fetch handler) fetchInput?: {} - // Data expected by the fetch operation + // Body object expected by the fetch operation body?: {} + // Data returned by the fetch operation + fetchData?: any } export type SWRHookSchemaBase = HookSchemaBase & { // Custom state added to the response object of SWR - swrState: {} + swrState?: {} } export type MutationSchemaBase = HookSchemaBase & { @@ -101,8 +108,6 @@ export type SWRHook = { fetcher?: HookFetcherFn } -type X = {} & undefined - export type SWRHookContext = { useData(context?: { input?: HookFetchInput | HookSWRInput