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(mobile): open the user card as a sheet on mention and avatar taps (#6773)

Peter Chinmanfd93f35bbc5f
diff --git a/apps/web/src/components/app/Layout.tsx b/apps/web/src/components/app/Layout.tsx
index 6b8113d604..73451c91ca 100644
--- a/apps/web/src/components/app/Layout.tsx
+++ b/apps/web/src/components/app/Layout.tsx
@@ -51,6 +51,7 @@ import {
SidebarVisibilityContext,
} from '@components/app/sidebarVisibility';
import { useIsAuthenticated } from '@core/auth';
+import { UserCardDrawer } from '@core/component/UserCardDrawer';
import { enableReminders } from '@core/constant/featureFlags';
import { usePaywallState } from '@core/constant/PaywallState';
import { isSoloSettings } from '@core/constant/SettingsState';
@@ -560,6 +561,9 @@ function LayoutInner(props: RouteSectionProps) {
}
>
<FloatRegionHost />
+ <Suspense>
+ <UserCardDrawer />
+ </Suspense>
<Show when={isMobile()}>
<MobileSettings />
</Show>
diff --git a/apps/web/src/features/channel/Message/FromPill.tsx b/apps/web/src/features/channel/Message/FromPill.tsx
index c5e0576e7b..08425b1ba4 100644
--- a/apps/web/src/features/channel/Message/FromPill.tsx
+++ b/apps/web/src/features/channel/Message/FromPill.tsx
@@ -1,8 +1,7 @@
-import { HoverCard } from '@core/component/HoverCard';
-import { UserTooltip } from '@core/component/UserTooltip';
+import { UserCardTrigger } from '@core/component/UserCardTrigger';
import { getDisplayName, macroIdToEmail, tryMacroId } from '@core/user';
import { cn } from '@ui';
-import { createSignal, Show } from 'solid-js';
+import { Show } from 'solid-js';
import { useMessage } from './context';
type FromPillProps = {
@@ -28,8 +27,6 @@ export function FromPill(props: FromPillProps) {
};
const label = () => displayName() || email() || (triggeredBy() ?? '');
- const [open, setOpen] = createSignal(false);
-
return (
<Show when={triggeredBy()}>
<span
@@ -39,24 +36,19 @@ export function FromPill(props: FromPillProps) {
)}
>
from
- <HoverCard
+ <UserCardTrigger
placement="top"
- open={open()}
- onOpenChange={setOpen}
triggerAs="span"
+ user={{
+ displayName: label(),
+ email: email(),
+ id: triggeredBy(),
+ }}
trigger={
<span class="cursor-default rounded-md p-0.5 font-medium text-accent hover:bg-accent/20 focus:bg-accent/20">
{label()}
</span>
}
- content={
- <UserTooltip
- displayName={label()}
- email={email()}
- id={triggeredBy()}
- onClose={() => setOpen(false)}
- />
- }
/>
</span>
</Show>
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/UserMention.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/UserMention.tsx
index 6ea16748b7..80d328a602 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/UserMention.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/UserMention.tsx
@@ -1,9 +1,8 @@
-import { HoverCard } from '@core/component/HoverCard';
-import { UserTooltip } from '@core/component/UserTooltip';
+import { UserCardTrigger } from '@core/component/UserCardTrigger';
import { getDisplayNameParts, macroIdToEmail, tryMacroId } from '@core/user';
import type { UserMentionDecoratorProps } from '@macro-inc/lexical-core';
import { cn } from '@ui';
-import { createEffect, createMemo, createSignal, useContext } from 'solid-js';
+import { createEffect, createMemo, useContext } from 'solid-js';
import { LexicalWrapperContext } from '../../context/LexicalWrapperContext';
import { UPDATE_USER_DISPLAY_NAME_COMMAND } from '../../plugins';
@@ -70,14 +69,15 @@ export function UserMention(props: UserMentionDecoratorProps) {
});
});
- const [open, setOpen] = createSignal(false);
-
return (
- <HoverCard
+ <UserCardTrigger
placement="top"
- open={open()}
- onOpenChange={setOpen}
triggerAs="span"
+ user={{
+ displayName: tooltipDisplayName() || email() || propEmail(),
+ email: email() || propEmail(),
+ id: userId(),
+ }}
trigger={
<span
class={cn(
@@ -95,14 +95,6 @@ export function UserMention(props: UserMentionDecoratorProps) {
</span>
</span>
}
- content={
- <UserTooltip
- displayName={tooltipDisplayName() || email() || propEmail()}
- email={email() || propEmail()}
- id={userId()}
- onClose={() => setOpen(false)}
- />
- }
/>
);
}
diff --git a/apps/web/src/lib/core/component/UserCardDrawer.test.tsx b/apps/web/src/lib/core/component/UserCardDrawer.test.tsx
new file mode 100644
index 0000000000..40d7d88834
--- /dev/null
+++ b/apps/web/src/lib/core/component/UserCardDrawer.test.tsx
@@ -0,0 +1,210 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import { render, screen, waitFor } from '@solidjs/testing-library';
+import userEvent from '@testing-library/user-event';
+import { type ComponentProps, type JSX, Show } from 'solid-js';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { openUserCard, UserCardDrawer } from './UserCardDrawer';
+
+const mocks = vi.hoisted(() => ({
+ crmFlagEnabled: false,
+ openWithSplit: vi.fn(),
+ popoverSplit: vi.fn(),
+ getOrCreateDm: vi.fn(),
+ toastSuccess: vi.fn(),
+ toastFailure: vi.fn(),
+}));
+
+vi.mock('@app/lib/analytics/posthog', () => ({
+ useFeatureFlag: () => () => ({
+ enabled: mocks.crmFlagEnabled,
+ payload: undefined,
+ }),
+}));
+
+vi.mock('@components/app/split-layout/layout', () => ({
+ useSplitLayout: () => ({
+ openWithSplit: mocks.openWithSplit,
+ popoverSplit: mocks.popoverSplit,
+ }),
+}));
+
+vi.mock('@core/component/Toast/Toast', () => ({
+ toast: { failure: mocks.toastFailure, success: mocks.toastSuccess },
+}));
+
+vi.mock('@core/context/user', () => ({
+ useUserId: () => () => 'macro|[email protected]',
+}));
+
+vi.mock('@core/user', () => ({
+ useIsConnectedSecondaryInbox: () => () => false,
+}));
+
+vi.mock('@queries/channel/get-or-create-dm', () => ({
+ useGetOrCreateDirectMessageMutation: () => ({
+ mutateAsync: mocks.getOrCreateDm,
+ }),
+}));
+
+vi.mock('@queries/crm/contacts', () => ({
+ useCrmContactByEmailQuery: () => ({ isSuccess: false, data: undefined }),
+}));
+
+vi.mock('@queries/team/teams', () => ({
+ useCurrentTeamQuery: () => ({ isSuccess: false, data: undefined }),
+}));
+
+vi.mock('./UserIcon', () => ({
+ UserIcon: () => <div data-testid="user-icon" />,
+}));
+
+vi.mock('@components/app/mobile/MobileDrawer', () => {
+ const Container = (props: { children?: JSX.Element }) => props.children;
+ const Root = (props: { open?: boolean; children?: JSX.Element }) => (
+ <Show when={props.open}>{props.children}</Show>
+ );
+ return {
+ MobileDrawer: Object.assign(Root, {
+ Portal: Container,
+ Overlay: () => null,
+ Content: Container,
+ Handle: () => null,
+ ScrollBody: Container,
+ Section: Container,
+ Item: (props: ComponentProps<'button'>) => (
+ <button type="button" {...props} />
+ ),
+ }),
+ };
+});
+
+beforeEach(() => {
+ mocks.crmFlagEnabled = false;
+ mocks.openWithSplit.mockReset();
+ mocks.popoverSplit.mockReset();
+ mocks.getOrCreateDm.mockReset().mockResolvedValue({ channel_id: 'chan-1' });
+ mocks.toastSuccess.mockReset();
+ mocks.toastFailure.mockReset();
+});
+
+function openJane() {
+ openUserCard({
+ displayName: 'Jane Doe',
+ email: '[email protected]',
+ id: 'macro|[email protected]',
+ });
+}
+
+describe('UserCardDrawer', () => {
+ it('stays closed until a user card is opened', () => {
+ render(() => <UserCardDrawer />);
+
+ expect(screen.queryByText('Jane Doe')).toBeNull();
+ });
+
+ it('shows the tapped person and the actions of the hover card', () => {
+ render(() => <UserCardDrawer />);
+ openJane();
+
+ expect(screen.getByText('Jane Doe')).toBeTruthy();
+ expect(screen.getByText('[email protected]')).toBeTruthy();
+ expect(screen.getByRole('button', { name: 'Copy email' })).toBeTruthy();
+ expect(screen.getByRole('button', { name: 'Copy name' })).toBeTruthy();
+ expect(screen.getByRole('button', { name: 'DM' })).toBeTruthy();
+ expect(screen.getByRole('button', { name: 'Assign task' })).toBeTruthy();
+ });
+
+ it('opens a direct message and closes the sheet', async () => {
+ const user = userEvent.setup({ skipHover: true });
+ render(() => <UserCardDrawer />);
+ openJane();
+
+ await user.click(screen.getByRole('button', { name: 'DM' }));
+
+ expect(mocks.getOrCreateDm).toHaveBeenCalledWith({
+ recipient_id: 'macro|[email protected]',
+ });
+ expect(screen.queryByRole('button', { name: 'DM' })).toBeNull();
+ });
+
+ it('copies the email and closes the sheet, which a toast confirms', async () => {
+ const user = userEvent.setup({ skipHover: true });
+ render(() => <UserCardDrawer />);
+ openJane();
+
+ await user.click(screen.getByRole('button', { name: 'Copy email' }));
+
+ expect(await navigator.clipboard.readText()).toBe('[email protected]');
+ expect(mocks.toastSuccess).toHaveBeenCalledWith('Email copied');
+ expect(screen.queryByRole('button', { name: 'Copy email' })).toBeNull();
+ });
+
+ it('assigns a task to the tapped person', async () => {
+ const user = userEvent.setup({ skipHover: true });
+ render(() => <UserCardDrawer />);
+ openJane();
+
+ await user.click(screen.getByRole('button', { name: 'Assign task' }));
+
+ expect(mocks.popoverSplit).toHaveBeenCalledWith({
+ type: 'component',
+ id: 'task-compose',
+ params: { initialAssigneeIds: ['macro|[email protected]'] },
+ });
+ });
+
+ it('waits for the clipboard before confirming and closing', async () => {
+ const user = userEvent.setup({ skipHover: true });
+ let finishCopy!: () => void;
+ vi.spyOn(navigator.clipboard, 'writeText').mockImplementationOnce(
+ () =>
+ new Promise<void>((resolve) => {
+ finishCopy = resolve;
+ })
+ );
+ render(() => <UserCardDrawer />);
+ openJane();
+
+ await user.click(screen.getByRole('button', { name: 'Copy email' }));
+ expect(mocks.toastSuccess).not.toHaveBeenCalled();
+ expect(screen.getByRole('button', { name: 'Copy email' })).toBeTruthy();
+
+ finishCopy();
+ await waitFor(() => {
+ expect(screen.queryByRole('button', { name: 'Copy email' })).toBeNull();
+ expect(mocks.toastSuccess).toHaveBeenCalledWith('Email copied');
+ });
+ });
+
+ it('keeps the sheet open and reports a failed clipboard write', async () => {
+ const user = userEvent.setup({ skipHover: true });
+ vi.spyOn(navigator.clipboard, 'writeText').mockRejectedValueOnce(
+ new Error('Clipboard denied')
+ );
+ render(() => <UserCardDrawer />);
+ openJane();
+
+ await user.click(screen.getByRole('button', { name: 'Copy email' }));
+
+ expect(mocks.toastFailure).toHaveBeenCalledWith(
+ 'Failed to copy to clipboard'
+ );
+ expect(mocks.toastSuccess).not.toHaveBeenCalled();
+ expect(screen.getByRole('button', { name: 'Copy email' })).toBeTruthy();
+ });
+
+ it('offers no DM for an agent, which is mentioned rather than messaged', () => {
+ render(() => <UserCardDrawer />);
+ openUserCard({
+ displayName: 'Cursor',
+ email: 'Cursor',
+ id: 'bot|00000000-0000-0000-0000-00000000c5c5',
+ });
+
+ expect(screen.queryByRole('button', { name: 'DM' })).toBeNull();
+ expect(screen.getByRole('button', { name: 'Assign task' })).toBeTruthy();
+ });
+});
diff --git a/apps/web/src/lib/core/component/UserCardDrawer.tsx b/apps/web/src/lib/core/component/UserCardDrawer.tsx
new file mode 100644
index 0000000000..8cac2845d0
--- /dev/null
+++ b/apps/web/src/lib/core/component/UserCardDrawer.tsx
@@ -0,0 +1,138 @@
+import { MobileDrawer } from '@components/app/mobile/MobileDrawer';
+import { createSignal, For, Show } from 'solid-js';
+import { Dynamic } from 'solid-js/web';
+import { UserIcon } from './UserIcon';
+import {
+ type UserCardAction,
+ type UserCardTarget,
+ useUserCardActions,
+} from './userCardActions';
+
+const [target, setTarget] = createSignal<UserCardTarget>();
+const [isOpen, setIsOpen] = createSignal(false);
+
+/**
+ * Opens the user card for `user` as a bottom sheet. Touch devices never get
+ * the hover card, so tapping an avatar or an @mention opens this instead.
+ */
+export function openUserCard(user: UserCardTarget) {
+ setTarget(user);
+ setIsOpen(true);
+}
+
+/**
+ * Host for the tapped-user card. Mounted once per app, near the root, so a
+ * mention inside an editor doesn't carry a sheet of its own.
+ */
+export function UserCardDrawer() {
+ const [restoreFocus, setRestoreFocus] = createSignal(true);
+ const close = (restoreFocus = true) => {
+ setRestoreFocus(restoreFocus);
+ setIsOpen(false);
+ };
+
+ return (
+ <MobileDrawer
+ side="bottom"
+ open={isOpen()}
+ onOpenChange={(open) => !open && close()}
+ closeOnOutsidePointerStrategy="pointerdown"
+ preventScroll={false}
+ preventScrollbarShift={false}
+ restoreFocus={restoreFocus()}
+ noOutsidePointerEvents={false}
+ >
+ <MobileDrawer.Portal>
+ <MobileDrawer.Overlay />
+ <MobileDrawer.Content aria-label="Profile">
+ <MobileDrawer.Handle />
+ {/* The target outlives the close so the sheet animates out with its
+ contents rather than emptying first. */}
+ <Show when={target()}>
+ {(user) => (
+ <UserCardBody
+ user={user()}
+ // Navigation owns focus in its destination; copying stays here.
+ onAction={(action) => close(action.copies === true)}
+ />
+ )}
+ </Show>
+ </MobileDrawer.Content>
+ </MobileDrawer.Portal>
+ </MobileDrawer>
+ );
+}
+
+function UserCardBody(props: {
+ user: UserCardTarget;
+ onAction: (action: UserCardAction) => void;
+}) {
+ const actions = useUserCardActions(() => props.user);
+
+ const avatarProps = () => {
+ if (props.user.id) {
+ return { id: props.user.id, photoUrl: props.user.photoUrl } as const;
+ }
+ return {
+ email: props.user.email || '?',
+ photoUrl: props.user.photoUrl,
+ } as const;
+ };
+
+ return (
+ <>
+ <div class="flex items-center gap-3 px-6 pb-4">
+ <UserIcon
+ {...avatarProps()}
+ size="lg"
+ isDeleted={props.user.isDeleted}
+ showTooltip={false}
+ suppressClick
+ class="pointer-events-none"
+ />
+ <div class="min-w-0 flex-1">
+ <div class="truncate text-base font-semibold text-ink">
+ {props.user.displayName}
+ </div>
+ <Show
+ when={
+ props.user.email && props.user.email !== props.user.displayName
+ }
+ >
+ <div class="truncate text-sm text-ink-muted">
+ {props.user.email}
+ </div>
+ </Show>
+ </div>
+ </div>
+
+ <Show when={actions().length > 0}>
+ <MobileDrawer.ScrollBody>
+ <MobileDrawer.Section class="flex flex-col shrink-0">
+ <For each={actions()}>
+ {(action) => (
+ <MobileDrawer.Item
+ data-user-card-action={action.id}
+ onClick={async (event) => {
+ try {
+ await action.onSelect(event);
+ } catch {
+ // The action reports the failure; keep the sheet open.
+ return;
+ }
+ props.onAction(action);
+ }}
+ >
+ <span class="flex size-5 shrink-0 items-center justify-center">
+ <Dynamic component={action.icon} class="size-5" />
+ </span>
+ {action.label}
+ </MobileDrawer.Item>
+ )}
+ </For>
+ </MobileDrawer.Section>
+ </MobileDrawer.ScrollBody>
+ </Show>
+ </>
+ );
+}
diff --git a/apps/web/src/lib/core/component/UserCardTrigger.test.tsx b/apps/web/src/lib/core/component/UserCardTrigger.test.tsx
new file mode 100644
index 0000000000..038d9b7618
--- /dev/null
+++ b/apps/web/src/lib/core/component/UserCardTrigger.test.tsx
@@ -0,0 +1,115 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import { render, screen } from '@solidjs/testing-library';
+import userEvent from '@testing-library/user-event';
+import type { JSX } from 'solid-js';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { UserCardTrigger } from './UserCardTrigger';
+
+const mocks = vi.hoisted(() => ({
+ isTouchDevice: false,
+ openUserCard: vi.fn(),
+}));
+
+vi.mock('@core/mobile/isTouchDevice', () => ({
+ isTouchDevice: () => mocks.isTouchDevice,
+}));
+
+vi.mock('./UserCardDrawer', () => ({
+ openUserCard: mocks.openUserCard,
+}));
+
+vi.mock('./UserTooltip', () => ({
+ UserTooltip: (props: { displayName: string }) => (
+ <div data-testid="user-tooltip">{props.displayName}</div>
+ ),
+}));
+
+vi.mock('./HoverCard', () => ({
+ HoverCard: (props: { trigger: JSX.Element }) => (
+ <span data-testid="hover-card">{props.trigger}</span>
+ ),
+}));
+
+const jane = {
+ displayName: 'Jane Doe',
+ email: '[email protected]',
+ id: 'macro|[email protected]',
+};
+
+beforeEach(() => {
+ mocks.isTouchDevice = false;
+ mocks.openUserCard.mockReset();
+});
+
+describe('UserCardTrigger', () => {
+ it('hangs the card off a hover card where there is a pointer', async () => {
+ const user = userEvent.setup({ skipHover: true });
+ render(() => <UserCardTrigger user={jane} trigger={<span>@Jane</span>} />);
+
+ expect(screen.getByTestId('hover-card')).toBeTruthy();
+
+ await user.click(screen.getByText('@Jane'));
+
+ expect(mocks.openUserCard).not.toHaveBeenCalled();
+ });
+
+ it('opens the card as a sheet when a touch device taps the trigger', async () => {
+ mocks.isTouchDevice = true;
+ const user = userEvent.setup({ skipHover: true });
+ render(() => <UserCardTrigger user={jane} trigger={<span>@Jane</span>} />);
+
+ expect(screen.queryByTestId('hover-card')).toBeNull();
+
+ await user.click(screen.getByText('@Jane'));
+
+ expect(mocks.openUserCard).toHaveBeenCalledWith(jane);
+ });
+
+ it('reads the person at tap time, so a late display name is not stale', async () => {
+ mocks.isTouchDevice = true;
+ const user = userEvent.setup({ skipHover: true });
+ let displayName = '';
+ render(() => (
+ <UserCardTrigger
+ user={{ displayName, id: jane.id }}
+ trigger={<span>@Jane</span>}
+ />
+ ));
+
+ displayName = 'Jane Doe';
+ await user.click(screen.getByText('@Jane'));
+
+ expect(mocks.openUserCard).toHaveBeenCalledWith({
+ displayName: 'Jane Doe',
+ id: jane.id,
+ });
+ });
+
+ it.each(['{Enter}', ' '])('opens the touch card with %s', async (key) => {
+ mocks.isTouchDevice = true;
+ const user = userEvent.setup();
+ render(() => <UserCardTrigger user={jane} trigger={<span>@Jane</span>} />);
+
+ await user.tab();
+ expect(document.activeElement).toBe(screen.getByRole('button'));
+ await user.keyboard(key);
+
+ expect(mocks.openUserCard).toHaveBeenCalledExactlyOnceWith(jane);
+ });
+
+ it('preserves an explicit touch trigger tab index', () => {
+ mocks.isTouchDevice = true;
+ render(() => (
+ <UserCardTrigger
+ user={jane}
+ trigger={<span>@Jane</span>}
+ triggerTabIndex={-1}
+ />
+ ));
+
+ expect(screen.getByRole('button').tabIndex).toBe(-1);
+ });
+});
diff --git a/apps/web/src/lib/core/component/UserCardTrigger.tsx b/apps/web/src/lib/core/component/UserCardTrigger.tsx
new file mode 100644
index 0000000000..b1bb8c2471
--- /dev/null
+++ b/apps/web/src/lib/core/component/UserCardTrigger.tsx
@@ -0,0 +1,72 @@
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
+import { cn } from '@ui/utils/classname';
+import { createSignal, type JSX, Show } from 'solid-js';
+import { Dynamic } from 'solid-js/web';
+import { HoverCard, type HoverCardComponentProps } from './HoverCard';
+import { openUserCard } from './UserCardDrawer';
+import { UserTooltip } from './UserTooltip';
+import type { UserCardTarget } from './userCardActions';
+
+type UserCardTriggerProps = {
+ /** The person the card describes. Read when the card opens. */
+ user: UserCardTarget;
+ /** What the card hangs off: an avatar, an @mention chip, a name. */
+ trigger: JSX.Element;
+ placement?: HoverCardComponentProps['placement'];
+ triggerAs?: 'span' | 'div';
+ triggerClass?: string;
+ triggerTabIndex?: number;
+};
+
+/**
+ * Shows the user card: on hover where there is a pointer, on tap where there
+ * is not. `HoverCard` disables itself on touch devices, so a phone gets the
+ * same card as a bottom sheet instead of nothing at all.
+ */
+export function UserCardTrigger(props: UserCardTriggerProps) {
+ const [open, setOpen] = createSignal(false);
+
+ return (
+ <Show
+ when={!isTouchDevice()}
+ fallback={
+ <Dynamic
+ component={props.triggerAs ?? 'span'}
+ role="button"
+ tabIndex={props.triggerTabIndex ?? 0}
+ class={cn(
+ 'focus-visible:outline-2 focus-visible:outline-accent',
+ props.triggerClass
+ )}
+ // A tap on a mention inside an editor would otherwise move the
+ // caret and raise the keyboard behind the sheet.
+ onMouseDown={(event: MouseEvent) => event.preventDefault()}
+ onClick={(event: MouseEvent) => {
+ event.preventDefault();
+ event.stopPropagation();
+ openUserCard(props.user);
+ }}
+ onKeyDown={(event: KeyboardEvent) => {
+ if (event.key !== 'Enter' && event.key !== ' ') return;
+ event.preventDefault();
+ event.stopPropagation();
+ openUserCard(props.user);
+ }}
+ >
+ {props.trigger}
+ </Dynamic>
+ }
+ >
+ <HoverCard
+ placement={props.placement}
+ open={open()}
+ onOpenChange={setOpen}
+ triggerAs={props.triggerAs ?? 'span'}
+ triggerClass={props.triggerClass}
+ triggerTabIndex={props.triggerTabIndex}
+ trigger={props.trigger}
+ content={<UserTooltip {...props.user} onClose={() => setOpen(false)} />}
+ />
+ </Show>
+ );
+}
diff --git a/apps/web/src/lib/core/component/UserIcon.tsx b/apps/web/src/lib/core/component/UserIcon.tsx
index 09400e9134..26d336c85b 100644
--- a/apps/web/src/lib/core/component/UserIcon.tsx
+++ b/apps/web/src/lib/core/component/UserIcon.tsx
@@ -5,6 +5,7 @@ import { isMacroCoderId } from '@core/constant/macroCoder';
import { isMacroNewId } from '@core/constant/macroNew';
import { staticFileSizedUrl } from '@core/constant/servers';
import { internalDrag } from '@core/directive/internalDragState';
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { useProfilePictureUrl } from '@core/signal/profilePicture';
import {
getDisplayName,
@@ -19,16 +20,8 @@ import RobotIcon from '@phosphor/robot.svg';
import Trash from '@phosphor-icons/core/regular/trash.svg?component-solid';
import { useGetOrCreateDirectMessageMutation } from '@queries/channel/get-or-create-dm';
import { Avatar, type AvatarSize, cn } from '@ui';
-import {
- createMemo,
- createSignal,
- type JSX,
- Match,
- Show,
- Switch,
-} from 'solid-js';
-import { HoverCard } from './HoverCard';
-import { UserTooltip } from './UserTooltip';
+import { createMemo, Match, Show, Switch } from 'solid-js';
+import { UserCardTrigger } from './UserCardTrigger';
export type UserIconSize = AvatarSize;
@@ -172,6 +165,11 @@ export function UserIcon(props: UserIconProps) {
const showTooltip = () => props.showTooltip !== false;
const hasTooltipContent = () => displayName() || email();
+ // On touch the tap belongs to the user card, which offers the DM as one of
+ // its actions rather than jumping straight into a conversation.
+ const avatarMouseDown = () =>
+ props.suppressClick || isTouchDevice() ? undefined : getOrCreateDm;
+
const triggerClass = () =>
size() === 'fill' ? 'size-full' : 'inline-flex shrink-0';
@@ -229,13 +227,23 @@ export function UserIcon(props: UserIconProps) {
<Match when={macroId()} keyed>
{(id) => (
- <UserAvatarWithTooltip
+ <UserCardTrigger
+ placement="left"
+ triggerAs="div"
triggerClass={triggerClass()}
- avatar={
+ triggerTabIndex={isTouchDevice() ? 0 : -1}
+ user={{
+ displayName: displayName() || email() || '',
+ email: email(),
+ id,
+ isDeleted: props.isDeleted,
+ photoUrl: props.photoUrl,
+ }}
+ trigger={
<Avatar
size={size()}
class={props.class}
- onMouseDown={props.suppressClick ? undefined : getOrCreateDm}
+ onMouseDown={avatarMouseDown()}
>
<UserIconContent
id={id}
@@ -245,28 +253,27 @@ export function UserIcon(props: UserIconProps) {
/>
</Avatar>
}
- renderContent={(close) => (
- <UserTooltip
- displayName={displayName() || email() || ''}
- email={email()}
- id={id}
- isDeleted={props.isDeleted}
- photoUrl={props.photoUrl}
- onClose={close}
- />
- )}
/>
)}
</Match>
<Match when={email()}>
- <UserAvatarWithTooltip
+ <UserCardTrigger
+ placement="left"
+ triggerAs="div"
triggerClass={triggerClass()}
- avatar={
+ triggerTabIndex={isTouchDevice() ? 0 : -1}
+ user={{
+ displayName: email() || '',
+ email: email(),
+ isDeleted: props.isDeleted,
+ photoUrl: props.photoUrl,
+ }}
+ trigger={
<Avatar
size={size()}
class={props.class}
- onMouseDown={props.suppressClick ? undefined : getOrCreateDm}
+ onMouseDown={avatarMouseDown()}
>
<UserIconContent
id={props.id}
@@ -276,41 +283,8 @@ export function UserIcon(props: UserIconProps) {
/>
</Avatar>
}
- renderContent={(close) => (
- <UserTooltip
- displayName={email() || ''}
- email={email()}
- isDeleted={props.isDeleted}
- photoUrl={props.photoUrl}
- onClose={close}
- />
- )}
/>
</Match>
</Switch>
);
}
-
-/**
- * Local wrapper that owns the controlled-open state needed to let
- * `<UserTooltip>`'s internal close button dismiss the surrounding card.
- */
-function UserAvatarWithTooltip(props: {
- triggerClass: string;
- avatar: JSX.Element;
- renderContent: (close: () => void) => JSX.Element;
-}) {
- const [open, setOpen] = createSignal(false);
- return (
- <HoverCard
- placement="left"
- open={open()}
- onOpenChange={setOpen}
- triggerAs="div"
- triggerClass={props.triggerClass}
- triggerTabIndex={-1}
- trigger={props.avatar}
- content={props.renderContent(() => setOpen(false))}
- />
- );
-}
diff --git a/apps/web/src/lib/core/component/UserTooltip.test.tsx b/apps/web/src/lib/core/component/UserTooltip.test.tsx
index 219b88bcd0..8e11e67f81 100644
--- a/apps/web/src/lib/core/component/UserTooltip.test.tsx
+++ b/apps/web/src/lib/core/component/UserTooltip.test.tsx
@@ -2,7 +2,7 @@
* @vitest-environment jsdom
*/
-import { render, screen } from '@solidjs/testing-library';
+import { render, screen, waitFor } from '@solidjs/testing-library';
import userEvent from '@testing-library/user-event';
import type { JSX } from 'solid-js';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -14,6 +14,8 @@ const mocks = vi.hoisted(() => ({
contact: { id: 'contact-1' } as { id: string } | null | undefined,
openWithSplit: vi.fn(),
onClose: vi.fn(),
+ toastSuccess: vi.fn(),
+ toastFailure: vi.fn(),
}));
vi.mock('@app/lib/analytics/posthog', () => ({
@@ -31,7 +33,7 @@ vi.mock('@components/app/split-layout/layout', () => ({
}));
vi.mock('@core/component/Toast/Toast', () => ({
- toast: { failure: vi.fn(), success: vi.fn() },
+ toast: { failure: mocks.toastFailure, success: mocks.toastSuccess },
}));
vi.mock('@core/context/user', () => ({
@@ -48,6 +50,10 @@ vi.mock('@queries/channel/get-or-create-dm', () => ({
vi.mock('@queries/crm/contacts', () => ({
useCrmContactByEmailQuery: () => ({
+ // Pending lookups report no data yet, exactly as solid-query does.
+ get isSuccess() {
+ return mocks.contact !== undefined;
+ },
get data() {
return mocks.contact;
},
@@ -56,9 +62,10 @@ vi.mock('@queries/crm/contacts', () => ({
vi.mock('@queries/team/teams', () => ({
useCurrentTeamQuery: () => ({
+ isSuccess: true,
get data() {
if (mocks.teamCrmEnabled === null) return null;
- return { team: { crm_enabled: mocks.teamCrmEnabled } };
+ return { team: { id: 'team-1', crm_enabled: mocks.teamCrmEnabled } };
},
}),
}));
@@ -81,6 +88,58 @@ beforeEach(() => {
mocks.contact = { id: 'contact-1' };
mocks.openWithSplit.mockReset();
mocks.onClose.mockReset();
+ mocks.toastSuccess.mockReset();
+ mocks.toastFailure.mockReset();
+});
+
+describe('UserTooltip clipboard action', () => {
+ it('shows the copied icon only after the clipboard resolves', async () => {
+ const user = userEvent.setup({ skipHover: true });
+ let finishCopy!: () => void;
+ vi.spyOn(navigator.clipboard, 'writeText').mockImplementationOnce(
+ () =>
+ new Promise<void>((resolve) => {
+ finishCopy = resolve;
+ })
+ );
+ render(() => (
+ <UserTooltip displayName="Jane Doe" onClose={mocks.onClose} />
+ ));
+ const button = screen.getByRole('button', { name: 'Copy name' });
+ const copyIcon = button.querySelector('svg');
+
+ await user.click(button);
+ expect(button.querySelector('svg')).toBe(copyIcon);
+ expect(mocks.toastSuccess).not.toHaveBeenCalled();
+
+ finishCopy();
+ await waitFor(() => {
+ expect(button.querySelector('svg')).not.toBe(copyIcon);
+ expect(mocks.toastSuccess).toHaveBeenCalledWith('Name copied');
+ });
+ expect(mocks.onClose).not.toHaveBeenCalled();
+ });
+
+ it('leaves the copy icon and card open after a clipboard rejection', async () => {
+ const user = userEvent.setup({ skipHover: true });
+ vi.spyOn(navigator.clipboard, 'writeText').mockRejectedValueOnce(
+ new Error('Clipboard denied')
+ );
+ render(() => (
+ <UserTooltip displayName="Jane Doe" onClose={mocks.onClose} />
+ ));
+ const button = screen.getByRole('button', { name: 'Copy name' });
+ const copyIcon = button.querySelector('svg');
+
+ await user.click(button);
+
+ expect(button.querySelector('svg')).toBe(copyIcon);
+ expect(mocks.toastFailure).toHaveBeenCalledWith(
+ 'Failed to copy to clipboard'
+ );
+ expect(mocks.toastSuccess).not.toHaveBeenCalled();
+ expect(mocks.onClose).not.toHaveBeenCalled();
+ });
});
describe('UserTooltip direct message action', () => {
diff --git a/apps/web/src/lib/core/component/UserTooltip.tsx b/apps/web/src/lib/core/component/UserTooltip.tsx
index d0a09a6698..a4b0bddfa4 100644
--- a/apps/web/src/lib/core/component/UserTooltip.tsx
+++ b/apps/web/src/lib/core/component/UserTooltip.tsx
@@ -1,96 +1,25 @@
-import { useFeatureFlag } from '@app/lib/analytics/posthog';
-import { useSplitLayout } from '@components/app/split-layout/layout';
-import { toast } from '@core/component/Toast/Toast';
-import { enableCrm } from '@core/constant/featureFlags';
-import { isBotPrincipalId } from '@core/constant/macroAgent';
-import { useUserId } from '@core/context/user';
-import { useIsConnectedSecondaryInbox } from '@core/user';
-import WideContact from '@phosphor/address-book.svg';
-import WideChat from '@phosphor/chat.svg';
import IconCheck from '@phosphor/check.svg';
-import CopyIcon from '@phosphor/copy.svg';
-import WideTask from '@phosphor/list-checks.svg';
-import { useGetOrCreateDirectMessageMutation } from '@queries/channel/get-or-create-dm';
-import { useCrmContactByEmailQuery } from '@queries/crm/contacts';
-import { useCurrentTeamQuery } from '@queries/team/teams';
import { debounce } from '@solid-primitives/scheduled';
-import { cn, Surface } from '@ui';
-import { createSignal, type JSX, Show, Suspense } from 'solid-js';
+import { Surface } from '@ui';
+import { createSignal, For, Show } from 'solid-js';
+import { Dynamic } from 'solid-js/web';
import { UserIcon } from './UserIcon';
+import {
+ type UserCardAction,
+ type UserCardTarget,
+ useUserCardActions,
+} from './userCardActions';
-type UserTooltipProps = {
- displayName: string;
- email?: string;
- id?: string;
- isDeleted?: boolean;
+type UserTooltipProps = UserCardTarget & {
onClose?: () => void;
- photoUrl?: string;
};
-function copyableName(
- displayName: string,
- email: string | undefined
-): string | undefined {
- const name = displayName.trim();
- if (!name) return undefined;
- if (name.toLowerCase() === 'me') return undefined;
- if (email && name.toLowerCase() === email.toLowerCase()) return undefined;
- const localPart = email?.split('@')[0];
- if (localPart && name.toLowerCase() === localPart.toLowerCase()) {
- return undefined;
- }
- return name;
-}
-
+/**
+ * The user card as a hover surface. `UserCardDrawer` renders the same card
+ * from the same actions for touch devices, which never hover.
+ */
export function UserTooltip(props: UserTooltipProps) {
- const currentUserId = useUserId();
- const isConnectedSecondaryInbox = useIsConnectedSecondaryInbox();
- const canTreatAsUser = () =>
- !!props.id && !props.isDeleted && !isConnectedSecondaryInbox(props.id);
- // An agent is mentioned like a person and hovers like one, but there is
- // nobody on the other end of a direct message to it: an agent answers where
- // it was mentioned, and a DM channel it never reads would look like a
- // conversation that is simply being ignored.
- const canDirectMessage = () =>
- canTreatAsUser() && !isBotPrincipalId(props.id);
- const { openWithSplit, popoverSplit } = useSplitLayout();
- const crmFlag = useFeatureFlag(enableCrm);
- const getOrCreateDmMutation = useGetOrCreateDirectMessageMutation({
- onError: () => toast.failure('Failed to open direct message'),
- });
-
- const openDM = async (e: MouseEvent) => {
- e.preventDefault();
- e.stopPropagation();
- if (!props.id) return;
- const preferNewSplit = e.shiftKey;
- try {
- const { channel_id } = await getOrCreateDmMutation.mutateAsync({
- recipient_id: props.id,
- });
- openWithSplit(
- { type: 'channel', id: channel_id },
- { preferNewSplit, reopen: 'latest' }
- );
- } catch {
- // The mutation's onError callback handles the toast.
- } finally {
- props.onClose?.();
- }
- };
-
- const openTaskComposer = (e: MouseEvent) => {
- e.preventDefault();
- e.stopPropagation();
- props.onClose?.();
- if (props.id) {
- popoverSplit({
- type: 'component',
- id: 'task-compose',
- params: { initialAssigneeIds: [props.id] },
- });
- }
- };
+ const actions = useUserCardActions(() => props);
// Determine avatar props based on what we have
const avatarProps = () => {
@@ -125,48 +54,14 @@ export function UserTooltip(props: UserTooltipProps) {
</div>
</div>
- <Show
- when={
- props.email ||
- props.id ||
- copyableName(props.displayName, props.email)
- }
- >
+ <Show when={actions().length > 0}>
<div class="border-t border-edge"></div>
<div class="p-1.5 flex flex-col gap-0.5">
- <Show when={props.email}>
- {(email) => (
- <CopyActionItem value={email()} toastMessage="Email copied">
- Copy email
- </CopyActionItem>
- )}
- </Show>
- <Show when={copyableName(props.displayName, props.email)}>
- {(name) => (
- <CopyActionItem value={name()} toastMessage="Name copied">
- Copy name
- </CopyActionItem>
+ <For each={actions()}>
+ {(action) => (
+ <ActionItem action={action} onClose={props.onClose} />
)}
- </Show>
- <Show when={crmFlag().enabled ? props.email : undefined}>
- {(email) => (
- <Suspense fallback={null}>
- <OpenContactAction email={email()} onClose={props.onClose} />
- </Suspense>
- )}
- </Show>
- <Show when={canDirectMessage() && props.id !== currentUserId()}>
- <ActionItem onClick={openDM}>
- <WideChat class="size-3.5" />
- DM
- </ActionItem>
- </Show>
- <Show when={canTreatAsUser()}>
- <ActionItem onClick={openTaskComposer}>
- <WideTask class="size-3.5" />
- Assign task
- </ActionItem>
- </Show>
+ </For>
</div>
</Show>
</div>
@@ -174,88 +69,37 @@ export function UserTooltip(props: UserTooltipProps) {
);
}
-/**
- * Inner action: lives inside a local `<Suspense>` so the team and contact
- * lookups suspend only this button, not the tooltip.
- */
-function OpenContactAction(props: { email: string; onClose?: () => void }) {
- const { openWithSplit } = useSplitLayout();
- const currentTeamQuery = useCurrentTeamQuery();
- const team = () => currentTeamQuery.data?.team;
- const crmEnabled = () => team()?.crm_enabled === true;
- const contactQuery = useCrmContactByEmailQuery(
- () => team()?.id ?? '',
- () => props.email,
- crmEnabled
- );
-
- const openContact = (e: MouseEvent, contactId: string) => {
- e.preventDefault();
- e.stopPropagation();
- openWithSplit(
- { type: 'contact', id: contactId },
- { preferNewSplit: e.shiftKey, reopen: 'latest' }
- );
- props.onClose?.();
- };
-
- return (
- <Show when={crmEnabled() ? contactQuery.data : undefined}>
- {(contact) => (
- <ActionItem onClick={(e) => openContact(e, contact().id)}>
- <WideContact class="size-3.5" />
- Open contact
- </ActionItem>
- )}
- </Show>
- );
-}
-
-function CopyActionItem(props: {
- value: string;
- toastMessage: string;
- children: JSX.Element;
-}) {
+function ActionItem(props: { action: UserCardAction; onClose?: () => void }) {
const [copied, setCopied] = createSignal(false);
const resetCopied = debounce(() => setCopied(false), 800);
- function handleCopy(e: MouseEvent) {
- e.stopPropagation();
- setCopied(true);
- navigator.clipboard.writeText(props.value);
- toast.success(props.toastMessage);
- resetCopied();
- }
-
- return (
- <ActionItem onClick={handleCopy}>
- {copied() ? (
- <IconCheck class="size-3.5" />
- ) : (
- <CopyIcon class="size-3.5" />
- )}
- {props.children}
- </ActionItem>
- );
-}
+ const handleClick = async (event: MouseEvent) => {
+ try {
+ await props.action.onSelect(event);
+ } catch {
+ // The action reports the failure; leave the card ready to retry.
+ return;
+ }
+ // A copy keeps the card open long enough to show that it landed; anything
+ // that navigates has already taken the user elsewhere.
+ if (props.action.copies) {
+ setCopied(true);
+ resetCopied();
+ return;
+ }
+ props.onClose?.();
+ };
-function ActionItem(props: {
- children: JSX.Element;
- onClick: JSX.EventHandler<HTMLButtonElement, MouseEvent>;
- class?: string;
- disabled?: boolean;
-}) {
return (
<button
type="button"
- class={cn(
- 'group rounded-lg w-full flex items-center gap-2 px-2 h-8 text-left font-medium text-xs cursor-default outline-none hover:bg-ink/5 focus:bg-ink/5 data-highlighted:bg-ink/5 data-disabled:opacity-50 data-disabled:cursor-not-allowed',
- props.class
- )}
- onClick={props.onClick}
- disabled={props.disabled}
+ class="group rounded-lg w-full flex items-center gap-2 px-2 h-8 text-left font-medium text-xs cursor-default outline-none hover:bg-ink/5 focus:bg-ink/5 data-highlighted:bg-ink/5 data-disabled:opacity-50 data-disabled:cursor-not-allowed"
+ onClick={handleClick}
>
- {props.children}
+ <Show when={!copied()} fallback={<IconCheck class="size-3.5" />}>
+ <Dynamic component={props.action.icon} class="size-3.5" />
+ </Show>
+ {props.action.label}
</button>
);
}
diff --git a/apps/web/src/lib/core/component/userCardActions.tsx b/apps/web/src/lib/core/component/userCardActions.tsx
new file mode 100644
index 0000000000..feda3c7c1d
--- /dev/null
+++ b/apps/web/src/lib/core/component/userCardActions.tsx
@@ -0,0 +1,210 @@
+import { useFeatureFlag } from '@app/lib/analytics/posthog';
+import { useSplitLayout } from '@components/app/split-layout/layout';
+import { toast } from '@core/component/Toast/Toast';
+import { enableCrm } from '@core/constant/featureFlags';
+import { isBotPrincipalId } from '@core/constant/macroAgent';
+import { useUserId } from '@core/context/user';
+import { useIsConnectedSecondaryInbox } from '@core/user';
+import WideContact from '@phosphor/address-book.svg';
+import WideChat from '@phosphor/chat.svg';
+import CopyIcon from '@phosphor/copy.svg';
+import WideTask from '@phosphor/list-checks.svg';
+import { useGetOrCreateDirectMessageMutation } from '@queries/channel/get-or-create-dm';
+import { useCrmContactByEmailQuery } from '@queries/crm/contacts';
+import { useCurrentTeamQuery } from '@queries/team/teams';
+import {
+ type Accessor,
+ type Component,
+ type ComponentProps,
+ createMemo,
+} from 'solid-js';
+
+/** The person a user card describes. */
+export type UserCardTarget = {
+ displayName: string;
+ email?: string;
+ id?: string;
+ isDeleted?: boolean;
+ photoUrl?: string;
+};
+
+type UserCardActionId =
+ | 'copy-email'
+ | 'copy-name'
+ | 'open-contact'
+ | 'dm'
+ | 'assign-task';
+
+export type UserCardAction = {
+ id: UserCardActionId;
+ label: string;
+ icon: Component<ComponentProps<'svg'>>;
+ /** Writes to the clipboard: confirm in place instead of dismissing the card. */
+ copies?: boolean;
+ onSelect: (event: MouseEvent) => void | Promise<void>;
+};
+
+function copyableName(
+ displayName: string,
+ email: string | undefined
+): string | undefined {
+ const name = displayName.trim();
+ if (!name) return undefined;
+ if (name.toLowerCase() === 'me') return undefined;
+ if (email && name.toLowerCase() === email.toLowerCase()) return undefined;
+ const localPart = email?.split('@')[0];
+ if (localPart && name.toLowerCase() === localPart.toLowerCase()) {
+ return undefined;
+ }
+ return name;
+}
+
+/**
+ * The actions a user card offers, shared by every presentation of it: the
+ * hover card on pointer devices and the bottom sheet on touch ones.
+ *
+ * Dismissal is left to the caller — a hover card stays open to show that a
+ * copy landed, a sheet closes after a successful action.
+ */
+export function useUserCardActions(
+ target: Accessor<UserCardTarget>
+): Accessor<UserCardAction[]> {
+ const currentUserId = useUserId();
+ const isConnectedSecondaryInbox = useIsConnectedSecondaryInbox();
+ const { openWithSplit, popoverSplit } = useSplitLayout();
+ const crmFlag = useFeatureFlag(enableCrm);
+ const getOrCreateDmMutation = useGetOrCreateDirectMessageMutation({
+ onError: () => toast.failure('Failed to open direct message'),
+ });
+
+ const userId = () => target().id;
+ const canTreatAsUser = () =>
+ !!userId() && !target().isDeleted && !isConnectedSecondaryInbox(userId());
+ // An agent is mentioned like a person and hovers like one, but there is
+ // nobody on the other end of a direct message to it: an agent answers where
+ // it was mentioned, and a DM channel it never reads would look like a
+ // conversation that is simply being ignored.
+ const canDirectMessage = () =>
+ canTreatAsUser() && !isBotPrincipalId(userId());
+
+ // Only the CRM contact lookup needs the team, so a card on a workspace
+ // without CRM never fetches one.
+ const currentTeamQuery = useCurrentTeamQuery(() => crmFlag().enabled);
+ // Guarded reads: an unguarded `data` suspends whoever renders the card, and
+ // a card that suspends takes its hover surface or sheet down with it.
+ const team = () =>
+ currentTeamQuery.isSuccess ? currentTeamQuery.data?.team : undefined;
+ const crmEnabled = () => crmFlag().enabled && team()?.crm_enabled === true;
+ const contactQuery = useCrmContactByEmailQuery(
+ () => team()?.id ?? '',
+ () => target().email ?? '',
+ crmEnabled
+ );
+ const crmContact = () =>
+ crmEnabled() && contactQuery.isSuccess ? contactQuery.data : undefined;
+
+ const copyAction = (
+ id: UserCardActionId,
+ label: string,
+ value: string,
+ toastMessage: string
+ ): UserCardAction => ({
+ id,
+ label,
+ icon: CopyIcon,
+ copies: true,
+ onSelect: async (event) => {
+ event.stopPropagation();
+ try {
+ await navigator.clipboard.writeText(value);
+ } catch (error) {
+ toast.failure('Failed to copy to clipboard');
+ throw error;
+ }
+ toast.success(toastMessage);
+ },
+ });
+
+ const openContact = (event: MouseEvent, contactId: string) => {
+ event.preventDefault();
+ event.stopPropagation();
+ openWithSplit(
+ { type: 'contact', id: contactId },
+ { preferNewSplit: event.shiftKey, reopen: 'latest' }
+ );
+ };
+
+ const openDirectMessage = async (event: MouseEvent) => {
+ event.preventDefault();
+ event.stopPropagation();
+ const recipientId = userId();
+ if (!recipientId) return;
+ const preferNewSplit = event.shiftKey;
+ // The mutation's onError callback handles failure feedback.
+ const { channel_id } = await getOrCreateDmMutation.mutateAsync({
+ recipient_id: recipientId,
+ });
+ openWithSplit(
+ { type: 'channel', id: channel_id },
+ { preferNewSplit, reopen: 'latest' }
+ );
+ };
+
+ const openTaskComposer = (event: MouseEvent) => {
+ event.preventDefault();
+ event.stopPropagation();
+ const assigneeId = userId();
+ if (!assigneeId) return;
+ popoverSplit({
+ type: 'component',
+ id: 'task-compose',
+ params: { initialAssigneeIds: [assigneeId] },
+ });
+ };
+
+ return createMemo(() => {
+ const { displayName, email } = target();
+ const actions: UserCardAction[] = [];
+
+ if (email) {
+ actions.push(
+ copyAction('copy-email', 'Copy email', email, 'Email copied')
+ );
+ }
+
+ const name = copyableName(displayName, email);
+ if (name) {
+ actions.push(copyAction('copy-name', 'Copy name', name, 'Name copied'));
+ }
+
+ const contact = crmContact();
+ if (contact) {
+ actions.push({
+ id: 'open-contact',
+ label: 'Open contact',
+ icon: WideContact,
+ onSelect: (event) => openContact(event, contact.id),
+ });
+ }
+
+ if (canDirectMessage() && userId() !== currentUserId()) {
+ actions.push({
+ id: 'dm',
+ label: 'DM',
+ icon: WideChat,
+ onSelect: openDirectMessage,
+ });
+ }
+
+ if (canTreatAsUser()) {
+ actions.push({
+ id: 'assign-task',
+ label: 'Assign task',
+ icon: WideTask,
+ onSelect: openTaskComposer,
+ });
+ }
+
+ return actions;
+ });
+}
diff --git a/docs/AGENT_GUIDE/navigation.md b/docs/AGENT_GUIDE/navigation.md
index 252a11ccfa..80c3434f57 100644
--- a/docs/AGENT_GUIDE/navigation.md
+++ b/docs/AGENT_GUIDE/navigation.md
@@ -293,6 +293,13 @@ rows; period, week start, time format, and month choices show trailing checkmark
All popover splits open as bottom drawers on touch devices and dialogs
on desktop, including task, calendar event, skill, and agent session composers.
+Hovering an `@user` mention or a profile picture on desktop opens the user card:
+the person's name and email above Copy email, Copy name, Open contact (CRM teams
+only), DM, and Assign task. Touch devices have no hover, so tapping the mention
+or the picture opens that same card as a bottom sheet; any action there runs and
+dismisses the sheet. Desktop keeps click-to-DM on the picture itself, which touch
+drops in favour of the card's DM action.
+
`Create` button (top-left) opens a menu of: Email E, Automation U, Agent A, Skill K,
Document D, Task T, Reminder R, Snippet S, Message M, Channel G, Canvas N, Folder F, Code O.
Document navigates straight into a new doc; Task and Channel open dialogs.
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index 088e7dd3bb..2154c68b3e 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -1,5 +1,17 @@
# Other Surfaces
+## User cards
+
+Avatar and user-mention cards open on hover on pointer devices and as a bottom
+sheet on touch devices. With a keyboard on a touch device, Tab to the trigger and
+press Enter or Space; verify focus enters the sheet and returns to the opener
+after dismissal or copying, including after reopening. DM, Open contact, and
+Assign task should leave focus in their destination when the sheet closes.
+On pointer devices, avatars should stay out of the Tab order while still opening
+their cards on hover. Copy email/name confirms only after the clipboard
+write succeeds: the hover card shows a checkmark, while the sheet closes. A failed
+write shows failure feedback and leaves the card open for retry.
+
## Canvas colors
To check the default canvas color, create a rectangle and a text box without