Added optional mutations to hook schema

This commit is contained in:
Luis Alvarez 2021-09-14 14:51:33 -05:00
parent 30744c5a6c
commit ac1a8be6c3
2 changed files with 19 additions and 12 deletions

View File

@ -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<T extends CheckoutTypes = CheckoutTypes> = {
@ -20,6 +22,7 @@ export type GetCheckoutHook<T extends CheckoutTypes = CheckoutTypes> = {
input: {}
fetcherInput: { cartId?: string }
swrState: { isEmpty: boolean }
mutations: { submit: UseSubmitCheckout }
}
export type CheckoutHooks<T extends CheckoutTypes = CheckoutTypes> = {
@ -27,13 +30,15 @@ export type CheckoutHooks<T extends CheckoutTypes = CheckoutTypes> = {
getCheckout: GetCheckoutHook<T>
}
export type GetCheckoutHandler<T extends CheckoutTypes = CheckoutTypes> = GetCheckoutHook<T> & {
body: { cartId: string }
}
export type GetCheckoutHandler<T extends CheckoutTypes = CheckoutTypes> =
GetCheckoutHook<T> & {
body: { cartId: string }
}
export type SubmitCheckoutHandler<T extends CheckoutTypes = CheckoutTypes> = SubmitCheckoutHook<T> & {
body: { cartId: string }
}
export type SubmitCheckoutHandler<T extends CheckoutTypes = CheckoutTypes> =
SubmitCheckoutHook<T> & {
body: { cartId: string }
}
export type CheckoutHandlers<T extends CheckoutTypes = CheckoutTypes> = {
getCheckout: GetCheckoutHandler<T>

View File

@ -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<string, ReturnType<MutationHook<any>['useHook']>>
}
export type MutationSchemaBase = HookSchemaBase & {
@ -102,7 +104,7 @@ export type SWRHook<H extends SWRHookSchemaBase> = {
context: SWRHookContext<H>
): HookFunction<
H['input'] & { swrOptions?: SwrOptions<H['data'], H['fetcherInput']> },
ResponseState<H['data']> & H['swrState']
ResponseState<H['data']> & H['swrState'] & H['mutations']
>
fetchOptions: HookFetcherOptions
fetcher?: HookFetcherFn<H>