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
fix(calendar): set up the calendar view from your own inboxes only (#8692)
gbirmand78bef176149
diff --git a/apps/web/src/features/calendar-view/components/SetupStatus.test.tsx b/apps/web/src/features/calendar-view/components/SetupStatus.test.tsxnew file mode 100644index 0000000000..7c10a38f6d--- /dev/null+++ b/apps/web/src/features/calendar-view/components/SetupStatus.test.tsx@@ -0,0 +1,185 @@+/**+ * @vitest-environment jsdom+ */++import type { Link as EmailLink } from '@service-email/generated/schemas';+import { cleanup, render, screen } from '@solidjs/testing-library';+import userEvent from '@testing-library/user-event';+import { createSignal } from 'solid-js';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++const mocks = vi.hoisted(() => ({ startAddInbox: vi.fn() }));++const [userId, setUserId] = createSignal<string | undefined>('macro|self');+const [links, setLinks] = createSignal<EmailLink[]>([]);++vi.mock('@app/features/calendar/components/CalendarPagerContext', () => ({+ useCalendarPager: () => ({+ activeData: () => ({+ range: () => undefined,+ occurrencesQuery: { isSuccess: true },+ events: () => [],+ }),+ activeTeamEvents: () => [],+ }),+}));++vi.mock('@core/context/user', () => ({ useUserId: () => userId }));++vi.mock('@core/email-link', () => ({+ useAddInboxFlow: () => mocks.startAddInbox,+}));++vi.mock('@queries/calendar/calendars', () => ({+ useVisibleCalendarsQuery: () => ({ isSuccess: true, data: [] }),+}));++vi.mock('@queries/email/link', () => ({+ useEmailLinksQuery: () => ({+ isSuccess: true,+ get data() {+ return { links: links() };+ },+ }),+}));++import { SetupStatus } from './SetupStatus';++// Only the overlay over an empty grid explains itself; the pill is title and+// action alone.+const CONNECT_DESCRIPTION =+ 'Connect a Google or Microsoft account to show your calendar events.';++const link = (id: string, overrides: Partial<EmailLink> = {}): EmailLink =>+ ({+ id,+ provider: 'GMAIL',+ macro_id: 'macro|self',+ email_address: `${id}@example.com`,+ is_sync_active: true,+ needs_calendar_permission: false,+ needs_reauth: false,+ calendar_disabled: false,+ ...overrides,+ }) as unknown as EmailLink;++const delegated = (id: string, overrides: Partial<EmailLink> = {}) =>+ link(id, { macro_id: 'macro|someone-else', ...overrides });++beforeEach(() => {+ mocks.startAddInbox.mockResolvedValue(undefined);+ setUserId('macro|self');+ setLinks([]);+});++afterEach(() => {+ cleanup();+ vi.clearAllMocks();+});++describe('SetupStatus', () => {+ it('asks a delegate with no inbox of their own to connect one', async () => {+ const user = userEvent.setup();+ setLinks([delegated('shared', { needs_calendar_permission: true })]);+ render(() => <SetupStatus />);++ expect(screen.getByText('Connect your calendar')).toBeTruthy();+ expect(screen.getByText(CONNECT_DESCRIPTION)).toBeTruthy();+ expect(screen.queryByText('Enable calendar')).toBeNull();+ await user.click(screen.getByRole('button', { name: 'Connect calendar' }));++ expect(mocks.startAddInbox).toHaveBeenCalledWith({+ provider: undefined,+ reconnectLinkId: undefined,+ emailAddress: undefined,+ scopes: 'gmail_and_calendar',+ });+ });++ it('offers a delegate whose shared calendar works their own without covering the grid', async () => {+ const user = userEvent.setup();+ setLinks([delegated('shared')]);+ render(() => <SetupStatus />);++ expect(screen.getByText('Connect your calendar')).toBeTruthy();+ expect(screen.queryByText(CONNECT_DESCRIPTION)).toBeNull();+ await user.click(screen.getByRole('button', { name: 'Connect calendar' }));++ expect(mocks.startAddInbox).toHaveBeenCalledWith(+ expect.objectContaining({+ reconnectLinkId: undefined,+ scopes: 'gmail_and_calendar',+ })+ );+ });++ it('keeps an own inbox’s fix out of the way while a shared calendar works', () => {+ setLinks([+ delegated('shared'),+ link('own', { needs_calendar_permission: true }),+ ]);+ render(() => <SetupStatus />);++ expect(screen.getByRole('button', { name: 'Grant access' })).toBeTruthy();+ expect(+ screen.queryByText('Grant calendar access to show your events in Macro.')+ ).toBeNull();+ });++ it('grants access for the viewer’s own inbox, not a delegated one needing reconnect', async () => {+ const user = userEvent.setup();+ setLinks([+ delegated('shared', { needs_reauth: true }),+ link('own', { needs_calendar_permission: true }),+ ]);+ render(() => <SetupStatus />);++ expect(screen.getByText('Enable calendar')).toBeTruthy();+ expect(screen.queryByText('Reconnect calendar')).toBeNull();+ await user.click(screen.getByRole('button', { name: 'Grant access' }));++ expect(mocks.startAddInbox).toHaveBeenCalledWith({+ provider: 'GMAIL',+ reconnectLinkId: 'own',+ emailAddress: '[email protected]',+ scopes: 'calendar',+ });+ });++ it('says calendar is off from the viewer’s own inboxes alone', async () => {+ const user = userEvent.setup();+ setLinks([+ delegated('shared', { needs_calendar_permission: true }),+ link('own', { needs_calendar_permission: true, calendar_disabled: true }),+ ]);+ render(() => <SetupStatus />);++ expect(screen.getByText('Calendar is off')).toBeTruthy();+ await user.click(screen.getByRole('button', { name: 'Turn on' }));++ expect(mocks.startAddInbox).toHaveBeenCalledWith(+ expect.objectContaining({ reconnectLinkId: 'own', scopes: 'calendar' })+ );+ });++ it('stays quiet when the viewer’s own calendar works, whatever a delegated inbox needs', () => {+ setLinks([+ link('own'),+ delegated('reauth', { needs_reauth: true }),+ delegated('permission', { needs_calendar_permission: true }),+ ]);+ render(() => <SetupStatus />);++ expect(screen.queryByRole('button')).toBeNull();+ });++ it('waits for the viewer’s id before deciding', () => {+ setUserId(undefined);+ setLinks([link('own', { needs_calendar_permission: true })]);+ render(() => <SetupStatus />);+ expect(screen.queryByRole('button')).toBeNull();++ setUserId('macro|self');+ expect(screen.getByRole('button', { name: 'Grant access' })).toBeTruthy();+ });+});diff --git a/apps/web/src/features/calendar-view/components/SetupStatus.tsx b/apps/web/src/features/calendar-view/components/SetupStatus.tsxindex 8ac6d9561c..bb694f7ae0 100644--- a/apps/web/src/features/calendar-view/components/SetupStatus.tsx+++ b/apps/web/src/features/calendar-view/components/SetupStatus.tsx@@ -1,9 +1,11 @@import { useCalendarPager } from '@app/features/calendar/components/CalendarPagerContext';import { isCalendarRangeSupported } from '@app/features/calendar/utils/calendar-supported-range';+import { useUserId } from '@core/context/user';import { useAddInboxFlow } from '@core/email-link';import { fireAndForget } from '@core/util/fireAndForget';import { useVisibleCalendarsQuery } from '@queries/calendar/calendars';import { useEmailLinksQuery } from '@queries/email/link';+import type { Link as EmailLink } from '@service-email/generated/schemas';import { Button } from '@ui';import { createMemo, For, Show } from 'solid-js';@@ -31,6 +33,12 @@ const SETUP_MESSAGES = {},} as const;+function isWorkingCalendar(link: EmailLink) {+ return (+ link.is_sync_active && !link.needs_calendar_permission && !link.needs_reauth+ );+}+/** Displays account setup actions above the complete calendar pager. */export function SetupStatus() {const calendarPager = useCalendarPager();@@ -42,11 +50,29 @@ export function SetupStatus() {: []);const startAddInbox = useAddInboxFlow();+ const userId = useUserId();++ // The links list also carries inboxes another Macro user delegated to the+ // viewer. Whether that user's calendar syncs is theirs to decide, as in the+ // calendar settings, so setup counts and acts on the viewer's own alone.+ const ownLinks = () =>+ linksQuery.isSuccess+ ? (linksQuery.data?.links ?? []).filter(+ (link) => link.macro_id === userId()+ )+ : [];const hasEvents = () =>(calendarPager.activeData()?.events().length ?? 0) > 0 ||calendarPager.activeTeamEvents().length > 0;+ // A working calendar shared with the viewer still fills the grid, so a week+ // without events is not a sign that nothing is set up: setting up their own+ // stays on offer without covering the grid.+ const seesWorkingCalendar = () =>+ linksQuery.isSuccess &&+ (linksQuery.data?.links ?? []).some(isWorkingCalendar);+// Existing events are not evidence that setup is complete: a revoked grant// or delegated inbox can leave events visible without a working calendar// connection belonging to the current user.@@ -57,20 +83,18 @@ export function SetupStatus() {const range = activeData?.range();if (range && !isCalendarRangeSupported(range)) return undefined;- if (!linksQuery.isSuccess || !activeData?.occurrencesQuery.isSuccess) {+ if (+ !linksQuery.isSuccess ||+ !activeData?.occurrencesQuery.isSuccess ||+ userId() === undefined+ ) {return undefined;}- const links = linksQuery.data?.links ?? [];+ const links = ownLinks();if (links.length === 0) return 'connect';- const hasAvailableCalendar = links.some(- (link) =>- link.is_sync_active &&- !link.needs_calendar_permission &&- !link.needs_reauth- );- if (hasAvailableCalendar) return undefined;+ if (links.some(isWorkingCalendar)) return undefined;if (links.some((link) => link.needs_reauth)) return 'reauth';if (links.some((link) => link.needs_calendar_permission)) {// A calendar the user turned off is not a missing upgrade; say so, and@@ -94,7 +118,7 @@ export function SetupStatus() {// alone. Connecting and reconnecting need the mailbox scopes alongside it.const startSetup = () => {const state = setupState();- const links = linksQuery.isSuccess ? linksQuery.data.links : [];+ const links = ownLinks();const link =state === 'reauth'? links.find((link) => link.needs_reauth)@@ -131,7 +155,7 @@ export function SetupStatus() {</Show><Show when={setupState() !== undefined}><Show- when={!hasEvents()}+ when={!hasEvents() && !seesWorkingCalendar()}fallback={<div class="absolute right-2 bottom-2 z-20 flex items-center gap-2 rounded-full border border-edge-muted bg-surface py-1 pr-1 pl-2.5 text-xs text-ink-muted shadow-menu"><span>{setupMessage().title}</span>diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.mdindex 1dcfaf15f5..c166380b2d 100644--- a/docs/agent-guide/calendar.md+++ b/docs/agent-guide/calendar.md@@ -232,6 +232,13 @@ toast (behind `enable-calendar-prompt-web` and `enable-calendar-prompt-mobile`)follows the same rule: it asks once per own inbox missing calendar permission,never for an inbox another Macro user delegated to the viewer (a **Shared** rowin Settings → Email, whose per-inbox Enable calendar button stays available).+The calendar view's setup prompt decides and acts on own inboxes alone too: a+delegate with no inbox of their own sees **Connect your calendar**, the Calendar+is off vs Enable calendar wording counts only own inboxes, and Grant access, Turn+on and Reconnect only start consent for one of them. It covers the grid only in a+week without events and with no working calendar the viewer can see; a working+calendar shared with them keeps it to the bottom-right pill, so a delegate whose+only working calendar is shared sees the pill in every week.Account checkboxes show/hide all child calendars; partial selection is shown asmixed. Individual calendars can also be shown/hidden. The account color is thedefault for its calendars; a child color overrides it. Click a color dot to open