Skip to content

armgit / crm

Public Imported from GitHub
0

Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM.

TypeScript

feat(app): split the company overview into main and rail

grimfc236a253fa3
diff --git a/apps/app/components/crm/record-sheet/company-sheet.tsx b/apps/app/components/crm/record-sheet/company-sheet.tsx
index 5a969a67..17a8a718 100644
--- a/apps/app/components/crm/record-sheet/company-sheet.tsx
+++ b/apps/app/components/crm/record-sheet/company-sheet.tsx
@@ -42,9 +42,13 @@ import { Timeline } from "@/components/crm/timeline/timeline";
import {
DetailSheetBody,
DetailSheetEmpty,
+ DetailSheetMain,
+ DetailSheetPending,
DetailSheetProperties,
DetailSheetProse,
+ DetailSheetRail,
DetailSheetSection,
+ DetailSheetSplit,
DetailSheetStat,
DetailSheetStats,
type DetailSheetTab,
@@ -66,6 +70,23 @@ type CompanyDeal = Company["deals"][number];
const UNASSIGNED = "unassigned";
+/**
+ * The fields only the agent can fill, that it has not filled yet.
+ *
+ * Strictly the ones with no editor anywhere in this sheet. Phone, email, city
+ * and country are `InlineField`s a rep types into, so their emptiness means
+ * "nobody has entered this" — listing them here would blame the agent for a
+ * blank a human was always going to fill, and imply it was off looking for
+ * something it never looks for.
+ */
+function pendingFields(company: Company): string[] {
+ const missing: string[] = [];
+ if (!company.industry) missing.push("industry");
+ if (!company.description) missing.push("description");
+ if (!hasCompanyLinks(company)) missing.push("social links");
+ return missing;
+}
+
const CONTACT_COLUMNS = [
{ srLabel: "Primary", width: "w-10", className: "pl-5" },
{ header: "Name", width: "w-[28%]" },
@@ -183,7 +204,15 @@ export function CompanySheet({ companyId }: { companyId: string }) {
{
value: "overview",
label: "Overview",
- content: <CompanyOverview company={company} />,
+ content: (
+ <CompanyOverview
+ company={company}
+ onAddContact={() => {
+ setAdding("contact");
+ setTab("contacts");
+ }}
+ />
+ ),
},
{
value: "contacts",
@@ -306,7 +335,13 @@ export function CompanySheet({ companyId }: { companyId: string }) {
);
}
-function CompanyOverview({ company }: { company: Company }) {
+function CompanyOverview({
+ company,
+ onAddContact,
+}: {
+ company: Company;
+ onAddContact: () => void;
+}) {
const trpc = useTRPC();
const cache = useCrmCache();
@@ -328,89 +363,116 @@ function CompanyOverview({ company }: { company: Company }) {
return (
<DetailSheetBody>
- {/*
- * Only the fields a rep would correct by hand are editable: the brand,
- * industry and socials come from the agent, and a text box inviting
- * someone to retype them is a text box inviting someone to fight it.
- */}
- <DetailSheetSection title="Details">
- <DetailSheetProperties>
- <InlineField
- label="Name"
- value={company.name}
- saving={isSaving("name")}
- onSave={(name) => name && save({ name })}
- />
- <InlineField
- label="Domain"
- value={company.domain}
- type="url"
- placeholder="stripe.com"
- saving={isSaving("domain")}
- onSave={(domain) => save({ domain })}
- />
- <InlineField
- label="Website"
- value={company.website}
- type="url"
- placeholder="https://stripe.com"
- saving={isSaving("website")}
- onSave={(website) => save({ website })}
- />
- <InlineField
- label="Phone"
- value={company.phone}
- type="tel"
- saving={isSaving("phone")}
- onSave={(phone) => save({ phone })}
- />
- <InlineField
- label="Email"
- value={company.email}
- type="email"
- saving={isSaving("email")}
- onSave={(email) => save({ email })}
- />
- <InlineField
- label="City"
- value={company.city}
- saving={isSaving("city")}
- onSave={(city) => save({ city })}
- />
- <InlineField
- label="Country"
- value={company.country}
- saving={isSaving("country")}
- onSave={(country) => save({ country })}
- />
- <InlineSelectField
- label="Owner"
- value={company.owner?.id ?? UNASSIGNED}
- options={[
- { value: UNASSIGNED, label: "Unassigned" },
- ...(users.data ?? []).map((user) => ({
- value: user.id,
- label: user.name,
- })),
- ]}
- onSave={(ownerId) =>
- save({ ownerId: ownerId === UNASSIGNED ? null : ownerId })
- }
+ <DetailSheetSplit>
+ <DetailSheetMain>
+ {company.description ? (
+ <DetailSheetSection title="About">
+ <DetailSheetProse>{company.description}</DetailSheetProse>
+ </DetailSheetSection>
+ ) : null}
+
+ {/*
+ * Promoted out of its tab. "Who do we know there" is the question a
+ * rep opens a company to answer, and it was behind a click while
+ * eight label/value rows had the whole panel.
+ */}
+ <DetailSheetSection title="People">
+ {/* Adding happens on the Contacts tab, which owns the form:
+ * two quick-add forms bound to one `?add=` would both open. */}
+ <CompanyContacts
+ company={company}
+ adding={false}
+ onAdd={onAddContact}
+ onDone={() => undefined}
+ />
+ </DetailSheetSection>
+ </DetailSheetMain>
+
+ <DetailSheetRail>
+ {/*
+ * Only the fields a rep would correct by hand are editable: the brand,
+ * industry and socials come from the agent, and a text box inviting
+ * someone to retype them is a text box inviting someone to fight it.
+ */}
+ <DetailSheetSection title="Details">
+ <DetailSheetProperties columns={1}>
+ <InlineField
+ label="Name"
+ value={company.name}
+ saving={isSaving("name")}
+ onSave={(name) => name && save({ name })}
+ />
+ <InlineField
+ label="Domain"
+ value={company.domain}
+ type="url"
+ placeholder="stripe.com"
+ saving={isSaving("domain")}
+ onSave={(domain) => save({ domain })}
+ />
+ <InlineField
+ label="Website"
+ value={company.website}
+ type="url"
+ placeholder="https://stripe.com"
+ saving={isSaving("website")}
+ onSave={(website) => save({ website })}
+ />
+ <InlineField
+ label="Phone"
+ value={company.phone}
+ type="tel"
+ saving={isSaving("phone")}
+ onSave={(phone) => save({ phone })}
+ />
+ <InlineField
+ label="Email"
+ value={company.email}
+ type="email"
+ saving={isSaving("email")}
+ onSave={(email) => save({ email })}
+ />
+ <InlineField
+ label="City"
+ value={company.city}
+ saving={isSaving("city")}
+ onSave={(city) => save({ city })}
+ />
+ <InlineField
+ label="Country"
+ value={company.country}
+ saving={isSaving("country")}
+ onSave={(country) => save({ country })}
+ />
+ <InlineSelectField
+ label="Owner"
+ value={company.owner?.id ?? UNASSIGNED}
+ options={[
+ { value: UNASSIGNED, label: "Unassigned" },
+ ...(users.data ?? []).map((user) => ({
+ value: user.id,
+ label: user.name,
+ })),
+ ]}
+ onSave={(ownerId) =>
+ save({ ownerId: ownerId === UNASSIGNED ? null : ownerId })
+ }
+ />
+ </DetailSheetProperties>
+ </DetailSheetSection>
+
+ <DetailSheetPending
+ fields={pendingFields(company)}
+ running={isEnriching(company.enrichmentStatus, company.queued)}
/>
- </DetailSheetProperties>
- </DetailSheetSection>
-
- {company.description ? (
- <DetailSheetSection title="About">
- <DetailSheetProse>{company.description}</DetailSheetProse>
- </DetailSheetSection>
- ) : null}
-
- {hasCompanyLinks(company) ? (
- <DetailSheetSection title="Links">
- <CompanySocials company={company} />
- </DetailSheetSection>
- ) : null}
+
+ {hasCompanyLinks(company) ? (
+ <DetailSheetSection title="Links">
+ <CompanySocials company={company} />
+ </DetailSheetSection>
+ ) : null}
+ </DetailSheetRail>
+ </DetailSheetSplit>
</DetailSheetBody>
);
}
diff --git a/apps/app/components/detail-sheet.tsx b/apps/app/components/detail-sheet.tsx
index 7471365d..8c63cfed 100644
--- a/apps/app/components/detail-sheet.tsx
+++ b/apps/app/components/detail-sheet.tsx
@@ -376,14 +376,104 @@ export function DetailSheetSection({
);
}
+/**
+ * An overview in two columns: what the record *is* on the left, what we know
+ * *about* it on the right.
+ *
+ * One column made the sheet a long list of label/value rows with the useful
+ * prose at the bottom, so a rep opening a company scrolled past eight fields to
+ * reach the description and never saw the contacts at all. Collapses below `lg`,
+ * where a rail would be too narrow to hold a value.
+ */
+export function DetailSheetSplit({ children }: { children: ReactNode }) {
+ return (
+ <div className="flex flex-col gap-6 lg:flex-row lg:items-start lg:gap-8">
+ {children}
+ </div>
+ );
+}
+
+/** The wide half of a split: prose, and the records hanging off this one. */
+export function DetailSheetMain({ children }: { children: ReactNode }) {
+ return <div className="flex min-w-0 flex-1 flex-col">{children}</div>;
+}
+
+/** The narrow half of a split: the record's own fields, and its gaps. */
+export function DetailSheetRail({ children }: { children: ReactNode }) {
+ // `min-w-0` so a long value truncates inside the rail instead of pushing it
+ // wider than the sheet and running off the edge of the screen.
+ return (
+ <div className="flex w-full min-w-0 shrink-0 flex-col lg:w-80">
+ {children}
+ </div>
+ );
+}
+
/**
* Two columns of editable properties on a wide panel, one on a narrow one.
*
* Paired rather than a single list because a company has eight of these and a
* single column turns the first screen of the sheet into a ladder you scroll.
*/
-export function DetailSheetProperties({ children }: { children: ReactNode }) {
- return <div className="grid gap-x-8 sm:grid-cols-2">{children}</div>;
+export function DetailSheetProperties({
+ children,
+ columns = 2,
+}: {
+ children: ReactNode;
+ /**
+ * One column when the properties sit in a `DetailSheetRail`.
+ *
+ * Each row is a 6.5rem label plus its value, so two of them inside a 288px
+ * rail leave about 32px for the value and every one of them clips. Two
+ * columns is right across a full-width panel and wrong anywhere narrow.
+ */
+ columns?: 1 | 2;
+}) {
+ return (
+ <div className={cn("grid gap-x-8", columns === 2 && "sm:grid-cols-2")}>
+ {children}
+ </div>
+ );
+}
+
+/**
+ * What the agent has not filled in yet, as one line rather than a column of
+ * em dashes.
+ *
+ * An empty field rendered as "—" costs a full row and says nothing; five of
+ * them say nothing five times. Naming the gaps once, next to the fact that
+ * something is working on them, is the same information in a tenth of the
+ * space — and it gives the agent a visible presence on a record, which matters
+ * in a product whose whole premise is that the agent does the looking.
+ */
+export function DetailSheetPending({
+ fields,
+ running,
+}: {
+ fields: string[];
+ running: boolean;
+}) {
+ if (fields.length === 0) return null;
+
+ return (
+ <div className="flex flex-col gap-1.5 rounded-md bg-muted/40 p-3">
+ <div className="flex items-center gap-2">
+ <span
+ aria-hidden
+ className={cn(
+ "size-1.5 shrink-0 rounded-full",
+ running ? "bg-primary" : "bg-muted-foreground",
+ )}
+ />
+ <span className="font-medium text-xs">
+ {running ? "Agent is researching" : "Not known yet"}
+ </span>
+ </div>
+ <p className="text-pretty text-muted-foreground text-xs/5">
+ {fields.join(", ")}
+ </p>
+ </div>
+ );
}
/**