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
import { ViewSidebar } from '@app/components/view-shell';
import { useFeatureFlag } from '@app/lib/analytics/posthog';
import { MobileDrawer } from '@components/app/mobile/MobileDrawer';
import { enableMultiInbox } from '@core/constant/featureFlags';
import { useAddInboxFlow } from '@core/email-link';
import { isMobile } from '@core/mobile/isMobile';
import { fireAndForget } from '@core/util/fireAndForget';
import CaretRightIcon from '@icon/system/regular/caret-right.svg';
import CheckIcon from '@icon/system/regular/check.svg';
import GearIcon from '@icon/system/regular/gear.svg';
import MinusIcon from '@icon/system/regular/minus.svg';
import PlusIcon from '@icon/system/regular/plus.svg';
import { Button, Dropdown } from '@ui';
import { createMemo, createSignal, For, Show } from 'solid-js';
import { match } from 'ts-pattern';
import {
type CalendarAccount,
useCalendarAccounts,
} from '../hooks/use-calendar-accounts';
import type { CalendarTimeFormat, CalendarWeekStart } from '../types';
import {
type CalendarAccountGroup,
groupCalendarSourcesByAccount,
} from '../utils/calendar-source-groups';
import { useCalendarView } from './CalendarViewContext';
import { MobilePeriodControls } from './PeriodSelector';
import {
TurnOffCalendarDialog,
type TurnOffCalendarTarget,
} from './TurnOffCalendarDialog';
const WEEK_START_OPTIONS: Array<{
value: CalendarWeekStart;
label: string;
}> = [
{ value: 0, label: 'Sunday' },
{ value: 1, label: 'Monday' },
];
const TIME_FORMAT_OPTIONS: Array<{
value: CalendarTimeFormat;
label: string;
}> = [
{ value: '12-hour', label: '12-hour' },
{ value: '24-hour', label: '24-hour' },
];
function createCalendarSettingsControls(isNarrow: () => boolean) {
const calendarView = useCalendarView();
const accounts = useCalendarAccounts();
const startAddInbox = useAddInboxFlow();
const multiInboxFlag = useFeatureFlag(enableMultiInbox);
const [turnOffTarget, setTurnOffTarget] =
createSignal<TurnOffCalendarTarget | null>(null);
const showCalendarVisibility = () =>
isNarrow() && calendarView.sources().length > 1;
const weekStartLabel = createMemo(
() =>
WEEK_START_OPTIONS.find(
(option) => option.value === calendarView.displaySettings.weekStartsOn
)?.label ?? 'Sunday'
);
const timeFormatLabel = createMemo(
() =>
TIME_FORMAT_OPTIONS.find(
(option) => option.value === calendarView.displaySettings.timeFormat
)?.label ?? '12-hour'
);
// The account row checkbox shows or hides every calendar in the group.
const changeAccountVisibility = (
group: CalendarAccountGroup,
visible: boolean
) => {
calendarView.closeEventDetails();
calendarView.setSourcesVisibility(
group.calendars.map((source) => source.id),
visible
);
};
const isAccountVisible = (group: CalendarAccountGroup) =>
group.calendars.every((source) => calendarView.isSourceVisible(source.id));
const isAccountPartiallyVisible = (group: CalendarAccountGroup) =>
!isAccountVisible(group) &&
group.calendars.some((source) => calendarView.isSourceVisible(source.id));
const changeShowWeekends = (showWeekends: boolean) => {
calendarView.closeEventDetails();
calendarView.setShowWeekends(showWeekends);
};
const changeWeekStartsOn = (weekStartsOn: CalendarWeekStart) => {
calendarView.closeEventDetails();
calendarView.setWeekStartsOn(weekStartsOn);
};
const changeTimeFormat = (timeFormat: CalendarTimeFormat) => {
calendarView.closeEventDetails();
calendarView.setTimeFormat(timeFormat);
};
// The add-inbox flow is entitlement-gated by the backend (402 -> paywall), so
// "Connect another account" follows the multi-inbox flag like the email
// inbox selector rather than mirroring that rule on the client.
const showConnectAccount = () => multiInboxFlag().enabled;
// Enable re-runs Google consent for calendar on an already-connected inbox;
// turn off opens the confirmation, which lives outside the closing menu.
const runAccountAction = (account: CalendarAccount) => {
calendarView.closeEventDetails();
match(account.action)
.with('enable', () => {
fireAndForget(
startAddInbox({
scopes: account.consentScopes,
provider: account.provider,
reconnectLinkId: account.linkId,
emailAddress: account.emailAddress,
}),
'add-inbox'
);
})
.with('reconnect', () => {
fireAndForget(
startAddInbox({
scopes: account.consentScopes,
provider: account.provider,
reconnectLinkId: account.linkId,
emailAddress: account.emailAddress,
}),
'add-inbox'
);
})
.with('turnOff', () => {
setTurnOffTarget({
linkId: account.linkId,
emailAddress: account.emailAddress,
});
})
.exhaustive();
};
// A brand-new account needs the mailbox scopes alongside calendar.
const connectAnotherAccount = () => {
calendarView.closeEventDetails();
fireAndForget(
startAddInbox({ scopes: 'gmail_and_calendar' }),
'calendar-settings'
);
};
return {
calendarView,
showCalendarVisibility,
weekStartLabel,
timeFormatLabel,
changeAccountVisibility,
isAccountVisible,
isAccountPartiallyVisible,
changeShowWeekends,
changeWeekStartsOn,
changeTimeFormat,
accounts,
showConnectAccount,
runAccountAction,
connectAnotherAccount,
turnOffTarget,
clearTurnOffTarget: () => setTurnOffTarget(null),
};
}
type CalendarSettingsControls = ReturnType<
typeof createCalendarSettingsControls
>;
function DesktopCalendarSettings(props: {
controls: CalendarSettingsControls;
sidebar?: boolean;
}) {
const controls = props.controls;
const calendarView = controls.calendarView;
return (
<Dropdown placement={props.sidebar ? 'top-end' : 'bottom-end'}>
<Dropdown.Trigger
variant="ghost"
size={props.sidebar ? 'md' : 'icon-lg'}
class={
props.sidebar
? 'h-(--sidebar-row-height) w-full justify-start gap-(--sidebar-label-gap) rounded-lg border-transparent bg-transparent px-(--sidebar-item-inset) text-left font-normal touch:h-11'
: 'shrink-0 border-transparent bg-transparent'
}
aria-label="Calendar settings"
>
<Show when={props.sidebar} fallback={<GearIcon class="size-5" />}>
<ViewSidebar.Icon>
<GearIcon class="size-4 touch:size-6 shrink-0 pointer-events-none" />
</ViewSidebar.Icon>
<span class="min-w-0 truncate">Settings</span>
</Show>
</Dropdown.Trigger>
<Dropdown.Content class="w-60 max-w-[calc(100vw-1rem)]">
<Show when={controls.showCalendarVisibility()}>
<Dropdown.Group>
<Dropdown.GroupLabel>Calendars</Dropdown.GroupLabel>
<For each={groupCalendarSourcesByAccount(calendarView.sources())}>
{(group) => (
<Dropdown.CheckboxItem
checked={controls.isAccountVisible(group)}
closeOnSelect={false}
onChange={(checked) =>
controls.changeAccountVisibility(group, checked)
}
>
<span class="min-w-0 flex-1 truncate">
{group.emailAddress}
</span>
</Dropdown.CheckboxItem>
)}
</For>
</Dropdown.Group>
</Show>
<Dropdown.Group>
<Dropdown.GroupLabel>Display</Dropdown.GroupLabel>
<Dropdown.CheckboxItem
checked={calendarView.displaySettings.showWeekends}
closeOnSelect={false}
onChange={controls.changeShowWeekends}
>
<span class="flex-1 truncate">Show weekends</span>
</Dropdown.CheckboxItem>
<Dropdown.Sub>
<Dropdown.SubTrigger>
<span class="min-w-0 flex-1 truncate text-xs text-ink-muted">
Week starts on
</span>
<span class="text-sm font-medium text-ink">
{controls.weekStartLabel()}
</span>
<CaretRightIcon class="size-3 shrink-0 text-ink-muted" />
</Dropdown.SubTrigger>
<Dropdown.SubContent class="min-w-36">
<Dropdown.Group>
<Dropdown.RadioGroup
value={String(calendarView.displaySettings.weekStartsOn)}
onChange={(value) =>
controls.changeWeekStartsOn(
Number(value) as CalendarWeekStart
)
}
>
<For each={WEEK_START_OPTIONS}>
{(option) => (
<Dropdown.RadioItem
closeOnSelect
value={String(option.value)}
>
<span class="flex-1">{option.label}</span>
<Dropdown.ItemIndicator>
<CheckIcon class="size-3.5 text-accent" />
</Dropdown.ItemIndicator>
</Dropdown.RadioItem>
)}
</For>
</Dropdown.RadioGroup>
</Dropdown.Group>
</Dropdown.SubContent>
</Dropdown.Sub>
<Dropdown.Sub>
<Dropdown.SubTrigger>
<span class="min-w-0 flex-1 truncate text-xs text-ink-muted">
Time format
</span>
<span class="text-sm font-medium text-ink">
{controls.timeFormatLabel()}
</span>
<CaretRightIcon class="size-3 shrink-0 text-ink-muted" />
</Dropdown.SubTrigger>
<Dropdown.SubContent class="min-w-36">
<Dropdown.Group>
<Dropdown.RadioGroup
value={calendarView.displaySettings.timeFormat}
onChange={(value) =>
controls.changeTimeFormat(value as CalendarTimeFormat)
}
>
<For each={TIME_FORMAT_OPTIONS}>
{(option) => (
<Dropdown.RadioItem closeOnSelect value={option.value}>
<span class="flex-1">{option.label}</span>
<Dropdown.ItemIndicator>
<CheckIcon class="size-3.5 text-accent" />
</Dropdown.ItemIndicator>
</Dropdown.RadioItem>
)}
</For>
</Dropdown.RadioGroup>
</Dropdown.Group>
</Dropdown.SubContent>
</Dropdown.Sub>
</Dropdown.Group>
<Show
when={controls.accounts().length > 0 || controls.showConnectAccount()}
>
<Dropdown.Group>
<Dropdown.GroupLabel>Accounts</Dropdown.GroupLabel>
<For each={controls.accounts()}>
{(account) => (
<Dropdown.Item
closeOnSelect
onSelect={() => controls.runAccountAction(account)}
>
<span class="min-w-0 flex-1 truncate">
{account.emailAddress}
</span>
<span
class="shrink-0 text-xs font-medium"
classList={{
'text-accent': account.action !== 'turnOff',
'text-failure': account.action === 'turnOff',
}}
>
{match(account.action)
.with('enable', () => 'Enable')
.with('reconnect', () => 'Reconnect')
.with('turnOff', () => 'Turn off')
.exhaustive()}
</span>
</Dropdown.Item>
)}
</For>
<Show when={controls.showConnectAccount()}>
<Dropdown.Item
closeOnSelect
onSelect={controls.connectAnotherAccount}
>
<PlusIcon class="size-3.5 shrink-0 text-ink-muted" />
<span class="flex min-w-0 flex-1 flex-col">
<span class="truncate">Connect another account</span>
<span class="truncate text-xs text-ink-muted">
Email and calendar together
</span>
</span>
</Dropdown.Item>
</Show>
</Dropdown.Group>
</Show>
</Dropdown.Content>
</Dropdown>
);
}
function MobileCalendarSettings(props: {
controls: CalendarSettingsControls;
sidebar?: boolean;
}) {
const controls = props.controls;
const calendarView = controls.calendarView;
const [open, setOpen] = createSignal(false);
return (
<MobileDrawer
side="bottom"
open={open()}
onOpenChange={setOpen}
preventScroll={false}
preventScrollbarShift={false}
>
<MobileDrawer.Trigger
as={Button}
variant="ghost"
size={props.sidebar ? 'md' : 'icon-lg'}
class={
props.sidebar
? 'h-(--sidebar-row-height) w-full justify-start gap-(--sidebar-label-gap) rounded-lg px-(--sidebar-item-inset) text-left font-normal touch:h-11'
: 'shrink-0 rounded-full'
}
aria-label="Calendar settings"
>
<Show when={props.sidebar} fallback={<GearIcon class="size-6" />}>
<ViewSidebar.Icon>
<GearIcon class="size-4 touch:size-6 shrink-0 pointer-events-none" />
</ViewSidebar.Icon>
<span class="min-w-0 truncate">Settings</span>
</Show>
</MobileDrawer.Trigger>
<MobileDrawer.Portal>
<MobileDrawer.Overlay />
<MobileDrawer.Content
aria-label="Calendar settings"
class="overflow-y-auto"
>
<MobileDrawer.Handle />
<MobilePeriodControls onSelect={() => setOpen(false)} />
<Show when={controls.showCalendarVisibility()}>
<MobileDrawer.Label>Calendars</MobileDrawer.Label>
<MobileDrawer.Section class="flex shrink-0 flex-col">
<For each={groupCalendarSourcesByAccount(calendarView.sources())}>
{(group) => (
<MobileDrawer.Item
role="checkbox"
aria-checked={
controls.isAccountPartiallyVisible(group)
? 'mixed'
: controls.isAccountVisible(group)
}
onClick={() =>
controls.changeAccountVisibility(
group,
!controls.isAccountVisible(group)
)
}
>
<span class="min-w-0 flex-1 truncate">
{group.emailAddress}
</span>
<Show
when={controls.isAccountPartiallyVisible(group)}
fallback={
<CheckIcon
class="size-4 shrink-0 text-accent"
classList={{
invisible: !controls.isAccountVisible(group),
}}
/>
}
>
<MinusIcon class="size-4 shrink-0 text-accent" />
</Show>
</MobileDrawer.Item>
)}
</For>
</MobileDrawer.Section>
<div class="mt-4" />
</Show>
<MobileDrawer.Label>Display</MobileDrawer.Label>
<MobileDrawer.Section class="flex shrink-0 flex-col">
<MobileDrawer.Item
role="checkbox"
aria-checked={calendarView.displaySettings.showWeekends}
onClick={() =>
controls.changeShowWeekends(
!calendarView.displaySettings.showWeekends
)
}
>
<span class="min-w-0 flex-1 truncate">Show weekends</span>
<CheckIcon
class="size-4 shrink-0 text-accent"
classList={{
invisible: !calendarView.displaySettings.showWeekends,
}}
/>
</MobileDrawer.Item>
</MobileDrawer.Section>
<MobileDrawer.Label class="pt-4">Week starts on</MobileDrawer.Label>
<MobileDrawer.Section class="flex shrink-0 flex-col">
<For each={WEEK_START_OPTIONS}>
{(option) => (
<MobileDrawer.Item
aria-pressed={
calendarView.displaySettings.weekStartsOn === option.value
}
onClick={() => controls.changeWeekStartsOn(option.value)}
>
<span class="flex-1">{option.label}</span>
<CheckIcon
class="size-4 shrink-0 text-accent"
classList={{
invisible:
calendarView.displaySettings.weekStartsOn !==
option.value,
}}
/>
</MobileDrawer.Item>
)}
</For>
</MobileDrawer.Section>
<MobileDrawer.Label class="pt-4">Time format</MobileDrawer.Label>
<MobileDrawer.Section class="flex shrink-0 flex-col">
<For each={TIME_FORMAT_OPTIONS}>
{(option) => (
<MobileDrawer.Item
aria-pressed={
calendarView.displaySettings.timeFormat === option.value
}
onClick={() => controls.changeTimeFormat(option.value)}
>
<span class="flex-1">{option.label}</span>
<CheckIcon
class="size-4 shrink-0 text-accent"
classList={{
invisible:
calendarView.displaySettings.timeFormat !==
option.value,
}}
/>
</MobileDrawer.Item>
)}
</For>
</MobileDrawer.Section>
<Show
when={
controls.accounts().length > 0 || controls.showConnectAccount()
}
>
<MobileDrawer.Label class="pt-4">Accounts</MobileDrawer.Label>
<MobileDrawer.Section class="mb-3 flex shrink-0 flex-col">
<For each={controls.accounts()}>
{(account) => (
<MobileDrawer.Item
onClick={() => {
setOpen(false);
controls.runAccountAction(account);
}}
>
<span class="min-w-0 flex-1 truncate">
{account.emailAddress}
</span>
<span
class="shrink-0 text-xs font-medium"
classList={{
'text-accent': account.action !== 'turnOff',
'text-failure': account.action === 'turnOff',
}}
>
{match(account.action)
.with('enable', () => 'Enable')
.with('reconnect', () => 'Reconnect')
.with('turnOff', () => 'Turn off')
.exhaustive()}
</span>
</MobileDrawer.Item>
)}
</For>
<Show when={controls.showConnectAccount()}>
<MobileDrawer.Item
onClick={() => {
setOpen(false);
controls.connectAnotherAccount();
}}
>
<PlusIcon class="size-4 shrink-0 text-ink-muted" />
<span class="flex min-w-0 flex-1 flex-col">
<span class="truncate">Connect another account</span>
<span class="truncate text-xs text-ink-muted">
Email and calendar together
</span>
</span>
</MobileDrawer.Item>
</Show>
</MobileDrawer.Section>
</Show>
</MobileDrawer.Content>
</MobileDrawer.Portal>
</MobileDrawer>
);
}
/**
* Responsive calendar display settings menu. The turn-off confirmation lives
* outside the menu so it survives the menu closing on select.
*/
export function CalendarSettingsDropdown(props: {
isNarrow?: boolean;
sidebar?: boolean;
}) {
const controls = createCalendarSettingsControls(
() => props.isNarrow ?? false
);
return (
<>
<Show
when={isMobile()}
fallback={
<DesktopCalendarSettings
controls={controls}
sidebar={props.sidebar}
/>
}
>
<MobileCalendarSettings controls={controls} sidebar={props.sidebar} />
</Show>
<TurnOffCalendarDialog
target={controls.turnOffTarget()}
onClose={controls.clearTurnOffTarget}
/>
</>
);
}