feat: enhance manage page with new styling and reminder functionality

Updated the manage page to improve layout and styling, introducing a grid-based design for better organization. Added functionality for managing reminder emails, allowing users to enable or disable reminders directly from the interface. Enhanced the JavaScript logic to support the new reminder management features and updated related tests to ensure proper functionality.
This commit is contained in:
blake committed 2026-10-30 16:49:49 -05:00
1 parent caaeded467
commit 724d5a68ae
7 files changed
+479 -62

No files matched your search

+297 -9
View File
@@ -661,6 +661,245 @@ main a:hover {
text-decoration: none; text-decoration: none;
} }
.manage {
display: grid;
gap: 0.35rem 0;
width: min(64rem, 100%);
margin-inline: auto;
}
.manage-intro h1 {
margin-bottom: 0.35rem;
}
.manage-intro h2,
.manage-intro p {
margin: 0.15rem 0;
}
.manage-intro .status {
margin: 0.15rem 0 0.65rem;
}
.status.is-cancelled {
display: inline-block;
width: fit-content;
padding: 0.15rem 0.7rem;
border: 1px solid var(--hope-full-edge);
border-radius: 999px;
background: var(--hope-full);
color: var(--hope-ink);
}
.manage-record {
position: relative;
margin-top: 0.85rem;
padding: 1.15rem 1.25rem 1.25rem;
background: var(--hope-blue-100);
border-radius: 1.75rem;
box-shadow: var(--hope-shadow);
}
.manage-follow {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
align-items: stretch;
margin-top: 1.15rem;
padding-top: 1.15rem;
border-top: 1px solid var(--hope-border-2);
}
.manage-follow:has(> :only-child) {
grid-template-columns: minmax(0, 1fr);
}
.manage-follow > .manage-action,
.manage-follow > .hint {
min-width: 0;
margin: 0;
padding: 0 1.35rem;
}
.manage-follow > :first-child {
padding-left: 0;
}
.manage-follow > :only-child {
padding-right: 0;
}
.manage-follow > :last-child:not(:only-child) {
padding-right: 0;
border-left: 1px solid var(--hope-border-2);
}
.manage-record .move-form {
margin: 0;
}
.manage-follow .move-form {
gap: 0.55rem;
}
.manage-follow .hint,
.manage-follow .field-error {
margin: 0;
}
.manage-action-row {
display: grid;
gap: 0.55rem;
}
.manage-follow .manage-action-row label,
.manage-follow .manage-action-row select {
width: 100%;
min-width: 0;
max-width: 100%;
}
.manage-follow .manage-action-row button {
width: 7.5rem;
min-height: 48px;
}
.manage > .move-form {
max-width: none;
margin-top: 1rem;
padding: 1.15rem 1.25rem 1.25rem;
background: var(--hope-blue-100);
border-radius: 1.75rem;
box-shadow: var(--hope-shadow);
}
.manage .cancel-form,
.manage-actions {
max-width: none;
margin-top: 1rem;
}
.manage .error {
margin: 0.5rem 0 0;
}
.manage-tools {
position: absolute;
z-index: 2;
top: 1.05rem;
right: 1.05rem;
display: flex;
align-items: center;
gap: 0.4rem;
margin: 0;
}
.manage-cancel {
margin: 0;
}
.manage-x {
width: 2.5rem;
height: 2.5rem;
min-height: 2.5rem;
padding: 0;
border-color: var(--hope-border);
background: #fff;
box-shadow: none;
}
.manage-x::before {
background: var(--hope-yellow);
}
.manage-x span {
position: relative;
width: 0.7rem;
height: 0.7rem;
font-size: 0;
}
.manage-x span::before,
.manage-x span::after {
content: "";
position: absolute;
left: 50%;
top: 50%;
width: 0.7rem;
height: 2px;
border-radius: 1px;
background: currentColor;
}
.manage-x span::before {
transform: translate(-50%, -50%) rotate(45deg);
}
.manage-x span::after {
transform: translate(-50%, -50%) rotate(-45deg);
}
.manage-menu {
position: relative;
}
.manage-menu > summary {
display: inline-flex;
align-items: center;
gap: 0.4rem;
min-height: 2.5rem;
padding: 0.2rem 0.8rem;
list-style: none;
cursor: pointer;
background: #fff;
border: 1px solid var(--hope-border-2);
border-radius: 999px;
font-weight: 650;
}
.manage-menu > summary::-webkit-details-marker {
display: none;
}
.manage-menu > summary::marker {
content: "";
}
.manage-menu > summary::after {
content: "";
width: 0.4rem;
height: 0.4rem;
border-right: 2px solid currentColor;
border-bottom: 2px solid currentColor;
transform: translateY(-0.12rem) rotate(45deg);
}
.manage-menu[open] > summary::after {
transform: translateY(0.1rem) rotate(225deg);
}
.manage-menu-panel {
position: absolute;
z-index: 4;
top: calc(100% + 0.25rem);
right: 0;
display: flex;
width: max-content;
margin: 0;
padding: 0.35rem 0.6rem;
background: #fff;
border-radius: 0.75rem;
box-shadow: var(--hope-shadow);
}
.manage-menu-panel .check {
min-height: 0;
gap: 0.4rem;
}
.manage-menu-panel .check input {
accent-color: var(--hope-blue-quiet-ink);
}
.signup-board { .signup-board {
margin-top: 1.25rem; margin-top: 1.25rem;
} }
@@ -786,7 +1025,7 @@ main a:hover {
.day-card { .day-card {
overflow: hidden; overflow: hidden;
background: var(--hope-blue-50); background: #fff;
border-radius: 1.75rem; border-radius: 1.75rem;
box-shadow: var(--hope-shadow); box-shadow: var(--hope-shadow);
container: day / inline-size; container: day / inline-size;
@@ -848,7 +1087,7 @@ main a:hover {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
min-width: 0; min-width: 0;
background: var(--hope-blue-50); background: #fff;
} }
.shift-pane.is-ended::after { .shift-pane.is-ended::after {
@@ -1776,15 +2015,20 @@ article.shift-card {
} }
.details { .details {
margin: 1.25rem 0; display: grid;
padding: 0.4rem 1.15rem 0.9rem; grid-template-columns: repeat(2, minmax(0, 1fr));
background: var(--hope-blue-100); gap: 0.85rem 1.5rem;
border-radius: 1.5rem; margin: 0;
box-shadow: var(--hope-shadow); padding: 0;
} }
.details div { .details div {
margin: 0.7rem 0; margin: 0;
min-width: 0;
}
.details .is-wide {
grid-column: 1 / -1;
} }
.details dt { .details dt {
@@ -1793,6 +2037,7 @@ article.shift-card {
.details dd { .details dd {
margin: 0; margin: 0;
overflow-wrap: anywhere;
} }
.hp { .hp {
@@ -2083,13 +2328,24 @@ html:has(#signup-dialog[open]) {
margin: 0; margin: 0;
} }
.confirm-form h2 { .confirm-form h2,
.confirm-card > h2 {
margin: 0 1.8rem 0.1rem 0; margin: 0 1.8rem 0.1rem 0;
font-size: 1.2rem; font-size: 1.2rem;
line-height: 1.3; line-height: 1.3;
overflow-wrap: anywhere; overflow-wrap: anywhere;
} }
.confirm-card > p {
margin: 0;
font-size: 0.95rem;
line-height: 1.45;
}
#manage-cancel-dialog .confirm-card {
width: min(28rem, 100%);
}
.confirm-form p, .confirm-form p,
.confirm-detail, .confirm-detail,
.confirm-note { .confirm-note {
@@ -3755,6 +4011,38 @@ button.btn-quiet::before {
grid-template-columns: 1fr; grid-template-columns: 1fr;
} }
.details {
grid-template-columns: 1fr;
}
.manage-follow {
grid-template-columns: minmax(0, 1fr);
}
.manage-follow > .manage-action,
.manage-follow > .hint {
padding: 0;
}
.manage-follow > :last-child:not(:only-child) {
margin-top: 1.15rem;
padding-top: 1.15rem;
border-top: 1px solid var(--hope-border-2);
border-left: 0;
}
.manage-follow .manage-action-row button {
width: 100%;
}
.manage-record:has(.manage-tools) {
padding-top: 4.35rem;
}
.manage-record:has(.manage-tools) .details {
padding-right: 0;
}
.signup-form button, .signup-form button,
.cancel-form button, .cancel-form button,
.move-form button { .move-form button {
+25 -1
View File
@@ -2,6 +2,7 @@
bindNav(); bindNav();
bindCalendar(); bindCalendar();
bindViewMenu(); bindViewMenu();
bindManage();
document.querySelectorAll('[data-contact]').forEach(bindContact); document.querySelectorAll('[data-contact]').forEach(bindContact);
document.querySelectorAll('[data-see-more]').forEach(bindSeeMore); document.querySelectorAll('[data-see-more]').forEach(bindSeeMore);
@@ -25,7 +26,7 @@
} }
function bindViewMenu() { function bindViewMenu() {
var menus = document.querySelectorAll('details.view-menu'); var menus = document.querySelectorAll('details.view-menu, details.manage-menu');
if (!menus.length) return; if (!menus.length) return;
document.addEventListener('click', function (event) { document.addEventListener('click', function (event) {
for (var i = 0; i < menus.length; i += 1) { for (var i = 0; i < menus.length; i += 1) {
@@ -74,6 +75,29 @@
} }
} }
function bindManage() {
document.querySelectorAll('[data-reminder-toggle]').forEach(function (box) {
box.addEventListener('change', function () {
if (box.form) box.form.submit();
});
});
var opener = document.querySelector('[data-manage-cancel]');
var dialog = document.getElementById('manage-cancel-dialog');
if (!opener || !dialog || typeof dialog.showModal !== 'function') return;
opener.addEventListener('click', function (event) {
event.preventDefault();
if (dialog.open) dialog.close();
dialog.showModal();
dialog.classList.add('is-modal');
});
dialog.addEventListener('click', function (event) {
if (event.target === dialog) dialog.close();
});
dialog.addEventListener('close', function () {
dialog.classList.remove('is-modal');
});
}
function bindSeeMore(link) { function bindSeeMore(link) {
var list = document.getElementById('contacts-list'); var list = document.getElementById('contacts-list');
if (!list) return; if (!list) return;
+102 -37
View File
@@ -370,21 +370,44 @@ export function ManagePage(props: {
cancel: { action: string; token: string } | null; cancel: { action: string; token: string } | null;
switches: SwitchForm | null; switches: SwitchForm | null;
party?: PartyForm | null; party?: PartyForm | null;
reminders?: { action: string; token: string } | 'off' | null; reminders?: { action: string; token: string; on: boolean } | null;
notice?: string; notice?: string;
note?: string; note?: string;
}) { }) {
const signup = props.signup; const signup = props.signup;
const cancelled = signup.status !== 'confirmed';
return ( return (
<> <article class="manage">
<header class="manage-intro">
<h1>Your signup</h1> <h1>Your signup</h1>
<p class={signup.status === 'confirmed' ? 'status is-confirmed' : 'status'}>{signup.status === 'confirmed' ? 'Confirmed' : 'Cancelled'}</p> <p class={cancelled ? 'status is-cancelled' : 'status is-confirmed'}>{cancelled ? 'Cancelled' : 'Confirmed'}</p>
<p>{signup.eventTitle}</p> <p>{signup.eventTitle}</p>
<h2>{signup.role}</h2> <h2>{signup.role}</h2>
<p class="when"> <p class="when">
<time dateTime={signup.when.date}>{signup.when.dateLabel}</time> {signup.when.timeLabel} {signup.when.abbreviation} <time dateTime={signup.when.date}>{signup.when.dateLabel}</time> {signup.when.timeLabel} {signup.when.abbreviation}
</p> </p>
{signup.location ? <p class="location">{signup.location}</p> : null} {signup.location ? <p class="location">{signup.location}</p> : null}
</header>
{props.note ? <p class="status">{props.note}</p> : null}
{props.notice ? (
<p class="error" role="alert">
{props.notice}
</p>
) : null}
<section class="manage-record">
{props.cancel || props.reminders ? (
<div class="manage-tools">
<ReminderMenu reminders={props.reminders} />
{props.cancel ? (
<form id="manage-cancel-form" class="manage-cancel" method="post" action={props.cancel.action}>
<input type="hidden" name="cancel_token" value={props.cancel.token} />
<button type="submit" class="manage-x" aria-label="Cancel this signup" aria-haspopup="dialog" data-manage-cancel="">
<span aria-hidden="true">×</span>
</button>
</form>
) : null}
</div>
) : null}
<dl class="details"> <dl class="details">
<div> <div>
<dt>Name</dt> <dt>Name</dt>
@@ -405,42 +428,57 @@ export function ManagePage(props: {
</div> </div>
) : null} ) : null}
{signup.notes ? ( {signup.notes ? (
<div> <div class="is-wide">
<dt>Notes</dt> <dt>Notes</dt>
<dd class="description">{signup.notes}</dd> <dd class="description">{signup.notes}</dd>
</div> </div>
) : null} ) : null}
</dl> </dl>
{props.note ? <p class="status">{props.note}</p> : null} {props.party || props.switches ? (
{props.notice ? ( <div class="manage-follow">
<p class="error" role="alert"> {props.party ? (
{props.notice} <form class="move-form manage-action" method="post" action={props.party.action}>
<input type="hidden" name="party_token" value={props.party.token} />
<div class="manage-action-row">
<label for="manage-partySize">
How many people?
<select
id="manage-partySize"
name="party_size"
aria-invalid={props.party.error ? 'true' : undefined}
aria-describedby={props.party.error ? 'manage-partySize-hint manage-partySize-error' : 'manage-partySize-hint'}
>
{partyChoices(props.party.remaining).map((count) => (
<option key={count} value={String(count)} selected={props.party.value === String(count) ? true : undefined}>
{partyChoiceLabel(count)}
</option>
))}
</select>
</label>
<button type="submit">Save</button>
</div>
<p class="hint" id="manage-partySize-hint">
Including you. This holds that many spots, and the name stays the same.
</p>
{props.party.error ? (
<p class="field-error" id="manage-partySize-error">
{props.party.error}
</p> </p>
) : null} ) : null}
{props.party ? (
<form class="move-form" method="post" action={props.party.action}>
<p>Change how many people are coming. The signup stays, and the name stays the same.</p>
<input type="hidden" name="party_token" value={props.party.token} />
<PartySizeField idPrefix="manage" value={props.party.value} error={props.party.error} remaining={props.party.remaining} />
<button type="submit">Save the number of people</button>
</form> </form>
) : null} ) : null}
{props.switches ? ( {props.switches ? (
props.switches.targets.length === 0 ? ( props.switches.targets.length === 0 ? (
<p> <p class="hint">
{signup.groupSize > 1 {signup.groupSize > 1
? 'There is no other open shift with room for everyone on this signup.' ? 'There is no other open shift with room for everyone on this signup.'
: 'There is no other open shift you can switch to.'} : 'There is no other open shift you can switch to.'}
</p> </p>
) : ( ) : (
<form class="move-form" method="post" action={props.switches.action}> <form class="move-form manage-action" method="post" action={props.switches.action}>
<p>
{signup.groupSize > 1
? `Switch to another shift in this event. This opens the ${signup.groupSize} spots here and queues a change email. This link stops working, and the next page has the new one.`
: 'Switch to another shift in this event. This opens your spot here and queues a change email. This link stops working, and the next page has the new one.'}
</p>
<input type="hidden" name="switch_token" value={props.switches.token} /> <input type="hidden" name="switch_token" value={props.switches.token} />
<input type="hidden" name="form_token" value={props.switches.formToken} /> <input type="hidden" name="form_token" value={props.switches.formToken} />
<div class="manage-action-row">
<label for="switch-to"> <label for="switch-to">
Switch to Switch to
<select id="switch-to" name="destination" required> <select id="switch-to" name="destination" required>
@@ -448,30 +486,42 @@ export function ManagePage(props: {
</select> </select>
</label> </label>
<button type="submit">Switch</button> <button type="submit">Switch</button>
</div>
<p class="hint">
{signup.groupSize > 1
? `Opens these ${signup.groupSize} spots, queues a change email, and replaces this link.`
: 'Opens your spot here, queues a change email, and replaces this link.'}
</p>
</form> </form>
) )
) : null} ) : null}
{props.reminders === 'off' ? ( </div>
<p>Reminder emails for this signup are off. The signup stays. Confirmation, change, and cancellation emails still arrive.</p>
) : null}
<div class="manage-actions">
{props.reminders && props.reminders !== 'off' ? (
<form class="cancel-form" method="post" action={props.reminders.action}>
<p>Stop reminder emails for this signup. The signup stays. Confirmation, change, and cancellation emails still arrive.</p>
<input type="hidden" name="reminder_token" value={props.reminders.token} />
<button type="submit">Stop reminder emails</button>
</form>
) : null} ) : null}
</section>
{props.cancel ? ( {props.cancel ? (
<form class="cancel-form" method="post" action={props.cancel.action}> <dialog id="manage-cancel-dialog" class="confirm-dialog" aria-labelledby="manage-cancel-title">
<div class="confirm-card">
<form method="dialog" id="manage-cancel-dismiss" class="confirm-x">
<button type="submit" class="event-dialog-close" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</form>
<h2 id="manage-cancel-title">Are you sure you want to cancel?</h2>
<p> <p>
{signup.groupSize > 1 {signup.groupSize > 1
? `Cancel this signup to open these ${signup.groupSize} spots for someone else. A cancellation email is queued when you cancel.` ? `Cancel this signup to open these ${signup.groupSize} spots for someone else. A cancellation email is queued when you cancel.`
: 'Cancel this signup to open the spot for someone else. A cancellation email is queued when you cancel.'} : 'Cancel this signup to open the spot for someone else. A cancellation email is queued when you cancel.'}
</p> </p>
<input type="hidden" name="cancel_token" value={props.cancel.token} /> <div class="confirm-actions">
<button type="submit">Cancel this signup</button> <button type="submit" form="manage-cancel-form">
</form> Cancel this signup
</button>
<button type="submit" class="btn-quiet" form="manage-cancel-dismiss">
Go back
</button>
</div>
</div>
</dialog>
) : ( ) : (
<p> <p>
{signup.groupSize > 1 {signup.groupSize > 1
@@ -479,8 +529,23 @@ export function ManagePage(props: {
: 'This signup is cancelled. The spot is open for someone else. A cancellation email is queued.'} : 'This signup is cancelled. The spot is open for someone else. A cancellation email is queued.'}
</p> </p>
)} )}
</div> </article>
</> );
}
function ReminderMenu(props: { reminders?: { action: string; token: string; on: boolean } | null }) {
if (!props.reminders) return null;
return (
<details class="manage-menu">
<summary>Reminders</summary>
<form class="manage-menu-panel" method="post" action={props.reminders.action}>
<input type="hidden" name="reminder_token" value={props.reminders.token} />
<label class="check">
<input type="checkbox" name="reminders" value="on" checked={props.reminders.on} data-reminder-toggle="" />
On
</label>
</form>
</details>
); );
} }
+26 -1
View File
@@ -75,6 +75,8 @@ export function queueDueReminders(db: Database.Database, mail: MailIdentity, sec
}).immediate(); }).immediate();
} }
const REMINDERS_OFF_REASON = 'Reminders were turned off before this message was sent.';
/** Turns reminders off for one signup. Confirmation, change, and cancellation mail still queue. */ /** Turns reminders off for one signup. Confirmation, change, and cancellation mail still queue. */
export function disableReminders( export function disableReminders(
db: Database.Database, db: Database.Database,
@@ -89,11 +91,34 @@ export function disableReminders(
if (row.reminders_off !== 1) { if (row.reminders_off !== 1) {
db.prepare('UPDATE signups SET reminders_off = 1, updated_at = ? WHERE id = ? AND anonymized_at IS NULL').run(now, signupId); db.prepare('UPDATE signups SET reminders_off = 1, updated_at = ? WHERE id = ? AND anonymized_at IS NULL').run(now, signupId);
} }
cancelPendingReminders(db, signupId, 'Reminders were turned off before this message was sent.'); cancelPendingReminders(db, signupId, REMINDERS_OFF_REASON);
return { ok: true, already: row.reminders_off === 1 }; return { ok: true, already: row.reminders_off === 1 };
}).immediate(); }).immediate();
} }
/** Turns reminders back on and restores a reminder that was cancelled only because they were off. */
export function enableReminders(
db: Database.Database,
signupId: number,
now: string,
): { ok: true } | { ok: false } {
return db.transaction((): { ok: true } | { ok: false } => {
const row = db
.prepare('SELECT reminders_off AS reminders_off FROM signups WHERE id = ? AND anonymized_at IS NULL')
.get(signupId) as { reminders_off: number } | undefined;
if (!row) return { ok: false };
if (row.reminders_off === 1) {
db.prepare('UPDATE signups SET reminders_off = 0, updated_at = ? WHERE id = ? AND anonymized_at IS NULL').run(now, signupId);
}
db.prepare(
`UPDATE outbox
SET status = 'pending', last_error = NULL
WHERE signup_id = ? AND kind = 'reminder' AND status = 'cancelled' AND last_error = ?`,
).run(signupId, REMINDERS_OFF_REASON);
return { ok: true };
}).immediate();
}
export function issueReminderOffToken(secret: string, signupId: number): string { export function issueReminderOffToken(secret: string, signupId: number): string {
const id = String(signupId); const id = String(signupId);
const mac = createHmac('sha256', secret).update(`hope-reminder-off-v1\0${id}`).digest('base64url'); const mac = createHmac('sha256', secret).update(`hope-reminder-off-v1\0${id}`).digest('base64url');
+11 -7
View File
@@ -30,7 +30,7 @@ import { getPublicShift, type PublicShift } from './schedule.js';
import { SIGNUP_TOO_EARLY } from './signup-window.js'; import { SIGNUP_TOO_EARLY } from './signup-window.js';
import { EMPTY_SIGNUP, parsePartySize, parseSignupForm, spotsLeftMessage, type SignupErrors, type SignupValues } from './signup-form.js'; import { EMPTY_SIGNUP, parsePartySize, parseSignupForm, spotsLeftMessage, type SignupErrors, type SignupValues } from './signup-form.js';
import type { MailIdentity } from './mail/types.js'; import type { MailIdentity } from './mail/types.js';
import { disableReminders } from './reminders.js'; import { disableReminders, enableReminders, queueDueReminders } from './reminders.js';
import { cancelSignup, changePartySize, confirmedOperationShift, findSignupByOperation, managePartyLimit, readManageSignup, reserveSignup } from './signup.js'; import { cancelSignup, changePartySize, confirmedOperationShift, findSignupByOperation, managePartyLimit, readManageSignup, reserveSignup } from './signup.js';
import { verifyTurnstile, type TurnstileCheck, type TurnstileVerdict } from './turnstile.js'; import { verifyTurnstile, type TurnstileCheck, type TurnstileVerdict } from './turnstile.js';
import { appPath, cookiePath } from './url.js'; import { appPath, cookiePath } from './url.js';
@@ -105,7 +105,7 @@ export function registerPublicSignup(app: Hono, services: SignupServices): void
app.post(appPath(config, '/m/:token/switch'), (c) => submitSwitch(c, services)); app.post(appPath(config, '/m/:token/switch'), (c) => submitSwitch(c, services));
app.post(appPath(config, '/m/:token/party'), (c) => submitParty(c, services)); app.post(appPath(config, '/m/:token/party'), (c) => submitParty(c, services));
app.post(appPath(config, '/m/:token/reminders'), (c) => submitRemindersOff(c, services)); app.post(appPath(config, '/m/:token/reminders'), (c) => submitReminders(c, services));
app.post(appPath(config, '/m/:token'), (c) => submitCancel(c, services)); app.post(appPath(config, '/m/:token'), (c) => submitCancel(c, services));
} }
@@ -503,16 +503,16 @@ function reminderForm(
services: SignupServices, services: SignupServices,
token: string, token: string,
signup: { status: 'confirmed' | 'cancelled'; remindersOff: boolean }, signup: { status: 'confirmed' | 'cancelled'; remindersOff: boolean },
): { action: string; token: string } | 'off' | null { ): { action: string; token: string; on: boolean } | null {
if (signup.status !== 'confirmed') return null; if (signup.status !== 'confirmed') return null;
if (signup.remindersOff) return 'off';
return { return {
action: appPath(services.config, `/m/${token}/reminders`), action: appPath(services.config, `/m/${token}/reminders`),
token: issueReminderPageToken(services.config.sessionSecret, token), token: issueReminderPageToken(services.config.sessionSecret, token),
on: !signup.remindersOff,
}; };
} }
async function submitRemindersOff(c: Context, services: SignupServices): Promise<Response> { async function submitReminders(c: Context, services: SignupServices): Promise<Response> {
const token = c.req.param('token') ?? ''; const token = c.req.param('token') ?? '';
const signup = readManageSignup(services.db, token, services.now()); const signup = readManageSignup(services.db, token, services.now());
if (!signup) return missingManage(c, services); if (!signup) return missingManage(c, services);
@@ -523,12 +523,16 @@ async function submitRemindersOff(c: Context, services: SignupServices): Promise
if (!reminderPageTokenMatches(services.config.sessionSecret, token, textField(body, 'reminder_token'))) { if (!reminderPageTokenMatches(services.config.sessionSecret, token, textField(body, 'reminder_token'))) {
return showManage(c, services, token, 400, CANCEL_REJECTED); return showManage(c, services, token, 400, CANCEL_REJECTED);
} }
const on = textField(body, 'reminders') === 'on';
try { try {
const result = disableReminders(services.db, signup.signupId, services.now()); const result = on
? enableReminders(services.db, signup.signupId, services.now())
: disableReminders(services.db, signup.signupId, services.now());
if (!result.ok) return missingManage(c, services); if (!result.ok) return missingManage(c, services);
if (on) queueDueReminders(services.db, mailIdentity(services.db, services.config), services.config.sessionSecret, services.now());
} catch (err) { } catch (err) {
if (!isBusy(err)) throw err; if (!isBusy(err)) throw err;
console.error('Reminder opt-out could not lock the database.'); console.error('Reminder setting could not lock the database.');
return showManage(c, services, token, 503, CANCEL_UNAVAILABLE); return showManage(c, services, token, 503, CANCEL_UNAVAILABLE);
} }
c.header('Cache-Control', 'no-store'); c.header('Cache-Control', 'no-store');
+2 -4
View File
@@ -333,10 +333,8 @@ describe('manage-link party size', () => {
const html = await viewed.text(); const html = await viewed.text();
expect(viewed.status).toBe(200); expect(viewed.status).toBe(200);
expect(html).toContain('How many people?'); expect(html).toContain('How many people?');
expect(html).toContain('This signup holds that many spots.'); expect(html).toContain('Including you. This holds that many spots, and the name stays the same.');
expect(html).toContain('You don&#39;t need to add their names.'); expect(html).toContain('>Save<');
expect(html).toContain('Change how many people are coming. The signup stays, and the name stays the same.');
expect(html).toContain('Save the number of people');
expect(partyOptions(html)).toEqual(['1', '2', '3', '4', '5', '6']); expect(partyOptions(html)).toEqual(['1', '2', '3', '4', '5', '6']);
expect(html).toContain('<dd>4</dd>'); expect(html).toContain('<dd>4</dd>');
expect(db.prepare('SELECT group_size, updated_at FROM signups').get()).toEqual({ expect(db.prepare('SELECT group_size, updated_at FROM signups').get()).toEqual({
+16 -3
View File
@@ -176,10 +176,11 @@ describe('reminder mail', () => {
const saved = reserveSignup(db, reservation(shiftId)); const saved = reserveSignup(db, reservation(shiftId));
expect(saved.ok && saved.manageToken).toBeTruthy(); expect(saved.ok && saved.manageToken).toBeTruthy();
if (!saved.ok || !saved.manageToken) return; if (!saved.ok || !saved.manageToken) return;
queueDueReminders(db, MAIL, SECRET, NOW);
const page = await app.request(`/m/${saved.manageToken}`); const page = await app.request(`/m/${saved.manageToken}`);
const html = await page.text(); const html = await page.text();
const token = /name="reminder_token"[^>]*value="([^"]*)"/.exec(html)?.[1] ?? ''; const token = /name="reminder_token"[^>]*value="([^"]*)"/.exec(html)?.[1] ?? '';
expect(html).toContain('Stop reminder emails'); expect(html).toContain('data-reminder-toggle');
const stopped = await app.request(`/m/${saved.manageToken}/reminders`, { const stopped = await app.request(`/m/${saved.manageToken}/reminders`, {
method: 'POST', method: 'POST',
@@ -188,10 +189,22 @@ describe('reminder mail', () => {
}); });
expect(stopped.status).toBe(303); expect(stopped.status).toBe(303);
expect(db.prepare(`SELECT reminders_off, status FROM signups`).get()).toEqual({ reminders_off: 1, status: 'confirmed' }); expect(db.prepare(`SELECT reminders_off, status FROM signups`).get()).toEqual({ reminders_off: 1, status: 'confirmed' });
expect(db.prepare(`SELECT status FROM outbox WHERE kind = 'reminder'`).get()).toEqual({ status: 'cancelled' });
const after = await app.request(`/m/${saved.manageToken}`); const after = await app.request(`/m/${saved.manageToken}`);
const afterHtml = await after.text(); const afterHtml = await after.text();
expect(afterHtml).toContain('Reminder emails for this signup are off.'); expect(afterHtml).toContain('name="reminder_token"');
expect(afterHtml).not.toContain('name="reminder_token"'); expect(afterHtml).not.toContain('checked');
const resumed = await app.request(`/m/${saved.manageToken}/reminders`, {
method: 'POST',
headers: { origin: ORIGIN, 'content-type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({ reminder_token: token, reminders: 'on' }),
});
expect(resumed.status).toBe(303);
expect(db.prepare(`SELECT reminders_off, status FROM signups`).get()).toEqual({ reminders_off: 0, status: 'confirmed' });
expect(db.prepare(`SELECT status FROM outbox WHERE kind = 'reminder'`).get()).toEqual({ status: 'pending' });
const resumedHtml = await (await app.request(`/m/${saved.manageToken}`)).text();
expect(resumedHtml).toContain('checked');
}); });
}); });