From 1f451dc8300d56a329936c0148f25b386d1c8e86 Mon Sep 17 00:00:00 2001
From: blake
Date: Wed, 28 Oct 2026 10:54:22 -0500
Subject: [PATCH] feat: implement signup dialog for event registration
Added a new signup dialog component that opens when users click on signup links. The dialog fetches and displays the signup form dynamically, enhancing user experience. Updated styles for the dialog and integrated it into the public schedule page. Adjusted asset loading rules to accommodate the new functionality.
---
public/css/app.css | 103 +++++++++++++-
public/js/signup-dialog.js | 275 +++++++++++++++++++++++++++++++++++++
src/pages.tsx | 21 ++-
src/static-assets.ts | 4 +-
tests/public-pages.test.ts | 6 +
5 files changed, 401 insertions(+), 8 deletions(-)
create mode 100644 public/js/signup-dialog.js
diff --git a/public/css/app.css b/public/css/app.css
index 3bdc382..ff435ed 100644
--- a/public/css/app.css
+++ b/public/css/app.css
@@ -313,10 +313,10 @@ a.btn:active {
align-items: center;
gap: 28px;
margin: 0;
- padding: 4px 30px;
- background: #fff;
- border: 1px solid var(--hope-border-2);
- border-radius: 50px;
+ padding: 0;
+ background: transparent;
+ border: 0;
+ border-radius: 0;
box-shadow: none;
font-size: 18px;
line-height: 1;
@@ -1597,6 +1597,101 @@ article.shift-card {
height: 1.15rem;
}
+html:has(#signup-dialog[open]) {
+ overflow: hidden;
+}
+
+#signup-dialog {
+ overflow: hidden;
+}
+
+.signup-dialog-card {
+ width: min(36rem, 100%);
+ max-height: calc(100dvh - 2rem);
+}
+
+.signup-dialog-close {
+ position: absolute;
+ top: 0.85rem;
+ right: 0.85rem;
+ z-index: 2;
+}
+
+#signup-dialog-body {
+ box-sizing: border-box;
+ overflow: hidden;
+ border-radius: 1.75rem;
+ max-height: inherit;
+ /* Keep the scrollbar off the curved corners. */
+ padding: 1.35rem 0.55rem 1.35rem 0;
+ background: var(--hope-blue-100);
+ box-shadow: var(--hope-shadow);
+}
+
+.signup-dialog-panel {
+ display: grid;
+ width: 100%;
+ max-height: calc(100dvh - 2rem - 2.7rem);
+ overflow: auto;
+ overscroll-behavior: contain;
+ background: transparent;
+ scrollbar-width: thin;
+ scrollbar-color: rgb(34 34 34 / 0.45) transparent;
+}
+
+.signup-dialog-panel::-webkit-scrollbar {
+ width: 10px;
+}
+
+.signup-dialog-panel::-webkit-scrollbar-track {
+ background: transparent;
+}
+
+.signup-dialog-panel::-webkit-scrollbar-thumb {
+ background: rgb(34 34 34 / 0.35);
+ border: 2px solid var(--hope-blue-100);
+ border-radius: 999px;
+}
+
+.signup-dialog-summary {
+ display: grid;
+ gap: 0.15rem;
+ padding: 0 3.4rem 0.15rem 1.35rem;
+}
+
+.signup-dialog-title {
+ margin: 0;
+ font-size: 1.6rem;
+ overflow-wrap: anywhere;
+}
+
+.signup-dialog-summary .location,
+.signup-dialog-summary .when,
+.signup-dialog-summary .status,
+.signup-dialog-summary .spots {
+ margin: 0;
+}
+
+.signup-dialog-note {
+ margin: 0;
+ padding: 0.35rem 1.35rem 1.35rem;
+}
+
+.event-dialog .signup-dialog-panel .signup-form {
+ max-width: none;
+ max-height: none;
+ margin: 0;
+ overflow: visible;
+ background: transparent;
+ box-shadow: none;
+ border-radius: 0;
+}
+
+.event-dialog .signup-dialog-panel .signup-form h2 {
+ padding-right: 0;
+ font-size: 1.25rem;
+}
+
.confirm-dialog {
width: 100%;
max-width: none;
diff --git a/public/js/signup-dialog.js b/public/js/signup-dialog.js
new file mode 100644
index 0000000..eee1140
--- /dev/null
+++ b/public/js/signup-dialog.js
@@ -0,0 +1,275 @@
+(function () {
+ var dialog = document.getElementById('signup-dialog');
+ var body = document.getElementById('signup-dialog-body');
+ if (!dialog || !body || typeof dialog.showModal !== 'function') return;
+
+ var requestId = 0;
+ var widgetId = null;
+ var turnstileLoading = null;
+ var lastTrigger = null;
+
+ document.querySelectorAll('a[data-signup]').forEach(function (link) {
+ link.setAttribute('aria-haspopup', 'dialog');
+ link.setAttribute('aria-controls', 'signup-dialog');
+ });
+
+ document.addEventListener('click', function (event) {
+ var link = event.target && event.target.closest ? event.target.closest('a[data-signup]') : null;
+ if (!link) return;
+ if (event.defaultPrevented || event.button !== 0) return;
+ if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
+ var href = link.getAttribute('href');
+ if (!href) return;
+ event.preventDefault();
+ openSignup(link, href);
+ });
+
+ var closeButton = dialog.querySelector('[data-signup-close]');
+ if (closeButton) closeButton.addEventListener('click', function () { dialog.close(); });
+
+ dialog.addEventListener('click', function (event) {
+ if (event.target === dialog) dialog.close();
+ });
+
+ dialog.addEventListener('close', function () {
+ requestId += 1;
+ clearWidget();
+ dialog.classList.remove('is-modal');
+ dialog.removeAttribute('aria-busy');
+ if (lastTrigger && typeof lastTrigger.focus === 'function') lastTrigger.focus();
+ });
+
+ function openSignup(link, href) {
+ lastTrigger = link;
+ var id = ++requestId;
+ showLoading();
+ if (!dialog.open) {
+ dialog.showModal();
+ dialog.classList.add('is-modal');
+ }
+ fetch(href, { credentials: 'same-origin', cache: 'no-store', headers: { Accept: 'text/html' } })
+ .then(function (response) {
+ return response.text();
+ })
+ .then(function (html) {
+ if (id !== requestId) return;
+ fill(html, href);
+ })
+ .catch(function () {
+ if (id !== requestId) return;
+ showFailure(href);
+ });
+ }
+
+ function showLoading() {
+ clearWidget();
+ dialog.setAttribute('aria-busy', 'true');
+ var panel = panelWithTitle('Sign up');
+ var note = document.createElement('p');
+ note.className = 'signup-dialog-note';
+ note.setAttribute('role', 'status');
+ note.textContent = 'Loading the signup form.';
+ panel.appendChild(note);
+ body.replaceChildren(panel);
+ }
+
+ function showFailure(href) {
+ clearWidget();
+ dialog.removeAttribute('aria-busy');
+ var panel = panelWithTitle('Sign up');
+ var note = document.createElement('p');
+ note.className = 'signup-dialog-note';
+ note.textContent = 'The signup form could not be loaded. ';
+ var link = document.createElement('a');
+ link.href = href;
+ link.textContent = 'Open the shift page';
+ note.appendChild(link);
+ panel.appendChild(note);
+ body.replaceChildren(panel);
+ if (closeButton) closeButton.focus();
+ }
+
+ function fill(html, href) {
+ var doc = new DOMParser().parseFromString(html, 'text/html');
+ var main = doc.querySelector('main');
+ if (!main) {
+ showFailure(href);
+ return;
+ }
+ var form = main.querySelector('form.signup-form');
+ var heading = main.querySelector('h1');
+ clearWidget();
+ dialog.removeAttribute('aria-busy');
+ var panel = document.createElement('div');
+ panel.className = 'signup-dialog-panel';
+ var summary = document.createElement('div');
+ summary.className = 'signup-dialog-summary';
+ var title = document.createElement('h2');
+ title.id = 'signup-dialog-label';
+ title.className = 'signup-dialog-title';
+ title.textContent = heading && heading.textContent ? heading.textContent.trim() : 'Sign up';
+ summary.appendChild(title);
+ appendFrom(summary, main, 'p.location');
+ appendFrom(summary, main, 'p.when');
+ appendFrom(summary, main, 'p.status');
+ appendFrom(summary, main, 'p.spots');
+ var notice = main.querySelector('p.error');
+ if (notice && (!form || !form.contains(notice))) summary.appendChild(document.importNode(notice, true));
+ panel.appendChild(summary);
+ if (!form) {
+ var closed = document.createElement('p');
+ closed.className = 'signup-dialog-note';
+ var paragraph = main.querySelector('p');
+ if (!main.querySelector('p.when') && paragraph) {
+ closed.textContent = paragraph.textContent.trim();
+ } else {
+ closed.textContent = 'This shift is not open for signup.';
+ }
+ panel.appendChild(closed);
+ body.replaceChildren(panel);
+ if (closeButton) closeButton.focus();
+ return;
+ }
+ var liveForm = document.importNode(form, true);
+ liveForm.querySelectorAll('noscript').forEach(function (node) { node.remove(); });
+ panel.appendChild(liveForm);
+ body.replaceChildren(panel);
+ bindForm(liveForm);
+ mountTurnstile(liveForm);
+ var field = firstField(liveForm);
+ if (field) field.focus();
+ }
+
+ function bindForm(form) {
+ form.addEventListener('submit', function (event) {
+ event.preventDefault();
+ if (form.getAttribute('data-sending') === 'true') return;
+ var action = form.getAttribute('action');
+ if (!action) return;
+ form.setAttribute('data-sending', 'true');
+ var submit = form.querySelector('button[type="submit"]');
+ if (submit) {
+ submit.disabled = true;
+ submit.textContent = 'Signing up…';
+ }
+ var id = requestId;
+ fetch(action, {
+ method: 'POST',
+ body: new URLSearchParams(new FormData(form)),
+ credentials: 'same-origin',
+ cache: 'no-store',
+ headers: { Accept: 'text/html' },
+ })
+ .then(function (response) {
+ if (isConfirmed(response)) {
+ window.location.assign(response.url);
+ return null;
+ }
+ return response.text();
+ })
+ .then(function (html) {
+ if (html === null || id !== requestId) return;
+ fill(html, action);
+ })
+ .catch(function () {
+ if (id !== requestId || !form.isConnected) return;
+ form.removeAttribute('data-sending');
+ if (submit) {
+ submit.disabled = false;
+ submit.textContent = 'Sign up';
+ }
+ var alert = form.querySelector('[data-signup-send-error]');
+ if (!alert) {
+ alert = document.createElement('p');
+ alert.className = 'error';
+ alert.setAttribute('role', 'alert');
+ alert.setAttribute('data-signup-send-error', '');
+ form.insertBefore(alert, form.firstChild);
+ }
+ alert.textContent = 'The signup could not be sent. Please try again.';
+ });
+ });
+ }
+
+ function mountTurnstile(scope) {
+ var widget = scope.querySelector('.cf-turnstile');
+ var sitekey = widget && widget.getAttribute('data-sitekey');
+ if (!widget || !sitekey) return;
+ loadTurnstile()
+ .then(function () {
+ if (!widget.isConnected || !window.turnstile) return;
+ // turnstile.ready() throws when this script is inserted dynamically.
+ widgetId = window.turnstile.render(widget, {
+ sitekey: sitekey,
+ action: widget.getAttribute('data-action') || 'signup',
+ });
+ })
+ .catch(function () {});
+ }
+
+ function loadTurnstile() {
+ if (window.turnstile) return Promise.resolve();
+ if (turnstileLoading) return turnstileLoading;
+ turnstileLoading = new Promise(function (resolve, reject) {
+ var script = document.createElement('script');
+ script.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit';
+ script.onload = function () { resolve(); };
+ script.onerror = function () {
+ turnstileLoading = null;
+ reject(new Error('Turnstile did not load.'));
+ };
+ document.head.appendChild(script);
+ });
+ return turnstileLoading;
+ }
+
+ function clearWidget() {
+ if (widgetId !== null && window.turnstile && window.turnstile.remove) {
+ try {
+ window.turnstile.remove(widgetId);
+ } catch (err) {
+ // The widget node is already gone.
+ }
+ }
+ widgetId = null;
+ }
+
+ function panelWithTitle(text) {
+ var panel = document.createElement('div');
+ panel.className = 'signup-dialog-panel';
+ var summary = document.createElement('div');
+ summary.className = 'signup-dialog-summary';
+ var title = document.createElement('h2');
+ title.id = 'signup-dialog-label';
+ title.className = 'signup-dialog-title';
+ title.textContent = text;
+ summary.appendChild(title);
+ panel.appendChild(summary);
+ return panel;
+ }
+
+ function appendFrom(parent, root, selector) {
+ var node = root.querySelector(selector);
+ if (node) parent.appendChild(document.importNode(node, true));
+ }
+
+ function firstField(form) {
+ var invalid = form.querySelector('[aria-invalid="true"]');
+ if (invalid && typeof invalid.focus === 'function') return invalid;
+ var inputs = form.querySelectorAll('input, textarea, select');
+ for (var i = 0; i < inputs.length; i += 1) {
+ var input = inputs[i];
+ if (input.type === 'hidden' || input.tabIndex < 0) continue;
+ return input;
+ }
+ return null;
+ }
+
+ function isConfirmed(response) {
+ try {
+ return /\/confirmed\/?$/.test(new URL(response.url, window.location.href).pathname);
+ } catch (err) {
+ return false;
+ }
+ }
+})();
diff --git a/src/pages.tsx b/src/pages.tsx
index fe975d0..6183720 100644
--- a/src/pages.tsx
+++ b/src/pages.tsx
@@ -543,10 +543,27 @@ function PublicSchedule(props: {
) : (
)}
+
);
}
+function SignupDialog(props: { config: AppConfig }) {
+ return (
+ <>
+
+
+ >
+ );
+}
+
type WednesdayGroup = {
date: string;
heading: string;
@@ -622,7 +639,7 @@ function ShiftPane(props: { config: AppConfig; shift: PublicShift }) {
Not accepting more signups
) : (
-
+
{action}
@@ -794,7 +811,7 @@ function CalendarShift(props: { config: AppConfig; shift: PublicShift }) {
const closed = shift.full || shift.cancelled || shift.ended;
const action = closed ? 'View shift' : 'Sign up';
return (
-
+
{shift.when.startLabel} {shift.role}
diff --git a/src/static-assets.ts b/src/static-assets.ts
index 03edf47..23883d5 100644
--- a/src/static-assets.ts
+++ b/src/static-assets.ts
@@ -15,7 +15,7 @@ const ASSET_ROOTS = ['css', 'brand', 'img', 'js'];
/**
* Same-origin GET links are fetched on hover.
- * Confirm and new-event controls open a dialog instead of navigating.
+ * Confirm, new-event, and signup controls open a dialog instead of navigating.
* Cross-origin links are not eligible unless a rule asks for them.
*/
export const SPECULATION_RULES = {
@@ -25,7 +25,7 @@ export const SPECULATION_RULES = {
where: {
and: [
{ href_matches: '/*' },
- { not: { selector_matches: '[data-confirm], [data-open-event]' } },
+ { not: { selector_matches: '[data-confirm], [data-open-event], [data-signup]' } },
],
},
eagerness: 'moderate',
diff --git a/tests/public-pages.test.ts b/tests/public-pages.test.ts
index d8dcd14..b3900a9 100644
--- a/tests/public-pages.test.ts
+++ b/tests/public-pages.test.ts
@@ -90,6 +90,9 @@ describe('public pages', () => {
expect(html).not.toContain('