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 channel name editing

Josué39f812b22dfd
diff --git a/profile-ui/app/components/__tests__/TelegramVerificationPanel.test.tsx b/profile-ui/app/components/__tests__/TelegramVerificationPanel.test.tsx
new file mode 100644
index 000000000..921dcf333
--- /dev/null
+++ b/profile-ui/app/components/__tests__/TelegramVerificationPanel.test.tsx
@@ -0,0 +1,98 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
+import type { WorkflowApprovalMediumAccount } from '@/app/types/approvalChannels'
+import { TelegramVerificationPanel } from '../../settings/TelegramVerificationPanel'
+import { ToastProvider } from '../Toast'
+
+const mocks = vi.hoisted(() => ({
+ updateDisplayName: vi.fn(),
+}))
+
+vi.mock('@lib/approvalChannels', async importOriginal => {
+ const original = await importOriginal<typeof import('@lib/approvalChannels')>()
+ return {
+ ...original,
+ updateWorkflowApprovalMediumDisplayName: mocks.updateDisplayName,
+ }
+})
+
+const account: WorkflowApprovalMediumAccount = {
+ id: 'account-1',
+ userId: 'user-1',
+ medium: 'slack',
+ providerUserId: 'provider-user',
+ providerWorkspaceId: 'workspace-1',
+ providerChannelId: 'channel-1',
+ displayName: 'Operations approvals',
+ targets: [],
+}
+
+afterEach(cleanup)
+
+describe('TelegramVerificationPanel display name editing', () => {
+ const onAccountsRefresh = vi.fn()
+
+ beforeEach(() => {
+ vi.clearAllMocks()
+ onAccountsRefresh.mockResolvedValue([account])
+ mocks.updateDisplayName.mockResolvedValue(undefined)
+ })
+
+ function renderPanel() {
+ return render(
+ <ToastProvider>
+ <TelegramVerificationPanel
+ accounts={[account]}
+ disabled={false}
+ medium="slack"
+ onAccountsRefresh={onAccountsRefresh}
+ onRemoveAccount={() => undefined}
+ targets={[]}
+ />
+ </ToastProvider>
+ )
+ }
+
+ async function openEditor() {
+ fireEvent.click(screen.getByRole('button', { name: 'Actions for Operations approvals' }))
+ fireEvent.click(await screen.findByRole('menuitem', { name: 'Edit display name' }))
+ return screen.findByRole('dialog', { name: 'Edit conversation name' })
+ }
+
+ it('saves a changed display name and refreshes authoritative account data', async () => {
+ renderPanel()
+ const dialog = await openEditor()
+ const input = within(dialog).getByRole('textbox', { name: 'Display name' })
+ expect(input).toHaveValue('Operations approvals')
+ expect(within(dialog).getByRole('button', { name: 'Save' })).toBeDisabled()
+
+ fireEvent.change(input, { target: { value: 'Leadership approvals' } })
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Save' }))
+
+ await waitFor(() =>
+ expect(mocks.updateDisplayName).toHaveBeenCalledWith('account-1', 'Leadership approvals')
+ )
+ expect(onAccountsRefresh).toHaveBeenCalledTimes(1)
+ await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
+ expect(screen.getByText('Conversation display name saved.')).toBeInTheDocument()
+ })
+
+ it('retains a failed draft and discards it on cancel', async () => {
+ mocks.updateDisplayName.mockRejectedValue(new Error('Display name update failed'))
+ renderPanel()
+ const dialog = await openEditor()
+ const input = within(dialog).getByRole('textbox', { name: 'Display name' })
+ fireEvent.change(input, { target: { value: 'Retry approvals' } })
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Save' }))
+
+ expect(await within(dialog).findByRole('alert')).toHaveTextContent('Display name update failed')
+ expect(input).toHaveValue('Retry approvals')
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }))
+ expect(screen.queryByRole('dialog')).toBeNull()
+
+ const reopened = await openEditor()
+ expect(within(reopened).getByRole('textbox', { name: 'Display name' })).toHaveValue(
+ 'Operations approvals'
+ )
+ })
+})
diff --git a/profile-ui/app/settings/TelegramVerificationPanel.tsx b/profile-ui/app/settings/TelegramVerificationPanel.tsx
index 95effc1aa..c5458d4ee 100644
--- a/profile-ui/app/settings/TelegramVerificationPanel.tsx
+++ b/profile-ui/app/settings/TelegramVerificationPanel.tsx
@@ -1,7 +1,12 @@
'use client'
import { useEffect, useMemo, useState } from 'react'
-import { RecordList, RecordListRow, RowActionMenu } from '@clerum/frontend-components'
+import {
+ RecordList,
+ RecordListRow,
+ RowActionMenu,
+ SingleValueEditDialog,
+} from '@clerum/frontend-components'
import { Button } from '@components/Button'
import { CheckboxField } from '@components/CheckboxField'
import { FormField } from '@components/FormField'
@@ -58,7 +63,6 @@ export function TelegramVerificationPanel({
const [busy, setBusy] = useState(false)
const [error, setError] = useState('')
const [editingAccount, setEditingAccount] = useState<WorkflowApprovalMediumAccount | null>(null)
- const [displayNameDraft, setDisplayNameDraft] = useState('')
const [displayNameBusy, setDisplayNameBusy] = useState(false)
const [displayNameError, setDisplayNameError] = useState('')
const [teamsReplyInThreads, setTeamsReplyInThreads] = useState(true)
@@ -126,20 +130,18 @@ export function TelegramVerificationPanel({
function openDisplayNameModal(account: WorkflowApprovalMediumAccount) {
setEditingAccount(account)
- setDisplayNameDraft(account.displayName?.trim() || approvalAccountDisplayName(account))
setDisplayNameError('')
}
function closeDisplayNameModal() {
if (displayNameBusy) return
setEditingAccount(null)
- setDisplayNameDraft('')
setDisplayNameError('')
}
- async function saveDisplayName() {
+ async function saveDisplayName(value: string) {
if (!editingAccount) return
- const nextDisplayName = displayNameDraft.trim()
+ const nextDisplayName = value.trim()
if (nextDisplayName.length > APPROVAL_ACCOUNT_DISPLAY_NAME_MAX_LENGTH) {
setDisplayNameError(
`Display name must be ${APPROVAL_ACCOUNT_DISPLAY_NAME_MAX_LENGTH} characters or fewer.`
@@ -152,7 +154,6 @@ export function TelegramVerificationPanel({
await updateWorkflowApprovalMediumDisplayName(editingAccount.id, nextDisplayName)
await onAccountsRefresh()
setEditingAccount(null)
- setDisplayNameDraft('')
setDisplayNameError('')
showToast('Conversation display name saved.', { tone: 'success' })
} catch (err) {
@@ -490,63 +491,32 @@ export function TelegramVerificationPanel({
</div>
) : null}
- {editingAccount ? (
- <div
- className="cu-modal-backdrop"
- role="presentation"
- onMouseDown={event => {
- if (event.target === event.currentTarget) closeDisplayNameModal()
- }}
- >
- <section
- className="cu-modal-panel cu-modal-panel--narrow"
- role="dialog"
- aria-modal="true"
- aria-labelledby={`${medium}-display-name-title`}
- onMouseDown={event => event.stopPropagation()}
- >
- <div className="cu-modal-panel__head">
- <h3 id={`${medium}-display-name-title`} className="cu-modal-panel__title">
- Edit conversation name
- </h3>
- <button
- type="button"
- className="cu-btn cu-btn--ghost"
- onClick={closeDisplayNameModal}
- disabled={displayNameBusy}
- >
- Close
- </button>
- </div>
- <div className="cu-modal-panel__body">
- <FormField label="Display name">
- <TextInput
- value={displayNameDraft}
- onChange={event => setDisplayNameDraft(event.target.value)}
- placeholder={approvalAccountDisplayName(editingAccount)}
- maxLength={APPROVAL_ACCOUNT_DISPLAY_NAME_MAX_LENGTH}
- disabled={displayNameBusy}
- />
- </FormField>
- {displayNameError ? (
- <div className="message message--error">{displayNameError}</div>
- ) : null}
- </div>
- <div className="cu-modal-panel__foot">
- <Button
- variant="secondary"
- onClick={closeDisplayNameModal}
- disabled={displayNameBusy}
- >
- Cancel
- </Button>
- <Button onClick={() => void saveDisplayName()} disabled={displayNameBusy}>
- {displayNameBusy ? 'Saving...' : 'Save'}
- </Button>
- </div>
- </section>
- </div>
- ) : null}
+ <SingleValueEditDialog
+ discardLabel="Cancel"
+ error={displayNameError || undefined}
+ initialValue={
+ editingAccount
+ ? editingAccount.displayName?.trim() || approvalAccountDisplayName(editingAccount)
+ : ''
+ }
+ onDismiss={closeDisplayNameModal}
+ onSave={value => void saveDisplayName(value)}
+ open={Boolean(editingAccount)}
+ pending={displayNameBusy}
+ renderEditor={({ value, onChange, disabled: editorDisabled }) => (
+ <FormField label="Display name">
+ <TextInput
+ aria-label="Display name"
+ disabled={editorDisabled}
+ maxLength={APPROVAL_ACCOUNT_DISPLAY_NAME_MAX_LENGTH}
+ onChange={event => onChange(event.target.value)}
+ placeholder={editingAccount ? approvalAccountDisplayName(editingAccount) : ''}
+ value={value}
+ />
+ </FormField>
+ )}
+ title="Edit conversation name"
+ />
</div>
)
}
diff --git a/profile-ui/package-lock.json b/profile-ui/package-lock.json
index 3884a83a8..c6ea97be5 100644
--- a/profile-ui/package-lock.json
+++ b/profile-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.141",
+ "version": "0.1.142",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-profile-ui",
- "version": "0.1.141",
+ "version": "0.1.142",
"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 b95888f85..c4c142c9f 100644
--- a/profile-ui/package.json
+++ b/profile-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.141",
+ "version": "0.1.142",
"private": true,
"scripts": {
"dev": "next dev",