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(settings): make account settings provider-neutral for Outlook (#8780)
teo8832d8682637
diff --git a/apps/web/src/features/calendar-view/tour.ts b/apps/web/src/features/calendar-view/tour.tsindex 0e53565542..5b80bfa871 100644--- a/apps/web/src/features/calendar-view/tour.ts+++ b/apps/web/src/features/calendar-view/tour.ts@@ -23,23 +23,23 @@ const openSidebar = {export const calendarTour = defineViewTour({id: 'calendar',title: 'Calendar',- connector: { kind: 'email', label: 'Google' },+ connector: { kind: 'email', label: 'account' },steps: [{// The Calendars list only appears with more than one calendar.target: [CALENDAR_TOUR.sources, VIEW_SHELL_TOUR.aside],...openSidebar,missingHint:- 'Connect another Google account to choose which calendars to show here.',+ 'Connect another account to choose which calendars to show here.',title: 'All your calendars, one schedule',description:- 'Connect multiple Google accounts and see work, personal, and shared calendars together. Expand an account here to toggle individual calendars.',+ 'Connect multiple accounts and see work, personal, and shared calendars together. Expand an account here to toggle individual calendars.',},{- // Copy availability needs a connected Google calendar.+ // Copy availability needs a connected calendar.target: [CALENDAR_TOUR.availability, CALENDAR_TOUR.upcoming],...openSidebar,- missingHint: 'Connect a Google calendar to copy your availability.',+ missingHint: 'Connect a calendar to copy your availability.',title: 'Copy your availability',description:'Choose a date range to copy your open times, then paste them into a message or email. Busy events across your connected calendars are taken into account.',diff --git a/apps/web/src/features/calendar/calendar-settings.test.tsx b/apps/web/src/features/calendar/calendar-settings.test.tsxnew file mode 100644index 0000000000..5b8aa47022--- /dev/null+++ b/apps/web/src/features/calendar/calendar-settings.test.tsx@@ -0,0 +1,113 @@+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';+import { afterEach, beforeEach, expect, it, vi } from 'vitest';++const mocks = vi.hoisted(() => ({+ startAddInbox: vi.fn(),+ links: [] as unknown[],+}));++vi.mock('@core/email-link', () => ({+ useAddInboxFlow: () => mocks.startAddInbox,+}));+vi.mock('@queries/email/link', () => ({+ useEmailLinksQuery: () => ({+ isSuccess: true,+ isPending: false,+ isError: false,+ data: { links: mocks.links },+ refetch: vi.fn(),+ }),+ useDisableCalendarMutation: () => ({ mutate: vi.fn(), isPending: false }),+}));+vi.mock('./hooks/use-calendar-sources', () => ({+ useCalendarSources: () => ({+ sources: () => [],+ calendarsQuery: {+ isSuccess: true,+ isPending: false,+ isError: false,+ data: [],+ refetch: vi.fn(),+ },+ }),+}));+vi.mock('@core/context/user', () => ({ useUserId: () => () => 'macro|self' }));+vi.mock('@app/lib/analytics/posthog', () => ({+ useFeatureFlag: () => () => ({ enabled: true }),+}));++import { CalendarConnectionSettings } from './calendar-settings';++beforeEach(() => {+ vi.clearAllMocks();+ mocks.startAddInbox.mockResolvedValue(undefined);+});+afterEach(cleanup);++it('re-consents the Outlook account whose Connect calendar was clicked', () => {+ mocks.links = [+ {+ id: 'gmail-link',+ macro_id: 'macro|self',+ email_address: '[email protected]',+ provider: 'GMAIL',+ needs_calendar_permission: false,+ needs_reauth: false,+ },+ {+ id: 'outlook-link',+ macro_id: 'macro|self',+ email_address: '[email protected]',+ provider: 'OUTLOOK',+ needs_calendar_permission: true,+ needs_reauth: false,+ },+ ];+ render(() => <CalendarConnectionSettings />);+ fireEvent.click(screen.getByRole('button', { name: 'Connect calendar' }));+ expect(mocks.startAddInbox).toHaveBeenCalledExactlyOnceWith({+ scopes: 'calendar',+ provider: 'OUTLOOK',+ reconnectLinkId: 'outlook-link',+ emailAddress: '[email protected]',+ });+});++it('re-consents a lone Gmail account, restoring mail access it lost', () => {+ mocks.links = [+ {+ id: 'gmail-link',+ macro_id: 'macro|self',+ email_address: '[email protected]',+ provider: 'GMAIL',+ needs_calendar_permission: true,+ needs_reauth: true,+ },+ ];+ render(() => <CalendarConnectionSettings />);+ fireEvent.click(screen.getByRole('button', { name: 'Connect' }));+ expect(mocks.startAddInbox).toHaveBeenCalledExactlyOnceWith({+ scopes: 'gmail_and_calendar',+ provider: 'GMAIL',+ reconnectLinkId: 'gmail-link',+ emailAddress: '[email protected]',+ });+});++it('asks for a provider when connecting another account', () => {+ mocks.links = [+ {+ id: 'outlook-link',+ macro_id: 'macro|self',+ email_address: '[email protected]',+ provider: 'OUTLOOK',+ needs_calendar_permission: false,+ needs_reauth: false,+ },+ ];+ render(() => <CalendarConnectionSettings />);+ fireEvent.click(screen.getByRole('button', { name: 'Connect account' }));+ expect(mocks.startAddInbox).toHaveBeenCalledExactlyOnceWith({+ scopes: 'gmail_and_calendar',+ });+});diff --git a/apps/web/src/features/calendar/calendar-settings.tsx b/apps/web/src/features/calendar/calendar-settings.tsxindex 551818c876..ce52597777 100644--- a/apps/web/src/features/calendar/calendar-settings.tsx+++ b/apps/web/src/features/calendar/calendar-settings.tsx@@ -3,6 +3,7 @@ import { toast } from '@core/component/Toast/Toast';import { enableMultiInbox } from '@core/constant/featureFlags';import { useUserId } from '@core/context/user';import { useAddInboxFlow } from '@core/email-link';+import { calendarConsentScopes } from '@core/email-link/consent';import { fireAndForget } from '@core/util/fireAndForget';import { useEmailLinksQuery } from '@queries/email/link';import { createSignal, Suspense } from 'solid-js';@@ -30,13 +31,15 @@ function CalendarSettingsContent() {const [connecting, setConnecting] = createSignal(false);const [disconnect, setDisconnect] =createSignal<TurnOffCalendarTarget | null>(null);+ const ownedLinks = () =>+ (links.isSuccess ? (links.data?.links ?? []) : []).filter(+ (l) => l.macro_id === userId()+ );const accounts = (): ConnectedCalendarAccount[] => {const groups = groupCalendarSourcesByAccount(sources().filter((s) => s.emailLinkId));- const owned = (links.isSuccess ? (links.data?.links ?? []) : []).filter(- (l) => l.macro_id === userId()- );+ const owned = ownedLinks();return [...owned.map((link) => ({id: link.id,@@ -61,17 +64,30 @@ function CalendarSettingsContent() {})),];};- const connect = async (scopes: 'calendar' | 'gmail_and_calendar') => {+ const connect = async (options: Parameters<typeof startAddInbox>[0]) => {if (connecting()) return;setConnecting(true);try {- await startAddInbox({ scopes });+ await startAddInbox(options);} catch {toast.failure('Could not connect your calendar. Please try again.');} finally {setConnecting(false);}};+ const enableCalendar = (account: ConnectedCalendarAccount) => {+ const link = ownedLinks().find((l) => l.id === account.id);+ if (!link) return;+ fireAndForget(+ connect({+ scopes: calendarConsentScopes(link),+ provider: link.provider,+ reconnectLinkId: link.id,+ emailAddress: link.email_address,+ }),+ 'calendar-settings'+ );+ };return (<><ConnectedCalendars@@ -88,9 +104,12 @@ function CalendarSettingsContent() {fireAndForget(calendarsQuery.refetch(), 'calendar-settings');}}onConnect={() =>- fireAndForget(connect('gmail_and_calendar'), 'calendar-settings')+ fireAndForget(+ connect({ scopes: 'gmail_and_calendar' }),+ 'calendar-settings'+ )}- onEnable={() => fireAndForget(connect('calendar'), 'calendar-settings')}+ onEnable={enableCalendar}onDisconnect={(account) =>setDisconnect({ linkId: account.id, emailAddress: account.email })}diff --git a/apps/web/src/features/calendar/components/connected-calendars.tsx b/apps/web/src/features/calendar/components/connected-calendars.tsxindex 372255b7c8..1c23f44fcd 100644--- a/apps/web/src/features/calendar/components/connected-calendars.tsx+++ b/apps/web/src/features/calendar/components/connected-calendars.tsx@@ -27,7 +27,7 @@ export function ConnectedCalendars(props: {canConnect: boolean;onRetry: () => void;onConnect: () => void;- onEnable: () => void;+ onEnable: (account: ConnectedCalendarAccount) => void;onDisconnect: (account: ConnectedCalendarAccount) => void;isVisible: (id: string) => boolean;onVisibilityChange: (ids: string[], visible: boolean) => void;@@ -74,14 +74,16 @@ export function ConnectedCalendars(props: {</Show>}>- <Button- size="sm"- variant="cta"- disabled={props.connecting}- onClick={props.onEnable}- >- {props.connecting ? 'Connecting…' : 'Connect'}- </Button>+ {(account) => (+ <Button+ size="sm"+ variant="cta"+ disabled={props.connecting}+ onClick={() => props.onEnable(account())}+ >+ {props.connecting ? 'Connecting…' : 'Connect'}+ </Button>+ )}</Show></SettingsRow><Show when={props.loading}>@@ -155,7 +157,7 @@ export function ConnectedCalendars(props: {disabled={props.connecting}onClick={() =>account().needsPermission- ? props.onEnable()+ ? props.onEnable(account()): props.onDisconnect(account())}>@@ -187,7 +189,8 @@ export function ConnectedCalendars(props: {<Checkbox.Label class="min-w-0 text-sm text-ink-muted"><span class="break-words">{calendar().name}</span><Show when={calendar().isPrimary}>- <span class="ml-2 text-xs text-ink-extra-muted">+ {' '}+ <span class="ml-1 text-xs text-ink-extra-muted">Primary</span></Show>diff --git a/apps/web/src/features/settings/Email.tsx b/apps/web/src/features/settings/Email.tsxindex c86d791d41..d23c11ab40 100644--- a/apps/web/src/features/settings/Email.tsx+++ b/apps/web/src/features/settings/Email.tsx@@ -35,13 +35,13 @@ import {import { useRemoveInboxMutation } from '@queries/email/link';import {type BackfillJob,- BackfillJobStatus,type Link as EmailLink,SyncStatus,} from '@service-email/generated/schemas';import { Dialog, Panel, Tooltip, Button as UiButton } from '@ui';import { createMemo, createSignal, For, Match, Show, Switch } from 'solid-js';import { match } from 'ts-pattern';+import { isInitialSyncComplete } from './core/initial-sync';import { InboxSettingsOperations } from './InboxSettingsOperations';import { ConnectAction, StatusDot } from './integration-ui';import {@@ -87,8 +87,8 @@ export function EmailCard(}return latest;});- const hasCompletedBackfill = (linkId: string): boolean =>- latestBackfillByLinkId().get(linkId)?.status === BackfillJobStatus.Complete;+ const initialSyncComplete = (link: EmailLink): boolean =>+ isInitialSyncComplete(link, latestBackfillByLinkId().get(link.id));const removeInboxMutation = useRemoveInboxMutation({onSuccess: (_data, linkId) => {@@ -197,7 +197,7 @@ export function EmailCard(link={primary()}isPrimaryisOwn={primary().macro_id === userId()}- hasCompletedBackfill={hasCompletedBackfill(primary().id)}+ initialSyncComplete={initialSyncComplete(primary())}resyncing={resyncingIds().has(primary().id)}onResync={() => handleResyncInbox(primary().id)}onReconnect={() =>@@ -250,7 +250,7 @@ export function EmailCard(link={link}isPrimary={false}isOwn={link.macro_id === userId()}- hasCompletedBackfill={hasCompletedBackfill(link.id)}+ initialSyncComplete={initialSyncComplete(link)}resyncing={resyncingIds().has(link.id)}onResync={() => handleResyncInbox(link.id)}onReconnect={() =>@@ -462,7 +462,7 @@ function InboxRow(props: {link: EmailLink;isPrimary: boolean;isOwn: boolean;- hasCompletedBackfill: boolean;+ initialSyncComplete: boolean;resyncing: boolean;onResync: () => void;onReconnect: () => void;@@ -519,13 +519,7 @@ function InboxRow(props: {<Match when={getBackfillProgress(props.link.id)}>{(progress) => <BackfillProgressBar progress={progress()} />}</Match>- {/* Settled inbox with a completed backfill from the BE list. */}- <Match- when={- props.link.sync_status === SyncStatus.UP_TO_DATE &&- props.hasCompletedBackfill- }- >+ <Match when={props.initialSyncComplete}><span class="text-xs text-ink-muted">Initial sync complete</span>diff --git a/apps/web/src/features/settings/core/initial-sync.test.ts b/apps/web/src/features/settings/core/initial-sync.test.tsnew file mode 100644index 0000000000..0c12c6f1e7--- /dev/null+++ b/apps/web/src/features/settings/core/initial-sync.test.ts@@ -0,0 +1,29 @@+import { describe, expect, it } from 'vitest';+import { isInitialSyncComplete } from './initial-sync';++describe('isInitialSyncComplete', () => {+ it('reports an up-to-date Outlook inbox as synced without a backfill job', () => {+ expect(+ isInitialSyncComplete(+ { provider: 'OUTLOOK', sync_status: 'UP_TO_DATE' },+ undefined+ )+ ).toBe(true);+ });++ it('keeps an Outlook inbox that is still importing unfinished', () => {+ expect(+ isInitialSyncComplete(+ { provider: 'OUTLOOK', sync_status: 'SYNCING' },+ undefined+ )+ ).toBe(false);+ });++ it('needs a completed backfill job before a Gmail inbox reports as synced', () => {+ const gmail = { provider: 'GMAIL', sync_status: 'UP_TO_DATE' } as const;+ expect(isInitialSyncComplete(gmail, undefined)).toBe(false);+ expect(isInitialSyncComplete(gmail, { status: 'Failed' })).toBe(false);+ expect(isInitialSyncComplete(gmail, { status: 'Complete' })).toBe(true);+ });+});diff --git a/apps/web/src/features/settings/core/initial-sync.ts b/apps/web/src/features/settings/core/initial-sync.tsnew file mode 100644index 0000000000..1ad84d5229--- /dev/null+++ b/apps/web/src/features/settings/core/initial-sync.ts@@ -0,0 +1,28 @@+import {+ type BackfillJob,+ BackfillJobStatus,+ type Link,+ SyncStatus,+ UserProvider,+} from '@service-email/generated/schemas';+import { match } from 'ts-pattern';++/**+ * Whether an inbox has finished its first full sync. Outlook's sync status+ * comes from its sync streams, so up to date means done. Gmail's also reads up+ * to date when the inbox has no backfill job, so its latest job must be+ * complete too.+ */+export function isInitialSyncComplete(+ link: Pick<Link, 'provider' | 'sync_status'>,+ latestBackfill: Pick<BackfillJob, 'status'> | undefined+): boolean {+ if (link.sync_status !== SyncStatus.UP_TO_DATE) return false;+ return match(link.provider)+ .with(UserProvider.OUTLOOK, () => true)+ .with(+ UserProvider.GMAIL,+ () => latestBackfill?.status === BackfillJobStatus.Complete+ )+ .exhaustive(() => false);+}diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.mdindex 057fc5bde9..a9a8736638 100644--- a/docs/agent-guide/calendar.md+++ b/docs/agent-guide/calendar.md@@ -222,9 +222,11 @@ so invitees can open those links. A public booking link stays available whenthe flag request gets no answer, for example when a browser blocks it.Calendar connections live in **Settings → Calendar** (`/app/settings/calendar`).-Connected calendars offers Connect account (the existing Google consent flow),-Connect calendar for accounts missing calendar permission, and Disconnect with-confirmation. When the only linked account lacks calendar permission, the Google+Connected calendars offers Connect account (pick Gmail or Outlook / Microsoft 365,+then consent), Connect calendar for accounts missing calendar permission (consent+again for that account at its own provider with its address preselected, as+Settings → Email's Enable calendar does), and Disconnect with confirmation. When+the only linked account lacks calendar permission, the GoogleCalendar row shows just a filled Connect button for it, with no account list orvisibility note. Disconnect removes calendar access/data, not the Gmail connection.Settings → Calendar lists only the viewer's own inboxes. The **Enable calendar**