diff --git a/packages/machines/toast/src/toast-group.connect.ts b/packages/machines/toast/src/toast-group.connect.ts index 49f6162a89..4092e09189 100644 --- a/packages/machines/toast/src/toast-group.connect.ts +++ b/packages/machines/toast/src/toast-group.connect.ts @@ -2,15 +2,7 @@ import { StateMachine as S, subscribe } from "@zag-js/core" import { normalizeProp, PropTypes, ReactPropTypes } from "@zag-js/types" import { runIfFn } from "@zag-js/utils" import { dom } from "./toast.dom" -import { - Toaster, - GroupProps, - GroupMachineContext, - Options, - Placement, - PromiseMessages, - PromiseOptions, -} from "./toast.types" +import { Toaster, GroupProps, GroupMachineContext, Options, Placement, PromiseOptions } from "./toast.types" import { getGroupPlacementStyle, getToastsByPlacement } from "./toast.utils" export let toaster: Toaster = {} as any @@ -94,17 +86,17 @@ export function groupConnect( return group.upsert(options) }, - promise(promise: Promise, msgs: PromiseMessages, opts: PromiseOptions = {}) { - const id = group.loading({ ...opts, ...opts?.loading, type: "loading", title: msgs.loading }) + promise(promise: Promise, options: PromiseOptions, shared: Options = {}) { + const id = group.loading({ ...shared, ...options.loading }) promise .then((response) => { - const message = runIfFn(msgs.loading, response) - group.success({ ...opts, ...opts?.success, id, title: message }) + const successOptions = runIfFn(options.success, response) + group.success({ ...shared, ...successOptions, id }) }) .catch((error) => { - const message = runIfFn(msgs.error, error) - group.error({ ...opts, ...opts?.error, id, title: message }) + const errorOptions = runIfFn(options.error, error) + group.error({ ...shared, ...errorOptions, id }) }) return promise diff --git a/packages/machines/toast/src/toast.types.ts b/packages/machines/toast/src/toast.types.ts index ffe5447152..480666efab 100644 --- a/packages/machines/toast/src/toast.types.ts +++ b/packages/machines/toast/src/toast.types.ts @@ -135,14 +135,10 @@ export type GroupMachineContext = SharedContext & type MaybeFunction = Value | ((arg: Args) => Value) -export type PromiseMessages = { - loading: Value - success: MaybeFunction - error: MaybeFunction -} - -export type PromiseOptions = Options & { - [key in "success" | "loading" | "error"]?: Options +export type PromiseOptions = { + loading: Options + success: MaybeFunction + error: MaybeFunction } export type GroupProps = { @@ -160,5 +156,5 @@ export type Toaster = { loading(options: Options): string | undefined dismiss(id?: string | undefined): void remove(id?: string | undefined): void - promise(promise: Promise, msgs: PromiseMessages, opts?: PromiseOptions): Promise + promise(promise: Promise, options: PromiseOptions, shared?: Options): Promise }