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(crm): project-style contact record with section tabs (#7281)

teo0552b961cc33
diff --git a/apps/web/src/features/block-contact/component/ContactBlockAdapter.tsx b/apps/web/src/features/block-contact/component/ContactBlockAdapter.tsx
index c17d4a6050..b4eb455974 100644
--- a/apps/web/src/features/block-contact/component/ContactBlockAdapter.tsx
+++ b/apps/web/src/features/block-contact/component/ContactBlockAdapter.tsx
@@ -1,7 +1,15 @@
-import { Contact } from '@app/features/crm/crm-contact';
+import {
+ Contact,
+ type ContactSection,
+ ContactTabs,
+} from '@app/features/crm/crm-contact';
import { CrmCopyLinkButton } from '@app/features/crm/crm-link';
+import { CollapsibleHeaderItem } from '@components/app/split-layout/components/CollapsibleItem';
import { HeaderIsland } from '@components/app/split-layout/components/HeaderIsland';
-import { SplitHeaderRight } from '@components/app/split-layout/components/SplitHeader';
+import {
+ SplitHeaderLeft,
+ SplitHeaderRight,
+} from '@components/app/split-layout/components/SplitHeader';
import { useBlockId } from '@core/block';
import {
createParamsState,
@@ -9,6 +17,7 @@ import {
} from '@core/component/ParamsProvider';
import { createMethodRegistration } from '@core/orchestrator';
import { blockHandleSignal } from '@core/signal/load';
+import { createSignal } from 'solid-js';
/**
* Legacy adapter: bridges the block/split-layout system to the standalone
@@ -18,18 +27,44 @@ import { blockHandleSignal } from '@core/signal/load';
export function ContactBlockAdapter() {
const contactId = useBlockId();
const params = createParamsState();
+ const [section, setSection] = createSignal<ContactSection>('overview');
createMethodRegistration(blockHandleSignal.get, {
goToLocationFromParams: params.navigate,
});
return (
<>
+ <SplitHeaderLeft>
+ <CollapsibleHeaderItem
+ id="contact-tabs"
+ priority={1}
+ containerClass="ph-no-capture min-w-0 h-full mx-2"
+ >
+ {(isCollapsed) => (
+ // Labels keep their width so the header collapses them to
+ // icons; the icons scroll once even they no longer fit.
+ <div
+ class={
+ isCollapsed()
+ ? 'min-w-0 overflow-x-auto scrollbar-hidden'
+ : 'shrink-0'
+ }
+ >
+ <ContactTabs
+ value={section()}
+ onChange={setSection}
+ compact={isCollapsed()}
+ />
+ </div>
+ )}
+ </CollapsibleHeaderItem>
+ </SplitHeaderLeft>
<SplitHeaderRight>
<HeaderIsland>
<CrmCopyLinkButton type="contact" id={contactId} />
</HeaderIsland>
</SplitHeaderRight>
<ParamsProvider state={params}>
- <Contact contactId={contactId} />
+ <Contact contactId={contactId} section={section()} />
</ParamsProvider>
</>
);
diff --git a/apps/web/src/features/crm/core/record.test.ts b/apps/web/src/features/crm/core/record.test.ts
index 759bf416dd..bdb5086dd5 100644
--- a/apps/web/src/features/crm/core/record.test.ts
+++ b/apps/web/src/features/crm/core/record.test.ts
@@ -17,8 +17,15 @@ describe('sameRecordScope', () => {
false
);
expect(sameRecordScope(acme, undefined)).toBe(false);
- const ada = { type: 'contact' as const, id: 'p1', email: '[email protected]' };
+ const ada = {
+ type: 'contact' as const,
+ id: 'p1',
+ email: '[email protected]',
+ companyId: 'c1',
+ };
+ expect(sameRecordScope(ada, { ...ada })).toBe(true);
expect(sameRecordScope(ada, { ...ada, email: '[email protected]' })).toBe(false);
+ expect(sameRecordScope(ada, { ...ada, companyId: 'c2' })).toBe(false);
expect(sameRecordScope(ada, { ...acme, id: 'p1' })).toBe(false);
});
});
diff --git a/apps/web/src/features/crm/core/record.ts b/apps/web/src/features/crm/core/record.ts
index 884fbd1a9d..6fdba5b7a9 100644
--- a/apps/web/src/features/crm/core/record.ts
+++ b/apps/web/src/features/crm/core/record.ts
@@ -1,7 +1,7 @@
/** A CRM record whose associated files, tasks and calls a record tab lists. */
export type CrmRecordScope =
| { type: 'company'; id: string; domains: string[] }
- | { type: 'contact'; id: string; email: string };
+ | { type: 'contact'; id: string; email: string; companyId: string };
/**
* Whether two scopes describe the same record. Record views keep their
@@ -16,7 +16,7 @@ export function sameRecordScope(
return a.id === b.id && a.domains.join('\n') === b.domains.join('\n');
}
if (a.type === 'contact' && b.type === 'contact') {
- return a.id === b.id && a.email === b.email;
+ return a.id === b.id && a.email === b.email && a.companyId === b.companyId;
}
return false;
}
diff --git a/apps/web/src/features/crm/crm-adapter.ts b/apps/web/src/features/crm/crm-adapter.ts
index e1d2530306..e55d09df78 100644
--- a/apps/web/src/features/crm/crm-adapter.ts
+++ b/apps/web/src/features/crm/crm-adapter.ts
@@ -22,7 +22,7 @@ import { storageServiceClient } from '@service-storage/client';
import { useQueryClient } from '@tanstack/solid-query';
import { createMemo, lazy } from 'solid-js';
import type { CrmContext } from './context/crm-context';
-import type { ItemListSource } from './context/crm-sources';
+import type { CrmQuery, ItemListSource } from './context/crm-sources';
import {
openCreateCompanyModal,
openCreateContactModal,
@@ -113,6 +113,31 @@ function withRowNotifications(source: ItemListSource): ItemListSource {
};
}
+/**
+ * A query contract whose `data` reads as `undefined` until the query is
+ * ready, so views can read it eagerly (e.g. in a memo) without suspending.
+ */
+function withReadyGate<T>(query: CrmQuery<T>): CrmQuery<T> {
+ return {
+ get data() {
+ return queryReadyGate(query) ? query.data : undefined;
+ },
+ get isPending() {
+ return query.isPending;
+ },
+ get isSuccess() {
+ return query.isSuccess;
+ },
+ get isLoading() {
+ return query.isLoading;
+ },
+ get isError() {
+ return query.isError;
+ },
+ refetch: () => query.refetch(),
+ };
+}
+
/** Only this app-facing adapter constructs production capabilities. */
export function createAppCrmContext(): CrmContext {
const deps = {
@@ -200,7 +225,8 @@ export function createAppCrmContext(): CrmContext {
userId,
isTeamAdmin: useIsTeamAdmin,
createCompanySource: (...args) => useCompanyQuery(deps, ...args),
- createContactSource: (...args) => useContactQuery(deps, ...args),
+ createContactSource: (...args) =>
+ withReadyGate(useContactQuery(deps, ...args)),
createTeamSource: useCurrentTeamQuery,
createTeamConfigSource: createSettings,
createCapabilities: () =>
diff --git a/apps/web/src/features/crm/crm-contact.tsx b/apps/web/src/features/crm/crm-contact.tsx
index 898e02ce2a..81ba69a1a5 100644
--- a/apps/web/src/features/crm/crm-contact.tsx
+++ b/apps/web/src/features/crm/crm-contact.tsx
@@ -1,7 +1,12 @@
import type { ComponentProps } from 'solid-js';
+import { RecordTabs } from './components/record-tabs';
import { CrmProvider } from './context/crm-context';
+import { CONTACT_SECTIONS, type ContactSection } from './core/record';
import { createAppCrmContext } from './crm-adapter';
import { Contact as View } from './views/contact-detail';
+
+export type { ContactSection } from './core/record';
+
export function Contact(props: ComponentProps<typeof View>) {
return (
<CrmProvider value={createAppCrmContext()}>
@@ -9,3 +14,12 @@ export function Contact(props: ComponentProps<typeof View>) {
</CrmProvider>
);
}
+
+/** The contact's section tabs, for a host's top bar. */
+export function ContactTabs(props: {
+ value: ContactSection;
+ onChange: (section: ContactSection) => void;
+ compact?: boolean;
+}) {
+ return <RecordTabs sections={CONTACT_SECTIONS} {...props} />;
+}
diff --git a/apps/web/src/features/crm/queries/record-items.test.ts b/apps/web/src/features/crm/queries/record-items.test.ts
index 22864ae534..c21a6dadfd 100644
--- a/apps/web/src/features/crm/queries/record-items.test.ts
+++ b/apps/web/src/features/crm/queries/record-items.test.ts
@@ -38,6 +38,7 @@ describe('CRM record item queries', () => {
type: 'contact',
id: 'contact-1',
+ companyId: 'company-1',
});
expect(body.df['&'][1]).toEqual({
diff --git a/apps/web/src/features/crm/queries/record-items.ts b/apps/web/src/features/crm/queries/record-items.ts
index a1daa52710..88ac194d3a 100644
--- a/apps/web/src/features/crm/queries/record-items.ts
+++ b/apps/web/src/features/crm/queries/record-items.ts
@@ -13,16 +13,6 @@ export function crmRecordPropertyId(scope: CrmRecordScope): string {
.exhaustive();
}
-/** The entity type of a reference to this kind of record. */
-export function crmRecordReferenceType(
- scope: CrmRecordScope
-): 'COMPANY' | 'CONTACT' {
- return match(scope.type)
- .with('company', () => 'COMPANY' as const)
- .with('contact', () => 'CONTACT' as const)
- .exhaustive();
-}
-
type AstNode = Record<string, unknown>;
const leaf = (literal: AstNode): AstNode => ({ l: literal });
diff --git a/apps/web/src/features/crm/record-tasks-adapter.tsx b/apps/web/src/features/crm/record-tasks-adapter.tsx
index d9fc1eca7c..7ff10055eb 100644
--- a/apps/web/src/features/crm/record-tasks-adapter.tsx
+++ b/apps/web/src/features/crm/record-tasks-adapter.tsx
@@ -8,16 +8,15 @@ import {
} from '@app/features/tasks-view/tasks-view-context';
import { createTaskWithProperties } from '@block-md/util/taskComposerProperties';
import { useSplitLayout } from '@components/app/split-layout/layout';
+import { SYSTEM_PROPERTY_IDS } from '@property/identifiers';
import { TagSetsQueryProvider } from '@property/tags/tag-sets-context';
import type { PropertyApiValues } from '@property/types';
import { Button } from '@ui';
import { Show } from 'solid-js';
+import { match } from 'ts-pattern';
import { RecordSection } from './components/record-section';
import type { CrmRecordScope } from './core/record';
-import {
- crmRecordPropertyId,
- crmRecordReferenceType,
-} from './queries/record-items';
+import { crmRecordPropertyId } from './queries/record-items';
/**
* The record's Tasks tab: the production Tasks list, scoped to tasks whose
@@ -60,25 +59,41 @@ export function CrmRecordTasks(props: { scope: CrmRecordScope }) {
);
}
+const reference = (
+ propertyId: string,
+ entityId: string,
+ entityType: 'COMPANY' | 'CONTACT'
+): [string, PropertyApiValues] => [
+ propertyId,
+ {
+ valueType: 'ENTITY',
+ refs: [{ entity_id: entityId, entity_type: entityType }],
+ },
+];
+
+/**
+ * Properties a task created from the record starts with, like project tasks
+ * start in their project. A contact's tasks also join its company.
+ */
+function taskAssociations(
+ scope: CrmRecordScope
+): [string, PropertyApiValues][] {
+ return match(scope)
+ .with({ type: 'company' }, ({ id }) => [
+ reference(SYSTEM_PROPERTY_IDS.COMPANIES, id, 'COMPANY'),
+ ])
+ .with({ type: 'contact' }, ({ id, companyId }) => [
+ reference(SYSTEM_PROPERTY_IDS.CONTACTS, id, 'CONTACT'),
+ reference(SYSTEM_PROPERTY_IDS.COMPANIES, companyId, 'COMPANY'),
+ ])
+ .exhaustive();
+}
+
function RecordTasksBody(props: { scope: CrmRecordScope }) {
const { state, setState } = useTasksView();
const layout = useSplitLayout();
let listElement: HTMLDivElement | undefined;
- // New tasks start associated with the record, like project tasks start
- // in their project.
- const association = (): [string, PropertyApiValues] => [
- crmRecordPropertyId(props.scope),
- {
- valueType: 'ENTITY',
- refs: [
- {
- entity_id: props.scope.id,
- entity_type: crmRecordReferenceType(props.scope),
- },
- ],
- },
- ];
const composeTask = () =>
layout.popoverSplit({
type: 'component',
@@ -92,7 +107,7 @@ function RecordTasksBody(props: { scope: CrmRecordScope }) {
createTaskWithProperties(
title,
content,
- [...properties, association()],
+ [...properties, ...taskAssociations(props.scope)],
...rest
),
},
diff --git a/apps/web/src/features/crm/views/contact-detail.tsx b/apps/web/src/features/crm/views/contact-detail.tsx
index e87426d5d6..56fba59633 100644
--- a/apps/web/src/features/crm/views/contact-detail.tsx
+++ b/apps/web/src/features/crm/views/contact-detail.tsx
@@ -1,48 +1,97 @@
import { SidePanel } from '@components/app/side-panel';
-import { Show } from 'solid-js';
+import { createMemo, Match, Show, Suspense, Switch } from 'solid-js';
+import { useCrmContext } from '../context/crm-context';
+import {
+ type ContactSection,
+ type CrmRecordScope,
+ sameRecordScope,
+} from '../core/record';
import { ContactDiscussionSection } from './contact-discussion-section';
import { ContactEmailsSection } from './contact-emails-section';
import { ContactHeader } from './contact-header';
-import { ContactMetadataSection } from './contact-metadata-section';
import { ContactSharingSection } from './contact-sharing-section';
+import { RecordCallsSection, RecordFilesSection } from './record-associations';
import { useContactQuery, useIsTeamAdmin } from './use-crm';
/**
- * Root of the contact detail view. Owns the contact query and pushes the
- * resolved entity down to presentational children. Layout mirrors the
- * company block: middle content constrained to a centered column, with
- * additional info in the right-hand SidePanel.
+ * Root of the contact detail view, laid out like a project: the host's top
+ * bar picks the section, Overview shows the contact and its discussion, and
+ * the other sections list its emails, files, tasks and calls. Sharing stays
+ * in the right-hand SidePanel.
*/
export function Contact(props: {
contactId: string;
+ section?: ContactSection;
headerToggle?: boolean;
onOpenCompany?: (companyId: string) => boolean;
}) {
+ const context = useCrmContext();
const contactQuery = useContactQuery(() => props.contactId);
const contact = () => contactQuery.data;
const isTeamAdmin = useIsTeamAdmin();
+ const section = () => props.section ?? 'overview';
+ const scope = createMemo(
+ (): CrmRecordScope | undefined => {
+ const current = contact();
+ if (!current) return;
+ return {
+ type: 'contact',
+ id: current.id,
+ email: current.email,
+ companyId: current.companyId,
+ };
+ },
+ undefined,
+ { equals: sameRecordScope }
+ );
return (
<SidePanel.Layout headerToggle={props.headerToggle}>
- <div class="flex h-full flex-col overflow-y-auto scrollbar-hidden">
- <div class="mx-auto flex w-full max-w-3xl min-w-0 grow flex-col gap-6 px-6 pt-12 pb-12">
- <ContactHeader contact={contact()} />
- <ContactDiscussionSection contactId={props.contactId} />
- <ContactEmailsSection contact={contact()} />
- </div>
+ <div class="size-full min-h-0 min-w-0">
+ <Switch>
+ <Match when={section() === 'overview'}>
+ <div class="h-full overflow-y-auto px-6 pb-12 pt-12 scrollbar-hidden touch:pt-6">
+ <div class="mx-auto flex max-w-3xl min-w-0 flex-col gap-6">
+ <ContactHeader
+ contact={contact()}
+ onOpenCompany={props.onOpenCompany}
+ />
+ <ContactDiscussionSection contactId={props.contactId} />
+ </div>
+ </div>
+ </Match>
+ <Match when={section() === 'emails'}>
+ <ContactEmailsSection contact={contact()} />
+ </Match>
+ <Match when={section() === 'files'}>
+ <RecordFilesSection scope={scope()} />
+ </Match>
+ <Match when={section() === 'tasks'}>
+ <Suspense
+ fallback={
+ <div class="p-6 text-center text-sm text-ink-muted">
+ Loading…
+ </div>
+ }
+ >
+ <Show
+ when={scope()}
+ fallback={
+ <div class="p-6 text-center text-sm text-ink-muted">
+ Loading…
+ </div>
+ }
+ >
+ {(current) => <context.RecordTasks scope={current()} />}
+ </Show>
+ </Suspense>
+ </Match>
+ <Match when={section() === 'calls'}>
+ <RecordCallsSection scope={scope()} />
+ </Match>
+ </Switch>
</div>
- <SidePanel.Section
- id="contact-details"
- title="Details"
- order={10}
- defaultOpen
- >
- <ContactMetadataSection
- contact={contact()}
- onOpenCompany={props.onOpenCompany}
- />
- </SidePanel.Section>
{/* Sharing is admin-only; hide the whole section for non-admins
rather than rendering it empty. */}
<Show when={isTeamAdmin()}>
diff --git a/apps/web/src/features/crm/views/contact-emails-section.tsx b/apps/web/src/features/crm/views/contact-emails-section.tsx
index e7dacc7e57..a9fabc7e83 100644
--- a/apps/web/src/features/crm/views/contact-emails-section.tsx
+++ b/apps/web/src/features/crm/views/contact-emails-section.tsx
@@ -1,46 +1,25 @@
import { TabsInset } from '@core/component/TabsInset';
-import {
- ListEntity,
- ListEntityMetadataQueryProvider,
- ListLayoutProvider,
-} from '@entity';
-import { createSignal, For, Show } from 'solid-js';
-import { useInfiniteScrollSentinel } from '../../../lib/primitives/infinite-scroll-sentinel';
-import { useCrmContext } from '../context/crm-context';
+import { createSignal } from 'solid-js';
+import { RecordSection } from '../components/record-section';
import type {
CrmEmailSignal as EmailSignalView,
CrmEmailScope as EmailView,
} from '../context/crm-sources';
import type { CrmContact as CrmContactResponse } from '../core/contact';
+import { RecordItemList } from './record-item-list';
import { useContactEmailsQuery } from './use-crm';
export function ContactEmailsSection(props: { contact?: CrmContactResponse }) {
- const { openEntity } = useCrmContext().createNavigation();
const email = () => props.contact?.email;
const [view, setView] = createSignal<EmailView>('team');
const [signalView, setSignalView] = createSignal<EmailSignalView>('all');
const emailsQuery = useContactEmailsQuery(email, view, signalView);
- const emails = () => emailsQuery.data?.entities ?? [];
- // An enabled query is loading until its first page is readable, including
- // paused requests; a disabled one shows the empty state instead.
- const loading = () =>
- !props.contact || (emailsQuery.isPending && emailsQuery.isEnabled);
-
- const [listRef, setListRef] = createSignal<HTMLElement>();
- const [sentinelRef, setSentinelRef] = createSignal<HTMLDivElement>();
-
- useInfiniteScrollSentinel({
- sentinel: sentinelRef,
- hasNextPage: () => emailsQuery.hasNextPage ?? false,
- isFetchingNextPage: () => emailsQuery.isFetchingNextPage,
- fetchNextPage: () => emailsQuery.fetchNextPage(),
- });
return (
- <div class="flex flex-col gap-2">
- <div class="flex items-center justify-between gap-2">
- <h2 class="text-sm font-medium text-ink-muted">Emails</h2>
- <div class="flex items-center gap-2.5">
+ <RecordSection
+ title="Emails"
+ actions={
+ <>
<TabsInset
list={[
{ value: 'signal', label: 'Signal' },
@@ -57,49 +36,14 @@ export function ContactEmailsSection(props: { contact?: CrmContactResponse }) {
value={view()}
onChange={(v) => setView(v as EmailView)}
/>
- </div>
- </div>
- <Show
- when={!loading()}
- fallback={
- <div class="p-6 text-center text-sm text-ink-muted">Loading…</div>
- }
- >
- <Show
- when={emails().length > 0}
- fallback={
- <div class="rounded-lg border border-dashed border-edge-muted p-6 text-center text-sm text-ink-muted">
- {`No ${signalView() === 'signal' ? 'signal emails' : 'emails'} with this contact ${view() === 'me' ? 'in your inbox' : 'yet'}.`}
- </div>
- }
- >
- <div class="max-h-96 overflow-y-auto">
- <ListEntityMetadataQueryProvider>
- <ListLayoutProvider ref={listRef}>
- <div ref={setListRef} class="flex flex-col">
- <For each={emails()}>
- {(entity) => (
- <ListEntity
- entity={entity}
- timestamp={entity.updatedAt}
- onClick={() => openEntity(entity)}
- />
- )}
- </For>
- </div>
- </ListLayoutProvider>
- </ListEntityMetadataQueryProvider>
- <Show when={emailsQuery.hasNextPage}>
- <div ref={setSentinelRef} class="h-px" />
- </Show>
- <Show when={emailsQuery.isFetchingNextPage}>
- <div class="p-3 text-center text-xs text-ink-muted">
- Loading more…
- </div>
- </Show>
- </div>
- </Show>
- </Show>
- </div>
+ </>
+ }
+ >
+ <RecordItemList
+ source={emailsQuery}
+ pending={!props.contact}
+ empty={`No ${signalView() === 'signal' ? 'signal emails' : 'emails'} with this contact ${view() === 'me' ? 'in your inbox' : 'yet'}.`}
+ />
+ </RecordSection>
);
}
diff --git a/apps/web/src/features/crm/views/contact-header.tsx b/apps/web/src/features/crm/views/contact-header.tsx
index fcd38d629f..36aa877195 100644
--- a/apps/web/src/features/crm/views/contact-header.tsx
+++ b/apps/web/src/features/crm/views/contact-header.tsx
@@ -1,10 +1,14 @@
+import { EntityIcon } from '@core/component/EntityIcon';
import { InlineTitleEditor } from '@core/component/InlineTitleEditor';
+import { formatDateAndTime, formatRelativeTimestamp } from '@entity';
import ContactIcon from '@phosphor/address-book.svg';
-import { Avatar } from '@ui';
+import ClockIcon from '@phosphor/clock.svg';
+import EnvelopeIcon from '@phosphor/envelope.svg';
+import { Avatar, Badge, badgeTriggerClasses, Tooltip } from '@ui';
import { Show } from 'solid-js';
import { useCrmContext } from '../context/crm-context';
import type { CrmContact as CrmContactResponse } from '../core/contact';
-import { useSetContactNameMutation } from './use-crm';
+import { useCompanyQuery, useSetContactNameMutation } from './use-crm';
// Renames overwrite `crm_contacts.name`, which is already team-scoped —
// no global directory involved (unlike company renames).
@@ -17,6 +21,7 @@ function TitleEditor(props: { contact: CrmContactResponse }) {
value={props.contact.name ?? props.contact.email}
placeholder="Contact"
ariaLabel="Contact name"
+ class="w-full text-2xl"
onRename={(name) =>
renameMutation.mutate({
contactId: props.contact.id,
@@ -28,11 +33,41 @@ function TitleEditor(props: { contact: CrmContactResponse }) {
);
}
-export function ContactHeader(props: { contact?: CrmContactResponse }) {
- const { contactInitials: getInitialsFromName } = useCrmContext();
- const showSubtitle = () =>
- props.contact?.name != null && props.contact.name !== props.contact.email;
+function CompanyPill(props: {
+ contact: CrmContactResponse;
+ onOpenCompany?: (companyId: string) => boolean;
+}) {
+ const { openWithSplit } = useCrmContext().createNavigation();
+ const { company } = useCompanyQuery(() => props.contact.companyId);
+ const openCompany = (event: MouseEvent) => {
+ const companyId = props.contact.companyId;
+ if (!event.shiftKey && props.onOpenCompany?.(companyId)) return;
+ openWithSplit(
+ { type: 'company', id: companyId },
+ { activate: true, preferNewSplit: event.shiftKey }
+ );
+ };
+ return (
+ <button
+ type="button"
+ onClick={openCompany}
+ class={badgeTriggerClasses({ variant: 'outline', size: 'sm' })}
+ >
+ <EntityIcon targetType="crm_company" size="xs" />
+ {company()?.name ?? 'Open company'}
+ </button>
+ );
+}
+/**
+ * Contact overview header laid out like a project: the name, then the
+ * contact's facts as pills beneath it.
+ */
+export function ContactHeader(props: {
+ contact?: CrmContactResponse;
+ onOpenCompany?: (companyId: string) => boolean;
+}) {
+ const { contactInitials: getInitialsFromName } = useCrmContext();
// Default avatar mirrors the channel user avatar: initials on a flat circle.
// Contacts have no photo, so initials come from the name or email.
const initials = () => {
@@ -42,32 +77,53 @@ export function ContactHeader(props: { contact?: CrmContactResponse }) {
};
return (
- <div class="flex items-start gap-3">
- <Avatar size="lg" class="shrink-0">
- <Show
- when={initials()}
- fallback={
- <Avatar.Fallback>
- <ContactIcon class="size-5 text-ink-muted" />
- </Avatar.Fallback>
- }
- keyed
- >
- {(value) => (
- <Avatar.Fallback class="font-semibold">{value}</Avatar.Fallback>
- )}
- </Show>
- </Avatar>
- <div class="flex min-w-0 flex-col gap-1">
- <h1 class="min-w-0 text-xl font-semibold">
+ <div>
+ <div class="flex items-center gap-3">
+ <Avatar size="lg" class="shrink-0">
+ <Show
+ when={initials()}
+ fallback={
+ <Avatar.Fallback>
+ <ContactIcon class="size-5 text-ink-muted" />
+ </Avatar.Fallback>
+ }
+ keyed
+ >
+ {(value) => (
+ <Avatar.Fallback class="font-semibold">{value}</Avatar.Fallback>
+ )}
+ </Show>
+ </Avatar>
+ <h1 class="min-w-0 flex-1 text-2xl font-semibold">
<Show when={props.contact} fallback={'Loading contact…'}>
{(contact) => <TitleEditor contact={contact()} />}
</Show>
</h1>
- <Show when={showSubtitle()}>
- <p class="truncate text-sm text-ink-muted">{props.contact?.email}</p>
- </Show>
</div>
+ <Show when={props.contact}>
+ {(contact) => (
+ <div
+ class="mt-3 flex flex-wrap items-center gap-2"
+ aria-label="Contact details"
+ >
+ <Badge variant="outline" size="sm">
+ <EnvelopeIcon class="size-3" />
+ {contact().email}
+ </Badge>
+ <CompanyPill
+ contact={contact()}
+ onOpenCompany={props.onOpenCompany}
+ />
+ <Tooltip label={formatDateAndTime(contact().lastInteraction)}>
+ <Badge variant="outline" size="sm">
+ <ClockIcon class="size-3" />
+ Last interacted{' '}
+ {formatRelativeTimestamp(contact().lastInteraction)}
+ </Badge>
+ </Tooltip>
+ </div>
+ )}
+ </Show>
</div>
);
}
diff --git a/apps/web/src/features/crm/views/contact-metadata-section.tsx b/apps/web/src/features/crm/views/contact-metadata-section.tsx
deleted file mode 100644
index 1d378d9b69..0000000000
--- a/apps/web/src/features/crm/views/contact-metadata-section.tsx
+++ /dev/null
@@ -1,59 +0,0 @@
-import { NIL_UUID } from '@app/features/next-soup/filters/filter-store';
-import { type JSX, Show } from 'solid-js';
-import { useCrmContext } from '../context/crm-context';
-
-import type { CrmContact as CrmContactResponse } from '../core/contact';
-import { useCompanyQuery } from './use-crm';
-
-function Field(props: { label: string; children: JSX.Element }) {
- return (
- <div class="flex flex-col gap-0.5">
- <span class="text-xs text-ink-muted">{props.label}</span>
- <div class="text-sm">{props.children}</div>
- </div>
- );
-}
-
-export function ContactMetadataSection(props: {
- contact?: CrmContactResponse;
- onOpenCompany?: (companyId: string) => boolean;
-}) {
- const { openWithSplit } = useCrmContext().createNavigation();
- // NIL while the contact is loading — useCompanyQuery's `enabled` gate
- // excludes it, so no doomed 404 fires before the real companyId arrives.
- const { company } = useCompanyQuery(
- () => props.contact?.companyId ?? NIL_UUID
- );
-
- const openCompany = (companyId: string, event: MouseEvent) => {
- if (!event.shiftKey && props.onOpenCompany?.(companyId)) return;
- openWithSplit(
- { type: 'company', id: companyId },
- { activate: true, preferNewSplit: event.shiftKey }
- );
- };
-
- return (
- <Show
- when={props.contact}
- fallback={<div class="text-sm text-ink-muted">Loading…</div>}
- >
- {(contact) => (
- <div class="flex flex-col gap-3">
- <Field label="Email">
- <span class="truncate">{contact().email}</span>
- </Field>
- <Field label="Company">
- <button
- type="button"
- onClick={(event) => openCompany(contact().companyId, event)}
- class="text-left text-sm text-link hover:text-link-hover hover:underline"
- >
- {company()?.name ?? 'Open company'}
- </button>
- </Field>
- </div>
- )}
- </Show>
- );
-}
diff --git a/apps/web/src/features/crm/views/record-detail.tsx b/apps/web/src/features/crm/views/record-detail.tsx
index 3ebfb1704a..50b07fafc5 100644
--- a/apps/web/src/features/crm/views/record-detail.tsx
+++ b/apps/web/src/features/crm/views/record-detail.tsx
@@ -13,7 +13,12 @@ import {
} from 'solid-js';
import { RecordTabs } from '../components/record-tabs';
import type { CrmContact as CompanyContact } from '../core/contact';
-import { COMPANY_SECTIONS, type CompanySection } from '../core/record';
+import {
+ COMPANY_SECTIONS,
+ CONTACT_SECTIONS,
+ type CompanySection,
+ type ContactSection,
+} from '../core/record';
import { Company } from './company-detail';
import { Contact } from './contact-detail';
import { CrmCopyLinkButton } from './copy-link-button';
@@ -30,6 +35,12 @@ export function CrmCompanyDetail(props: {
const [selectedContact, setSelectedContact] = createSignal<CompanyContact>();
const [companySection, setCompanySection] =
createSignal<CompanySection>('overview');
+ const [contactSection, setContactSection] =
+ createSignal<ContactSection>('overview');
+ const openContact = (contact: CompanyContact) => {
+ setContactSection('overview');
+ setSelectedContact(contact);
+ };
const contactQuery = useContactQuery(() => selectedContact()?.id ?? '');
const contactName = () => {
const contact = contactQuery.isSuccess
@@ -124,15 +135,24 @@ export function CrmCompanyDetail(props: {
aria-label="CRM record location"
class="min-w-0 shrink"
/>
- <Show when={!selectedContact()}>
- <div class="min-w-0 overflow-x-auto">
+ <div class="min-w-0 overflow-x-auto">
+ <Show
+ when={selectedContact()}
+ fallback={
+ <RecordTabs
+ sections={COMPANY_SECTIONS}
+ value={companySection()}
+ onChange={setCompanySection}
+ />
+ }
+ >
<RecordTabs
- sections={COMPANY_SECTIONS}
- value={companySection()}
- onChange={setCompanySection}
+ sections={CONTACT_SECTIONS}
+ value={contactSection()}
+ onChange={setContactSection}
/>
- </div>
- </Show>
+ </Show>
+ </div>
<div class="ml-auto flex shrink-0 items-center gap-2">
<CrmCopyLinkButton
type={selectedContact() ? 'contact' : 'company'}
@@ -189,13 +209,14 @@ export function CrmCompanyDetail(props: {
section={companySection()}
headerToggle={false}
onHidden={props.onClose}
- onOpenContact={setSelectedContact}
+ onOpenContact={openContact}
/>
}
>
{(contact) => (
<Contact
contactId={contact.id}
+ section={contactSection()}
headerToggle={false}
onOpenCompany={(companyId) => {
if (companyId !== props.company.id) return false;
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index 3d8d79f984..140b7698c0 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -1479,6 +1479,11 @@ its domains. Tasks is the Tasks list scoped to the `Companies` property; its
`New task` composer pre-fills the company. Calls lists calls linked to the
company, including those linked automatically from their participants. The side
panel keeps Properties and Sharing.
+A contact has the same layout with `Overview`, `Emails`, `Files`, `Tasks` and
+`Calls`: Overview pills show the email, the company (opens it) and `Last
+interacted`. Files and Calls match on the contact's `Contacts` property and, for
+files, attachments of emails with its address. Tasks created from a contact also
+reference its company. The side panel keeps Sharing (admins only).
Company and contact pages have a **Discussion** section built from the same
message conversation as a document's Discussion: threaded replies, reactions,