-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8199094
commit a84b43d
Showing
2 changed files
with
43 additions
and
35 deletions.
There are no files selected for viewing
65 changes: 38 additions & 27 deletions
65
ui/admin/app/components/workflow-triggers/DeleteWorkflowTrigger.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,77 @@ | ||
import { useState } from "react"; | ||
import { toast } from "sonner"; | ||
import { mutate } from "swr"; | ||
|
||
import { CronJobApiService } from "~/lib/service/api/cronjobApiService"; | ||
import { WebhookApiService } from "~/lib/service/api/webhookApiService"; | ||
|
||
import { TypographyP } from "~/components/Typography"; | ||
import { ConfirmationDialog } from "~/components/composed/ConfirmationDialog"; | ||
import { DropdownMenuItem } from "~/components/ui/dropdown-menu"; | ||
import { useConfirmationDialog } from "~/hooks/component-helpers/useConfirmationDialog"; | ||
import { useAsync } from "~/hooks/useAsync"; | ||
|
||
export function DeleteWorkflowTrigger({ | ||
id, | ||
name, | ||
type, | ||
children, | ||
}: { | ||
id: string; | ||
name?: string; | ||
type: "webhook" | "schedule"; | ||
children?: React.ReactNode; | ||
}) { | ||
const [open, setOpen] = useState(false); | ||
|
||
const deleteWebhook = useAsync(WebhookApiService.deleteWebhook, { | ||
onSuccess: () => { | ||
mutate(WebhookApiService.getWebhooks.key()); | ||
toast.success("Webhook workflow trigger has been deleted."); | ||
setOpen(false); | ||
}, | ||
}); | ||
|
||
const deleteCronjob = useAsync(CronJobApiService.deleteCronJob, { | ||
onSuccess: () => { | ||
mutate(CronJobApiService.getCronJobs.key()); | ||
toast.success("Schedule workflow trigger has been deleted."); | ||
setOpen(false); | ||
}, | ||
}); | ||
|
||
const handleConfirmDelete = () => { | ||
const handleConfirmDelete = async () => { | ||
if (type === "webhook") { | ||
deleteWebhook.execute(id); | ||
await deleteWebhook.executeAsync(id); | ||
} else { | ||
deleteCronjob.execute(id); | ||
await deleteCronjob.executeAsync(id); | ||
} | ||
}; | ||
|
||
const loading = deleteWebhook.isLoading || deleteCronjob.isLoading; | ||
const { interceptAsync, dialogProps } = useConfirmationDialog(); | ||
|
||
return ( | ||
<ConfirmationDialog | ||
open={open} | ||
onOpenChange={setOpen} | ||
title="Delete Trigger?" | ||
description="This action cannot be undone." | ||
onConfirm={handleConfirmDelete} | ||
closeOnConfirm={false} | ||
confirmProps={{ | ||
loading: loading, | ||
disabled: loading, | ||
variant: "destructive", | ||
children: "Delete", | ||
}} | ||
> | ||
{children} | ||
</ConfirmationDialog> | ||
<> | ||
<DropdownMenuItem | ||
variant="destructive" | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
interceptAsync(handleConfirmDelete); | ||
}} | ||
> | ||
Delete | ||
</DropdownMenuItem> | ||
|
||
<ConfirmationDialog | ||
{...dialogProps} | ||
title="Delete Workflow Trigger?" | ||
description={ | ||
<div className="flex flex-col"> | ||
<TypographyP> | ||
Are you sure you want to delete workflow trigger:{" "} | ||
<b>{name || id}</b>? | ||
</TypographyP> | ||
<TypographyP>The action cannot be undone.</TypographyP> | ||
</div> | ||
} | ||
confirmProps={{ | ||
children: "Delete", | ||
variant: "destructive", | ||
}} | ||
/> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters