From ac1a8be6c3f60b144d6114960869f169c4354139 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Tue, 14 Sep 2021 14:51:33 -0500 Subject: [PATCH] Added optional mutations to hook schema --- framework/commerce/types/checkout.ts | 27 ++++++++++++++++----------- framework/commerce/utils/types.ts | 4 +++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/framework/commerce/types/checkout.ts b/framework/commerce/types/checkout.ts index 8672f93b9..e43837825 100644 --- a/framework/commerce/types/checkout.ts +++ b/framework/commerce/types/checkout.ts @@ -1,10 +1,12 @@ +import type { UseSubmitCheckout } from '../checkout/use-submit-checkout' + // Index export type CheckoutTypes = { - card?: any; - address?: any; - checkout?: any; - hasPayment?: boolean; - hasShipping?: boolean; + card?: any + address?: any + checkout?: any + hasPayment?: boolean + hasShipping?: boolean } export type SubmitCheckoutHook = { @@ -20,6 +22,7 @@ export type GetCheckoutHook = { input: {} fetcherInput: { cartId?: string } swrState: { isEmpty: boolean } + mutations: { submit: UseSubmitCheckout } } export type CheckoutHooks = { @@ -27,13 +30,15 @@ export type CheckoutHooks = { getCheckout: GetCheckoutHook } -export type GetCheckoutHandler = GetCheckoutHook & { - body: { cartId: string } -} +export type GetCheckoutHandler = + GetCheckoutHook & { + body: { cartId: string } + } -export type SubmitCheckoutHandler = SubmitCheckoutHook & { - body: { cartId: string } -} +export type SubmitCheckoutHandler = + SubmitCheckoutHook & { + body: { cartId: string } + } export type CheckoutHandlers = { getCheckout: GetCheckoutHandler diff --git a/framework/commerce/utils/types.ts b/framework/commerce/utils/types.ts index 751cea4a5..2bca30852 100644 --- a/framework/commerce/utils/types.ts +++ b/framework/commerce/utils/types.ts @@ -87,6 +87,8 @@ export type HookSchemaBase = { export type SWRHookSchemaBase = HookSchemaBase & { // Custom state added to the response object of SWR swrState?: {} + // Instances of MutationSchemaBase that the hook returns for better DX + mutations?: Record['useHook']>> } export type MutationSchemaBase = HookSchemaBase & { @@ -102,7 +104,7 @@ export type SWRHook = { context: SWRHookContext ): HookFunction< H['input'] & { swrOptions?: SwrOptions }, - ResponseState & H['swrState'] + ResponseState & H['swrState'] & H['mutations'] > fetchOptions: HookFetcherOptions fetcher?: HookFetcherFn