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(teams): onboarding step for creating team and inviting members (#2811)

dev-rb9a447414dfd2
diff --git a/js/app/packages/app/component/interactive-onboarding/InteractiveOnboarding.tsx b/js/app/packages/app/component/interactive-onboarding/InteractiveOnboarding.tsx
index d65aec9927..7a8fa71fa3 100644
--- a/js/app/packages/app/component/interactive-onboarding/InteractiveOnboarding.tsx
+++ b/js/app/packages/app/component/interactive-onboarding/InteractiveOnboarding.tsx
@@ -5,6 +5,7 @@ import { registerHotkey, useHotkeyDOMScope } from '@core/hotkey/hotkeys';
import { useLocation, useNavigate } from '@solidjs/router';
import {
createEffect,
+ createMemo,
createSignal,
on,
onCleanup,
@@ -34,6 +35,8 @@ import MobileWebSignupSent from './MobileWebSignupSent';
import { useSendMobileWelcomeEmail } from '@queries/auth';
import { isOk } from '@core/util/maybeResult';
import { toast } from '@core/component/Toast/Toast';
+import { useFeatureFlag } from '@app/lib/analytics/posthog';
+import { ENABLE_INVITE_TEAM_ONBOARDING_OVERRIDE } from '@core/constant/featureFlags';
export default function InteractiveOnboarding() {
const isAuthenticated = useIsAuthenticated();
@@ -101,21 +104,29 @@ function InteractiveOnboardingInner() {
const hasPaid = useHasPaidAccess();
const isAuthenticated = useIsAuthenticated();
- const allLessons = LESSONS.filter((l) => {
- if (l.id === 'choose-plan' && (hasPaid() || tutorialCompleted()))
- return false;
- if (l.id === 'about-us' && isAuthenticated()) return false;
- return true;
+ const inviteTeamEnabled = useFeatureFlag('enable-teams-onboarding', {
+ enabledOverride: ENABLE_INVITE_TEAM_ONBOARDING_OVERRIDE,
});
- const lessons = isTouch
- ? allLessons.filter(
- (l) =>
- l.id === 'welcome' ||
- l.id === 'about-us' ||
- l.id === 'choose-plan' ||
- l.id === 'launch'
- )
- : allLessons;
+ const allLessons = createMemo(() =>
+ LESSONS.filter((l) => {
+ if (l.id === 'choose-plan' && (hasPaid() || tutorialCompleted()))
+ return false;
+ if (l.id === 'about-us' && isAuthenticated()) return false;
+ if (l.id === 'invite-team' && !inviteTeamEnabled().enabled) return false;
+ return true;
+ })
+ );
+ const lessons = createMemo(() =>
+ isTouch
+ ? allLessons().filter(
+ (l) =>
+ l.id === 'welcome' ||
+ l.id === 'about-us' ||
+ l.id === 'choose-plan' ||
+ l.id === 'launch'
+ )
+ : allLessons()
+ );
const testMode = new URLSearchParams(location.search).has('test');
@@ -124,12 +135,16 @@ function InteractiveOnboardingInner() {
const slideIndex =
slideParam !== null ? Math.max(0, parseInt(slideParam, 10) - 1) : null;
- const sortedLessons = [...lessons].sort(
- (a, b) => (a.order ?? 0) - (b.order ?? 0)
+ const sortedLessons = createMemo(() =>
+ [...lessons()].sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
);
const debugCompleted =
slideIndex !== null
- ? new Set(sortedLessons.slice(0, slideIndex).map((l) => l.id))
+ ? new Set(
+ sortedLessons()
+ .slice(0, slideIndex)
+ .map((l) => l.id)
+ )
: undefined;
// Detect a return-from-OAuth param synchronously so we can pre-populate
@@ -141,7 +156,7 @@ function InteractiveOnboardingInner() {
);
const returnCompleted = returningLesson
? new Set(
- sortedLessons
+ sortedLessons()
.filter((l) => (l.order ?? 0) <= (returningLesson.order ?? 0))
.map((l) => l.id)
)
@@ -181,16 +196,23 @@ function InteractiveOnboardingInner() {
let continueButtonRef: HTMLButtonElement | undefined;
- const handleLessonComplete = (buttonLabel?: string) => {
+ const handleLessonComplete = (
+ buttonLabel?: string,
+ options?: { skipFocus?: boolean }
+ ) => {
setContinueLabel(buttonLabel);
setReadyToContinue(true);
// Skip auto-focus on touch — Safari scrolls to the focused element,
// which jumps the view to the bottom on longer lessons.
- if (!isTouch) {
+ if (!isTouch && !options?.skipFocus) {
requestAnimationFrame(() => continueButtonRef?.focus());
}
};
+ const handleLessonUnready = () => {
+ setReadyToContinue(false);
+ };
+
// Programmatic advance for lessons that progress on their own interaction
// (e.g. clicking a plan card) rather than the Continue button.
const advanceLesson = () => {
@@ -513,6 +535,7 @@ function InteractiveOnboardingInner() {
<Dynamic
component={lesson().definition.content}
onComplete={handleLessonComplete}
+ onUnready={handleLessonUnready}
advance={advanceLesson}
isActive={true}
scopeId={scopeId}
@@ -524,6 +547,7 @@ function InteractiveOnboardingInner() {
<Dynamic
component={Demo()}
onComplete={handleLessonComplete}
+ onUnready={handleLessonUnready}
advance={advanceLesson}
isActive={true}
scopeId={scopeId}
@@ -543,7 +567,16 @@ function InteractiveOnboardingInner() {
centered={lesson().definition.centeredButton}
/>
<Show when={lesson().definition.secondaryAction}>
- {(Action) => <Dynamic component={Action()} />}
+ {(Action) => (
+ <Dynamic
+ component={Action()}
+ onComplete={handleLessonComplete}
+ onUnready={handleLessonUnready}
+ advance={advanceLesson}
+ isActive={true}
+ scopeId={scopeId}
+ />
+ )}
</Show>
</div>
</Show>
@@ -576,6 +609,7 @@ function InteractiveOnboardingInner() {
<Dynamic
component={lesson().definition.content}
onComplete={handleLessonComplete}
+ onUnready={handleLessonUnready}
advance={advanceLesson}
isActive={true}
scopeId={scopeId}
@@ -593,7 +627,16 @@ function InteractiveOnboardingInner() {
centered={lesson().definition.centeredButton}
/>
<Show when={lesson().definition.secondaryAction}>
- {(Action) => <Dynamic component={Action()} />}
+ {(Action) => (
+ <Dynamic
+ component={Action()}
+ onComplete={handleLessonComplete}
+ onUnready={handleLessonUnready}
+ advance={advanceLesson}
+ isActive={true}
+ scopeId={scopeId}
+ />
+ )}
</Show>
</div>
</Show>
@@ -630,6 +673,7 @@ function InteractiveOnboardingInner() {
<Dynamic
component={Demo()}
onComplete={handleLessonComplete}
+ onUnready={handleLessonUnready}
advance={advanceLesson}
isActive={true}
scopeId={scopeId}
diff --git a/js/app/packages/app/component/interactive-onboarding/create-onboarding-state.test.ts b/js/app/packages/app/component/interactive-onboarding/create-onboarding-state.test.ts
index 824e74815e..5f46f57f3f 100644
--- a/js/app/packages/app/component/interactive-onboarding/create-onboarding-state.test.ts
+++ b/js/app/packages/app/component/interactive-onboarding/create-onboarding-state.test.ts
@@ -18,7 +18,7 @@ describe('createOnboardingState', () => {
it('should start with all lessons incomplete', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a'), createTestLesson('b')],
+ definitions: () => [createTestLesson('a'), createTestLesson('b')],
});
expect(state.lessons().length).toBe(2);
@@ -33,7 +33,7 @@ describe('createOnboardingState', () => {
it('should sort lessons by order', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [
+ definitions: () => [
createTestLesson('b', 2),
createTestLesson('a', 1),
createTestLesson('c', 3),
@@ -51,7 +51,7 @@ describe('createOnboardingState', () => {
it('should mark initial completed lessons', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a'), createTestLesson('b')],
+ definitions: () => [createTestLesson('a'), createTestLesson('b')],
initialCompleted: new Set(['a']),
});
@@ -66,7 +66,7 @@ describe('createOnboardingState', () => {
it('should be finished if all initially completed', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a'), createTestLesson('b')],
+ definitions: () => [createTestLesson('a'), createTestLesson('b')],
initialCompleted: new Set(['a', 'b']),
});
@@ -83,7 +83,7 @@ describe('createOnboardingState', () => {
it('should return the first incomplete lesson', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a'), createTestLesson('b')],
+ definitions: () => [createTestLesson('a'), createTestLesson('b')],
});
expect(state.currentLesson()?.definition.id).toBe('a');
@@ -95,7 +95,7 @@ describe('createOnboardingState', () => {
it('should return undefined when all done', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a')],
+ definitions: () => [createTestLesson('a')],
});
state.completeLesson('a');
@@ -110,7 +110,7 @@ describe('createOnboardingState', () => {
it('should mark a lesson as completed', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a'), createTestLesson('b')],
+ definitions: () => [createTestLesson('a'), createTestLesson('b')],
});
state.completeLesson('a');
@@ -126,7 +126,7 @@ describe('createOnboardingState', () => {
it('should set isFinished when all completed', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a'), createTestLesson('b')],
+ definitions: () => [createTestLesson('a'), createTestLesson('b')],
});
state.completeLesson('a');
@@ -141,7 +141,7 @@ describe('createOnboardingState', () => {
it('should be a no-op for unknown id', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a')],
+ definitions: () => [createTestLesson('a')],
});
state.completeLesson('unknown');
@@ -156,7 +156,7 @@ describe('createOnboardingState', () => {
it('should mark a lesson as skipped and advance', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a'), createTestLesson('b')],
+ definitions: () => [createTestLesson('a'), createTestLesson('b')],
});
state.skipLesson('a');
@@ -171,7 +171,7 @@ describe('createOnboardingState', () => {
it('should set isFinished when all skipped', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a'), createTestLesson('b')],
+ definitions: () => [createTestLesson('a'), createTestLesson('b')],
});
state.skipLesson('a');
@@ -188,7 +188,7 @@ describe('createOnboardingState', () => {
it('should skip the current lesson', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a'), createTestLesson('b')],
+ definitions: () => [createTestLesson('a'), createTestLesson('b')],
});
state.advanceToNext();
@@ -203,7 +203,7 @@ describe('createOnboardingState', () => {
it('should be a no-op when all done', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a')],
+ definitions: () => [createTestLesson('a')],
});
state.completeLesson('a');
@@ -220,7 +220,7 @@ describe('createOnboardingState', () => {
it('should un-skip a previously skipped lesson', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a'), createTestLesson('b')],
+ definitions: () => [createTestLesson('a'), createTestLesson('b')],
});
state.skipLesson('a');
@@ -236,7 +236,7 @@ describe('createOnboardingState', () => {
it('should ignore out-of-bounds index', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a')],
+ definitions: () => [createTestLesson('a')],
});
state.goToLesson(-1);
@@ -252,7 +252,7 @@ describe('createOnboardingState', () => {
it('should set dismissed to true', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [createTestLesson('a')],
+ definitions: () => [createTestLesson('a')],
});
state.dismiss();
@@ -267,7 +267,7 @@ describe('createOnboardingState', () => {
it('should handle mixed complete and skip correctly', () => {
createRoot((dispose) => {
const state = createOnboardingState({
- definitions: [
+ definitions: () => [
createTestLesson('a'),
createTestLesson('b'),
createTestLesson('c'),
diff --git a/js/app/packages/app/component/interactive-onboarding/create-onboarding-state.ts b/js/app/packages/app/component/interactive-onboarding/create-onboarding-state.ts
index 241857e125..df89485a06 100644
--- a/js/app/packages/app/component/interactive-onboarding/create-onboarding-state.ts
+++ b/js/app/packages/app/component/interactive-onboarding/create-onboarding-state.ts
@@ -1,24 +1,45 @@
-import { createSignal } from 'solid-js';
-import { createStore } from 'solid-js/store';
+import { type Accessor, createEffect, createSignal, on } from 'solid-js';
+import { createStore, reconcile } from 'solid-js/store';
import type { LessonDefinition, LessonId, LessonState } from './types';
interface OnboardingStateOptions {
- definitions: LessonDefinition[];
+ definitions: Accessor<LessonDefinition[]>;
initialCompleted?: Set<LessonId>;
}
export function createOnboardingState(options: OnboardingStateOptions) {
- const sorted = [...options.definitions].sort(
- (a, b) => (a.order ?? 0) - (b.order ?? 0)
- );
+ const sortDefinitions = (defs: LessonDefinition[]) =>
+ [...defs].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
+
+ const buildLessonStates = (
+ defs: LessonDefinition[],
+ existingStates?: LessonState[]
+ ): LessonState[] => {
+ const sorted = sortDefinitions(defs);
+ const existingById = new Map(
+ existingStates?.map((s) => [s.definition.id, s])
+ );
+
+ return sorted.map((def, index) => {
+ const existing = existingById.get(def.id);
+ return {
+ definition: def,
+ index,
+ completed:
+ existing?.completed ?? options.initialCompleted?.has(def.id) ?? false,
+ skipped: existing?.skipped ?? false,
+ };
+ });
+ };
const [store, setStore] = createStore<LessonState[]>(
- sorted.map((def, index) => ({
- definition: def,
- index,
- completed: options.initialCompleted?.has(def.id) ?? false,
- skipped: false,
- }))
+ buildLessonStates(options.definitions())
+ );
+
+ createEffect(
+ on(options.definitions, (defs) => {
+ setStore(reconcile(buildLessonStates(defs, store)));
+ })
);
const [dismissed, setDismissed] = createSignal(false);
diff --git a/js/app/packages/app/component/interactive-onboarding/lessons/index.ts b/js/app/packages/app/component/interactive-onboarding/lessons/index.ts
index c57d224382..413677c747 100644
--- a/js/app/packages/app/component/interactive-onboarding/lessons/index.ts
+++ b/js/app/packages/app/component/interactive-onboarding/lessons/index.ts
@@ -7,6 +7,7 @@ import { markdownMentionsLesson } from './markdown-mentions';
// import { composersPreviewLesson } from './composers-preview';
import { aboutUsLesson } from './about-us';
import { choosePlanLesson } from './choose-plan';
+import { inviteTeamLesson } from './invite-team';
import { launchLesson } from './launch';
export const LESSONS: LessonDefinition[] = [
@@ -18,5 +19,6 @@ export const LESSONS: LessonDefinition[] = [
// composersPreviewLesson,
aboutUsLesson,
choosePlanLesson,
+ inviteTeamLesson,
launchLesson,
];
diff --git a/js/app/packages/app/component/interactive-onboarding/lessons/invite-team.tsx b/js/app/packages/app/component/interactive-onboarding/lessons/invite-team.tsx
new file mode 100644
index 0000000000..4f65080a8d
--- /dev/null
+++ b/js/app/packages/app/component/interactive-onboarding/lessons/invite-team.tsx
@@ -0,0 +1,391 @@
+import {
+ createEffect,
+ createMemo,
+ createSignal,
+ Index,
+ on,
+ Show,
+} from 'solid-js';
+import { Tooltip } from '@core/component/Tooltip';
+import { z } from 'zod';
+import { cn } from '@ui/utils/classname';
+import PlusIcon from '@icon/regular/plus.svg';
+import XIcon from '@icon/regular/x.svg';
+import TrashIcon from '@icon/regular/trash-simple.svg';
+import {
+ invalidateUserTeams,
+ useCreateTeamWithInvitesMutation,
+} from '@queries/team';
+import { useEmail } from '@core/context/user';
+import type { LessonContentProps, LessonDefinition } from '../types';
+
+const inviteFormSchema = z.object({
+ teamName: z
+ .string()
+ .min(1, 'Team name is required')
+ .max(50, 'Team name is too long'),
+ emails: z
+ .array(z.string())
+ .transform((emails) => emails.filter((e) => e.trim() !== ''))
+ .pipe(z.array(z.string().email('Invalid email address'))),
+});
+
+const INVITE_FORM_ID = 'invite-team-form';
+const TEAM_NAME_MAX_LENGTH = 50;
+
+function InviteTeamContent() {
+ return (
+ <div class="flex flex-col gap-3 onboarding-stagger">
+ <p>Create your team and invite collaborators to get started together.</p>
+ </div>
+ );
+}
+
+type FormErrors = {
+ teamName?: string;
+ emails?: Record<number, string | undefined>;
+};
+
+function InviteTeamDemo(props: LessonContentProps) {
+ const [teamName, setTeamName] = createSignal('');
+ const [emails, setEmails] = createSignal<string[]>(['']);
+ const [errors, setErrors] = createSignal<FormErrors>({});
+
+ const createTeamMutation = useCreateTeamWithInvitesMutation({
+ onSettled: () => invalidateUserTeams(),
+ });
+ const userEmail = useEmail();
+
+ const emailPlaceholder = createMemo(() => {
+ const email = userEmail();
+ if (!email) return '[email protected]';
+ const domain = email.split('@')[1];
+ return domain ? `colleague@${domain}` : '[email protected]';
+ });
+
+ const isValid = () => teamName().trim().length > 0;
+ const isPending = () => createTeamMutation.isPending;
+
+ const charCountColor = () => {
+ const len = teamName().length;
+ if (len > TEAM_NAME_MAX_LENGTH) return 'text-failure-ink';
+ if (len > TEAM_NAME_MAX_LENGTH - 10) return 'text-alert-ink';
+ return 'text-ink/40';
+ };
+
+ createEffect(
+ on(
+ () => [isValid(), isPending()] as const,
+ ([valid, pending]) => {
+ props.onComplete(pending ? 'Creating...' : 'Create team', {
+ skipFocus: true,
+ });
+ if (!valid || pending) {
+ props.onUnready();
+ }
+ },
+ { defer: false }
+ )
+ );
+
+ const canAddEmail = () => {
+ const currentEmails = emails();
+ if (currentEmails.length === 0) {
+ return true;
+ }
+ const lastEmail = currentEmails[currentEmails.length - 1];
+ return lastEmail?.trim() !== '';
+ };
+
+ const addEmailField = () => {
+ if (!canAddEmail() || isPending()) return;
+ const newIndex = emails().length;
+ setEmails((prev) => [...prev, '']);
+ requestAnimationFrame(() => {
+ const input = document.getElementById(`invite-email-${newIndex}`);
+ input?.focus();
+ });
+ };
+
+ const updateEmail = (index: number, value: string) => {
+ setEmails((prev) => {
+ const next = [...prev];
+ next[index] = value;
+ return next;
+ });
+ if (errors().emails?.[index]) {
+ setErrors((prev) => {
+ const emailErrors = { ...prev.emails };
+ delete emailErrors[index];
+ return { ...prev, emails: emailErrors };
+ });
+ }
+ };
+
+ const updateTeamName = (value: string) => {
+ setTeamName(value);
+ if (errors().teamName) {
+ setErrors((prev) => ({ ...prev, teamName: undefined }));
+ }
+ };
+
+ const removeEmail = (index: number) => {
+ setEmails((prev) => prev.filter((_, i) => i !== index));
+ setErrors((prev) => {
+ const emailErrors = { ...prev.emails };
+ delete emailErrors[index];
+ return { ...prev, emails: emailErrors };
+ });
+ };
+
+ const validateField = (
+ field: 'teamName' | 'email',
+ index: number,
+ value: string
+ ) => {
+ if (field === 'teamName') {
+ const result = z
+ .string()
+ .min(1, 'Team name is required')
+ .max(50, 'Team name is too long')
+ .safeParse(value);
+ setErrors((prev) => ({
+ ...prev,
+ teamName: result.success ? undefined : result.error.errors[0]?.message,
+ }));
+ } else if (field === 'email' && value.trim() !== '') {
+ const result = z.string().email('Invalid email address').safeParse(value);
+ setErrors((prev) => ({
+ ...prev,
+ emails: {
+ ...prev.emails,
+ [index]: result.success ? undefined : result.error.errors[0]?.message,
+ },
+ }));
+ }
+ };
+
+ const handleSubmit = async (e: SubmitEvent) => {
+ e.preventDefault();
+ if (isPending()) return;
+
+ const result = inviteFormSchema.safeParse({
+ teamName: teamName(),
+ emails: emails(),
+ });
+
+ if (!result.success) {
+ const newErrors: FormErrors = {};
+ for (const error of result.error.errors) {
+ if (error.path[0] === 'teamName') {
+ newErrors.teamName = error.message;
+ } else if (
+ error.path[0] === 'emails' &&
+ typeof error.path[1] === 'number'
+ ) {
+ newErrors.emails = newErrors.emails || {};
+ newErrors.emails[error.path[1]] = error.message;
+ }
+ }
+ setErrors(newErrors);
+ return;
+ }
+
+ setErrors({});
+
+ try {
+ await createTeamMutation.mutateAsync({
+ name: result.data.teamName,
+ emails: result.data.emails.length > 0 ? result.data.emails : undefined,
+ });
+ props.advance();
+ } catch {
+ // Error is displayed in the form via createTeamMutation.error
+ }
+ };
+
+ return (
+ <div class="h-full w-full flex items-start justify-start p-12 overflow-hidden">
+ <form
+ id={INVITE_FORM_ID}
+ onSubmit={handleSubmit}
+ class="w-full max-w-lg flex flex-col gap-8 h-full"
+ >
+ <div class="flex flex-col gap-2 shrink-0 px-2">
+ <label class="text-base font-medium text-ink" for="team-name">
+ Team name
+ </label>
+ <input
+ id="team-name"
+ type="text"
+ value={teamName()}
+ onInput={(e) => updateTeamName(e.currentTarget.value)}
+ onBlur={() => validateField('teamName', 0, teamName())}
+ placeholder="Enter your team name"
+ disabled={isPending()}
+ aria-describedby="team-name-counter"
+ class={cn(
+ 'w-[calc(100%-36px)] px-3 py-2 text-base rounded-xs border bg-panel text-ink placeholder:text-ink/40 bracket-never focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-offset-panel',
+ errors().teamName
+ ? 'border-failure focus-visible:ring-failure'
+ : 'border-edge focus-visible:ring-accent',
+ isPending() && 'opacity-50 cursor-not-allowed'
+ )}
+ />
+ <div class="flex justify-between items-center w-[calc(100%-36px)]">
+ <Show when={errors().teamName}>
+ <p class="text-sm text-failure-ink" role="alert">
+ {errors().teamName}
+ </p>
+ </Show>
+ <p
+ id="team-name-counter"
+ class={cn('text-sm ml-auto', charCountColor())}
+ >
+ {teamName().length}/{TEAM_NAME_MAX_LENGTH}
+ </p>
+ </div>
+ </div>
+
+ <div class="flex flex-col gap-2 min-h-0 flex-1">
+ <div class="flex flex-col min-h-0">
+ <div class="shrink-0 px-2">
+ <label
+ class="text-base font-medium text-ink"
+ id="invite-members-label"
+ >
+ Invite members{' '}
+ <span class="font-normal text-ink/50">(optional)</span>
+ </label>
+ <p class="text-sm text-ink/50" id="invite-members-description">
+ We'll send them an invite to join your workspace
+ </p>
+ </div>
+ <div class="flex flex-col gap-3 overflow-y-auto min-h-0 p-2">
+ <Index each={emails()}>
+ {(email, index) => (
+ <div class="flex flex-col gap-1 shrink-0">
+ <div class="flex items-center gap-2">
+ <input
+ id={`invite-email-${index}`}
+ type="email"
+ value={email()}
+ onInput={(e) =>
+ updateEmail(index, e.currentTarget.value)
+ }
+ onBlur={(e) =>
+ validateField('email', index, e.currentTarget.value)
+ }
+ placeholder={emailPlaceholder()}
+ disabled={isPending()}
+ aria-labelledby="invite-members-label"
+ aria-describedby="invite-members-description"
+ aria-invalid={!!errors().emails?.[index]}
+ class={cn(
+ 'flex-1 px-3 py-2 text-base rounded-xs border bg-panel text-ink placeholder:text-ink/40 bracket-never focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-offset-panel',
+ errors().emails?.[index]
+ ? 'border-failure focus-visible:ring-failure'
+ : 'border-edge focus-visible:ring-accent',
+ isPending() && 'opacity-50 cursor-not-allowed'
+ )}
+ />
+ <Tooltip
+ tooltip={emails().length > 1 ? 'Remove' : 'Clear'}
+ placement="top"
+ >
+ <button
+ type="button"
+ onClick={() =>
+ emails().length === 1
+ ? updateEmail(0, '')
+ : removeEmail(index)
+ }
+ disabled={isPending()}
+ aria-label={
+ emails().length > 1
+ ? `Remove email ${index + 1}`
+ : 'Clear email'
+ }
+ class={cn(
+ 'shrink-0 p-1.5 text-ink/40 hover:text-ink hover:bg-ink/5 rounded-xs bracket-never focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 focus-visible:ring-offset-1 focus-visible:ring-offset-panel',
+ isPending() && 'opacity-50 cursor-not-allowed'
+ )}
+ >
+ <Show
+ when={emails().length > 1}
+ fallback={<XIcon class="size-4" />}
+ >
+ <TrashIcon class="size-4" />
+ </Show>
+ </button>
+ </Tooltip>
+ </div>
+ <Show when={errors().emails?.[index]}>
+ <p class="text-sm text-failure-ink" role="alert">
+ {errors().emails?.[index]}
+ </p>
+ </Show>
+ </div>
+ )}
+ </Index>
+ </div>
+ </div>
+ <div class="flex items-center gap-2 px-2">
+ <button
+ type="button"
+ onClick={addEmailField}
+ disabled={!canAddEmail() || isPending()}
+ aria-label="Add another email invite"
+ class={cn(
+ 'flex-1 flex items-center gap-2 px-3 py-2 text-sm rounded-xs bracket-never focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 focus-visible:ring-offset-1 focus-visible:ring-offset-panel shrink-0',
+ canAddEmail() && !isPending()
+ ? 'text-ink bg-ink/8 hover:bg-ink/12'
+ : 'text-ink/30 bg-ink/4 cursor-not-allowed'
+ )}
+ >
+ <PlusIcon class="size-4" />
+ Add another
+ </button>
+ <div class="shrink-0 w-7" />
+ </div>
+ <p class="text-sm text-ink/40 shrink-0 px-2">
+ You can always invite more people later from Settings
+ </p>
+ </div>
+
+ <Show when={createTeamMutation.error}>
+ <p class="text-sm text-failure-ink px-2" role="alert">
+ {createTeamMutation.error?.message ?? 'Failed to create team'}
+ </p>
+ </Show>
+ </form>
+ </div>
+ );
+}
+
+function SkipAction(props: LessonContentProps) {
+ return (
+ <button
+ type="button"
+ onClick={() => props.advance()}
+ class="w-full px-3 py-2.5 text-lg rounded-xs flex items-center justify-between text-ink/40 hover:text-ink hover:bg-ink/5 bracket-never focus:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 focus-visible:ring-offset-1 focus-visible:ring-offset-panel"
+ >
+ Skip for now
+ </button>
+ );
+}
+
+export const inviteTeamLesson: LessonDefinition = {
+ id: 'invite-team',
+ title: 'Set up your team',
+ content: InviteTeamContent,
+ demo: InviteTeamDemo,
+ order: 90,
+ secondaryAction: SkipAction,
+ onContinue: () => {
+ const form = document.getElementById(
+ INVITE_FORM_ID
+ ) as HTMLFormElement | null;
+ form?.requestSubmit();
+ },
+};
diff --git a/js/app/packages/app/component/interactive-onboarding/types.ts b/js/app/packages/app/component/interactive-onboarding/types.ts
index 723c188f91..71c361c821 100644
--- a/js/app/packages/app/component/interactive-onboarding/types.ts
+++ b/js/app/packages/app/component/interactive-onboarding/types.ts
@@ -21,12 +21,14 @@ export interface LessonDefinition {
/** Center the continue button label. */
centeredButton?: boolean;
/** Optional secondary button rendered below the continue button. */
- secondaryAction?: Component;
+ secondaryAction?: Component<LessonContentProps>;
}
export interface LessonContentProps {
- /** Call when the user has demonstrated understanding. Pass a string to customise the "Get Started" button label. */
- onComplete: (buttonLabel?: string) => void;
+ /** Call when the user has demonstrated understanding. Pass a string to customise the "Get Started" button label. Pass skipFocus: true to prevent auto-focusing the continue button. */
+ onComplete: (buttonLabel?: string, options?: { skipFocus?: boolean }) => void;
+ /** Call to disable the continue button (e.g., when form validation fails). */
+ onUnready: () => void;
/** Whether this lesson is currently visible */
isActive: boolean;
/** Hotkey scope ID from the shell — register all lesson hotkeys into this scope */
diff --git a/js/app/packages/core/constant/featureFlags.ts b/js/app/packages/core/constant/featureFlags.ts
index a112510793..0bb508f946 100644
--- a/js/app/packages/core/constant/featureFlags.ts
+++ b/js/app/packages/core/constant/featureFlags.ts
@@ -329,3 +329,7 @@ export function ENABLE_CALLS(): boolean {
return analytics.posthog.isFeatureEnabled('enable-calls') ?? false;
}
+
+export const ENABLE_INVITE_TEAM_ONBOARDING_OVERRIDE = DEV_MODE_ENV
+ ? true
+ : undefined;
diff --git a/js/app/packages/queries/team/index.ts b/js/app/packages/queries/team/index.ts
index 694af39107..276eeb8fb4 100644
--- a/js/app/packages/queries/team/index.ts
+++ b/js/app/packages/queries/team/index.ts
@@ -4,6 +4,7 @@ export {
useUserTeamsQuery,
useTeamQuery,
useCreateTeamMutation,
+ useCreateTeamWithInvitesMutation,
usePatchTeamMutation,
useDeleteTeamMutation,
invalidateUserTeams,
diff --git a/js/app/packages/queries/team/teams.ts b/js/app/packages/queries/team/teams.ts
index 4c46265a0f..8f78f6de98 100644
--- a/js/app/packages/queries/team/teams.ts
+++ b/js/app/packages/queries/team/teams.ts
@@ -7,6 +7,7 @@ import type { Team } from '@service-auth/generated/schemas/team';
import { useMutation, useQuery } from '@tanstack/solid-query';
import type { Accessor } from 'solid-js';
+import { authKeys } from '../auth';
import { queryClient } from '../client';
import { type MutationCallbacks, withCallbacks } from '../utils';
@@ -147,3 +148,94 @@ export function useDeleteTeamMutation(callbacks?: DeleteTeamCallbacks) {
),
}));
}
+
+type CreateTeamWithInvitesArgs = {
+ name: string;
+ emails?: string[];
+};
+type CreateTeamWithInvitesContext = { previousTeams: Team[] | undefined };
+type CreateTeamWithInvitesCallbacks = MutationCallbacks<
+ Team,
+ Error,
+ CreateTeamWithInvitesArgs,
+ CreateTeamWithInvitesContext
+>;
+
+export function useCreateTeamWithInvitesMutation(
+ callbacks?: CreateTeamWithInvitesCallbacks
+) {
+ return useMutation(() => ({
+ mutationFn: async ({ name, emails }: CreateTeamWithInvitesArgs) => {
+ const team = await throwOnErr(() =>
+ authServiceClient.createTeam({ name })
+ );
+
+ if (emails && emails.length > 0) {
+ await throwOnErr(() =>
+ authServiceClient.inviteToTeam(team.id, { emails })
+ );
+ }
+
+ return team;
+ },
+
+ ...withCallbacks<
+ Team,
+ Error,
+ CreateTeamWithInvitesArgs,
+ CreateTeamWithInvitesContext
+ >(
+ {
+ onMutate: async ({ name }) => {
+ await queryClient.cancelQueries({
+ queryKey: teamKeys.userTeams.queryKey,
+ });
+
+ const previousTeams = queryClient.getQueryData<Team[]>(
+ teamKeys.userTeams.queryKey
+ );
+
+ const userInfo = queryClient.getQueryData<{ userId: string }>(
+ authKeys.userInfo.queryKey
+ );
+
+ if (userInfo?.userId) {
+ const optimisticTeam: Team = {
+ id: `optimistic-${Date.now()}`,
+ name,
+ owner_id: userInfo.userId,
+ };
+
+ queryClient.setQueryData<Team[]>(
+ teamKeys.userTeams.queryKey,
+ (old) => (old ? [...old, optimisticTeam] : [optimisticTeam])
+ );
+ }
+
+ return { previousTeams };
+ },
+
+ onSuccess: (_team, { emails }) => {
+ invalidateUserTeams();
+ const hasInvites = emails && emails.length > 0;
+ toast.success(
+ hasInvites ? 'Team created and invitations sent' : 'Team created'
+ );
+ },
+
+ onError: (error, _args, context) => {
+ console.error('Failed to create team', error);
+ toast.failure('Failed to create team');
+
+ if (context?.previousTeams) {
+ queryClient.setQueryData(
+ teamKeys.userTeams.queryKey,
+ context.previousTeams
+ );
+ }
+ },
+ },
+ callbacks
+ ),
+ }));
+}