Public: anyone can read this; the crew can change it.

A party's phone or email on the People page and a deal's page is one tap to call, text or write, so the agent reaches a lender from the meeting without copying a number #77

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/deal-clock:mason/74-a-party-s-phone-or-email-on-the-people-p → main 1 commit fork 1 thread · 1 unresolved

  • Merged. mason/74-a-party-s-phone-or-email-on-the-people-p was merged into main as c903740.

Review

Sign in to review this change.
8 files changed +91 −6
README.md +1 −1
@@ -25,7 +25,7 @@ for the same list; over MCP, an agent asks for the `this_week` tool.
2525 Before calling a lender or an inspector, open **People** in the header: each
2626 person on your deals appears once, with every open date they owe across all
2727 deals, soonest first (try Priya Nair, who works both 1418 Alder Lane and 9 Orchard
28 Row). In the terminal, press P; over MCP, ask for `list_people`.
28 Row). Tap a number to call or text, an address to write. In the terminal, press P; over MCP, ask for `list_people`.
2929
3030 To find a deal, type part of its address, or of a buyer's, seller's or other
3131 party's name, phone or email, into **Find a deal** above the clock and press
docs/design/areas/people.md +1
@@ -3,3 +3,4 @@
33 Classes on `/people`, the list of everyone on the agent's deals with the dates they owe. Rows reuse `.week-list`, `.week-row` and `.badge`.
44
55 - `.person` — one person's card: name, roles and contact, then their open dates or "Nothing open".
6 - `.contact-link` — a party's email, phone or Text link on `/people` and the deal page's party list; at least `--size-tap` tall.
src/outbox.ts +14 −3
@@ -16,22 +16,33 @@ export interface Outbox {
1616 /** What shows where there is no link to offer. */
1717 export const NO_CONTACT = "No email or phone on file";
1818
19 /** What a party's contact is, by the one rule Send and the contact links share: an email, a phone or neither. */
20 export function contactKind(contact: string): "email" | "phone" | "other" {
21 if (validEmail(contact)) return "email";
22 if (validPhone(contact)) return "phone";
23 return "other";
24 }
25
26 /** A phone as dialable digits and a leading +, nothing else. */
27 export const dialable = (phone: string): string => phone.replace(/[^0-9+]/g, "");
28
1929 /**
2030 * The link for these words to this contact: `mailto:` for an email, `sms:`
2131 * for a phone, null for anything else. A contact is only used after it passes
2232 * the same checks the settings do, so no quote or scheme can ride in it.
2333 */
2434 export function outbox(contact: string, subject: string, body: string): Outbox | null {
25 if (validEmail(contact))
35 const kind = contactKind(contact);
36 if (kind === "email")
2637 return {
2738 kind: "mail",
2839 href: `mailto:${contact}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`,
2940 label: "Open in Mail",
3041 };
31 if (validPhone(contact))
42 if (kind === "phone")
3243 return {
3344 kind: "sms",
34 href: `sms:${contact.replace(/[^0-9+]/g, "")}?&body=${encodeURIComponent(body)}`,
45 href: `sms:${dialable(contact)}?&body=${encodeURIComponent(body)}`,
3546 label: "Open in Messages",
3647 };
3748 return null;
src/pages/contact.ts +19
@@ -2,6 +2,25 @@
22
33 import type { Agent } from "../reminders.ts";
44 import { escape } from "../http.ts";
5 import { contactKind, dialable } from "../outbox.ts";
56
67 export const contactLinks = (agent: Agent): string =>
78 `<a href="tel:${escape(agent.phone.replace(/[^0-9+]/g, ""))}">${escape(agent.phone)}</a> · <a href="mailto:${escape(agent.email)}">${escape(agent.email)}</a>`;

Nit: reuse dialable(agent.phone) here so there is truly one digit-stripping rule.

9
10 /**
11 * A party's contact: an email is a `mailto:` link, a phone a `tel:` link with
12 * a Text (`sms:`) link beside it, anything else plain escaped text. Links are
13 * built only from a contact that passed the same checks Send uses.
14 */
15 export function partyContact(contact: string): string {
16 const value = contact.trim();
17 const label = escape(contact);
18 switch (contactKind(value)) {
19 case "email":
20 return `<a class="contact-link" href="mailto:${escape(value)}">${label}</a>`;
21 case "phone":
22 return `<a class="contact-link" href="tel:${escape(dialable(value))}">${label}</a> <a class="contact-link" href="sms:${escape(dialable(value))}">Text</a>`;
23 default:
24 return label;
25 }
26 }
src/pages/deal.ts +2 −1
@@ -12,6 +12,7 @@ import { escape } from "../http.ts";
1212 import { MOMENT_LABEL, type Agent } from "../reminders.ts";
1313 import type { Who } from "../who.ts";
1414 import { amendForm, type AmendState } from "./amend.ts";
15 import { partyContact } from "./contact.ts";
1516 import { confirmRemove } from "./confirm.ts";
1617 import { layout } from "./layout.ts";
1718 import { badge, conflictLines, dueLine, outboxLine, owedBy, sheet, sheetId } from "./sheet.ts";
@@ -104,7 +105,7 @@ export function dealPage(input: {
104105 : `<ul class="parties">${deal.parties
105106 .map(
106107 (p) =>
107 `<li><span class="muted">${escape(PARTY_LABEL[p.role])}</span><b>${escape(p.name)}</b>${p.contact === "" ? "" : `<span class="mono">${escape(p.contact)}</span>`}${may ? partyControls(p, path) : ""}</li>`,
108 `<li><span class="muted">${escape(PARTY_LABEL[p.role])}</span><b>${escape(p.name)}</b>${p.contact === "" ? "" : `<span class="mono">${partyContact(p.contact)}</span>`}${may ? partyControls(p, path) : ""}</li>`,
108109 )
109110 .join("")}</ul>`;
110111 const forms = may
src/pages/people.ts +2 −1
@@ -9,6 +9,7 @@ import { escape } from "../http.ts";
99 import type { Person } from "../people.ts";
1010 import type { Who } from "../who.ts";
1111 import type { Agent } from "../reminders.ts";
12 import { partyContact } from "./contact.ts";
1213 import { layout } from "./layout.ts";
1314 import { URGENCY_LABEL } from "./sheet.ts";
1415
@@ -17,7 +18,7 @@ const owedRow = (o: Person["owes"][number], on: string): string =>
1718
1819 const person = (p: Person, on: string): string => `<section class="card person">
1920 <h2>${escape(p.name)}</h2>
20 <p class="muted">${escape(p.roles.join(", "))}${p.contact === "" ? "" : ` · ${escape(p.contact)}`}</p>
21 <p class="muted">${escape(p.roles.join(", "))}${p.contact === "" ? "" : ` · ${partyContact(p.contact)}`}</p>
2122 ${p.owes.length === 0 ? `<p class="muted">Nothing open</p>` : `<ul class="week-list">${p.owes.map((o) => owedRow(o, on)).join("")}</ul>`}
2223 </section>`;
2324
src/partycontact.test.ts added +47
@@ -0,0 +1,47 @@
1 import { expect, test } from "bun:test";
2 import { partyContact } from "./pages/contact.ts";
3 import { peoplePage } from "./pages/people.ts";
4 import { dealPage } from "./pages/deal.ts";
5 import type { Person } from "./people.ts";
6 import type { DealView } from "./deals.ts";
7
8 const who = { role: "user", id: "u", name: "Dana" } as const;
9 const contacts = ["[email protected]", "(555) 010-0142", "Ask at the front desk", `javascript:alert("x")<b>`, `"><img src=x onerror=1>`];
10
11 const bare = (h: string) => h.replace(/<p class="agent-contact">.*?<\/p>/, "");
12 const peopleHtml = (contact: string) => bare(
13 peoplePage({ who, on: "2026-10-10", people: [{ name: "P", roles: ["Lender"], contact, owes: [] } as unknown as Person] }));
14 const dealHtml = (contact: string) => bare(
15 dealPage({
16 who,
17 on: "2026-10-10",
18 deal: { id: 1, address: "A", closed: false, contract_date: "2026-10-01", closing: "2026-11-01", business_days: 0, parties: [{ id: 1, deal_id: 1, role: "lender", name: "P", contact }], deadlines: [], conflicts: [], sent: [] } as unknown as DealView,
19 }));
20
21 for (const [page, render] of [["people", peopleHtml], ["deal", dealHtml]] as const) {
22 test(`${page}: an email is a mailto link`, () => {
23 expect(render(contacts[0]!)).toContain(`href="mailto:[email protected]"`);
24 });
25 test(`${page}: a phone is tel and sms links of digits and +`, () => {
26 const h = render("+1 (555) 010-0142");
27 expect(h).toContain(`href="tel:+15550100142"`);
28 expect(h).toContain(`href="sms:+15550100142"`);
29 });
30 test(`${page}: a name-only contact has no link`, () => {
31 const h = render(contacts[2]!);
32 expect(h).toContain("Ask at the front desk");
33 expect(h).not.toMatch(/href="(mailto|tel|sms):/);
34 });
35 test(`${page}: a hostile contact is escaped and unlinked`, () => {
36 for (const c of [contacts[3]!, contacts[4]!]) {
37 const h = render(c);
38 expect(h).not.toMatch(/href="(mailto|tel|sms|javascript):/);
39 expect(h).not.toContain("<img src=x");
40 expect(h).not.toContain("alert(\"x\")<b>");
41 }
42 });
43 }
44
45 test("partyContact leaves an empty contact empty of links", () => {
46 expect(partyContact("")).toBe("");
47 });
static/app.css +5
@@ -645,6 +645,11 @@ footer code {
645645 grid-column: 2;
646646 overflow-wrap: anywhere;
647647 }
648 .contact-link {
649 display: inline-flex;
650 align-items: center;
651 min-height: var(--size-tap);
652 }
648653 .party-controls {
649654 grid-column: 1 / -1;
650655 display: flex;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs