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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/deal-clock:mason/64-removing-a-deal-a-party-or-a-date-asks-o → main 1 commit fork

  • Merged. mason/64-removing-a-deal-a-party-or-a-date-asks-o was merged into main as 108ac2b.

Review

Sign in to review this change.
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
9797 add it. The party appears in the list, and the dates that concern them now
9898 have reminders for them.
9999 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.
101102 9. **Add a date.** On the same page, add a date the contract added, such as
102103 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
105106 moved or marked done.
106107 10. **Open a new deal.** Back on the clock, tap New deal. Type an address,
107108 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(
730730 return within(db, who, dealId, ok({ id: input.id }));
731731 }
732732
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
733745 /**
734746 * Remove a date the contract dropped. Only custom dates go: the standard
735747 * 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";
1111 import { escape } from "../http.ts";
1212 import { MOMENT_LABEL } from "../reminders.ts";
1313 import type { Who } from "../who.ts";
14 import { confirmRemove } from "./confirm.ts";
1415 import { layout } from "./layout.ts";
1516 import { badge, conflictLines, dueLine, outboxLine, owedBy, sheet, sheetId } from "./sheet.ts";
1617
@@ -19,6 +20,8 @@ const roleOptions = (selected?: string): string =>
1920 (r) => `<option value="${r}"${r === selected ? " selected" : ""}>${escape(PARTY_LABEL[r])}</option>`,
2021 ).join("");
2122
23 const count = (n: number, one: string, many = `${one}s`): string => `${n} ${n === 1 ? one : many}`;
24
2225 /** Correct a party or remove them: a plain form each, back to this page. */
2326 const partyControls = (p: Party, to: string): string => `<div class="party-controls">
2427 <details class="party-edit">
@@ -30,7 +33,14 @@ const partyControls = (p: Party, to: string): string => `<div class="party-contr
3033 <button class="button">Save</button>
3134 </form>
3235 </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 })}
3444 </div>`;
3545
3646 /** The record of what went out: each sent reminder with the words approved, newest first. */
@@ -147,7 +157,13 @@ export function dealPage(input: {
147157 ${forms}
148158 ${
149159 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 })
151167 : ""
152168 }`;
153169 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";
1010 import { PARTY_LABEL } from "../deadlines.ts";
1111 import { agent } from "../env.ts";
1212 import { escape } from "../http.ts";
13 import { confirmRemove } from "./confirm.ts";
1314 import { memoizer, print } from "../memo.ts";
1415 import { labelOf, NO_CONTACT, outbox } from "../outbox.ts";
1516 import { conflictLine } from "../order.ts";
@@ -174,9 +175,13 @@ export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to:
174175 <p class="muted small">Moving a date moves nothing else; the reason is kept.</p>
175176 ${
176177 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 })}
180185 <p class="muted small">For a date the contract dropped. Its unsent reminders go too; ones already sent stay on record.</p>`
181186 : ""
182187 }
src/routes.ts +24 −4
@@ -53,6 +53,7 @@ import {
5353 plan,
5454 plannedDates,
5555 moveDeadline,
56 nameOf,
5657 removeDeadline,
5758 removeParty,
5859 sendReminder,
@@ -339,6 +340,13 @@ async function form(c: Context): Promise<Record<string, string> | Response> {
339340 return out;
340341 }
341342
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
342350 /** An unticked box is absent from a form: that says no, not "the agent's default". */
343351 const fromForm = (f: Record<string, unknown>): Record<string, unknown> => ({
344352 ...f,
@@ -576,10 +584,16 @@ export const routes: readonly Route[] = [
576584 {
577585 method: "POST",
578586 path: "/deals/:id/delete",
579 handle: (c) => {
587 handle: async (c) => {
588 const f = await form(c);
589 if (f instanceof Response) return f;
580590 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 });
581593 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}`));
583597 },
584598 },
585599 {
@@ -608,7 +622,10 @@ export const routes: readonly Route[] = [
608622 handle: async (c) => {
609623 const f = await form(c);
610624 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}.`);
612629 },
613630 },
614631 {
@@ -626,7 +643,10 @@ export const routes: readonly Route[] = [
626643 handle: async (c) => {
627644 const f = await form(c);
628645 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}.`);
630650 },
631651 },
632652 {
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
801801 for (const [k, v] of Object.entries(fields)) body.set(k, v);
802802 return api(path, { method: "POST", body, redirect: "manual" }, who);
803803 };
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);
804809 const edited = await post(`/parties/${buyer}/edit`, { name: "Bo B.", contact: "[email protected]", to: `/deals/${deal.id}` });
805810 expect(edited.headers.get("location")).toBe(`/deals/${deal.id}`);
806811 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
818823 const hoa = now.deadlines.find((d) => d.kind === "custom")!;
819824 expect(now.parties.some((p) => p.id === buyer)).toBe(false);
820825 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);
822829 expect((await api(`/api/deals/${deal.id}/deadlines/${hoa.id}`, { method: "DELETE" }, mia)).status).toBe(404);
823830 });
824831
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
825855 test("an agent corrects a party, removes dates, a party and a deal over MCP, as the actions allow", async () => {
826856 const dan = as("u11", "dan");
827857 const eve = as("u12", "eve");
static/app.css +4 −1
@@ -665,9 +665,12 @@ footer code {
665665 .party-edit[open] summary {
666666 margin-bottom: var(--space-2);
667667 }
668 .party-controls > form {
668 .party-controls > .confirm {
669669 order: 1;
670670 }
671 .party-controls > .confirm[open] {
672 flex: 1 1 100%;
673 }
671674 .stack {
672675 display: grid;
673676 gap: var(--space-3);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs