From b142dd9748a8b8403401955b14548c830a474200 Mon Sep 17 00:00:00 2001 From: Cosmically Creative <99832139+Cosmically-Creative@users.noreply.github.com> Date: Fri, 20 Nov 2026 13:18:07 -0600 Subject: [PATCH] feat: contacts as pills on a white card; remove several at once - Contacts list sits in the same white card as the Shifts panels, and each contact is a light-blue pill like a shift row. Stacks cleanly on phones. - Each contact has a checkbox, with Select all and Remove selected. The confirm dialog says how many contacts will be removed. - Select all only ticks contacts currently shown, never rows still behind "See more"; revealing more rows leaves Select all partial, not extended. This applies to every picker but changes nothing where no rows are hidden. - POST /admin/contacts/remove: session, origin and CSRF checked; one transaction; if any contact is missing, none are removed; one audit row. Signups are never touched and no email is sent. - tests: 5 new contact tests. --- public/css/app.css | 105 +++++++++++++++++++++++++++++++--- public/js/confirm-dialog.js | 30 ++++++++-- src/admin-http.tsx | 26 +++++++++ src/admin-pages.tsx | 42 ++++++++++++-- src/auth/audit.ts | 4 +- src/contacts.ts | 24 ++++++++ tests/contacts.test.ts | 111 ++++++++++++++++++++++++++++++++++++ 7 files changed, 324 insertions(+), 18 deletions(-) diff --git a/public/css/app.css b/public/css/app.css index c35f867..de69e44 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -3367,7 +3367,8 @@ button.btn-quiet::before { gap: 1rem; } -.coordinator-board .desk-panel { +.coordinator-board .desk-panel, +.contacts-board { display: flex; flex-direction: column; gap: 0.8rem; @@ -3380,7 +3381,8 @@ button.btn-quiet::before { box-shadow: 0 8px 24px rgb(34 55 70 / 0.05); } -.coordinator-board .desk-panel h2 { +.coordinator-board .desk-panel h2, +.contacts-board h2 { margin: 0; font-size: 1.35rem; font-weight: 650; @@ -3688,7 +3690,8 @@ button.btn-quiet::before { stroke-linejoin: round; } -.coordinator-board .desk-panel .empty { +.coordinator-board .desk-panel .empty, +.contacts-board .empty { margin: 0; padding: 0.85rem 1rem; background: #f3f7fb; @@ -3815,19 +3818,29 @@ button.btn-quiet::before { max-width: 100%; } +/* Contact rows: light-blue pills on the white panel, like the shift rows. */ .contact-list { list-style: none; - margin: 1rem 0 0; + display: grid; + gap: 0.55rem; + margin: 0; padding: 0; } .contact-row { - display: grid; - grid-template-columns: minmax(10rem, 1.2fr) minmax(12rem, 1.6fr) minmax(7rem, 0.8fr) auto; + display: flex; + flex-wrap: wrap; + align-items: center; gap: 0.35rem 1rem; - align-items: baseline; - padding: 0.75rem 0; - border-top: 1px solid var(--hope-border-2); + min-height: 4.15rem; + padding: 0.7rem 0.95rem; + background: #f3f7fb; + border-radius: 0.95rem; + color: var(--hope-ink); +} + +.contact-row:hover { + background: #e8f1f7; } .contact-row p { @@ -3839,6 +3852,80 @@ button.btn-quiet::before { display: none; } +.contact-row .pick { + flex: none; + justify-content: center; + min-height: 2.4rem; + padding: 0 0.3rem; + cursor: pointer; +} + +.contact-row .pick input { + width: 1.25rem; + height: 1.25rem; + margin: 0; + accent-color: var(--hope-ink); + cursor: pointer; +} + +.contact-name { + display: flex; + align-items: center; + flex: 1 1 10rem; + min-width: 8rem; + margin: 0; + font-size: 0.98rem; + line-height: 1.3; +} + +.contact-name a { + color: inherit; + font-weight: 650; + text-decoration: none; +} + +.contact-name a:hover, +.contact-name a:active { + text-decoration: underline; + text-underline-offset: 0.12em; +} + +.contact-email { + flex: 1 1 13rem; + min-width: 0; + margin: 0; + color: #7d8b99; + font-size: var(--hope-text-small); + line-height: 1.3; +} + +.contact-phone { + flex: 0 1 auto; + margin: 0; + color: #7d8b99; + font-size: var(--hope-text-small); + line-height: 1.3; + white-space: nowrap; +} + +.contact-remove { + flex: none; + margin: 0 0 0 auto; +} + +@media (max-width: 42em) { + .contact-name { + flex: 1 1 auto; + min-width: 0; + } + + .contact-email, + .contact-phone { + flex: 1 1 100%; + white-space: normal; + } +} + .contact-actions { display: grid; grid-template-columns: repeat(3, max-content) minmax(0, 1fr); diff --git a/public/js/confirm-dialog.js b/public/js/confirm-dialog.js index 31ba6a9..6e97d82 100644 --- a/public/js/confirm-dialog.js +++ b/public/js/confirm-dialog.js @@ -15,12 +15,23 @@ return link.getAttribute(name) || ''; }; + // A box inside a [hidden] subtree is not shown to the user (rows still behind "See more"), so it never counts. + var visibleBoxes = function (selector) { + var all = document.querySelectorAll(selector); + var shown = []; + for (var i = 0; i < all.length; i += 1) { + if (all[i].closest('[hidden]')) continue; + shown.push(all[i]); + } + return shown; + }; + var chosenFor = function (name) { - return document.querySelectorAll('input[data-pick="' + name + '"]:checked'); + return visibleBoxes('input[data-pick="' + name + '"]:checked'); }; var boxesFor = function (name) { - return document.querySelectorAll('input[data-pick="' + name + '"]'); + return visibleBoxes('input[data-pick="' + name + '"]'); }; var fill = function (link) { @@ -88,7 +99,12 @@ if (blocked > 0 && kept.length > 0) { detail.textContent = kept.length + ' of ' + chosen.length + ' can be ' + verb; } else { - detail.textContent = chosen.length === 1 ? '1 selected' : chosen.length + ' selected'; + var unit = text(link, 'data-confirm-unit'); + if (unit) { + detail.textContent = chosen.length === 1 ? '1 ' + unit + ' will be removed.' : chosen.length + ' ' + unit + 's will be removed.'; + } else { + detail.textContent = chosen.length === 1 ? '1 selected' : chosen.length + ' selected'; + } } detail.hidden = false; if (weekly && weeklyNote) notes.push(weeklyNote); @@ -109,7 +125,8 @@ var syncPicks = function () { document.querySelectorAll('[data-confirm-pick]').forEach(function (control) { var name = control.getAttribute('data-confirm-pick'); - control.hidden = !name || chosenFor(name).length === 0; + var hide = !name || chosenFor(name).length === 0; + if (control.hidden !== hide) control.hidden = hide; }); document.querySelectorAll('[data-pick-all]').forEach(function (all) { var name = all.getAttribute('data-pick-all'); @@ -163,5 +180,10 @@ }); syncPicks(); + // Re-check the pick state when rows appear or disappear, e.g. "See more" revealing contacts. + // The guarded writes in syncPicks keep this from looping. + if (typeof MutationObserver === 'function') { + new MutationObserver(syncPicks).observe(document.body, { attributes: true, attributeFilter: ['hidden'], subtree: true }); + } if (dialog.open) show(); })(); diff --git a/src/admin-http.tsx b/src/admin-http.tsx index 126bc51..be333d3 100644 --- a/src/admin-http.tsx +++ b/src/admin-http.tsx @@ -91,6 +91,7 @@ import { loadContacts, parseContactSkips, removeContact, + removeContacts, saveManualContact, contactSignupShifts, walkInFromContact, @@ -154,6 +155,7 @@ export function registerAdmin(app: Hono, services: AdminServices): void { app.post(appPath(config, '/admin/contacts/new'), (c) => submitNewContact(c, services)); app.post(appPath(config, '/admin/contacts/import'), (c) => submitImportContacts(c, services)); app.post(appPath(config, '/admin/contacts/export'), (c) => submitExportContacts(c, services)); + app.post(appPath(config, '/admin/contacts/remove'), (c) => submitRemoveContacts(c, services)); app.get(appPath(config, '/admin/contacts/:id/remove'), (c) => showRemoveContact(c, services)); app.post(appPath(config, '/admin/contacts/:id/remove'), (c) => submitRemoveContact(c, services)); app.post(appPath(config, '/admin/contacts/:id/add'), (c) => submitAddContactToShift(c, services)); @@ -364,6 +366,7 @@ function showContacts( services: AdminServices, options?: { error?: string; + removeError?: string; status?: 200 | 400 | 403; confirm?: ConfirmPrompt; manual?: { values: ContactManualValues; errors: ContactManualErrors }; @@ -384,6 +387,8 @@ function showContacts( query={loaded.query} limit={contactListLimit(c.req.query('shown'))} notice={options?.error ? undefined : knownNotice(c.req.query('notice'))} + noticeText={contactsRemovedNotice(c.req.query('removed'))} + removeError={options?.removeError} summary={options?.error ? undefined : contactSummary(c)} importError={options?.error} manual={options?.manual} @@ -600,6 +605,20 @@ async function submitRemoveContact(c: Context, services: AdminServices): Promise } } +async function submitRemoveContacts(c: Context, services: AdminServices): Promise { + const session = await postedSession(c, services); + if (session instanceof Response) return session; + const ids = idList(session.body, 'contact[]'); + if (!ids) return showContacts(c, services, { removeError: 'That saved contact is not available.', status: 400 }); + try { + const removed = removeContacts(services.db, session.coordinatorId, ids, services.now()); + if (!removed.ok) return showContacts(c, services, { removeError: 'That saved contact is not available.', status: 400 }); + return c.redirect(appPath(services.config, `/admin/contacts?removed=${removed.count}`), 303); + } catch (err) { + return saveFailed(c, services, session, err); + } +} + function csvDownload(c: Context, filename: string, csv: string): Response { return c.body(new TextEncoder().encode(csv), 200, { 'Cache-Control': 'no-store', @@ -1788,6 +1807,13 @@ function wholeNumber(value: string | undefined): number | null { return Number.isSafeInteger(parsed) ? parsed : null; } +/** Notice text after a bulk removal. Blank unless the count is a real positive number. */ +function contactsRemovedNotice(value: string | undefined): string | undefined { + const count = wholeNumber(value); + if (count === null || count === 0) return undefined; + return count === 1 ? '1 contact removed.' : `${count} contacts removed.`; +} + function importLocation(config: AppConfig, result: ContactImportSummary): string { const params = new URLSearchParams({ notice: 'contacts-imported', diff --git a/src/admin-pages.tsx b/src/admin-pages.tsx index 45ca223..bf8335f 100644 --- a/src/admin-pages.tsx +++ b/src/admin-pages.tsx @@ -47,6 +47,8 @@ const SHIFT_WAIT_BODY = 'Cancel this shift, or wait until it has ended, before r const SHIFT_WEEKLY_NOTE = 'This date came from a weekly template that is still active. Saving that template puts this date back. End that template first if the date should stay gone.'; const PERSON_DELETE_BODY = 'This deletes their name, email, phone, and notes from the roster. It does not send email.'; +const CONTACT_REMOVE_MANY_BODY = + 'This deletes their names, emails, and phones from the contact list. Their signups stay, and no email is sent.'; const PERSON_WAIT_BODY = 'Cancel this signup before removing it.'; const PERSON_CANCEL_BODY = 'Cancelling a signup emails them. Their old private link stops working, and the email includes a new one.'; const SHIFT_CANCEL_EMPTY = 'No one is signed up. Cancelling closes the shift, takes it off this list, and does not send email.'; @@ -624,6 +626,8 @@ export function ContactsPage(props: { query: string; limit: number; notice?: string; + noticeText?: string; + removeError?: string; summary?: ContactImportSummary; importError?: string; manual?: { values: ContactManualValues; errors: ContactManualErrors }; @@ -645,7 +649,7 @@ export function ContactsPage(props: { return ( <>

Contacts

- {props.summary ? : } + {props.summary ? : } {props.summary && props.summary.skips.length > 0 ? (
    {props.summary.skips.map((skip) => ( @@ -654,7 +658,8 @@ export function ContactsPage(props: {
) : null} {hiddenSkips > 0 ?

{hiddenSkips === 1 ? '1 more row was skipped.' : `${hiddenSkips} more rows were skipped.`}

: null} -
+ {props.removeError ?

{props.removeError}

: null} +

{heading}

{props.total > 0 ? ( @@ -717,11 +722,34 @@ export function ContactsPage(props: {
+ {props.people.length > 0 ? ( +
+ {props.people.length > 1 ? ( + + ) : null} + + Remove selected + +
+ ) : null} {props.total > 0 && props.people.length === 0 ?

No contacts match.

: null} {props.people.length > 0 ? (
    {props.people.map((person, index) => (