Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(email): pick the from-inbox in the composer/reply input (#3726)
gbirman5487644ce438
diff --git a/js/app/packages/block-email/component/BaseInput.tsx b/js/app/packages/block-email/component/BaseInput.tsxindex 251e58d346..e1167ddfcb 100644--- a/js/app/packages/block-email/component/BaseInput.tsx+++ b/js/app/packages/block-email/component/BaseInput.tsx@@ -26,7 +26,7 @@ import type { UserMentionRecord } from '@core/component/LexicalMarkdown/utils/meimport { RecipientSelector } from '@core/component/RecipientSelector';import { toast } from '@core/component/Toast/Toast';import { ENABLE_EMAIL_SCHEDULED_SEND } from '@core/constant/featureFlags';-import { useEmail, useUserId } from '@core/context/user';+import { useEmail } from '@core/context/user';import { fileFolderDrop } from '@core/directive/fileFolderDrop';import { fileSelector } from '@core/directive/fileSelector';import { observedSize } from '@core/directive/observedSize';@@ -34,7 +34,6 @@ import { TOKENS } from '@core/hotkey/tokens';import { isMobile } from '@core/mobile/isMobile';import { useTouchOutsideToDismissKeyboard } from '@core/mobile/useTouchOutsideToDismissKeyboard';import { trackMention } from '@core/signal/mention';-import { tryMacroId, useDisplayName } from '@core/user';import { plural } from '@core/util/string';import { handleFileFolderDrop } from '@core/util/upload';@@ -51,6 +50,7 @@ import Forward from '@phosphor/arrow-bend-up-right.svg';import ChevronDown from '@phosphor/caret-down.svg';import Paperclip from '@phosphor/paperclip.svg';+import PencilSimple from '@phosphor/pencil-simple.svg';import Quotes from '@phosphor/quotes.svg';import TextAa from '@phosphor/text-aa.svg';@@ -136,6 +136,7 @@ import {useEmailContext,} from './EmailContext';import { getOrInitEmailFormContext } from './EmailFormContext';+import { FromInboxSelector } from './FromInboxSelector';false && fileFolderDrop;false && fileSelector;@@ -322,7 +323,7 @@ function TruncatedRecipientList(props: {return (<divuse:observedSize={{ setSize: setContainerRect }}- class="flex items-center text-sm overflow-hidden whitespace-nowrap mt-1 min-w-0 flex-1"+ class="flex items-center text-sm overflow-hidden whitespace-nowrap min-w-0"onclick={props.onClick}>{/* Hidden measurement element - must have same font styles */}@@ -440,6 +441,7 @@ export function BaseInput(props: {// inbox for a new message. Mutations send it as X-Email-Link-Id when it's a// non-primary inbox so the draft/send targets the right account.const activeLinkId = () =>+ form().selectedLinkId() ??ctx.thread()?.link_id ??props.draft?.link_id ??primaryLinkId() ??@@ -662,9 +664,6 @@ export function BaseInput(props: {return registerToggleAppendedThread(editor);});- const userId = useUserId();- const [userName] = useDisplayName(tryMacroId(userId() ?? ''));-let draftSaveTimer: number | undefined;let pendingDeletion = false;let pendingSend = false;@@ -1427,12 +1426,22 @@ export function BaseInput(props: {<Showwhen={showExpandedRecipients()}fallback={- <TruncatedRecipientList- toRecipients={form().recipients().to}- ccRecipients={form().recipients().cc}- bccRecipients={form().recipients().bcc}+ <div+ class="flex flex-1 items-center gap-1.5 min-w-0 mt-1 text-sm text-ink-muted"onClick={() => setShowExpandedRecipients(true)}- />+ >+ <TruncatedRecipientList+ toRecipients={form().recipients().to}+ ccRecipients={form().recipients().cc}+ bccRecipients={form().recipients().bcc}+ onClick={() => setShowExpandedRecipients(true)}+ />+ <Show when={(emailLinksQuery.data?.links.length ?? 0) > 1}>+ <span class="shrink-0 text-ink-extra-muted">·</span>+ <span class="shrink-0 truncate">from {activeInboxEmail()}</span>+ </Show>+ <PencilSimple class="size-3.5 shrink-0 text-ink-extra-muted" />+ </div>}><div@@ -1440,11 +1449,16 @@ export function BaseInput(props: {class="w-full text-sm text-ink-muted">{/* Expanded FROM */}- <div class="flex flex-row items-baseline py-0.5">+ <div class="flex flex-row items-center py-0.5"><div class="min-w-8">from</div>- <span class="ml-2">- {userName()} <{activeInboxEmail()}>- </span>+ <div class="pl-4 min-w-0 flex-1">+ <FromInboxSelector+ links={emailLinksQuery.data?.links ?? []}+ activeLinkId={activeLinkId()}+ onSelect={(id) => form().setSelectedFromLink(id)}+ readonly={!!props.replyingTo()}+ />+ </div></div>{/* Expanded TO */}diff --git a/js/app/packages/block-email/component/FromInboxSelector.tsx b/js/app/packages/block-email/component/FromInboxSelector.tsxnew file mode 100644index 0000000000..9a6fb3feac--- /dev/null+++ b/js/app/packages/block-email/component/FromInboxSelector.tsx@@ -0,0 +1,90 @@+import { UserIcon, type UserIconProps } from '@core/component/UserIcon';+import { emailToMacroId, useDisplayName } from '@core/user';+import ChevronDown from '@phosphor/caret-down.svg';+import Check from '@phosphor/check.svg';+import { Dropdown } from '@ui';+import { For, Show } from 'solid-js';++type FromInbox = { id: string; email_address: string };++// Resolve each inbox's identity from its own address, not the link's macro_id:+// an own secondary inbox shares the parent account's macro_id, so keying on the+// address gives each inbox its own name and icon.+function inboxIconProps(inbox: FromInbox): UserIconProps {+ const macroId = emailToMacroId(inbox.email_address);+ return macroId ? { id: macroId } : { email: inbox.email_address };+}++/** A single inbox: the account's user icon, name, and address. */+function FromInboxOption(props: { inbox: FromInbox }) {+ const [name] = useDisplayName(emailToMacroId(props.inbox.email_address));+ return (+ <>+ <UserIcon+ {...inboxIconProps(props.inbox)}+ size="sm"+ suppressClick+ class="shrink-0"+ />+ <span class="flex-1 truncate">+ <Show when={name()} fallback={props.inbox.email_address}>+ {name()} <{props.inbox.email_address}>+ </Show>+ </span>+ </>+ );+}++/**+ * Lets the user pick which linked inbox a compose/reply sends from. Renders an+ * identical "from" chip in every composer: the active inbox's icon, name, and+ * address, with a dropdown over the other inboxes when there's more than one.+ */+export function FromInboxSelector(props: {+ links: FromInbox[];+ activeLinkId: string | undefined;+ onSelect: (linkId: string) => void;+ readonly?: boolean;+}) {+ const activeInbox = () =>+ props.links.find((l) => l.id === props.activeLinkId) ?? props.links[0];+ return (+ <Show when={activeInbox()}>+ {(active) => (+ <Show+ when={!props.readonly && props.links.length > 1}+ fallback={+ <div class="flex items-center gap-2 min-w-0 text-sm text-ink-muted">+ <Show when={active()} keyed>+ {(inbox) => <FromInboxOption inbox={inbox} />}+ </Show>+ </div>+ }+ >+ <Dropdown>+ <Dropdown.Trigger class="gap-2 text-sm text-ink-muted">+ <Show when={active()} keyed>+ {(inbox) => <FromInboxOption inbox={inbox} />}+ </Show>+ <ChevronDown class="size-3 shrink-0" />+ </Dropdown.Trigger>+ <Dropdown.Content>+ <Dropdown.Group>+ <For each={props.links}>+ {(inbox) => (+ <Dropdown.Item onSelect={() => props.onSelect(inbox.id)}>+ <FromInboxOption inbox={inbox} />+ <Show when={inbox.id === props.activeLinkId}>+ <Check class="size-3.5 shrink-0" />+ </Show>+ </Dropdown.Item>+ )}+ </For>+ </Dropdown.Group>+ </Dropdown.Content>+ </Dropdown>+ </Show>+ )}+ </Show>+ );+}diff --git a/js/app/packages/block-email/component/compose/Compose.tsx b/js/app/packages/block-email/component/compose/Compose.tsxindex 0531cb01bd..a9dd7dbbf1 100644--- a/js/app/packages/block-email/component/compose/Compose.tsx+++ b/js/app/packages/block-email/component/compose/Compose.tsx@@ -98,18 +98,35 @@ export function EmailCompose(props: EmailComposeProps) {const deleteDraftMutation = useDeleteDraftMutation();const emailContext = useMaybeEmailContext();+ const form = createEmailFormState(+ props.draftID+ ? {+ type: 'draft',+ messageID: props.draftID,+ }+ : undefined,+ emailContext+ ? {+ getMessageByID: (id) =>+ emailContext.messages.unfiltered().find((m) => m.db_id === id),+ getDraftForMessageReply: emailContext.drafts.getDraftForMessage,+ onRecipientsChange: emailContext.onRecipientsChange,+ }+ : undefined+ );+const primaryLinkId = usePrimaryEmailLinkId();const link = createMemo(() => {const data = emailLinksQuery.data;if (!data || data.links.length === 0) return undefined;- // Send from the inbox that owns the draft being edited; fall back to the- // primary inbox for a fresh compose rather than whichever inbox sorts first.+ // Send from the inbox the user picked, else the inbox that owns the draft+ // being edited, else the primary inbox — not whichever inbox sorts first.const draftLinkId = props.draftID? emailContext?.messages.unfiltered().find((m) => m.db_id === props.draftID)?.link_id: undefined;- const targetId = draftLinkId ?? primaryLinkId();+ const targetId = form.selectedLinkId() ?? draftLinkId ?? primaryLinkId();return data.links.find((l) => l.id === targetId) ?? data.links[0];});@@ -128,23 +145,6 @@ export function EmailCompose(props: EmailComposeProps) {const { users: destinationOptions } = useCombinedRecipients();- const form = createEmailFormState(- props.draftID- ? {- type: 'draft',- messageID: props.draftID,- }- : undefined,- emailContext- ? {- getMessageByID: (id) =>- emailContext.messages.unfiltered().find((m) => m.db_id === id),- getDraftForMessageReply: emailContext.drafts.getDraftForMessage,- onRecipientsChange: emailContext.onRecipientsChange,- }- : undefined- );-const [editor, setEditor] = createSignal<LexicalEditor | undefined>();const [content, setContent] = createSignal('');const [currentDraftID, setCurrentDraftID] = createSignal<string | undefined>(@@ -666,6 +666,9 @@ export function EmailCompose(props: EmailComposeProps) {// DisplayfromAddress: () => link()?.email_address,+ fromInboxes: () => emailLinksQuery.data?.links ?? [],+ selectedFromLinkId: () => link()?.id,+ onSelectFromLink: form.setSelectedFromLink,hasPaidAccess,};diff --git a/js/app/packages/block-email/component/compose/ComposeContext.ts b/js/app/packages/block-email/component/compose/ComposeContext.tsindex 37debd80fd..b03220edcc 100644--- a/js/app/packages/block-email/component/compose/ComposeContext.ts+++ b/js/app/packages/block-email/component/compose/ComposeContext.ts@@ -66,6 +66,11 @@ export interface ComposeContextValue {// DisplayfromAddress?: Accessor<string | undefined>;+ // From-inbox selection: the inboxes the user can send from, the active one,+ // and a setter to change it.+ fromInboxes?: Accessor<{ id: string; email_address: string }[]>;+ selectedFromLinkId?: Accessor<string | undefined>;+ onSelectFromLink?: (linkId: string) => void;hasPaidAccess: Accessor<boolean>;// Toolbar slot — allows orchestrators to provide a custom toolbardiff --git a/js/app/packages/block-email/component/compose/ComposeLayout.tsx b/js/app/packages/block-email/component/compose/ComposeLayout.tsxindex 165f699b32..62a58a287d 100644--- a/js/app/packages/block-email/component/compose/ComposeLayout.tsx+++ b/js/app/packages/block-email/component/compose/ComposeLayout.tsx@@ -2,6 +2,7 @@ import { CircleSpinner } from '@core/component/CircleSpinner';import { registerHotkey, useHotkeyDOMScope } from '@core/hotkey/hotkeys';import { TOKENS } from '@core/hotkey/tokens';import { createSignal, type JSX, onMount, Show, Suspense } from 'solid-js';+import { FromInboxSelector } from '../FromInboxSelector';import { ComposeBody } from './ComposeBody';import { useCompose } from './ComposeContext';import { ComposeRecipients } from './ComposeRecipients';@@ -175,11 +176,14 @@ export function ComposeLayout(props: {}><Show when={ctx.fromAddress?.()}>- {(addr) => (- <div class="text-xs text-ink-extra-muted/50">- from {addr()}- </div>- )}+ <div class="text-xs text-ink-extra-muted/50 flex items-center gap-1">+ <span>from</span>+ <FromInboxSelector+ links={ctx.fromInboxes?.() ?? []}+ activeLinkId={ctx.selectedFromLinkId?.()}+ onSelect={(id) => ctx.onSelectFromLink?.(id)}+ />+ </div></Show></Suspense>}diff --git a/js/app/packages/block-email/component/createEmailFormState.ts b/js/app/packages/block-email/component/createEmailFormState.tsindex dab32164a1..29f1e8214d 100644--- a/js/app/packages/block-email/component/createEmailFormState.ts+++ b/js/app/packages/block-email/component/createEmailFormState.ts@@ -104,12 +104,17 @@ export function createEmailFormState(}const linksQuery = useEmailLinksQuery();- // Reply logic ("did I send this?") must be judged against the inbox that owns- // the thread, not the account's primary email — otherwise replying within a- // secondary or delegated inbox misclassifies the sender and picks the wrong- // recipients.+ // The inbox this compose sends from. Defaults to the inbox that owns the+ // thread/draft; the user can change it via the "from" selector.+ const [selectedLinkId, setSelectedLinkId] = createSignal<string | undefined>(+ (draft ?? replyingTo)?.link_id ?? undefined+ );+ // Reply logic ("did I send this?") must be judged against the inbox the+ // message is sent from, not the account's primary email — otherwise replying+ // from a secondary or delegated inbox misclassifies the sender and picks the+ // wrong recipients.const inboxEmail = () => {- const linkId = (draft ?? replyingTo)?.link_id;+ const linkId = selectedLinkId() ?? (draft ?? replyingTo)?.link_id;const ownerEmail = linkId? linksQuery.data?.links.find((l) => l.id === linkId)?.email_address: undefined;@@ -285,6 +290,20 @@ export function createEmailFormState(return rt;};+ // Change the inbox this compose sends from. For an active reply, re-derive the+ // recipients against the newly selected inbox (the sender comparison changes).+ const setSelectedFromLink = (linkId: string | undefined) => {+ setSelectedLinkId(linkId);+ if (!replyingTo || draft || state.replyType === 'forward') return;+ const recalculated =+ state.replyType === 'reply-all'+ ? getReplyAllRecipients(replyingTo, inboxEmail())+ : getReplyRecipientsFromParent(replyingTo, inboxEmail());+ setRecipients('to', recalculated.to ?? []);+ setRecipients('cc', recalculated.cc ?? []);+ setRecipients('bcc', recalculated.bcc ?? []);+ };+const setSendTime = (date: Date | null) => {setState('sendTime', date ?? undefined);};@@ -335,6 +354,8 @@ export function createEmailFormState(setSubject,replyType: () => state.replyType,setReplyType,+ selectedLinkId: () => selectedLinkId(),+ setSelectedFromLink,shouldFocusInput,setShouldFocusInput,sendTime: () => state.sendTime,