cleanup 5
continuous-integration/drone/pr Build is failing

This commit is contained in:
2026-07-03 18:59:50 -04:00
parent c9c9563a1f
commit 5a8b773a0b
13 changed files with 206 additions and 123 deletions
@@ -29,3 +29,40 @@ export function useMutationWithToast() {
};
};
}
interface RunToastMutationOptions<T> {
error: string;
success?: string;
onSuccess?: (response: T) => void;
}
/**
* Imperative sibling of `useMutationWithToast` for flows that must `await` a result (e.g. keep an
* editor open on failure). Runs the action, treats non-2xx as failure, toasts accordingly, and
* resolves to `true` only on success.
*/
export function useToastMutation() {
const { showInfo, showError } = useToasts();
return async function runWithToast<T extends ApiResponseLike>(
action: () => Promise<T>,
{ error, success, onSuccess }: RunToastMutationOptions<T>
): Promise<boolean> {
try {
const response = await action();
const message = getResponseError(response);
if (message) {
showError(`${error}: ${message}`);
return false;
}
onSuccess?.(response);
if (success) {
showInfo(success);
}
return true;
} catch (err) {
showError(`${error}: ${getErrorMessage(err)}`);
return false;
}
};
}