Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(email): fix edge case (#7017)

Peter Chinmand5aa9d393d9b
diff --git a/apps/web/src/features/email-compose/components/from-inbox-selector.tsx b/apps/web/src/features/email-compose/components/from-inbox-selector.tsx
index f257e23e23..453e067147 100644
--- a/apps/web/src/features/email-compose/components/from-inbox-selector.tsx
+++ b/apps/web/src/features/email-compose/components/from-inbox-selector.tsx
@@ -75,15 +75,43 @@ export function FromInboxSelector(props: {
portalScope?: 'local';
}) {
const activeInbox = () =>
- props.links.find((l) => l.id === props.activeInboxId) ?? props.links[0];
+ props.links.find((l) => l.id === props.activeInboxId);
const sortedLinks = () =>
[...props.links].sort((a, b) =>
a.email_address.localeCompare(b.email_address)
);
+ const unresolvedInboxPicker = () => (
+ <Show when={props.links.length > 0}>
+ <Dropdown>
+ <Dropdown.Trigger
+ disabled={props.disabled}
+ class={cn(
+ 'inline-flex items-center gap-1 text-sm text-ink-muted',
+ props.class
+ )}
+ >
+ Select sending inbox
+ <ChevronDown class="size-3 shrink-0" />
+ </Dropdown.Trigger>
+ <Dropdown.Content portalScope={props.portalScope}>
+ <Dropdown.Group>
+ <For each={sortedLinks()}>
+ {(inbox) => (
+ <Dropdown.Item onSelect={() => props.onSelect(inbox.id)}>
+ <FromInboxOption inbox={inbox} />
+ </Dropdown.Item>
+ )}
+ </For>
+ </Dropdown.Group>
+ </Dropdown.Content>
+ </Dropdown>
+ </Show>
+ );
+
if (props.compact) {
return (
- <Show when={activeInbox()}>
+ <Show when={activeInbox()} fallback={unresolvedInboxPicker()}>
{(active) => (
<Show
when={props.links.length > 1}
@@ -120,7 +148,7 @@ export function FromInboxSelector(props: {
if (props.pill) {
return (
- <Show when={activeInbox()}>
+ <Show when={activeInbox()} fallback={unresolvedInboxPicker()}>
{(active) => (
<Show
when={props.links.length > 1}
@@ -162,7 +190,7 @@ export function FromInboxSelector(props: {
}
return (
- <Show when={activeInbox()}>
+ <Show when={activeInbox()} fallback={unresolvedInboxPicker()}>
{(active) => (
<Show
when={props.links.length > 1}
diff --git a/apps/web/src/features/email-compose/primitives/email-composer.test.ts b/apps/web/src/features/email-compose/primitives/email-composer.test.ts
index e493e09830..d118ee8a58 100644
--- a/apps/web/src/features/email-compose/primitives/email-composer.test.ts
+++ b/apps/web/src/features/email-compose/primitives/email-composer.test.ts
@@ -55,7 +55,7 @@ describe('standalone compose controller', () => {
expect(root.state.context.fromAddress?.()).toBeUndefined();
expect(root.state.context.validationError('no_link')).toMatchObject({
type: 'no_link',
- message: 'Unable to find linked email account',
+ message: 'Unable to find linked email account. Select a sending inbox.',
});
expect(context.delivery.sendMessage).not.toHaveBeenCalled();
} finally {
@@ -63,6 +63,56 @@ describe('standalone compose controller', () => {
}
});
+ it.each(['initial', 'draft'])(
+ 'recovers a missing %s sender after explicitly choosing the remaining inbox',
+ async (source) => {
+ const context = createComposeContext();
+ const root = mountEmailComposer(
+ context,
+ undefined,
+ source === 'draft'
+ ? {
+ draft: message('existing-draft', {
+ is_draft: true,
+ link_id: 'removed-inbox',
+ }),
+ }
+ : { initialInboxId: 'removed-inbox' }
+ );
+ try {
+ root.state.context.setRecipients('to', [
+ {
+ kind: 'custom',
+ data: {
+ email: '[email protected]',
+ invalid: false,
+ },
+ },
+ ]);
+ root.edit('Keep this message');
+ root.state.context.onSend();
+ expect(root.state.context.validationError('no_link')).toBeDefined();
+ expect(root.state.hasInboxError()).toBe(false);
+ expect(context.delivery.sendMessage).not.toHaveBeenCalled();
+
+ root.state.context.onSelectInbox?.('inbox');
+ await vi.advanceTimersByTimeAsync(0);
+
+ expect(root.state.context.validationError('no_link')).toBeUndefined();
+ expect(root.state.context.fromAddress?.()).toBe('[email protected]');
+ root.state.context.onSend();
+ await vi.advanceTimersByTimeAsync(0);
+ expect(context.delivery.sendMessage).toHaveBeenCalledWith(
+ expect.objectContaining({ inboxId: 'inbox' })
+ );
+ } finally {
+ root.dispose();
+ }
+ }
+ );
+
it.each([undefined, 'missing-primary'])(
'falls back to the first inbox without an explicit selection when primary is %s',
async (primaryId) => {
diff --git a/apps/web/src/features/email-compose/primitives/email-composer.ts b/apps/web/src/features/email-compose/primitives/email-composer.ts
index b19be12cfb..14ecce18ea 100644
--- a/apps/web/src/features/email-compose/primitives/email-composer.ts
+++ b/apps/web/src/features/email-compose/primitives/email-composer.ts
@@ -610,7 +610,7 @@ export function createEmailComposer(props: EmailComposerOptions) {
if (!currentLink) {
setValidationError({
type: 'no_link',
- message: 'Unable to find linked email account',
+ message: 'Unable to find linked email account. Select a sending inbox.',
});
return;
}
@@ -1061,6 +1061,7 @@ export function createEmailComposer(props: EmailComposerOptions) {
// Validation
validationError: (type) => {
+ if (type === 'no_link' && link()) return undefined;
const error = validationError();
if (error?.type === type) return error;
return undefined;
diff --git a/apps/web/src/features/email-compose/views/compose-layout.test.tsx b/apps/web/src/features/email-compose/views/compose-layout.test.tsx
index 353cb8c87a..97157c1b50 100644
--- a/apps/web/src/features/email-compose/views/compose-layout.test.tsx
+++ b/apps/web/src/features/email-compose/views/compose-layout.test.tsx
@@ -2,6 +2,9 @@ import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
import { ComposerSurface } from '@ui/components/ComposerSurface';
import { type ComponentProps, createSignal } from 'solid-js';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import type { ComposeState } from '../primitives/compose-view-state';
+import { createComposeContext } from '../tests/capabilities';
+import { mountEmailComposer } from '../tests/composer';
import { ComposeLayout } from './compose-layout';
const attachHotkeys = vi.hoisted(() => vi.fn());
@@ -9,6 +12,7 @@ const registerHotkeyMock = vi.hoisted(() => vi.fn());
const onSend = vi.hoisted(() => vi.fn());
const composeStatus = vi.hoisted(() => ({
disabled: false,
+ sender: {} as Partial<ComposeState>,
}));
vi.mock('@core/hotkey/hotkeys', () => ({
registerHotkey: registerHotkeyMock,
@@ -18,6 +22,7 @@ vi.mock('@core/mobile/isTouchDevice', () => ({ isTouchDevice: () => false }));
vi.mock('@ui', async () => ({
cn: (await import('@ui/utils/classname')).cn,
Button: (props: ComponentProps<'button'>) => <button {...props} />,
+ Dropdown: (await import('@ui/components/Dropdown')).Dropdown,
}));
vi.mock('../context/compose-context', () => ({
useCompose: () => ({
@@ -25,11 +30,12 @@ vi.mock('../context/compose-context', () => ({
disabled: () => composeStatus.disabled,
onSend,
isMobile: () => false,
+ validationError: () => undefined,
+ ...composeStatus.sender,
}),
}));
-vi.mock('../components/from-inbox-selector', () => ({
- FromInboxSelector: () => null,
-}));
+vi.mock('@core/component/UserIcon', () => ({ UserIcon: () => null }));
+vi.mock('@core/component/inboxIcon', () => ({ inboxIconProps: () => ({}) }));
vi.mock('./compose-recipients', () => ({ ComposeRecipients: () => null }));
vi.mock('./compose-subject', () => ({ ComposeSubject: () => null }));
vi.mock('./compose-body', () => ({
@@ -47,10 +53,58 @@ beforeEach(() => {
registerHotkeyMock.mockClear();
onSend.mockClear();
composeStatus.disabled = false;
+ composeStatus.sender = {};
+});
+afterEach(() => {
+ cleanup();
+ vi.restoreAllMocks();
});
-afterEach(cleanup);
describe('ComposeLayout root composition', () => {
+ it('shows the missing-sender error and lets the user select the only remaining inbox', async () => {
+ vi.spyOn(window, 'scrollTo').mockImplementation(() => {});
+ const context = createComposeContext();
+ const root = mountEmailComposer(context, undefined, {
+ initialInboxId: 'removed',
+ });
+ composeStatus.sender = root.state.context;
+ try {
+ root.edit('Keep this message');
+ render(() => (
+ <ComposeLayout
+ toolbar={
+ <button onClick={root.state.context.onSend}>Send email</button>
+ }
+ />
+ ));
+ const picker = screen.getByRole('button', {
+ name: 'Select sending inbox',
+ });
+ expect(screen.queryByText('[email protected]')).toBeNull();
+
+ fireEvent.click(screen.getByRole('button', { name: 'Send email' }));
+ expect(screen.getByRole('alert').textContent).toContain(
+ 'Select a sending inbox.'
+ );
+ expect(context.delivery.sendMessage).not.toHaveBeenCalled();
+
+ fireEvent.keyDown(picker, { key: 'Enter' });
+ const inbox = await screen.findByRole('menuitem', {
+ });
+ fireEvent.keyDown(inbox, { key: 'Enter' });
+ expect(root.state.context.selectedInboxId?.()).toBe('inbox');
+ expect(screen.queryByRole('alert')).toBeNull();
+ expect(
+ screen.queryByRole('button', { name: 'Select sending inbox' })
+ ).toBeNull();
+ expect(screen.getByText('[email protected]')).toBeTruthy();
+ } finally {
+ cleanup();
+ root.dispose();
+ }
+ });
+
it.each([undefined, DraftSurface])(
'keeps the editor and hotkey scope on the same root when layout props change (%s)',
(as) => {
diff --git a/apps/web/src/features/email-compose/views/compose-layout.tsx b/apps/web/src/features/email-compose/views/compose-layout.tsx
index decbdd31bd..f2bf49d710 100644
--- a/apps/web/src/features/email-compose/views/compose-layout.tsx
+++ b/apps/web/src/features/email-compose/views/compose-layout.tsx
@@ -218,7 +218,7 @@ export function ComposeLayout(props: {
</div>
}
>
- <Show when={ctx.fromAddress?.()}>
+ <Show when={ctx.fromInboxes?.().length}>
<div class="flex items-center gap-2 min-w-0 flex-1 py-3">
<span class="w-14 shrink-0 text-sm text-ink-placeholder">
From
@@ -265,6 +265,14 @@ export function ComposeLayout(props: {
</div>
</div>
+ <Show when={ctx.validationError('no_link')}>
+ {(error) => (
+ <div role="alert" class="text-failure-ink text-sm mt-1">
+ {error().message}
+ </div>
+ )}
+ </Show>
+
<Show when={props.notice}>
<div class="mb-4">{props.notice}</div>
</Show>
diff --git a/apps/web/src/features/email-compose/views/compose-recipients.tsx b/apps/web/src/features/email-compose/views/compose-recipients.tsx
index 23cb81fa57..6c1530adc3 100644
--- a/apps/web/src/features/email-compose/views/compose-recipients.tsx
+++ b/apps/web/src/features/email-compose/views/compose-recipients.tsx
@@ -341,7 +341,7 @@ export function ComposeRecipients(props: {
Cc/Bcc, From:
</span>
<span class="ph-no-capture text-sm text-ink-muted truncate min-h-9 flex items-center">
- {ctx.fromAddress?.()}
+ {ctx.fromAddress?.() ?? 'Select sending inbox'}
</span>
</button>
}
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index c93514101b..45e0c7d27a 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -578,8 +578,12 @@ search field, filter menu and preview control. The sidebar lists the inboxes abo
scrolling list. `New email` prefills From with the selected inbox, or the primary
inbox when All inboxes is selected; reopening a draft keeps its saved sender.
If an explicitly selected sending inbox is unavailable, Send reports
-`Unable to find linked email account` without delivering through another
-account. With no explicit selection, an unavailable primary still falls back to
+`Unable to find linked email account. Select a sending inbox.` without delivering
+through another account. The From picker stays available as `Select sending inbox`,
+including when only one linked inbox remains. On mobile, expand `Cc/Bcc, From:`
+to choose the sender. Selecting an available inbox clears the error and allows
+sending; the picker never displays another inbox as selected before that choice.
+With no explicit selection, an unavailable primary still falls back to
the first linked inbox.
Sidebar rows, including `All inboxes`, replace their icon with an accent-colored checkmark when
selected. With exactly one connected inbox, only its address appears as the selected