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(calendar): open Email guests in its own composer when another is open (#8562)

gbirman252d9b202b95
diff --git a/apps/web/src/features/calendar-view/components/focus-new-composer.test.ts b/apps/web/src/features/calendar-view/components/focus-new-composer.test.ts
new file mode 100644
index 0000000000..5247a2083b
--- /dev/null
+++ b/apps/web/src/features/calendar-view/components/focus-new-composer.test.ts
@@ -0,0 +1,38 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import { EMAIL_COMPOSE_TO_INPUT_ID } from '@app/features/email-compose/core/constants';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { focusNewComposerTo } from './focus-new-composer';
+
+const mocks = vi.hoisted(() => ({ triggerFocusInput: vi.fn() }));
+
+vi.mock('@core/directive/focusInput', () => ({
+ triggerFocusInput: mocks.triggerFocusInput,
+}));
+
+function mountToInput() {
+ const input = document.createElement('input');
+ input.id = EMAIL_COMPOSE_TO_INPUT_ID;
+ document.body.append(input);
+ return input;
+}
+
+afterEach(() => {
+ document.body.replaceChildren();
+ vi.clearAllMocks();
+});
+
+describe('focusNewComposerTo', () => {
+ it('waits for the new composer instead of focusing one already open', () => {
+ mountToInput();
+
+ focusNewComposerTo();
+ const target = mocks.triggerFocusInput.mock.calls[0][0];
+ expect(target()).toBeUndefined();
+
+ const opened = mountToInput();
+ expect(target()).toBe(opened);
+ });
+});
diff --git a/apps/web/src/features/calendar-view/components/focus-new-composer.ts b/apps/web/src/features/calendar-view/components/focus-new-composer.ts
new file mode 100644
index 0000000000..b16ff09b58
--- /dev/null
+++ b/apps/web/src/features/calendar-view/components/focus-new-composer.ts
@@ -0,0 +1,16 @@
+import { EMAIL_COMPOSE_TO_INPUT_ID } from '@app/features/email-compose/core/constants';
+import { triggerFocusInput } from '@core/directive/focusInput';
+
+const toInputs = () =>
+ document.querySelectorAll<HTMLElement>(`[id="${EMAIL_COMPOSE_TO_INPUT_ID}"]`);
+
+/**
+ * Focus the To field of the composer about to open, within this gesture so
+ * the iOS keyboard opens. Every composer's To field shares one id, so a
+ * composer already open is skipped: focusing it would leave the new one
+ * unfocused once closing the details hands focus back to the calendar chip.
+ */
+export function focusNewComposerTo() {
+ const open = new Set(toInputs());
+ triggerFocusInput(() => [...toInputs()].find((input) => !open.has(input)));
+}
diff --git a/apps/web/src/features/calendar-view/components/use-forward-event-email.ts b/apps/web/src/features/calendar-view/components/use-forward-event-email.ts
index 0d58d24638..2d8b347e5e 100644
--- a/apps/web/src/features/calendar-view/components/use-forward-event-email.ts
+++ b/apps/web/src/features/calendar-view/components/use-forward-event-email.ts
@@ -6,12 +6,11 @@ import {
eventDisplayTitle,
eventForwardSummary,
} from '@app/features/calendar/utils/event-forward-summary';
-import { EMAIL_COMPOSE_TO_INPUT_ID } from '@app/features/email-compose/core/constants';
import { useSplitLayout } from '@components/app/split-layout/layout';
import { toast } from '@core/component/Toast/Toast';
-import { triggerFocusInput } from '@core/directive/focusInput';
import { Telemetry } from '@macro-inc/observability';
import { fetchCalendarEventIcs } from '@queries/calendar/ics';
+import { focusNewComposerTo } from './focus-new-composer';
/**
* Opens a new email that passes the event on, as Gmail forwards an
@@ -32,11 +31,8 @@ export function useForwardEventEmail() {
Telemetry.span('calendar.forward_event', async (span) => {
span.setAttr('calendar.event_id', event.eventId);
options.closeDetails();
- // Focus the To field within this gesture so the iOS keyboard opens; the
- // composer mounts after the file arrives, so this waits for the input.
- triggerFocusInput(() =>
- document.getElementById(EMAIL_COMPOSE_TO_INPUT_ID)
- );
+ // The composer mounts after the file arrives; the focus waits for it.
+ focusNewComposerTo();
const ics = await fetchCalendarEventIcs(event.eventId);
if (ics.isErr()) {
span.error('Calendar event .ics fetch failed');
diff --git a/apps/web/src/features/calendar-view/components/use-open-event-email.ts b/apps/web/src/features/calendar-view/components/use-open-event-email.ts
index a59f789084..e60ddf4cec 100644
--- a/apps/web/src/features/calendar-view/components/use-open-event-email.ts
+++ b/apps/web/src/features/calendar-view/components/use-open-event-email.ts
@@ -1,8 +1,7 @@
import type { CalendarEvent } from '@app/features/calendar/types';
import { eventEmailRecipients } from '@app/features/calendar/utils/guest-emails';
-import { EMAIL_COMPOSE_TO_INPUT_ID } from '@app/features/email-compose/core/constants';
import { useSplitLayout } from '@components/app/split-layout/layout';
-import { triggerFocusInput } from '@core/directive/focusInput';
+import { focusNewComposerTo } from './focus-new-composer';
/**
* Opens a new email addressed to the event's other guests. Desktop gets the
@@ -15,9 +14,7 @@ export function useOpenEventEmail() {
const { openWithSplit } = useSplitLayout();
return (event: CalendarEvent) => {
- // Focus the To field within this gesture so the iOS keyboard opens; the
- // composer mounts asynchronously, so this waits for the input.
- triggerFocusInput(() => document.getElementById(EMAIL_COMPOSE_TO_INPUT_ID));
+ focusNewComposerTo();
openWithSplit(
{
type: 'component',
@@ -25,7 +22,9 @@ export function useOpenEventEmail() {
params: { initialTo: eventEmailRecipients(event) },
preserveParams: true,
},
- { preferNewSplit: true }
+ // A composer already open holds another message; reusing it would
+ // drop these recipients.
+ { preferNewSplit: true, allowDuplicate: true }
);
};
}
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index 2ce30f796f..c5d4684f78 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -435,7 +435,8 @@ As in Google Calendar, the guests row of the details popover (a bottom sheet on
carries `Copy guest emails` and `Email guests` icon buttons. Copying puts every guest's
address on the clipboard, comma-separated. Emailing opens a new email addressed to every
guest but you — in a split beside the calendar on desktop, as the full-screen composer on
-touch devices — and is hidden when you are the only guest.
+touch devices, in its own composer even when another one is open — and is hidden when you
+are the only guest.
With the `enable-calendar-guest-invites` flag on, a third icon button, `Add guests`, shows
whenever the event's `viewerCan.inviteGuests` allows it, including for a guest whose
organizer lets guests invite. It opens an editor anchored to the button (a bottom sheet on
@@ -467,7 +468,7 @@ is absent from teammates' out-of-office chips. Its endpoint, document storage's
belongs to.
Beside it, `Forward by email` (shown under the same rule) passes the event on the way Gmail
forwards an invitation: it closes the details, fetches the same file, and opens a new email
-where `Email guests` does (its own composer, even when another one is open), with no recipients, the title as subject, a plain-text summary in
+where `Email guests` does, with no recipients, the title as subject, a plain-text summary in
the body (title, when in the viewer's zone, the repeat rule in words, location, organizer and
description, never guests or a join link) and the `.ics` attached as a picked file would be.
Nothing is saved as a draft until you edit something. The file is `METHOD:PUBLISH`, so