Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(home): confirm a draft's send or discard after its card has gone
trohitg4bd6dae14c56
diff --git a/client/src/features/home/__tests__/drafts.test.tsx b/client/src/features/home/__tests__/drafts.test.tsxindex b8ab04a3..d4f9145c 100644--- a/client/src/features/home/__tests__/drafts.test.tsx+++ b/client/src/features/home/__tests__/drafts.test.tsx@@ -110,6 +110,30 @@ describe('DraftsSection', () => {renderSection(true);expect(await screen.findByText('Sends when you resume Maya.')).toBeInTheDocument();});++ // The card leaves the page the moment the owner decides, before the+ // server answers; the confirmation must still show.+ it('confirms a send after the card has gone', async () => {+ renderSection();+ fireEvent.click(await screen.findByRole('button', { name: 'Send' }));+ await waitFor(() => expect(pillToast).toHaveBeenCalledWith('Sent to Priya'));+ expect(screen.queryByRole('button', { name: 'Send' })).toBeNull();+ });++ it('confirms a discard after the card has gone', async () => {+ renderSection();+ fireEvent.click(await screen.findByRole('button', { name: 'Discard' }));+ await waitFor(() => expect(pillToast).toHaveBeenCalledWith('Draft discarded', { tone: 'info' }));+ });++ it('says a send waits for Resume when the server holds it', async () => {+ renderSection(true);+ sendRequest.mockImplementation(async (type: string) =>+ type === 'decide_approval' ? { success: true, will_send_on_resume: true } : { success: true, approvals: [] },+ );+ fireEvent.click(await screen.findByRole('button', { name: 'Send' }));+ await waitFor(() => expect(pillToast).toHaveBeenCalledWith('Sends when you resume Maya'));+ });});describe('applyApprovalLifecycle', () => {diff --git a/client/src/features/home/approvals/data.ts b/client/src/features/home/approvals/data.tsindex da05c644..e2b4a633 100644--- a/client/src/features/home/approvals/data.ts+++ b/client/src/features/home/approvals/data.ts@@ -5,7 +5,10 @@* - `useApprovalsQuery(workflowId)`: one employee's pending drafts.* - `useDecideApproval()`: Send or Discard. The draft leaves the list at* once and comes back if the server refuses; every click carries a fresh- * `decision_key`, so a replayed request settles the draft only once.+ * `decision_key`, so a replayed request settles the draft only once. The+ * confirmation toast belongs to the hook, not to the click: the card has+ * already left the page when the answer arrives, and TanStack drops a+ * per-call callback whose component unmounted.* - `useApprovalLifecycle()`: `approval_lifecycle` broadcasts (identity* only) refetch the affected list, and a new draft says so in a toast.*/@@ -73,6 +76,8 @@ export interface DecideInput {approval: Approval;decision: Decision;text?: string;+ /** Names the employee in "Sends when you resume {name}". */+ employeeName?: string;}const DECIDE_ERRORS: Record<string, string> = {@@ -123,6 +128,15 @@ export function useDecideApproval() {queryClient.setQueryData<Approval[]>(key, (list) => list?.filter((item) => item.approval_id !== approval.approval_id));return { previous, key };},+ onSuccess: (result, { approval, decision, employeeName }) => {+ if (decision === 'discard') {+ pillToast('Draft discarded', { tone: 'info' });+ } else if (result.will_send_on_resume) {+ pillToast(`Sends when you resume ${employeeName || 'the employee'}`);+ } else {+ pillToast(`Sent to ${approval.recipient_label || approval.recipient}`);+ }+ },onError: (error, _input, context) => {if (context) queryClient.setQueryData(context.key, context.previous);pillToast(error.message, { tone: 'error' });diff --git a/client/src/features/home/employee/DraftsSection.tsx b/client/src/features/home/employee/DraftsSection.tsxindex 80108702..61fd5fa8 100644--- a/client/src/features/home/employee/DraftsSection.tsx+++ b/client/src/features/home/employee/DraftsSection.tsx@@ -15,7 +15,6 @@ import { cn } from '@/lib/utils';import { useApprovalsQuery, useDecideApproval, type Approval } from '../approvals/data';import { DraftMessagePreview } from '../genui';import { MicroLabel } from '../ui/primitives';-import { pillToast } from '../ui/pillToast';function DraftCard({ approval, employeeName, paused }: { approval: Approval; employeeName: string; paused: boolean }) {const decide = useDecideApproval();@@ -25,16 +24,7 @@ function DraftCard({ approval, employeeName, paused }: { approval: Approval; empconst tooLong = trimmed.length > approval.max_length;const busy = decide.isPending;- const send = () =>- decide.mutate(- { approval, decision: 'send', text: editing ? trimmed : undefined },- {- onSuccess: (result) =>- pillToast(- result.will_send_on_resume ? `Sends when you resume ${employeeName}` : `Sent to ${approval.recipient_label || approval.recipient}`,- ),- },- );+ const send = () => decide.mutate({ approval, decision: 'send', text: editing ? trimmed : undefined, employeeName });return (<div data-approval={approval.approval_id} className="flex flex-col gap-2.5">@@ -68,7 +58,7 @@ function DraftCard({ approval, employeeName, paused }: { approval: Approval; emp<Buttonvariant="quiet"disabled={busy}- onClick={() => decide.mutate({ approval, decision: 'discard' }, { onSuccess: () => pillToast('Draft discarded', { tone: 'info' }) })}+ onClick={() => decide.mutate({ approval, decision: 'discard', employeeName })}className="h-8.5 rounded-row border-border-default px-3.5 font-semibold text-fg-default">Discard