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
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/74-a-party-s-phone-or-email-on-the-people-p → main 1 commit fork 1 thread · 1 unresolved
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. | ||
| 25 | 25 | Before calling a lender or an inspector, open **People** in the header: each |
| 26 | 26 | person on your deals appears once, with every open date they owe across all |
| 27 | 27 | 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`. | |
| 29 | 29 | |
| 30 | 30 | To find a deal, type part of its address, or of a buyer's, seller's or other |
| 31 | 31 | 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 @@ | ||
| 3 | 3 | 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`. |
| 4 | 4 | |
| 5 | 5 | - `.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 { | ||
| 16 | 16 | /** What shows where there is no link to offer. */ |
| 17 | 17 | export const NO_CONTACT = "No email or phone on file"; |
| 18 | 18 | |
| 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 | ||
| 19 | 29 | /** |
| 20 | 30 | * The link for these words to this contact: `mailto:` for an email, `sms:` |
| 21 | 31 | * for a phone, null for anything else. A contact is only used after it passes |
| 22 | 32 | * the same checks the settings do, so no quote or scheme can ride in it. |
| 23 | 33 | */ |
| 24 | 34 | export function outbox(contact: string, subject: string, body: string): Outbox | null { |
| 25 | if (validEmail(contact)) | |
| 35 | const kind = contactKind(contact); | |
| 36 | if (kind === "email") | |
| 26 | 37 | return { |
| 27 | 38 | kind: "mail", |
| 28 | 39 | href: `mailto:${contact}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`, |
| 29 | 40 | label: "Open in Mail", |
| 30 | 41 | }; |
| 31 | if (validPhone(contact)) | |
| 42 | if (kind === "phone") | |
| 32 | 43 | return { |
| 33 | 44 | kind: "sms", |
| 34 | href: `sms:${contact.replace(/[^0-9+]/g, "")}?&body=${encodeURIComponent(body)}`, | |
| 45 | href: `sms:${dialable(contact)}?&body=${encodeURIComponent(body)}`, | |
| 35 | 46 | label: "Open in Messages", |
| 36 | 47 | }; |
| 37 | 48 | return null; |
src/pages/contact.ts +19
| @@ -2,6 +2,25 @@ | ||
| 2 | 2 | |
| 3 | 3 | import type { Agent } from "../reminders.ts"; |
| 4 | 4 | import { escape } from "../http.ts"; |
| 5 | import { contactKind, dialable } from "../outbox.ts"; | |
| 5 | 6 | |
| 6 | 7 | export const contactLinks = (agent: Agent): string => |
| 7 | 8 | `<a href="tel:${escape(agent.phone.replace(/[^0-9+]/g, ""))}">${escape(agent.phone)}</a> · <a href="mailto:${escape(agent.email)}">${escape(agent.email)}</a>`; |
| 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"; | ||
| 12 | 12 | import { MOMENT_LABEL, type Agent } from "../reminders.ts"; |
| 13 | 13 | import type { Who } from "../who.ts"; |
| 14 | 14 | import { amendForm, type AmendState } from "./amend.ts"; |
| 15 | import { partyContact } from "./contact.ts"; | |
| 15 | 16 | import { confirmRemove } from "./confirm.ts"; |
| 16 | 17 | import { layout } from "./layout.ts"; |
| 17 | 18 | import { badge, conflictLines, dueLine, outboxLine, owedBy, sheet, sheetId } from "./sheet.ts"; |
| @@ -104,7 +105,7 @@ export function dealPage(input: { | ||
| 104 | 105 | : `<ul class="parties">${deal.parties |
| 105 | 106 | .map( |
| 106 | 107 | (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>`, | |
| 108 | 109 | ) |
| 109 | 110 | .join("")}</ul>`; |
| 110 | 111 | const forms = may |
src/pages/people.ts +2 −1
| @@ -9,6 +9,7 @@ import { escape } from "../http.ts"; | ||
| 9 | 9 | import type { Person } from "../people.ts"; |
| 10 | 10 | import type { Who } from "../who.ts"; |
| 11 | 11 | import type { Agent } from "../reminders.ts"; |
| 12 | import { partyContact } from "./contact.ts"; | |
| 12 | 13 | import { layout } from "./layout.ts"; |
| 13 | 14 | import { URGENCY_LABEL } from "./sheet.ts"; |
| 14 | 15 | |
| @@ -17,7 +18,7 @@ const owedRow = (o: Person["owes"][number], on: string): string => | ||
| 17 | 18 | |
| 18 | 19 | const person = (p: Person, on: string): string => `<section class="card person"> |
| 19 | 20 | <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> | |
| 21 | 22 | ${p.owes.length === 0 ? `<p class="muted">Nothing open</p>` : `<ul class="week-list">${p.owes.map((o) => owedRow(o, on)).join("")}</ul>`} |
| 22 | 23 | </section>`; |
| 23 | 24 |
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 { | ||
| 645 | 645 | grid-column: 2; |
| 646 | 646 | overflow-wrap: anywhere; |
| 647 | 647 | } |
| 648 | .contact-link { | |
| 649 | display: inline-flex; | |
| 650 | align-items: center; | |
| 651 | min-height: var(); | |
| 652 | } | |
| 648 | 653 | .party-controls { |
| 649 | 654 | grid-column: 1 / -1; |
| 650 | 655 | display: flex; |
new above
offline
Nit: reuse dialable(agent.phone) here so there is truly one digit-stripping rule.