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(mentions): show booking links in mentions menu when no text after @ (#8326)

Jacob Beckerman239ee2732df1
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx
index 657169626f..d6622a92c9 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx
@@ -42,6 +42,7 @@ vi.mock('@core/block', () => ({
vi.mock('@core/constant/featureFlags', () => ({
enableCrm: {},
isFeatureEnabled: () => mocks.crmEnabled,
+ ENABLE_BEARER_TOKEN_AUTH: false,
}));
vi.mock('@core/context/quickAccess', () => ({
useQuickAccess: () => ({
@@ -89,6 +90,12 @@ vi.mock('./utils/mentionHandlers', () => ({ createItemHandler: vi.fn() }));
vi.mock('./hooks/useEmailSearchMention', () => ({
useEmailSearchMention: vi.fn(),
}));
+vi.mock('./hooks/useBookingLinkMention', () => ({
+ useBookingLinkMention: () => ({
+ bookingLinks: () => [],
+ isLoading: () => false,
+ }),
+}));
vi.mock('@core/component/EntityIcon', () => ({ EntityIcon: () => null }));
vi.mock('@core/component/UserIcon', () => ({ UserIcon: () => null }));
vi.mock('@ui', () => ({
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
index 57c3294ba6..8cb4703c9c 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
@@ -52,6 +52,7 @@ import { useMenuKeyboardNavigation } from '../useMenuKeyboardNavigation';
import { ItemBin } from './components/ItemBin';
import { MentionsMenuItem } from './components/MentionsMenuItem';
import { createMentionPageLoader } from './hooks/createMentionPageLoader';
+import { useBookingLinkMention } from './hooks/useBookingLinkMention';
import { useEmailSearchMention } from './hooks/useEmailSearchMention';
import {
useEntityMention,
@@ -263,6 +264,14 @@ function MentionsMenuInner(props: MentionsMenuProps) {
);
});
+ const bookingLinksEnabled = () =>
+ !hasCustomEntities() &&
+ (!props.sources || props.sources.includes('bookingLinks'));
+ const { bookingLinks } = useBookingLinkMention({
+ enabled: bookingLinksEnabled,
+ searchTerm,
+ });
+
const openTabs = createLazyMemo(() => {
const splitManager = globalSplitManager();
if (!splitManager) return [];
@@ -319,6 +328,7 @@ function MentionsMenuInner(props: MentionsMenuProps) {
const mobileAllItems = createLazyMemo((): MentionItem[] => {
const users = sourceEnabled('users') ? mentionUsers() : [];
const combined: MentionItem[] = [
+ ...(sourceEnabled('bookingLinks') ? bookingLinks() : []),
...users,
...(sourceEnabled('documents') ? (docs() ?? []) : []),
...(sourceEnabled('channels') ? (channels() ?? []) : []),
@@ -342,6 +352,7 @@ function MentionsMenuInner(props: MentionsMenuProps) {
label: 'All',
getData: mobileAllItems,
getFullCount: () =>
+ (sourceEnabled('bookingLinks') ? bookingLinks().length : 0) +
(sourceEnabled('users') ? mentionUsers().length : 0) +
(sourceEnabled('documents') ? docsMention.totalCount() : 0) +
(sourceEnabled('agentSessions') ? agentSessions().length : 0) +
@@ -385,6 +396,12 @@ function MentionsMenuInner(props: MentionsMenuProps) {
}
const buckets: BucketConfig[] = [
+ {
+ id: 'bookingLinks',
+ label: 'Booking Links',
+ getData: bookingLinks,
+ getFullCount: () => bookingLinks().length,
+ },
{
id: 'users',
label:
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenuController.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenuController.ts
index 44a9e380ea..d1dfeaf166 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenuController.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenuController.ts
@@ -12,7 +12,8 @@ export type MentionBucketId =
| 'companies'
| 'emails'
| 'dates'
- | 'openTabs';
+ | 'openTabs'
+ | 'bookingLinks';
export interface BucketConfig<T extends MentionItem = MentionItem> {
id: MentionBucketId;
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/components/MentionsMenuItem.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/components/MentionsMenuItem.tsx
index 257c040946..7468c4bd47 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/components/MentionsMenuItem.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/components/MentionsMenuItem.tsx
@@ -1,6 +1,7 @@
import { EntityIcon } from '@core/component/EntityIcon';
import { UserIcon } from '@core/component/UserIcon';
import type { ChannelEntity } from '@entity';
+import CalendarBlankIcon from '@phosphor/calendar-blank.svg';
import ClockIcon from '@phosphor/clock.svg';
import EmailIcon from '@phosphor/envelope.svg';
import UsersIcon from '@phosphor/users.svg';
@@ -49,6 +50,10 @@ export function MentionsMenuItem(props: {
name: data.name || 'Agent session',
detail: data.bot?.name ? `@${data.bot.name}` : undefined,
}))
+ .with({ kind: 'bookingLink' }, ({ data }) => ({
+ name: data.title,
+ detail: `${data.durationMinutes} min · ${data.owner}`,
+ }))
.otherwise(() => ({ name: name(), detail: undefined }));
const icon = () => {
@@ -71,6 +76,9 @@ export function MentionsMenuItem(props: {
case 'date':
return <ClockIcon class="size-4 text-ink-muted" />;
+ case 'bookingLink':
+ return <CalendarBlankIcon class="size-4 text-accent" />;
+
case 'entity':
if (props.item.bucket === 'email') {
return <EmailIcon class="size-4 text-ink-muted" />;
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/hooks/useBookingLinkMention.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/hooks/useBookingLinkMention.ts
new file mode 100644
index 0000000000..40aaa37e2f
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/hooks/useBookingLinkMention.ts
@@ -0,0 +1,87 @@
+import type {
+ EventType,
+ SchedulingProfile,
+} from '@app/features/scheduling/core/types';
+import { schedulingKeys } from '@app/features/scheduling/queries/keys';
+import { throwOnErr } from '@core/util/result';
+import { useCurrentTeamQuery } from '@queries/team/teams';
+import { schedulingClient } from '@service-email/scheduling';
+import { createLazyMemo } from '@solid-primitives/memo';
+import { useQuery } from '@tanstack/solid-query';
+import type { Accessor } from 'solid-js';
+import type { BookingLinkMentionItem } from '../../../../utils/mentionsUtils';
+
+export type UseBookingLinkMentionOptions = {
+ /** Whether to fetch booking links. */
+ enabled: Accessor<boolean>;
+ /** Current search term; booking links only show when empty. */
+ searchTerm: Accessor<string>;
+};
+
+function profileBookingLinks(
+ profile: SchedulingProfile,
+ owner: string
+): Array<{ event: EventType; owner: string; profileId: string }> {
+ return profile.eventTypes
+ .filter((event) => event.enabled)
+ .map((event) => ({ event, owner, profileId: profile.id }));
+}
+
+export function useBookingLinkMention(options: UseBookingLinkMentionOptions) {
+ const { enabled, searchTerm } = options;
+
+ const shouldFetch = () => enabled() && searchTerm().trim() === '';
+
+ const personal = useQuery(() => ({
+ queryKey: schedulingKeys.settings('me').queryKey,
+ queryFn: async () =>
+ (await throwOnErr(() => schedulingClient.settings())).profile,
+ enabled: shouldFetch(),
+ retry: false,
+ staleTime: 30_000,
+ }));
+
+ const team = useCurrentTeamQuery(shouldFetch);
+ const teamId = () => (team.isSuccess ? team.data?.team.id : undefined);
+ const teamName = () => (team.isSuccess ? team.data?.team.name : undefined);
+
+ const teamProfile = useQuery(() => ({
+ queryKey: schedulingKeys.settings(teamId() ?? '').queryKey,
+ queryFn: async () =>
+ (await throwOnErr(() => schedulingClient.settings(teamId()))).profile,
+ enabled: shouldFetch() && !!teamId(),
+ retry: false,
+ staleTime: 30_000,
+ }));
+
+ const bookingLinks = createLazyMemo((): BookingLinkMentionItem[] => {
+ if (!shouldFetch()) return [];
+ if (!personal.isSuccess) return [];
+
+ const personalLinks = profileBookingLinks(personal.data, 'Personal');
+
+ const teamLinks =
+ teamName() && teamProfile.isSuccess
+ ? profileBookingLinks(teamProfile.data, teamName()!)
+ : [];
+
+ return [...personalLinks, ...teamLinks].map((link) => ({
+ kind: 'bookingLink' as const,
+ id: `${link.profileId}:${link.event.id}`,
+ data: {
+ profileId: link.profileId,
+ slug: link.event.slug,
+ title: link.event.title,
+ durationMinutes: link.event.durationMinutes,
+ owner: link.owner,
+ },
+ }));
+ });
+
+ return {
+ bookingLinks,
+ isLoading: () =>
+ shouldFetch() &&
+ (personal.isPending || (teamId() !== undefined && teamProfile.isPending)),
+ };
+}
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/entityUtils.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/entityUtils.ts
index 2a96ca3270..ad5a1fb476 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/entityUtils.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/entityUtils.ts
@@ -56,6 +56,8 @@ export function getMentionItemName(item: MentionItem): string {
]
.filter(Boolean)
.join(' ');
+ case 'bookingLink':
+ return item.data.title;
case 'entity':
return item.data.name ?? (item.bucket === 'email' ? 'No Subject' : '');
}
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mentionHandlers.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mentionHandlers.ts
index 64fc953f46..d119d9ca56 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mentionHandlers.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mentionHandlers.ts
@@ -6,11 +6,13 @@ import { match } from 'ts-pattern';
import { REMOVE_INLINE_SEARCH_COMMAND } from '../../../../plugins';
import {
INSERT_AGENT_SESSION_MENTION_COMMAND,
+ INSERT_BOOKING_LINK_MENTION_COMMAND,
INSERT_DATE_MENTION_COMMAND,
INSERT_DOCUMENT_MENTION_COMMAND,
INSERT_GROUP_MENTION_COMMAND,
} from '../../../../plugins/mentions';
import type {
+ BookingLinkMentionItem,
HandlerDependencies,
MentionItem,
} from '../../../../utils/mentionsUtils';
@@ -170,6 +172,30 @@ async function handleGroupMentionItem(
});
}
+function buildBookingUrl(profileId: string, slug: string): string {
+ const hostname = window.location.hostname;
+ const cleanHost =
+ hostname === 'localhost' ? 'dev.macro.com' : hostname.replace('www.', '');
+ return `https://${cleanHost}/app/book/${encodeURIComponent(profileId)}/${encodeURIComponent(slug)}`;
+}
+
+/**
+ * Handle booking link mention insertion.
+ */
+async function handleBookingLinkMention(
+ item: BookingLinkMentionItem,
+ dependencies: HandlerDependencies
+): Promise<void> {
+ const { editor } = dependencies;
+ const { profileId, slug, title } = item.data;
+ editor.dispatchCommand(INSERT_BOOKING_LINK_MENTION_COMMAND, {
+ profileId,
+ slug,
+ label: title,
+ url: buildBookingUrl(profileId, slug),
+ });
+}
+
/**
* Creates a handler for MentionItem selection.
*/
@@ -192,6 +218,8 @@ export function createItemHandler(dependencies: HandlerDependencies) {
{ id: item.id, name: item.data.name },
dependencies
);
+ case 'bookingLink':
+ return await handleBookingLinkMention(item, dependencies);
case 'entity':
return await handleEntityMention(item, dependencies);
}
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.ts
index 18bdc70434..1fd8cdc31c 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.ts
@@ -4,11 +4,17 @@ import type { MentionItem } from '../../../../utils/mentionsUtils';
function getMentionName(item: MentionItem): string {
if (item.kind === 'date') return item.data.displayText;
if (item.kind === 'group') return item.data.groupAlias;
+ if (item.kind === 'bookingLink') return item.data.title;
return item.searchText;
}
function getMentionTimestamps(item: MentionItem) {
- if (item.kind === 'date' || item.kind === 'group') return {};
+ if (
+ item.kind === 'date' ||
+ item.kind === 'group' ||
+ item.kind === 'bookingLink'
+ )
+ return {};
return item.timestamps;
}
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts
index 99ed43630b..fc4c9928ec 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts
@@ -6,6 +6,7 @@ import type { PeerIdValidator } from '@macro-inc/lexical-core';
import {
$collapseInlineSearch,
$createAgentSessionMentionNode,
+ $createBookingLinkMentionNode,
$createContactMentionNode,
$createDateMentionNode,
$createDocumentMentionNode,
@@ -27,6 +28,8 @@ import {
$removeInlineSearch,
type AgentSessionMentionInfo,
AgentSessionMentionNode,
+ type BookingLinkMentionInfo,
+ BookingLinkMentionNode,
type ContactMentionInfo,
ContactMentionNode,
type DateMentionInfo,
@@ -133,6 +136,9 @@ export const INSERT_PR_MENTION_COMMAND: LexicalCommand<PullRequestMentionInfo> =
export const INSERT_THEME_MENTION_COMMAND: LexicalCommand<ThemeMentionInfo> =
createCommand('INSERT_THEME_MENTION_COMMAND');
+export const INSERT_BOOKING_LINK_MENTION_COMMAND: LexicalCommand<BookingLinkMentionInfo> =
+ createCommand('INSERT_BOOKING_LINK_MENTION_COMMAND');
+
export type ItemMention = {
itemType:
| 'document'
@@ -731,6 +737,23 @@ function registerMentionsPlugin(
COMMAND_PRIORITY_NORMAL
),
+ editor.registerCommand(
+ INSERT_BOOKING_LINK_MENTION_COMMAND,
+ (payload) => {
+ if (!editor.hasNode(BookingLinkMentionNode)) return false;
+ editor.update(() => {
+ const mentionNode = $createBookingLinkMentionNode(payload);
+ $insertNodes([mentionNode]);
+ if ($isRootOrShadowRoot(mentionNode.getParentOrThrow())) {
+ $wrapNodeInElement(mentionNode, $createParagraphNode);
+ }
+ mentionNode.selectEnd();
+ });
+ return true;
+ },
+ COMMAND_PRIORITY_NORMAL
+ ),
+
registerInlineMenuTrigger(editor, '@', () => {
editor.dispatchCommand(TYPE_AT_SYMBOL_COMMAND, undefined);
}),
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/utils/mentionsUtils.ts b/apps/web/src/lib/core/component/LexicalMarkdown/utils/mentionsUtils.ts
index f91cb42ceb..0af3f210bc 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/utils/mentionsUtils.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/utils/mentionsUtils.ts
@@ -381,7 +381,22 @@ export type GroupMentionItem = {
};
/**
- * MentionItem = QuickAccessItem + Date + Group.
+ * Booking link mention item for sharing scheduling links.
+ */
+export type BookingLinkMentionItem = {
+ kind: 'bookingLink';
+ id: string;
+ data: {
+ profileId: string;
+ slug: string;
+ title: string;
+ durationMinutes: number;
+ owner: string;
+ };
+};
+
+/**
+ * MentionItem = QuickAccessItem + Date + Group + BookingLink.
* Used in MentionsMenu to unify all mentionable item types.
*/
export type AgentSessionMentionItem = Omit<
@@ -393,7 +408,8 @@ export type MentionItem =
| QuickAccessItem
| DateMentionItem
| GroupMentionItem
- | AgentSessionMentionItem;
+ | AgentSessionMentionItem
+ | BookingLinkMentionItem;
/**
* Type guard for DateMentionItem.