From 58d782b78087feab38535f01da731acbc6458249 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Tue, 25 May 2021 09:31:52 -0500 Subject: [PATCH] Updated types for auth hooks --- framework/bigcommerce/auth/use-login.tsx | 4 ++-- framework/bigcommerce/auth/use-logout.tsx | 3 ++- framework/bigcommerce/auth/use-signup.tsx | 4 ++-- framework/commerce/auth/use-login.tsx | 5 +++-- framework/commerce/auth/use-logout.tsx | 5 +++-- framework/commerce/auth/use-signup.tsx | 5 +++-- framework/commerce/cart/use-add-item.tsx | 4 ---- framework/commerce/types/login.ts | 12 ++++++++---- framework/commerce/types/logout.ts | 16 +++++++++++----- framework/commerce/types/signup.ts | 12 ++++++++---- framework/commerce/utils/types.ts | 2 +- 11 files changed, 43 insertions(+), 29 deletions(-) diff --git a/framework/bigcommerce/auth/use-login.tsx b/framework/bigcommerce/auth/use-login.tsx index 1be96a58c..bf2360af6 100644 --- a/framework/bigcommerce/auth/use-login.tsx +++ b/framework/bigcommerce/auth/use-login.tsx @@ -2,12 +2,12 @@ import { useCallback } from 'react' import type { MutationHook } from '@commerce/utils/types' import { CommerceError } from '@commerce/utils/errors' import useLogin, { UseLogin } from '@commerce/auth/use-login' -import type { LoginBody } from '../api/customers/login' +import type { LoginHook } from '../types/login' import useCustomer from '../customer/use-customer' export default useLogin as UseLogin -export const handler: MutationHook = { +export const handler: MutationHook = { fetchOptions: { url: '/api/bigcommerce/customers/login', method: 'POST', diff --git a/framework/bigcommerce/auth/use-logout.tsx b/framework/bigcommerce/auth/use-logout.tsx index 71015a1c1..f704563e9 100644 --- a/framework/bigcommerce/auth/use-logout.tsx +++ b/framework/bigcommerce/auth/use-logout.tsx @@ -1,11 +1,12 @@ import { useCallback } from 'react' import type { MutationHook } from '@commerce/utils/types' import useLogout, { UseLogout } from '@commerce/auth/use-logout' +import type { LogoutHook } from '../types/logout' import useCustomer from '../customer/use-customer' export default useLogout as UseLogout -export const handler: MutationHook = { +export const handler: MutationHook = { fetchOptions: { url: '/api/bigcommerce/customers/logout', method: 'GET', diff --git a/framework/bigcommerce/auth/use-signup.tsx b/framework/bigcommerce/auth/use-signup.tsx index 28f7024ef..bcd6886a3 100644 --- a/framework/bigcommerce/auth/use-signup.tsx +++ b/framework/bigcommerce/auth/use-signup.tsx @@ -2,12 +2,12 @@ import { useCallback } from 'react' import type { MutationHook } from '@commerce/utils/types' import { CommerceError } from '@commerce/utils/errors' import useSignup, { UseSignup } from '@commerce/auth/use-signup' -import type { SignupBody } from '../api/customers/signup' +import type { SignupHook } from '../types/signup' import useCustomer from '../customer/use-customer' export default useSignup as UseSignup -export const handler: MutationHook = { +export const handler: MutationHook = { fetchOptions: { url: '/api/bigcommerce/customers/signup', method: 'POST', diff --git a/framework/commerce/auth/use-login.tsx b/framework/commerce/auth/use-login.tsx index cc4cf6a73..67fb429dc 100644 --- a/framework/commerce/auth/use-login.tsx +++ b/framework/commerce/auth/use-login.tsx @@ -1,13 +1,14 @@ import { useHook, useMutationHook } from '../utils/use-hook' import { mutationFetcher } from '../utils/default-fetcher' import type { MutationHook, HookFetcherFn } from '../utils/types' +import type { LoginHook } from '../types/login' import type { Provider } from '..' export type UseLogin< - H extends MutationHook = MutationHook + H extends MutationHook> = MutationHook > = ReturnType -export const fetcher: HookFetcherFn = mutationFetcher +export const fetcher: HookFetcherFn = mutationFetcher const fn = (provider: Provider) => provider.auth?.useLogin! diff --git a/framework/commerce/auth/use-logout.tsx b/framework/commerce/auth/use-logout.tsx index d0f7e3ae0..6ca16decf 100644 --- a/framework/commerce/auth/use-logout.tsx +++ b/framework/commerce/auth/use-logout.tsx @@ -1,13 +1,14 @@ import { useHook, useMutationHook } from '../utils/use-hook' import { mutationFetcher } from '../utils/default-fetcher' import type { HookFetcherFn, MutationHook } from '../utils/types' +import type { LogoutHook } from '../types/logout' import type { Provider } from '..' export type UseLogout< - H extends MutationHook = MutationHook + H extends MutationHook> = MutationHook > = ReturnType -export const fetcher: HookFetcherFn = mutationFetcher +export const fetcher: HookFetcherFn = mutationFetcher const fn = (provider: Provider) => provider.auth?.useLogout! diff --git a/framework/commerce/auth/use-signup.tsx b/framework/commerce/auth/use-signup.tsx index 72e242209..2f846fad6 100644 --- a/framework/commerce/auth/use-signup.tsx +++ b/framework/commerce/auth/use-signup.tsx @@ -1,13 +1,14 @@ import { useHook, useMutationHook } from '../utils/use-hook' import { mutationFetcher } from '../utils/default-fetcher' import type { HookFetcherFn, MutationHook } from '../utils/types' +import type { SignupHook } from '../types/signup' import type { Provider } from '..' export type UseSignup< - H extends MutationHook = MutationHook + H extends MutationHook> = MutationHook > = ReturnType -export const fetcher: HookFetcherFn = mutationFetcher +export const fetcher: HookFetcherFn = mutationFetcher const fn = (provider: Provider) => provider.auth?.useSignup! diff --git a/framework/commerce/cart/use-add-item.tsx b/framework/commerce/cart/use-add-item.tsx index a9d1db146..f4072c763 100644 --- a/framework/commerce/cart/use-add-item.tsx +++ b/framework/commerce/cart/use-add-item.tsx @@ -8,10 +8,6 @@ export type UseAddItem< H extends MutationHook> = MutationHook > = ReturnType -export type UseAddItem2< - H extends MutationHook = MutationHook -> = ReturnType - export const fetcher: HookFetcherFn = mutationFetcher const fn = (provider: Provider) => provider.cart?.useAddItem! diff --git a/framework/commerce/types/login.ts b/framework/commerce/types/login.ts index 726649719..031574a33 100644 --- a/framework/commerce/types/login.ts +++ b/framework/commerce/types/login.ts @@ -7,14 +7,18 @@ export type LoginTypes = { body: LoginBody } +export type LoginHook = { + data: null + actionInput: LoginBody + fetchInput: LoginBody + body: T['body'] +} + export type LoginSchema = { endpoint: { options: {} handlers: { - login: { - data: null - body: T['body'] - } + login: LoginHook } } } diff --git a/framework/commerce/types/logout.ts b/framework/commerce/types/logout.ts index 6923237a7..a7240052f 100644 --- a/framework/commerce/types/logout.ts +++ b/framework/commerce/types/logout.ts @@ -1,11 +1,17 @@ -export type LogoutSchema = { +export type LogoutTypes = { + body: { redirectTo?: string } +} + +export type LogoutHook = { + data: null + body: T['body'] +} + +export type LogoutSchema = { endpoint: { options: {} handlers: { - logout: { - data: null - body: { redirectTo?: string } - } + logout: LogoutHook } } } diff --git a/framework/commerce/types/signup.ts b/framework/commerce/types/signup.ts index 5878bedf9..df5f9aca7 100644 --- a/framework/commerce/types/signup.ts +++ b/framework/commerce/types/signup.ts @@ -9,14 +9,18 @@ export type SignupTypes = { body: SignupBody } +export type SignupHook = { + data: null + body: T['body'] + actionInput: T['body'] + fetchInput: T['body'] +} + export type SignupSchema = { endpoint: { options: {} handlers: { - signup: { - data: null - body: T['body'] - } + signup: SignupHook } } } diff --git a/framework/commerce/utils/types.ts b/framework/commerce/utils/types.ts index 93fd8153c..736ef60f3 100644 --- a/framework/commerce/utils/types.ts +++ b/framework/commerce/utils/types.ts @@ -70,7 +70,7 @@ export type HookSchemaBase = { // Data obj returned by the hook and fetch operation data: any // Input expected by the hook - input: {} + input?: {} // Input expected before doing a fetch operation (aka fetch handler) fetchInput?: {} // Data expected by the fetch operation