import { ReactNode } from 'react'; import { AthenaToastContent, AthenaToastOptions } from '../../lib/toast.js'; export interface NetworkRequestRunnerMessages { /** Toast after failure. Defaults to the error message. */ error?: AthenaToastContent | ((error: Error) => AthenaToastContent); /** Variant for the error toast (default `danger`). */ errorVariant?: Exclude; /** Toast while the request is in flight. */ loading: AthenaToastContent; /** Toast after success. Defaults to closing the loading toast only. */ success?: AthenaToastContent | ((result: T) => AthenaToastContent); /** Variant for the success toast (default `success`). */ successVariant?: Exclude; } export interface RunNetworkRequestOptions extends NetworkRequestRunnerMessages { /** When true, rethrow after showing the error toast (default true). */ rethrow?: boolean; } /** * Runs an async network call with a loading toast, then success/error update. * Prefer this over ad hoc `showLoadingToast` + `closeToast` pairs. * * @param work - The work to run * @param options - The options for the network request * @returns The result of the network request */ export declare function runNetworkRequest(work: () => Promise, options: RunNetworkRequestOptions): Promise; export interface NetworkRequestRunnerRenderState { isPending: boolean; run: () => Promise; } export interface NetworkRequestRunnerProps extends NetworkRequestRunnerMessages { children: (state: NetworkRequestRunnerRenderState) => ReactNode; onError?: (error: Error) => void; /** * Async work to run when `run()` is invoked. * Errors are toasted; rethrow is disabled so UI handlers stay quiet. */ onRequest: () => Promise; onSuccess?: (result: T) => void; } /** * Render-prop helper that tracks pending state and runs * {@link runNetworkRequest} with the given toast messages. * * @param children - The children to render * @param error - The error to toast * @param errorVariant - The variant to use for the error toast * @param loading - The loading toast to show * @param onError - The function to call when an error occurs * @param onRequest - The function to call when the request is made * @param onSuccess - The function to call when the request is successful * @param success - The success toast to show * @param successVariant - The variant to use for the success toast * * @example * ```tsx * ({ title: "Save failed", description: e.message })} * onRequest={() => saveProfile(form)} * > * {({ isPending, run }) => ( * * )} * * ``` */ export declare function NetworkRequestRunner({ children, error, errorVariant, loading, onError, onRequest, onSuccess, success, successVariant, }: NetworkRequestRunnerProps): import("react").JSX.Element;