Public: anyone can read this; the crew can change it.
Removing a deal, a party or a date asks once before it happens, so a mis-tap in the meeting never loses a deal #70
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/64-removing-a-deal-a-party-or-a-date-asks-o → main 1 commit fork
9 files
changed +135
−14
README.md +4 −3
| @@ -97,11 +97,12 @@ Signed out, `/` shows what deal-clock does, three short points, a still picture | ||
| 97 | 97 | add it. The party appears in the list, and the dates that concern them now |
| 98 | 98 | have reminders for them. |
| 99 | 99 | Made a typo? Each party has Edit (fix the name or email; the next |
| 100 | reminder uses it) and Remove (its unsent reminders go with it). | |
| 100 | reminder uses it) and Remove (its unsent reminders go with it). Remove asks once: it opens | |
| 101 | a line saying what goes and a Yes, remove button. | |
| 101 | 102 | 9. **Add a date.** On the same page, add a date the contract added, such as |
| 102 | 103 | an HOA review: a name, a date, who owes it. It joins the deal's list and |
| 103 | the clock. A date you added has a Remove this date button in its sheet, | |
| 104 | for when the contract drops it; the standard dates cannot be removed, only | |
| 104 | the clock. A date you added has a Remove this date button in its sheet | |
| 105 | (it asks once, like every removal, including Remove this deal), for when the contract drops it; the standard dates cannot be removed, only | |
| 105 | 106 | moved or marked done. |
| 106 | 107 | 10. **Open a new deal.** Back on the clock, tap New deal. Type an address, |
| 107 | 108 | buyer, seller, contract date and closing date. The standard lengths are |
docs/design/areas/remove.md added +3
| @@ -0,0 +1,3 @@ | ||
| 1 | # Remove | |
| 2 | ||
| 3 | No new class. Removing a deal, a party or a date reuses `.confirm` (the `<details>` the clock uses for Restore the sample deals): the summary reads "Remove …", opening it shows one line of what goes and a **Yes, remove** button that posts `confirm=yes`. Beside a party's Edit, `.party-controls > .confirm[open]` takes the full row, as `.party-edit[open]` does. |
src/deals.ts +12
| @@ -730,6 +730,18 @@ export function removeParty( | ||
| 730 | 730 | return within(db, who, dealId, ok({ id: input.id })); |
| 731 | 731 | } |
| 732 | 732 | |
| 733 | /** What a party or a date is called, for a notice saying it was removed. */ | |
| 734 | export function nameOf(db: Database, table: "party" | "deadline", id: number): string | undefined { | |
| 735 | const row = Number.isInteger(id) | |
| 736 | ? db | |
| 737 | .query<{ name: string }, [number]>( | |
| 738 | table === "party" ? "SELECT name FROM party WHERE id = ?1" : "SELECT label AS name FROM deadline WHERE id = ?1", | |
| 739 | ) | |
| 740 | .get(id) | |
| 741 | : null; | |
| 742 | return row?.name; | |
| 743 | } | |
| 744 | ||
| 733 | 745 | /** |
| 734 | 746 | * Remove a date the contract dropped. Only custom dates go: the standard |
| 735 | 747 | * ones can be moved or marked done, never removed. Its unsent reminders go |
src/pages/confirm.ts added +31
| @@ -0,0 +1,31 @@ | ||
| 1 | /** | |
| 2 | * A removal that asks once: a closed `<details class="confirm">` whose | |
| 3 | * summary names what goes, and which opens onto one line saying what is lost | |
| 4 | * and a button that posts `confirm=yes`. No script; closed, it is the size | |
| 5 | * of the button it replaces. | |
| 6 | */ | |
| 7 | ||
| 8 | import { escape } from "../http.ts"; | |
| 9 | ||
| 10 | export function confirmRemove(input: { | |
| 11 | /** The summary: "Remove this deal…". */ | |
| 12 | summary: string; | |
| 13 | /** What goes, in one sentence. */ | |
| 14 | goes: string; | |
| 15 | action: string; | |
| 16 | /** Hidden fields the handler reads, such as where to go back to. */ | |
| 17 | fields?: Readonly<Record<string, string>>; | |
| 18 | /** What the button's accessible name says it removes: "Yes, remove 77 Harbor View Dr". */ | |
| 19 | name: string; | |
| 20 | small?: boolean; | |
| 21 | class?: string; | |
| 22 | }): string { | |
| 23 | const hidden = Object.entries({ ...input.fields, confirm: "yes" }) | |
| 24 | .map(([k, v]) => `<input type="hidden" name="${escape(k)}" value="${escape(v)}">`) | |
| 25 | .join(""); | |
| 26 | return `<details class="confirm${input.class === undefined ? "" : ` ${input.class}`}"> | |
| 27 | <summary class="button button-quiet${input.small ? " button-small" : ""}">${escape(input.summary)}</summary> | |
| 28 | <p>${escape(input.goes)}</p> | |
| 29 | <form method="post" action="${escape(input.action)}">${hidden}<button class="button" aria-label="${escape(input.name)}">Yes, remove</button></form> | |
| 30 | </details>`; | |
| 31 | } |
src/pages/deal.ts +18 −2
| @@ -11,6 +11,7 @@ import { DEFAULT_LENGTHS, PARTY_LABEL, PARTY_ROLES } from "../deadlines.ts"; | ||
| 11 | 11 | import { escape } from "../http.ts"; |
| 12 | 12 | import { MOMENT_LABEL } from "../reminders.ts"; |
| 13 | 13 | import type { Who } from "../who.ts"; |
| 14 | import { confirmRemove } from "./confirm.ts"; | |
| 14 | 15 | import { layout } from "./layout.ts"; |
| 15 | 16 | import { badge, conflictLines, dueLine, outboxLine, owedBy, sheet, sheetId } from "./sheet.ts"; |
| 16 | 17 | |
| @@ -19,6 +20,8 @@ const roleOptions = (selected?: string): string => | ||
| 19 | 20 | (r) => `<option value="${r}"${r === selected ? " selected" : ""}>${escape(PARTY_LABEL[r])}</option>`, |
| 20 | 21 | ).join(""); |
| 21 | 22 | |
| 23 | const count = (n: number, one: string, many = `${one}s`): string => `${n} ${n === 1 ? one : many}`; | |
| 24 | ||
| 22 | 25 | /** Correct a party or remove them: a plain form each, back to this page. */ |
| 23 | 26 | const partyControls = (p: Party, to: string): string => `<div class="party-controls"> |
| 24 | 27 | <details class="party-edit"> |
| @@ -30,7 +33,14 @@ const partyControls = (p: Party, to: string): string => `<div class="party-contr | ||
| 30 | 33 | <button class="button">Save</button> |
| 31 | 34 | </form> |
| 32 | 35 | </details> |
| 33 | <form method="post" action="/parties/${p.id}/remove"><input type="hidden" name="to" value="${escape(to)}"><button class="button button-quiet button-small" aria-label="Remove ${escape(p.name)}">Remove</button></form> | |
| 36 | ${confirmRemove({ | |
| 37 | summary: `Remove ${p.name}…`, | |
| 38 | goes: `${p.name} and the reminders not yet sent to them. Reminders already sent stay in the record.`, | |
| 39 | action: `/parties/${p.id}/remove`, | |
| 40 | fields: { to }, | |
| 41 | name: `Yes, remove ${p.name}`, | |
| 42 | small: true, | |
| 43 | })} | |
| 34 | 44 | </div>`; |
| 35 | 45 | |
| 36 | 46 | /** The record of what went out: each sent reminder with the words approved, newest first. */ |
| @@ -147,7 +157,13 @@ export function dealPage(input: { | ||
| 147 | 157 | ${forms} |
| 148 | 158 | ${ |
| 149 | 159 | canRemove(who, deal) |
| 150 | ? `<form method="post" action="${path}/delete" class="remove"><button class="button button-quiet">Remove this deal</button></form>` | |
| 160 | ? confirmRemove({ | |
| 161 | summary: "Remove this deal…", | |
| 162 | goes: `${deal.address}, its ${count(deal.deadlines.length, "date")}, ${count(deal.parties.length, "party", "parties")} and their messages.`, | |
| 163 | action: `${path}/delete`, | |
| 164 | name: `Yes, remove ${deal.address}`, | |
| 165 | class: "remove", | |
| 166 | }) | |
| 151 | 167 | : "" |
| 152 | 168 | }`; |
| 153 | 169 | return layout({ body, who, path, heading: deal.address, notice, open: opened?.href }); |
src/pages/sheet.ts +8 −3
| @@ -10,6 +10,7 @@ import { relative, short, spoken, urgency, type Urgency } from "../dates.ts"; | ||
| 10 | 10 | import { PARTY_LABEL } from "../deadlines.ts"; |
| 11 | 11 | import { agent } from "../env.ts"; |
| 12 | 12 | import { escape } from "../http.ts"; |
| 13 | import { confirmRemove } from "./confirm.ts"; | |
| 13 | 14 | import { memoizer, print } from "../memo.ts"; |
| 14 | 15 | import { labelOf, NO_CONTACT, outbox } from "../outbox.ts"; |
| 15 | 16 | import { conflictLine } from "../order.ts"; |
| @@ -174,9 +175,13 @@ export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to: | ||
| 174 | 175 | <p class="muted small">Moving a date moves nothing else; the reason is kept.</p> |
| 175 | 176 | ${ |
| 176 | 177 | d.kind === "custom" |
| 177 | ? `<form method="post" action="/deadlines/${d.id}/remove">${hidden({ to: `/deals/${deal.id}` })} | |
| 178 | <button class="button button-quiet">Remove this date</button> | |
| 179 | </form> | |
| 178 | ? `${confirmRemove({ | |
| 179 | summary: "Remove this date…", | |
| 180 | goes: `${d.label}, and its unsent reminders. Ones already sent stay on record.`, | |
| 181 | action: `/deadlines/${d.id}/remove`, | |
| 182 | fields: { to: `/deals/${deal.id}` }, | |
| 183 | name: `Yes, remove ${d.label}`, | |
| 184 | })} | |
| 180 | 185 | <p class="muted small">For a date the contract dropped. Its unsent reminders go too; ones already sent stay on record.</p>` |
| 181 | 186 | : "" |
| 182 | 187 | } |
src/routes.ts +24 −4
| @@ -53,6 +53,7 @@ import { | ||
| 53 | 53 | plan, |
| 54 | 54 | plannedDates, |
| 55 | 55 | moveDeadline, |
| 56 | nameOf, | |
| 56 | 57 | removeDeadline, |
| 57 | 58 | removeParty, |
| 58 | 59 | sendReminder, |
| @@ -339,6 +340,13 @@ async function form(c: Context): Promise<Record<string, string> | Response> { | ||
| 339 | 340 | return out; |
| 340 | 341 | } |
| 341 | 342 | |
| 343 | /** A removal posted without `confirm=yes`: refused like any invalid form, and nothing goes. */ | |
| 344 | const unconfirmed = (c: Context, path: string): Response => | |
| 345 | html( | |
| 346 | refusedPage({ who: c.who, path, heading: "Not removed", error: "invalid", message: "Nothing was removed: a removal has to be confirmed." }), | |
| 347 | STATUS.invalid, | |
| 348 | ); | |
| 349 | ||
| 342 | 350 | /** An unticked box is absent from a form: that says no, not "the agent's default". */ |
| 343 | 351 | const fromForm = (f: Record<string, unknown>): Record<string, unknown> => ({ |
| 344 | 352 | ...f, |
| @@ -576,10 +584,16 @@ export const routes: readonly Route[] = [ | ||
| 576 | 584 | { |
| 577 | 585 | method: "POST", |
| 578 | 586 | path: "/deals/:id/delete", |
| 579 | handle: (c) => { | |
| 587 | handle: async (c) => { | |
| 588 | const f = await form(c); | |
| 589 | if (f instanceof Response) return f; | |
| 580 | 590 | const id = Number(c.params.id); |
| 591 | if (f.confirm !== "yes") return unconfirmed(c, `/deals/${id}`); | |
| 592 | const address = getDeal(c.db, c.who, { id }); | |
| 581 | 593 | const removed = deleteDeal(c.db, c.who, { id }); |
| 582 | return removed.ok ? back("Deal removed.") : back(removed.message, backTo(`/deals/${id}`)); | |
| 594 | return removed.ok | |
| 595 | ? back(address.ok ? `Removed ${address.value.address}.` : "Deal removed.") | |
| 596 | : back(removed.message, backTo(`/deals/${id}`)); | |
| 583 | 597 | }, |
| 584 | 598 | }, |
| 585 | 599 | { |
| @@ -608,7 +622,10 @@ export const routes: readonly Route[] = [ | ||
| 608 | 622 | handle: async (c) => { |
| 609 | 623 | const f = await form(c); |
| 610 | 624 | if (f instanceof Response) return f; |
| 611 | return done(removeDeadline(c.db, c.who, { id: Number(c.params.id) }), backTo(f.to), "Date removed."); | |
| 625 | const id = Number(c.params.id); | |
| 626 | if (f.confirm !== "yes") return unconfirmed(c, backTo(f.to)); | |
| 627 | const label = nameOf(c.db, "deadline", id); | |
| 628 | return done(removeDeadline(c.db, c.who, { id }), backTo(f.to), label === undefined ? "Date removed." : `Removed ${label}.`); | |
| 612 | 629 | }, |
| 613 | 630 | }, |
| 614 | 631 | { |
| @@ -626,7 +643,10 @@ export const routes: readonly Route[] = [ | ||
| 626 | 643 | handle: async (c) => { |
| 627 | 644 | const f = await form(c); |
| 628 | 645 | if (f instanceof Response) return f; |
| 629 | return done(removeParty(c.db, c.who, { id: Number(c.params.id) }), backTo(f.to), "Party removed."); | |
| 646 | const id = Number(c.params.id); | |
| 647 | if (f.confirm !== "yes") return unconfirmed(c, backTo(f.to)); | |
| 648 | const name = nameOf(c.db, "party", id); | |
| 649 | return done(removeParty(c.db, c.who, { id }), backTo(f.to), name === undefined ? "Party removed." : `Removed ${name}.`); | |
| 630 | 650 | }, |
| 631 | 651 | }, |
| 632 | 652 | { |
src/server.test.ts +31 −1
| @@ -801,6 +801,11 @@ test("a party is corrected and removed from the page and the API; a custom date | ||
| 801 | 801 | for (const [k, v] of Object.entries(fields)) body.set(k, v); |
| 802 | 802 | return api(path, { method: "POST", body, redirect: "manual" }, who); |
| 803 | 803 | }; |
| 804 | expect(page).toContain(`<summary class="button button-quiet button-small">Remove Bo Buyer…</summary>`); | |
| 805 | expect(page).toContain(`aria-label="Yes, remove Bo Buyer"`); | |
| 806 | expect((await post(`/parties/${buyer}/remove`, { to: `/deals/${deal.id}` })).status).toBe(422); | |
| 807 | expect((await post(`/parties/${buyer}/remove`, { to: `/deals/${deal.id}`, confirm: "no" })).status).toBe(422); | |
| 808 | expect(((await (await api(`/api/deals/${deal.id}`, {}, alice)).json()) as typeof deal).parties.some((p) => p.id === buyer)).toBe(true); | |
| 804 | 809 | const edited = await post(`/parties/${buyer}/edit`, { name: "Bo B.", contact: "[email protected]", to: `/deals/${deal.id}` }); |
| 805 | 810 | expect(edited.headers.get("location")).toBe(`/deals/${deal.id}`); |
| 806 | 811 | const patched = await api(`/api/deals/${deal.id}/parties/${buyer}`, { method: "PATCH", ...jsonBody({ name: "Bo Buyer", contact: "[email protected]" }) }, mia); |
| @@ -818,10 +823,35 @@ test("a party is corrected and removed from the page and the API; a custom date | ||
| 818 | 823 | const hoa = now.deadlines.find((d) => d.kind === "custom")!; |
| 819 | 824 | expect(now.parties.some((p) => p.id === buyer)).toBe(false); |
| 820 | 825 | expect(await (await api(`/deals/${deal.id}`, {}, alice)).text()).toContain(`action="/deadlines/${hoa.id}/remove"`); |
| 821 | expect((await post(`/deadlines/${hoa.id}/remove`, { to: `/deals/${deal.id}` })).status).toBe(303); | |
| 826 | expect((await post(`/deadlines/${hoa.id}/remove`, { to: `/deals/${deal.id}` })).status).toBe(422); | |
| 827 | expect((await api(`/api/deals/${deal.id}`, {}, alice).then((r) => r.json()) as typeof deal).deadlines.some((d) => d.id === hoa.id)).toBe(true); | |
| 828 | expect((await post(`/deadlines/${hoa.id}/remove`, { to: `/deals/${deal.id}`, confirm: "yes" })).status).toBe(303); | |
| 822 | 829 | expect((await api(`/api/deals/${deal.id}/deadlines/${hoa.id}`, { method: "DELETE" }, mia)).status).toBe(404); |
| 823 | 830 | }); |
| 824 | 831 | |
| 832 | test("a deal's page removal asks once, is refused without confirm=yes, and says what went", async () => { | |
| 833 | const made = await api("/api/deals", { method: "POST", ...jsonBody({ address: "77 Harbor View Dr", buyer: "Bo Buyer", seller: "Su Seller", contract_date: "2027-05-01", closing_date: "2027-06-05" }) }, mia); | |
| 834 | const deal = (await made.json()) as { id: number; deadlines: unknown[]; parties: unknown[] }; | |
| 835 | const page = await (await api(`/deals/${deal.id}`, {}, mia)).text(); | |
| 836 | expect(page).toContain("Remove this deal…"); | |
| 837 | expect(page).toContain(`77 Harbor View Dr, its ${deal.deadlines.length} dates, ${deal.parties.length} parties and their messages.`); | |
| 838 | expect(page).toContain(`aria-label="Yes, remove 77 Harbor View Dr"`); | |
| 839 | const post = (fields: Record<string, string>) => { | |
| 840 | const body = new FormData(); | |
| 841 | for (const [k, v] of Object.entries(fields)) body.set(k, v); | |
| 842 | return api(`/deals/${deal.id}/delete`, { method: "POST", body, redirect: "manual" }, mia); | |
| 843 | }; | |
| 844 | expect((await post({})).status).toBe(422); | |
| 845 | expect((await api(`/api/deals/${deal.id}`, {}, mia)).status).toBe(200); | |
| 846 | const deletes = async () => ((await (await api("/api/audit", {}, root)).json()) as { verb: string; outcome: string }[]).filter((a) => a.verb === "delete" && a.outcome === "ok").length; | |
| 847 | const before = await deletes(); | |
| 848 | const gone = await post({ confirm: "yes" }); | |
| 849 | expect(gone.status).toBe(303); | |
| 850 | expect(decodeURIComponent(gone.headers.get("set-cookie") ?? "")).toContain("Removed 77 Harbor View Dr."); | |
| 851 | expect((await api(`/api/deals/${deal.id}`, {}, mia)).status).toBe(404); | |
| 852 | expect(await deletes()).toBe(before + 1); | |
| 853 | }); | |
| 854 | ||
| 825 | 855 | test("an agent corrects a party, removes dates, a party and a deal over MCP, as the actions allow", async () => { |
| 826 | 856 | const dan = as("u11", "dan"); |
| 827 | 857 | const eve = as("u12", "eve"); |
static/app.css +4 −1
| @@ -665,9 +665,12 @@ footer code { | ||
| 665 | 665 | .party-edit[open] summary { |
| 666 | 666 | margin-bottom: var(); |
| 667 | 667 | } |
| 668 | .party-controls > form { | |
| 668 | .party-controls > .confirm { | |
| 669 | 669 | order: 1; |
| 670 | 670 | } |
| 671 | .party-controls > .confirm[open] { | |
| 672 | flex: 1 1 100%; | |
| 673 | } | |
| 671 | 674 | .stack { |
| 672 | 675 | display: grid; |
| 673 | 676 | gap: var(); |
new above
offline