Skip to content

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

improvement: revise identity alert ui

Scott Wilson8fc31290f4ab
diff --git a/frontend/src/pages/organization/IdentityDetailsByIDPage/IdentityDetailsByIDPage.tsx b/frontend/src/pages/organization/IdentityDetailsByIDPage/IdentityDetailsByIDPage.tsx
index 69457bf0b0..464a36c794 100644
--- a/frontend/src/pages/organization/IdentityDetailsByIDPage/IdentityDetailsByIDPage.tsx
+++ b/frontend/src/pages/organization/IdentityDetailsByIDPage/IdentityDetailsByIDPage.tsx
@@ -42,6 +42,7 @@ import { OrgAccessControlTabSections } from "@app/types/org";
import { IdentityAuthMethodModal } from "../AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAuthMethodModal";
import { OrgIdentityModal } from "../AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/OrgIdentityModal";
import {
+ IdentityAlertAction,
IdentityAuthenticationSection,
IdentityDetailsSection,
IdentityProjectsSection
@@ -110,6 +111,9 @@ const Page = () => {
description={`Configure and manage${isScopeIdentity ? " machine identity and " : " "}${isSubOrganization ? "sub-" : ""}organization access control`}
title={data.identity.name}
>
+ {isScopeIdentity && !data.identity.projectId && (
+ <IdentityAlertAction identityId={identityId} identityName={data.identity.name} />
+ )}
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline">
diff --git a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityAlertDetail.tsx b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityAlertAction.tsx
similarity index 79%
rename from frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityAlertDetail.tsx
rename to frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityAlertAction.tsx
index bab4f8947f..9278ecb076 100644
--- a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityAlertDetail.tsx
+++ b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityAlertAction.tsx
@@ -1,14 +1,14 @@
import { OrgPermissionCan } from "@app/components/permissions";
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/context";
-import { AlertDetail } from "@app/views/Alerts";
+import { AlertAction } from "@app/views/Alerts";
type Props = {
identityId: string;
identityName: string;
};
-export const IdentityAlertDetail = ({ identityId, identityName }: Props) => (
- <AlertDetail
+export const IdentityAlertAction = ({ identityId, identityName }: Props) => (
+ <AlertAction
identityId={identityId}
identityName={identityName}
renderPermissionGate={(render) => (
diff --git a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityDetailsSection.tsx b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityDetailsSection.tsx
index c5da5eb3e4..d812d5d28c 100644
--- a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityDetailsSection.tsx
+++ b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityDetailsSection.tsx
@@ -25,8 +25,6 @@ import { useTimedReset } from "@app/hooks";
import { identityAuthToNameMap, useGetOrgIdentityMembershipById } from "@app/hooks/api";
import { UsePopUpState } from "@app/hooks/usePopUp";
-import { IdentityAlertDetail } from "./IdentityAlertDetail";
-
type Props = {
identityId: string;
isCurrentOrgIdentity?: boolean;
@@ -189,9 +187,6 @@ export const IdentityDetailsSection = ({
)}
</DetailValue>
</Detail>
- {!data.identity.projectId && (
- <IdentityAlertDetail identityId={identityId} identityName={data.identity.name} />
- )}
</>
)}
</DetailGroup>
diff --git a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/index.tsx b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/index.tsx
index c9ad2f4144..8cfe25ae87 100644
--- a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/index.tsx
+++ b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/index.tsx
@@ -1,3 +1,4 @@
+export { IdentityAlertAction } from "./IdentityAlertAction";
export { IdentityAuthenticationSection } from "./IdentityAuthenticationSection/IdentityAuthenticationSection";
export { IdentityClientSecretModal } from "./IdentityClientSecretModal";
export { IdentityDetailsSection } from "./IdentityDetailsSection";
diff --git a/frontend/src/pages/project/IdentityDetailsByIDPage/IdentityDetailsByIDPage.tsx b/frontend/src/pages/project/IdentityDetailsByIDPage/IdentityDetailsByIDPage.tsx
index e38f657b6b..c5bdac29e5 100644
--- a/frontend/src/pages/project/IdentityDetailsByIDPage/IdentityDetailsByIDPage.tsx
+++ b/frontend/src/pages/project/IdentityDetailsByIDPage/IdentityDetailsByIDPage.tsx
@@ -56,6 +56,7 @@ import { ProjectAccessControlTabs } from "@app/types/project";
import { IdentityPermissionAuditSheet } from "./components/IdentityPermissionAuditSheet";
import { IdentityProjectAdditionalPrivilegeSection } from "./components/IdentityProjectAdditionalPrivilegeSection";
import { IdentityRoleDetailsSection } from "./components/IdentityRoleDetailsSection";
+import { ProjectIdentityAlertAction } from "./components/ProjectIdentityAlertAction";
const Page = () => {
const navigate = useNavigate();
@@ -178,6 +179,20 @@ const Page = () => {
title={identityMembershipDetails.identity.name}
>
<div className="flex items-center gap-2">
+ {isProjectIdentity ? (
+ <ProjectIdentityAlertAction
+ identityId={identityMembershipDetails.identity.id}
+ identityName={identityMembershipDetails.identity.name}
+ projectId={currentProject.id}
+ projectName={currentProject.name}
+ />
+ ) : (
+ <ProjectIdentityAlertAction
+ identityId={identityMembershipDetails.identity.id}
+ identityName={identityMembershipDetails.identity.name}
+ readOnly
+ />
+ )}
{!isCertManager && (
<Button variant="outline" onClick={() => setIsPermissionAuditOpen(true)}>
<ShieldIcon />
diff --git a/frontend/src/pages/project/IdentityDetailsByIDPage/components/ProjectIdentityAlertDetail.tsx b/frontend/src/pages/project/IdentityDetailsByIDPage/components/ProjectIdentityAlertAction.tsx
similarity index 88%
rename from frontend/src/pages/project/IdentityDetailsByIDPage/components/ProjectIdentityAlertDetail.tsx
rename to frontend/src/pages/project/IdentityDetailsByIDPage/components/ProjectIdentityAlertAction.tsx
index d6b3a85638..3db8cb0163 100644
--- a/frontend/src/pages/project/IdentityDetailsByIDPage/components/ProjectIdentityAlertDetail.tsx
+++ b/frontend/src/pages/project/IdentityDetailsByIDPage/components/ProjectIdentityAlertAction.tsx
@@ -2,7 +2,7 @@ import { subject } from "@casl/ability";
import { ProjectPermissionCan } from "@app/components/permissions";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/context";
-import { AlertDetail } from "@app/views/Alerts";
+import { AlertAction } from "@app/views/Alerts";
type Props = {
identityId: string;
@@ -12,14 +12,14 @@ type Props = {
readOnly?: boolean;
};
-export const ProjectIdentityAlertDetail = ({
+export const ProjectIdentityAlertAction = ({
identityId,
identityName,
projectId,
projectName,
readOnly = false
}: Props) => (
- <AlertDetail
+ <AlertAction
identityId={identityId}
identityName={identityName}
projectId={projectId}
diff --git a/frontend/src/pages/project/IdentityDetailsByIDPage/components/ProjectIdentityDetailsSection.tsx b/frontend/src/pages/project/IdentityDetailsByIDPage/components/ProjectIdentityDetailsSection.tsx
index bd514963ab..fd69baadb8 100644
--- a/frontend/src/pages/project/IdentityDetailsByIDPage/components/ProjectIdentityDetailsSection.tsx
+++ b/frontend/src/pages/project/IdentityDetailsByIDPage/components/ProjectIdentityDetailsSection.tsx
@@ -34,8 +34,6 @@ import { IdentityProjectMembershipV1 } from "@app/hooks/api/identities/types";
import { ProjectType } from "@app/hooks/api/projects/types";
import { ProjectIdentityModal } from "@app/pages/project/AccessControlPage/components/IdentityTab/components/ProjectIdentityModal";
-import { ProjectIdentityAlertDetail } from "./ProjectIdentityAlertDetail";
-
type Props = {
identity: TProjectIdentity;
isOrgIdentity?: boolean;
@@ -198,23 +196,8 @@ export const ProjectIdentityDetailsSection = ({
)}
</DetailValue>
</Detail>
- {currentProject && (
- <ProjectIdentityAlertDetail
- identityId={identity.id}
- identityName={identity.name}
- projectId={currentProject.id}
- projectName={currentProject.name}
- />
- )}
</>
)}
- {isOrgIdentity && (
- <ProjectIdentityAlertDetail
- identityId={identity.id}
- identityName={identity.name}
- readOnly
- />
- )}
</DetailGroup>
</CardContent>
</Card>
diff --git a/frontend/src/views/Alerts/AddAlertModal.tsx b/frontend/src/views/Alerts/AddAlertModal.tsx
index 7fa96460dc..611bda9fa9 100644
--- a/frontend/src/views/Alerts/AddAlertModal.tsx
+++ b/frontend/src/views/Alerts/AddAlertModal.tsx
@@ -26,10 +26,10 @@ export const AddAlertModal = ({
return (
<Sheet open={isOpen} onOpenChange={onOpenChange}>
- <SheetContent className="flex h-full max-h-full flex-col gap-y-0 sm:max-w-2xl">
+ <SheetContent className="flex h-full max-h-full flex-col gap-y-0 sm:max-w-lg">
<SheetHeader className="border-b">
<SheetTitle>{isEditing ? "Edit Alert" : "Add Alert"}</SheetTitle>
- <SheetDescription>
+ <SheetDescription className="sr-only">
Route notifications when a resource event and condition are met.
</SheetDescription>
</SheetHeader>
diff --git a/frontend/src/views/Alerts/AlertAction.tsx b/frontend/src/views/Alerts/AlertAction.tsx
new file mode 100644
index 0000000000..f9bc221671
--- /dev/null
+++ b/frontend/src/views/Alerts/AlertAction.tsx
@@ -0,0 +1,285 @@
+import { ReactNode, useState } from "react";
+import { BellIcon } from "lucide-react";
+
+import { createNotification } from "@app/components/notifications";
+import {
+ Alert,
+ AlertDescription,
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogConfirmationField,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+ Badge,
+ Button,
+ Field,
+ FieldLabel,
+ Input,
+ Label,
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+ Switch
+} from "@app/components/v3";
+import { usePopUp, useScopeVariant } from "@app/hooks";
+import {
+ ALERT_CHANNEL_TYPE_LABELS,
+ ALERT_EVENT_TYPE_LABELS,
+ AlertChannelType,
+ AlertEventType,
+ AlertResourceType,
+ parseAlertBeforeDays,
+ TAlert,
+ useDeleteAlert,
+ useListAlerts,
+ useUpdateAlert
+} from "@app/hooks/api/alerts";
+
+import { AddAlertModal } from "./AddAlertModal";
+
+type Props = {
+ identityId: string;
+ identityName: string;
+ // Org-scoped when omitted.
+ projectId?: string;
+ scopeName?: string;
+ // Renders the alert without any way to create, edit or remove it.
+ readOnly?: boolean;
+ // Wraps the mutating actions in the caller's permission gate (org- or project-scoped), which is the
+ // only thing that differs between the org and project entry points.
+ renderPermissionGate: (render: (isAllowed: boolean) => ReactNode) => ReactNode;
+};
+
+// "7 days before client secret expiry"; falls back to the event label when the
+// stored condition is missing or malformed.
+const formatConditionSummary = (alert: TAlert): string => {
+ const days = parseAlertBeforeDays(alert.condition?.alertBefore);
+ if (days === null) {
+ return ALERT_EVENT_TYPE_LABELS[alert.eventType as AlertEventType] ?? alert.eventType;
+ }
+ return `${days} day${days === 1 ? "" : "s"} before client secret expiry`;
+};
+
+const formatChannelSummary = (alert: TAlert): string =>
+ Object.values(AlertChannelType)
+ .filter((type) => alert.channels.some((channel) => channel.channelType === type))
+ .map((type) => ALERT_CHANNEL_TYPE_LABELS[type])
+ .join(", ");
+
+export const AlertAction = ({
+ identityId,
+ identityName,
+ projectId,
+ scopeName,
+ readOnly = false,
+ renderPermissionGate
+}: Props) => {
+ const { data: alerts = [] } = useListAlerts({
+ resourceType: AlertResourceType.IdentityAuthentication,
+ resourceId: identityId,
+ ...(projectId ? { projectId } : {})
+ });
+
+ const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp(["alert", "deleteAlert"] as const);
+ const [isSummaryOpen, setIsSummaryOpen] = useState(false);
+ const [deleteConfirmation, setDeleteConfirmation] = useState("");
+ const scopeVariant = useScopeVariant();
+
+ const updateAlert = useUpdateAlert();
+ const deleteAlert = useDeleteAlert();
+
+ const existingAlert = alerts[0] as TAlert | undefined;
+
+ const handleToggleEnabled = async (enabled: boolean) => {
+ if (!existingAlert) return;
+
+ try {
+ await updateAlert.mutateAsync({ alertId: existingAlert.id, enabled });
+ createNotification({ text: `Alert ${enabled ? "enabled" : "disabled"}`, type: "success" });
+ } catch {
+ // MutationCache reports request errors globally.
+ }
+ };
+
+ const handleDeleteAlert = async () => {
+ if (!existingAlert) return;
+
+ try {
+ await deleteAlert.mutateAsync({ alertId: existingAlert.id });
+ createNotification({ text: "Successfully deleted alert", type: "success" });
+ handlePopUpToggle("deleteAlert", false);
+ } catch {
+ // MutationCache reports request errors globally; keep the dialog open.
+ }
+ };
+
+ if (!existingAlert) {
+ if (readOnly) return null;
+
+ return (
+ <>
+ {renderPermissionGate((isAllowed) => (
+ <Button
+ variant="outline"
+ isDisabled={!isAllowed}
+ onClick={() => handlePopUpOpen("alert")}
+ >
+ <BellIcon />
+ Alert
+ </Button>
+ ))}
+ <AddAlertModal
+ isOpen={popUp.alert.isOpen}
+ onOpenChange={(isOpen) => handlePopUpToggle("alert", isOpen)}
+ projectId={projectId}
+ scopeName={scopeName}
+ resourceId={identityId}
+ resourceName={identityName}
+ />
+ </>
+ );
+ }
+
+ const channelSummary = formatChannelSummary(existingAlert);
+
+ return (
+ <>
+ <Popover open={isSummaryOpen} onOpenChange={setIsSummaryOpen}>
+ <PopoverTrigger asChild>
+ <Button variant="outline">
+ <BellIcon />
+ Alert
+ <span
+ aria-hidden
+ className={`size-1.5 rounded-full ${existingAlert.enabled ? "bg-success" : "bg-neutral"}`}
+ />
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent align="end" className="w-96 p-0">
+ <div className="flex flex-col gap-1 p-4">
+ <div className="flex items-center justify-between gap-2">
+ <span className="truncate text-sm font-semibold text-foreground">
+ {existingAlert.name}
+ </span>
+ <Badge variant={existingAlert.enabled ? "success" : "neutral"}>
+ {existingAlert.enabled ? "Active" : "Disabled"}
+ </Badge>
+ </div>
+ <p className="text-sm text-muted">{formatConditionSummary(existingAlert)}</p>
+ {channelSummary && <p className="text-sm text-muted">Notifies {channelSummary}</p>}
+ </div>
+ {!readOnly &&
+ renderPermissionGate((isAllowed) => (
+ <>
+ <div className="flex items-center justify-between border-t border-border px-4 py-3">
+ <Label htmlFor="alert-quick-enable" className="cursor-pointer font-normal">
+ Enabled
+ </Label>
+ <Switch
+ id="alert-quick-enable"
+ variant={scopeVariant}
+ checked={existingAlert.enabled}
+ disabled={!isAllowed || updateAlert.isPending}
+ onCheckedChange={handleToggleEnabled}
+ />
+ </div>
+ <div className="flex items-center justify-between border-t border-border px-4 py-3">
+ <Button
+ variant="outline"
+ size="sm"
+ isDisabled={!isAllowed}
+ onClick={() => {
+ setIsSummaryOpen(false);
+ handlePopUpOpen("alert");
+ }}
+ >
+ Edit Details
+ </Button>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-danger hover:bg-danger/10 hover:text-danger"
+ isDisabled={!isAllowed}
+ onClick={() => {
+ setIsSummaryOpen(false);
+ handlePopUpOpen("deleteAlert");
+ }}
+ >
+ Remove Alert
+ </Button>
+ </div>
+ </>
+ ))}
+ </PopoverContent>
+ </Popover>
+ {!readOnly && (
+ <>
+ <AddAlertModal
+ isOpen={popUp.alert.isOpen}
+ onOpenChange={(isOpen) => handlePopUpToggle("alert", isOpen)}
+ projectId={projectId}
+ scopeName={scopeName}
+ resourceId={identityId}
+ resourceName={identityName}
+ alert={existingAlert}
+ />
+ <AlertDialog
+ open={popUp.deleteAlert.isOpen}
+ onOpenChange={(open) => {
+ if (!open) setDeleteConfirmation("");
+ handlePopUpToggle("deleteAlert", open);
+ }}
+ >
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Remove Alert?</AlertDialogTitle>
+ <AlertDialogDescription>
+ This permanently removes the alert and stops its notifications.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogConfirmationField>
+ <Field>
+ <FieldLabel htmlFor="delete-alert-confirmation" size="sm">
+ <span>
+ Type &quot;<span className="text-foreground">{existingAlert.name}</span>
+ &quot; to confirm.
+ </span>
+ </FieldLabel>
+ <Input
+ id="delete-alert-confirmation"
+ value={deleteConfirmation}
+ onChange={(event) => setDeleteConfirmation(event.target.value)}
+ placeholder={existingAlert.name}
+ autoComplete="off"
+ autoFocus
+ />
+ </Field>
+ </AlertDialogConfirmationField>
+ <Alert variant="danger" appearance="borderless">
+ <AlertDescription>Removing this alert cannot be undone.</AlertDescription>
+ </Alert>
+ <AlertDialogFooter>
+ <AlertDialogCancel isDisabled={deleteAlert.isPending}>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ variant="danger"
+ isPending={deleteAlert.isPending}
+ isDisabled={deleteConfirmation !== existingAlert.name}
+ onClick={(event) => {
+ event.preventDefault();
+ handleDeleteAlert();
+ }}
+ >
+ Remove Alert
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ </>
+ )}
+ </>
+ );
+};
diff --git a/frontend/src/views/Alerts/AlertDetail.tsx b/frontend/src/views/Alerts/AlertDetail.tsx
deleted file mode 100644
index ded8d09b28..0000000000
--- a/frontend/src/views/Alerts/AlertDetail.tsx
+++ /dev/null
@@ -1,168 +0,0 @@
-import { ReactNode } from "react";
-import {
- BanIcon,
- BellPlusIcon,
- CheckIcon,
- MoreHorizontalIcon,
- PencilIcon,
- TrashIcon
-} from "lucide-react";
-
-import { createNotification } from "@app/components/notifications";
-import { DeleteActionModal } from "@app/components/v2";
-import {
- Badge,
- Button,
- Detail,
- DetailLabel,
- DetailValue,
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
- IconButton
-} from "@app/components/v3";
-import { usePopUp } from "@app/hooks";
-import {
- ALERT_EVENT_TYPE_LABELS,
- AlertEventType,
- AlertResourceType,
- formatAlertBefore,
- TAlert,
- useDeleteAlert,
- useListAlerts
-} from "@app/hooks/api/alerts";
-
-import { AddAlertModal } from "./AddAlertModal";
-
-type Props = {
- identityId: string;
- identityName: string;
- // Org-scoped when omitted.
- projectId?: string;
- scopeName?: string;
- // Renders the alert without any way to create, edit or remove it.
- readOnly?: boolean;
- // Wraps the mutating actions in the caller's permission gate (org- or project-scoped), which is the
- // only thing that differs between the org and project entry points.
- renderPermissionGate: (render: (isAllowed: boolean) => ReactNode) => ReactNode;
-};
-
-export const AlertDetail = ({
- identityId,
- identityName,
- projectId,
- scopeName,
- readOnly = false,
- renderPermissionGate
-}: Props) => {
- const { data: alerts = [] } = useListAlerts({
- resourceType: AlertResourceType.IdentityAuthentication,
- resourceId: identityId,
- ...(projectId ? { projectId } : {})
- });
-
- const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp(["alert", "deleteAlert"] as const);
-
- const deleteAlert = useDeleteAlert();
-
- const existingAlert = alerts[0] as TAlert | undefined;
-
- const eventLabel = existingAlert
- ? (ALERT_EVENT_TYPE_LABELS[existingAlert.eventType as AlertEventType] ??
- existingAlert.eventType)
- : "";
- const summary = [eventLabel, formatAlertBefore(existingAlert?.condition?.alertBefore)]
- .filter(Boolean)
- .join(" · ");
-
- const handleDeleteAlert = async () => {
- if (!existingAlert) return;
-
- await deleteAlert.mutateAsync({ alertId: existingAlert.id });
- createNotification({ text: "Successfully deleted alert", type: "success" });
- handlePopUpToggle("deleteAlert", false);
- };
-
- const renderValue = () => {
- if (existingAlert) {
- return (
- <div className="flex w-full items-center gap-2">
- <Badge variant={existingAlert.enabled ? "success" : "neutral"}>
- {existingAlert.enabled ? <CheckIcon /> : <BanIcon />}
- {existingAlert.enabled ? "Enabled" : "Disabled"}
- </Badge>
- <span className="min-w-0 flex-1 truncate text-xs text-muted">{summary}</span>
- {!readOnly &&
- renderPermissionGate((isAllowed) => (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <IconButton
- aria-label="Alert actions"
- isDisabled={!isAllowed}
- variant="ghost"
- size="xs"
- >
- <MoreHorizontalIcon />
- </IconButton>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem onClick={() => handlePopUpOpen("alert")}>
- <PencilIcon />
- Edit
- </DropdownMenuItem>
- <DropdownMenuItem variant="danger" onClick={() => handlePopUpOpen("deleteAlert")}>
- <TrashIcon />
- Remove
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- ))}
- </div>
- );
- }
-
- if (readOnly) {
- return <span className="text-muted">—</span>;
- }
-
- return renderPermissionGate((isAllowed) => (
- <Button
- variant="outline"
- size="xs"
- isDisabled={!isAllowed}
- onClick={() => handlePopUpOpen("alert")}
- >
- <BellPlusIcon />
- Create Alert
- </Button>
- ));
- };
-
- return (
- <Detail>
- <DetailLabel>Alert</DetailLabel>
- <DetailValue>{renderValue()}</DetailValue>
- {!readOnly && (
- <>
- <AddAlertModal
- isOpen={popUp.alert.isOpen}
- onOpenChange={(isOpen) => handlePopUpToggle("alert", isOpen)}
- projectId={projectId}
- scopeName={scopeName}
- resourceId={identityId}
- resourceName={identityName}
- alert={existingAlert}
- />
- <DeleteActionModal
- isOpen={popUp.deleteAlert.isOpen}
- title={`Are you sure you want to delete the alert ${existingAlert?.name ?? ""}?`}
- onChange={(isOpen) => handlePopUpToggle("deleteAlert", isOpen)}
- deleteKey="confirm"
- onDeleteApproved={handleDeleteAlert}
- />
- </>
- )}
- </Detail>
- );
-};
diff --git a/frontend/src/views/Alerts/AlertForm.tsx b/frontend/src/views/Alerts/AlertForm.tsx
index a331bafa05..ac871e195f 100644
--- a/frontend/src/views/Alerts/AlertForm.tsx
+++ b/frontend/src/views/Alerts/AlertForm.tsx
@@ -1,37 +1,30 @@
-import { ReactNode } from "react";
import { Controller, FormProvider, useForm, useWatch } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
-import { CircleHelpIcon, FingerprintIcon, KeyRoundIcon } from "lucide-react";
+import { ClockAlertIcon, KeyRoundIcon } from "lucide-react";
import { createNotification } from "@app/components/notifications";
import {
- Badge,
+ Alert,
+ AlertDescription,
Button,
- Card,
+ Checkbox,
Field,
FieldContent,
FieldError,
FieldLabel,
Input,
Label,
- OrgIcon,
- ProjectIcon,
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
SheetFooter,
- SubOrgIcon,
Switch,
- TextArea,
- Tooltip,
- TooltipContent,
- TooltipTrigger
+ TextArea
} from "@app/components/v3";
import { useScopeVariant } from "@app/hooks";
import {
- ALERT_EVENT_TYPE_LABELS,
ALERT_RESOURCE_TYPE_LABELS,
AlertEventType,
alertFormSchema,
@@ -60,18 +53,8 @@ type Props = {
onCancel: () => void;
};
-const SectionHeader = ({ title }: { title: string }) => (
- <p className="text-[11px] font-medium tracking-wider text-muted uppercase">{title}</p>
-);
-
-const FixedField = ({ label, children }: { label: string; children: ReactNode }) => (
- <div className="flex flex-col gap-1.5">
- <FieldLabel>{label}</FieldLabel>
- <Card className="flex-row items-center gap-3">{children}</Card>
- </div>
-);
-
const DEFAULT_ALERT_BEFORE_DAYS = 7;
+const DEFAULT_ALERT_NAME = "Secret expiration alert";
const toChannelForm = (channel: TAlert["channels"][number]): TChannelForm => ({
id: channel.id,
@@ -91,7 +74,7 @@ const toChannelForm = (channel: TAlert["channels"][number]): TChannelForm => ({
const buildFormDefaults = (alert?: TAlert): TAlertForm => {
if (!alert) {
return {
- name: "",
+ name: DEFAULT_ALERT_NAME,
description: "",
resourceType: AlertResourceType.IdentityAuthentication,
eventType: AlertEventType.IdentityAuthenticationExpiry,
@@ -145,31 +128,12 @@ export const AlertForm = ({
const resourceTypeValue = useWatch({ control, name: "resourceType" });
const isProjectScope = Boolean(projectId);
const isResourceScope = Boolean(resourceId ?? alert?.resourceId);
- const resolveScopeIcon = () => {
- if (isResourceScope) return FingerprintIcon;
- if (isProjectScope) return ProjectIcon;
- if (scopeVariant === "sub-org") return SubOrgIcon;
- return OrgIcon;
- };
- const ScopeIcon = resolveScopeIcon();
- // eslint-disable-next-line no-nested-ternary
- const scopeColor = isProjectScope
- ? "text-project"
- : scopeVariant === "sub-org"
- ? "text-sub-org"
- : "text-org";
// eslint-disable-next-line no-nested-ternary
- const scopeTitle = isResourceScope
- ? `${resourceName ?? "this identity"}`
+ const watchTarget = isResourceScope
+ ? (resourceName ?? "this machine identity")
: isProjectScope
- ? `Project · ${scopeName ?? "this project"}`
- : "Organization";
- // eslint-disable-next-line no-nested-ternary
- const scopeDescription = isResourceScope
- ? "Watches this machine identity's authentications"
- : isProjectScope
- ? "Watches every machine identity authentication in this project"
- : "Watches every machine identity authentication in this organization";
+ ? `every machine identity in ${scopeName ?? "this project"}`
+ : `every machine identity in this ${scopeVariant === "sub-org" ? "sub-organization" : "organization"}`;
const onSubmit = async (data: TAlertForm) => {
const condition = {
@@ -215,209 +179,150 @@ export const AlertForm = ({
noValidate
className="flex min-h-0 flex-1 flex-col overflow-y-auto"
>
- <div className="flex flex-col gap-8 p-4">
- <section className="flex flex-col gap-4">
- <SectionHeader title="Details" />
- <Field>
- <FieldLabel htmlFor="alert-name">Name</FieldLabel>
- <FieldContent>
- <Input
- id="alert-name"
- autoFocus
- placeholder="Secret Expiration Alert"
- isError={Boolean(errors.name)}
- {...register("name")}
- />
- <FieldError errors={[errors.name]} />
- </FieldContent>
- </Field>
+ <div className="flex flex-col gap-5 p-4">
+ <Field>
+ <FieldLabel htmlFor="alert-name">Name</FieldLabel>
+ <FieldContent>
+ <Input
+ id="alert-name"
+ autoFocus
+ placeholder={DEFAULT_ALERT_NAME}
+ isError={Boolean(errors.name)}
+ {...register("name")}
+ />
+ <FieldError errors={[errors.name]} />
+ </FieldContent>
+ </Field>
- <Field>
- <FieldLabel htmlFor="alert-description">
- Description <span className="text-muted">(optional)</span>
- </FieldLabel>
- <FieldContent>
- <TextArea
- id="alert-description"
- rows={2}
- className="resize-none"
- placeholder="What this alert is for"
- isError={Boolean(errors.description)}
- {...register("description")}
- />
- <FieldError errors={[errors.description]} />
- </FieldContent>
- </Field>
- </section>
+ <Field>
+ <FieldLabel htmlFor="alert-description">
+ Description <span className="text-muted">(optional)</span>
+ </FieldLabel>
+ <FieldContent>
+ <TextArea
+ id="alert-description"
+ rows={3}
+ placeholder="What is this alert for?"
+ isError={Boolean(errors.description)}
+ {...register("description")}
+ />
+ <FieldError errors={[errors.description]} />
+ </FieldContent>
+ </Field>
- <section className="flex flex-col gap-4">
- <SectionHeader title="Trigger" />
+ <Alert className="items-start [&>svg]:mt-0.5 [&>svg]:text-info">
+ <ClockAlertIcon />
+ <AlertDescription>
+ <span>
+ Watching <span className="font-medium text-foreground">{watchTarget}</span> ·
+ Universal Auth client secret expiration
+ </span>
+ </AlertDescription>
+ </Alert>
+ <Controller
+ control={control}
+ name="enabled"
+ render={({ field }) => (
+ <Label
+ htmlFor="alert-enabled"
+ className="cursor-pointer justify-between rounded-md border border-border px-3 py-2.5 font-normal"
+ >
+ Enabled
+ <Switch
+ id="alert-enabled"
+ variant={scopeVariant}
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </Label>
+ )}
+ />
+
+ {!isResourceScope && (
<Controller
control={control}
name="resourceType"
- render={({ field: { value, onChange } }) =>
- isResourceScope ? (
- <FixedField label="Resource type">
- <KeyRoundIcon className="size-5 text-muted" />
- <div className="flex items-center gap-2">
- <span className="text-sm text-foreground">
- {ALERT_RESOURCE_TYPE_LABELS[value]}
- </span>
- <span className="font-mono text-xs text-muted">{value}</span>
- </div>
- </FixedField>
- ) : (
- <Field>
- <FieldLabel>Resource type</FieldLabel>
- <FieldContent>
- <Select value={value} onValueChange={onChange}>
- <SelectTrigger className="w-full">
- <SelectValue />
- </SelectTrigger>
- <SelectContent position="popper">
- {Object.values(AlertResourceType).map((resourceType) => (
- <SelectItem key={resourceType} value={resourceType}>
- <span className="flex items-center gap-2">
- <KeyRoundIcon className="size-4 text-muted" />
- <span className="font-medium">
- {ALERT_RESOURCE_TYPE_LABELS[resourceType]}
- </span>
- <span className="font-mono text-xs text-muted">{resourceType}</span>
+ render={({ field: { value, onChange } }) => (
+ <Field>
+ <FieldLabel>Resource type</FieldLabel>
+ <FieldContent>
+ <Select value={value} onValueChange={onChange}>
+ <SelectTrigger className="w-full">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent position="popper">
+ {Object.values(AlertResourceType).map((resourceType) => (
+ <SelectItem key={resourceType} value={resourceType}>
+ <span className="flex items-center gap-2">
+ <KeyRoundIcon className="size-4 text-muted" />
+ <span className="font-medium">
+ {ALERT_RESOURCE_TYPE_LABELS[resourceType]}
</span>
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- </FieldContent>
- </Field>
- )
- }
- />
-
- <FixedField label="Scope">
- <ScopeIcon className={`size-5 ${scopeColor}`} />
- <div className="flex items-center gap-2">
- <span className="text-sm text-foreground">{scopeTitle}</span>
- <span className="text-xs text-muted">{scopeDescription}</span>
- </div>
- </FixedField>
-
- <Controller
- control={control}
- name="eventType"
- render={({ field: { value } }) => (
- <FixedField label="Event">
- <Badge variant="warning">{ALERT_EVENT_TYPE_LABELS[value]}</Badge>
- <div className="flex flex-col gap-0.5">
- <span className="text-sm text-foreground">
- Alerts before a credential expires.
- </span>
- <span className="text-xs text-muted">
- Supports Universal Auth client secrets with a TTL. More credential types
- coming.
- </span>
- </div>
- </FixedField>
+ <span className="font-mono text-xs text-muted">{resourceType}</span>
+ </span>
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </FieldContent>
+ </Field>
)}
/>
+ )}
- <div className="flex flex-col gap-1.5">
- <FieldLabel htmlFor="alert-alert-before">Condition</FieldLabel>
- <div className="grid grid-cols-[auto_auto_1fr] items-center gap-x-3 gap-y-1 text-sm text-muted">
- <span>Alert me</span>
- <Input
- id="alert-alert-before"
- type="number"
- min={MIN_ALERT_BEFORE_DAYS}
- max={MAX_ALERT_BEFORE_DAYS}
- className="w-20 text-center"
- isError={Boolean(errors.alertBeforeDays)}
- {...register("alertBeforeDays", { valueAsNumber: true })}
- />
- <span>days before the credential expires. (1-90)</span>
- {errors.alertBeforeDays && (
- <div className="col-start-2 flex w-0 justify-self-center">
- <FieldError
- errors={[errors.alertBeforeDays]}
- className="shrink-0 -translate-x-1/2 whitespace-nowrap"
- />
- </div>
- )}
- </div>
+ <div className="mb-1 flex flex-col gap-1.5">
+ <Label htmlFor="alert-alert-before">Condition</Label>
+ <div className="mt-1 flex flex-wrap items-center gap-3 text-sm text-foreground">
+ <span>Alert</span>
+ <Input
+ id="alert-alert-before"
+ type="number"
+ min={MIN_ALERT_BEFORE_DAYS}
+ max={MAX_ALERT_BEFORE_DAYS}
+ className="w-16 text-center"
+ isError={Boolean(errors.alertBeforeDays)}
+ {...register("alertBeforeDays", { valueAsNumber: true })}
+ />
+ <span>days before a client secret expires</span>
</div>
-
+ <FieldError errors={[errors.alertBeforeDays]} />
<Controller
control={control}
name="dailyReminder"
render={({ field }) => (
- <div className="flex items-center gap-2">
- <FieldLabel htmlFor="alert-repeat-daily" className="cursor-pointer">
- Daily Reminder
- </FieldLabel>
- <Tooltip>
- <TooltipTrigger asChild>
- <CircleHelpIcon className="size-3.5 text-muted" />
- </TooltipTrigger>
- <TooltipContent>
- Send a reminder every day from the alert threshold until the event happens
- </TooltipContent>
- </Tooltip>
- <Switch
+ <Label htmlFor="alert-repeat-daily" className="cursor-pointer font-normal">
+ <Checkbox
id="alert-repeat-daily"
variant={scopeVariant}
- checked={field.value}
- onCheckedChange={field.onChange}
+ isChecked={field.value}
+ onCheckedChange={(checked) => field.onChange(checked === true)}
/>
- </div>
+ Repeat daily until the secret is rotated
+ </Label>
)}
/>
- </section>
+ </div>
- <section className="flex flex-col gap-4">
- <SectionHeader title="Delivery" />
- <ChannelsField
- projectId={projectId}
- resourceType={resourceTypeValue}
- resourceId={resourceId ?? alert?.resourceId ?? null}
- />
- </section>
+ <ChannelsField
+ projectId={projectId}
+ resourceType={resourceTypeValue}
+ resourceId={resourceId ?? alert?.resourceId ?? null}
+ />
</div>
<SheetFooter className="sticky bottom-0 border-t bg-popover">
- <div className="flex w-full items-center justify-between">
- <div className="flex items-center gap-2">
- <Button
- type="submit"
- variant={scopeVariant}
- isPending={isSubmitting}
- isDisabled={isSubmitting}
- >
- {isEditing ? "Update Alert" : "Create Alert"}
- </Button>
- <Button type="button" variant="outline" onClick={onCancel} isDisabled={isSubmitting}>
- Cancel
- </Button>
- </div>
- <Controller
- control={control}
- name="enabled"
- render={({ field }) => (
- <Label
- htmlFor="alert-enabled"
- className="cursor-pointer text-sm font-normal text-muted"
- >
- Enabled
- <Switch
- id="alert-enabled"
- variant={scopeVariant}
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </Label>
- )}
- />
- </div>
+ <Button
+ type="submit"
+ variant={scopeVariant}
+ isPending={isSubmitting}
+ isDisabled={isSubmitting}
+ >
+ {isEditing ? "Update Alert" : "Create Alert"}
+ </Button>
+ <Button type="button" variant="outline" onClick={onCancel} isDisabled={isSubmitting}>
+ Cancel
+ </Button>
</SheetFooter>
</form>
</FormProvider>
diff --git a/frontend/src/views/Alerts/ChannelCard.tsx b/frontend/src/views/Alerts/ChannelCard.tsx
index a50784e723..d5b4145a42 100644
--- a/frontend/src/views/Alerts/ChannelCard.tsx
+++ b/frontend/src/views/Alerts/ChannelCard.tsx
@@ -10,7 +10,6 @@ import {
FieldLabel,
IconButton,
Input,
- Label,
Switch
} from "@app/components/v3";
import { useScopeVariant } from "@app/hooks";
@@ -121,18 +120,12 @@ export const ChannelCard = ({
control={control}
name={`channels.${index}.enabled`}
render={({ field }) => (
- <Label
- htmlFor={`channel-${index}-enabled`}
- className="cursor-pointer text-xs font-normal text-muted"
- >
- Enabled
- <Switch
- id={`channel-${index}-enabled`}
- variant={scopeVariant}
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </Label>
+ <Switch
+ aria-label={`Toggle ${channelLabel} channel`}
+ variant={scopeVariant}
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
)}
/>
{canRemove && (
@@ -143,19 +136,6 @@ export const ChannelCard = ({
</div>
</div>
- <Field>
- <FieldLabel htmlFor={`channel-${index}-name`}>Name</FieldLabel>
- <FieldContent>
- <Input
- id={`channel-${index}-name`}
- placeholder="Notify on-call"
- isError={Boolean(channelErrors?.name)}
- {...register(`channels.${index}.name`)}
- />
- <FieldError errors={[channelErrors?.name]} />
- </FieldContent>
- </Field>
-
{channelType === AlertChannelType.Email && (
<Field>
<FieldLabel>Recipients</FieldLabel>
diff --git a/frontend/src/views/Alerts/ChannelRecipientsField.tsx b/frontend/src/views/Alerts/ChannelRecipientsField.tsx
index cedae77436..7e78761e69 100644
--- a/frontend/src/views/Alerts/ChannelRecipientsField.tsx
+++ b/frontend/src/views/Alerts/ChannelRecipientsField.tsx
@@ -87,7 +87,7 @@ const RecipientSelect = ({
<div ref={containerRef}>
<FilterableSelect<RecipientOption>
isMulti
- placeholder="Select users or groups..."
+ placeholder="Add users or groups..."
options={options}
value={selected}
isError={isError}
diff --git a/frontend/src/views/Alerts/ChannelsField.tsx b/frontend/src/views/Alerts/ChannelsField.tsx
index a1bcee8045..08db2f0171 100644
--- a/frontend/src/views/Alerts/ChannelsField.tsx
+++ b/frontend/src/views/Alerts/ChannelsField.tsx
@@ -7,7 +7,7 @@ import {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
- FieldLabel
+ Label
} from "@app/components/v3";
import {
ALERT_CHANNEL_TYPE_LABELS,
@@ -28,7 +28,8 @@ type Props = {
const buildNewChannel = (channelType: AlertChannelType): TChannelForm => ({
channelType,
- name: "",
+ // The name input was dropped from the design; new channels are named after their type.
+ name: ALERT_CHANNEL_TYPE_LABELS[channelType],
enabled: true,
recipients: [] as { principalType: AlertPrincipalType; principalId: string }[],
webhookUrl: "",
@@ -48,10 +49,10 @@ export const ChannelsField = ({ projectId, resourceType, resourceId }: Props) =>
return (
<div className="flex flex-col gap-3">
<div className="flex items-center justify-between">
- <div className="flex flex-col">
- <FieldLabel>
+ <div className="flex flex-col gap-1">
+ <Label>
Channels <span className="text-danger">*</span>
- </FieldLabel>
+ </Label>
<span className="text-xs text-muted">Add at least one delivery channel.</span>
</div>
<DropdownMenu>
diff --git a/frontend/src/views/Alerts/index.ts b/frontend/src/views/Alerts/index.ts
index b0b1d6ebf6..68fe73c77e 100644
--- a/frontend/src/views/Alerts/index.ts
+++ b/frontend/src/views/Alerts/index.ts
@@ -1,2 +1,2 @@
export { AddAlertModal } from "./AddAlertModal";
-export { AlertDetail } from "./AlertDetail";
+export { AlertAction } from "./AlertAction";