mirror of
https://github.com/block/buzz.git
synced 2026-11-13 12:51:34 +00:00
fix(desktop): surface workflow action failures
Signed-off-by: tornquist <tornquist@squareup.com>
This commit is contained in:
committed by
Luke Tornquist
parent
45e98393b7
commit
0326141326
@@ -12,6 +12,7 @@ import {
|
||||
import { Button } from "@/shared/ui/button";
|
||||
|
||||
type WorkflowDeleteDialogProps = {
|
||||
isPending: boolean;
|
||||
open: boolean;
|
||||
workflow: Workflow | null;
|
||||
onConfirm: (workflow: Workflow) => void;
|
||||
@@ -19,6 +20,7 @@ type WorkflowDeleteDialogProps = {
|
||||
};
|
||||
|
||||
export function WorkflowDeleteDialog({
|
||||
isPending,
|
||||
open,
|
||||
workflow,
|
||||
onConfirm,
|
||||
@@ -37,13 +39,17 @@ export function WorkflowDeleteDialog({
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel asChild>
|
||||
<Button type="button" variant="outline">
|
||||
<Button disabled={isPending} type="button" variant="outline">
|
||||
Cancel
|
||||
</Button>
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction asChild>
|
||||
<Button
|
||||
onClick={() => {
|
||||
disabled={isPending}
|
||||
onClick={(event) => {
|
||||
// Keep this controlled dialog open until the relay confirms
|
||||
// deletion. On failure the toast appears and the user can retry.
|
||||
event.preventDefault();
|
||||
if (workflow) {
|
||||
onConfirm(workflow);
|
||||
}
|
||||
@@ -51,7 +57,7 @@ export function WorkflowDeleteDialog({
|
||||
type="button"
|
||||
variant="destructive"
|
||||
>
|
||||
Delete
|
||||
{isPending ? "Deleting…" : "Delete"}
|
||||
</Button>
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
|
||||
@@ -126,6 +126,14 @@ export function WorkflowsView({
|
||||
|
||||
const triggerMutation = useMutation({
|
||||
mutationFn: (workflowId: string) => triggerWorkflow(workflowId),
|
||||
onError: (error) => {
|
||||
toast.error("Couldn’t run workflow", {
|
||||
description:
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: "The workflow did not start. Try again.",
|
||||
});
|
||||
},
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({
|
||||
predicate: (query) => query.queryKey[0] === "workflow-runs",
|
||||
@@ -135,7 +143,16 @@ export function WorkflowsView({
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: (workflowId: string) => deleteWorkflow(workflowId),
|
||||
onError: (error) => {
|
||||
toast.error("Couldn’t delete workflow", {
|
||||
description:
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: "The workflow was not deleted. Try again.",
|
||||
});
|
||||
},
|
||||
onSuccess: (_data, workflowId) => {
|
||||
setDeleteTarget(null);
|
||||
if (selectedWorkflowId === workflowId) {
|
||||
onCloseWorkflow();
|
||||
}
|
||||
@@ -194,7 +211,6 @@ export function WorkflowsView({
|
||||
const handleConfirmDelete = React.useCallback(
|
||||
(workflow: Workflow) => {
|
||||
deleteOne(workflow.id);
|
||||
setDeleteTarget(null);
|
||||
},
|
||||
[deleteOne],
|
||||
);
|
||||
@@ -314,9 +330,10 @@ export function WorkflowsView({
|
||||
/>
|
||||
|
||||
<WorkflowDeleteDialog
|
||||
isPending={deleteMutation.isPending}
|
||||
onConfirm={handleConfirmDelete}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setDeleteTarget(null);
|
||||
if (!open && !deleteMutation.isPending) setDeleteTarget(null);
|
||||
}}
|
||||
open={deleteTarget !== null}
|
||||
workflow={deleteTarget}
|
||||
|
||||
Reference in New Issue
Block a user