Public: anyone can read this; the crew can change it.
A reminder to a party with no email or phone on file lets the agent add one right on the review page, so Send reaches them #116
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/114-a-reminder-to-a-party-with-no-email-or-p → main 2 commits fork 2 threads · 2 unresolved
5 files
changed +143
−13
README.md +5 −1
| @@ -61,7 +61,11 @@ Signed out, `/` shows what deal-clock does, three short points, a still picture | ||
| 61 | 61 | 3. **Read and edit a reminder.** In the sheet, tap a party's reminder. You |
| 62 | 62 | see the words it would send, in a subject field and a message field, |
| 63 | 63 | already filled in. Change the message; the subject can run to 150 |
| 64 | characters and the message to 2000. | |
| 64 | characters and the message to 2000. On the review page, a party with no | |
| 65 | email or phone shows an **Email or phone** field and a **Save contact** | |
| 66 | button; save it and you land back on the same draft with the contact | |
| 67 | shown and your edited words kept. Send without a contact still records | |
| 68 | your approval, and your Mail then opens with no recipient. | |
| 65 | 69 | 4. **Send it.** Tap Send. Send records your approval and opens your own |
| 66 | 70 | Mail or Messages with the words: nothing is sent by the app itself. A |
| 67 | 71 | short notice at the top of the page reads "Reminder sent." with one link, |
src/deals.ts +3 −1
| @@ -199,6 +199,8 @@ export function message(value: unknown, min: number, max: number): string | unde | ||
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | export const SUBJECT_MAX = 150; |
| 202 | /** The longest a party's contact may be. */ | |
| 203 | export const CONTACT_MAX = 120; | |
| 202 | 204 | export const REASON_MAX = 200; |
| 203 | 205 | /** Why a move is recorded when the agent takes the next-business-day suggestion. */ |
| 204 | 206 | export const ROLL_REASON = "Rolled to the next business day"; |
| @@ -938,7 +940,7 @@ function partyText(input: { name: unknown; contact?: unknown }): Result<{ name: | ||
| 938 | 940 | const name = line(input.name, 1, 100); |
| 939 | 941 | if (name === undefined) return fail("invalid", "A name is 1 to 100 characters."); |
| 940 | 942 | const contact = |
| 941 | input.contact === undefined || input.contact === "" ? "" : line(input.contact, 1, 120); | |
| 943 | input.contact === undefined || input.contact === "" ? "" : line(input.contact, 1, CONTACT_MAX); | |
| 942 | 944 | if (contact === undefined) return fail("invalid", "A contact is up to 120 characters."); |
| 943 | 945 | return ok({ name, contact }); |
| 944 | 946 | } |
src/pages/review.ts +21 −4
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | import type { Agent } from "../reminders.ts"; |
| 10 | import { BODY_MAX, REASON_MAX, SUBJECT_MAX } from "../deals.ts"; | |
| 10 | import { BODY_MAX, CONTACT_MAX, REASON_MAX, SUBJECT_MAX } from "../deals.ts"; | |
| 11 | 11 | import { spoken } from "../dates.ts"; |
| 12 | 12 | import { PARTY_LABEL } from "../deadlines.ts"; |
| 13 | 13 | import { escape } from "../http.ts"; |
| @@ -29,7 +29,7 @@ export function reviewHref(q: string, at: number, done: number): string { | ||
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** Which field of the form a refusal is about. */ |
| 32 | export type ReviewField = "subject" | "body" | "reason"; | |
| 32 | export type ReviewField = "subject" | "body" | "reason" | "contact"; | |
| 33 | 33 | |
| 34 | 34 | export interface ReviewError { |
| 35 | 35 | readonly field: ReviewField; |
| @@ -41,9 +41,11 @@ export interface Typed { | ||
| 41 | 41 | readonly subject: string; |
| 42 | 42 | readonly body: string; |
| 43 | 43 | readonly reason: string; |
| 44 | /** The contact typed into the Save contact field; empty when there was none. */ | |
| 45 | readonly contact?: string | undefined; | |
| 44 | 46 | } |
| 45 | 47 | |
| 46 | const FIELD_LABEL: Readonly<Record<ReviewField, string>> = { subject: "Subject", body: "Message", reason: "Why not" }; | |
| 48 | const FIELD_LABEL: Readonly<Record<ReviewField, string>> = { subject: "Subject", body: "Message", reason: "Why not", contact: "Email or phone" }; | |
| 47 | 49 | |
| 48 | 50 | export function reviewPage(input: { |
| 49 | 51 | who: Who; |
| @@ -73,6 +75,18 @@ export function reviewPage(input: { | ||
| 73 | 75 | return layout({ body, who, agent, waiting: input.waiting, path: REVIEW_PATH, heading: "Review today's reminders", notice: input.notice, open: input.open, live: false }); |
| 74 | 76 | } |
| 75 | 77 | |
| 78 | /** | |
| 79 | * The Save contact field for a party with nothing on file. It sits inside the | |
| 80 | * draft's form, first, so the edited words travel with it and Enter in it | |
| 81 | * saves the contact; its button posts to the contact action instead of Send. The form opens with a | |
| 82 | * hidden Send button so Enter anywhere in it still sends. | |
| 83 | */ | |
| 84 | function contactField(value: string, problem: string, invalid: string): string { | |
| 85 | return `${problem} | |
| 86 | <label>Email or phone<input class="input" name="contact" value="${escape(value)}" maxlength="${CONTACT_MAX}" autocomplete="off"${invalid}></label> | |
| 87 | <button class="button button-quiet" formaction="${REVIEW_PATH}/contact">Save contact</button>`; | |
| 88 | } | |
| 89 | ||
| 76 | 90 | function form( |
| 77 | 91 | draft: Draft, |
| 78 | 92 | s: { q: string; at: number; done: number; position: number; total: number; error: ReviewError | undefined; typed: Typed | undefined }, |
| @@ -90,13 +104,16 @@ function form( | ||
| 90 | 104 | <h1>Review today's reminders</h1> |
| 91 | 105 | <p><a href="/deals/${draft.deal_id}">${escape(draft.address)}</a></p> |
| 92 | 106 | <p><b>${escape(draft.label)}</b> <span class="muted">· ${escape(spoken(draft.due))} · ${escape(momentLabel(draft.moment, draft.lead_days))}${draft.held === null ? "" : ` · ${escape(heldFrom(draft.held))}`}</span></p> |
| 93 | <p>To <b>${escape(draft.party_name)}</b> <span class="muted">· ${escape(PARTY_LABEL[draft.party_role])} · ${escape(draft.contact === "" ? "no contact on file" : draft.contact)}</span></p> | |
| 107 | <p>To <b>${escape(draft.party_name)}</b> <span class="muted">· ${escape(PARTY_LABEL[draft.party_role])}${draft.contact === "" ? "" : ` · ${escape(draft.contact)}`}</span></p> | |
| 94 | 108 | <form class="move" method="post" action="${REVIEW_PATH}/send">${hidden(keys)} |
| 109 | ${draft.contact === "" ? '<button class="button" hidden tabindex="-1" aria-hidden="true">Send</button>' : ""} | |
| 110 | ${draft.contact === "" ? contactField(typed.contact ?? "", problem("contact"), invalid("contact")) : ""} | |
| 95 | 111 | ${problem("subject")} |
| 96 | 112 | <label>Subject<input class="input" name="subject" value="${escape(typed.subject)}" maxlength="${SUBJECT_MAX}" required${invalid("subject")}></label> |
| 97 | 113 | ${problem("body")} |
| 98 | 114 | <label>Message<textarea class="input" name="body" rows="9" maxlength="${BODY_MAX}" required${invalid("body")}>${escape(typed.body)}</textarea></label> |
| 99 | 115 | <button class="button">Send</button> |
| 116 | ${draft.contact === "" ? '<span class="muted small">No contact on file: Send records the approval and your Mail opens with no recipient.</span>' : ""} | |
| 100 | 117 | ${draft.moment === "status" ? "" : `<button class="button button-quiet" formaction="${REVIEW_PATH}/hold">Tomorrow</button>`} |
| 101 | 118 | </form> |
| 102 | 119 | <form class="move" method="post" action="${REVIEW_PATH}/decline">${hidden(keys)} |
src/review.test.ts +75
| @@ -117,3 +117,78 @@ test("anon is asked to sign in, and a cross-origin or anon POST is refused", asy | ||
| 117 | 117 | expect([401, 403]).toContain(anon.status); |
| 118 | 118 | expect(shown(await get("/reminders/today")).deadline).toBe(one.deadline); |
| 119 | 119 | }); |
| 120 | ||
| 121 | // ---- a party with no contact: add one in place ---- | |
| 122 | ||
| 123 | const dayOffset = (n: number): string => new Date(Date.now() + n * 86_400_000).toISOString().slice(0, 10); | |
| 124 | const jsonHeaders = { ...alice, "content-type": "application/json" }; | |
| 125 | ||
| 126 | /** Open a deal whose parties have no contact, and walk the review pages to its first draft. */ | |
| 127 | const bareDraft = async (address: string) => { | |
| 128 | const made = await fetch(base + "/api/deals", { method: "POST", headers: jsonHeaders, body: JSON.stringify({ address, buyer: "Ann Buyer", seller: "Sam Seller", contract_date: dayOffset(-5), closing_date: dayOffset(40), inspection: 8 }) }); | |
| 129 | expect(made.status).toBe(201); | |
| 130 | for (let at = 0; at < 40; at++) { | |
| 131 | const page = await get(`/reminders/today?at=${at}`); | |
| 132 | if (page.includes(address)) return { page, at }; | |
| 133 | } | |
| 134 | throw new Error("draft not found"); | |
| 135 | }; | |
| 136 | ||
| 137 | test("the contact field shows only while the party has no contact", async () => { | |
| 138 | const { page } = await bareDraft("31 Bare Contact Rd"); | |
| 139 | expect(page).toContain('name="contact"'); | |
| 140 | expect(page).toContain("Save contact"); | |
| 141 | expect(page.indexOf("<button class=\"button\" hidden")).toBeGreaterThan(-1); | |
| 142 | expect(page.indexOf("<button class=\"button\" hidden")).toBeLessThan(page.indexOf("Save contact")); | |
| 143 | expect(page).not.toContain('name="name"'); | |
| 144 | expect(page).toContain("your Mail opens with no recipient"); | |
| 145 | }); | |
| 146 | ||
| 147 | test("Save contact fills it in, returns to the same draft, and keeps the edited words", async () => { | |
| 148 | const { page, at } = await bareDraft("32 Save Contact Rd"); | |
| 149 | const s = shown(page); | |
| 150 | const res = await post("/reminders/today/contact", { ...keys(s), at: String(at), contact: "[email protected]", subject: "My subject", body: "My words" }); | |
| 151 | expect(res.status).toBe(200); | |
| 152 | const after = await res.text(); | |
| 153 | expect(shown(after).deadline).toBe(s.deadline); | |
| 154 | expect(shown(after).party).toBe(s.party); | |
| 155 | expect(after).toContain("[email protected]"); | |
| 156 | expect(after).not.toContain("Save contact"); | |
| 157 | expect(after).toContain("My subject"); | |
| 158 | expect(after).toContain("My words"); | |
| 159 | expect(await get(`/reminders/today?at=${at}`)).toContain("[email protected]"); | |
| 160 | }); | |
| 161 | ||
| 162 | test("bad contact input is a 422 that keeps what was typed and the edited words", async () => { | |
| 163 | const { page, at } = await bareDraft("33 Bad Contact Rd"); | |
| 164 | const s = shown(page); | |
| 165 | const long = "x".repeat(121); | |
| 166 | const res = await post("/reminders/today/contact", { ...keys(s), at: String(at), contact: long, subject: "Kept subject", body: "Kept body" }); | |
| 167 | expect(res.status).toBe(422); | |
| 168 | const bad = await res.text(); | |
| 169 | expect(bad).toContain("<b>Email or phone:</b>"); | |
| 170 | expect(bad).toContain(long); | |
| 171 | expect(bad).toContain("Kept subject"); | |
| 172 | expect(bad).toContain("Kept body"); | |
| 173 | const empty = await post("/reminders/today/contact", { ...keys(s), at: String(at), contact: " ", subject: "Kept subject", body: "Kept body" }); | |
| 174 | expect(empty.status).toBe(422); | |
| 175 | const anon = await post("/reminders/today/contact", { ...keys(s), contact: "[email protected]" }, {}); | |
| 176 | expect([401, 403]).toContain(anon.status); | |
| 177 | }); | |
| 178 | ||
| 179 | test("Send on a draft with no contact still records the approval", async () => { | |
| 180 | const { page, at } = await bareDraft("34 Send Bare Rd"); | |
| 181 | const s = shown(page); | |
| 182 | const res = await post("/reminders/today/send", { ...keys(s), at: String(at), subject: "Hello", body: "There" }); | |
| 183 | expect(res.status).toBe(303); | |
| 184 | const deals = (await (await fetch(base + "/api/deals", { headers: alice })).json()) as { address: string; sent: { subject: string; body: string }[] }[]; | |
| 185 | expect(deals.find((d) => d.address === "34 Send Bare Rd")!.sent.map((m) => m.subject)).toContain("Hello"); | |
| 186 | }); | |
| 187 | ||
| 188 | test("a stale or tampered name posted with the contact renames no one", async () => { | |
| 189 | const { page, at } = await bareDraft("35 Name Rd"); | |
| 190 | const s = shown(page); | |
| 191 | const res = await post("/reminders/today/contact", { ...keys(s), at: String(at), name: "Mallory", contact: "[email protected]" }); | |
| 192 | expect(res.status).toBe(200); | |
| 193 | expect(await res.text()).not.toContain("Mallory"); | |
| 194 | }); |
src/routes.ts +39 −7
| @@ -88,7 +88,7 @@ import { dealPage, newDealPage } from "./pages/deal.ts"; | ||
| 88 | 88 | import { missingPage } from "./pages/missing.ts"; |
| 89 | 89 | import { refusedPage } from "./pages/refused.ts"; |
| 90 | 90 | import { people } from "./people.ts"; |
| 91 | import { reviewHref, reviewPage, type ReviewField } from "./pages/review.ts"; | |
| 91 | import { reviewHref, reviewPage, type ReviewError, type ReviewField } from "./pages/review.ts"; | |
| 92 | 92 | import { peoplePage } from "./pages/people.ts"; |
| 93 | 93 | import { activityPage } from "./pages/activity.ts"; |
| 94 | 94 | import { ACTIVITY_PAGE } from "./activity.ts"; |
| @@ -506,16 +506,43 @@ async function reviewed(c: Context, act: (f: Record<string, string>) => Result<{ | ||
| 506 | 506 | if (result.ok) return back(said, reviewHref(q, at, settled + 1), said === SENT ? result.value.id : undefined); |
| 507 | 507 | if (result.error === "signin_required" || result.error === "forbidden") |
| 508 | 508 | return html(refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path: reviewHref(q, at, settled), heading: "Review today's reminders", error: result.error, message: result.message }), STATUS[result.error]); |
| 509 | const shown = sameDraft(c, f, q, settled, result.error === "invalid" ? { field: fieldOf(result.message), message: result.message } : undefined); | |
| 510 | if (result.error !== "invalid" || shown === undefined) return back(result.message, reviewHref(q, at, settled)); | |
| 511 | return html(shown, STATUS.invalid); | |
| 512 | } | |
| 513 | ||
| 514 | /** The review page at the draft a form was posted for, with what was typed kept; undefined when that draft is no longer in the queue. */ | |
| 515 | function sameDraft(c: Context, f: Record<string, string>, q: string, settled: number, error: ReviewError | undefined): string | undefined { | |
| 509 | 516 | const queue = reviewQueue(c, q); |
| 510 | 517 | const same = queue.ok |
| 511 | 518 | ? queue.value.findIndex((d) => d.deadline_id === Number(f.deadline) && d.party_id === Number(f.party) && d.moment === f.moment) |
| 512 | 519 | : -1; |
| 513 | if (result.error !== "invalid" || !queue.ok || same === -1) return back(result.message, reviewHref(q, at, settled)); | |
| 514 | const typed = { subject: f.subject ?? "", body: f.body ?? "", reason: f.reason ?? "" }; | |
| 515 | return html( | |
| 516 | reviewPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), queue: queue.value, q, at: same, done: settled, error: { field: fieldOf(result.message), message: result.message }, typed }), | |
| 517 | STATUS.invalid, | |
| 518 | ); | |
| 520 | if (!queue.ok || same === -1) return undefined; | |
| 521 | const typed = { subject: f.subject ?? "", body: f.body ?? "", reason: f.reason ?? "", contact: f.contact ?? "" }; | |
| 522 | return reviewPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), queue: queue.value, q, at: same, done: settled, error, typed }); | |
| 523 | } | |
| 524 | ||
| 525 | /** | |
| 526 | * The Save contact button on the review page: the party's contact is set | |
| 527 | * through the same action as the deal's page, then the same draft is shown | |
| 528 | * again with the agent's edited words and the contact on it. | |
| 529 | */ | |
| 530 | async function reviewedContact(c: Context): Promise<Response> { | |
| 531 | const f = await form(c); | |
| 532 | if (f instanceof Response) return f; | |
| 533 | const q = query(f.q ?? "") ?? ""; | |
| 534 | const at = count(f.at); | |
| 535 | const settled = count(f.done); | |
| 536 | const party = Number(f.party); | |
| 537 | const result: Result<unknown> = | |
| 538 | (f.contact ?? "").trim() === "" | |
| 539 | ? { ok: false, error: "invalid", message: "Add an email or phone to save." } | |
| 540 | : editParty(c.db, c.who, { id: party, name: nameOf(c.db, "party", party), contact: f.contact }); | |
| 541 | if (!result.ok && (result.error === "signin_required" || result.error === "forbidden")) | |
| 542 | return html(refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path: reviewHref(q, at, settled), heading: "Review today's reminders", error: result.error, message: result.message }), STATUS[result.error]); | |
| 543 | const shown = sameDraft(c, f, q, settled, result.ok ? undefined : { field: "contact", message: result.message }); | |
f.name comes from the client and editParty renames the party to it. Take the name from the stored party instead. |
||
| 544 | if (shown === undefined) return back(result.ok ? "Contact saved." : result.message, reviewHref(q, at, settled)); | |
| 545 | return html(shown, result.ok ? 200 : STATUS.invalid); | |
| 519 | 546 | } |
| 520 | 547 | |
| 521 | 548 | const SENT = "Reminder sent."; |
| @@ -1095,6 +1122,11 @@ export const routes: readonly Route[] = [ | ||
| 1095 | 1122 | handle: (c) => |
| 1096 | 1123 | reviewed(c, (f) => sendReminder(c.db, c.who, { deadlineId: Number(f.deadline), partyId: Number(f.party), moment: f.moment, subject: f.subject, body: f.body }), SENT), |
| 1097 | 1124 | }, |
| 1125 | { | |
| 1126 | method: "POST", | |
| 1127 | path: "/reminders/today/contact", | |
| 1128 | handle: reviewedContact, | |
| 1129 | }, | |
| 1098 | 1130 | { |
| 1099 | 1131 | method: "POST", |
| 1100 | 1132 | path: "/reminders/today/decline", |
new above
offline
Save contact is the form's first submit button, so it becomes the implicit Enter target. Send must be the default.