mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 12:24:18 +00:00
Added optional mutations to hook schema
This commit is contained in:
parent
30744c5a6c
commit
ac1a8be6c3
@ -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> & {
|
||||
export type GetCheckoutHandler<T extends CheckoutTypes = CheckoutTypes> =
|
||||
GetCheckoutHook<T> & {
|
||||
body: { cartId: string }
|
||||
}
|
||||
}
|
||||
|
||||
export type SubmitCheckoutHandler<T extends CheckoutTypes = CheckoutTypes> = SubmitCheckoutHook<T> & {
|
||||
export type SubmitCheckoutHandler<T extends CheckoutTypes = CheckoutTypes> =
|
||||
SubmitCheckoutHook<T> & {
|
||||
body: { cartId: string }
|
||||
}
|
||||
}
|
||||
|
||||
export type CheckoutHandlers<T extends CheckoutTypes = CheckoutTypes> = {
|
||||
getCheckout: GetCheckoutHandler<T>
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user