Skip to content

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

TypeScript

feat(profile-ui): standardize approval preference editing

Josué98975ac40bae
diff --git a/profile-ui/app/approval-channels/page.tsx b/profile-ui/app/approval-channels/page.tsx
index cad743dbc..0daa3aeb8 100644
--- a/profile-ui/app/approval-channels/page.tsx
+++ b/profile-ui/app/approval-channels/page.tsx
@@ -2,6 +2,7 @@
import { useEffect, useMemo, useState } from 'react'
import { useRouter } from 'next/navigation'
+import { SingleValueEditDialog } from '@clerum/frontend-components'
import { AuthGate } from '@components/AuthGate'
import { Button } from '@components/Button'
import { useProfileAccess } from '@components/ProfileAccessContext'
@@ -43,6 +44,8 @@ function ApprovalChannelsContent() {
const [state, setState] = useState<LoadState>('loading')
const [busy, setBusy] = useState(false)
const [error, setError] = useState('')
+ const [editingPreferred, setEditingPreferred] = useState(false)
+ const [preferredEditError, setPreferredEditError] = useState('')
const activeAccounts = useMemo(() => {
const authorizedTargetIds = new Set(targets.map(target => target.id))
@@ -52,6 +55,9 @@ function ApprovalChannelsContent() {
}, [accounts, targets])
const selectedPreferredAccountId = preferences?.preferredAccountId ?? ''
const selectedAccount = activeAccounts.find(account => account.id === selectedPreferredAccountId)
+ const selectedPreferredAccountLabel = selectedAccount
+ ? preferredAccountOptionLabel(selectedAccount)
+ : 'Automatic (most recent channel)'
const manageMedium = selectedAccount?.medium || activeAccounts[0]?.medium || 'telegram'
async function loadAll(forceAccess = false) {
@@ -86,22 +92,27 @@ function ApprovalChannelsContent() {
? (activeAccounts.find(account => account.id === preferredAccountId)?.medium ?? null)
: null
setBusy(true)
- setError('')
+ setPreferredEditError('')
try {
const next = await updateNotificationPreferences({
preferredMedium:
- preferredMedium === 'telegram' || preferredMedium === 'slack' ? preferredMedium : null,
+ preferredMedium === 'telegram' ||
+ preferredMedium === 'slack' ||
+ preferredMedium === 'teams'
+ ? preferredMedium
+ : null,
preferredAccountId,
channelFallbackEnabled: preferences.channelFallbackEnabled,
})
setPreferences(next)
+ setEditingPreferred(false)
showToast(
preferredAccountId ? 'Preferred channel updated.' : 'Preferred channel set to automatic.',
{ tone: 'success' }
)
} catch (err) {
const message = err instanceof Error ? err.message : ''
- setError(
+ setPreferredEditError(
message.includes('preferred_account_not_found')
? 'That channel is no longer available. Pick another or leave Automatic.'
: 'Could not update the preferred channel.'
@@ -166,13 +177,48 @@ function ApprovalChannelsContent() {
No external channels are connected. Use Manage to connect one.
</div>
) : (
+ <div className="stack-tight">
+ <span className="small muted">Preferred channel</span>
+ <div className="settings-section-head">
+ <span>{selectedPreferredAccountLabel}</span>
+ <Button
+ variant="secondary"
+ aria-label="Edit preferred channel"
+ onClick={() => {
+ setPreferredEditError('')
+ setEditingPreferred(true)
+ }}
+ >
+ Edit
+ </Button>
+ </div>
+ </div>
+ )}
+ </section>
+ ) : null}
+
+ {preferences && activeAccounts.length > 0 ? (
+ <SingleValueEditDialog
+ open={editingPreferred}
+ initialValue={selectedPreferredAccountId}
+ title="Edit preferred approval channel"
+ description="Choose which connected conversation receives approval notifications by default."
+ pending={busy}
+ error={preferredEditError || undefined}
+ discardLabel="Cancel"
+ onDismiss={() => {
+ setPreferredEditError('')
+ setEditingPreferred(false)
+ }}
+ onSave={value => void changePreferredAccount(value)}
+ renderEditor={({ value, onChange, disabled }) => (
<label className="stack-tight" htmlFor="preferred-notification-account">
<span className="small muted">Preferred channel</span>
<SelectControl
id="preferred-notification-account"
- value={selectedPreferredAccountId}
- onChange={event => void changePreferredAccount(event.target.value)}
- disabled={busy}
+ value={value}
+ onChange={event => onChange(event.target.value)}
+ disabled={disabled}
>
<option value="">Automatic (most recent channel)</option>
{activeAccounts.map(account => (
@@ -183,7 +229,7 @@ function ApprovalChannelsContent() {
</SelectControl>
</label>
)}
- </section>
+ />
) : null}
</div>
</ProfileShell>
diff --git a/profile-ui/app/components/__tests__/ApprovalChannelsPage.test.tsx b/profile-ui/app/components/__tests__/ApprovalChannelsPage.test.tsx
new file mode 100644
index 000000000..4e283b17e
--- /dev/null
+++ b/profile-ui/app/components/__tests__/ApprovalChannelsPage.test.tsx
@@ -0,0 +1,167 @@
+import type { ReactNode } from 'react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import '@testing-library/jest-dom/vitest'
+import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
+import type {
+ ApprovalChannelTarget,
+ WorkflowApprovalMediumAccount,
+} from '@/app/types/approvalChannels'
+import type { NotificationPreferences } from '@/app/types/profile'
+import ApprovalChannelsPage from '../../approval-channels/page'
+
+const mocks = vi.hoisted(() => ({
+ getMe: vi.fn(),
+ getNotificationPreferences: vi.fn(),
+ listWorkflowApprovalMediums: vi.fn(),
+ refreshApprovalTargets: vi.fn(),
+ routerPush: vi.fn(),
+ showToast: vi.fn(),
+ updateNotificationPreferences: vi.fn(),
+}))
+
+const target: ApprovalChannelTarget = {
+ id: 'target-1',
+ medium: 'slack',
+ agentName: 'Support agent',
+ channelName: 'approvals',
+ channelNamespace: 'default',
+ botLabel: 'Evenfire',
+ botUsername: null,
+ botDeepLink: null,
+ status: 'ready',
+}
+
+const slackAccount: WorkflowApprovalMediumAccount = {
+ id: 'account-1',
+ userId: 'user-1',
+ medium: 'slack',
+ providerUserId: 'provider-user-1',
+ providerWorkspaceId: 'workspace-1',
+ providerChannelId: 'channel-1',
+ displayName: 'Operations',
+ targets: [target],
+}
+
+const selectedPreferences: NotificationPreferences = {
+ preferredMedium: 'slack',
+ preferredAccountId: slackAccount.id,
+ channelFallbackEnabled: true,
+ verifiedMedia: ['slack'],
+}
+
+vi.mock('next/navigation', () => ({
+ useRouter: () => ({ push: mocks.routerPush }),
+}))
+
+vi.mock('@components/AuthGate', () => ({
+ AuthGate: ({ children }: { children: ReactNode }) => children,
+}))
+
+vi.mock('@components/ProfileShell', () => ({
+ ProfileShell: ({ children }: { children: ReactNode }) => <>{children}</>,
+}))
+
+vi.mock('@components/ProfileAccessContext', () => ({
+ useProfileAccess: () => ({
+ approvalTargets: [target],
+ refreshApprovalTargets: mocks.refreshApprovalTargets,
+ }),
+}))
+
+vi.mock('@components/Toast', () => ({
+ useToast: () => ({ showToast: mocks.showToast }),
+}))
+
+vi.mock('@lib/api', () => ({
+ getMe: mocks.getMe,
+ getNotificationPreferences: mocks.getNotificationPreferences,
+ isSilentApiError: () => false,
+ updateNotificationPreferences: mocks.updateNotificationPreferences,
+}))
+
+vi.mock('@lib/approvalChannels', () => ({
+ activeApprovalAccounts: (accounts: WorkflowApprovalMediumAccount[]) =>
+ accounts.filter(account => !account.disabledAt),
+ listWorkflowApprovalMediums: mocks.listWorkflowApprovalMediums,
+ preferredAccountOptionLabel: (account: WorkflowApprovalMediumAccount) =>
+ `${account.displayName} · Slack`,
+}))
+
+function renderPage() {
+ return render(<ApprovalChannelsPage />)
+}
+
+beforeEach(() => {
+ vi.clearAllMocks()
+ mocks.getMe.mockResolvedValue({ id: 'user-1', email: '[email protected]' })
+ mocks.refreshApprovalTargets.mockResolvedValue(undefined)
+ mocks.listWorkflowApprovalMediums.mockResolvedValue([slackAccount])
+ mocks.getNotificationPreferences.mockResolvedValue(selectedPreferences)
+})
+
+afterEach(cleanup)
+
+describe('ApprovalChannelsPage preferred channel editing', () => {
+ it('stages an automatic preference and persists it only after Save', async () => {
+ const automaticPreferences: NotificationPreferences = {
+ ...selectedPreferences,
+ preferredMedium: null,
+ preferredAccountId: null,
+ }
+ mocks.updateNotificationPreferences.mockResolvedValue(automaticPreferences)
+ renderPage()
+
+ expect(await screen.findByText('Operations · Slack')).toBeInTheDocument()
+ expect(screen.queryByRole('combobox', { name: 'Preferred channel' })).toBeNull()
+
+ fireEvent.click(screen.getByRole('button', { name: 'Edit preferred channel' }))
+ const dialog = await screen.findByRole('dialog', { name: 'Edit preferred approval channel' })
+ const select = within(dialog).getByRole('combobox', { name: 'Preferred channel' })
+ expect(select).toHaveValue(slackAccount.id)
+
+ fireEvent.change(select, { target: { value: '' } })
+ expect(mocks.updateNotificationPreferences).not.toHaveBeenCalled()
+ expect(
+ screen.getByRole('button', { name: 'Edit preferred channel' }).parentElement
+ ).toHaveTextContent('Operations · Slack')
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Save' }))
+
+ await waitFor(() =>
+ expect(mocks.updateNotificationPreferences).toHaveBeenCalledWith({
+ preferredMedium: null,
+ preferredAccountId: null,
+ channelFallbackEnabled: true,
+ })
+ )
+ expect(mocks.updateNotificationPreferences).toHaveBeenCalledTimes(1)
+ await waitFor(() =>
+ expect(screen.queryByRole('dialog', { name: 'Edit preferred approval channel' })).toBeNull()
+ )
+ expect(screen.getByText('Automatic (most recent channel)')).toBeInTheDocument()
+ })
+
+ it('keeps a failed draft open and discards it on cancel', async () => {
+ mocks.updateNotificationPreferences.mockRejectedValue(new Error('preferred_account_not_found'))
+ renderPage()
+
+ await screen.findByText('Operations · Slack')
+ fireEvent.click(screen.getByRole('button', { name: 'Edit preferred channel' }))
+ const dialog = await screen.findByRole('dialog', { name: 'Edit preferred approval channel' })
+ const select = within(dialog).getByRole('combobox', { name: 'Preferred channel' })
+ fireEvent.change(select, { target: { value: '' } })
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Save' }))
+
+ expect(await within(dialog).findByRole('alert')).toHaveTextContent(
+ 'That channel is no longer available. Pick another or leave Automatic.'
+ )
+ expect(select).toHaveValue('')
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }))
+ expect(screen.queryByRole('dialog', { name: 'Edit preferred approval channel' })).toBeNull()
+ expect(screen.getByText('Operations · Slack')).toBeInTheDocument()
+
+ fireEvent.click(screen.getByRole('button', { name: 'Edit preferred channel' }))
+ expect(await screen.findByRole('combobox', { name: 'Preferred channel' })).toHaveValue(
+ slackAccount.id
+ )
+ })
+})
diff --git a/profile-ui/package-lock.json b/profile-ui/package-lock.json
index c77d05d67..3884a83a8 100644
--- a/profile-ui/package-lock.json
+++ b/profile-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.140",
+ "version": "0.1.141",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-profile-ui",
- "version": "0.1.140",
+ "version": "0.1.141",
"dependencies": {
"@clerum/desktop-app-links": "file:../packages/desktop-app-links",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/profile-ui/package.json b/profile-ui/package.json
index 766abfa1a..b95888f85 100644
--- a/profile-ui/package.json
+++ b/profile-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.140",
+ "version": "0.1.141",
"private": true,
"scripts": {
"dev": "next dev",