Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: add new edit button that allow users to edit webhooks

adilsonfdc014308b40
diff --git a/frontend/src/hooks/api/webhooks/mutation.tsx b/frontend/src/hooks/api/webhooks/mutation.tsx
index 66eb8ae170..277a748d12 100644
--- a/frontend/src/hooks/api/webhooks/mutation.tsx
+++ b/frontend/src/hooks/api/webhooks/mutation.tsx
@@ -41,8 +41,26 @@ export const useUpdateWebhook = () => {
return useMutation<object, object, TUpdateWebhookDto>({
mutationFn: async (dto) => {
+ const payload: {
+ isDisabled?: boolean;
+ isSecretModifiedEventEnabled?: boolean;
+ isSecretRotationFailedEventEnabled?: boolean;
+ } = {};
+
+ if (dto.isDisabled !== undefined) {
+ payload.isDisabled = dto.isDisabled;
+ }
+
+ if (dto.isSecretModifiedEventEnabled !== undefined) {
+ payload.isSecretModifiedEventEnabled = dto.isSecretModifiedEventEnabled;
+ }
+
+ if (dto.isSecretRotationFailedEventEnabled !== undefined) {
+ payload.isSecretRotationFailedEventEnabled = dto.isSecretRotationFailedEventEnabled;
+ }
+
const { data } = await apiRequest.patch(`/api/v1/webhooks/${dto.webhookId}`, {
- isDisabled: dto.isDisabled
+ ...payload
});
return data;
},
diff --git a/frontend/src/hooks/api/webhooks/types.ts b/frontend/src/hooks/api/webhooks/types.ts
index c1c98b4e3f..3edad0b5ec 100644
--- a/frontend/src/hooks/api/webhooks/types.ts
+++ b/frontend/src/hooks/api/webhooks/types.ts
@@ -4,6 +4,37 @@ export enum WebhookType {
MICROSOFT_TEAMS = "microsoft-teams"
}
+export enum WebhookEvent {
+ SecretModified = "secrets.modified",
+ SecretRotationFailed = "secrets.rotation-failed"
+}
+
+export type TWebhookEventToggleKey = Exclude<
+ keyof TUpdateWebhookDto,
+ "webhookId" | "projectId" | "isDisabled"
+>;
+
+export type TWebhookEventMetadata = {
+ key: TWebhookEventToggleKey;
+ label: string;
+ description: string;
+};
+
+export const WEBHOOK_EVENTS = Object.values(WebhookEvent) as WebhookEvent[];
+
+export const WEBHOOK_EVENT_METADATA: Record<WebhookEvent, TWebhookEventMetadata> = {
+ [WebhookEvent.SecretRotationFailed]: {
+ key: "isSecretRotationFailedEventEnabled",
+ label: "Secret Rotation Failed",
+ description: "Triggered when a secret rotation fails"
+ },
+ [WebhookEvent.SecretModified]: {
+ key: "isSecretModifiedEventEnabled",
+ label: "Secret Modified",
+ description: "Triggered when secrets are modified"
+ }
+};
+
export type TWebhook = {
id: string;
type: WebhookType;
@@ -19,6 +50,8 @@ export type TWebhook = {
lastStatus: "success" | "failed";
lastRunErrorMessage?: string;
isDisabled: boolean;
+ isSecretModifiedEventEnabled: boolean;
+ isSecretRotationFailedEventEnabled: boolean;
createdAt: string;
updatedAt: string;
};
@@ -36,6 +69,8 @@ export type TUpdateWebhookDto = {
webhookId: string;
projectId: string;
isDisabled?: boolean;
+ isSecretModifiedEventEnabled?: boolean;
+ isSecretRotationFailedEventEnabled?: boolean;
};
export type TDeleteWebhookDto = {
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/WebhooksTab/EditWebhookEventsModal.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/WebhooksTab/EditWebhookEventsModal.tsx
new file mode 100644
index 0000000000..5990f7f84e
--- /dev/null
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/WebhooksTab/EditWebhookEventsModal.tsx
@@ -0,0 +1,107 @@
+import { FormEvent, useEffect, useMemo, useState } from "react";
+
+import { Button, Modal, ModalClose, ModalContent, Switch } from "@app/components/v2";
+import {
+ TWebhook,
+ TWebhookEventToggleKey,
+ WEBHOOK_EVENT_METADATA,
+ WEBHOOK_EVENTS
+} from "@app/hooks/api/webhooks/types";
+
+type TWebhookEventSettings = Record<TWebhookEventToggleKey, boolean>;
+type Props = {
+ isOpen?: boolean;
+ webhook?: TWebhook;
+ isSubmitting?: boolean;
+ onOpenChange: (isOpen: boolean) => void;
+ onSave: (settings: TWebhookEventSettings) => Promise<void>;
+};
+
+export const EditWebhookEventsModal = ({
+ isOpen,
+ webhook,
+ isSubmitting,
+ onOpenChange,
+ onSave
+}: Props) => {
+ const defaultSettings = useMemo(
+ () => ({ isSecretModifiedEventEnabled: true, isSecretRotationFailedEventEnabled: true }),
+ []
+ );
+ const [eventSettings, setEventSettings] = useState<TWebhookEventSettings>(defaultSettings);
+
+ useEffect(() => {
+ if (!isOpen) return;
+
+ if (!webhook) {
+ setEventSettings(defaultSettings);
+ return;
+ }
+
+ setEventSettings(
+ WEBHOOK_EVENTS.reduce<TWebhookEventSettings>((acc, event) => {
+ const { key } = WEBHOOK_EVENT_METADATA[event];
+ acc[key] = webhook[key] ?? true;
+ return acc;
+ }, {} as TWebhookEventSettings)
+ );
+ }, [isOpen, webhook, defaultSettings]);
+
+ const handleToggle = (key: TWebhookEventToggleKey, isEnabled: boolean) => {
+ setEventSettings((curr) => ({
+ ...curr,
+ [key]: isEnabled
+ }));
+ };
+
+ const handleSave = async (e: FormEvent<HTMLFormElement>) => {
+ e.preventDefault();
+ await onSave(eventSettings);
+ };
+
+ return (
+ <Modal isOpen={isOpen} onOpenChange={onOpenChange}>
+ <ModalContent
+ title="Edit Webhook Events"
+ subTitle="Select which events should trigger this webhook."
+ >
+ <form onSubmit={handleSave}>
+ <div className="space-y-3">
+ {WEBHOOK_EVENTS.map((event) => {
+ const { key, label, description } = WEBHOOK_EVENT_METADATA[event];
+
+ return (
+ <div
+ key={event}
+ className="flex items-center justify-between rounded-lg border border-mineshaft-600 bg-mineshaft-800 px-4 py-3"
+ >
+ <div className="pr-6">
+ <p className="text-sm font-medium text-mineshaft-50">{label}</p>
+ <p className="text-sm text-mineshaft-400">{description}</p>
+ </div>
+ <Switch
+ id={`webhook-event-${event}`}
+ isChecked={eventSettings[key]}
+ onCheckedChange={(checked) => handleToggle(key, checked === true)}
+ thumbClassName="bg-mineshaft-800"
+ />
+ </div>
+ );
+ })}
+ </div>
+
+ <div className="mt-6 flex items-center justify-end gap-2">
+ <ModalClose asChild>
+ <Button variant="plain" colorSchema="secondary">
+ Cancel
+ </Button>
+ </ModalClose>
+ <Button type="submit" isDisabled={isSubmitting} isLoading={isSubmitting}>
+ Save Changes
+ </Button>
+ </div>
+ </form>
+ </ModalContent>
+ </Modal>
+ );
+};
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/WebhooksTab/WebhooksTab.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/WebhooksTab/WebhooksTab.tsx
index 5296bc4ad0..095b8355a2 100644
--- a/frontend/src/pages/secret-manager/SettingsPage/components/WebhooksTab/WebhooksTab.tsx
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/WebhooksTab/WebhooksTab.tsx
@@ -28,8 +28,10 @@ import {
useTestWebhook,
useUpdateWebhook
} from "@app/hooks/api";
+import { TWebhook } from "@app/hooks/api/webhooks/types";
import { AddWebhookForm, TFormSchema } from "./AddWebhookForm";
+import { EditWebhookEventsModal } from "./EditWebhookEventsModal";
export const WebhooksTab = withProjectPermission(
() => {
@@ -39,7 +41,8 @@ export const WebhooksTab = withProjectPermission(
const projectId = currentProject?.id || "";
const { popUp, handlePopUpOpen, handlePopUpToggle, handlePopUpClose } = usePopUp([
"addWebhook",
- "deleteWebhook"
+ "deleteWebhook",
+ "editWebhook"
] as const);
const { data: webhooks, isPending: isWebhooksLoading } = useGetWebhooks(projectId);
@@ -82,6 +85,25 @@ export const WebhooksTab = withProjectPermission(
});
};
+ const handleWebhookEventsUpdate = async (
+ webhookId: string,
+ settings: {
+ isSecretModifiedEventEnabled: boolean;
+ isSecretRotationFailedEventEnabled: boolean;
+ }
+ ) => {
+ await updateWebhook({
+ webhookId,
+ projectId,
+ ...settings
+ });
+ handlePopUpClose("editWebhook");
+ createNotification({
+ type: "success",
+ text: "Successfully updated webhook events"
+ });
+ };
+
const handleWebhookDelete = async () => {
const webhookId = popUp?.deleteWebhook?.data as string;
await deleteWebhook({
@@ -148,8 +170,8 @@ export const WebhooksTab = withProjectPermission(
</Tr>
)}
{!isWebhooksLoading &&
- webhooks?.map(
- ({
+ webhooks?.map((webhook) => {
+ const {
id,
url,
environment,
@@ -158,7 +180,9 @@ export const WebhooksTab = withProjectPermission(
isDisabled,
updatedAt,
lastRunErrorMessage
- }) => (
+ } = webhook;
+
+ return (
<Tr key={id}>
<Td className="max-w-xs overflow-hidden text-ellipsis hover:overflow-auto hover:break-all">
{url}
@@ -199,6 +223,21 @@ export const WebhooksTab = withProjectPermission(
</Td>
<Td>
<div className="flex items-center justify-end space-x-2">
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Edit}
+ a={ProjectPermissionSub.Webhooks}
+ >
+ {(isAllowed) => (
+ <Button
+ variant="outline_bg"
+ size="xs"
+ isDisabled={!isAllowed}
+ onClick={() => handlePopUpOpen("editWebhook", webhook)}
+ >
+ Edit
+ </Button>
+ )}
+ </ProjectPermissionCan>
<ProjectPermissionCan
I={ProjectPermissionActions.Edit}
a={ProjectPermissionSub.Webhooks}
@@ -263,8 +302,8 @@ export const WebhooksTab = withProjectPermission(
</div>
</Td>
</Tr>
- )
- )}
+ );
+ })}
</TBody>
</Table>
</TableContainer>
@@ -283,6 +322,20 @@ export const WebhooksTab = withProjectPermission(
onClose={() => handlePopUpClose("deleteWebhook")}
onDeleteApproved={handleWebhookDelete}
/>
+ <EditWebhookEventsModal
+ isOpen={popUp.editWebhook.isOpen}
+ onOpenChange={(isOpen) => handlePopUpToggle("editWebhook", isOpen)}
+ webhook={popUp.editWebhook.data as TWebhook | undefined}
+ isSubmitting={
+ isUpdateWebhookSubmitting &&
+ updateWebhookVars?.webhookId === (popUp.editWebhook.data as TWebhook | undefined)?.id
+ }
+ onSave={async (settings) => {
+ const webhookId = (popUp.editWebhook.data as TWebhook | undefined)?.id;
+ if (!webhookId) return;
+ await handleWebhookEventsUpdate(webhookId, settings);
+ }}
+ />
</div>
);
},