Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: add dismissable alert component, stories, storage and usage
Scott Wilsond36c209d3b70
diff --git a/frontend/src/components/v3/generic/Alert/DismissableAlert.stories.tsx b/frontend/src/components/v3/generic/Alert/DismissableAlert.stories.tsxnew file mode 100644index 0000000000..f8debc4c68--- /dev/null+++ b/frontend/src/components/v3/generic/Alert/DismissableAlert.stories.tsx@@ -0,0 +1,142 @@+import * as React from "react";+import type { Decorator, Meta, StoryObj } from "@storybook/react-vite";+import { InfoIcon, TriangleAlertIcon } from "lucide-react";++import { AlertDescription, AlertTitle } from "./Alert";+import { DismissableAlert } from "./DismissableAlert";++const getStorageKey = (actionKey: string) => `infisical:dismissed-alert:${actionKey}`;++const withSeededDismissal = (actionKey: string, dismissed = false): Decorator =>+ function SeededDismissalDecorator(Story) {+ const storageKey = getStorageKey(actionKey);+ if (dismissed) {+ localStorage.setItem(storageKey, "true");+ } else {+ localStorage.removeItem(storageKey);+ }++ React.useEffect(() => () => localStorage.removeItem(storageKey), [storageKey]);++ return <Story />;+ };++/**+ * An Alert the user can permanently dismiss. The dismissal is persisted per+ * browser profile through local storage, so the notice stays hidden across+ * reloads on that browser. Dismissing collapses the alert with the standard+ * 200ms motion before it unmounts.+ *+ * These stories seed local storage so each renders deterministically.+ */+const meta = {+ title: "Generic/DismissableAlert",+ component: DismissableAlert,+ parameters: {+ layout: "centered"+ },+ tags: ["autodocs"],+ argTypes: {+ variant: {+ control: "select",+ options: ["default", "info", "success", "warning", "danger", "project", "org", "sub-org"]+ },+ actionKey: {+ control: false+ },+ children: {+ table: {+ disable: true+ }+ },+ className: {+ table: {+ disable: true+ }+ }+ },+ args: {+ className: "w-[500px]"+ }+} satisfies Meta<typeof DismissableAlert>;++export default meta;+type Story = StoryObj<typeof meta>;++export const MigrationNotice: Story = {+ name: "Example: Migration Notice",+ args: {+ variant: "info",+ actionKey: "storybook_migration_notice_dismissed"+ },+ decorators: [withSeededDismissal("storybook_migration_notice_dismissed")],+ parameters: {+ docs: {+ description: {+ story:+ "The primary use case: a one-time notice the user reads and closes. Click the X to play the dismissal collapse; in the app the dismissal also persists, so the notice never returns."+ }+ }+ },+ render: (args) => (+ <DismissableAlert {...args}>+ <InfoIcon />+ <AlertTitle>Secret Sharing Has Moved</AlertTitle>+ <AlertDescription>+ Secret Sharing now lives in its own product tab in the sidebar.+ </AlertDescription>+ </DismissableAlert>+ )+};++export const Warning: Story = {+ name: "Variant: Warning",+ args: {+ variant: "warning",+ actionKey: "storybook_warning_notice_dismissed"+ },+ decorators: [withSeededDismissal("storybook_warning_notice_dismissed")],+ parameters: {+ docs: {+ description: {+ story:+ "Every Alert variant passes through. Reserve dismissable warnings for one-time notices; a state the user must resolve should stay permanent instead."+ }+ }+ },+ render: (args) => (+ <DismissableAlert {...args}>+ <TriangleAlertIcon />+ <AlertTitle>Service tokens are deprecated.</AlertTitle>+ <AlertDescription>+ Existing tokens keep working, but new integrations should use machine identities.+ </AlertDescription>+ </DismissableAlert>+ )+};++export const AlreadyDismissed: Story = {+ name: "Example: Already Dismissed",+ args: {+ variant: "info",+ actionKey: "storybook_already_dismissed_notice"+ },+ decorators: [withSeededDismissal("storybook_already_dismissed_notice", true)],+ parameters: {+ docs: {+ description: {+ story:+ "Once the local-storage entry exists (seeded here), the component renders nothing at all: no reserved space, no placeholder. The dashed frame is story chrome to make the absence visible."+ }+ }+ },+ render: (args) => (+ <div className="w-[500px] rounded-md border border-dashed border-border p-3 text-xs text-foreground/50">+ Already-dismissed notices render nothing:+ <DismissableAlert {...args}>+ <InfoIcon />+ <AlertTitle>You should never see this notice.</AlertTitle>+ </DismissableAlert>+ </div>+ )+};diff --git a/frontend/src/components/v3/generic/Alert/DismissableAlert.tsx b/frontend/src/components/v3/generic/Alert/DismissableAlert.tsxnew file mode 100644index 0000000000..15ffc6fb06--- /dev/null+++ b/frontend/src/components/v3/generic/Alert/DismissableAlert.tsx@@ -0,0 +1,120 @@+/* eslint-disable react/prop-types */++import * as React from "react";+import { XIcon } from "lucide-react";++import { cn } from "../../utils";+import { AnimatedCollapse } from "../AnimatedCollapse";+import { IconButton } from "../IconButton";+import { Alert, AlertDescription, AlertTitle } from "./Alert";++type DismissableAlertProps = React.ComponentProps<typeof Alert> & {+ /**+ * The identifier used to persist the dismissal in local storage. Must be+ * unique per banner so dismissals don't collide.+ */+ actionKey: string;+ title?: React.ReactNode;+ description?: React.ReactNode;+};++const DISMISSED_ALERT_STORAGE_PREFIX = "infisical:dismissed-alert:";++const getDismissedAlertStorageKey = (actionKey: string) =>+ `${DISMISSED_ALERT_STORAGE_PREFIX}${actionKey}`;++const isAlertDismissed = (actionKey: string) => {+ if (typeof window === "undefined") return false;++ try {+ return window.localStorage.getItem(getDismissedAlertStorageKey(actionKey)) !== null;+ } catch {+ return false;+ }+};++const persistAlertDismissal = (actionKey: string) => {+ if (typeof window === "undefined") return;++ try {+ window.localStorage.setItem(getDismissedAlertStorageKey(actionKey), "true");+ } catch {+ // The in-memory state still dismisses the alert for the current session.+ }+};++/**+ * A `variant="info"` (or any variant) informational Alert that a user can+ * permanently dismiss. Dismissal is persisted in local storage, so the notice+ * stays hidden across reloads in the current browser profile once closed.+ *+ * Pass `children` for full control over the Alert body (icon + title ++ * description, links, etc.), or the convenience `title`/`description` props for+ * simple notices. The close affordance is rendered by this wrapper — the shared+ * `Alert` primitive is left untouched.+ */+function DismissableAlert({+ actionKey,+ title,+ description,+ children,+ className,+ ...props+}: DismissableAlertProps) {+ const [isDismissing, setIsDismissing] = React.useState(false);+ const [isLocallyDismissed, setIsLocallyDismissed] = React.useState(() =>+ isAlertDismissed(actionKey)+ );++ const handleDismiss = () => {+ persistAlertDismissal(actionKey);+ // Under prefers-reduced-motion the collapse transition never runs, so its+ // end event never fires; unmount immediately instead.+ if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {+ setIsLocallyDismissed(true);+ return;+ }+ setIsDismissing(true);+ };++ if (isLocallyDismissed) {+ return null;+ }++ return (+ <AnimatedCollapse+ isOpen={!isDismissing}+ onTransitionEnd={(event) => {+ // transitionend bubbles and fires once per property; unmount only when+ // the wrapper's own row collapse completes.+ if (+ isDismissing &&+ event.target === event.currentTarget &&+ event.propertyName === "grid-template-rows"+ ) {+ setIsLocallyDismissed(true);+ }+ }}+ >+ <Alert className={cn("pr-10", className)} {...props}>+ {children ?? (+ <>+ {title && <AlertTitle>{title}</AlertTitle>}+ {description && <AlertDescription>{description}</AlertDescription>}+ </>+ )}+ <IconButton+ variant="ghost"+ size="xs"+ aria-label="Dismiss notice"+ onClick={handleDismiss}+ className="absolute top-2 right-2 text-current"+ >+ <XIcon />+ </IconButton>+ </Alert>+ </AnimatedCollapse>+ );+}++export { DismissableAlert };diff --git a/frontend/src/components/v3/generic/Alert/index.ts b/frontend/src/components/v3/generic/Alert/index.tsindex b8e17a03c9..764c37412a 100644--- a/frontend/src/components/v3/generic/Alert/index.ts+++ b/frontend/src/components/v3/generic/Alert/index.ts@@ -1 +1,2 @@export * from "./Alert";+export * from "./DismissableAlert";diff --git a/frontend/src/pages/organization/IntegrationsPage/IntegrationsPage.tsx b/frontend/src/pages/organization/IntegrationsPage/IntegrationsPage.tsxindex 6893cfca8f..aeb2288373 100644--- a/frontend/src/pages/organization/IntegrationsPage/IntegrationsPage.tsx+++ b/frontend/src/pages/organization/IntegrationsPage/IntegrationsPage.tsx@@ -3,7 +3,7 @@ import { useNavigate, useSearch } from "@tanstack/react-router";import { InfoIcon } from "lucide-react";import { PageHeader, Tab, TabList, TabPanel, Tabs } from "@app/components/v2";-import { Alert, AlertTitle } from "@app/components/v3";+import { AlertTitle, DismissableAlert } from "@app/components/v3";import { ROUTE_PATHS } from "@app/const/routes";import { useOrganization } from "@app/context";import {@@ -19,12 +19,16 @@ import { IntegrationsListPageTabs } from "@app/types/integrations";const AppConnectionsTab = withPermission(() => (<>- <Alert variant="info" className="mb-4">+ <DismissableAlert+ variant="info"+ className="mb-4"+ actionKey="app_connections_project_scope_banner_dismissed"+ ><InfoIcon /><AlertTitle>App connections can also be created and managed independently in projects now.</AlertTitle>- </Alert>+ </DismissableAlert><AppConnectionsTable /></>),diff --git a/frontend/src/pages/organization/ProjectsPage/ProjectsPage.tsx b/frontend/src/pages/organization/ProjectsPage/ProjectsPage.tsxindex dfa73987ee..0f85189f54 100644--- a/frontend/src/pages/organization/ProjectsPage/ProjectsPage.tsx+++ b/frontend/src/pages/organization/ProjectsPage/ProjectsPage.tsx@@ -7,7 +7,7 @@ import { InfoIcon } from "lucide-react";import { AnnouncementModal } from "@app/components/announcements/AnnouncementModal";import { useAnnouncementSeen } from "@app/components/announcements/useAnnouncementSeen";import { PageHeader } from "@app/components/v2";-import { Alert, AlertDescription, AlertTitle } from "@app/components/v3";+import { AlertDescription, AlertTitle, DismissableAlert } from "@app/components/v3";import { useOrganization } from "@app/context";import { useGetRecentAnnouncements } from "@app/hooks/api/announcement";@@ -55,7 +55,11 @@ export const ProjectsPage = () => {title={`${isSubOrganization ? "Sub-Organization" : "Organization"} Overview`}description="Your team's complete security toolkit — organized and ready when you need them."/>- <Alert variant="info" className="mb-6">+ <DismissableAlert+ variant="info"+ className="mb-6"+ actionKey="secret_sharing_moved_banner_dismissed"+ ><InfoIcon /><AlertTitle>Secret Sharing Has Moved</AlertTitle><AlertDescription>@@ -71,7 +75,7 @@ export const ProjectsPage = () => {.</p></AlertDescription>- </Alert>+ </DismissableAlert><ProjectCategoryOverview />{announcements && announcements.length > 0 && (<AnnouncementModaldiff --git a/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/OrgProductSettingsTab.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/OrgProductSettingsTab.tsxindex b3ac381cbe..480ee168b4 100644--- a/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/OrgProductSettingsTab.tsx+++ b/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/OrgProductSettingsTab.tsx@@ -1,7 +1,7 @@import { Link } from "@tanstack/react-router";import { InfoIcon } from "lucide-react";-import { Alert, AlertDescription, AlertTitle } from "@app/components/v3";+import { AlertDescription, AlertTitle, DismissableAlert } from "@app/components/v3";import { useOrganization } from "@app/context";import { OrgCertManagerTab } from "../OrgCertManagerTab";@@ -11,7 +11,10 @@ export const OrgProductSettingsTab = () => {return (<div className="flex flex-col gap-4">- <Alert variant="info">+ <DismissableAlert+ variant="info"+ actionKey="secrets_management_settings_moved_banner_dismissed"+ ><InfoIcon /><AlertTitle>Secrets Management Settings Have Moved</AlertTitle><AlertDescription className="inline">@@ -25,7 +28,7 @@ export const OrgProductSettingsTab = () => {</Link>.</AlertDescription>- </Alert>+ </DismissableAlert><OrgCertManagerTab /></div>);diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgTabGroup/OrgTabGroup.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgTabGroup/OrgTabGroup.tsxindex 5345dd6488..f95331c3f0 100644--- a/frontend/src/pages/organization/SettingsPage/components/OrgTabGroup/OrgTabGroup.tsx+++ b/frontend/src/pages/organization/SettingsPage/components/OrgTabGroup/OrgTabGroup.tsx@@ -4,7 +4,7 @@ import { Link, useSearch } from "@tanstack/react-router";import { InfoIcon } from "lucide-react";import { PageHeader, TabPanel, Tabs } from "@app/components/v2";-import { Alert, AlertDescription, AlertTitle } from "@app/components/v3";+import { AlertDescription, AlertTitle, DismissableAlert } from "@app/components/v3";import { ROUTE_PATHS } from "@app/const/routes";import { useOrganization, useSubscription } from "@app/context";@@ -110,7 +110,11 @@ export const OrgTabGroup = () => {)}</PageHeader>{selectedTab === "tab-org-general" && (- <Alert variant="info" className="mb-6">+ <DismissableAlert+ variant="info"+ className="mb-6"+ actionKey="org_general_settings_moved_banner_dismissed"+ ><InfoIcon /><AlertTitle>Some Settings Have Moved</AlertTitle><AlertDescription>@@ -135,7 +139,7 @@ export const OrgTabGroup = () => {.</p></AlertDescription>- </Alert>+ </DismissableAlert>)}<Tabs orientation="vertical" value={selectedTab}>{visibleTabsdiff --git a/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/ProjectTemplatesTab.tsx b/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/ProjectTemplatesTab.tsxindex 53c8726f0c..8afb1349f4 100644--- a/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/ProjectTemplatesTab.tsx+++ b/frontend/src/pages/organization/SettingsPage/components/ProjectTemplatesTab/ProjectTemplatesTab.tsx@@ -1,7 +1,7 @@import { Link } from "@tanstack/react-router";import { InfoIcon } from "lucide-react";-import { Alert, AlertDescription, AlertTitle } from "@app/components/v3";+import { AlertDescription, AlertTitle, DismissableAlert } from "@app/components/v3";import { OrgPermissionActions, OrgPermissionSubjects, useOrganization } from "@app/context";import { withPermission } from "@app/hoc";@@ -13,7 +13,10 @@ export const ProjectTemplatesTab = withPermission(return (<div className="flex flex-col gap-4">- <Alert variant="info">+ <DismissableAlert+ variant="info"+ actionKey="secret_management_templates_moved_banner_dismissed"+ ><InfoIcon /><AlertTitle>Secret Management Templates Have Moved</AlertTitle><AlertDescription className="inline">@@ -27,7 +30,7 @@ export const ProjectTemplatesTab = withPermission(</Link>.</AlertDescription>- </Alert>+ </DismissableAlert><ProjectTemplatesSection /></div>);