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.

feat(onboarding): separate switch for the domain notice email (#9914)

Jacob Beckerman0de2d28629b3
diff --git a/apps/web/src/features/onboarding/context/onboarding-context.tsx b/apps/web/src/features/onboarding/context/onboarding-context.tsx
index 96ae26186c..f61c29a0d5 100644
--- a/apps/web/src/features/onboarding/context/onboarding-context.tsx
+++ b/apps/web/src/features/onboarding/context/onboarding-context.tsx
@@ -115,12 +115,14 @@ export type OnboardingContext = {
configureGithubRepositories(): void;
createTeamDirectory(): TeamDirectorySource;
/** Rejects on failure; the capability reports its own errors. */
- /** `allowDomainJoin` lets people on the owner's work domain join, and
- * tells the owner's same-domain contacts the team exists. */
+ /** `allowDomainJoin` lets people on the owner's work domain join.
+ * `notifyDomain` also emails the owner's same-domain contacts that the team
+ * exists; the server sends it only to a team with an auto-join domain. */
createTeam(input: {
name: string;
invites: string[];
allowDomainJoin: boolean;
+ notifyDomain: boolean;
}): Promise<void>;
/** Rejects on failure; the capability reports its own errors. */
joinTeam(inviteId: string): Promise<void>;
diff --git a/apps/web/src/features/onboarding/create-app-onboarding-context.ts b/apps/web/src/features/onboarding/create-app-onboarding-context.ts
index f0492ab975..9a315db4c6 100644
--- a/apps/web/src/features/onboarding/create-app-onboarding-context.ts
+++ b/apps/web/src/features/onboarding/create-app-onboarding-context.ts
@@ -301,11 +301,12 @@ export function createAppOnboardingContext(): OnboardingContext {
},
};
},
- createTeam: async ({ name, invites, allowDomainJoin }) => {
+ createTeam: async ({ name, invites, allowDomainJoin, notifyDomain }) => {
const creation = createTeam.mutateAsync({
name,
invites: invites.map((email) => ({ email })),
allowDomainJoin,
+ notifyDomain,
});
createdTeam = createdTeamId(creation);
await creation;
diff --git a/apps/web/src/features/onboarding/primitives/team-step.ts b/apps/web/src/features/onboarding/primitives/team-step.ts
index f58ff223fb..5ecd3769f9 100644
--- a/apps/web/src/features/onboarding/primitives/team-step.ts
+++ b/apps/web/src/features/onboarding/primitives/team-step.ts
@@ -137,6 +137,10 @@ export function createTeamForm(
// Only a work domain can be joined by domain; on by default.
const [allowDomainJoin, setAllowDomainJoin] = createSignal(true);
const domainJoin = () => seed.domain !== undefined && allowDomainJoin();
+ // The notice invites colleagues to join by domain, so it needs domain join.
+ // The choice is kept while domain join is off and returns with it.
+ const [notifyDomainChoice, setNotifyDomain] = createSignal(true);
+ const notifyDomain = () => domainJoin() && notifyDomainChoice();
const invites = () => validInviteEmails(rows.slots(), options.ownEmail);
const canCreate = () => name().trim().length > 0 && !pending();
@@ -150,6 +154,7 @@ export function createTeamForm(
name: name().trim(),
invites: sent,
allowDomainJoin: domainJoin(),
+ notifyDomain: notifyDomain(),
});
} catch {
// The capability reports its own failure; keep the form intact.
@@ -166,6 +171,7 @@ export function createTeamForm(
.length,
used_domain_suggestion: seed.domain !== undefined,
allow_domain_join: domainJoin(),
+ notify_domain: notifyDomain(),
});
options.onCreated?.(sent);
};
@@ -181,6 +187,9 @@ export function createTeamForm(
domain: seed.domain,
allowDomainJoin,
setAllowDomainJoin,
+ /** Whether the domain notice will be sent; off while domain join is. */
+ notifyDomain,
+ setNotifyDomain,
create,
};
}
diff --git a/apps/web/src/features/onboarding/tests/fake-onboarding-context.ts b/apps/web/src/features/onboarding/tests/fake-onboarding-context.ts
index 6fd04fdb21..a8ae47cc9a 100644
--- a/apps/web/src/features/onboarding/tests/fake-onboarding-context.ts
+++ b/apps/web/src/features/onboarding/tests/fake-onboarding-context.ts
@@ -137,6 +137,14 @@ export function defaultFakeWorld(): FakeOnboardingWorld {
};
}
+/** How a recorded createTeam call marks domain join: `:closed` without it,
+ * `:quiet` with it but no notice, nothing when both are on. */
+function domainSuffix(allowDomainJoin: boolean, notifyDomain: boolean) {
+ if (!allowDomainJoin) return ':closed';
+ if (!notifyDomain) return ':quiet';
+ return '';
+}
+
/**
* An in-memory onboarding backend behind the real contract. `onChange` lets a
* harness persist the world; `roundTrip` models the inbox OAuth redirect by
@@ -308,9 +316,9 @@ export function createFakeOnboarding(
contacts: () => ({ t: 'ready', value: world.contacts }),
retry: () => call('retryTeams'),
}),
- createTeam: async ({ name, invites, allowDomainJoin }) => {
+ createTeam: async ({ name, invites, allowDomainJoin, notifyDomain }) => {
call(
- `createTeam:${name}:${invites.join(',')}${allowDomainJoin ? '' : ':closed'}`
+ `createTeam:${name}:${invites.join(',')}${domainSuffix(allowDomainJoin, notifyDomain)}`
);
fail('createTeam');
update((draft) => {
diff --git a/apps/web/src/features/onboarding/views/onboarding-flow-view.test.tsx b/apps/web/src/features/onboarding/views/onboarding-flow-view.test.tsx
index 1811717a45..39e2fd416e 100644
--- a/apps/web/src/features/onboarding/views/onboarding-flow-view.test.tsx
+++ b/apps/web/src/features/onboarding/views/onboarding-flow-view.test.tsx
@@ -157,6 +157,75 @@ describe('onboarding flow', () => {
);
});
+ it('explains each domain switch without toggling it', async () => {
+ setup({ resume: 'team' });
+ await heading('Built for teams.');
+ await screen.findByDisplayValue('Acme');
+
+ const domainJoin = screen.getByRole('switch', {
+ name: /^Allow @acme.com emails to join/,
+ }) as HTMLInputElement;
+ const joinInfo = screen.getByRole('button', { name: 'About domain join' });
+ expect(joinInfo.getAttribute('aria-description')).toMatch(
+ /joins this team automatically/
+ );
+ expect(
+ screen
+ .getByRole('button', { name: 'About the team email' })
+ .getAttribute('aria-description')
+ ).toMatch(/contacts who aren't on Macro yet/);
+
+ fireEvent.click(joinInfo);
+ expect(domainJoin.checked).toBe(true);
+ // The info button stays out of the switch's accessible name.
+ expect(
+ screen.queryByRole('switch', { name: /About domain join/ })
+ ).toBeNull();
+ });
+
+ it('notifies the domain only while domain join is on', async () => {
+ const { fake } = setup({ resume: 'team' });
+ await heading('Built for teams.');
+ await screen.findByDisplayValue('Acme');
+
+ const domainJoin = screen.getByRole('switch', {
+ name: /^Allow @acme.com emails to join/,
+ }) as HTMLInputElement;
+ const notify = screen.getByRole('switch', {
+ name: /^Notify your team via email/,
+ }) as HTMLInputElement;
+ expect(notify.checked).toBe(true);
+ expect(notify.disabled).toBe(false);
+
+ // Without domain join the notice can't go out, so it reads as off.
+ fireEvent.click(domainJoin);
+ await waitFor(() => expect(notify.disabled).toBe(true));
+ expect(notify.checked).toBe(false);
+
+ // Turning domain join back on restores the earlier choice.
+ fireEvent.click(domainJoin);
+ await waitFor(() => expect(notify.disabled).toBe(false));
+ expect(notify.checked).toBe(true);
+
+ fireEvent.click(notify);
+ click('Create team & invite 2');
+ await waitFor(() =>
+ expect(fake.calls()).toContainEqual(
+ expect.stringMatching(/^createTeam:Acme:[^:]+:quiet$/)
+ )
+ );
+ expect(fake.events()).toContainEqual(
+ expect.objectContaining({
+ event: 'onboarding_v4_team',
+ data: expect.objectContaining({
+ action: 'created',
+ allow_domain_join: true,
+ notify_domain: false,
+ }),
+ })
+ );
+ });
+
it('shows the created team with its invite link before continuing', async () => {
const { fake } = setup({ resume: 'team' });
await heading('Built for teams.');
diff --git a/apps/web/src/features/onboarding/views/team-step.tsx b/apps/web/src/features/onboarding/views/team-step.tsx
index b870cae351..f941e2425f 100644
--- a/apps/web/src/features/onboarding/views/team-step.tsx
+++ b/apps/web/src/features/onboarding/views/team-step.tsx
@@ -1,7 +1,17 @@
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { fireAndForget } from '@core/util/fireAndForget';
+import InfoIcon from '@icon/system/regular/info.svg';
import LinkIcon from '@icon/system/regular/link.svg';
-import { ToggleSwitch } from '@ui';
-import { createMemo, createSignal, Match, Show, Switch } from 'solid-js';
+import { Popover } from '@kobalte/core/popover';
+import { Button, ToggleSwitch } from '@ui';
+import {
+ createMemo,
+ createSignal,
+ type JSX,
+ Match,
+ Show,
+ Switch,
+} from 'solid-js';
import {
ContinueButton,
SecondaryButton,
@@ -146,6 +156,97 @@ const pendingInvites = (
state: ReturnType<ReturnType<typeof createTeamStep>['state']>
) => (state.t === 'invites' ? state.invites : undefined);
+/** A full-width team option switch marked recommended, with an info button
+ * between its label and control. The switch root lays its parts into the row
+ * (`contents`) so the info button sits outside the label: pressing it never
+ * toggles the switch or joins its accessible name. */
+function RecommendedSwitch(props: {
+ checked: boolean;
+ disabled?: boolean;
+ onChange: (checked: boolean) => void;
+ info: string;
+ infoLabel: string;
+ children: JSX.Element;
+}) {
+ return (
+ <div class="flex w-full items-center gap-1.5">
+ <ToggleSwitch
+ size="md"
+ class="contents"
+ labelClass="order-1 data-disabled:opacity-50"
+ controlClass="order-3 ml-auto shrink-0 data-disabled:opacity-50"
+ checked={props.checked}
+ disabled={props.disabled}
+ onChange={props.onChange}
+ label={
+ <span class="text-xs text-ink sm:text-sm">
+ {props.children}
+ <span class="ml-1 whitespace-nowrap rounded bg-ink/5 px-1 py-0.5 align-middle text-[9px] text-ink-muted opacity-60 sm:ml-2 sm:px-1.5 sm:text-[10px]">
+ recommended
+ </span>
+ </span>
+ }
+ />
+ <div class="order-2 flex">
+ <InfoHint label={props.infoLabel}>{props.info}</InfoHint>
+ </div>
+ </div>
+ );
+}
+
+/** An (i) button explaining a setting: a tooltip on hover or focus, and on
+ * touch, where tooltips are off, a popover on tap. */
+function InfoHint(props: { label: string; children: string }) {
+ const [trigger, setTrigger] = createSignal<HTMLButtonElement>();
+ return (
+ <Show
+ when={isTouchDevice()}
+ fallback={
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon-xs"
+ aria-label={props.label}
+ aria-description={props.children}
+ class="text-ink-muted"
+ tooltip={{
+ content: (
+ <span class="block max-w-64 text-left leading-relaxed">
+ {props.children}
+ </span>
+ ),
+ placement: 'top',
+ }}
+ >
+ <InfoIcon class="size-3.5" aria-hidden="true" />
+ </Button>
+ }
+ >
+ <Popover placement="top" gutter={8} modal={false}>
+ <Popover.Trigger
+ as={Button}
+ ref={setTrigger}
+ type="button"
+ variant="ghost"
+ size="icon-xs"
+ aria-label={props.label}
+ class="text-ink-muted"
+ >
+ <InfoIcon class="size-3.5" aria-hidden="true" />
+ </Popover.Trigger>
+ <Popover.Portal
+ mount={trigger()?.closest<HTMLElement>('.portal-scope') ?? undefined}
+ >
+ <Popover.Content class="menu-surface z-action-menu w-72 max-w-[min(18rem,var(--kb-popper-content-available-width),calc(100vw-2rem))] p-3 text-xs leading-relaxed whitespace-normal break-words outline-none">
+ <Popover.Title class="sr-only">{props.label}</Popover.Title>
+ <Popover.Description>{props.children}</Popover.Description>
+ </Popover.Content>
+ </Popover.Portal>
+ </Popover>
+ </Show>
+ );
+}
+
/** Creating the team switches the step to the on-team confirmation, where
* the creator can copy the team's invite link before continuing. */
function TeamForm(props: {
@@ -174,21 +275,27 @@ function TeamForm(props: {
>
<Show when={form.domain}>
{(domain) => (
- <ToggleSwitch
- size="md"
- class="w-full flex-row-reverse justify-between gap-2 border-t border-edge-muted pt-6"
- controlClass="shrink-0"
- checked={form.allowDomainJoin()}
- onChange={form.setAllowDomainJoin}
- label={
- <span class="text-xs text-ink sm:text-sm">
- Allow @{domain()} emails to join
- <span class="ml-1 whitespace-nowrap rounded bg-ink/5 px-1 py-0.5 text-[10px] text-ink-muted sm:ml-2 sm:px-1.5 sm:text-xs">
- recommended
- </span>
- </span>
- }
- />
+ <div class="flex w-full flex-col gap-4 border-t border-edge-muted pt-6">
+ <RecommendedSwitch
+ checked={form.allowDomainJoin()}
+ onChange={form.setAllowDomainJoin}
+ infoLabel="About domain join"
+ info={`Anyone who signs up with an @${domain()} email joins this team automatically. You can turn this off later in Settings.`}
+ >
+ Allow @{domain()} emails to join
+ </RecommendedSwitch>
+ {/* The notice invites colleagues to join by domain, so it
+ reads as off and can't be turned on without domain join. */}
+ <RecommendedSwitch
+ checked={form.notifyDomain()}
+ disabled={!form.allowDomainJoin()}
+ onChange={form.setNotifyDomain}
+ infoLabel="About the team email"
+ info={`We'll email your @${domain()} contacts who aren't on Macro yet to let them know the team exists. Needs domain join on.`}
+ >
+ Notify your team via email
+ </RecommendedSwitch>
+ </div>
)}
</Show>
</TeamSetupFields>
diff --git a/apps/web/src/lib/analytics/app-events.ts b/apps/web/src/lib/analytics/app-events.ts
index 346f73f226..a80a33b2be 100644
--- a/apps/web/src/lib/analytics/app-events.ts
+++ b/apps/web/src/lib/analytics/app-events.ts
@@ -109,8 +109,10 @@ export type AppEvents = {
/** How many of those the user removed before creating the team. */
invites_removed?: number;
used_domain_suggestion?: boolean;
- /** Whether people on the work domain may join, which also sends the notice. */
+ /** Whether people on the work domain may join. */
allow_domain_join?: boolean;
+ /** Whether the domain notice was requested; only with domain join. */
+ notify_domain?: boolean;
};
/**
* The flow finished (free, premium, or plan skipped) with a rollup of
diff --git a/apps/web/src/lib/queries/team/teams.test.ts b/apps/web/src/lib/queries/team/teams.test.ts
new file mode 100644
index 0000000000..01e9c7b372
--- /dev/null
+++ b/apps/web/src/lib/queries/team/teams.test.ts
@@ -0,0 +1,48 @@
+import { describe, expect, it, vi } from 'vitest';
+import { shouldSendDomainNotice } from './teams';
+
+vi.mock('@service-auth/client', () => ({ authServiceClient: {} }));
+
+const DOMAIN_TEAM = { auto_join_domain: 'acme.com' };
+
+describe('shouldSendDomainNotice', () => {
+ it('sends when domain join and the notice are both on', () => {
+ expect(
+ shouldSendDomainNotice(
+ { allowDomainJoin: true, notifyDomain: true },
+ DOMAIN_TEAM
+ )
+ ).toBe(true);
+ });
+
+ it('skips when the notice is off', () => {
+ expect(
+ shouldSendDomainNotice(
+ { allowDomainJoin: true, notifyDomain: false },
+ DOMAIN_TEAM
+ )
+ ).toBe(false);
+ });
+
+ it('skips without domain join, whatever the notice choice', () => {
+ expect(
+ shouldSendDomainNotice(
+ { allowDomainJoin: false, notifyDomain: true },
+ DOMAIN_TEAM
+ )
+ ).toBe(false);
+ });
+
+ it('skips when neither is chosen, as Settings team creation does', () => {
+ expect(shouldSendDomainNotice({}, DOMAIN_TEAM)).toBe(false);
+ });
+
+ it('skips when the team got no auto-join domain', () => {
+ expect(
+ shouldSendDomainNotice(
+ { allowDomainJoin: true, notifyDomain: true },
+ { auto_join_domain: null }
+ )
+ ).toBe(false);
+ });
+});
diff --git a/apps/web/src/lib/queries/team/teams.ts b/apps/web/src/lib/queries/team/teams.ts
index 5b2929b77e..4db8c8de47 100644
--- a/apps/web/src/lib/queries/team/teams.ts
+++ b/apps/web/src/lib/queries/team/teams.ts
@@ -362,12 +362,30 @@ export function useDeleteTeamMutation(callbacks?: DeleteTeamCallbacks) {
type CreateTeamWithInvitesArgs = {
name: string;
invites?: { email: string }[];
- /** Whether people on the owner's work domain join automatically. When
- * explicitly `true`, the owner's same-domain contacts are also told the
- * team exists. Omitted keeps the server default without the notice. */
+ /** Whether people on the owner's work domain join automatically. Omitted
+ * keeps the server default. */
allowDomainJoin?: boolean;
+ /** Whether to email the owner's same-domain contacts that the team exists.
+ * Sent only when `allowDomainJoin` is also `true` and the team got an
+ * auto-join domain; the server sends nothing to a team without one. */
+ notifyDomain?: boolean;
};
type CreateTeamWithInvitesContext = { previousTeams: Team[] | undefined };
+
+/** The domain notice goes out only when both domain join and the notice were
+ * explicitly chosen and the server gave the team an auto-join domain (a
+ * personal email domain gets none). The server also sends nothing without
+ * one; checking here skips a request that can't send anything. */
+export function shouldSendDomainNotice(
+ args: Pick<CreateTeamWithInvitesArgs, 'allowDomainJoin' | 'notifyDomain'>,
+ team: Pick<Team, 'auto_join_domain'>
+): boolean {
+ return (
+ args.allowDomainJoin === true &&
+ args.notifyDomain === true &&
+ !!team.auto_join_domain
+ );
+}
type CreateTeamWithInvitesCallbacks = MutationCallbacks<
Team,
Error,
@@ -383,6 +401,7 @@ export function useCreateTeamWithInvitesMutation(
name,
invites,
allowDomainJoin,
+ notifyDomain,
}: CreateTeamWithInvitesArgs) => {
const team = await throwOnErr(() =>
authServiceClient.createTeam({
@@ -397,7 +416,7 @@ export function useCreateTeamWithInvitesMutation(
// After the invites, so invitees aren't also sent the notice. The
// team already exists, so a failed notice doesn't fail creation.
- if (allowDomainJoin === true && team.auto_join_domain) {
+ if (shouldSendDomainNotice({ allowDomainJoin, notifyDomain }, team)) {
const notice = await catchToResult(() =>
throwOnErr(() => authServiceClient.sendTeamDomainNotice())
);
diff --git a/docs/agent-guide/login.md b/docs/agent-guide/login.md
index 343dbe587a..118e14fdea 100644
--- a/docs/agent-guide/login.md
+++ b/docs/agent-guide/login.md
@@ -296,10 +296,16 @@ then allow onboarding/contacts queries to refresh. The same inputs must retain
their values and focus as suggestions arrive or a background request fails.
Pending queries must show local loading states without suspending the flow.
When the server suggests a work domain, the create form has no Skip button and
-shows an **Allow @domain emails to join** switch, on by default. Creating the
-team with it on sets the team's auto-join domain and, after the invites, emails
-up to 25 of the creator's same-domain contacts who are not on Macro, invited,
-or already sent a notice (`POST /team/domain-notice`). Creating the team does not leave the step: it
+shows two switches, both on by default and marked recommended: **Allow @domain
+emails to join** and **Notify your team via email**. Creating the team with the
+first on sets the team's auto-join domain. With both on, it then, after the
+invites, emails up to 25 of the creator's same-domain contacts who are not on
+Macro, invited, or already sent a notice (`POST /team/domain-notice`). The
+notice switch is disabled and reads off while domain join is off, because the
+server sends nothing to a team without an auto-join domain; turning domain
+join back on restores its earlier setting. Each switch has an info button
+beside it that explains the setting in a tooltip on hover or focus, and in a
+popover on tap on touch devices; pressing it never toggles the switch. Creating the team does not leave the step: it
switches to the **You're on <team>** confirmation, the same panel members who
were already on a team (auto-joined or invite-accepted) see. That panel has
**Copy invite link** beside **Continue**; it copies the team's