Public: anyone can read this; the crew can change it.
The desk lists the agent's upcoming showings in time order, each linked to its lead #76
Check · Review · Land · Live done — Landed and live in production.
mason/speed-to-lead:mason/59-the-desk-lists-the-agent-s-upcoming-show → main 1 commit fork
11 files
changed +141
−7
README.md +1
| @@ -65,6 +65,7 @@ what you see right after a restart. Do step 1 first. | ||
| 65 | 65 | lead's plan as "After the showing". The sample **Rosa Alvarez** had a |
| 66 | 66 | showing yesterday, so her note is already waiting on a fresh desk. A |
| 67 | 67 | cancelled showing has none; a second showing gets a second note. |
| 68 | A fresh desk also lists upcoming showings above the leads (soonest first, at most five, each linked to its lead): **Aisha Bello** has one in two days. | |
| 68 | 69 | 8. Set your profile (admin to save). Press "Your profile" at the top, fill |
| 69 | 70 | in your name, brokerage, license number, phone and email, and save. Every |
| 70 | 71 | draft not yet sent takes it at once. |
docs/design/areas/desk.md +7
| @@ -12,3 +12,10 @@ The agent opens the desk and a lead's page on a phone in the meeting. Under | ||
| 12 | 12 | |
| 13 | 13 | No new component class: the rules extend `.lead-row`, `.actions`, `.states`, |
| 14 | 14 | `.button`, `.views`, `.search` and `.plan`. |
| 15 | ||
| 16 | # Desk: the showings list | |
| 17 | ||
| 18 | Above the record and the leads, while a showing is ahead: `.showings`, a | |
| 19 | `section` holding an `h2`, a plain `ul` of `.showing-when` (the time, as the | |
| 20 | badge words it), the lead's name as a link, and the address in `.muted`. | |
| 21 | At most five, then "and N more". Absent, not empty, when none is ahead. |
src/after-showing.test.ts +3 −1
| @@ -227,7 +227,9 @@ test("a sample desk has a showing from yesterday and its note ready now", () => | ||
| 227 | 227 | .query<{ name: string; status: string; body: string }, [number]>( |
| 228 | 228 | "SELECT lead.name, message.status, message.body FROM message JOIN lead ON lead.id = message.lead_id WHERE message.day = ?1", |
| 229 | 229 | ) |
| 230 | .all(AFTER_SHOWING_DAY); | |
| 230 | .all(AFTER_SHOWING_DAY) | |
| 231 | // A showing still ahead (Aisha's) drafts its note too, but it is not due. | |
| 232 | .filter((m) => m.name === "Rosa Alvarez"); | |
| 231 | 233 | expect(ready).toHaveLength(1); |
| 232 | 234 | expect(ready[0]!.status).toBe("due"); |
| 233 | 235 | expect(ready[0]!.body).toContain("418 Juniper Ln"); |
src/leads.ts +18
| @@ -232,6 +232,24 @@ export const showingOf = (db: Database, id: number): Showing | null => | ||
| 232 | 232 | .query<Showing, [number]>("SELECT * FROM showing WHERE lead_id = ?1") |
| 233 | 233 | .get(id); |
| 234 | 234 | |
| 235 | /** A showing still ahead, with the lead it is for. */ | |
| 236 | export interface Ahead { | |
| 237 | readonly id: number; | |
| 238 | readonly name: string; | |
| 239 | readonly at: string; | |
| 240 | readonly address: string; | |
| 241 | } | |
| 242 | ||
| 243 | /** Every showing after `now`, soonest first (cancelled ones are gone from the table). */ | |
| 244 | export const showingsAhead = (db: Database, now: number): Ahead[] => | |
| 245 | db | |
| 246 | .query<Ahead, [string]>( | |
| 247 | `SELECT lead.id AS id, lead.name AS name, showing.at AS at, showing.address AS address | |
| 248 | FROM showing JOIN lead ON lead.id = showing.lead_id | |
| 249 | WHERE showing.at > ?1 ORDER BY showing.at, lead.id`, | |
| 250 | ) | |
| 251 | .all(new Date(now).toISOString()); | |
| 252 | ||
| 235 | 253 | export function detail(db: Database, id: number): LeadDetail | null { |
| 236 | 254 | const found = findLead(db, id); |
| 237 | 255 | return found === null |
src/pages/desk.ts +22 −2
| @@ -9,9 +9,9 @@ import { escape } from "../http.ts"; | ||
| 9 | 9 | import { recordLine, sourceLine } from "../clock.ts"; |
| 10 | 10 | import { isAfterShowing, isAnswer } from "../drafts.ts"; |
| 11 | 11 | import { goesLabel, RECORD_NOTE } from "../quiet.ts"; |
| 12 | import { showingWhen } from "../showings.ts"; | |
| 12 | import { MAX_LISTED, showingWhen } from "../showings.ts"; | |
| 13 | 13 | import { MAX_EMAIL_TEXT, missingLine } from "../intake.ts"; |
| 14 | import { inView, noteLine, type DeskLead, type NewLead, type ResponseRecord, type View } from "../leads.ts"; | |
| 14 | import { inView, type Ahead, noteLine, type DeskLead, type NewLead, type ResponseRecord, type View } from "../leads.ts"; | |
| 15 | 15 | import type { Agent } from "../env.ts"; |
| 16 | 16 | import type { Who } from "../who.ts"; |
| 17 | 17 | |
| @@ -23,6 +23,8 @@ export function deskPage(input: { | ||
| 23 | 23 | show?: View | undefined; |
| 24 | 24 | q?: string | undefined; |
| 25 | 25 | counts?: Record<View, number> | undefined; |
| 26 | /** Every showing still ahead, soonest first; the desk lists the first few. */ | |
| 27 | ahead?: readonly Ahead[] | undefined; | |
| 26 | 28 | mayAdd: boolean; |
| 27 | 29 | mayReset: boolean; |
| 28 | 30 | notice?: string | undefined; |
| @@ -74,6 +76,7 @@ export function deskPage(input: { | ||
| 74 | 76 | leads.length === 0 |
| 75 | 77 | ? `<p class="empty">${q === "" ? EMPTY[show] : `No lead matches '${escape(q)}'${show === "all" ? "" : " in this view"}.`}</p>` |
| 76 | 78 | : `<ul class="desk">${leads.map((lead) => row(lead, now, agent.timeZone)).join("")}</ul>`; |
| 79 | const showings = showingsList(input.ahead ?? [], now, agent.timeZone); | |
| 77 | 80 | const tab = deskTitle(counts?.needs ?? leads.filter((l) => inView(l, "needs")).length); |
| 78 | 81 | return layout({ |
| 79 | 82 | who, |
| @@ -83,6 +86,7 @@ export function deskPage(input: { | ||
| 83 | 86 | tab, |
| 84 | 87 | body: `<div id="desk" data-live="lead.added lead.changed" data-title="${escape(tab)}"> |
| 85 | 88 | <div class="desk-head"><h1>Leads</h1>${summary}</div> |
| 89 | ${showings} | |
| 86 | 90 | ${record} |
| 87 | 91 | ${search} |
| 88 | 92 | ${views} |
| @@ -145,6 +149,22 @@ const EMPTY: Record<View, string> = { | ||
| 145 | 149 | all: "No leads yet. New inquiries appear here the moment they arrive.", |
| 146 | 150 | }; |
| 147 | 151 | |
| 152 | /** The next showings, soonest first, each linking to its lead; nothing at all when none is ahead. */ | |
| 153 | function showingsList(ahead: readonly Ahead[], now: number, zone: string): string { | |
| 154 | if (ahead.length === 0) return ""; | |
| 155 | const more = ahead.length - MAX_LISTED; | |
| 156 | return `<section class="showings" aria-label="Showings"> | |
| 157 | <h2>Showings</h2> | |
| 158 | <ul>${ahead | |
| 159 | .slice(0, MAX_LISTED) | |
| 160 | .map( | |
| 161 | (s) => | |
| 162 | `<li><span class="showing-when">${escape(showingWhen(s.at, now, zone))}</span> <a href="/leads/${s.id}">${escape(s.name)}</a>${s.address === "" ? "" : ` <span class="muted">${escape(s.address)}</span>`}</li>`, | |
| 163 | ) | |
| 164 | .join("")}</ul>${more > 0 ? `\n <p class="muted">and ${more} more</p>` : ""} | |
| 165 | </section>`; | |
| 166 | } | |
| 167 | ||
| 148 | 168 | /** A follow-up due while a showing is ahead waits until the day after it. */ |
| 149 | 169 | const held = (lead: DeskLead, due: string): string => |
| 150 | 170 | lead.showing !== null && due < lead.showing.hold_until ? lead.showing.hold_until : due; |
src/routes.ts +2 −1
| @@ -68,7 +68,7 @@ import { MAX_NOTE, OUTCOMES } from "./calls.ts"; | ||
| 68 | 68 | import { MAX_ADDRESS, MAX_AHEAD_DAYS } from "./showings.ts"; |
| 69 | 69 | import { MAX_EMAIL_TEXT } from "./intake.ts"; |
| 70 | 70 | import { LOST_REASONS, lostSaid } from "./lost.ts"; |
| 71 | import { MAX_INBOUND, MAX_LEAD_NOTE, MAX_QUERY, Q_HELP, VIEW_HELP, VIEWS, type NewLead } from "./leads.ts"; | |
| 71 | import { MAX_INBOUND, MAX_LEAD_NOTE, MAX_QUERY, Q_HELP, showingsAhead, VIEW_HELP, VIEWS, type NewLead } from "./leads.ts"; | |
| 72 | 72 | import { events } from "./live.ts"; |
| 73 | 73 | import { rpc } from "./mcp.ts"; |
| 74 | 74 | import { deskPage } from "./pages/desk.ts"; |
| @@ -559,6 +559,7 @@ function desk( | ||
| 559 | 559 | show: leads.ok ? leads.value.show : undefined, |
| 560 | 560 | q: leads.ok ? leads.value.q : undefined, |
| 561 | 561 | counts: leads.ok ? leads.value.counts : undefined, |
| 562 | ahead: leads.ok ? showingsAhead(c.db, Date.now()) : undefined, | |
| 562 | 563 | mayAdd: permit(c.who, "lead", "create") === "yes", |
| 563 | 564 | mayReset: permit(c.who, "lead", "delete") === "yes", |
| 564 | 565 | notice: pasted?.notice ?? refused ?? notice, |
src/sample.ts +8 −1
| @@ -34,6 +34,8 @@ interface Sample extends NewLead { | ||
| 34 | 34 | readonly closed?: Closing; |
| 35 | 35 | /** A showing already held, this long ago (rounded to the agent's morning after it). */ |
| 36 | 36 | readonly showedAgo?: number; |
| 37 | /** A showing booked ahead: this many days from today at 10:00 in the agent's zone. */ | |
| 38 | readonly showingInDays?: number; | |
| 37 | 39 | /** The agent's private note on the lead, as of the first reply or the inquiry. */ |
| 38 | 40 | readonly note?: string; |
| 39 | 41 | } |
| @@ -69,7 +71,7 @@ export const SAMPLES: readonly Sample[] = [ | ||
| 69 | 71 | person("David Chen", "website", false, "We're thinking about selling our townhouse in the spring. Any idea what it might be worth in today's market?", { ago: 3 * M + 10 * S }), |
| 70 | 72 | person("Priya Raman", "open_house", true, "Loved the kitchen at Sunday's open house on Alder Ct. Are the sellers flexible on price at all?", { ago: 18 * M }), |
| 71 | 73 | person("James O'Neill", "referral", false, "Sarah Patel said you helped her family relocate last year. We're moving from Denver in August and don't know the area.", { ago: 47 * M }), |
| 72 | person("Aisha Bello", "zillow", false, "Pre-approved up to $550k. Looking for 3 bedrooms with a yard, ideally near good schools.", { ago: 2 * H + 12 * M, note: "Pre-approved to $550k. Wants 3 bed with a yard near Lincoln Elementary. Lease ends in June, so moving by then." }), | |
| 74 | person("Aisha Bello", "zillow", false, "Pre-approved up to $550k. Looking for 3 bedrooms with a yard, ideally near good schools.", { ago: 2 * H + 12 * M, showingInDays: 2, note: "Pre-approved to $550k. Wants 3 bed with a yard near Lincoln Elementary. Lease ends in June, so moving by then." }), | |
| 73 | 75 | person("Tom Becker", "website", true, "Do you work with first-time buyers? We have no idea where to start.", { ago: 5 * H + 30 * M }), |
| 74 | 76 | person("Lena Novak", "open_house", false, "Signed in at the open house on Birch St. Could you send me the disclosures and HOA details?", { ago: 26 * H }), |
| 75 | 77 | person("Marcus Lee", "zillow", true, "Can I tour 92 Harbor View Dr this week? Available most evenings after 6.", { ago: 2 * D + 3 * H, answeredIn: 48 * S, touched: [1], note: "Works nights: call after 6. Cash buyer, relocating from Austin; wants a short closing." }), |
| @@ -106,6 +108,11 @@ export function seed(db: Database, now: Date): number { | ||
| 106 | 108 | held = wallAt(held, -1, 10, agent.timeZone) ?? held - D; |
| 107 | 109 | bookShowing(db, findLead(db, id)!, iso(held), "418 Juniper Ln", iso(replied(sample, asked)), agent); |
| 108 | 110 | } |
| 111 | if (sample.showingInDays !== undefined) { | |
| 112 | const agent = currentAgent(db); | |
| 113 | const ahead = wallAt(t, sample.showingInDays, 10, agent.timeZone) ?? t + sample.showingInDays * D; | |
| 114 | bookShowing(db, findLead(db, id)!, iso(ahead), "27 Alder Ct", iso(asked), agent); | |
| 115 | } | |
| 109 | 116 | if (sample.note !== undefined) |
| 110 | 117 | writeNote(db, findLead(db, id)!, sample.note, iso(asked + 30 * M)); |
| 111 | 118 | if (sample.closed !== undefined) close(db, id, sample.closed, iso(t - 2 * D)); |
src/server.test.ts +1 −1
| @@ -636,7 +636,7 @@ test("the desk views: links with counts, aria-current, bad value is all, JSON ma | ||
| 636 | 636 | leads: { id: number }[]; |
| 637 | 637 | }; |
| 638 | 638 | expect(json.show).toBe(show); |
| 639 | const inHtml = [...page.matchAll(/href="\/leads\/(\d+)"/g)].map((m) => Number(m[1])); | |
| 639 | const inHtml = [...page.matchAll(/class="lead-row" href="\/leads\/(\d+)"/g)].map((m) => Number(m[1])); | |
| 640 | 640 | expect(inHtml).toEqual(json.leads.map((l) => l.id)); |
| 641 | 641 | } |
| 642 | 642 | const bad = await (await api("/?show=zzz", {}, alice)).text(); |
src/showings.test.ts +64 −1
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | * before it held until the day after and released on cancel, the history |
| 4 | 4 | * and the desk badge escaped; at every door. |
| 5 | 5 | */ |
| 6 | import { afterAll, expect, test } from "bun:test"; | |
| 6 | import { afterAll, describe, expect, test } from "bun:test"; | |
| 7 | 7 | import { mkdtempSync } from "node:fs"; |
| 8 | 8 | import { tmpdir } from "node:os"; |
| 9 | 9 | import { join } from "node:path"; |
| @@ -18,6 +18,8 @@ import { | ||
| 18 | 18 | turn, |
| 19 | 19 | } from "./actions.ts"; |
| 20 | 20 | import { openDb } from "./db.ts"; |
| 21 | import { deskPage } from "./pages/desk.ts"; | |
| 22 | import { showingsAhead, type Ahead } from "./leads.ts"; | |
| 21 | 23 | import { currentAgent, storeAgent } from "./profile.ts"; |
| 22 | 24 | import { serve } from "./server.ts"; |
| 23 | 25 | import { localInput, showingLine, showingWhen, timeOf } from "./showings.ts"; |
| @@ -397,3 +399,64 @@ test("booking reads a time with no offset in the profile's zone, and holds follo | ||
| 397 | 399 | const explicit = value(bookShowing(db, alice, { id, when: "2026-03-07T10:00:00Z" }, at(1))); |
| 398 | 400 | expect(explicit.showing?.at).toBe("2026-03-07T10:00:00.000Z"); |
| 399 | 401 | }); |
| 402 | ||
| 403 | describe("the desk's list of upcoming showings", () => { | |
| 404 | const NOW = Date.parse("2026-03-01T10:00:00Z"); | |
| 405 | const listing = (ahead: Ahead[], who: Who = alice) => | |
| 406 | deskPage({ who, agent: currentAgent(fresh()), leads: who.role === "anon" ? undefined : [], ahead, mayAdd: false, mayReset: false }); | |
| 407 | const a = (id: number, days: number, name = `Lead ${id}`, address = ""): Ahead => ({ | |
| 408 | id, | |
| 409 | name, | |
| 410 | address, | |
| 411 | at: new Date(NOW + days * DAY).toISOString(), | |
| 412 | }); | |
| 413 | ||
| 414 | test("lists soonest first, linked, with the address", () => { | |
| 415 | const db = fresh(); | |
| 416 | const mk = (name: string) => | |
| 417 | value(addLead(db, alice, { name, email: `${name}@example.com`, phone: "", source: "zillow", message: "Hi", consent: false }, T0)).id; | |
| 418 | const [x, y, z] = [mk("late"), mk("soon"), mk("past")]; | |
| 419 | value(bookShowing(db, alice, { id: x, when: "2026-03-05T10:00", address: "9 Late St" }, T0)); | |
| 420 | value(bookShowing(db, alice, { id: y, when: "2026-03-03T10:00", address: "" }, T0)); | |
| 421 | value(bookShowing(db, alice, { id: z, when: "2026-03-04T10:00", address: "" }, T0)); | |
| 422 | value(cancelShowing(db, alice, { id: z }, T0)); | |
| 423 | const rows = showingsAhead(db, T0.getTime()); | |
| 424 | expect(rows.map((r) => r.name)).toEqual(["soon", "late"]); | |
| 425 | const page = listing(rows); | |
| 426 | expect(page.indexOf(`/leads/${y}">soon`)).toBeLessThan(page.indexOf(`/leads/${x}">late`)); | |
| 427 | expect(page).toContain("9 Late St"); | |
| 428 | expect(page).not.toContain("past"); | |
| 429 | }); | |
| 430 | ||
| 431 | test("a showing already past is not ahead", () => { | |
| 432 | const db = fresh(); | |
| 433 | const id = value(addLead(db, alice, { name: "Old", email: "[email protected]", phone: "", source: "zillow", message: "Hi", consent: false }, T0)).id; | |
| 434 | value(bookShowing(db, alice, { id, when: "2026-03-03T10:00", address: "" }, T0)); | |
| 435 | expect(showingsAhead(db, at(3).getTime())).toEqual([]); | |
| 436 | }); | |
| 437 | ||
| 438 | test("shows five and counts the rest", () => { | |
| 439 | const page = listing([1, 2, 3, 4, 5, 6, 7].map((i) => a(i, i))); | |
| 440 | expect(page.match(/class="showing-when"/g)).toHaveLength(5); | |
| 441 | expect(page).toContain("and 2 more"); | |
| 442 | expect(listing([1, 2, 3, 4, 5].map((i) => a(i, i)))).not.toContain(" more"); | |
| 443 | }); | |
| 444 | ||
| 445 | test("with none ahead there is no list", () => { | |
| 446 | expect(listing([])).not.toContain("showings"); | |
| 447 | expect(listing([])).not.toContain("Showings"); | |
| 448 | }); | |
| 449 | ||
| 450 | test("names and addresses are escaped", () => { | |
| 451 | const page = listing([a(1, 1, "<script>x()</script>", "<img src=x onerror=y()>")]); | |
| 452 | expect(page).not.toContain("<script>x()"); | |
| 453 | expect(page).not.toContain("<img src=x"); | |
| 454 | expect(page).toContain("<script>"); | |
| 455 | }); | |
| 456 | ||
| 457 | test("the signed-out page has no list", () => { | |
| 458 | const page = listing([a(1, 1, "Secret Name")], anon); | |
| 459 | expect(page).not.toContain("Secret Name"); | |
| 460 | expect(page).not.toContain('class="showings"'); | |
| 461 | }); | |
| 462 | }); |
src/showings.ts +3
| @@ -9,6 +9,9 @@ export const MAX_ADDRESS = 200; | ||
| 9 | 9 | /** How far ahead a showing may be booked. */ |
| 10 | 10 | export const MAX_AHEAD_DAYS = 90; |
| 11 | 11 | |
| 12 | /** How many upcoming showings the desk lists before "and N more". */ | |
| 13 | export const MAX_LISTED = 5; | |
| 14 | ||
| 12 | 15 | const DAY_MS = 86_400_000; |
| 13 | 16 | |
| 14 | 17 | /** A showing as stored: one per lead. */ |
static/app.css +12
| @@ -724,3 +724,15 @@ label.check input { | ||
| 724 | 724 | bottom: var(); |
| 725 | 725 | } |
| 726 | 726 | } |
| 727 | ||
| 728 | .showings { | |
| 729 | margin-block: var(); | |
| 730 | } | |
| 731 | .showings ul { | |
| 732 | list-style: none; | |
| 733 | margin: 0; | |
| 734 | padding: 0; | |
| 735 | } | |
| 736 | .showing-when { | |
| 737 | font-weight: 600; | |
| 738 | } |
new above
offline