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(settings): move log out to account and guard account deletion (#8154)

Jacob Beckerman330c069cabb3
diff --git a/apps/marketing/src/app/routes/RouteDeleteAccount.tsx b/apps/marketing/src/app/routes/RouteDeleteAccount.tsx
index 809163bb33..a19e16b837 100644
--- a/apps/marketing/src/app/routes/RouteDeleteAccount.tsx
+++ b/apps/marketing/src/app/routes/RouteDeleteAccount.tsx
@@ -22,7 +22,7 @@ If you cannot access your account email, contact the same address and explain th
1. Open Macro and sign in.
2. Open Settings, then Account.
-3. Under Danger zone, select Delete account and follow the confirmation steps.
+3. Below Log out, select Delete account and follow the confirmation steps. The final step asks you to press and hold the delete button for 5 seconds.
Account deletion is permanent. Save anything you need before confirming. Uninstalling the app does not delete your account.
diff --git a/apps/web/src/components/ui/components/HoldButton.docs.tsx b/apps/web/src/components/ui/components/HoldButton.docs.tsx
new file mode 100644
index 0000000000..7aedc21afc
--- /dev/null
+++ b/apps/web/src/components/ui/components/HoldButton.docs.tsx
@@ -0,0 +1,34 @@
+import { defineDoc } from '@app/features/ui-gallery/types';
+import TrashIcon from '@phosphor/trash.svg';
+import { createSignal } from 'solid-js';
+import { HoldButton } from './HoldButton';
+
+// #region demo:hold
+function HoldDemo() {
+ const [confirmed, setConfirmed] = createSignal(0);
+ return (
+ <div class="flex items-center gap-3">
+ <HoldButton
+ variant="danger"
+ duration={2000}
+ onConfirm={() => setConfirmed((count) => count + 1)}
+ >
+ <TrashIcon />
+ Hold to delete
+ </HoldButton>
+ <span class="text-sm text-ink-muted">Confirmed {confirmed()} times</span>
+ </div>
+ );
+}
+// #endregion
+
+export default defineDoc({
+ name: 'HoldButton',
+ category: 'Actions',
+ description:
+ 'A Button that runs onConfirm only after it is held down for `duration` milliseconds. A fill sweeps across while held; releasing early resets it. Space and Enter can be held too.',
+ status: 'stable',
+ exports: ['HoldButton'],
+ import: "import { HoldButton } from '@ui';",
+ demos: [{ id: 'hold', title: 'Hold to confirm', render: HoldDemo }],
+});
diff --git a/apps/web/src/components/ui/components/HoldButton.test.tsx b/apps/web/src/components/ui/components/HoldButton.test.tsx
new file mode 100644
index 0000000000..6e00b5a1cb
--- /dev/null
+++ b/apps/web/src/components/ui/components/HoldButton.test.tsx
@@ -0,0 +1,98 @@
+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { HoldButton } from './HoldButton';
+
+beforeEach(() => {
+ vi.useFakeTimers();
+});
+
+afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+});
+
+describe('HoldButton', () => {
+ it('confirms only after the press lasts the full duration', () => {
+ const onConfirm = vi.fn();
+ render(() => (
+ <HoldButton duration={5000} onConfirm={onConfirm}>
+ Hold to delete
+ </HoldButton>
+ ));
+ const button = screen.getByRole('button', { name: 'Hold to delete' });
+
+ fireEvent.pointerDown(button);
+ vi.advanceTimersByTime(4999);
+ expect(onConfirm).not.toHaveBeenCalled();
+ vi.advanceTimersByTime(1);
+ expect(onConfirm).toHaveBeenCalledOnce();
+ });
+
+ it('does not confirm when released early or when the pointer leaves', () => {
+ const onConfirm = vi.fn();
+ render(() => (
+ <HoldButton duration={5000} onConfirm={onConfirm}>
+ Hold to delete
+ </HoldButton>
+ ));
+ const button = screen.getByRole('button', { name: 'Hold to delete' });
+
+ fireEvent.pointerDown(button);
+ vi.advanceTimersByTime(4000);
+ fireEvent.pointerUp(button);
+ fireEvent.pointerDown(button);
+ vi.advanceTimersByTime(4000);
+ fireEvent.pointerLeave(button);
+ vi.advanceTimersByTime(5000);
+ expect(onConfirm).not.toHaveBeenCalled();
+ });
+
+ it('does not confirm on a click', () => {
+ const onConfirm = vi.fn();
+ render(() => (
+ <HoldButton duration={5000} onConfirm={onConfirm}>
+ Hold to delete
+ </HoldButton>
+ ));
+
+ fireEvent.click(screen.getByRole('button', { name: 'Hold to delete' }));
+ vi.advanceTimersByTime(5000);
+ expect(onConfirm).not.toHaveBeenCalled();
+ });
+
+ it('confirms when Space is held and not when it is released early', () => {
+ const onConfirm = vi.fn();
+ render(() => (
+ <HoldButton duration={5000} onConfirm={onConfirm}>
+ Hold to delete
+ </HoldButton>
+ ));
+ const button = screen.getByRole('button', { name: 'Hold to delete' });
+
+ fireEvent.keyDown(button, { key: ' ' });
+ vi.advanceTimersByTime(3000);
+ fireEvent.keyUp(button, { key: ' ' });
+ vi.advanceTimersByTime(5000);
+ expect(onConfirm).not.toHaveBeenCalled();
+
+ fireEvent.keyDown(button, { key: ' ' });
+ fireEvent.keyDown(button, { key: ' ', repeat: true });
+ vi.advanceTimersByTime(5000);
+ expect(onConfirm).toHaveBeenCalledOnce();
+ });
+
+ it('ignores presses while disabled', () => {
+ const onConfirm = vi.fn();
+ render(() => (
+ <HoldButton duration={5000} onConfirm={onConfirm} disabled>
+ Hold to delete
+ </HoldButton>
+ ));
+
+ fireEvent.pointerDown(
+ screen.getByRole('button', { name: 'Hold to delete' })
+ );
+ vi.advanceTimersByTime(5000);
+ expect(onConfirm).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/web/src/components/ui/components/HoldButton.tsx b/apps/web/src/components/ui/components/HoldButton.tsx
new file mode 100644
index 0000000000..ee12ddd5cd
--- /dev/null
+++ b/apps/web/src/components/ui/components/HoldButton.tsx
@@ -0,0 +1,98 @@
+import { createSignal, type JSX, onCleanup, splitProps } from 'solid-js';
+import { cn } from '../utils/classname';
+import { Button, type ButtonProps } from './Button';
+
+export type HoldButtonProps = Omit<ButtonProps, 'onClick'> & {
+ /** How long the button must stay pressed before `onConfirm` runs, in ms. */
+ duration: number;
+ /** Runs once when a press lasts the full `duration`. */
+ onConfirm: () => void;
+};
+
+const RELEASE_MS = 150;
+
+/**
+ * Button that only fires after it is held down for `duration`. A fill sweeps
+ * across while held; releasing, leaving, or cancelling early resets it.
+ * Pointer and keyboard (Space or Enter) presses both count.
+ *
+ * @do Use for irreversible actions that people trigger by accident.
+ * @do Say "Hold" in the label so the gesture is discoverable.
+ * @dont Use for routine confirmations; a confirm dialog is enough there.
+ */
+export function HoldButton(props: HoldButtonProps) {
+ const [local, rest] = splitProps(props, [
+ 'duration',
+ 'onConfirm',
+ 'children',
+ 'class',
+ ]);
+ const [holding, setHolding] = createSignal(false);
+ let timer: ReturnType<typeof setTimeout> | undefined;
+
+ function release() {
+ clearTimeout(timer);
+ timer = undefined;
+ setHolding(false);
+ }
+
+ function press() {
+ if (props.disabled || timer !== undefined) return;
+ setHolding(true);
+ timer = setTimeout(() => {
+ release();
+ local.onConfirm();
+ }, local.duration);
+ }
+
+ onCleanup(release);
+
+ const isHoldKey = (event: KeyboardEvent) =>
+ event.key === ' ' || event.key === 'Enter';
+
+ const onKeyDown: JSX.EventHandler<HTMLButtonElement, KeyboardEvent> = (
+ event
+ ) => {
+ if (!isHoldKey(event)) return;
+ event.preventDefault();
+ if (!event.repeat) press();
+ };
+
+ const onKeyUp: JSX.EventHandler<HTMLButtonElement, KeyboardEvent> = (
+ event
+ ) => {
+ if (!isHoldKey(event)) return;
+ event.preventDefault();
+ release();
+ };
+
+ return (
+ <Button
+ {...rest}
+ data-holding={holding() ? '' : undefined}
+ class={cn('overflow-hidden touch-none', local.class)}
+ onPointerDown={(event) => {
+ if (event.button > 0) return;
+ press();
+ }}
+ onPointerUp={release}
+ onPointerLeave={release}
+ onPointerCancel={release}
+ onBlur={release}
+ onKeyDown={onKeyDown}
+ onKeyUp={onKeyUp}
+ onContextMenu={(event) => event.preventDefault()}
+ >
+ <span
+ aria-hidden="true"
+ data-hold-progress
+ class="pointer-events-none absolute inset-0 origin-left bg-current opacity-15"
+ style={{
+ transform: `scaleX(${holding() ? 1 : 0})`,
+ transition: `transform ${holding() ? local.duration : RELEASE_MS}ms linear`,
+ }}
+ />
+ {local.children}
+ </Button>
+ );
+}
diff --git a/apps/web/src/components/ui/index.ts b/apps/web/src/components/ui/index.ts
index af16f65b68..17322e4889 100644
--- a/apps/web/src/components/ui/index.ts
+++ b/apps/web/src/components/ui/index.ts
@@ -86,6 +86,7 @@ export { EmptyStatePanel } from './components/EmptyStatePanel';
export { EntityComposer } from './components/EntityComposer';
export type { FilteredHiddenBannerProps } from './components/FilteredHiddenBanner';
export { FilteredHiddenBanner } from './components/FilteredHiddenBanner';
+export { HoldButton, type HoldButtonProps } from './components/HoldButton';
export { Hotkey } from './components/Hotkey';
export { HoverCard } from './components/HoverCard';
export type {
diff --git a/apps/web/src/features/scheduling/browser-test/fixture.tsx b/apps/web/src/features/scheduling/browser-test/fixture.tsx
index a9f2c1e5a1..a7c5fc9e6c 100644
--- a/apps/web/src/features/scheduling/browser-test/fixture.tsx
+++ b/apps/web/src/features/scheduling/browser-test/fixture.tsx
@@ -363,7 +363,6 @@ function Fixture() {
setSettingsTab(result.tab);
setSelectedResult({ ...result });
}}
- onLogout={() => setNotice('Preview only')}
/>
</ViewShell.Aside>
<ViewShell.Main>
diff --git a/apps/web/src/features/settings/Account.tsx b/apps/web/src/features/settings/Account.tsx
index c082d2f27b..e29d708172 100644
--- a/apps/web/src/features/settings/Account.tsx
+++ b/apps/web/src/features/settings/Account.tsx
@@ -19,7 +19,6 @@ import { staticFileIdEndpoint } from '@core/constant/servers';
import { useSettingsTabAvailable } from '@core/constant/settingsTabsConfig';
import { useEmail, useUserId } from '@core/context/user';
import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
-import { isTouchDevice } from '@core/mobile/isTouchDevice';
import {
type ProfilePictureItem,
useProfilePictureUrl,
@@ -35,6 +34,7 @@ import CheckIcon from '@phosphor/check.svg';
import PencilIcon from '@phosphor/pencil-simple.svg';
import SpinnerIcon from '@phosphor/spinner-gap.svg';
import TrashIcon from '@phosphor/trash.svg';
+import WarningIcon from '@phosphor/warning.svg';
import WarningCircleIcon from '@phosphor/warning-circle.svg';
import SignOutIcon from '@phosphor-icons/core/regular/sign-out.svg?component-solid';
import IconUpload from '@phosphor-icons/core/regular/upload-simple.svg?component-solid';
@@ -45,7 +45,7 @@ import {
} from '@queries/auth/user-name-self';
import { authServiceClient } from '@service-auth/client';
import { invoke } from '@tauri-apps/api/core';
-import { Button, Dialog, Dropdown, Panel, Tooltip } from '@ui';
+import { Button, Dialog, Dropdown, HoldButton, Panel, Tooltip } from '@ui';
import {
createEffect,
createMemo,
@@ -74,6 +74,8 @@ import {
SettingsSection,
} from './primitives';
+const DELETE_HOLD_MS = 5000;
+
// 16 megabytes
const MAX_PROFILE_PICTURE_SIZE = 16 * 1000 * 1000;
@@ -486,43 +488,39 @@ export function Account() {
<AccountPlanCard />
</Show>
- <Show when={isTouchDevice()}>
- <SettingsSection>
- <SettingsCard>
- <div class="px-6 py-3.5">
- <Button
- fullWidth
- variant="accent"
- depth={4}
- onClick={() => logout()}
- >
- <SignOutIcon class="size-4" />
- Log out
- </Button>
- </div>
- </SettingsCard>
- </SettingsSection>
- </Show>
-
- <SettingsSection title="Danger zone">
+ <SettingsSection>
<SettingsCard>
<SettingsRow
- label="Delete account"
- description="Permanently delete your account and all associated data."
+ label="Log out"
+ description="Sign out of Macro on this device."
>
- <Button
- variant="danger"
- depth={3}
- onClick={() => {
- resetDeleteFlow();
- setShowDeleteModal(true);
- }}
- >
- Delete Account
+ <Button variant="outline" depth={3} onClick={() => logout()}>
+ <SignOutIcon class="size-4" />
+ Log out
</Button>
</SettingsRow>
</SettingsCard>
</SettingsSection>
+
+ {/* Deliberately quiet and outside a card, so it isn't mistaken for
+ Log out. */}
+ <SettingsRow
+ class="px-5"
+ label="Delete account"
+ description="Permanently delete your account and all associated data."
+ >
+ <Button
+ variant="danger"
+ size="sm"
+ depth={3}
+ onClick={() => {
+ resetDeleteFlow();
+ setShowDeleteModal(true);
+ }}
+ >
+ Delete account
+ </Button>
+ </SettingsRow>
<Dialog
open={showDeleteModal()}
onOpenChange={(open) => {
@@ -539,10 +537,19 @@ export function Account() {
</Dialog.Title>
</Panel.Header>
<Panel.Body class="p-6 font-sans flex flex-col gap-3">
- <Dialog.Description class="text-ink-muted text-sm/tight font-normal">
- Are you sure you want to delete your account? This action is
- permanent and cannot be undone.
+ <Dialog.Description as="div">
+ <IrreversibleWarning />
</Dialog.Description>
+ <p class="text-ink-muted text-sm/tight">
+ Only want to sign out?{' '}
+ <button
+ type="button"
+ class="text-ink underline underline-offset-2 outline-none focus-visible:ring-2 focus-visible:ring-edge-focus"
+ onClick={() => logout()}
+ >
+ Log out instead
+ </button>
+ </p>
<div class="flex flex-col gap-3 pt-2">
<label class="flex flex-col gap-1.5 text-sm" for="delete-reason">
<span>
@@ -634,9 +641,11 @@ export function Account() {
</Dialog.Title>
</Panel.Header>
<Panel.Body class="p-6 font-sans flex flex-col gap-3">
- <Dialog.Description class="text-ink-muted text-sm/tight font-normal">
- This will permanently delete your account and all associated data.
- This cannot be undone.
+ <Dialog.Description as="div" class="flex flex-col gap-3">
+ <IrreversibleWarning />
+ <p class="text-ink-muted text-sm/tight">
+ To confirm, press and hold the button below for 5 seconds.
+ </p>
</Dialog.Description>
<div class="pt-3 justify-end items-center gap-3 inline-flex">
<Button
@@ -650,17 +659,18 @@ export function Account() {
>
Cancel
</Button>
- <Button
- variant="strong"
+ <HoldButton
+ variant="danger"
depth={3}
+ duration={DELETE_HOLD_MS}
disabled={isDeleting()}
- onClick={deleteAccountHandler}
+ onConfirm={deleteAccountHandler}
>
- <Show when={isDeleting()} fallback="Delete My Account">
+ <Show when={isDeleting()} fallback="Hold to delete my account">
<SpinnerIcon class="size-4 animate-spin" />
Deleting…
</Show>
- </Button>
+ </HoldButton>
</div>
</Panel.Body>
</Panel>
@@ -669,6 +679,24 @@ export function Account() {
);
}
+/** The deletion dialogs' warning; people kept deleting accounts by mistake. */
+function IrreversibleWarning() {
+ return (
+ <div class="flex gap-3 rounded-lg border border-failure/30 bg-failure/10 p-3 text-sm/tight">
+ <WarningIcon class="size-5 shrink-0 text-failure" />
+ <div class="flex flex-col gap-1">
+ <span class="font-semibold text-failure">
+ This is permanent and irreversible.
+ </span>
+ <span class="text-ink">
+ Your account and everything in it, including your documents, messages,
+ files, and settings, will be deleted and cannot be recovered.
+ </span>
+ </div>
+ </div>
+ );
+}
+
function Row(props: { label: string; children?: JSX.Element }) {
return <SettingsRow label={props.label}>{props.children}</SettingsRow>;
}
diff --git a/apps/web/src/features/settings/Settings.tsx b/apps/web/src/features/settings/Settings.tsx
index bbbc0964c8..b3df06d7a8 100644
--- a/apps/web/src/features/settings/Settings.tsx
+++ b/apps/web/src/features/settings/Settings.tsx
@@ -7,7 +7,6 @@ import {
import { PillTabs } from '@components/app/mobile/PillTabs';
import { SplitHeaderLeft } from '@components/app/split-layout/components/SplitHeader';
import { SplitPanel } from '@components/app/split-panel';
-import { useLogout } from '@core/auth/logout';
import { enableEmailSignatures } from '@core/constant/featureFlags';
import {
type SettingsTab,
@@ -38,6 +37,7 @@ import {
searchSettings,
} from './core/settings-search';
import { SettingsTabContent } from './SettingsTabContent';
+import { TeamSidebarAction } from './TeamSidebarAction';
export function SettingsPanelComponentWrapper() {
const params = useParams<{ tab?: string }>();
@@ -84,7 +84,6 @@ export function SettingsPanel(props: SettingsPanelProps) {
const { closeSettings, activeTabId, selectTab } = useSettingsState();
const splitNavigate = useSplitNavigate();
const { groups, searchGroups, flatTabs } = useSettingsTabs();
- const logout = useLogout();
const signatures = useFeatureFlag(enableEmailSignatures);
const activeNavigationTab = activeTabId;
@@ -253,7 +252,7 @@ export function SettingsPanel(props: SettingsPanelProps) {
onSearchQueryChange={setSearchQuery}
isItemActive={isItemActive}
onSelect={selectRoutedTab}
- onLogout={() => logout()}
+ footer={<TeamSidebarAction />}
/>
</ViewShell.Aside>
<ViewShell.Main>
diff --git a/apps/web/src/features/settings/Team.tsx b/apps/web/src/features/settings/Team.tsx
index 240997d0c9..8fa0fbcd92 100644
--- a/apps/web/src/features/settings/Team.tsx
+++ b/apps/web/src/features/settings/Team.tsx
@@ -96,6 +96,7 @@ import {
SettingsSection,
} from './primitives';
import {
+ canInviteToTeam,
canRemoveTeamMember,
isTeamAdminOrOwner,
} from './teamMemberPermissions';
@@ -623,7 +624,10 @@ const teamNameSchema = z
.max(TEAM_NAME_MAX_LENGTH, 'Team name is too long')
);
-function CreateTeamDialog(props: { open: boolean; onClose: () => void }) {
+export function CreateTeamDialog(props: {
+ open: boolean;
+ onClose: () => void;
+}) {
let teamNameInputRef: HTMLInputElement | undefined;
const [teamName, setTeamName] = createSignal('');
const [teamNameError, setTeamNameError] = createSignal<string | undefined>(
@@ -766,6 +770,101 @@ function CreateTeamDialog(props: { open: boolean; onClose: () => void }) {
);
}
+/** Invite people to an existing team by email. */
+export function InviteToTeamDialog(props: {
+ teamId: string;
+ open: boolean;
+ onClose: () => void;
+}) {
+ const inviteToTeamMutation = useInviteToTeamMutation();
+ const [invites, setInvites] = createSignal<InviteEntry[]>([EMPTY_INVITE]);
+ const [inviteErrors, setInviteErrors] = createSignal<(string | undefined)[]>(
+ []
+ );
+
+ const hasValidInvites = () => {
+ const inv = invites();
+ const hasNonEmptyEmail = inv.some((i) => i.email.trim() !== '');
+ const hasNoErrors = !inviteErrors().some((e) => e !== undefined);
+ return hasNonEmptyEmail && hasNoErrors;
+ };
+
+ const validateInvites = () => {
+ const { errors, hasError } = validateInviteEmails(invites());
+ setInviteErrors(errors);
+ return !hasError;
+ };
+
+ const close = () => {
+ setInvites([EMPTY_INVITE]);
+ setInviteErrors([]);
+ props.onClose();
+ };
+
+ const handleInvite = () => {
+ if (!validateInvites()) return;
+
+ const inviteEntries = invites()
+ .filter((i) => i.email.trim() !== '')
+ .map((i) => ({ email: i.email.trim() }));
+ if (inviteEntries.length === 0) return;
+
+ inviteToTeamMutation.mutate(
+ { teamId: props.teamId, request: { invites: inviteEntries } },
+ { onSuccess: close }
+ );
+ };
+
+ return (
+ <Dialog open={props.open} onOpenChange={(open) => !open && close()}>
+ <Panel depth={2} class="max-h-[75vh] text-ink rounded-xl">
+ <Panel.Header class="px-2 gap-1">
+ <Dialog.CloseButton as={Button} variant="ghost" size="icon-sm">
+ <XIcon />
+ </Dialog.CloseButton>
+ <Dialog.Title as="span" class="text-sm font-medium p-0 m-0">
+ Invite to Team
+ </Dialog.Title>
+ </Panel.Header>
+
+ <Panel.Body class="p-3 flex flex-col gap-3">
+ <InviteEmailsInput
+ invites={invites()}
+ onChange={setInvites}
+ errors={inviteErrors()}
+ onErrorsChange={setInviteErrors}
+ />
+ <div class="flex justify-end gap-1 pt-2">
+ <Button
+ variant="ghost"
+ disabled={inviteToTeamMutation.isPending}
+ onClick={close}
+ >
+ Cancel
+ </Button>
+ <Button
+ variant="strong"
+ disabled={!hasValidInvites() || inviteToTeamMutation.isPending}
+ onClick={handleInvite}
+ >
+ <Show
+ when={inviteToTeamMutation.isPending}
+ fallback={
+ invites().length > 1
+ ? `Send ${invites().length} Invites`
+ : 'Send Invite'
+ }
+ >
+ <SpinnerIcon class="size-4 animate-spin" />
+ </Show>
+ </Button>
+ </div>
+ </Panel.Body>
+ </Panel>
+ </Dialog>
+ );
+}
+
function EmptyTeamState() {
const [showCreateModal, setShowCreateModal] = createSignal(false);
@@ -872,7 +971,6 @@ function TeamManagement(props: {
const deleteInviteMutation = useDeleteTeamInviteMutation();
const removeUserMutation = useRemoveUserFromTeamMutation();
const patchTeamMutation = usePatchTeamMutation();
- const inviteToTeamMutation = useInviteToTeamMutation();
const deleteTeamMutation = useDeleteTeamMutation();
const toggleAutoJoinMutation = useToggleAutoJoinDomainMutation();
const toggleNonAdminInvitesMutation = useToggleNonAdminInvitesMutation();
@@ -885,10 +983,6 @@ function TeamManagement(props: {
const [showCancelInviteModal, setShowCancelInviteModal] =
createSignal<TeamInviteDetails | null>(null);
const [showInviteModal, setShowInviteModal] = createSignal(false);
- const [invites, setInvites] = createSignal<InviteEntry[]>([EMPTY_INVITE]);
- const [inviteErrors, setInviteErrors] = createSignal<(string | undefined)[]>(
- []
- );
const [editingTeamName, setEditingTeamName] = createSignal<
string | undefined
>(undefined);
@@ -899,19 +993,6 @@ function TeamManagement(props: {
undefined
);
- const hasValidInvites = () => {
- const inv = invites();
- const hasNonEmptyEmail = inv.some((i) => i.email.trim() !== '');
- const hasNoErrors = !inviteErrors().some((e) => e !== undefined);
- return hasNonEmptyEmail && hasNoErrors;
- };
-
- const validateInvites = () => {
- const { errors, hasError } = validateInviteEmails(invites());
- setInviteErrors(errors);
- return !hasError;
- };
-
const deleteConfirmationPhrase = () => `Delete ${props.teamName}`;
const canDeleteTeam = () =>
deleteConfirmation() === deleteConfirmationPhrase();
@@ -1183,38 +1264,6 @@ function TeamManagement(props: {
);
};
- const handleInvite = () => {
- const currentInvites = invites();
- if (currentInvites.length === 0 || !props.teamId) return;
-
- if (!validateInvites()) {
- return;
- }
-
- const inviteEntries = currentInvites
- .filter((i) => i.email.trim() !== '')
- .map((i) => ({ email: i.email.trim() }));
-
- inviteToTeamMutation.mutate(
- { teamId: props.teamId, request: { invites: inviteEntries } },
- {
- onSuccess: () => {
- setInvites([]);
- setInviteErrors([]);
- setShowInviteModal(false);
- },
- }
- );
- };
-
- const handleInviteModalClose = (open: boolean) => {
- if (!open) {
- setInvites([EMPTY_INVITE]);
- setInviteErrors([]);
- setShowInviteModal(false);
- }
- };
-
return (
<>
<SettingsPage
@@ -1457,7 +1506,9 @@ function TeamManagement(props: {
actions={
// Members can invite unless the team has restricted inviting
// to admins; removals stay admin-only.
- <Show when={isAdminOrOwner() || allowNonAdminInvites()}>
+ <Show
+ when={canInviteToTeam(currentUserRole(), allowNonAdminInvites())}
+ >
<Button
variant="outline"
size="sm"
@@ -1701,52 +1752,11 @@ function TeamManagement(props: {
}
/>
- <Dialog open={showInviteModal()} onOpenChange={handleInviteModalClose}>
- <Panel depth={2} class="max-h-[75vh] text-ink rounded-xl">
- <Panel.Header class="px-2 gap-1">
- <Dialog.CloseButton as={Button} variant="ghost" size="icon-sm">
- <XIcon />
- </Dialog.CloseButton>
- <Dialog.Title as="span" class="text-sm font-medium p-0 m-0">
- Invite to Team
- </Dialog.Title>
- </Panel.Header>
-
- <Panel.Body class="p-3 flex flex-col gap-3">
- <InviteEmailsInput
- invites={invites()}
- onChange={setInvites}
- errors={inviteErrors()}
- onErrorsChange={setInviteErrors}
- />
- <div class="flex justify-end gap-1 pt-2">
- <Button
- variant="ghost"
- disabled={inviteToTeamMutation.isPending}
- onClick={() => handleInviteModalClose(false)}
- >
- Cancel
- </Button>
- <Button
- variant="strong"
- disabled={!hasValidInvites() || inviteToTeamMutation.isPending}
- onClick={handleInvite}
- >
- <Show
- when={inviteToTeamMutation.isPending}
- fallback={
- invites().length > 1
- ? `Send ${invites().length} Invites`
- : 'Send Invite'
- }
- >
- <SpinnerIcon class="size-4 animate-spin" />
- </Show>
- </Button>
- </div>
- </Panel.Body>
- </Panel>
- </Dialog>
+ <InviteToTeamDialog
+ teamId={props.teamId}
+ open={showInviteModal()}
+ onClose={() => setShowInviteModal(false)}
+ />
</>
);
}
diff --git a/apps/web/src/features/settings/TeamSidebarAction.tsx b/apps/web/src/features/settings/TeamSidebarAction.tsx
new file mode 100644
index 0000000000..088949edc9
--- /dev/null
+++ b/apps/web/src/features/settings/TeamSidebarAction.tsx
@@ -0,0 +1,88 @@
+import { ViewSidebar } from '@app/components/view-shell';
+import { useUserId } from '@core/context/user';
+import UserPlusIcon from '@phosphor/user-plus.svg';
+import UsersThreeIcon from '@phosphor/users-three.svg';
+import { useTeamQuery, useUserTeamsQuery } from '@queries/team/teams';
+import { pressHandlers } from '@ui';
+import { createSignal, type JSX, Show } from 'solid-js';
+import { CreateTeamDialog, InviteToTeamDialog } from './Team';
+import { canInviteToTeam } from './teamMemberPermissions';
+
+/**
+ * The settings sidebar's footer action: invite people to your team, or create
+ * a team when you don't have one yet.
+ */
+export function TeamSidebarAction() {
+ const userTeamsQuery = useUserTeamsQuery();
+ // Wait for the teams so the label doesn't flip from Create to Invite.
+ const teams = () =>
+ userTeamsQuery.isSuccess ? userTeamsQuery.data : undefined;
+
+ return (
+ <Show when={teams()}>
+ {(loaded) => (
+ <Show when={loaded()[0]} keyed fallback={<CreateTeamAction />}>
+ {(team) => <InviteToTeamAction teamId={team.id} />}
+ </Show>
+ )}
+ </Show>
+ );
+}
+
+function CreateTeamAction() {
+ const [open, setOpen] = createSignal(false);
+ return (
+ <>
+ <FooterItem
+ icon={<UsersThreeIcon class="size-4" />}
+ label="Create a team"
+ onPress={() => setOpen(true)}
+ />
+ <Show when={open()}>
+ <CreateTeamDialog open onClose={() => setOpen(false)} />
+ </Show>
+ </>
+ );
+}
+
+function InviteToTeamAction(props: { teamId: string }) {
+ const userId = useUserId();
+ const teamQuery = useTeamQuery(() => props.teamId);
+ const [open, setOpen] = createSignal(false);
+ const canInvite = () => {
+ const team = teamQuery.isSuccess ? teamQuery.data : undefined;
+ if (!team) return false;
+ const role = team.members.find(
+ (member) => member.user_id === userId()
+ )?.role;
+ return canInviteToTeam(role, team.team.allow_non_admin_invites);
+ };
+
+ return (
+ <Show when={canInvite()}>
+ <FooterItem
+ icon={<UserPlusIcon class="size-4" />}
+ label="Invite your team"
+ onPress={() => setOpen(true)}
+ />
+ <InviteToTeamDialog
+ teamId={props.teamId}
+ open={open()}
+ onClose={() => setOpen(false)}
+ />
+ </Show>
+ );
+}
+
+function FooterItem(props: {
+ icon: JSX.Element;
+ label: string;
+ onPress: () => void;
+}) {
+ return (
+ <ViewSidebar.Item {...pressHandlers(() => props.onPress())}>
+ <ViewSidebar.Icon>{props.icon}</ViewSidebar.Icon>
+ <span class="truncate">{props.label}</span>
+ </ViewSidebar.Item>
+ );
+}
diff --git a/apps/web/src/features/settings/browser-test/fixture.tsx b/apps/web/src/features/settings/browser-test/fixture.tsx
index 73aafda1a6..0fa6b8eb8f 100644
--- a/apps/web/src/features/settings/browser-test/fixture.tsx
+++ b/apps/web/src/features/settings/browser-test/fixture.tsx
@@ -195,7 +195,6 @@ function Fixture() {
setTab(result.tab);
setSelected({ ...result });
}}
- onLogout={() => {}}
/>
</ViewShell.Aside>
<ViewShell.Main>
diff --git a/apps/web/src/features/settings/components/settings-sidebar.tsx b/apps/web/src/features/settings/components/settings-sidebar.tsx
index 4c22da5c1c..691ee58d08 100644
--- a/apps/web/src/features/settings/components/settings-sidebar.tsx
+++ b/apps/web/src/features/settings/components/settings-sidebar.tsx
@@ -1,17 +1,16 @@
import { SearchBar, ViewSidebar } from '@app/components/view-shell';
import type { SettingsTab } from '@core/constant/SettingsState';
import type { SettingsTabGroup } from '@core/constant/settingsTabsConfig';
-import SignOutIcon from '@phosphor/sign-out.svg';
import { pressHandlers } from '@ui';
-import { For, Show } from 'solid-js';
+import { children, For, type JSX, Show } from 'solid-js';
import { Dynamic } from 'solid-js/web';
import type { SettingsSearchResult } from '../core/settings-search';
import { SettingsSearchResults } from './settings-search-results';
/**
* Settings' inner navigation, laid out like every other view's sidebar: a
- * title bar, a search field, the grouped section pills, and Log out pinned to
- * the bottom.
+ * title bar, a search field, the grouped section pills, and an optional
+ * footer action pinned to the bottom.
*/
export function SettingsSidebar(props: {
groups: SettingsTabGroup[];
@@ -22,8 +21,9 @@ export function SettingsSidebar(props: {
onSearchQueryChange: (query: string) => void;
isItemActive: (tab: SettingsTab) => boolean;
onSelect: (tab: SettingsTab) => void;
- onLogout: () => void;
+ footer?: JSX.Element;
}) {
+ const footer = children(() => props.footer);
let root: HTMLDivElement | undefined;
return (
<ViewSidebar.Root ref={root} aria-label="Settings navigation">
@@ -104,14 +104,11 @@ export function SettingsSidebar(props: {
</Show>
</ViewSidebar.Content>
- <ViewSidebar.Footer class="py-(--sidebar-gutter)">
- <ViewSidebar.Item {...pressHandlers(() => props.onLogout())}>
- <ViewSidebar.Icon>
- <SignOutIcon class="size-4" />
- </ViewSidebar.Icon>
- <span class="truncate">Log out</span>
- </ViewSidebar.Item>
- </ViewSidebar.Footer>
+ <Show when={footer()}>
+ <ViewSidebar.Footer class="py-(--sidebar-gutter)">
+ {footer()}
+ </ViewSidebar.Footer>
+ </Show>
</ViewSidebar.Root>
);
}
diff --git a/apps/web/src/features/settings/teamMemberPermissions.test.ts b/apps/web/src/features/settings/teamMemberPermissions.test.ts
index 4fb4920ac5..1975be1f94 100644
--- a/apps/web/src/features/settings/teamMemberPermissions.test.ts
+++ b/apps/web/src/features/settings/teamMemberPermissions.test.ts
@@ -5,6 +5,7 @@ import {
} from '@service-auth/generated/schemas';
import { describe, expect, it } from 'vitest';
import {
+ canInviteToTeam,
canRemoveTeamMember,
isTeamAdminOrOwner,
} from './teamMemberPermissions.ts';
@@ -21,6 +22,21 @@ function teamMember(userId: string, role: TeamRole): TeamMember {
};
}
+describe('canInviteToTeam', function () {
+ it.each([
+ [TeamRole.owner, false, true],
+ [TeamRole.admin, false, true],
+ [TeamRole.member, true, true],
+ [TeamRole.member, false, false],
+ [undefined, false, false],
+ ])(
+ 'lets the %s role invite when member invites are %s: %s',
+ function (role, allowNonAdminInvites, expected) {
+ expect(canInviteToTeam(role, allowNonAdminInvites)).toBe(expected);
+ }
+ );
+});
+
describe('isTeamAdminOrOwner', function () {
it.each([
[TeamRole.owner, true],
diff --git a/apps/web/src/features/settings/teamMemberPermissions.ts b/apps/web/src/features/settings/teamMemberPermissions.ts
index 24b5383fdc..5839d6dfd4 100644
--- a/apps/web/src/features/settings/teamMemberPermissions.ts
+++ b/apps/web/src/features/settings/teamMemberPermissions.ts
@@ -4,6 +4,14 @@ export function isTeamAdminOrOwner(role: TeamRole | undefined): boolean {
return role === TeamRole.admin || role === TeamRole.owner;
}
+/** Admins and owners can always invite; members only when the team allows it. */
+export function canInviteToTeam(
+ role: TeamRole | undefined,
+ allowNonAdminInvites: boolean
+): boolean {
+ return isTeamAdminOrOwner(role) || allowNonAdminInvites;
+}
+
export function canRemoveTeamMember(
actingUserId: string | undefined,
actingRole: TeamRole | undefined,
diff --git a/docs/agent-guide/navigation.md b/docs/agent-guide/navigation.md
index 82526596d1..50867d64a2 100644
--- a/docs/agent-guide/navigation.md
+++ b/docs/agent-guide/navigation.md
@@ -362,7 +362,7 @@ Touch devices retain the flag-gated Reviews tab in Tasks.
- Bottom: `Settings` (`Ctrl ;`) — a gear with the signed-in account's profile
photo as a badge in its corner. It opens Settings directly in the active
split (Shift-click for a new split); there is no account menu. Log out lives
- at the bottom of the Settings sidebar, and the command menu is `Ctrl K`.
+ on **Settings → Account**, and the command menu is `Ctrl K`.
The rail highlights the workspace shown by the **active split**, not every app
named in the multi-split URL. Nested details keep their owning workspace selected
diff --git a/docs/agent-guide/settings.md b/docs/agent-guide/settings.md
index 1d1c6a4c07..2d2c34faeb 100644
--- a/docs/agent-guide/settings.md
+++ b/docs/agent-guide/settings.md
@@ -155,10 +155,12 @@ like any other rail item, and Shift-click opens it in a new split.
`/app/settings/<tab>` opens it as the only split with the app rail still
visible, and `/app/home/~/settings/<tab>` places it beside Home. Its inner
sidebar matches Email and Tasks: a **Settings** title bar, a rounded
-**Search settings** field, the grouped section pills, and **Log out** pinned to
-the bottom. Unlike other views, it cannot be hidden at desktop widths: there is
-no **Hide navigation** toggle and `Cmd .` does nothing, even if it was hidden
-before. Below 720px the sidebar becomes an overlay opened from **Show
+**Search settings** field, the grouped section pills, and a team action pinned
+to the bottom: **Invite your team** (opens the invite dialog; hidden for members
+when the team limits invites to admins) or, with no team, **Create a team**
+(opens the create-team dialog). Unlike other views, it cannot be hidden at
+desktop widths: there is no **Hide navigation** toggle and `Cmd .` does
+nothing, even if it was hidden before. Below 720px the sidebar becomes an overlay opened from **Show
navigation** (or `Cmd .`), which starts closed. Escape closes a
settings split that shares the layout, or steps back to the previous view when
it is the only split (Home when there is none). Leave settings by picking any
@@ -195,6 +197,12 @@ Below Profile, **Account** shows a card naming the current plan (**Free plan**,
**Pro plan**, or **Max plan**; **Loading plan…** until the billing summary
arrives). Clicking it opens **Billing** settings.
+Below the plan card, a **Log out** card signs out. Under it, outside any card,
+**Delete account** opens a two-step dialog: an irreversibility warning with
+optional feedback (and a **Log out instead** link), then a final step whose
+**Hold to delete my account** button deletes only after it is held for 5
+seconds (pointer, or Space/Enter); releasing early cancels.
+
Left nav (feature and platform gates still apply):
- **Blocks**: Email, Calendar, Agents, CRM.