From 43be85d01b62759db19af46e9fcf163aeb94a3eb Mon Sep 17 00:00:00 2001 From: Dotta Date: Fri, 9 Oct 2026 16:34:36 -0500 Subject: [PATCH] fix: restore task selection focus after call inventory retry Co-Authored-By: Paperclip --- ui/src/components/voice/SpekoIncomingCalls.test.tsx | 2 ++ ui/src/components/voice/SpekoIncomingCalls.tsx | 11 +++++++++-- ui/storybook/stories/speko/incoming-call.stories.tsx | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ui/src/components/voice/SpekoIncomingCalls.test.tsx b/ui/src/components/voice/SpekoIncomingCalls.test.tsx index 14d7edb92ef..e534bd09476 100644 --- a/ui/src/components/voice/SpekoIncomingCalls.test.tsx +++ b/ui/src/components/voice/SpekoIncomingCalls.test.tsx @@ -22,9 +22,11 @@ describe("incoming call task selection", () => { mocks.list.mockRejectedValueOnce(new Error("Offline")).mockResolvedValue(tasks); await render(); await vi.waitFor(() => expect(container.textContent).toContain("Task list could not be loaded")); const retry = [...container.querySelectorAll("button")].find(button => button.textContent === "Retry tasks")!; + retry.focus(); await act(async () => retry.click()); await vi.waitFor(() => expect(container.querySelector('option[value="task"]')).not.toBeNull()); expect(container.querySelector('[role="alert"]')).toBeNull(); + expect(document.activeElement).toBe(container.querySelector("select")); }); it("preserves previously loaded tasks when a background task request fails", async () => { mocks.list.mockResolvedValue(tasks); await render(); diff --git a/ui/src/components/voice/SpekoIncomingCalls.tsx b/ui/src/components/voice/SpekoIncomingCalls.tsx index 9bc89f3e13f..e32b6a567f2 100644 --- a/ui/src/components/voice/SpekoIncomingCalls.tsx +++ b/ui/src/components/voice/SpekoIncomingCalls.tsx @@ -34,10 +34,17 @@ export function SpekoIncomingCallCard({call, tasks = [], busy, error, onDecide}: } export function SpekoIncomingCalls({companyId, endpointId, agentId}: {companyId: string; endpointId: string; agentId: string}) { const [decision, setDecision] = useState(); - useEffect(() => { setDecision(undefined); }, [companyId, endpointId]); + const host = useRef(null), restoreTaskFocus = useRef(false); + useEffect(() => { setDecision(undefined); restoreTaskFocus.current = false; }, [companyId, endpointId]); const query = useQuery({queryKey: ["speko-incoming", companyId, endpointId], queryFn: () => voicePhoneApi.incoming(companyId, endpointId), refetchInterval: 2000, retry: false}); const needsTaskSelection = Boolean(query.data?.some(call => ["awaiting_approval", "approving"].includes(call.state))); const tasks = useQuery({queryKey: ["speko-approval-tasks", companyId, agentId], queryFn: () => issuesApi.list(companyId, {assigneeAgentId: agentId}), enabled: needsTaskSelection, retry: false}); + useEffect(() => { + if (restoreTaskFocus.current && !tasks.isFetching && !tasks.isError) { + restoreTaskFocus.current = false; + host.current?.querySelector('select[aria-label="Conversation task"]')?.focus(); + } + }, [tasks.data, tasks.isFetching, tasks.isError]); const mutation = useMutation({mutationFn: ({id, ...input}: {id: string; approve: boolean; approvalCode: string; issueId?: string}) => voicePhoneApi.decide(companyId, endpointId, id, input), onSuccess: result => { setDecision(result); return query.refetch(); }}); - return
{needsTaskSelection && tasks.isError &&

Task list could not be loaded. Retry to choose an existing task.

}{query.error &&

Incoming call approval is unavailable. {query.error.message}

}{!query.error && [...(query.data ?? []).filter(call => call.id !== decision?.id), ...(decision ? [decision] : [])].map(call => !["done", "cancelled"].includes(task.status)).map(task => ({id: task.id, label: `${task.identifier ?? "Task"} · ${task.title}`}))} busy={mutation.isPending && mutation.variables?.id === call.id} error={mutation.variables?.id === call.id ? mutation.error?.message : undefined} onDecide={input => mutation.mutate({id: call.id, ...input})} />)}
; + return
{needsTaskSelection && tasks.isError &&

Task list could not be loaded. Retry to choose an existing task.

}{query.error &&

Incoming call approval is unavailable. {query.error.message}

}{!query.error && [...(query.data ?? []).filter(call => call.id !== decision?.id), ...(decision ? [decision] : [])].map(call => !["done", "cancelled"].includes(task.status)).map(task => ({id: task.id, label: `${task.identifier ?? "Task"} · ${task.title}`}))} busy={mutation.isPending && mutation.variables?.id === call.id} error={mutation.variables?.id === call.id ? mutation.error?.message : undefined} onDecide={input => mutation.mutate({id: call.id, ...input})} />)}
; } diff --git a/ui/storybook/stories/speko/incoming-call.stories.tsx b/ui/storybook/stories/speko/incoming-call.stories.tsx index fcf59519273..4fdab5cbb4a 100644 --- a/ui/storybook/stories/speko/incoming-call.stories.tsx +++ b/ui/storybook/stories/speko/incoming-call.stories.tsx @@ -52,5 +52,6 @@ export const TaskListFailureAndRecovery: Story = { await userEvent.keyboard("{Enter}"); await expect(await canvas.findByRole("option", {name: "PAP-42 · Ready existing conversation"})).toBeVisible(); await waitFor(() => expect(canvas.queryByRole("alert")).not.toBeInTheDocument()); + await waitFor(() => expect(canvas.getByRole("combobox", {name: "Conversation task"})).toHaveFocus()); }, };