Public: anyone can read this; the crew can change it.
When a lead's last follow-up has gone out with no answer, the desk says so and one tap marks them lost (never answered) #88
Check · Review · Land · Live done — Landed and live in production.
mason/speed-to-lead:mason/69-when-a-lead-s-last-follow-up-has-gone-ou → main 3 commits fork
14 files
changed +301
−21
README.md +12
| @@ -131,6 +131,18 @@ samples (step 1). | ||
| 131 | 131 | |
| 132 | 132 | ## How it works |
| 133 | 133 | |
| 134 | **When follow-ups run out.** A lead that is still new or contacted, whose | |
| 135 | every follow-up (on its own schedule, whatever cadence the agent chose) has | |
| 136 | gone out or been set aside, and who has never written back, been called or had | |
| 137 | a showing booked, shows "Follow-ups finished — no answer" on its desk row and | |
| 138 | its page (`followUpsFinished`, `src/finished.ts`). The row offers one button, | |
| 139 | "Mark lost — never answered": it posts to `/leads/:id/state` with the | |
| 140 | `never_answered` reason, so it is the same action, `permit` check and Activity | |
| 141 | entry as marking lost by hand, and nothing is sent to the lead. The | |
| 142 | terminal says the same on the desk and lead screen, and `m` on the lead screen | |
| 143 | does the same one thing (hidden for anyone `permit` would refuse). No new | |
| 144 | permission cell. The sample desk includes one such lead (Ruth Okafor). | |
| 145 | ||
| 134 | 146 | **Sample inquiries** arrive on demand from the desk button, `POST |
| 135 | 147 | /sample/inquiry` (JSON, 201), the MCP `new_sample_inquiry` tool, or `i` in the |
| 136 | 148 | terminal desk. They go through the same path as `POST /leads`, for anyone who |
docs/design/areas/desk.md +9
| @@ -29,3 +29,12 @@ link; `.lead-item` is a two-column grid (the row, then the star). On a lead's | ||
| 29 | 29 | page the same form sits under the name. The button is `--size-tap` (44px) |
| 30 | 30 | square on every screen, so it is a thumb-sized target on a phone, and it |
| 31 | 31 | works as a plain POST with no JavaScript. |
| 32 | ||
| 33 | # Desk: a lead the follow-ups have finished with | |
| 34 | ||
| 35 | `.status[data-finished]` reads "Follow-ups finished — no answer". Under the | |
| 36 | row, `.close-out` is a form holding one `.button.button-quiet` ("Mark lost — | |
| 37 | never answered"), padded to line up with the row; it sits beside the row's | |
| 38 | link inside `li.lead-item` (full width under the row, shown to whoever | |
| 39 | sees the star), never inside it. On the lead's page the same form leads | |
| 40 | `.states`, as a plain `.button`. |
src/actions.test.ts +2 −2
| @@ -226,10 +226,10 @@ test("qualified or lost leaves the cadence", () => { | ||
| 226 | 226 | if (!gone.ok) expect(gone.error).toBe("not_found"); |
| 227 | 227 | }); |
| 228 | 228 | |
| 229 | test("the sample desk: fifteen leads, some red, some mid-cadence; only an admin restarts it", () => { | |
| 229 | test("the sample desk: sixteen leads, some red, some mid-cadence; only an admin restarts it", () => { | |
| 230 | 230 | const sampleDb = openDb(mkdtempSync(join(tmpdir(), "app-sample-"))); |
| 231 | 231 | expect(resetSample(sampleDb, alice).ok).toBe(false); |
| 232 | expect(must(resetSample(sampleDb, root, T0)).leads).toBe(15); | |
| 232 | expect(must(resetSample(sampleDb, root, T0)).leads).toBe(16); | |
| 233 | 233 | const listed = must(listLeads(sampleDb, alice, { now: T0.getTime() })); |
| 234 | 234 | // A believable first record: 14 leads in 30 days, 57% answered or waiting under 5 minutes. |
| 235 | 235 | expect(listed.record).toMatchObject({ leads: 14, replied: 7, within_5_min_pct: 57 }); |
src/export.test.ts +1 −1
| @@ -56,7 +56,7 @@ test("the download has the header, one row per lead, and the file headers", asyn | ||
| 56 | 56 | expect(rows[0]).toEqual([...COLUMNS]); |
| 57 | 57 | const all = await (await get("/leads")).json(); |
| 58 | 58 | expect(rows.length).toBe(1 + all.leads.length); |
| 59 | expect(all.leads.length).toBe(15); | |
| 59 | expect(all.leads.length).toBe(16); | |
| 60 | 60 | expect(rows[1]!.length).toBe(COLUMNS.length); |
| 61 | 61 | expect(["yes", "no"]).toContain(rows[1]![9]!); |
| 62 | 62 | expect(["open", "qualified", "lost"]).toContain(rows[1]![4]!); |
src/finished.test.ts added +133
| @@ -0,0 +1,133 @@ | ||
| 1 | /** | |
| 2 | * A lead whose follow-ups have all gone out with no answer says so on the | |
| 3 | * desk and on its page, and one tap marks it lost (never answered). A reply, | |
| 4 | * a call or a showing keeps it from being flagged; the cadence is the lead's own. | |
| 5 | */ | |
| 6 | import { expect, test } from "bun:test"; | |
| 7 | import { mkdtempSync } from "node:fs"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { activity, addLead, bookShowing, getLead, listLeads, logCall, logLeadReply, sendReply, setState, skipFollowUp, type Result } from "./actions.ts"; | |
| 11 | import { openDb } from "./db.ts"; | |
| 12 | import { advance } from "./leads.ts"; | |
| 13 | import { deskPage } from "./pages/desk.ts"; | |
| 14 | import { leadPage } from "./pages/lead.ts"; | |
| 15 | import { FINISHED_ACTION, FINISHED_LABEL } from "./finished.ts"; | |
| 16 | import { currentAgent, storeAgent } from "./profile.ts"; | |
| 17 | import { SAMPLES, seed } from "./sample.ts"; | |
| 18 | import type { Who } from "./who.ts"; | |
| 19 | ||
| 20 | const alice: Who = { role: "user", id: "u1", name: "alice" }; | |
| 21 | const anon: Who = { role: "anon" }; | |
| 22 | const T0 = new Date("2026-03-01T10:00:00Z"); | |
| 23 | const DAY = 86_400_000; | |
| 24 | const at = (days: number) => new Date(T0.getTime() + days * DAY); | |
| 25 | const must = <T>(r: Result<T>): T => { | |
| 26 | if (!r.ok) throw new Error(r.message); | |
| 27 | return r.value; | |
| 28 | }; | |
| 29 | const fresh = () => openDb(mkdtempSync(join(tmpdir(), "app-finished-"))); | |
| 30 | let n = 0; | |
| 31 | const arrive = (db: ReturnType<typeof fresh>) => { | |
| 32 | const l = must( | |
| 33 | addLead(db, alice, { name: `Ana ${++n}`, email: `a${n}@example.com`, phone: `(206) 555-${String(1000 + n)}`, source: "website", message: "Is 12 Oak St open?", consent: false }, T0), | |
| 34 | ); | |
| 35 | must(sendReply(db, alice, { id: l.id }, T0)); | |
| 36 | return l.id; | |
| 37 | }; | |
| 38 | /** Send every follow-up on its day, as the agent approving each. */ | |
| 39 | const runCadence = (db: ReturnType<typeof fresh>, id: number, last: number) => { | |
| 40 | for (let d = 1; d <= last; d++) { | |
| 41 | advance(db, at(d).toISOString()); | |
| 42 | const lead = must(getLead(db, alice, { id })); | |
| 43 | const due = lead.messages.find((m) => m.status === "due"); | |
| 44 | if (due !== undefined) must(sendReply(db, alice, { id }, at(d))); | |
| 45 | } | |
| 46 | }; | |
| 47 | const flagged = (db: ReturnType<typeof fresh>, id: number) => must(getLead(db, alice, { id })).finished; | |
| 48 | const onDesk = (db: ReturnType<typeof fresh>, id: number) => must(listLeads(db, alice, {})).leads.find((l) => l.id === id)!.finished; | |
| 49 | ||
| 50 | test("flagged once every follow-up has gone out, not before", () => { | |
| 51 | const db = fresh(); | |
| 52 | const id = arrive(db); | |
| 53 | runCadence(db, id, 14); | |
| 54 | expect(flagged(db, id)).toBe(false); | |
| 55 | expect(onDesk(db, id)).toBe(false); | |
| 56 | runCadence(db, id, 31); | |
| 57 | expect(flagged(db, id)).toBe(true); | |
| 58 | expect(onDesk(db, id)).toBe(true); | |
| 59 | }); | |
| 60 | ||
| 61 | test("a skipped follow-up counts as finished, and a custom cadence is the lead's own", () => { | |
| 62 | const db = fresh(); | |
| 63 | storeAgent(db, { ...currentAgent(db), cadence: [2, 5] }, "test", T0.toISOString()); | |
| 64 | const id = arrive(db); | |
| 65 | const first = must(getLead(db, alice, { id })).messages.find((m) => m.day === 5)!; | |
| 66 | must(skipFollowUp(db, alice, { id, messageId: first.id }, at(1))); | |
| 67 | runCadence(db, id, 2); | |
| 68 | expect(flagged(db, id)).toBe(true); | |
| 69 | }); | |
| 70 | ||
| 71 | test("never flagged after a reply, a call or a showing", () => { | |
| 72 | const db = fresh(); | |
| 73 | const replied = arrive(db); | |
| 74 | const called = arrive(db); | |
| 75 | const showing = arrive(db); | |
| 76 | const fine = arrive(db); | |
| 77 | for (const id of [replied, called, showing, fine]) runCadence(db, id, 31); | |
| 78 | must(logLeadReply(db, alice, { id: replied, body: "Still looking!", channel: "email" }, at(32))); | |
| 79 | must(sendReply(db, alice, { id: replied }, at(32))); | |
| 80 | must(logCall(db, alice, { id: called, outcome: "no_answer" }, at(32))); | |
| 81 | must(bookShowing(db, alice, { id: showing, when: "2026-04-20T10:00", address: "12 Oak St" }, at(32))); | |
| 82 | expect(flagged(db, replied)).toBe(false); | |
| 83 | expect(flagged(db, called)).toBe(false); | |
| 84 | expect(flagged(db, showing)).toBe(false); | |
| 85 | expect(flagged(db, fine)).toBe(true); | |
| 86 | for (const id of [replied, called, showing]) expect(onDesk(db, id)).toBe(false); | |
| 87 | expect(onDesk(db, fine)).toBe(true); | |
| 88 | }); | |
| 89 | ||
| 90 | test("the desk row and the lead page say so in plain words, with the one button", () => { | |
| 91 | const db = fresh(); | |
| 92 | const id = arrive(db); | |
| 93 | runCadence(db, id, 31); | |
| 94 | const desk = must(listLeads(db, alice, {})).leads; | |
| 95 | const row = deskPage({ who: alice, agent: currentAgent(db), leads: desk, mayAdd: true, mayStar: true, mayReset: false }); | |
| 96 | expect(row).toContain(FINISHED_LABEL); | |
| 97 | expect(row).toContain(`action="/leads/${id}/state"`); | |
| 98 | expect(row).toContain('name="reason" value="never_answered"'); | |
| 99 | expect(row).toContain(FINISHED_ACTION); | |
| 100 | const noButton = deskPage({ who: anon, agent: currentAgent(db), leads: desk, mayAdd: false, mayStar: false, mayReset: false }); | |
| 101 | expect(noButton).toContain(FINISHED_LABEL); | |
| 102 | expect(noButton).not.toContain(FINISHED_ACTION); | |
| 103 | const page = leadPage({ who: alice, agent: currentAgent(db), lead: must(getLead(db, alice, { id })), mayUpdate: true, next: null, now: at(32).getTime() }); | |
| 104 | expect(page).toContain(FINISHED_LABEL); | |
| 105 | expect(page).toContain(FINISHED_ACTION); | |
| 106 | }); | |
| 107 | ||
| 108 | test("the action marks it lost, never answered, sends nothing, and Activity lists it", () => { | |
| 109 | const db = fresh(); | |
| 110 | const id = arrive(db); | |
| 111 | runCadence(db, id, 31); | |
| 112 | const sent = () => db.query<{ n: number }, []>("SELECT count(*) AS n FROM message WHERE status = 'sent'").get()!.n; | |
| 113 | const before = sent(); | |
| 114 | const lost = must(setStateFor(db, id)); | |
| 115 | expect(lost).toMatchObject({ state: "lost", lostReason: "never_answered", finished: false }); | |
| 116 | expect(sent()).toBe(before); | |
| 117 | const root: Who = { role: "admin", id: "u0", name: "root" }; | |
| 118 | const trail = must(activity(db, root, {})); | |
| 119 | expect(trail.lost).toEqual([{ reason: "never_answered", count: 1 }]); | |
| 120 | expect(JSON.stringify(trail.rows)).toContain("lost"); | |
| 121 | expect(setStateFor(db, id, anon).ok).toBe(false); | |
| 122 | }); | |
| 123 | ||
| 124 | test("the sample data holds one such lead", () => { | |
| 125 | const db = fresh(); | |
| 126 | seed(db, new Date()); | |
| 127 | const desk = must(listLeads(db, alice, {})).leads; | |
| 128 | expect(desk.filter((l) => l.finished).map((l) => l.name)).toEqual(["Ruth Okafor"]); | |
| 129 | expect(SAMPLES.some((s) => s.name === "Ruth Okafor")).toBe(true); | |
| 130 | }); | |
| 131 | ||
| 132 | const setStateFor = (db: ReturnType<typeof fresh>, id: number, who: Who = alice) => | |
| 133 | setState(db, who, { id, state: "lost", reason: "never_answered" }); |
src/finished.ts added +35
| @@ -0,0 +1,35 @@ | ||
| 1 | /** | |
| 2 | * A lead the follow-ups have finished with: every follow-up on its own | |
| 3 | * schedule has gone out (or been set aside), and nobody has answered. | |
| 4 | * Plain data in, a yes or no out; the schedule is the lead's own, so it | |
| 5 | * holds for any cadence the agent chose. | |
| 6 | */ | |
| 7 | ||
| 8 | import { CHECK_IN_DAY } from "./drafts.ts"; | |
| 9 | import type { Lead } from "./leads.ts"; | |
| 10 | ||
| 11 | /** What the desk says of such a lead, in the agent's words. */ | |
| 12 | export const FINISHED_LABEL = "Follow-ups finished — no answer"; | |
| 13 | ||
| 14 | /** What the one-tap button says. */ | |
| 15 | export const FINISHED_ACTION = "Mark lost — never answered"; | |
| 16 | ||
| 17 | /** | |
| 18 | * True when the lead is still new or contacted, was replied to, is not put | |
| 19 | * away, has no showing, has never written back or been called, and every | |
| 20 | * message it has is sent or skipped with at least one follow-up among them. | |
| 21 | * A check-in, a showing's note or an answer to a reply is not a follow-up | |
| 22 | * on the cadence, so a lead with one is never flagged. | |
| 23 | */ | |
| 24 | export function followUpsFinished( | |
| 25 | lead: Pick<Lead, "state" | "replied_at" | "back_on">, | |
| 26 | messages: readonly { readonly day: number; readonly status: string }[], | |
| 27 | heardFrom: boolean, | |
| 28 | showing: boolean, | |
| 29 | ): boolean { | |
| 30 | if (lead.state !== "new" && lead.state !== "contacted") return false; | |
| 31 | if (lead.replied_at === null || lead.back_on !== null || heardFrom || showing) return false; | |
| 32 | if (!messages.every((m) => m.status === "sent" || m.status === "skipped")) return false; | |
| 33 | if (messages.some((m) => m.day >= CHECK_IN_DAY)) return false; | |
| 34 | return messages.some((m) => m.day > 0); | |
| 35 | } |
src/leads.ts +46 −9
| @@ -38,6 +38,7 @@ import { between, GREEN_MS } from "./clock.ts"; | ||
| 38 | 38 | import type { Agent } from "./env.ts"; |
| 39 | 39 | import { isQuiet, nextOpening } from "./quiet.ts"; |
| 40 | 40 | import { type LostReason } from "./lost.ts"; |
| 41 | import { followUpsFinished } from "./finished.ts"; | |
| 41 | 42 | import { morningOn } from "./putaway.ts"; |
| 42 | 43 | import { clockTime, dayName, holdUntil, morningAfter, morningBefore, type Showing } from "./showings.ts"; |
| 43 | 44 | |
| @@ -114,6 +115,8 @@ export interface LeadDetail extends Lead { | ||
| 114 | 115 | readonly calls: readonly Call[]; |
| 115 | 116 | /** The showing booked on this lead; null when none. */ |
| 116 | 117 | readonly showing: Showing | null; |
| 118 | /** Every follow-up has gone out or been set aside and no one answered: the agent may close it out. */ | |
| 119 | readonly finished: boolean; | |
| 117 | 120 | } |
| 118 | 121 | |
| 119 | 122 | /** When the lead began to wait on our answer to what they wrote back; null when no answer is owed. */ |
| @@ -130,6 +133,8 @@ export interface DeskLead extends Lead { | ||
| 130 | 133 | readonly goes_at: string | null; |
| 131 | 134 | /** The showing booked on this lead, if one is. */ |
| 132 | 135 | readonly showing: Pick<Showing, "at" | "address" | "hold_until"> | null; |
| 136 | /** Every follow-up has gone out or been set aside and no one answered. */ | |
| 137 | readonly finished: boolean; | |
| 133 | 138 | } |
| 134 | 139 | |
| 135 | 140 | /** |
| @@ -288,15 +293,19 @@ export const showingsAhead = (db: Database, now: number): Ahead[] => | ||
| 288 | 293 | |
| 289 | 294 | export function detail(db: Database, id: number): LeadDetail | null { |
| 290 | 295 | const found = findLead(db, id); |
| 291 | return found === null | |
| 292 | ? null | |
| 293 | : { | |
| 294 | ...found, | |
| 295 | messages: messagesOf(db, id), | |
| 296 | replies: repliesOf(db, id), | |
| 297 | calls: callsOf(db, id), | |
| 298 | showing: showingOf(db, id), | |
| 299 | }; | |
| 296 | if (found === null) return null; | |
| 297 | const messages = messagesOf(db, id); | |
| 298 | const replies = repliesOf(db, id); | |
| 299 | const calls = callsOf(db, id); | |
| 300 | const showing = showingOf(db, id); | |
| 301 | return { | |
| 302 | ...found, | |
| 303 | messages, | |
| 304 | replies, | |
| 305 | calls, | |
| 306 | showing, | |
| 307 | finished: followUpsFinished(found, messages, replies.length + calls.length > 0, showing !== null), | |
| 308 | }; | |
| 300 | 309 | } |
| 301 | 310 | |
| 302 | 311 | export const MAX_QUERY = 80; |
| @@ -341,6 +350,7 @@ const DIGITS = ["(", ")", "-", " ", ".", "+"].reduce( | ||
| 341 | 350 | * note holds it, or whose phone holds its digits ("555 0101" finds "(206) 555-0101"). |
| 342 | 351 | */ |
| 343 | 352 | export function desk(db: Database, limit: number, q = ""): DeskLead[] { |
| 353 | const finishedIds = finishedLeads(db); | |
| 344 | 354 | const digits = /^[\d\s()+.\-]+$/.test(q) ? q.replace(/\D/g, "") : ""; |
| 345 | 355 | return db |
| 346 | 356 | .query< |
| @@ -374,6 +384,7 @@ export function desk(db: Database, limit: number, q = ""): DeskLead[] { | ||
| 374 | 384 | .all(limit, q === "" ? "" : likeOf(q), digits === "" ? "" : `%${digits}%`) |
| 375 | 385 | .map(({ ready_id, ready_day, ready_since, next_at, goes_at, show_at, show_address, show_hold, ...row }) => ({ |
| 376 | 386 | ...lead(row), |
| 387 | finished: finishedIds.has(row.id), | |
| 377 | 388 | ready: |
| 378 | 389 | ready_id === null || ready_day === null || ready_since === null |
| 379 | 390 | ? null |
| @@ -387,6 +398,32 @@ export function desk(db: Database, limit: number, q = ""): DeskLead[] { | ||
| 387 | 398 | })); |
| 388 | 399 | } |
| 389 | 400 | |
| 401 | /** The ids of leads whose follow-ups have finished with no answer (see `followUpsFinished`), for the whole desk at once. */ | |
| 402 | function finishedLeads(db: Database): Set<number> { | |
| 403 | const rows = db | |
| 404 | .query< | |
| 405 | Pick<Lead, "state" | "replied_at" | "back_on"> & { id: number; day: number | null; status: string | null; heard: number; booked: number }, | |
| 406 | [] | |
| 407 | >( | |
| 408 | `SELECT lead.id AS id, lead.state AS state, lead.replied_at AS replied_at, lead.back_on AS back_on, | |
| 409 | message.day AS day, message.status AS status, | |
| 410 | (EXISTS (SELECT 1 FROM inbound WHERE lead_id = lead.id) OR EXISTS (SELECT 1 FROM phone_call WHERE lead_id = lead.id)) AS heard, | |
| 411 | EXISTS (SELECT 1 FROM showing WHERE lead_id = lead.id) AS booked | |
| 412 | FROM lead LEFT JOIN message ON message.lead_id = lead.id | |
| 413 | WHERE lead.state IN ('new', 'contacted') AND lead.replied_at IS NOT NULL`, | |
| 414 | ) | |
| 415 | .all(); | |
| 416 | const byLead = new Map<number, typeof rows>(); | |
| 417 | for (const r of rows) byLead.set(r.id, [...(byLead.get(r.id) ?? []), r]); | |
| 418 | const found = new Set<number>(); | |
| 419 | for (const [id, mine] of byLead) { | |
| 420 | const first = mine[0]!; | |
| 421 | const messages = mine.flatMap((r) => (r.day === null || r.status === null ? [] : [{ day: r.day, status: r.status }])); | |
| 422 | if (followUpsFinished(first, messages, first.heard === 1, first.booked === 1)) found.add(id); | |
| 423 | } | |
| 424 | return found; | |
| 425 | } | |
| 426 | ||
| 390 | 427 | /** The lead that needs the agent next, and since when it has. */ |
| 391 | 428 | export interface NextLead { |
| 392 | 429 | readonly id: number; |
src/pages/desk.ts +10 −1
| @@ -8,6 +8,7 @@ import { deskTitle, layout } from "./layout.ts"; | ||
| 8 | 8 | import { escape } from "../http.ts"; |
| 9 | 9 | import { recordLine, sourceLine } from "../clock.ts"; |
| 10 | 10 | import { isAfterShowing, isBeforeShowing, isAnswer, isCheckIn } from "../drafts.ts"; |
| 11 | import { FINISHED_ACTION, FINISHED_LABEL } from "../finished.ts"; | |
| 11 | 12 | import { dateName } from "../putaway.ts"; |
| 12 | 13 | import { goesLabel, RECORD_NOTE } from "../quiet.ts"; |
| 13 | 14 | import { MAX_ADDRESS, MAX_LISTED, showingWhen } from "../showings.ts"; |
| @@ -208,9 +209,17 @@ function status(lead: DeskLead, now: number, zone: string): string { | ||
| 208 | 209 | return `<span class="status">Put away until ${escape(dateName(lead.back_on))}</span>`; |
| 209 | 210 | if (lead.next_at !== null) |
| 210 | 211 | return `<span class="status">Next follow-up ${escape(day(held(lead, lead.next_at), zone))}</span>`; |
| 212 | if (lead.finished) return `<span class="status" data-finished>${FINISHED_LABEL}</span>`; | |
| 211 | 213 | return `<span class="status">Follow-ups done</span>`; |
| 212 | 214 | } |
| 213 | 215 | |
| 216 | /** The one tap that closes a finished lead out: the same lost-with-a-reason post as the lead's page; nothing is sent. */ | |
| 217 | const closeOut = (lead: DeskLead, may: boolean): string => | |
| 218 | !lead.finished || !may | |
| 219 | ? "" | |
| 220 | : ` | |
| 221 | <form class="close-out" method="post" action="/leads/${lead.id}/state"><input type="hidden" name="state" value="lost"><input type="hidden" name="reason" value="never_answered"><button class="button button-quiet">${FINISHED_ACTION}</button></form>`; | |
| 222 | ||
| 214 | 223 | const row = (lead: DeskLead, now: number, zone: string, back?: string): string => `<li class="lead-item"> |
| 215 | 224 | <a class="lead-row" href="/leads/${lead.id}"${lead.state === "lost" ? " data-closed" : ""}> |
| 216 | 225 | <span class="lead-main"> |
| @@ -222,7 +231,7 @@ const row = (lead: DeskLead, now: number, zone: string, back?: string): string = | ||
| 222 | 231 | </span> |
| 223 | 232 | ${clock(lead, now, lead.ready !== null && isAnswer(lead.ready.day) ? lead.ready.since : null)} |
| 224 | 233 | </a>${back === undefined ? "" : ` |
| 225 | ${starForm(lead, back)}`} | |
| 234 | ${starForm(lead, back)}`}${closeOut(lead, back !== undefined)} | |
| 226 | 235 | </li>`; |
| 227 | 236 | |
| 228 | 237 | const pasteForm = `<details class="card add"> |
src/pages/lead.ts +10 −2
| @@ -17,6 +17,7 @@ import { answerSince, MAX_INBOUND, MAX_LEAD_NOTE, type LeadDetail, type Message, | ||
| 17 | 17 | import type { Agent } from "../env.ts"; |
| 18 | 18 | import type { Who } from "../who.ts"; |
| 19 | 19 | import { layout } from "./layout.ts"; |
| 20 | import { FINISHED_ACTION, FINISHED_LABEL } from "../finished.ts"; | |
| 20 | 21 | import { LOST_REASONS, REASON_LABEL, lostSaid } from "../lost.ts"; |
| 21 | 22 | import { clock, consent, day, source, starForm, STATE_LABEL, when } from "./parts.ts"; |
| 22 | 23 | |
| @@ -90,7 +91,9 @@ export function leadPage(input: { | ||
| 90 | 91 | : `Marked ${STATE_LABEL[lead.state].toLowerCase()}: out of the follow-up plan.` |
| 91 | 92 | : lead.messages.some((m) => m.status === "scheduled") |
| 92 | 93 | ? "The next follow-up is drafted below and comes due on its day." |
| 93 | : "Every follow-up has gone out." | |
| 94 | : lead.finished | |
| 95 | ? `${FINISHED_LABEL}. Every follow-up has gone out and they have not answered.` | |
| 96 | : "Every follow-up has gone out." | |
| 94 | 97 | }</p></div>` |
| 95 | 98 | : `<div class="pane ours ready"> |
| 96 | 99 | <h2>${titleOf(ready)} <span class="muted">· by ${CHANNEL[ready.channel]}</span></h2> |
| @@ -192,7 +195,12 @@ export function leadPage(input: { | ||
| 192 | 195 | |
| 193 | 196 | const states = |
| 194 | 197 | mayUpdate && !closed |
| 195 | ? `<section class="states"> | |
| 198 | ? `<section class="states">${ | |
| 199 | lead.finished | |
| 200 | ? ` | |
| 201 | <form class="close-out" method="post" action="${path}/state"><input type="hidden" name="state" value="lost"><input type="hidden" name="reason" value="never_answered"><button class="button">${FINISHED_ACTION}</button></form>` | |
| 202 | : "" | |
| 203 | } | |
| 196 | 204 | <form method="post" action="${path}/state"><input type="hidden" name="state" value="qualified"><button class="button button-quiet">Mark qualified</button></form> |
| 197 | 205 | <form method="post" action="${path}/state"><input type="hidden" name="state" value="lost"> |
| 198 | 206 | <label>Why? <select name="reason" required>${LOST_REASONS.map((r) => `<option value="${r}">${escape(REASON_LABEL[r])}</option>`).join("")}</select></label> |
src/sample.ts +1
| @@ -86,6 +86,7 @@ export const SAMPLES: readonly Sample[] = [ | ||
| 86 | 86 | person("Owen Hart", "zillow", false, "Is 55 Cedar Ln still on the market? We'd like a second showing.", { ago: 9 * D, answeredIn: 2 * M + 40 * S, touched: [1, 3], closed: { state: "lost", reason: "bought_elsewhere" } }), |
| 87 | 87 | person("Nadia Petrov", "website", true, "We might sell, but not before our kids finish school in two years. What should we do now?", { ago: 12 * D, answeredIn: 3 * M + 5 * S, touched: [1, 3], closed: { state: "lost", reason: "not_ready" } }), |
| 88 | 88 | person("Carl Dunn", "referral", false, "A friend gave me your name. Call me about listing the duplex.", { ago: 20 * D, answeredIn: 5 * M, touched: [1, 3, 7], closed: { state: "lost", reason: "never_answered" } }), |
| 89 | person("Ruth Okafor", "website", false, "Looking at starter homes under $400k. Can you send a few options?", { ago: 34 * D, answeredIn: 2 * M + 10 * S, touched: [1, 3, 7, 14, 30] }), | |
| 89 | 90 | ]; |
| 90 | 91 | |
| 91 | 92 | /** Lay the samples out as of `now`. Returns how many. */ |
src/search.test.ts +2 −2
| @@ -37,8 +37,8 @@ test("a name, an email or a phone finds the lead, in any case", () => { | ||
| 37 | 37 | }); |
| 38 | 38 | |
| 39 | 39 | test("no search is the whole desk", () => { |
| 40 | expect(names({}).length).toBe(15); | |
| 41 | expect(names({ q: "" }).length).toBe(15); | |
| 40 | expect(names({}).length).toBe(16); | |
| 41 | expect(names({ q: "" }).length).toBe(16); | |
| 42 | 42 | }); |
| 43 | 43 | |
| 44 | 44 | test("a search combines with the view", () => { |
src/terminal.test.ts +26 −1
| @@ -412,7 +412,7 @@ test("x on the desk shows the leads as CSV, for those who may list; esc goes bac | ||
| 412 | 412 | const t = terminal(db, alice); |
| 413 | 413 | t.key("x"); |
| 414 | 414 | const screen = read(t); |
| 415 | expect(screen).toContain("15 leads as CSV"); | |
| 415 | expect(screen).toContain("16 leads as CSV"); | |
| 416 | 416 | expect(screen).toContain("name,email,phone,source,status"); |
| 417 | 417 | expect(screen).toContain("Maria Gonzalez"); |
| 418 | 418 | t.key("\x1b"); |
| @@ -546,3 +546,28 @@ test("the terminal shows the follow-up days, an admin edits them, a bad list cha | ||
| 546 | 546 | expect(read(user)).not.toContain("editing"); |
| 547 | 547 | expect(days()).toBe("[2,5,10]"); |
| 548 | 548 | }); |
| 549 | ||
| 550 | test("a lead whose follow-ups finished says so, and m marks it lost, never answered; a guest cannot", () => { | |
| 551 | const db = fresh(); | |
| 552 | const t = terminal(db, alice); | |
| 553 | expect(read(t)).toContain("Follow-ups finished — no answer"); | |
| 554 | t.key("/"); | |
| 555 | type(t, "Ruth"); | |
| 556 | t.key("\r"); | |
| 557 | t.key("\r"); | |
| 558 | const screen = read(t); | |
| 559 | expect(screen).toContain("Follow-ups finished — no answer"); | |
| 560 | expect(screen).toContain("m mark lost — never answered"); | |
| 561 | const id = (listLeads(db, alice) as { ok: true; value: { leads: { id: number; name: string }[] } }).value.leads.find((l) => l.name === "Ruth Okafor")!.id; | |
| 562 | const sent = () => db.query<{ n: number }, []>("SELECT count(*) AS n FROM message WHERE status = 'sent'").get()!.n; | |
| 563 | const before = sent(); | |
| 564 | const stranger = terminal(db, { role: "anon" }); | |
| 565 | stranger.key("m"); | |
| 566 | expect(getLead(db, alice, { id })).toMatchObject({ value: { state: "contacted" } }); | |
| 567 | t.key("m"); | |
| 568 | expect(read(t)).toContain("Ruth Okafor: lost, never answered."); | |
| 569 | expect(getLead(db, alice, { id })).toMatchObject({ value: { state: "lost", lostReason: "never_answered" } }); | |
| 570 | expect(sent()).toBe(before); | |
| 571 | const guest = terminal(db, { role: "anon" }); | |
| 572 | expect(read(guest)).not.toContain("Follow-ups finished"); | |
| 573 | }); |
src/terminal.ts +10 −3
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | * Screens: |
| 8 | 8 | * desk j/k move · enter open · * star · f view (needs/open/closed/all) · / find by name, email, phone or note · n log a lead · v paste a lead email · o open house sign-ins · i new sample inquiry · p profile · a activity (admin) · R restart samples (admin) · esc quit |
| 9 | 9 | * lead s approve and send · e edit, then send · w they wrote back · ] next lead that needs you · |
| 10 | * q qualified · x lost · t asked to stop texts · D remove (admin) · esc back | |
| 10 | * q qualified · x lost · m lost, never answered (follow-ups finished) · t asked to stop texts · D remove (admin) · esc back | |
| 11 | 11 | * edit type; enter is a new line · ctrl-d approve and send · esc cancel |
| 12 | 12 | * wrote type what they wrote · ctrl-t text/email (text only with consent) · ctrl-d record it and draft the answer · esc cancel |
| 13 | 13 | * paste paste the notification email · ctrl-d read it, then check each field in the add screen (consent starts as n) · esc cancel |
| @@ -69,6 +69,7 @@ import { goesLabel, isQuiet, nextOpening, RECORD_NOTE } from "./quiet.ts"; | ||
| 69 | 69 | import { said as saidOf } from "./sentences.ts"; |
| 70 | 70 | import { SOURCE_LABEL, SOURCES, channelFor, dayLabel, isAfterShowing, isAnswer, isBeforeShowing, isCheckIn, planLabel, type Channel, type Source } from "./drafts.ts"; |
| 71 | 71 | import { ssh, title, where } from "./env.ts"; |
| 72 | import { FINISHED_ACTION, FINISHED_LABEL } from "./finished.ts"; | |
| 72 | 73 | import { LOST_REASONS, REASON_LABEL, lostSaid } from "./lost.ts"; |
| 73 | 74 | import { answerSince, CLOSED, MAX_QUERY, VIEWS, queryOf, type DeskLead, type LeadDetail, type Message, type View as DeskView } from "./leads.ts"; |
| 74 | 75 | import { when } from "./pages/parts.ts"; |
| @@ -288,7 +289,7 @@ export function terminal( | ||
| 288 | 289 | l.goes_at !== null |
| 289 | 290 | ? dim(goesLabel(l.goes_at, now(), zone)) |
| 290 | 291 | : l.ready === null |
| 291 | ? dim(l.state === "qualified" || l.state === "lost" ? l.state : l.back_on !== null ? `back on ${dateName(l.back_on)}` : "") | |
| 292 | ? dim(l.state === "qualified" || l.state === "lost" ? l.state : l.back_on !== null ? `back on ${dateName(l.back_on)}` : l.finished ? FINISHED_LABEL : "") | |
| 292 | 293 | : l.ready.day === 0 |
| 293 | 294 | ? "reply drafted" |
| 294 | 295 | : isAnswer(l.ready.day) |
| @@ -387,7 +388,9 @@ export function terminal( | ||
| 387 | 388 | ? `Marked ${l.state}${l.state === "lost" ? ` — ${lostSaid(l)}` : ""}: out of the follow-up plan.` |
| 388 | 389 | : next !== undefined |
| 389 | 390 | ? `Nothing to send now. ${titleOf(next)} comes due ${next.due_at.slice(0, 10)}.` |
| 390 | : "Every follow-up has gone out.", | |
| 391 | : l.finished | |
| 392 | ? `${FINISHED_LABEL}. Every follow-up has gone out and they have not answered.` | |
| 393 | : "Every follow-up has gone out.", | |
| 391 | 394 | ), |
| 392 | 395 | ); |
| 393 | 396 | } else { |
| @@ -452,6 +455,7 @@ export function terminal( | ||
| 452 | 455 | ...(l.state === "qualified" || l.state === "lost" |
| 453 | 456 | ? ["o put back in follow-ups"] |
| 454 | 457 | : ["q qualified", "x lost"]), |
| 458 | ...(l.finished && mayEdit(l) ? [`m ${FINISHED_ACTION.toLowerCase()}`] : []), | |
| 455 | 459 | ...(mayEdit(l) ? ["d fix details"] : []), |
| 456 | 460 | ...(mayNote(l) ? [l.note === "" ? "n add a note" : "n edit your note"] : []), |
| 457 | 461 | ...(mayStar(l) ? [l.starred ? "* take the star off" : "* star"] : []), |
| @@ -860,6 +864,9 @@ export function terminal( | ||
| 860 | 864 | } else if (input === "q") { |
| 861 | 865 | const marked = setState(db, me, { id, state: "qualified" }); |
| 862 | 866 | said = marked.ok ? `${l.name}: ${marked.value.state}.` : marked.message; |
| 867 | } else if (input === "m" && l.finished) { | |
| 868 | const marked = setState(db, me, { id, state: "lost", reason: "never_answered" }); | |
| 869 | said = marked.ok ? `${marked.value.name}: lost, ${REASON_LABEL.never_answered}.` : marked.message; | |
| 863 | 870 | } else if (input === "x" && !CLOSED.includes(l.state)) |
| 864 | 871 | view = { name: "lost", id }; |
| 865 | 872 | else if (input === "c" && l.phone !== "") |
static/app.css +4
| @@ -230,6 +230,10 @@ footer { | ||
| 230 | 230 | .lead-row:hover { |
| 231 | 231 | background: var(); |
| 232 | 232 | } |
| 233 | .close-out { | |
| 234 | grid-column: 1 / -1; | |
| 235 | padding: 0 var() var(); | |
| 236 | } | |
| 233 | 237 | .lead-row[data-closed] { |
| 234 | 238 | opacity: 0.72; |
| 235 | 239 | } |
new above
offline