Public: anyone can read this; the crew can change it.
A deal's page lists the reminders still to come, by day, party and date, so in the meeting the agent shows what the app will draft next and that nothing goes out unapproved #176
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/170-a-deal-s-page-lists-the-reminders-still → main 4 commits fork 3 threads · 3 unresolved
6 files
changed +175
−0
README.md +3
| @@ -51,6 +51,9 @@ looks like today. | ||
| 51 | 51 | offers **Open in Mail** or **Open in Messages**, which open your own app with |
| 52 | 52 | the words: deal-clock never sends anything itself. The count in the header |
| 53 | 53 | goes down. |
| 54 | Under a deal's dates, **Coming reminders** lists what the app will draft | |
| 55 | next, by day, party and date; each is drafted for your approval and nothing | |
| 56 | is sent by itself. The terminal's deal view lists the same. | |
| 54 | 57 | 7. **Hand the client a timeline.** On 1418 Alder Lane's page tap **Client |
| 55 | 58 | timeline**: its dates in order, who owes each, and what the buyer or seller |
| 56 | 59 | does for it, with no controls. Tap **Print** for a one-page handout for Maya |
src/coming.test.ts added +87
| @@ -0,0 +1,87 @@ | ||
| 1 | /** The reminders still to come: derived from the deal's dates, lead times and parties. */ | |
| 2 | import { expect, test } from "bun:test"; | |
| 3 | import { mkdtempSync } from "node:fs"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { addDays, DEFAULT_ZONE, today } from "./dates.ts"; | |
| 7 | import { openDb } from "./db.ts"; | |
| 8 | import { COMING_MAX, coming } from "./coming.ts"; | |
| 9 | import { createDeal, getDeal, markDone, moveDeadline, setReminderLead, waiveDate, type DealView } from "./deals.ts"; | |
| 10 | import { drafts } from "./reminders.ts"; | |
| 11 | import { escape } from "./http.ts"; | |
| 12 | import { dealPage } from "./pages/deal.ts"; | |
| 13 | import type { Who } from "./who.ts"; | |
| 14 | ||
| 15 | const db = openDb(mkdtempSync(join(tmpdir(), "app-coming-"))); | |
| 16 | const alice: Who = { role: "user", id: "u1", name: "alice" }; | |
| 17 | const agent = { name: "Dana", brokerage: "Harbor", phone: "555", email: "[email protected]" }; | |
| 18 | const day = today(DEFAULT_ZONE); | |
| 19 | ||
| 20 | const open = (): DealView => { | |
| 21 | const made = createDeal(db, alice, { openAnyway: true, address: "9 Coming <b>Court", buyer: "Ann <i>Buyer", seller: "Sam Seller", contractDate: day, closingDate: addDays(day, 90) }); | |
| 22 | if (!made.ok) throw new Error(made.message); | |
| 23 | return made.value; | |
| 24 | }; | |
| 25 | const fresh = (id: number): DealView => { | |
| 26 | const got = getDeal(db, alice, { id }); | |
| 27 | if (!got.ok) throw new Error(got.message); | |
| 28 | return got.value; | |
| 29 | }; | |
| 30 | const inspection = (deal: DealView) => deal.deadlines.find((d) => d.kind === "inspection")!; | |
| 31 | ||
| 32 | test("a 7-day lead lists its 'before' reminder on the right day to the right party; moving the date moves it", () => { | |
| 33 | const deal = open(); | |
| 34 | const id = inspection(deal).id; | |
| 35 | expect(moveDeadline(db, alice, { id, due: addDays(day, 30), reason: "test" }).ok).toBe(true); | |
| 36 | expect(setReminderLead(db, alice, { id, leadDays: 7 }).ok).toBe(true); | |
| 37 | const mine = (d: DealView) => coming(d, day, agent).shown.filter((c) => c.label === inspection(d).label && c.moment === "7 days before"); | |
| 38 | const first = mine(fresh(deal.id)); | |
| 39 | expect(first.length).toBeGreaterThan(0); | |
| 40 | expect(first.every((c) => c.on === addDays(day, 23) && c.due === addDays(day, 30))).toBe(true); | |
| 41 | const real = drafts(fresh(deal.id), agent).filter((d) => d.deadline_id === id && d.moment === "before"); | |
| 42 | expect(first.map((c) => c.party_name).sort()).toEqual(real.map((d) => d.party_name).sort()); | |
| 43 | ||
| 44 | expect(moveDeadline(db, alice, { id, due: addDays(day, 40), reason: "test" }).ok).toBe(true); | |
| 45 | expect(mine(fresh(deal.id)).every((c) => c.on === addDays(day, 33))).toBe(true); | |
| 46 | }); | |
| 47 | ||
| 48 | test("done or waived removes a date's reminders; the list is in day order and capped", () => { | |
| 49 | const deal = open(); | |
| 50 | const id = inspection(deal).id; | |
| 51 | moveDeadline(db, alice, { id, due: addDays(day, 30), reason: "test" }); | |
| 52 | const has = (d: DealView) => coming(d, day, agent).shown.some((c) => c.label === inspection(d).label); | |
| 53 | expect(has(fresh(deal.id))).toBe(true); | |
| 54 | markDone(db, alice, { id, done: true }); | |
| 55 | expect(has(fresh(deal.id))).toBe(false); | |
| 56 | markDone(db, alice, { id, done: false }); | |
| 57 | expect(has(fresh(deal.id))).toBe(true); | |
| 58 | waiveDate(db, alice, { id, waived: true }); | |
| 59 | expect(has(fresh(deal.id))).toBe(false); | |
| 60 | const list = coming(fresh(deal.id), day, agent); | |
| 61 | expect(list.shown.length).toBeLessThanOrEqual(COMING_MAX); | |
| 62 | expect([...list.shown].map((c) => c.on)).toEqual([...list.shown].map((c) => c.on).sort()); | |
| 63 | }); | |
| 64 | ||
| 65 | test("a closed deal shows no section; the page escapes names and says nothing is sent by itself", () => { | |
| 66 | const deal = open(); | |
| 67 | const page = (d: DealView) => dealPage({ who: alice, agent, deal: d, on: day }); | |
| 68 | const html = page(fresh(deal.id)); | |
| 69 | expect(html).toContain("Coming reminders"); | |
| 70 | expect(html).toContain("nothing is sent by itself"); | |
| 71 | expect(html).toContain(escape("Ann <i>Buyer")); | |
| 72 | expect(html).not.toContain("Ann <i>Buyer"); | |
| 73 | for (const d of fresh(deal.id).deadlines) markDone(db, alice, { id: d.id, done: true }); | |
| 74 | const closed = fresh(deal.id); | |
| 75 | expect(closed.closed).toBe(true); | |
| 76 | expect(coming(closed, day, agent).shown).toEqual([]); | |
| 77 | expect(page(closed)).not.toContain("Coming reminders"); | |
| 78 | }); | |
| 79 | ||
| 80 | test("a deal with nothing coming says so", () => { | |
| 81 | const deal = open(); | |
| 82 | for (const d of deal.deadlines) if (d.kind !== "closing") markDone(db, alice, { id: d.id, done: true }); | |
| 83 | const closing = fresh(deal.id).deadlines.find((d) => d.kind === "closing")!; | |
| 84 | moveDeadline(db, alice, { id: closing.id, due: day, reason: "test" }); | |
| 85 | const html = dealPage({ who: alice, agent, deal: fresh(deal.id), on: addDays(day, 5) }); | |
| 86 | expect(html).toContain("No reminders coming. Every date is done, waived or past."); | |
| 87 | }); |
src/coming.ts added +52
| @@ -0,0 +1,52 @@ | ||
| 1 | /** | |
| 2 | * The reminders a deal has yet to draft: plain data computed from its dates, | |
| 3 | * lead times and parties on each request, by reading `drafts` itself, so the | |
| 4 | * list and the real drafts can never disagree. Nothing is stored. | |
| 5 | */ | |
| 6 | ||
| 7 | import { drafts, momentLabel, type Agent } from "./reminders.ts"; | |
| 8 | import type { DealView } from "./deals.ts"; | |
| 9 | import { PARTY_LABEL, type PartyRole } from "./deadlines.ts"; | |
| 10 | import { spoken } from "./dates.ts"; | |
| 11 | ||
| 12 | /** At most this many are listed; the rest are counted. */ | |
| 13 | export const COMING_MAX = 10; | |
| 14 | ||
| 15 | export interface Coming { | |
| 16 | /** The morning it will be drafted. */ | |
| 17 | readonly on: string; | |
| 18 | /** "7 days before", "Morning of", "Overdue follow-up". */ | |
| 19 | readonly moment: string; | |
| 20 | readonly label: string; | |
| 21 | readonly due: string; | |
| 22 | readonly party_name: string; | |
| 23 | readonly party_role: PartyRole; | |
| 24 | } | |
| 25 | ||
| 26 | export interface ComingList { | |
| 27 | readonly shown: readonly Coming[]; | |
| 28 | /** How many more there are beyond `shown`. */ | |
| 29 | readonly rest: number; | |
| 30 | } | |
| 31 | ||
| 32 | /** The reminders after `day` for the open dates of `deal`, in day order; none once the deal is closed or fell through. */ | |
| 33 | export function coming(deal: DealView, day: string, agent: Agent): ComingList { | |
| 34 | const all = drafts(deal, agent) | |
| 35 | .filter((d) => d.on > day && d.sent_at === null && d.declined === null && d.held === null) | |
| 36 | .filter((d) => d.moment === "before" || d.moment === "day_of" || d.moment === "late") | |
| 37 | .map((d, i) => ({ d, i })) | |
| 38 | .sort((a, b) => a.d.on.localeCompare(b.d.on) || a.i - b.i) | |
| 39 | .map(({ d }) => ({ | |
| 40 | on: d.on, | |
| 41 | moment: momentLabel(d.moment, d.lead_days), | |
| 42 | label: d.label, | |
| 43 | due: d.due, | |
| 44 | party_name: d.party_name, | |
| 45 | party_role: d.party_role, | |
| 46 | })); | |
| 47 | return { shown: all.slice(0, COMING_MAX), rest: Math.max(0, all.length - COMING_MAX) }; | |
| 48 | } | |
| 49 | ||
| 50 | /** "Mon, Nov 16 · 7 days before · Inspection due Mon, Nov 23 · to Ann Buyer (buyer)": one line, for the page and the terminal alike. */ | |
| 51 | export const comingLine = (c: Coming): string => | |
| 52 | `${spoken(c.on)} · ${c.moment} · ${c.label} due ${spoken(c.due)} · to ${c.party_name} (${PARTY_LABEL[c.party_role].toLowerCase()})`; |
src/pages/deal.ts +15
| @@ -10,6 +10,7 @@ import { matchKnown, type Known } from "../people.ts"; | ||
| 10 | 10 | import { agent as defaults, standard } from "../env.ts"; |
| 11 | 11 | import { DEFAULT_LENGTHS, PARTY_LABEL, PARTY_ROLES, SUGGESTED_DATES } from "../deadlines.ts"; |
| 12 | 12 | import { escape } from "../http.ts"; |
| 13 | import { coming, comingLine, type Coming } from "../coming.ts"; | |
| 13 | 14 | import { closingLine } from "../closing.ts"; |
| 14 | 15 | import { commission, dollars, percent } from "../money.ts"; |
| 15 | 16 | import { checkinDrafts, drafts, sentLabel, statusDrafts, type Agent } from "../reminders.ts"; |
| @@ -159,6 +160,19 @@ function figuresLine(deal: DealView): string { | ||
| 159 | 160 | return parts.length === 0 && pays === "" ? "" : `${parts.length === 0 ? "" : `<p class="summary" id="figures">${parts.join(" · ")}</p>`}${pays}`; |
| 160 | 161 | } |
| 161 | 162 | |
| 163 | /** The reminders still to be drafted, by day: what the agent shows in the meeting. Nothing for a deal that is over. */ | |
| 164 | function comingCard(deal: DealView, agent: Agent, on: string): string { | |
| 165 | if (deal.closed || deal.fell_through) return ""; | |
| 166 | const { shown, rest } = coming(deal, on, agent); | |
| 167 | const row = (c: Coming): string => `<li>${escape(comingLine(c))}</li>`; | |
| 168 | return `<section class="card" id="coming"> | |
| 169 | <h2>Coming reminders</h2> | |
| 170 | <p class="muted">Each is drafted for your approval; nothing is sent by itself.</p> | |
| 171 | ${shown.length === 0 ? `<p>No reminders coming. Every date is done, waived or past.</p>` : `<ul class="stack">${shown.map(row).join("")}</ul>${rest > 0 ? `<p class="muted">…and ${rest} more after that.</p>` : ""}`} | |
| 172 | </section> | |
| 173 | `; | |
| 174 | } | |
| 175 | ||
| 162 | 176 | /** What the deal pays the agent at closing: for the agent's page only, never the client's. */ |
| 163 | 177 | function commissionLine(deal: DealView): string { |
| 164 | 178 | if (deal.commission_rate === null) return ""; |
| @@ -354,6 +368,7 @@ export function dealPage(input: { | ||
| 354 | 368 | ${conflictLines(deal)} |
| 355 | 369 | <ol class="dates">${dates}</ol> |
| 356 | 370 | </section> |
| 371 | ${comingCard(deal, agent ?? defaults, on)} | |
| 357 | 372 | <section class="card" id="parties"> |
| 358 | 373 | <h2>Parties</h2> |
| 359 | 374 | ${parties} |
src/terminal.test.ts +10
| @@ -919,3 +919,13 @@ test("c with yes lists no appraisal or financing date, and with enter lists them | ||
| 919 | 919 | if (!listed.ok) throw new Error(listed.message); |
| 920 | 920 | expect(listed.value.some((d) => d.address === "70 Preview Ln")).toBe(false); |
| 921 | 921 | }); |
| 922 | ||
| 923 | test("the deal view lists the reminders still to come, and says nothing is sent by itself", () => { | |
| 924 | const t = terminal(db, alice, context); | |
| 925 | goTo(t, "12 Elm St"); | |
| 926 | press(t, "o"); | |
| 927 | const screen = lines(t).join("\n"); | |
| 928 | expect(screen).toContain("Coming reminders"); | |
| 929 | expect(screen).toContain("nothing is sent by itself"); | |
| 930 | expect(screen).toMatch(/· \d+ days? before · .* due .* · to /); | |
| 931 | }); |
src/terminal.ts +8
| @@ -75,6 +75,7 @@ import { permit } from "./contract.ts"; | ||
| 75 | 75 | import { exportDeals, exportName } from "./export.ts"; |
| 76 | 76 | import { mkdirSync, writeFileSync } from "node:fs"; |
| 77 | 77 | import { join } from "node:path"; |
| 78 | import { coming, comingLine } from "./coming.ts"; | |
| 78 | 79 | import { drafts, heldFrom, momentLabel, pending, remindsLine, sentLabel, unsent, type Agent, type Draft } from "./reminders.ts"; |
| 79 | 80 | import type { AuditRow } from "./audit.ts"; |
| 80 | 81 | import type { Result } from "./result.ts"; |
| @@ -870,6 +871,13 @@ export function terminal( | ||
| 870 | 871 | const at = deal.deadlines.length + i === cursor; |
| 871 | 872 | lines.push(`${at ? "▸" : " "} ${PARTY_LABEL[p.role].padEnd(14)} ${at ? bold(p.name) : p.name}${reachedAt(p) === "" ? "" : dim(` ${reachedAt(p)}`)}`); |
| 872 | 873 | }); |
| 874 | if (!deal.closed && !deal.fell_through) { | |
| 875 | const { shown, rest } = coming(deal, day, agentNow()); | |
| 876 | lines.push("", bold("Coming reminders"), dim("Each is drafted for your approval; nothing is sent by itself.")); | |
| 877 | if (shown.length === 0) lines.push(" No reminders coming. Every date is done, waived or past."); | |
| 878 | shown.forEach((c) => lines.push(` ${comingLine(c)}`)); | |
| 879 | if (rest > 0) lines.push(dim(` …and ${rest} more after that.`)); | |
| 880 | } | |
| 873 | 881 | } |
| 874 | 882 | } else { |
| 875 | 883 | const rows = reminderRows(); |
new above
offline
Stacked commas: "Inspection, Mon, Nov 23". Use "due" or a dash.