Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(control-ui): persist admin email banner dismissal across remounts

Mfdcac41cb79b
diff --git a/control-ui/components/AdminBridgeAlerts/index.tsx b/control-ui/components/AdminBridgeAlerts/index.tsx
index 3f82517f0..dcc34aef3 100644
--- a/control-ui/components/AdminBridgeAlerts/index.tsx
+++ b/control-ui/components/AdminBridgeAlerts/index.tsx
@@ -107,7 +107,7 @@ export function AdminBridgeAlerts() {
setAlert(null)
}
- function remindLater() {
+ function dismissForNow() {
window.localStorage.setItem(
storageKey(alert.kind, alert.status.admin.id, 'snooze'),
String(Date.now() + REMIND_LATER_MS)
@@ -163,7 +163,7 @@ export function AdminBridgeAlerts() {
<button
type="button"
className="cu-account-alert__close"
- onClick={closeAlert}
+ onClick={dismissForNow}
aria-label="Close account alert"
>
<IconX width={16} height={16} />
@@ -178,7 +178,7 @@ export function AdminBridgeAlerts() {
>
{copy.primaryLabel}
</button>
- <button type="button" className="cu-btn cu-btn--ghost cu-btn--sm" onClick={remindLater}>
+ <button type="button" className="cu-btn cu-btn--ghost cu-btn--sm" onClick={dismissForNow}>
Remind me later
</button>
<button
diff --git a/control-ui/components/__tests__/AdminBridgeAlerts.test.tsx b/control-ui/components/__tests__/AdminBridgeAlerts.test.tsx
new file mode 100644
index 000000000..6daf39187
--- /dev/null
+++ b/control-ui/components/__tests__/AdminBridgeAlerts.test.tsx
@@ -0,0 +1,150 @@
+import React from 'react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
+import type { ControlAdminBridgeStatus } from '../../lib/api'
+import { AdminBridgeAlerts, resetControlAdminBridgeAlerts } from '../AdminBridgeAlerts'
+
+const pushMock = vi.fn()
+const bridgeStatusMock = vi.fn()
+
+vi.mock('next/navigation', () => ({
+ useRouter: () => ({ push: pushMock }),
+}))
+
+vi.mock('@lib/api', async importOriginal => {
+ const actual = await importOriginal<typeof import('../../lib/api')>()
+ return {
+ ...actual,
+ getControlAdminBridgeStatus: () => bridgeStatusMock() as Promise<ControlAdminBridgeStatus>,
+ }
+})
+
+vi.mock('@components/AuthContext', () => ({
+ useAuth: () => ({
+ authState: { id: 'admin-1', isLoggedIn: true, isLoading: false, username: 'admin', email: '' },
+ }),
+}))
+
+const SNOOZE_KEY = 'control-admin-bridge-alert:admin-1:email:snooze'
+const DISMISSED_KEY = 'control-admin-bridge-alert:admin-1:email:dismissed'
+const REMIND_LATER_MS = 4 * 60 * 60 * 1000
+
+function emailPendingStatus(): ControlAdminBridgeStatus {
+ return {
+ admin: {
+ id: 'admin-1',
+ username: 'admin',
+ email: null,
+ emailConfirmed: false,
+ pendingEmailChange: null,
+ },
+ member: { id: 'member-1', email: '[email protected]' },
+ }
+}
+
+function renderAlerts() {
+ return render(<AdminBridgeAlerts />)
+}
+
+async function renderAndWaitForBanner() {
+ const view = renderAlerts()
+ await waitFor(() =>
+ expect(screen.getByRole('status')).toHaveTextContent('Set up your admin email')
+ )
+ return view
+}
+
+describe('AdminBridgeAlerts dismissal persistence', () => {
+ beforeEach(() => {
+ vi.clearAllMocks()
+ window.localStorage.clear()
+ bridgeStatusMock.mockResolvedValue(emailPendingStatus())
+ })
+
+ afterEach(() => {
+ cleanup()
+ window.localStorage.clear()
+ vi.useRealTimers()
+ })
+
+ it('shows the admin email setup banner when no email is set', async () => {
+ await renderAndWaitForBanner()
+ expect(screen.getByText('Set up your admin email')).toBeVisible()
+ })
+
+ it('persists the X-button dismissal across remounts via the snooze key', async () => {
+ const view = await renderAndWaitForBanner()
+
+ fireEvent.click(screen.getByRole('button', { name: 'Close account alert' }))
+ await waitFor(() => expect(screen.queryByRole('status')).toBeNull())
+
+ const snoozeUntil = Number(window.localStorage.getItem(SNOOZE_KEY))
+ expect(Number.isFinite(snoozeUntil)).toBe(true)
+ expect(snoozeUntil).toBeGreaterThan(Date.now())
+
+ view.unmount()
+ renderAlerts()
+ await waitFor(() => expect(bridgeStatusMock).toHaveBeenCalledTimes(2))
+ await act(async () => {})
+ expect(screen.queryByRole('status')).toBeNull()
+ expect(screen.queryByText('Set up your admin email')).toBeNull()
+ })
+
+ it('snoozes for the remind-later window and resurfaces after it expires', async () => {
+ vi.useFakeTimers({ toFake: ['Date'] })
+ vi.setSystemTime(new Date('2026-01-01T08:00:00Z'))
+ const view = await renderAndWaitForBanner()
+
+ fireEvent.click(screen.getByRole('button', { name: 'Remind me later', exact: true }))
+ await waitFor(() => expect(screen.queryByRole('status')).toBeNull())
+ expect(Number(window.localStorage.getItem(SNOOZE_KEY))).toBe(Date.now() + REMIND_LATER_MS)
+
+ view.unmount()
+ renderAlerts()
+ await waitFor(() => expect(bridgeStatusMock).toHaveBeenCalledTimes(2))
+ await act(async () => {})
+ expect(screen.queryByText('Set up your admin email')).toBeNull()
+
+ vi.setSystemTime(new Date('2026-01-01T13:00:01Z'))
+ const second = renderAlerts()
+ await waitFor(() => expect(bridgeStatusMock).toHaveBeenCalledTimes(3))
+ await waitFor(() =>
+ expect(screen.getByRole('status')).toHaveTextContent('Set up your admin email')
+ )
+ second.unmount()
+ })
+
+ it('keeps the banner hidden permanently after confirming do-not-show-again', async () => {
+ await renderAndWaitForBanner()
+
+ fireEvent.click(screen.getByRole('button', { name: "Don't show again" }))
+ const dialog = await screen.findByRole('alertdialog')
+ fireEvent.click(within(dialog).getByRole('button', { name: "Don't show again" }))
+ await waitFor(() => expect(screen.queryByRole('status')).toBeNull())
+ expect(window.localStorage.getItem(DISMISSED_KEY)).toBe('true')
+
+ cleanup()
+ renderAlerts()
+ await waitFor(() => expect(bridgeStatusMock).toHaveBeenCalledTimes(2))
+ await act(async () => {})
+ expect(screen.queryByText('Set up your admin email')).toBeNull()
+ })
+
+ it('clears overrides and shows the banner again after a reset event', async () => {
+ const view = await renderAndWaitForBanner()
+ fireEvent.click(screen.getByRole('button', { name: 'Close account alert' }))
+ await waitFor(() => expect(screen.queryByRole('status')).toBeNull())
+ view.unmount()
+
+ const second = renderAlerts()
+ await waitFor(() => expect(bridgeStatusMock).toHaveBeenCalledTimes(2))
+ await act(async () => {})
+ expect(screen.queryByText('Set up your admin email')).toBeNull()
+
+ resetControlAdminBridgeAlerts()
+ await waitFor(() =>
+ expect(screen.getByRole('status')).toHaveTextContent('Set up your admin email')
+ )
+ second.unmount()
+ })
+})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 5e6c53516..5d120b740 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.609",
+ "version": "0.1.610",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.609",
+ "version": "0.1.610",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/control-ui/package.json b/control-ui/package.json
index 569aa1d0a..4c7f668ee 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.609",
+ "version": "0.1.610",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",