feat: open the next three months of Wednesday shifts on the public list
Volunteers can see who is signed up, and a full shift stays closed. Coordinators can see a contact's current and past shifts.
This commit is contained in:
1 parent
e7c99a788e
commit
1a8959c86a
26 files changed
+1402
-192
No files matched your search
@@ -10,7 +10,7 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|||||||
|
|
||||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
**This is not ready for a public launch, and it is not ready for real volunteer records.** Phase 1A has public browsing, individual signup, cancellation, queued email, and coordinator sign-in for events, one-off shifts, rosters, and cancellation. A coordinator can add a walk-in, mark attendance, and move a signup from a shift roster. A volunteer can switch shifts from their private link. An active weekly template fills shifts for the next eight weeks. A coordinator can add, change, or end a weekly template, and can remove a cancelled person, a finished empty shift, an ended template, or an event that is off the public list and already empty. A confirmed signup can receive a reminder 48 hours before the shift and again 2 hours before, and can turn reminders off without cancelling. A coordinator can download a roster for one shift, one event, or a local date range. A coordinator can import a contact list, download it, use a saved contact when adding a walk-in, and add a saved contact to an open shift. A coordinator can set the two reminder times, the reply-to address, how many months to keep a signup, and the wording on the privacy page. A signed-in administrator can add another administrator. Removing someone takes away their sign-in access. The last administrator cannot be removed. After 1:00 AM Central Time, signups older than that many months lose their name and contact details in this app. After 2:30 AM Central Time, the app saves a database backup on this computer. A container can run that same app on this computer, on port 3020, without opening it to the network. This is not a public launch. Around 1:00 AM in each event's time zone, the app adds any missing weekly shifts for the next eight weeks, once that local day. Development prints mail in the server log. It does not send real email.
|
**This is not ready for a public launch, and it is not ready for real volunteer records.** Phase 1A has public browsing, individual signup, cancellation, queued email, and coordinator sign-in for events, one-off shifts, rosters, and cancellation. A coordinator can add a walk-in, mark attendance, and move a signup from a shift roster. A volunteer can switch shifts from their private link. An active weekly template fills shifts for the next three months. A coordinator can add, change, or end a weekly template, and can remove a cancelled person, a finished empty shift, an ended template, or an event that is off the public list and already empty. A confirmed signup can receive a reminder 48 hours before the shift and again 2 hours before, and can turn reminders off without cancelling. A coordinator can download a roster for one shift, one event, or a local date range. A coordinator can import a contact list, download it, open a person to see current and past shifts, use a saved contact when adding a walk-in, and add a saved contact to an open shift. A coordinator can set the two reminder times, the reply-to address, how many months to keep a signup, and the wording on the privacy page. A signed-in administrator can add another administrator. Removing someone takes away their sign-in access. The last administrator cannot be removed. After 1:00 AM Central Time, signups older than that many months lose their name and contact details in this app. After 2:30 AM Central Time, the app saves a database backup on this computer. A container can run that same app on this computer, on port 3020, without opening it to the network. This is not a public launch. Around 1:00 AM in each event's time zone, the app adds any missing weekly shifts for the next eight weeks, once that local day. Development prints mail in the server log. It does not send real email.
|
||||||
|
|
||||||
## Current step
|
## Current step
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ You should have received a copy of the GNU General Public License along with thi
|
|||||||
| Move a signup to another shift | Done |
|
| Move a signup to another shift | Done |
|
||||||
| Switch your own signup to another shift | Done |
|
| Switch your own signup to another shift | Done |
|
||||||
| Manage other signups from one private link | Disabled; requires a separate verified identity flow |
|
| Manage other signups from one private link | Disabled; requires a separate verified identity flow |
|
||||||
| Add weekly shifts for the next eight weeks | Done |
|
| Add weekly shifts for the next three months | Done |
|
||||||
| Add, change, or end a weekly template | Done |
|
| Add, change, or end a weekly template | Done |
|
||||||
| Remove a cancelled person, a finished shift, an ended template, or an empty hidden event | Done |
|
| Remove a cancelled person, a finished shift, an ended template, or an empty hidden event | Done |
|
||||||
| Reminder emails, 48 hours and 2 hours, with a way to stop them | Done |
|
| Reminder emails, 48 hours and 2 hours, with a way to stop them | Done |
|
||||||
@@ -71,7 +71,7 @@ npm run seed
|
|||||||
|
|
||||||
`npm run dev` serves the site on `127.0.0.1` at `BASE_URL` (from `.env`, `http://127.0.0.1:3000`). It is loopback only. Stop it with Ctrl+C.
|
`npm run dev` serves the site on `127.0.0.1` at `BASE_URL` (from `.env`, `http://127.0.0.1:3000`). It is loopback only. Stop it with Ctrl+C.
|
||||||
|
|
||||||
Open `/` for the weekly pantry schedule. `/e/weekly-pantry` is the same seeded event. `/privacy` is the unapproved privacy notice. `/healthz` returns `{"ok":true,"database":"ok"}` and nothing else. Volunteer names, emails, and notes are not on the public list. A shift shows how many spots are filled, such as 3/5 spots filled. A shift with space left uses a soft green label. A full shift uses a soft red label.
|
Open `/` for the weekly pantry sign-up page. **View** starts on **List**: a card for each Wednesday in the next three months, split into that day's shifts. Each shift lists the names of the people who are signed up. Emails, phone numbers, and notes stay off the page. **Calendar** is the other choice in that menu, at `/?view=calendar`, and it stops at that same three-month date. A shift later than that date is left off both views, and the signup form does not take a reservation for it. Shifts on other weekdays stay on the calendar. `/e/weekly-pantry` is the same seeded event. `/privacy` is the unapproved privacy notice. `/healthz` returns `{"ok":true,"database":"ok"}` and nothing else. A shift shows how many spots are filled, such as 3/5 spots filled. A shift with space left uses a soft green label. A full shift uses a soft red label.
|
||||||
|
|
||||||
An open shift has a signup form. It asks for one person. Another person can use the same email and takes another spot. The same person cannot take a second spot. The form needs JavaScript because of the Turnstile check. Wait a few seconds after the page loads before submitting. The confirmation page shows a private link and says a confirmation email is on the way. That page works without JavaScript. Cancel this signup there to open the spot again. A cancellation email is queued, and a confirmation that has not been sent yet is dropped. That person can sign up again once the cancellation is saved. Someone else can use the email while the first signup is still confirmed. A cancelled signup stays on that private page until the link expires. A private link controls only that signup. Use the separate link for each signup.
|
An open shift has a signup form. It asks for one person. Another person can use the same email and takes another spot. The same person cannot take a second spot. The form needs JavaScript because of the Turnstile check. Wait a few seconds after the page loads before submitting. The confirmation page shows a private link and says a confirmation email is on the way. That page works without JavaScript. Cancel this signup there to open the spot again. A cancellation email is queued, and a confirmation that has not been sent yet is dropped. That person can sign up again once the cancellation is saved. Someone else can use the email while the first signup is still confirmed. A cancelled signup stays on that private page until the link expires. A private link controls only that signup. Use the separate link for each signup.
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ Coordinator sign-in is at `/login`. The first time the app starts with an empty
|
|||||||
|
|
||||||
After sign-in, `/admin` lists events, including events that are off the public list. A coordinator can add and edit an event, show or hide it, add and edit a one-off shift, read that shift's roster, cancel one signup, or cancel the shift. Cancelling keeps the roster. It does not delete the shift or the signup. A time, role, or location change emails the people who are signed up and replaces their private links. The old link stops working when that email is queued.
|
After sign-in, `/admin` lists events, including events that are off the public list. A coordinator can add and edit an event, show or hide it, add and edit a one-off shift, read that shift's roster, cancel one signup, or cancel the shift. Cancelling keeps the roster. It does not delete the shift or the signup. A time, role, or location change emails the people who are signed up and replaces their private links. The old link stops working when that email is queued.
|
||||||
|
|
||||||
On an open shift, **Add a walk-in** records one person who is here. It takes one spot, uses the same person rule as the public form, and queues a confirmation email. The name stays off the public list. A full, cancelled, or ended shift does not take a walk-in.
|
On an open shift, **Add a walk-in** records one person who is here. It takes one spot, uses the same person rule as the public form, and queues a confirmation email. The name is listed on the public sign-up page when that shift is posted there. Email and notes stay off that page. A full, cancelled, or ended shift does not take a walk-in.
|
||||||
|
|
||||||
On a confirmed signup, **Attended** and **No-show** record whether that person came. **Clear** removes the mark. The mark stays on the roster. It does not send email, and it does not change how many spots are open. A cancelled signup cannot be marked.
|
On a confirmed signup, **Attended** and **No-show** record whether that person came. **Clear** removes the mark. The mark stays on the roster. It does not send email, and it does not change how many spots are open. A cancelled signup cannot be marked.
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ Public switching permits 10 validated attempts per IP per 10-minute window and 5
|
|||||||
|
|
||||||
**Management link scope:** names and email addresses entered in a public form are unverified. Each private link authorizes only its own signup, including links from confirmation cookies and email. Cross-signup listing, cancellation, and switching are disabled, and the old `/m/:token/also/...` routes return 404. This also applies to existing links. A future multi-signup view must verify identity separately.
|
**Management link scope:** names and email addresses entered in a public form are unverified. Each private link authorizes only its own signup, including links from confirmation cookies and email. Cross-signup listing, cancellation, and switching are disabled, and the old `/m/:token/also/...` routes return 404. This also applies to existing links. A future multi-signup view must verify identity separately.
|
||||||
|
|
||||||
**Add weekly shifts**, on a coordinator event page, fills the next eight weeks from that event's active weekly templates. Starting the app does the same thing for every event. A shift that is already on that date stays as it is, including a cancelled one, so the template cannot recreate it. A 9:00 shift stays 9:00 when daylight saving time changes. A local time that does not exist, or that happens twice, is skipped.
|
**Add weekly shifts**, on a coordinator event page, fills the next three months from that event's active weekly templates. Starting the app does the same thing for every event. A shift that is already on that date stays as it is, including a cancelled one, so the template cannot recreate it. A 9:00 shift stays 9:00 when daylight saving time changes. A local time that does not exist, or that happens twice, is skipped.
|
||||||
|
|
||||||
**Add a weekly template** saves a repeating role, day, and time. **Edit this template** changes later weeks only. Shifts already on the schedule keep their role, time, and number of spots. **End this template** stops later weeks from being added. It does not cancel shifts already listed, and it does not email anyone.
|
**Add a weekly template** saves a repeating role, day, and time. **Edit this template** changes later weeks only. Shifts already on the schedule keep their role, time, and number of spots. **End this template** stops later weeks from being added. It does not cancel shifts already listed, and it does not email anyone.
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ A reminder is queued at each saved time before a confirmed signup, while the shi
|
|||||||
|
|
||||||
**Download this roster**, on a shift, and **Download this event**, on an event, save a spreadsheet of the signups. **Download this date range**, on the coordinator page, uses each event's local shift date. The file includes cancelled signups and attendance. A cell that would be a spreadsheet formula is saved as text. The download is not cached. A copy on a coordinator's computer is outside this app, and the app does not delete it later.
|
**Download this roster**, on a shift, and **Download this event**, on an event, save a spreadsheet of the signups. **Download this date range**, on the coordinator page, uses each event's local shift date. The file includes cancelled signups and attendance. A cell that would be a spreadsheet formula is saved as text. The download is not cached. A copy on a coordinator's computer is outside this app, and the app does not delete it later.
|
||||||
|
|
||||||
**Contacts**, on the coordinator page, keeps a list of people. A confirmed signup is saved on this list. The name is split at the last space. A signup name with no space is saved with a hyphen as the last name. A different name is a separate contact, even when the email matches. The same name and email updates that contact. Cancelling the signup does not remove the contact. Saving someone here does not sign them up for a shift. **Import this list** reads a spreadsheet with First Name, Last Name, Email, and Phone, including the SignUpGenius people export. An Address column is ignored. The same name and email updates that person. A different name stays a separate person, even when the email matches. A different email stays a separate person, even when the name matches. A row without a phone is skipped. Names are capitalized. A word that already mixes upper and lower case stays as written. A phone number with ten digits is saved with dashes, like 712-555-0100. A leading 1 is left off. Email addresses are stored in lowercase. Importing does not take a spot and does not send email. **Download contacts** saves that list. A cell that would be a spreadsheet formula is saved as text. A downloaded copy stays on the coordinator's computer. The signup retention job does not clear this list. The list is the contacts table in `app.db`. The list shows 20 people. **See more** shows the next 20 on this page, without returning to the top, and keeps a search. **Choose a name**, then choose the shift from **Shift**. That takes one spot and queues a confirmation email. A full, cancelled, or ended shift is not in that list, and a shift they are already on is not in that list. A shift that is not on the public list can still be chosen. **Correct this contact**, on that page, saves a corrected name, email, or phone on the same person. A phone typo can be replaced. A hyphen saved as the last name can be replaced with the real last name. Changing the name does not create a second person, even when the email stays the same. Phone is required. It does not change a signup, take a spot, or send email. **Remove** deletes that person from the list only. On an open shift, **Saved contact** fills a walk-in. The walk-in still takes one spot and queues a confirmation email. **Add a contact** saves one person who has not signed up. It does not take a spot and does not send email. The same name and email updates that person. A different name is saved separately, even with the same email. Typing a walk-in who is not on the list saves them here too.
|
**Contacts**, on the coordinator page, keeps a list of people. A confirmed signup is saved on this list. The name is split at the last space. A signup name with no space is saved with a hyphen as the last name. A different name is a separate contact, even when the email matches. The same name and email updates that contact. Cancelling the signup does not remove the contact. Saving someone here does not sign them up for a shift. The list is at the top of this page. **Add a contact**, **Import**, and **Download** stay closed until one is opened. **Import** reads a spreadsheet with First Name, Last Name, Email, and Phone, including the SignUpGenius people export. An Address column is ignored. The same name and email updates that person. A different name stays a separate person, even when the email matches. A different email stays a separate person, even when the name matches. A row without a phone is skipped. Names are capitalized. A word that already mixes upper and lower case stays as written. A phone number with ten digits is saved with dashes, like 712-555-0100. A leading 1 is left off. Email addresses are stored in lowercase. Importing does not take a spot and does not send email. **Download** saves that list. A cell that would be a spreadsheet formula is saved as text. A downloaded copy stays on the coordinator's computer. The signup retention job does not clear this list. The list is the contacts table in `app.db`. The list shows 20 people. **See more** shows the next 20 on this page, without returning to the top, and keeps a search. **Choose a name** to see the shifts they are signed up for and every past shift they signed up for. The signup has to use the same name and email. A signup name with no space matches the contact saved with a hyphen for the last name. A confirmed signup on a shift that has not ended is listed under Signed up for. A shift that has ended is listed under Past shifts, including a cancelled signup, which is marked cancelled. Choosing the shift opens it. Signup details cleared by retention drop off this page. **Edit contact** and **Add to a shift** stay closed until opened. **Add to a shift** uses their saved name, email, and phone. That takes one spot and queues a confirmation email. A full, cancelled, or ended shift is not in that list, and a shift they are already on is not in that list. A shift that is not on the public list can still be chosen. **Edit contact**, on that page, saves a corrected name, email, or phone on the same person. A phone typo can be replaced. A hyphen saved as the last name can be replaced with the real last name. Changing the name does not create a second person, even when the email stays the same. Phone is required. It does not change a signup, take a spot, or send email. **Remove** deletes that person from the list only. On an open shift, **Saved contact** fills a walk-in. The walk-in still takes one spot and queues a confirmation email. **Add a contact** saves one person who has not signed up. It does not take a spot and does not send email. The same name and email updates that person. A different name is saved separately, even with the same email. Typing a walk-in who is not on the list saves them here too.
|
||||||
|
|
||||||
**Settings**, on the coordinator page, saves the two reminder times, the reply-to address, the privacy-page wording, and how many months to keep a signup after the shift ends. The defaults are 48 hours, 2 hours, the reply-to address from the server configuration, a blank privacy notice, and 24 months. The two reminder times have to be different whole hours from 1 to 336. The month count is a whole number from 1 to 120. A blank privacy notice leaves the public page saying a notice is not approved yet. Saved wording is shown on `/privacy` as written. Saving it does not by itself make that wording an approved privacy policy. New mail uses the saved reply-to address. Mail already queued keeps the address it was given. The sending address stays in the server configuration.
|
**Settings**, on the coordinator page, saves the two reminder times, the reply-to address, the privacy-page wording, and how many months to keep a signup after the shift ends. The defaults are 48 hours, 2 hours, the reply-to address from the server configuration, a blank privacy notice, and 24 months. The two reminder times have to be different whole hours from 1 to 336. The month count is a whole number from 1 to 120. A blank privacy notice leaves the public page saying a notice is not approved yet. Saved wording is shown on `/privacy` as written. Saving it does not by itself make that wording an approved privacy policy. New mail uses the saved reply-to address. Mail already queued keeps the address it was given. The sending address stays in the server configuration.
|
||||||
|
|
||||||
|
|||||||
+474
-2
@@ -463,10 +463,234 @@ main a:hover {
|
|||||||
user-select: all;
|
user-select: all;
|
||||||
}
|
}
|
||||||
|
|
||||||
.shift-calendar {
|
.signup-board {
|
||||||
margin-top: 1.25rem;
|
margin-top: 1.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.schedule-bar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 0.75rem 1.25rem;
|
||||||
|
margin: 0 0 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-menu {
|
||||||
|
position: relative;
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-menu > summary {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.45rem;
|
||||||
|
min-height: 2.5rem;
|
||||||
|
padding: 0.2rem 0.85rem;
|
||||||
|
list-style: none;
|
||||||
|
cursor: pointer;
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid var(--hope-border-2);
|
||||||
|
border-radius: 999px;
|
||||||
|
color: var(--hope-ink);
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-menu > summary::-webkit-details-marker {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-menu > summary::marker {
|
||||||
|
content: "";
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-menu > summary::after {
|
||||||
|
content: "";
|
||||||
|
width: 0.4rem;
|
||||||
|
height: 0.4rem;
|
||||||
|
margin-left: 0.15rem;
|
||||||
|
border-right: 2px solid currentColor;
|
||||||
|
border-bottom: 2px solid currentColor;
|
||||||
|
transform: translateY(-0.12rem) rotate(45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-menu[open] > summary::after {
|
||||||
|
transform: translateY(0.12rem) rotate(225deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-menu-kicker {
|
||||||
|
color: var(--hope-ink-2);
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-menu-list {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 4;
|
||||||
|
top: calc(100% + 0.35rem);
|
||||||
|
left: 0;
|
||||||
|
display: grid;
|
||||||
|
min-width: 100%;
|
||||||
|
padding: 0.3rem;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 1rem;
|
||||||
|
box-shadow: var(--hope-shadow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-menu-list a {
|
||||||
|
padding: 0.45rem 0.8rem;
|
||||||
|
border-radius: 0.7rem;
|
||||||
|
color: var(--hope-ink);
|
||||||
|
font-weight: 650;
|
||||||
|
text-decoration: none;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-menu-list a:hover,
|
||||||
|
.view-menu-list a:active {
|
||||||
|
background: var(--hope-blue-75);
|
||||||
|
color: var(--hope-ink);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-menu-list a[aria-current='page'] {
|
||||||
|
background: var(--hope-yellow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.window-note {
|
||||||
|
flex: 1 1 16rem;
|
||||||
|
min-width: 0;
|
||||||
|
margin: 0;
|
||||||
|
color: var(--hope-ink-2);
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 42em) {
|
||||||
|
.schedule-bar {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.window-note {
|
||||||
|
flex-basis: 100%;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-menu[open] {
|
||||||
|
margin-bottom: 6.4rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.day-board {
|
||||||
|
list-style: none;
|
||||||
|
display: grid;
|
||||||
|
gap: 1.25rem;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.day-card {
|
||||||
|
overflow: hidden;
|
||||||
|
background: var(--hope-blue-50);
|
||||||
|
border-radius: 1.75rem;
|
||||||
|
box-shadow: var(--hope-shadow);
|
||||||
|
container: day / inline-size;
|
||||||
|
}
|
||||||
|
|
||||||
|
.day-card[aria-current='date'] {
|
||||||
|
outline: 2px solid var(--hope-ink);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.day-card-head {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.35rem 0.85rem;
|
||||||
|
padding: 0.95rem 1.1rem;
|
||||||
|
background: var(--hope-yellow);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.day-card-dow {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1.05rem;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
.day-card-head h2 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: clamp(1.6rem, 3vw, 2.1rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
.day-card-head .today-flag {
|
||||||
|
align-self: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.day-card-shifts {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 1px;
|
||||||
|
background: var(--hope-border-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A row is 4, 2, or 1. Three columns leaves one shift alone on the next row. */
|
||||||
|
@container day (min-width: 32rem) {
|
||||||
|
.day-card-shifts:has(> :nth-child(2)) {
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@container day (min-width: 64rem) {
|
||||||
|
.day-card-shifts:has(> :nth-child(4)) {
|
||||||
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.shift-pane {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-width: 0;
|
||||||
|
background: var(--hope-blue-50);
|
||||||
|
}
|
||||||
|
|
||||||
|
.shift-pane-body {
|
||||||
|
display: grid;
|
||||||
|
gap: 0.15rem;
|
||||||
|
flex: 1;
|
||||||
|
padding: 1rem 1.2rem 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shift-pane-body h3 {
|
||||||
|
margin-bottom: 0.15rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.roster-label {
|
||||||
|
margin: 0.75rem 0 0.2rem;
|
||||||
|
color: var(--hope-ink-2);
|
||||||
|
font-size: 0.82rem;
|
||||||
|
font-weight: 650;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.roster-names {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.roster-names li {
|
||||||
|
padding: 0.12rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.roster-empty {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--hope-ink-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.shift-calendar {
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
.month-nav {
|
.month-nav {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
|
grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
|
||||||
@@ -794,6 +1018,7 @@ main a:hover {
|
|||||||
.cal-detail .when,
|
.cal-detail .when,
|
||||||
.cal-detail .status,
|
.cal-detail .status,
|
||||||
.cal-detail .spots,
|
.cal-detail .spots,
|
||||||
|
.cal-detail .cal-names,
|
||||||
.cal-detail .cal-action {
|
.cal-detail .cal-action {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 0.95rem;
|
font-size: 0.95rem;
|
||||||
@@ -944,6 +1169,34 @@ article.shift-card {
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-card.is-static {
|
||||||
|
margin: 0;
|
||||||
|
margin-top: auto;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0;
|
||||||
|
cursor: default;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
font-weight: 500;
|
||||||
|
line-height: 1.25;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shift-full-label {
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-card.is-static::before,
|
||||||
|
.btn-card.is-static:hover::before,
|
||||||
|
.btn-card.is-static:active::before {
|
||||||
|
content: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-card.is-static:hover,
|
||||||
|
.btn-card.is-static:active {
|
||||||
|
color: var(--hope-ink);
|
||||||
|
}
|
||||||
|
|
||||||
.empty {
|
.empty {
|
||||||
margin-top: 0.5rem;
|
margin-top: 0.5rem;
|
||||||
padding: 1.1rem 1.25rem;
|
padding: 1.1rem 1.25rem;
|
||||||
@@ -2289,6 +2542,224 @@ button.btn-quiet::before {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.contact-actions {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, max-content) minmax(0, 1fr);
|
||||||
|
align-items: start;
|
||||||
|
column-gap: 0.75rem;
|
||||||
|
row-gap: 0.85rem;
|
||||||
|
width: 100%;
|
||||||
|
margin: 1.25rem 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-menu {
|
||||||
|
display: contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-menu > summary {
|
||||||
|
grid-row: 1;
|
||||||
|
justify-self: start;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.4rem;
|
||||||
|
min-height: 2.35rem;
|
||||||
|
padding: 0.28rem 0.9rem;
|
||||||
|
list-style: none;
|
||||||
|
cursor: pointer;
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid #d5dee6;
|
||||||
|
border-radius: 999px;
|
||||||
|
color: var(--hope-ink);
|
||||||
|
font-size: 0.92rem;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-actions > .contact-menu:nth-child(1) > summary {
|
||||||
|
grid-column: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-actions > .contact-menu:nth-child(2) > summary {
|
||||||
|
grid-column: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-actions > .contact-menu:nth-child(3) > summary {
|
||||||
|
grid-column: 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-menu > summary::-webkit-details-marker {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-menu:not([open]) > :not(summary) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-menu[open] > :not(summary),
|
||||||
|
.contact-menu[open]::details-content {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
grid-row: 2;
|
||||||
|
justify-self: start;
|
||||||
|
width: min(36rem, 100%);
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-actions > .contact-menu:nth-child(2)[open] > :not(summary),
|
||||||
|
.contact-actions > .contact-menu:nth-child(2)[open]::details-content {
|
||||||
|
grid-row: 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-actions > .contact-menu:nth-child(3)[open] > :not(summary),
|
||||||
|
.contact-actions > .contact-menu:nth-child(3)[open]::details-content {
|
||||||
|
grid-row: 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar > .contact-find {
|
||||||
|
margin-top: 0;
|
||||||
|
padding: 0;
|
||||||
|
background: transparent;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar > .contact-find button {
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-menu > .signup-form {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 42em) {
|
||||||
|
.contact-actions {
|
||||||
|
column-gap: 0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-menu > summary {
|
||||||
|
padding-inline: 0.65rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-menu[open] .edit-chevron {
|
||||||
|
transform: translateY(0.08rem) rotate(225deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) max-content max-content max-content;
|
||||||
|
align-items: center;
|
||||||
|
column-gap: 0.75rem;
|
||||||
|
row-gap: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar > .contact-find,
|
||||||
|
.contact-toolbar > .empty {
|
||||||
|
grid-column: 1;
|
||||||
|
grid-row: 1;
|
||||||
|
justify-self: start;
|
||||||
|
min-width: 0;
|
||||||
|
width: min(28rem, 100%);
|
||||||
|
max-width: 28rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar > .contact-actions {
|
||||||
|
display: contents;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar > .contact-actions > .contact-menu:nth-child(1) > summary {
|
||||||
|
grid-column: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar > .contact-actions > .contact-menu:nth-child(2) > summary {
|
||||||
|
grid-column: 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar > .contact-actions > .contact-menu:nth-child(3) > summary {
|
||||||
|
grid-column: 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar > .contact-actions > .contact-menu[open] > :not(summary),
|
||||||
|
.contact-toolbar > .contact-actions > .contact-menu[open]::details-content {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
grid-row: 2;
|
||||||
|
justify-self: stretch;
|
||||||
|
width: 100%;
|
||||||
|
max-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar .contact-menu .signup-form {
|
||||||
|
width: 100%;
|
||||||
|
max-width: none;
|
||||||
|
background: var(--hope-blue-50);
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar .contact-actions > .contact-menu:nth-child(1) .signup-form input[type="text"],
|
||||||
|
.contact-toolbar .contact-actions > .contact-menu:nth-child(1) .signup-form input[type="email"],
|
||||||
|
.contact-toolbar .contact-actions > .contact-menu:nth-child(1) .signup-form input[type="tel"] {
|
||||||
|
background: #fff;
|
||||||
|
box-shadow: var(--hope-shadow);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 42em) {
|
||||||
|
.contact-toolbar {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
gap: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar > .contact-find,
|
||||||
|
.contact-toolbar > .empty {
|
||||||
|
grid-column: auto;
|
||||||
|
width: 100%;
|
||||||
|
max-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar > .contact-actions {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 0.5rem;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar > .contact-actions > .contact-menu {
|
||||||
|
display: block;
|
||||||
|
width: max-content;
|
||||||
|
order: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar > .contact-actions > .contact-menu > summary {
|
||||||
|
grid-column: auto;
|
||||||
|
grid-row: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar > .contact-actions > .contact-menu[open] {
|
||||||
|
order: 1;
|
||||||
|
flex: 1 0 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-toolbar > .contact-actions > .contact-menu[open] > :not(summary),
|
||||||
|
.contact-toolbar > .contact-actions > .contact-menu[open]::details-content {
|
||||||
|
grid-column: auto;
|
||||||
|
grid-row: auto;
|
||||||
|
width: 100%;
|
||||||
|
max-width: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-shift-list {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0 0 1.25rem;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contact-shift-list li {
|
||||||
|
padding: 0.35rem 0;
|
||||||
|
border-top: 1px solid var(--hope-border-2);
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
.contact-more {
|
.contact-more {
|
||||||
margin: 0.35rem 0 0;
|
margin: 0.35rem 0 0;
|
||||||
}
|
}
|
||||||
@@ -2941,7 +3412,8 @@ button.btn-quiet::before {
|
|||||||
|
|
||||||
.cal-detail .when,
|
.cal-detail .when,
|
||||||
.cal-detail .status,
|
.cal-detail .status,
|
||||||
.cal-detail .spots {
|
.cal-detail .spots,
|
||||||
|
.cal-detail .cal-names {
|
||||||
grid-column: 1;
|
grid-column: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
(function () {
|
(function () {
|
||||||
bindNav();
|
bindNav();
|
||||||
bindCalendar();
|
bindCalendar();
|
||||||
|
bindViewMenu();
|
||||||
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);
|
||||||
|
|
||||||
@@ -23,6 +24,21 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bindViewMenu() {
|
||||||
|
var menus = document.querySelectorAll('details.view-menu');
|
||||||
|
if (!menus.length) return;
|
||||||
|
document.addEventListener('click', function (event) {
|
||||||
|
for (var i = 0; i < menus.length; i += 1) {
|
||||||
|
if (!menus[i].open || menus[i].contains(event.target)) continue;
|
||||||
|
menus[i].open = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
document.addEventListener('keydown', function (event) {
|
||||||
|
if (event.key !== 'Escape') return;
|
||||||
|
for (var i = 0; i < menus.length; i += 1) menus[i].open = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function bindCalendar() {
|
function bindCalendar() {
|
||||||
var calendar = document.querySelector('.shift-calendar');
|
var calendar = document.querySelector('.shift-calendar');
|
||||||
var weeks = document.querySelectorAll('.cal-week');
|
var weeks = document.querySelectorAll('.cal-week');
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ import {
|
|||||||
parseContactSkips,
|
parseContactSkips,
|
||||||
removeContact,
|
removeContact,
|
||||||
saveManualContact,
|
saveManualContact,
|
||||||
|
contactSignupShifts,
|
||||||
walkInFromContact,
|
walkInFromContact,
|
||||||
type ContactImportSummary,
|
type ContactImportSummary,
|
||||||
type ContactManualErrors,
|
type ContactManualErrors,
|
||||||
@@ -474,6 +475,7 @@ function showContact(
|
|||||||
config={services.config}
|
config={services.config}
|
||||||
csrf={session.csrf}
|
csrf={session.csrf}
|
||||||
contact={contact}
|
contact={contact}
|
||||||
|
signedUp={contactSignupShifts(services.db, contact, services.now())}
|
||||||
shifts={listOpenShiftsForPerson(services.db, { email: contact.email, name: contact.name }, services.now())}
|
shifts={listOpenShiftsForPerson(services.db, { email: contact.email, name: contact.name }, services.now())}
|
||||||
form={state?.form ?? blankWalkIn(services, contact.id)}
|
form={state?.form ?? blankWalkIn(services, contact.id)}
|
||||||
shiftId={state?.shiftId ?? ''}
|
shiftId={state?.shiftId ?? ''}
|
||||||
|
|||||||
+140
-91
@@ -12,6 +12,7 @@ import {
|
|||||||
type ContactImportSummary,
|
type ContactImportSummary,
|
||||||
type ContactManualErrors,
|
type ContactManualErrors,
|
||||||
type ContactManualValues,
|
type ContactManualValues,
|
||||||
|
type ContactShift,
|
||||||
} from './contacts.js';
|
} from './contacts.js';
|
||||||
import type { SignupErrors, SignupValues } from './signup-form.js';
|
import type { SignupErrors, SignupValues } from './signup-form.js';
|
||||||
import { addLocalDays, formatInstantInZone, todayInZone } from './time.js';
|
import { addLocalDays, formatInstantInZone, todayInZone } from './time.js';
|
||||||
@@ -458,6 +459,19 @@ function contactListHref(config: AppConfig, query: string, shown: number): strin
|
|||||||
return `${appPath(config, '/admin/contacts')}?${params.toString()}#contact-more`;
|
return `${appPath(config, '/admin/contacts')}?${params.toString()}#contact-more`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ContactShiftList(props: { config: AppConfig; shifts: ContactShift[]; empty: string }) {
|
||||||
|
if (props.shifts.length === 0) return <p class="empty">{props.empty}</p>;
|
||||||
|
return (
|
||||||
|
<ul class="contact-shift-list">
|
||||||
|
{props.shifts.map((shift) => (
|
||||||
|
<li key={shift.signupId}>
|
||||||
|
<a href={appPath(props.config, `/admin/shifts/${shift.shiftId}`)}>{shift.label}</a>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function ContactsPage(props: {
|
export function ContactsPage(props: {
|
||||||
config: AppConfig;
|
config: AppConfig;
|
||||||
csrf: string;
|
csrf: string;
|
||||||
@@ -482,6 +496,8 @@ export function ContactsPage(props: {
|
|||||||
: `${props.total} people`;
|
: `${props.total} people`;
|
||||||
const hiddenSkips = props.summary ? Math.max(0, props.summary.skipped - props.summary.skips.length) : 0;
|
const hiddenSkips = props.summary ? Math.max(0, props.summary.skipped - props.summary.skips.length) : 0;
|
||||||
const moreHref = contactListHref(props.config, props.query, props.limit + CONTACT_LIST_PAGE);
|
const moreHref = contactListHref(props.config, props.query, props.limit + CONTACT_LIST_PAGE);
|
||||||
|
const addOpen = Object.keys(manual.errors).length > 0;
|
||||||
|
const importOpen = Boolean(props.importError);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Crumb items={[{ href: appPath(props.config, '/admin'), label: 'Coordinator' }, { label: 'Contacts' }]} />
|
<Crumb items={[{ href: appPath(props.config, '/admin'), label: 'Coordinator' }, { label: 'Contacts' }]} />
|
||||||
@@ -495,42 +511,11 @@ export function ContactsPage(props: {
|
|||||||
</ul>
|
</ul>
|
||||||
) : null}
|
) : null}
|
||||||
{hiddenSkips > 0 ? <p class="panel-note">{hiddenSkips === 1 ? '1 more row was skipped.' : `${hiddenSkips} more rows were skipped.`}</p> : null}
|
{hiddenSkips > 0 ? <p class="panel-note">{hiddenSkips === 1 ? '1 more row was skipped.' : `${hiddenSkips} more rows were skipped.`}</p> : null}
|
||||||
<p>
|
|
||||||
Someone who signs up is saved here. Cancelling that signup does not remove them. A different name is a separate contact, even when the email matches. To add someone who has not signed up, import a spreadsheet or save them below. That does not take a spot and does not send email. Choose a name to correct that person or add them to an open shift. Old signups lose their details after the retention period. This list stays until you remove someone.
|
|
||||||
</p>
|
|
||||||
<form method="post" action={appPath(props.config, '/admin/contacts/new')} class="signup-form desk-download">
|
|
||||||
<input type="hidden" name="csrf" value={props.csrf} />
|
|
||||||
<h2>Add a contact</h2>
|
|
||||||
<p>This saves one person. It does not sign them up and does not send email. The same name and email updates that person. A different name is saved separately, even with the same email. Names are capitalized. A 10-digit phone is saved with dashes, like 712-555-0100.</p>
|
|
||||||
<WalkInField id="contact-first" label="First name" name="first_name" type="text" value={manual.values.firstName} error={manual.errors.firstName} />
|
|
||||||
<WalkInField id="contact-last" label="Last name" name="last_name" type="text" value={manual.values.lastName} error={manual.errors.lastName} />
|
|
||||||
<WalkInField id="contact-email" label="Email" name="email" type="email" value={manual.values.email} error={manual.errors.email} />
|
|
||||||
<WalkInField id="contact-phone" label="Phone" name="phone" type="tel" value={manual.values.phone} error={manual.errors.phone} required />
|
|
||||||
<button type="submit">Save this contact</button>
|
|
||||||
</form>
|
|
||||||
<form method="post" action={appPath(props.config, '/admin/contacts/import')} class="signup-form desk-download" enctype="multipart/form-data">
|
|
||||||
<input type="hidden" name="csrf" value={props.csrf} />
|
|
||||||
<h2>Import a contact list</h2>
|
|
||||||
<p>
|
|
||||||
Use a spreadsheet with First Name, Last Name, Email, and Phone. The SignUpGenius people export works. Address is ignored. The same name and email updates that person. A different name stays a separate person, even when the email matches. A different email stays a separate person, even when the name matches. A row without a phone is skipped. Names are capitalized. A 10-digit phone is saved with dashes, like 712-555-0100. Email addresses are stored in lowercase. The file has to be under 64 KB.
|
|
||||||
</p>
|
|
||||||
{props.importError ? <p class="error">{props.importError}</p> : null}
|
|
||||||
<label>
|
|
||||||
Spreadsheet
|
|
||||||
<input name="file" type="file" accept=".csv,text/csv,text/plain" required />
|
|
||||||
</label>
|
|
||||||
<button type="submit">Import this list</button>
|
|
||||||
</form>
|
|
||||||
<form method="post" action={appPath(props.config, '/admin/contacts/export')} class="signup-form desk-download">
|
|
||||||
<input type="hidden" name="csrf" value={props.csrf} />
|
|
||||||
<h2>Download contacts</h2>
|
|
||||||
<p>A downloaded copy stays on your computer. This app does not delete it later. The Address column is blank. A cell that would be a spreadsheet formula is saved as text.</p>
|
|
||||||
<button type="submit">Download contacts</button>
|
|
||||||
</form>
|
|
||||||
<section class="desk-events" aria-labelledby="contacts-heading">
|
<section class="desk-events" aria-labelledby="contacts-heading">
|
||||||
<h2 id="contacts-heading">{heading}</h2>
|
<h2 id="contacts-heading">{heading}</h2>
|
||||||
|
<div class="contact-toolbar">
|
||||||
{props.total > 0 ? (
|
{props.total > 0 ? (
|
||||||
<form method="get" action={appPath(props.config, '/admin/contacts')} class="signup-form desk-download">
|
<form method="get" action={appPath(props.config, '/admin/contacts')} class="signup-form desk-download contact-find">
|
||||||
<div class="desk-range">
|
<div class="desk-range">
|
||||||
<label>
|
<label>
|
||||||
Find
|
Find
|
||||||
@@ -542,6 +527,53 @@ export function ContactsPage(props: {
|
|||||||
) : (
|
) : (
|
||||||
<p class="empty">No contacts yet.</p>
|
<p class="empty">No contacts yet.</p>
|
||||||
)}
|
)}
|
||||||
|
<div class="contact-actions">
|
||||||
|
<details class="contact-menu" name="contact-tools" open={addOpen ? true : undefined}>
|
||||||
|
<summary>
|
||||||
|
Add a contact
|
||||||
|
<span class="edit-chevron" aria-hidden="true" />
|
||||||
|
</summary>
|
||||||
|
<form method="post" action={appPath(props.config, '/admin/contacts/new')} class="signup-form">
|
||||||
|
<input type="hidden" name="csrf" value={props.csrf} />
|
||||||
|
<p>This saves one person. It does not sign them up and does not send email. The same name and email updates that person. A different name is saved separately, even with the same email. Names are capitalized. A 10-digit phone is saved with dashes, like 712-555-0100.</p>
|
||||||
|
<WalkInField id="contact-first" label="First name" name="first_name" type="text" value={manual.values.firstName} error={manual.errors.firstName} />
|
||||||
|
<WalkInField id="contact-last" label="Last name" name="last_name" type="text" value={manual.values.lastName} error={manual.errors.lastName} />
|
||||||
|
<WalkInField id="contact-email" label="Email" name="email" type="email" value={manual.values.email} error={manual.errors.email} />
|
||||||
|
<WalkInField id="contact-phone" label="Phone" name="phone" type="tel" value={manual.values.phone} error={manual.errors.phone} required />
|
||||||
|
<button type="submit">Save this contact</button>
|
||||||
|
</form>
|
||||||
|
</details>
|
||||||
|
<details class="contact-menu" name="contact-tools" open={importOpen ? true : undefined}>
|
||||||
|
<summary>
|
||||||
|
Import
|
||||||
|
<span class="edit-chevron" aria-hidden="true" />
|
||||||
|
</summary>
|
||||||
|
<form method="post" action={appPath(props.config, '/admin/contacts/import')} class="signup-form" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" name="csrf" value={props.csrf} />
|
||||||
|
<p>
|
||||||
|
Use a spreadsheet with First Name, Last Name, Email, and Phone. The SignUpGenius people export works. Address is ignored. The same name and email updates that person. A different name stays a separate person, even when the email matches. A different email stays a separate person, even when the name matches. A row without a phone is skipped. Names are capitalized. A 10-digit phone is saved with dashes, like 712-555-0100. Email addresses are stored in lowercase. The file has to be under 64 KB.
|
||||||
|
</p>
|
||||||
|
{props.importError ? <p class="error">{props.importError}</p> : null}
|
||||||
|
<label>
|
||||||
|
Spreadsheet
|
||||||
|
<input name="file" type="file" accept=".csv,text/csv,text/plain" required />
|
||||||
|
</label>
|
||||||
|
<button type="submit">Import this list</button>
|
||||||
|
</form>
|
||||||
|
</details>
|
||||||
|
<details class="contact-menu" name="contact-tools">
|
||||||
|
<summary>
|
||||||
|
Download
|
||||||
|
<span class="edit-chevron" aria-hidden="true" />
|
||||||
|
</summary>
|
||||||
|
<form method="post" action={appPath(props.config, '/admin/contacts/export')} class="signup-form">
|
||||||
|
<input type="hidden" name="csrf" value={props.csrf} />
|
||||||
|
<p>A downloaded copy stays on your computer. This app does not delete it later. The Address column is blank. A cell that would be a spreadsheet formula is saved as text.</p>
|
||||||
|
<button type="submit">Download contacts</button>
|
||||||
|
</form>
|
||||||
|
</details>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{props.total > 0 && props.people.length === 0 ? <p class="empty">No contacts match.</p> : null}
|
{props.total > 0 && props.people.length === 0 ? <p class="empty">No contacts match.</p> : null}
|
||||||
{props.people.length > 0 ? (
|
{props.people.length > 0 ? (
|
||||||
<ul class="contact-list" id="contacts-list">
|
<ul class="contact-list" id="contacts-list">
|
||||||
@@ -580,6 +612,7 @@ export function ContactPage(props: {
|
|||||||
config: AppConfig;
|
config: AppConfig;
|
||||||
csrf: string;
|
csrf: string;
|
||||||
contact: Contact;
|
contact: Contact;
|
||||||
|
signedUp: { current: ContactShift[]; past: ContactShift[] };
|
||||||
shifts: MoveTarget[];
|
shifts: MoveTarget[];
|
||||||
form: WalkInState;
|
form: WalkInState;
|
||||||
shiftId: string;
|
shiftId: string;
|
||||||
@@ -599,6 +632,8 @@ export function ContactPage(props: {
|
|||||||
},
|
},
|
||||||
errors: {},
|
errors: {},
|
||||||
};
|
};
|
||||||
|
const editOpen = Object.keys(correction.errors).length > 0;
|
||||||
|
const addOpen = Boolean(props.error || props.form.message || errorEntries.length > 0 || props.shiftId);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Crumb
|
<Crumb
|
||||||
@@ -612,62 +647,76 @@ export function ContactPage(props: {
|
|||||||
<p>{props.contact.email}</p>
|
<p>{props.contact.email}</p>
|
||||||
{props.contact.phone ? <p>{props.contact.phone}</p> : null}
|
{props.contact.phone ? <p>{props.contact.phone}</p> : null}
|
||||||
<Notice notice={props.notice} />
|
<Notice notice={props.notice} />
|
||||||
<form method="post" action={appPath(props.config, `/admin/contacts/${props.contact.id}`)} class="signup-form">
|
<h2>Signed up for</h2>
|
||||||
<input type="hidden" name="csrf" value={props.csrf} />
|
<ContactShiftList config={props.config} shifts={props.signedUp.current} empty="Not signed up for a shift." />
|
||||||
<h2>Correct this contact</h2>
|
<h2>Past shifts</h2>
|
||||||
<p>
|
<ContactShiftList config={props.config} shifts={props.signedUp.past} empty="No past shifts." />
|
||||||
This changes the saved person. A different name stays this contact and does not create a second person. It does not change a signup, take a spot, or send email. Names are capitalized. A 10-digit phone is saved with dashes, like 712-555-0100.
|
<div class="contact-actions">
|
||||||
</p>
|
<details class="contact-menu" name="contact-action" open={editOpen ? true : undefined}>
|
||||||
<WalkInField id="correct-first" label="First name" name="first_name" type="text" value={correction.values.firstName} error={correction.errors.firstName} />
|
<summary>
|
||||||
<WalkInField id="correct-last" label="Last name" name="last_name" type="text" value={correction.values.lastName} error={correction.errors.lastName} />
|
Edit contact
|
||||||
<WalkInField id="correct-email" label="Email" name="email" type="email" value={correction.values.email} error={correction.errors.email} />
|
<span class="edit-chevron" aria-hidden="true" />
|
||||||
<WalkInField
|
</summary>
|
||||||
id="correct-phone"
|
<form method="post" action={appPath(props.config, `/admin/contacts/${props.contact.id}`)} class="signup-form">
|
||||||
label="Phone"
|
|
||||||
name="phone"
|
|
||||||
type="tel"
|
|
||||||
value={correction.values.phone}
|
|
||||||
error={correction.errors.phone}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
<button type="submit">Save this correction</button>
|
|
||||||
</form>
|
|
||||||
{props.error ? <p class="error">{props.error}</p> : null}
|
|
||||||
<h2>Add to a shift</h2>
|
|
||||||
<p>Choose an open shift. This uses their saved name, email, and phone. It takes one spot and queues a confirmation email. Their name stays off the public list. Full, cancelled, and ended shifts are left off this list, and so is a shift they are already on.</p>
|
|
||||||
{props.shifts.length > 0 ? (
|
|
||||||
<form method="post" action={appPath(props.config, `/admin/contacts/${props.contact.id}/add`)} class="signup-form">
|
|
||||||
{props.form.message ? <p class="error">{props.form.message}</p> : null}
|
|
||||||
{errorEntries.length > 0 ? (
|
|
||||||
<div class="error" role="alert">
|
|
||||||
<p>Check these fields:</p>
|
|
||||||
<ul>
|
|
||||||
{errorEntries.map(([field, message]) => (
|
|
||||||
<li key={field}>{message}</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
) : null}
|
|
||||||
<input type="hidden" name="csrf" value={props.csrf} />
|
<input type="hidden" name="csrf" value={props.csrf} />
|
||||||
<input type="hidden" name="form_token" value={props.form.token} />
|
<p>This changes the saved person. It does not change a signup, take a spot, or send email.</p>
|
||||||
<label for="add-shift">
|
<WalkInField id="correct-first" label="First name" name="first_name" type="text" value={correction.values.firstName} error={correction.errors.firstName} />
|
||||||
Shift
|
<WalkInField id="correct-last" label="Last name" name="last_name" type="text" value={correction.values.lastName} error={correction.errors.lastName} />
|
||||||
<select id="add-shift" name="shift" required>
|
<WalkInField id="correct-email" label="Email" name="email" type="email" value={correction.values.email} error={correction.errors.email} />
|
||||||
<ShiftTargetOptions targets={props.shifts} selectedId={props.shiftId} />
|
<WalkInField
|
||||||
</select>
|
id="correct-phone"
|
||||||
</label>
|
label="Phone"
|
||||||
<label for="add-notes">
|
name="phone"
|
||||||
Notes (optional)
|
type="tel"
|
||||||
<textarea id="add-notes" name="notes" aria-invalid={errors.notes ? 'true' : undefined}>
|
value={correction.values.phone}
|
||||||
{values.notes}
|
error={correction.errors.phone}
|
||||||
</textarea>
|
required
|
||||||
{errors.notes ? <span class="field-error">{errors.notes}</span> : null}
|
/>
|
||||||
</label>
|
<button type="submit">Save contact</button>
|
||||||
<button type="submit">Add to this shift</button>
|
|
||||||
</form>
|
</form>
|
||||||
) : (
|
</details>
|
||||||
<p class="empty">No open shift is available.</p>
|
<details class="contact-menu" name="contact-action" open={addOpen ? true : undefined}>
|
||||||
)}
|
<summary>
|
||||||
|
Add to a shift
|
||||||
|
<span class="edit-chevron" aria-hidden="true" />
|
||||||
|
</summary>
|
||||||
|
{props.error ? <p class="error">{props.error}</p> : null}
|
||||||
|
{props.shifts.length > 0 ? (
|
||||||
|
<form method="post" action={appPath(props.config, `/admin/contacts/${props.contact.id}/add`)} class="signup-form">
|
||||||
|
<p>This uses their saved name, email, and phone. It takes one spot and queues a confirmation email.</p>
|
||||||
|
{props.form.message ? <p class="error">{props.form.message}</p> : null}
|
||||||
|
{errorEntries.length > 0 ? (
|
||||||
|
<div class="error" role="alert">
|
||||||
|
<p>Check these fields:</p>
|
||||||
|
<ul>
|
||||||
|
{errorEntries.map(([field, message]) => (
|
||||||
|
<li key={field}>{message}</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<input type="hidden" name="csrf" value={props.csrf} />
|
||||||
|
<input type="hidden" name="form_token" value={props.form.token} />
|
||||||
|
<label for="add-shift">
|
||||||
|
Shift
|
||||||
|
<select id="add-shift" name="shift" required>
|
||||||
|
<ShiftTargetOptions targets={props.shifts} selectedId={props.shiftId} />
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label for="add-notes">
|
||||||
|
Notes (optional)
|
||||||
|
<textarea id="add-notes" name="notes" aria-invalid={errors.notes ? 'true' : undefined}>
|
||||||
|
{values.notes}
|
||||||
|
</textarea>
|
||||||
|
{errors.notes ? <span class="field-error">{errors.notes}</span> : null}
|
||||||
|
</label>
|
||||||
|
<button type="submit">Add to this shift</button>
|
||||||
|
</form>
|
||||||
|
) : (
|
||||||
|
<p class="empty">No open shift is available.</p>
|
||||||
|
)}
|
||||||
|
</details>
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1195,7 +1244,7 @@ function ShiftList(props: { config: AppConfig; event: AdminEvent; csrf: string;
|
|||||||
<details class="help-tip">
|
<details class="help-tip">
|
||||||
<summary aria-label="About upcoming shifts">?</summary>
|
<summary aria-label="About upcoming shifts">?</summary>
|
||||||
<p>
|
<p>
|
||||||
Shifts show on the public list when this event is public, the shift is not cancelled, and it has not ended. Repeating shifts add dates for the next eight weeks. Add weekly shifts fills those dates. Shifts already on the schedule stay as they are, including cancelled ones.
|
Shifts show on the public list when this event is public, the shift is not cancelled, and it has not ended. Repeating shifts add dates for the next three months. Add weekly shifts fills those dates. Shifts already on the schedule stay as they are, including cancelled ones.
|
||||||
</p>
|
</p>
|
||||||
</details>
|
</details>
|
||||||
</div>
|
</div>
|
||||||
@@ -1374,7 +1423,7 @@ function WeeklyTemplates(props: { config: AppConfig; event: AdminEvent; csrf: st
|
|||||||
<div>
|
<div>
|
||||||
<h2 id="templates-heading">Repeating shifts</h2>
|
<h2 id="templates-heading">Repeating shifts</h2>
|
||||||
<p class="event-panel-note">
|
<p class="event-panel-note">
|
||||||
Each one adds 8 weeks ahead.{' '}
|
Each one adds three months ahead.{' '}
|
||||||
<button type="submit" class="text-action" form="add-weekly">
|
<button type="submit" class="text-action" form="add-weekly">
|
||||||
Add weekly shifts
|
Add weekly shifts
|
||||||
</button>
|
</button>
|
||||||
@@ -1603,7 +1652,7 @@ function WalkInForm(props: { config: AppConfig; csrf: string; shiftId: number; f
|
|||||||
return (
|
return (
|
||||||
<form method="post" action={appPath(props.config, `/admin/shifts/${props.shiftId}/walk-in`)} class="signup-form event-details-form">
|
<form method="post" action={appPath(props.config, `/admin/shifts/${props.shiftId}/walk-in`)} class="signup-form event-details-form">
|
||||||
<h2 id="walkin-heading">Add a walk-in</h2>
|
<h2 id="walkin-heading">Add a walk-in</h2>
|
||||||
<p>This is one person who is here. It takes one spot and queues a confirmation email. Another person can use the same email. Their name stays off the public list.</p>
|
<p>This is one person who is here. It takes one spot and queues a confirmation email. Another person can use the same email. Their name is listed on the public sign-up page when this shift is posted there. Email and notes stay off that page.</p>
|
||||||
{props.form.message ? <p class="error">{props.form.message}</p> : null}
|
{props.form.message ? <p class="error">{props.form.message}</p> : null}
|
||||||
{errorEntries.length > 0 ? (
|
{errorEntries.length > 0 ? (
|
||||||
<div class="error" role="alert">
|
<div class="error" role="alert">
|
||||||
@@ -1890,7 +1939,7 @@ const NOTICES: Record<string, string> = {
|
|||||||
'no-show': 'Marked as a no-show.',
|
'no-show': 'Marked as a no-show.',
|
||||||
'attendance-cleared': 'The attendance mark is cleared.',
|
'attendance-cleared': 'The attendance mark is cleared.',
|
||||||
moved: 'They are on this shift. A change email is queued.',
|
moved: 'They are on this shift. A change email is queued.',
|
||||||
generated: 'Weekly shifts for the next eight weeks are on the schedule. Existing shifts were left as they are.',
|
generated: 'Weekly shifts for the next three months are on the schedule. Existing shifts were left as they are.',
|
||||||
'no-template': 'There is no active weekly template.',
|
'no-template': 'There is no active weekly template.',
|
||||||
'template-saved': 'The weekly template is saved. Shifts already on the schedule were not changed.',
|
'template-saved': 'The weekly template is saved. Shifts already on the schedule were not changed.',
|
||||||
'template-ended': 'This weekly template has ended. Shifts already on the schedule stay.',
|
'template-ended': 'This weekly template has ended. Shifts already on the schedule stay.',
|
||||||
|
|||||||
+25
-4
@@ -7,6 +7,7 @@ import { cancelPendingConfirmations, cancelPendingReminders, queueCancellation,
|
|||||||
import type { MailShift } from '../mail/templates.js';
|
import type { MailShift } from '../mail/templates.js';
|
||||||
import type { MailIdentity } from '../mail/types.js';
|
import type { MailIdentity } from '../mail/types.js';
|
||||||
import { confirmedPersonOnShift, confirmedPersonShiftIds, reserveSignup, type ReserveInput, type ReserveResult } from '../signup.js';
|
import { confirmedPersonOnShift, confirmedPersonShiftIds, reserveSignup, type ReserveInput, type ReserveResult } from '../signup.js';
|
||||||
|
import { isWithinSignupWindow } from '../signup-window.js';
|
||||||
import { isUniqueConstraint } from '../sqlite-error.js';
|
import { isUniqueConstraint } from '../sqlite-error.js';
|
||||||
import { addLocalDays, assertSameDayShift, assertValidTimeZone, formatInstantInZone, formatUtc, localShiftToUtc, LocalTimeError, todayInZone } from '../time.js';
|
import { addLocalDays, assertSameDayShift, assertValidTimeZone, formatInstantInZone, formatUtc, localShiftToUtc, LocalTimeError, todayInZone } from '../time.js';
|
||||||
|
|
||||||
@@ -1006,7 +1007,7 @@ export function listMoveTargets(
|
|||||||
eventId: number,
|
eventId: number,
|
||||||
shiftId: number,
|
shiftId: number,
|
||||||
now: string,
|
now: string,
|
||||||
options?: { publishedOnly?: boolean; excludePerson?: { email: string; name: string } },
|
options?: { publishedOnly?: boolean; excludePerson?: { email: string; name: string }; signupWindow?: boolean },
|
||||||
): MoveTarget[] {
|
): MoveTarget[] {
|
||||||
const blocked = new Set<number>();
|
const blocked = new Set<number>();
|
||||||
if (options?.excludePerson) {
|
if (options?.excludePerson) {
|
||||||
@@ -1042,6 +1043,7 @@ export function listMoveTargets(
|
|||||||
if (Number(row.occupied) >= Number(row.capacity)) return [];
|
if (Number(row.occupied) >= Number(row.capacity)) return [];
|
||||||
const start = formatInstantInZone(row.starts_at_utc, row.tz);
|
const start = formatInstantInZone(row.starts_at_utc, row.tz);
|
||||||
const end = formatInstantInZone(row.ends_at_utc, row.tz);
|
const end = formatInstantInZone(row.ends_at_utc, row.tz);
|
||||||
|
if (options?.signupWindow && !isWithinSignupWindow(start.date, todayInZone(row.tz, Temporal.Instant.from(now)))) return [];
|
||||||
return [{
|
return [{
|
||||||
id: row.id,
|
id: row.id,
|
||||||
date: start.date,
|
date: start.date,
|
||||||
@@ -1197,14 +1199,23 @@ function relocate(
|
|||||||
if (destinationShiftId === source.shift_id) return { ok: false, error: transferError(options.audience, 'same'), shiftId: source.shift_id };
|
if (destinationShiftId === source.shift_id) return { ok: false, error: transferError(options.audience, 'same'), shiftId: source.shift_id };
|
||||||
const destination = db
|
const destination = db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT s.id AS id, s.event_id AS event_id, s.cancelled AS cancelled, s.ends_at_utc AS ends_at_utc,
|
`SELECT s.id AS id, s.event_id AS event_id, s.cancelled AS cancelled, s.starts_at_utc AS starts_at_utc,
|
||||||
s.capacity AS capacity, e.published AS published
|
s.ends_at_utc AS ends_at_utc, s.capacity AS capacity, e.published AS published, e.tz AS tz
|
||||||
FROM shifts s
|
FROM shifts s
|
||||||
JOIN events e ON e.id = s.event_id
|
JOIN events e ON e.id = s.event_id
|
||||||
WHERE s.id = ?`,
|
WHERE s.id = ?`,
|
||||||
)
|
)
|
||||||
.get(destinationShiftId) as
|
.get(destinationShiftId) as
|
||||||
| { id: number; event_id: number; cancelled: number; ends_at_utc: string; capacity: number; published: number }
|
| {
|
||||||
|
id: number;
|
||||||
|
event_id: number;
|
||||||
|
cancelled: number;
|
||||||
|
starts_at_utc: string;
|
||||||
|
ends_at_utc: string;
|
||||||
|
capacity: number;
|
||||||
|
published: number;
|
||||||
|
tz: string;
|
||||||
|
}
|
||||||
| undefined;
|
| undefined;
|
||||||
if (!destination) return { ok: false, error: transferError(options.audience, 'missing'), shiftId: source.shift_id };
|
if (!destination) return { ok: false, error: transferError(options.audience, 'missing'), shiftId: source.shift_id };
|
||||||
if (destination.event_id !== source.event_id) return { ok: false, error: transferError(options.audience, 'event'), shiftId: source.shift_id };
|
if (destination.event_id !== source.event_id) return { ok: false, error: transferError(options.audience, 'event'), shiftId: source.shift_id };
|
||||||
@@ -1214,6 +1225,13 @@ function relocate(
|
|||||||
if (destination.cancelled === 1 || destination.ends_at_utc <= now) {
|
if (destination.cancelled === 1 || destination.ends_at_utc <= now) {
|
||||||
return { ok: false, error: transferError(options.audience, 'closed'), shiftId: source.shift_id };
|
return { ok: false, error: transferError(options.audience, 'closed'), shiftId: source.shift_id };
|
||||||
}
|
}
|
||||||
|
if (options.audience === 'volunteer') {
|
||||||
|
const start = formatInstantInZone(destination.starts_at_utc, destination.tz);
|
||||||
|
const today = todayInZone(destination.tz, Temporal.Instant.from(now));
|
||||||
|
if (!isWithinSignupWindow(start.date, today)) {
|
||||||
|
return { ok: false, error: transferError(options.audience, 'early'), shiftId: source.shift_id };
|
||||||
|
}
|
||||||
|
}
|
||||||
if (confirmedPersonOnShift(db, destination.id, source.email_norm, source.name)) {
|
if (confirmedPersonOnShift(db, destination.id, source.email_norm, source.name)) {
|
||||||
return { ok: false, error: transferError(options.audience, 'duplicate'), shiftId: source.shift_id };
|
return { ok: false, error: transferError(options.audience, 'duplicate'), shiftId: source.shift_id };
|
||||||
}
|
}
|
||||||
@@ -1308,6 +1326,7 @@ function transferError(audience: TransferOptions['audience'], code: TransferErro
|
|||||||
missing: 'That shift is not available.',
|
missing: 'That shift is not available.',
|
||||||
event: 'Choose a shift in this event.',
|
event: 'Choose a shift in this event.',
|
||||||
closed: 'That shift is closed.',
|
closed: 'That shift is closed.',
|
||||||
|
early: 'That shift is not open for sign-up yet.',
|
||||||
duplicate: 'That person is already signed up for this shift.',
|
duplicate: 'That person is already signed up for this shift.',
|
||||||
full: 'That shift is full.',
|
full: 'That shift is full.',
|
||||||
used: 'This form was already used for a different signup. Submit it again.',
|
used: 'This form was already used for a different signup. Submit it again.',
|
||||||
@@ -1322,6 +1341,7 @@ function transferError(audience: TransferOptions['audience'], code: TransferErro
|
|||||||
missing: 'That shift is not available.',
|
missing: 'That shift is not available.',
|
||||||
event: 'Choose a shift in this event.',
|
event: 'Choose a shift in this event.',
|
||||||
closed: 'That shift is closed.',
|
closed: 'That shift is closed.',
|
||||||
|
early: 'Sign-up for that shift opens three months before the date.',
|
||||||
duplicate: 'You are already signed up for that shift.',
|
duplicate: 'You are already signed up for that shift.',
|
||||||
full: 'That shift is full.',
|
full: 'That shift is full.',
|
||||||
used: 'This form was already used. Open the link from your email.',
|
used: 'This form was already used. Open the link from your email.',
|
||||||
@@ -1339,6 +1359,7 @@ type TransferError =
|
|||||||
| 'missing'
|
| 'missing'
|
||||||
| 'event'
|
| 'event'
|
||||||
| 'closed'
|
| 'closed'
|
||||||
|
| 'early'
|
||||||
| 'duplicate'
|
| 'duplicate'
|
||||||
| 'full'
|
| 'full'
|
||||||
| 'used'
|
| 'used'
|
||||||
|
|||||||
+2
-2
@@ -72,7 +72,7 @@ export function createApp(
|
|||||||
db,
|
db,
|
||||||
at,
|
at,
|
||||||
`${event.title} · Hope Volunteer`,
|
`${event.title} · Hope Volunteer`,
|
||||||
<EventPage config={config} event={event} now={at} month={c.req.query('month')} path="/" />,
|
<EventPage config={config} event={event} now={at} month={c.req.query('month')} view={c.req.query('view')} path="/" />,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ export function createApp(
|
|||||||
db,
|
db,
|
||||||
at,
|
at,
|
||||||
`${event.title} · Hope Volunteer`,
|
`${event.title} · Hope Volunteer`,
|
||||||
<EventPage config={config} event={event} now={at} month={c.req.query('month')} />,
|
<EventPage config={config} event={event} now={at} month={c.req.query('month')} view={c.req.query('view')} />,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { csvCell, csvImportedCell } from './export.js';
|
|||||||
import { capitalizeName, formatPhone } from './person-format.js';
|
import { capitalizeName, formatPhone } from './person-format.js';
|
||||||
import type { SignupValues } from './signup-form.js';
|
import type { SignupValues } from './signup-form.js';
|
||||||
import { isUniqueConstraint } from './sqlite-error.js';
|
import { isUniqueConstraint } from './sqlite-error.js';
|
||||||
|
import { formatInstantInZone, isUtcInstant } from './time.js';
|
||||||
|
|
||||||
const MAX_ROWS = 2000;
|
const MAX_ROWS = 2000;
|
||||||
export const CONTACT_LIST_PAGE = 20;
|
export const CONTACT_LIST_PAGE = 20;
|
||||||
@@ -34,6 +35,12 @@ export type ContactImportSummary = {
|
|||||||
skips: ContactSkip[];
|
skips: ContactSkip[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ContactShift = {
|
||||||
|
signupId: number;
|
||||||
|
shiftId: number;
|
||||||
|
label: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type Contact = {
|
export type Contact = {
|
||||||
id: number;
|
id: number;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
@@ -207,6 +214,41 @@ export function loadContacts(db: Database.Database, query: string): { total: num
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shifts this saved person signed up for.
|
||||||
|
* Current means a confirmed signup whose shift has not ended.
|
||||||
|
* Past means the shift has ended, including a cancelled signup.
|
||||||
|
*/
|
||||||
|
export function contactSignupShifts(
|
||||||
|
db: Database.Database,
|
||||||
|
person: Pick<Contact, 'firstName' | 'lastName' | 'email'>,
|
||||||
|
now: string,
|
||||||
|
): { current: ContactShift[]; past: ContactShift[] } {
|
||||||
|
if (!isUtcInstant(now)) return { current: [], past: [] };
|
||||||
|
const rows = db
|
||||||
|
.prepare(
|
||||||
|
`SELECT su.id AS signup_id, su.status AS status,
|
||||||
|
s.id AS id, s.role AS role, s.starts_at_utc AS starts_at_utc, s.ends_at_utc AS ends_at_utc,
|
||||||
|
s.cancelled AS cancelled, e.title AS title, e.tz AS tz, e.published AS published
|
||||||
|
FROM signups su
|
||||||
|
JOIN shifts s ON s.id = su.shift_id
|
||||||
|
JOIN events e ON e.id = s.event_id
|
||||||
|
WHERE su.anonymized_at IS NULL AND su.name IS NOT NULL AND su.email_norm IS NOT NULL
|
||||||
|
AND su.email_norm = ? AND su.name = ? COLLATE NOCASE
|
||||||
|
ORDER BY s.starts_at_utc, s.id, su.id`,
|
||||||
|
)
|
||||||
|
.all(person.email, contactSignupName(person)) as ContactShiftRow[];
|
||||||
|
const current: ContactShift[] = [];
|
||||||
|
const past: ContactShift[] = [];
|
||||||
|
for (const row of rows) {
|
||||||
|
const shift = { signupId: row.signup_id, shiftId: row.id, label: contactShiftLabel(row) };
|
||||||
|
if (row.ends_at_utc > now && row.status === 'confirmed' && row.cancelled === 0) current.push(shift);
|
||||||
|
else if (row.ends_at_utc <= now) past.push(shift);
|
||||||
|
}
|
||||||
|
past.reverse();
|
||||||
|
return { current, past };
|
||||||
|
}
|
||||||
|
|
||||||
export function getContact(db: Database.Database, id: number): Contact | null {
|
export function getContact(db: Database.Database, id: number): Contact | null {
|
||||||
if (!Number.isSafeInteger(id) || id < 1) return null;
|
if (!Number.isSafeInteger(id) || id < 1) return null;
|
||||||
const row = db.prepare('SELECT id, first_name, last_name, email, phone FROM contacts WHERE id = ?').get(id) as ContactRow | undefined;
|
const row = db.prepare('SELECT id, first_name, last_name, email, phone FROM contacts WHERE id = ?').get(id) as ContactRow | undefined;
|
||||||
@@ -341,6 +383,34 @@ function present(row: ContactRow): Contact {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ContactShiftRow = {
|
||||||
|
signup_id: number;
|
||||||
|
status: string;
|
||||||
|
id: number;
|
||||||
|
role: string;
|
||||||
|
starts_at_utc: string;
|
||||||
|
ends_at_utc: string;
|
||||||
|
cancelled: number;
|
||||||
|
title: string;
|
||||||
|
tz: string;
|
||||||
|
published: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** A signup with no space is saved with a hyphen as the last name. The signup itself keeps the single name. */
|
||||||
|
function contactSignupName(person: Pick<Contact, 'firstName' | 'lastName'>): string {
|
||||||
|
return person.lastName === '-' ? person.firstName : `${person.firstName} ${person.lastName}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function contactShiftLabel(row: ContactShiftRow): string {
|
||||||
|
const start = formatInstantInZone(row.starts_at_utc, row.tz);
|
||||||
|
const end = formatInstantInZone(row.ends_at_utc, row.tz);
|
||||||
|
const comma = start.dateLabel.indexOf(', ');
|
||||||
|
const date = comma === -1 ? start.dateLabel : start.dateLabel.slice(comma + 2);
|
||||||
|
const publicity = row.published === 1 ? '' : ' (not on the public list)';
|
||||||
|
const state = row.status === 'cancelled' ? ' (cancelled)' : row.cancelled === 1 ? ' (shift cancelled)' : '';
|
||||||
|
return `${row.title}: ${row.role}, ${date}, ${start.timeLabel} to ${end.timeLabel} ${end.abbreviation}${publicity}${state}`;
|
||||||
|
}
|
||||||
|
|
||||||
function columnIndex(cells: string[]): { first: number; last: number; email: number; phone: number } | null {
|
function columnIndex(cells: string[]): { first: number; last: number; email: number; phone: number } | null {
|
||||||
const names = cells.map((cell) => csvImportedCell(cell).toLowerCase());
|
const names = cells.map((cell) => csvImportedCell(cell).toLowerCase());
|
||||||
const first = names.indexOf('first name');
|
const first = names.indexOf('first name');
|
||||||
|
|||||||
+1
-1
@@ -107,7 +107,7 @@ export async function runSeedCli(env: NodeJS.ProcessEnv = process.env): Promise<
|
|||||||
`Event ${result.slug}: ${result.shiftIds.length} one-off shifts and ${result.signupIds.length} fake signups.`,
|
`Event ${result.slug}: ${result.shiftIds.length} one-off shifts and ${result.signupIds.length} fake signups.`,
|
||||||
);
|
);
|
||||||
console.log('Each signup is one person. Another person can use the same email. Group size is fixed at 1.');
|
console.log('Each signup is one person. Another person can use the same email. Group size is fixed at 1.');
|
||||||
console.log('The weekly template is stored. Starting the app adds its shifts for the next eight weeks.');
|
console.log('The weekly template is stored. Starting the app adds its shifts for the next three months.');
|
||||||
console.log('No coordinator account was created.');
|
console.log('No coordinator account was created.');
|
||||||
} finally {
|
} finally {
|
||||||
db.close();
|
db.close();
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ export function startDailyExpansionRunner(db: Database.Database, now: () => stri
|
|||||||
try {
|
try {
|
||||||
const result = runDueTemplateExpansion(db, now());
|
const result = runDueTemplateExpansion(db, now());
|
||||||
if (result.created > 0) {
|
if (result.created > 0) {
|
||||||
console.log(`Added ${result.created} weekly shifts for the next eight weeks.`);
|
console.log(`Added ${result.created} weekly shifts for the next three months.`);
|
||||||
}
|
}
|
||||||
for (const skip of result.skipped) console.error(skip);
|
for (const skip of result.skipped) console.error(skip);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ async function main(): Promise<void> {
|
|||||||
}
|
}
|
||||||
const expanded = expandTemplates(database, startedAt);
|
const expanded = expandTemplates(database, startedAt);
|
||||||
if (expanded.created > 0) {
|
if (expanded.created > 0) {
|
||||||
console.log(`Added ${expanded.created} weekly shifts for the next eight weeks.`);
|
console.log(`Added ${expanded.created} weekly shifts for the next three months.`);
|
||||||
}
|
}
|
||||||
for (const skip of expanded.skipped) console.error(skip);
|
for (const skip of expanded.skipped) console.error(skip);
|
||||||
runRetention(database, startedAt);
|
runRetention(database, startedAt);
|
||||||
|
|||||||
+165
-5
@@ -1,7 +1,8 @@
|
|||||||
import type { Child } from 'hono/jsx';
|
import type { Child } from 'hono/jsx';
|
||||||
import type { AppConfig } from './config.js';
|
import type { AppConfig } from './config.js';
|
||||||
import { WEEKDAY_SHORT, calendarMonth, calendarToday, chooseCalendarMonth, monthStep, type CalendarDay } from './calendar.js';
|
import { WEEKDAY_SHORT, calendarMonth, calendarToday, chooseCalendarMonth, monthStep, type CalendarDay } from './calendar.js';
|
||||||
import { spotsSentence, type PublicEvent, type PublicShift } from './schedule.js';
|
import { WEDNESDAY, spotsSentence, type PublicEvent, type PublicShift } from './schedule.js';
|
||||||
|
import { SIGNUP_TOO_EARLY, signupDeadlineLabel } from './signup-window.js';
|
||||||
import type { SignupErrors, SignupValues } from './signup-form.js';
|
import type { SignupErrors, SignupValues } from './signup-form.js';
|
||||||
import type { MoveTarget } from './admin/store.js';
|
import type { MoveTarget } from './admin/store.js';
|
||||||
import { ShiftTargetOptions } from './shift-options.js';
|
import { ShiftTargetOptions } from './shift-options.js';
|
||||||
@@ -100,7 +101,7 @@ export function Layout(props: {
|
|||||||
<main id="content" tabIndex={-1}>
|
<main id="content" tabIndex={-1}>
|
||||||
<div class="session-bar">
|
<div class="session-bar">
|
||||||
<a href={home} aria-current={props.path === home ? 'page' : undefined}>
|
<a href={home} aria-current={props.path === home ? 'page' : undefined}>
|
||||||
Calendar
|
Sign Up
|
||||||
</a>
|
</a>
|
||||||
<a href={coordinator} class={props.account ? undefined : 'session-entry'} aria-current={coordinatorHere ? 'page' : undefined}>
|
<a href={coordinator} class={props.account ? undefined : 'session-entry'} aria-current={coordinatorHere ? 'page' : undefined}>
|
||||||
Coordinator
|
Coordinator
|
||||||
@@ -224,7 +225,14 @@ export function EmptySchedulePage() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function EventPage(props: { config: AppConfig; event: PublicEvent; now: string; month?: string; path?: string }) {
|
export function EventPage(props: {
|
||||||
|
config: AppConfig;
|
||||||
|
event: PublicEvent;
|
||||||
|
now: string;
|
||||||
|
month?: string;
|
||||||
|
view?: string;
|
||||||
|
path?: string;
|
||||||
|
}) {
|
||||||
const description = props.event.description.trim();
|
const description = props.event.description.trim();
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -235,11 +243,12 @@ export function EventPage(props: { config: AppConfig; event: PublicEvent; now: s
|
|||||||
{props.event.shifts.length === 0 ? (
|
{props.event.shifts.length === 0 ? (
|
||||||
<p class="empty">No upcoming shifts are posted for this event.</p>
|
<p class="empty">No upcoming shifts are posted for this event.</p>
|
||||||
) : (
|
) : (
|
||||||
<ShiftCalendar
|
<PublicSchedule
|
||||||
config={props.config}
|
config={props.config}
|
||||||
event={props.event}
|
event={props.event}
|
||||||
now={props.now}
|
now={props.now}
|
||||||
month={props.month}
|
month={props.month}
|
||||||
|
view={props.view}
|
||||||
path={props.path ?? `/e/${encodeURIComponent(props.event.slug)}`}
|
path={props.path ?? `/e/${encodeURIComponent(props.event.slug)}`}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -485,8 +494,149 @@ export function WaitPage() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function scheduleHref(config: AppConfig, path: string, view?: 'calendar', monthId?: string): string {
|
||||||
|
const base = appPath(config, path);
|
||||||
|
if (view !== 'calendar') return base;
|
||||||
|
const params = new URLSearchParams({ view: 'calendar' });
|
||||||
|
if (monthId) params.set('month', monthId);
|
||||||
|
return `${base}?${params.toString()}`;
|
||||||
|
}
|
||||||
|
|
||||||
function monthHref(config: AppConfig, path: string, monthId: string): string {
|
function monthHref(config: AppConfig, path: string, monthId: string): string {
|
||||||
return `${appPath(config, path)}?month=${monthId}`;
|
return scheduleHref(config, path, 'calendar', monthId);
|
||||||
|
}
|
||||||
|
|
||||||
|
function signupWindowSentence(timeZone: string, now: string): string {
|
||||||
|
return `Sign-up is open through ${signupDeadlineLabel(calendarToday(timeZone, now))}.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function PublicSchedule(props: {
|
||||||
|
config: AppConfig;
|
||||||
|
event: PublicEvent;
|
||||||
|
now: string;
|
||||||
|
month?: string;
|
||||||
|
view?: string;
|
||||||
|
path: string;
|
||||||
|
}) {
|
||||||
|
const calendarView = props.view === 'calendar';
|
||||||
|
return (
|
||||||
|
<div class="signup-board">
|
||||||
|
<div class="schedule-bar">
|
||||||
|
<details class="view-menu">
|
||||||
|
<summary>
|
||||||
|
<span class="view-menu-kicker">View</span>
|
||||||
|
<span>{calendarView ? 'Calendar' : 'List'}</span>
|
||||||
|
</summary>
|
||||||
|
<div class="view-menu-list">
|
||||||
|
<a href={scheduleHref(props.config, props.path)} aria-current={calendarView ? undefined : 'page'}>
|
||||||
|
List
|
||||||
|
</a>
|
||||||
|
<a href={scheduleHref(props.config, props.path, 'calendar')} aria-current={calendarView ? 'page' : undefined}>
|
||||||
|
Calendar
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
<p class="window-note">{signupWindowSentence(props.event.timeZone, props.now)}</p>
|
||||||
|
</div>
|
||||||
|
{calendarView ? (
|
||||||
|
<ShiftCalendar config={props.config} event={props.event} now={props.now} month={props.month} path={props.path} />
|
||||||
|
) : (
|
||||||
|
<WednesdayBoard config={props.config} event={props.event} now={props.now} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
type WednesdayGroup = {
|
||||||
|
date: string;
|
||||||
|
heading: string;
|
||||||
|
shifts: PublicShift[];
|
||||||
|
};
|
||||||
|
|
||||||
|
function wednesdayGroups(shifts: PublicShift[]): WednesdayGroup[] {
|
||||||
|
const groups: WednesdayGroup[] = [];
|
||||||
|
for (const shift of shifts) {
|
||||||
|
if (shift.when.weekday !== WEDNESDAY) continue;
|
||||||
|
const last = groups.at(-1);
|
||||||
|
if (last && last.date === shift.when.date) {
|
||||||
|
last.shifts.push(shift);
|
||||||
|
} else {
|
||||||
|
const comma = shift.when.dateLabel.indexOf(', ');
|
||||||
|
groups.push({
|
||||||
|
date: shift.when.date,
|
||||||
|
heading: comma === -1 ? shift.when.dateLabel : shift.when.dateLabel.slice(comma + 2),
|
||||||
|
shifts: [shift],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
function WednesdayBoard(props: { config: AppConfig; event: PublicEvent; now: string }) {
|
||||||
|
const today = calendarToday(props.event.timeZone, props.now);
|
||||||
|
const days = wednesdayGroups(props.event.shifts);
|
||||||
|
if (days.length === 0) {
|
||||||
|
return <p class="empty">No Wednesday shifts are posted. The calendar lists shifts on other days.</p>;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<ol class="day-board">
|
||||||
|
{days.map((day) => (
|
||||||
|
<li key={day.date}>
|
||||||
|
<article class="day-card" aria-current={day.date === today ? 'date' : undefined}>
|
||||||
|
<header class="day-card-head">
|
||||||
|
<p class="day-card-dow">Wednesday</p>
|
||||||
|
<h2>
|
||||||
|
<time dateTime={day.date}>{day.heading}</time>
|
||||||
|
</h2>
|
||||||
|
{day.date === today ? <span class="today-flag">Today</span> : null}
|
||||||
|
</header>
|
||||||
|
<div class="day-card-shifts">
|
||||||
|
{day.shifts.map((shift) => (
|
||||||
|
<ShiftPane key={shift.id} config={props.config} shift={shift} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ol>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ShiftPane(props: { config: AppConfig; shift: PublicShift }) {
|
||||||
|
const shift = props.shift;
|
||||||
|
const closed = shift.full || shift.cancelled || shift.ended;
|
||||||
|
const action = closed ? 'View shift' : 'Sign up';
|
||||||
|
return (
|
||||||
|
<section class="shift-pane">
|
||||||
|
<div class="shift-pane-body">
|
||||||
|
<h3>{shift.role}</h3>
|
||||||
|
<ShiftWhen shift={shift} />
|
||||||
|
{shift.inProgress ? <p class="status">In progress</p> : null}
|
||||||
|
<Spots shift={shift} />
|
||||||
|
<h4 class="roster-label">Volunteers</h4>
|
||||||
|
{shift.volunteers.length === 0 ? (
|
||||||
|
<p class="roster-empty">No one signed up yet.</p>
|
||||||
|
) : (
|
||||||
|
<ul class="roster-names">
|
||||||
|
{shift.volunteers.map((name, index) => (
|
||||||
|
<li key={`${shift.id}-${index}`}>{name}</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{shift.full ? (
|
||||||
|
<p class="btn-card is-static">
|
||||||
|
<span class="shift-full-label">Full</span>
|
||||||
|
<span>Not accepting more signups</span>
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<a class="btn-card" href={appPath(props.config, `/s/${shift.id}`)}>
|
||||||
|
{action}
|
||||||
|
<img src={asset(props.config, '/img/icons/right-arrow.svg')} alt="" />
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function MonthArrow(props: { config: AppConfig; path: string; monthId: string; direction: 'prev' | 'next' }) {
|
function MonthArrow(props: { config: AppConfig; path: string; monthId: string; direction: 'prev' | 'next' }) {
|
||||||
@@ -661,6 +811,7 @@ function CalendarShift(props: { config: AppConfig; shift: PublicShift }) {
|
|||||||
{action} for {shift.role} on {shift.when.dateLabel}, {shift.when.startLabel} to {shift.when.endLabel}{' '}
|
{action} for {shift.role} on {shift.when.dateLabel}, {shift.when.startLabel} to {shift.when.endLabel}{' '}
|
||||||
{shift.when.abbreviation}. {spotsSentence(shift)}
|
{shift.when.abbreviation}. {spotsSentence(shift)}
|
||||||
{shift.inProgress ? ' In progress.' : ''}
|
{shift.inProgress ? ' In progress.' : ''}
|
||||||
|
{shift.volunteers.length > 0 ? ` Volunteers: ${shift.volunteers.join(', ')}.` : ' No one signed up yet.'}
|
||||||
</span>
|
</span>
|
||||||
<div class="cal-detail" aria-hidden="true">
|
<div class="cal-detail" aria-hidden="true">
|
||||||
<span class="cal-hold" aria-hidden="true"></span>
|
<span class="cal-hold" aria-hidden="true"></span>
|
||||||
@@ -673,6 +824,7 @@ function CalendarShift(props: { config: AppConfig; shift: PublicShift }) {
|
|||||||
</span>
|
</span>
|
||||||
{shift.inProgress ? <span class="status">In progress</span> : null}
|
{shift.inProgress ? <span class="status">In progress</span> : null}
|
||||||
<Spots shift={shift} />
|
<Spots shift={shift} />
|
||||||
|
<span class="cal-names">{shift.volunteers.length > 0 ? shift.volunteers.join(', ') : 'No one signed up yet.'}</span>
|
||||||
<span class="cal-action">{action}</span>
|
<span class="cal-action">{action}</span>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
@@ -822,6 +974,14 @@ function Field(props: {
|
|||||||
function StatusLine(props: { shift: PublicShift }) {
|
function StatusLine(props: { shift: PublicShift }) {
|
||||||
if (props.shift.cancelled) return <p class="status">Cancelled. This shift is closed.</p>;
|
if (props.shift.cancelled) return <p class="status">Cancelled. This shift is closed.</p>;
|
||||||
if (props.shift.ended) return <p class="status">Ended. This shift is closed.</p>;
|
if (props.shift.ended) return <p class="status">Ended. This shift is closed.</p>;
|
||||||
|
if (props.shift.tooEarly) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<p class="status">{SIGNUP_TOO_EARLY}</p>
|
||||||
|
<Spots shift={props.shift} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{props.shift.inProgress ? <p class="status">In progress</p> : null}
|
{props.shift.inProgress ? <p class="status">In progress</p> : null}
|
||||||
|
|||||||
+3
-5
@@ -1,10 +1,8 @@
|
|||||||
import { Temporal } from '@js-temporal/polyfill';
|
import { Temporal } from '@js-temporal/polyfill';
|
||||||
import type Database from 'better-sqlite3';
|
import type Database from 'better-sqlite3';
|
||||||
import { writeAudit } from './auth/audit.js';
|
import { writeAudit } from './auth/audit.js';
|
||||||
import { LocalTimeError, addLocalDays, localShiftToUtc, todayInZone } from './time.js';
|
import { signupDeadline } from './signup-window.js';
|
||||||
|
import { LocalTimeError, localShiftToUtc, todayInZone } from './time.js';
|
||||||
/** How far ahead an active template fills the schedule, counted in local days. */
|
|
||||||
export const TEMPLATE_HORIZON_DAYS = 56;
|
|
||||||
|
|
||||||
export type ExpandResult = {
|
export type ExpandResult = {
|
||||||
created: number;
|
created: number;
|
||||||
@@ -88,7 +86,7 @@ function expandOne(
|
|||||||
if (err instanceof LocalTimeError) return { created: 0, skipped: [err.message] };
|
if (err instanceof LocalTimeError) return { created: 0, skipped: [err.message] };
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
const windowEnd = addLocalDays(today, TEMPLATE_HORIZON_DAYS);
|
const windowEnd = signupDeadline(today);
|
||||||
const dates = occurrenceDates(template, today, windowEnd);
|
const dates = occurrenceDates(template, today, windowEnd);
|
||||||
const insert = db.prepare(
|
const insert = db.prepare(
|
||||||
`INSERT OR IGNORE INTO shifts (
|
`INSERT OR IGNORE INTO shifts (
|
||||||
|
|||||||
+48
-4
@@ -1,5 +1,12 @@
|
|||||||
|
import { Temporal } from '@js-temporal/polyfill';
|
||||||
import type Database from 'better-sqlite3';
|
import type Database from 'better-sqlite3';
|
||||||
import { formatInstantInZone } from './time.js';
|
import { isWithinSignupWindow } from './signup-window.js';
|
||||||
|
import { formatInstantInZone, todayInZone } from './time.js';
|
||||||
|
|
||||||
|
/** Weekday 0 is Sunday, matching the zoned clock. The public sign-up cards use Wednesday. */
|
||||||
|
export const WEDNESDAY = 3;
|
||||||
|
|
||||||
|
const WEEKDAY_LABELS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] as const;
|
||||||
|
|
||||||
export type PublicShift = {
|
export type PublicShift = {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -13,6 +20,9 @@ export type PublicShift = {
|
|||||||
cancelled: boolean;
|
cancelled: boolean;
|
||||||
ended: boolean;
|
ended: boolean;
|
||||||
inProgress: boolean;
|
inProgress: boolean;
|
||||||
|
/** The shift starts more than three months from today in the event time zone. */
|
||||||
|
tooEarly: boolean;
|
||||||
|
volunteers: string[];
|
||||||
event: {
|
event: {
|
||||||
id: number;
|
id: number;
|
||||||
slug: string;
|
slug: string;
|
||||||
@@ -29,6 +39,8 @@ export type PublicShift = {
|
|||||||
startLabel: string;
|
startLabel: string;
|
||||||
endLabel: string;
|
endLabel: string;
|
||||||
abbreviation: string;
|
abbreviation: string;
|
||||||
|
weekday: number;
|
||||||
|
weekdayLabel: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -107,6 +119,7 @@ export function getPublishedEvent(db: Database.Database, slug: string, now: stri
|
|||||||
ORDER BY s.starts_at_utc, s.role, s.id`,
|
ORDER BY s.starts_at_utc, s.role, s.id`,
|
||||||
)
|
)
|
||||||
.all(event.id, now) as ShiftRow[];
|
.all(event.id, now) as ShiftRow[];
|
||||||
|
const names = volunteerNamesByShift(db, rows.map((row) => row.id));
|
||||||
return {
|
return {
|
||||||
id: event.id,
|
id: event.id,
|
||||||
slug: event.slug,
|
slug: event.slug,
|
||||||
@@ -114,7 +127,9 @@ export function getPublishedEvent(db: Database.Database, slug: string, now: stri
|
|||||||
description: event.description,
|
description: event.description,
|
||||||
location: event.location,
|
location: event.location,
|
||||||
timeZone: event.tz,
|
timeZone: event.tz,
|
||||||
shifts: rows.map((row) => presentShift(row, now)),
|
shifts: rows
|
||||||
|
.map((row) => presentShift(row, now, names.get(row.id) ?? []))
|
||||||
|
.filter((shift) => !shift.tooEarly),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +142,9 @@ export function getPublicShift(db: Database.Database, id: number, now: string):
|
|||||||
GROUP BY s.id`,
|
GROUP BY s.id`,
|
||||||
)
|
)
|
||||||
.get(id) as ShiftRow | undefined;
|
.get(id) as ShiftRow | undefined;
|
||||||
return row ? presentShift(row, now) : null;
|
if (!row) return null;
|
||||||
|
const names = volunteerNamesByShift(db, [row.id]);
|
||||||
|
return presentShift(row, now, names.get(row.id) ?? []);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function spotsSentence(shift: Pick<PublicShift, 'occupied' | 'capacity'>): string {
|
export function spotsSentence(shift: Pick<PublicShift, 'occupied' | 'capacity'>): string {
|
||||||
@@ -135,7 +152,7 @@ export function spotsSentence(shift: Pick<PublicShift, 'occupied' | 'capacity'>)
|
|||||||
return `${filled}/${shift.capacity} spots filled`;
|
return `${filled}/${shift.capacity} spots filled`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function presentShift(row: ShiftRow, now: string): PublicShift {
|
function presentShift(row: ShiftRow, now: string, volunteers: string[]): PublicShift {
|
||||||
const start = formatInstantInZone(row.starts_at_utc, row.tz);
|
const start = formatInstantInZone(row.starts_at_utc, row.tz);
|
||||||
const end = formatInstantInZone(row.ends_at_utc, row.tz);
|
const end = formatInstantInZone(row.ends_at_utc, row.tz);
|
||||||
const occupied = Number(row.occupied);
|
const occupied = Number(row.occupied);
|
||||||
@@ -144,6 +161,8 @@ function presentShift(row: ShiftRow, now: string): PublicShift {
|
|||||||
const cancelled = row.cancelled === 1;
|
const cancelled = row.cancelled === 1;
|
||||||
const ended = row.ends_at_utc <= now;
|
const ended = row.ends_at_utc <= now;
|
||||||
const inProgress = !cancelled && !ended && row.starts_at_utc <= now;
|
const inProgress = !cancelled && !ended && row.starts_at_utc <= now;
|
||||||
|
const today = todayInZone(row.tz, Temporal.Instant.from(now));
|
||||||
|
const tooEarly = !isWithinSignupWindow(start.date, today);
|
||||||
return {
|
return {
|
||||||
id: row.id,
|
id: row.id,
|
||||||
role: row.role,
|
role: row.role,
|
||||||
@@ -156,6 +175,8 @@ function presentShift(row: ShiftRow, now: string): PublicShift {
|
|||||||
cancelled,
|
cancelled,
|
||||||
ended,
|
ended,
|
||||||
inProgress,
|
inProgress,
|
||||||
|
tooEarly,
|
||||||
|
volunteers,
|
||||||
event: {
|
event: {
|
||||||
id: row.event_id,
|
id: row.event_id,
|
||||||
slug: row.slug,
|
slug: row.slug,
|
||||||
@@ -172,6 +193,29 @@ function presentShift(row: ShiftRow, now: string): PublicShift {
|
|||||||
startLabel: start.timeLabel,
|
startLabel: start.timeLabel,
|
||||||
endLabel: end.timeLabel,
|
endLabel: end.timeLabel,
|
||||||
abbreviation: start.abbreviation,
|
abbreviation: start.abbreviation,
|
||||||
|
weekday: start.weekday,
|
||||||
|
weekdayLabel: WEEKDAY_LABELS[start.weekday] ?? 'Day',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function volunteerNamesByShift(db: Database.Database, shiftIds: number[]): Map<number, string[]> {
|
||||||
|
const names = new Map<number, string[]>();
|
||||||
|
if (shiftIds.length === 0) return names;
|
||||||
|
const marks = shiftIds.map(() => '?').join(', ');
|
||||||
|
const rows = db
|
||||||
|
.prepare(
|
||||||
|
`SELECT shift_id AS shift_id, name AS name
|
||||||
|
FROM signups
|
||||||
|
WHERE status = 'confirmed' AND anonymized_at IS NULL AND name IS NOT NULL
|
||||||
|
AND shift_id IN (${marks})
|
||||||
|
ORDER BY name COLLATE NOCASE, id`,
|
||||||
|
)
|
||||||
|
.all(...shiftIds) as { shift_id: number; name: string }[];
|
||||||
|
for (const row of rows) {
|
||||||
|
const listed = names.get(row.shift_id);
|
||||||
|
if (listed) listed.push(row.name);
|
||||||
|
else names.set(row.shift_id, [row.name]);
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
+6
-2
@@ -26,6 +26,7 @@ import {
|
|||||||
} from './pages.js';
|
} from './pages.js';
|
||||||
import { recordInvalidManageToken, recordSignupEmail, recordSignupIp, recordSwitchAttempt } from './rate-limit.js';
|
import { recordInvalidManageToken, recordSignupEmail, recordSignupIp, recordSwitchAttempt } from './rate-limit.js';
|
||||||
import { getPublicShift, type PublicShift } from './schedule.js';
|
import { getPublicShift, type PublicShift } from './schedule.js';
|
||||||
|
import { SIGNUP_TOO_EARLY } from './signup-window.js';
|
||||||
import { EMPTY_SIGNUP, parseSignupForm, type SignupErrors, type SignupValues } from './signup-form.js';
|
import { EMPTY_SIGNUP, parseSignupForm, 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 } from './reminders.js';
|
||||||
@@ -106,6 +107,7 @@ async function submitSignup(c: Context, services: SignupServices): Promise<Respo
|
|||||||
const now = services.now();
|
const now = services.now();
|
||||||
const shift = loadShift(services, c.req.param('id') ?? '');
|
const shift = loadShift(services, c.req.param('id') ?? '');
|
||||||
if (!shift) return html(c, services, 'That page is not available · Hope Volunteer', <NotFoundPage />, 404);
|
if (!shift) return html(c, services, 'That page is not available · Hope Volunteer', <NotFoundPage />, 404);
|
||||||
|
if (shift.tooEarly) return shiftResponse(c, services, shift, 400, null, SIGNUP_TOO_EARLY);
|
||||||
const ip = clientAddress(config.trustProxy, peerAddress(c, services.clientIp), c.req.header('x-forwarded-for'));
|
const ip = clientAddress(config.trustProxy, peerAddress(c, services.clientIp), c.req.header('x-forwarded-for'));
|
||||||
if (!originAllowed(c, config.baseUrl)) {
|
if (!originAllowed(c, config.baseUrl)) {
|
||||||
return shiftResponse(c, services, shift, 403, formFor(services, shift, EMPTY_SIGNUP, {}, null), ORIGIN);
|
return shiftResponse(c, services, shift, 403, formFor(services, shift, EMPTY_SIGNUP, {}, null), ORIGIN);
|
||||||
@@ -168,6 +170,7 @@ async function submitSignup(c: Context, services: SignupServices): Promise<Respo
|
|||||||
if (reserved.ok) return redirectConfirmed(c, services, shift.id, reserved.manageToken ? { signupId: reserved.signupId, token: reserved.manageToken } : null);
|
if (reserved.ok) return redirectConfirmed(c, services, shift.id, reserved.manageToken ? { signupId: reserved.signupId, token: reserved.manageToken } : null);
|
||||||
if (reserved.reason === 'not_found') return html(c, services, 'That page is not available · Hope Volunteer', <NotFoundPage />, 404);
|
if (reserved.reason === 'not_found') return html(c, services, 'That page is not available · Hope Volunteer', <NotFoundPage />, 404);
|
||||||
if (reserved.reason === 'closed') return shiftResponse(c, services, loadShift(services, String(shift.id)) ?? shift, 400, null, CLOSED);
|
if (reserved.reason === 'closed') return shiftResponse(c, services, loadShift(services, String(shift.id)) ?? shift, 400, null, CLOSED);
|
||||||
|
if (reserved.reason === 'early') return shiftResponse(c, services, loadShift(services, String(shift.id)) ?? shift, 400, null, SIGNUP_TOO_EARLY);
|
||||||
if (reserved.reason === 'full') return shiftResponse(c, services, loadShift(services, String(shift.id)) ?? shift, 409, null, FULL);
|
if (reserved.reason === 'full') return shiftResponse(c, services, loadShift(services, String(shift.id)) ?? shift, 409, null, FULL);
|
||||||
if (reserved.reason === 'duplicate') {
|
if (reserved.reason === 'duplicate') {
|
||||||
return shiftResponse(c, services, shift, 409, formFor(services, shift, values, {}, null), ALREADY_SIGNED_UP);
|
return shiftResponse(c, services, shift, 409, formFor(services, shift, values, {}, null), ALREADY_SIGNED_UP);
|
||||||
@@ -210,7 +213,7 @@ function shiftResponse(
|
|||||||
) {
|
) {
|
||||||
if (retryAfter !== undefined) c.header('Retry-After', String(retryAfter));
|
if (retryAfter !== undefined) c.header('Retry-After', String(retryAfter));
|
||||||
const current = loadShift(services, String(shift.id)) ?? shift;
|
const current = loadShift(services, String(shift.id)) ?? shift;
|
||||||
const showForm = signup !== null && !current.cancelled && !current.ended && !current.full;
|
const showForm = signup !== null && !current.cancelled && !current.ended && !current.full && !current.tooEarly;
|
||||||
return html(
|
return html(
|
||||||
c,
|
c,
|
||||||
services,
|
services,
|
||||||
@@ -222,7 +225,7 @@ function shiftResponse(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function blankForm(services: SignupServices, shift: PublicShift): SignupFormView | null {
|
function blankForm(services: SignupServices, shift: PublicShift): SignupFormView | null {
|
||||||
if (shift.cancelled || shift.ended || shift.full) return null;
|
if (shift.cancelled || shift.ended || shift.full || shift.tooEarly) return null;
|
||||||
return formFor(services, shift, EMPTY_SIGNUP, {}, null);
|
return formFor(services, shift, EMPTY_SIGNUP, {}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,6 +403,7 @@ function switchForm(services: SignupServices, token: string, signup: { status: '
|
|||||||
if (signup.status !== 'confirmed') return null;
|
if (signup.status !== 'confirmed') return null;
|
||||||
const targets = listMoveTargets(services.db, signup.eventId, signup.shiftId, services.now(), {
|
const targets = listMoveTargets(services.db, signup.eventId, signup.shiftId, services.now(), {
|
||||||
publishedOnly: true,
|
publishedOnly: true,
|
||||||
|
signupWindow: true,
|
||||||
});
|
});
|
||||||
if (targets.length === 0) return { action: '', token: '', formToken: '', targets };
|
if (targets.length === 0) return { action: '', token: '', formToken: '', targets };
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { Temporal } from '@js-temporal/polyfill';
|
||||||
|
|
||||||
|
/** How far ahead a volunteer can join a shift, counted from today in the event's time zone. */
|
||||||
|
export const SIGNUP_WINDOW_MONTHS = 3;
|
||||||
|
|
||||||
|
export const SIGNUP_TOO_EARLY = 'Sign-up opens three months before this shift.';
|
||||||
|
|
||||||
|
const MONTHS = [
|
||||||
|
'January',
|
||||||
|
'February',
|
||||||
|
'March',
|
||||||
|
'April',
|
||||||
|
'May',
|
||||||
|
'June',
|
||||||
|
'July',
|
||||||
|
'August',
|
||||||
|
'September',
|
||||||
|
'October',
|
||||||
|
'November',
|
||||||
|
'December',
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
/** Last local date, inclusive, that is open for signup on `today`. */
|
||||||
|
export function signupDeadline(today: string): string {
|
||||||
|
return Temporal.PlainDate.from(today).add({ months: SIGNUP_WINDOW_MONTHS }).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isWithinSignupWindow(date: string, today: string): boolean {
|
||||||
|
return date <= signupDeadline(today);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function signupDeadlineLabel(today: string): string {
|
||||||
|
const date = Temporal.PlainDate.from(signupDeadline(today));
|
||||||
|
const month = MONTHS[date.month - 1];
|
||||||
|
if (!month) throw new Error(`${today} is not a date.`);
|
||||||
|
return `${month} ${date.day}, ${date.year}`;
|
||||||
|
}
|
||||||
+8
-2
@@ -5,7 +5,8 @@ import { rememberSignupContact } from './contacts.js';
|
|||||||
import { normalizeEmail } from './email.js';
|
import { normalizeEmail } from './email.js';
|
||||||
import { queueCancellation, queueConfirmation, cancelPendingConfirmations, cancelPendingReminders } from './mail/queue.js';
|
import { queueCancellation, queueConfirmation, cancelPendingConfirmations, cancelPendingReminders } from './mail/queue.js';
|
||||||
import type { MailIdentity } from './mail/types.js';
|
import type { MailIdentity } from './mail/types.js';
|
||||||
import { formatInstantInZone, formatUtc, type ZonedClock } from './time.js';
|
import { isWithinSignupWindow } from './signup-window.js';
|
||||||
|
import { formatInstantInZone, formatUtc, todayInZone, type ZonedClock } from './time.js';
|
||||||
|
|
||||||
const MANAGE_TOKEN_TTL_HOURS = 24 * 7;
|
const MANAGE_TOKEN_TTL_HOURS = 24 * 7;
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ export type ReserveInput = {
|
|||||||
|
|
||||||
export type ReserveResult =
|
export type ReserveResult =
|
||||||
| { ok: true; signupId: number; manageToken: string | null; replay: boolean }
|
| { ok: true; signupId: number; manageToken: string | null; replay: boolean }
|
||||||
| { ok: false; reason: 'not_found' | 'closed' | 'full' | 'duplicate' | 'conflict' };
|
| { ok: false; reason: 'not_found' | 'closed' | 'early' | 'full' | 'duplicate' | 'conflict' };
|
||||||
|
|
||||||
export type ManageView = {
|
export type ManageView = {
|
||||||
signupId: number;
|
signupId: number;
|
||||||
@@ -167,6 +168,11 @@ function placeReservation(db: Database.Database, input: ReserveInput, emailNorm:
|
|||||||
const coordinator = input.audience === 'coordinator';
|
const coordinator = input.audience === 'coordinator';
|
||||||
if (!shift || (!coordinator && shift.published !== 1)) return { ok: false, reason: 'not_found' };
|
if (!shift || (!coordinator && shift.published !== 1)) return { ok: false, reason: 'not_found' };
|
||||||
if (shift.cancelled === 1 || shift.ends_at_utc <= input.now) return { ok: false, reason: 'closed' };
|
if (shift.cancelled === 1 || shift.ends_at_utc <= input.now) return { ok: false, reason: 'closed' };
|
||||||
|
if (!coordinator) {
|
||||||
|
const start = formatInstantInZone(shift.starts_at_utc, shift.tz);
|
||||||
|
const today = todayInZone(shift.tz, Temporal.Instant.from(input.now));
|
||||||
|
if (!isWithinSignupWindow(start.date, today)) return { ok: false, reason: 'early' };
|
||||||
|
}
|
||||||
|
|
||||||
const existing = findOperation(db, operationKey);
|
const existing = findOperation(db, operationKey);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
|
|||||||
+3
-2
@@ -630,10 +630,11 @@ describe('coordinator screens', () => {
|
|||||||
expect(sourceRoster).not.toContain(`/admin/signups/${signupId}/move`);
|
expect(sourceRoster).not.toContain(`/admin/signups/${signupId}/move`);
|
||||||
expect(sourceRoster).toContain('0/2 spots filled');
|
expect(sourceRoster).toContain('0/2 spots filled');
|
||||||
expect(sourceRoster).toContain('event-pill is-open');
|
expect(sourceRoster).toContain('event-pill is-open');
|
||||||
const home = await (await app.request('/')).text();
|
const home = await (await app.request('/e/pantry?view=calendar')).text();
|
||||||
const shiftPage = await (await app.request(`/s/${destinationId}`)).text();
|
const shiftPage = await (await app.request(`/s/${destinationId}`)).text();
|
||||||
expect(home).not.toContain('kim@example.invalid');
|
expect(home).not.toContain('kim@example.invalid');
|
||||||
expect(home).not.toContain('Kim Example');
|
expect(home).not.toContain('Blue shirt');
|
||||||
|
expect(home).toContain('Kim Example');
|
||||||
expect(shiftPage).not.toContain('kim@example.invalid');
|
expect(shiftPage).not.toContain('kim@example.invalid');
|
||||||
expect(shiftPage).not.toContain('Attended.');
|
expect(shiftPage).not.toContain('Attended.');
|
||||||
expect(auditJson(db)).not.toContain('@');
|
expect(auditJson(db)).not.toContain('@');
|
||||||
|
|||||||
@@ -82,7 +82,9 @@ describe('manage-link cancellation', () => {
|
|||||||
{ status: 'confirmed' },
|
{ status: 'confirmed' },
|
||||||
]);
|
]);
|
||||||
expect((await (await app.request(`/s/${shiftId}`)).text())).toContain('1/1 spots filled');
|
expect((await (await app.request(`/s/${shiftId}`)).text())).toContain('1/1 spots filled');
|
||||||
expect((await (await app.request('/')).text())).not.toContain('Pat Cancel');
|
const listed = await (await app.request('/?view=calendar')).text();
|
||||||
|
expect(listed).toContain('Pat Cancel');
|
||||||
|
expect(listed).not.toContain('pat.cancel@example.invalid');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('refuses a cancel that did not come from this signup page', async () => {
|
it('refuses a cancel that did not come from this signup page', async () => {
|
||||||
@@ -207,9 +209,9 @@ describe('manage-link switch', () => {
|
|||||||
expect(letter.body_text).toContain('You switched this signup to a different shift.');
|
expect(letter.body_text).toContain('You switched this signup to a different shift.');
|
||||||
expect(letter.body_text).not.toContain('A coordinator moved');
|
expect(letter.body_text).not.toContain('A coordinator moved');
|
||||||
expect(letter.body_text).toContain(nextPath.split('?')[0]);
|
expect(letter.body_text).toContain(nextPath.split('?')[0]);
|
||||||
const home = await (await app.request('/')).text();
|
const home = await (await app.request('/?view=calendar')).text();
|
||||||
expect(home).not.toContain('pat.switch@example.invalid');
|
expect(home).not.toContain('pat.switch@example.invalid');
|
||||||
expect(home).not.toContain('Pat Cancel');
|
expect(home).toContain('Pat Cancel');
|
||||||
expect(home).toContain('0/2 spots filled');
|
expect(home).toContain('0/2 spots filled');
|
||||||
expect(home).toContain('1/2 spots filled');
|
expect(home).toContain('1/2 spots filled');
|
||||||
|
|
||||||
|
|||||||
+141
-3
@@ -284,6 +284,120 @@ describe('contact pages', () => {
|
|||||||
expect(await hidden.text()).not.toContain('kristi@example.invalid');
|
expect(await hidden.text()).not.toContain('kristi@example.invalid');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('shows current and past shifts on the contact page', async () => {
|
||||||
|
const { app, db } = await buildApp();
|
||||||
|
const cookie = await signIn(app, db);
|
||||||
|
await postFile(
|
||||||
|
app,
|
||||||
|
cookie,
|
||||||
|
[
|
||||||
|
'First Name,Last Name,Email,Phone',
|
||||||
|
'Ada,Example,ada@example.invalid,712-555-0101',
|
||||||
|
'Ada,Other,ada@example.invalid,712-555-0102',
|
||||||
|
'Pat,-,pat@example.invalid,712-555-0103',
|
||||||
|
].join('\n'),
|
||||||
|
);
|
||||||
|
const currentId = insertShift(db, { title: 'Weekly pantry', role: 'Sorting', start: '2026-10-14T16:00:00.000Z', end: '2026-10-14T20:00:00.000Z' });
|
||||||
|
const nextId = insertShift(db, { slug: 'next', title: 'Pantry & <shift>', role: 'Packing' });
|
||||||
|
const quietId = insertShift(db, {
|
||||||
|
slug: 'soup',
|
||||||
|
title: 'Soup kitchen',
|
||||||
|
role: 'Serving',
|
||||||
|
published: 0,
|
||||||
|
start: '2026-10-22T14:00:00.000Z',
|
||||||
|
end: '2026-10-22T17:00:00.000Z',
|
||||||
|
});
|
||||||
|
const greetingId = insertShift(db, {
|
||||||
|
slug: 'door',
|
||||||
|
title: 'Front door',
|
||||||
|
role: 'Greeting',
|
||||||
|
start: '2026-10-23T14:00:00.000Z',
|
||||||
|
end: '2026-10-23T17:00:00.000Z',
|
||||||
|
});
|
||||||
|
const endedId = insertShift(db, {
|
||||||
|
slug: 'finished',
|
||||||
|
title: 'Finished pantry',
|
||||||
|
role: 'Finished',
|
||||||
|
start: '2026-10-14T14:00:00.000Z',
|
||||||
|
end: '2026-10-14T17:00:00.000Z',
|
||||||
|
});
|
||||||
|
const olderId = insertShift(db, {
|
||||||
|
slug: 'older',
|
||||||
|
title: 'Older pantry',
|
||||||
|
role: 'Older',
|
||||||
|
start: '2026-10-07T14:00:00.000Z',
|
||||||
|
end: '2026-10-07T17:00:00.000Z',
|
||||||
|
});
|
||||||
|
const closedId = insertShift(db, { slug: 'closed', title: 'Closed pantry', role: 'Closing', cancelled: 1 });
|
||||||
|
const droppedId = insertShift(db, {
|
||||||
|
slug: 'dropped',
|
||||||
|
title: 'Dropped pantry',
|
||||||
|
role: 'Dropped',
|
||||||
|
start: '2026-10-24T14:00:00.000Z',
|
||||||
|
end: '2026-10-24T17:00:00.000Z',
|
||||||
|
});
|
||||||
|
insertSignup(db, currentId, { name: 'ADA EXAMPLE', email: 'ada@example.invalid' });
|
||||||
|
insertSignup(db, nextId, { name: 'Ada Example', email: 'ada@example.invalid' });
|
||||||
|
insertSignup(db, quietId, { name: 'Ada Example', email: 'ada@example.invalid' });
|
||||||
|
insertSignup(db, greetingId, { name: 'Pat', email: 'pat@example.invalid' });
|
||||||
|
insertSignup(db, endedId, { name: 'Ada Example', email: 'ada@example.invalid' });
|
||||||
|
insertSignup(db, olderId, { name: 'Ada Example', email: 'ada@example.invalid', status: 'cancelled' });
|
||||||
|
insertSignup(db, closedId, { name: 'Ada Example', email: 'ada@example.invalid' });
|
||||||
|
insertSignup(db, droppedId, { name: 'Ada Example', email: 'ada@example.invalid', status: 'cancelled' });
|
||||||
|
insertSignup(db, greetingId, { name: 'Ada Other', email: 'other@example.invalid' });
|
||||||
|
|
||||||
|
const found = await app.request('/admin/contacts?q=ada', { headers: { cookie } });
|
||||||
|
const foundHtml = await found.text();
|
||||||
|
expect(foundHtml).toContain('Ada Example');
|
||||||
|
expect(foundHtml).toContain('Ada Other');
|
||||||
|
expect(foundHtml).not.toContain('Not signed up for a shift.');
|
||||||
|
expect(foundHtml).not.toContain('Pantry & <shift>');
|
||||||
|
expect(foundHtml).not.toContain('/admin/shifts/');
|
||||||
|
|
||||||
|
const adaId = (db.prepare(`SELECT id AS id FROM contacts WHERE last_name = 'Example'`).get() as { id: number }).id;
|
||||||
|
const person = await app.request(`/admin/contacts/${adaId}`, { headers: { cookie } });
|
||||||
|
const personHtml = await person.text();
|
||||||
|
const current = sectionHtml(personHtml, 'Signed up for', 'Past shifts');
|
||||||
|
const past = sectionHtml(personHtml, 'Past shifts', 'Edit contact');
|
||||||
|
expect(current).toContain(`href="/admin/shifts/${currentId}"`);
|
||||||
|
expect(current).toContain('Weekly pantry: Sorting, October 14, 2026, 11:00 AM to 3:00 PM CDT');
|
||||||
|
expect(current).toContain(`href="/admin/shifts/${nextId}"`);
|
||||||
|
expect(current).toContain('Pantry & <shift>: Packing, October 21, 2026, 9:00 AM to 12:00 PM CDT');
|
||||||
|
expect(current).not.toContain('Pantry & <shift>');
|
||||||
|
expect(current).toContain(`href="/admin/shifts/${quietId}"`);
|
||||||
|
expect(current).toContain('Soup kitchen: Serving, October 22, 2026, 9:00 AM to 12:00 PM CDT (not on the public list)');
|
||||||
|
expect(current.indexOf(`href="/admin/shifts/${currentId}"`)).toBeLessThan(current.indexOf(`href="/admin/shifts/${nextId}"`));
|
||||||
|
expect(current.indexOf(`href="/admin/shifts/${nextId}"`)).toBeLessThan(current.indexOf(`href="/admin/shifts/${quietId}"`));
|
||||||
|
expect(current).not.toContain('Finished');
|
||||||
|
expect(current).not.toContain('Closing');
|
||||||
|
expect(current).not.toContain('Dropped');
|
||||||
|
expect(past).toContain(`href="/admin/shifts/${endedId}"`);
|
||||||
|
expect(past).toContain('Finished pantry: Finished, October 14, 2026, 9:00 AM to 12:00 PM CDT');
|
||||||
|
expect(past).toContain(`href="/admin/shifts/${olderId}"`);
|
||||||
|
expect(past).toContain('Older pantry: Older, October 7, 2026, 9:00 AM to 12:00 PM CDT (cancelled)');
|
||||||
|
expect(past.indexOf(`href="/admin/shifts/${endedId}"`)).toBeLessThan(past.indexOf(`href="/admin/shifts/${olderId}"`));
|
||||||
|
expect(past).not.toContain('Weekly pantry');
|
||||||
|
expect(past).not.toContain('Dropped');
|
||||||
|
expect(past).not.toContain('Closing');
|
||||||
|
expect(personHtml).toContain('<summary>Edit contact');
|
||||||
|
expect(personHtml).toContain('<summary>Add to a shift');
|
||||||
|
expect(personHtml.match(/<details class="contact-menu" name="contact-action"/g)).toHaveLength(2);
|
||||||
|
expect(personHtml).not.toContain('<details class="contact-menu" open');
|
||||||
|
|
||||||
|
const otherId = (db.prepare(`SELECT id AS id FROM contacts WHERE last_name = 'Other'`).get() as { id: number }).id;
|
||||||
|
const otherPage = await app.request(`/admin/contacts/${otherId}`, { headers: { cookie } });
|
||||||
|
const otherHtml = await otherPage.text();
|
||||||
|
expect(otherHtml).toContain('Not signed up for a shift.');
|
||||||
|
expect(otherHtml).toContain('No past shifts.');
|
||||||
|
expect(otherHtml).not.toContain('/admin/shifts/');
|
||||||
|
|
||||||
|
const patId = (db.prepare(`SELECT id AS id FROM contacts WHERE last_name = '-'`).get() as { id: number }).id;
|
||||||
|
const patPage = await app.request(`/admin/contacts/${patId}`, { headers: { cookie } });
|
||||||
|
const patHtml = await patPage.text();
|
||||||
|
expect(sectionHtml(patHtml, 'Signed up for', 'Past shifts')).toContain(`href="/admin/shifts/${greetingId}"`);
|
||||||
|
expect(patHtml).toContain('Front door: Greeting, October 23, 2026, 9:00 AM to 12:00 PM CDT');
|
||||||
|
});
|
||||||
|
|
||||||
it('fills a walk-in from a saved contact and can remove the contact afterward', async () => {
|
it('fills a walk-in from a saved contact and can remove the contact afterward', async () => {
|
||||||
const { app, db } = await buildApp();
|
const { app, db } = await buildApp();
|
||||||
const cookie = await signIn(app, db);
|
const cookie = await signIn(app, db);
|
||||||
@@ -475,7 +589,12 @@ describe('contact pages', () => {
|
|||||||
expect(loggedOut.status).toBe(303);
|
expect(loggedOut.status).toBe(303);
|
||||||
const cookie = await signIn(app, db);
|
const cookie = await signIn(app, db);
|
||||||
const page = await app.request('/admin/contacts', { headers: { cookie } });
|
const page = await app.request('/admin/contacts', { headers: { cookie } });
|
||||||
expect(await page.text()).toContain('Save this contact');
|
const pageHtml = await page.text();
|
||||||
|
expect(pageHtml).toContain('Save this contact');
|
||||||
|
expect(pageHtml.indexOf('id="contacts-heading"')).toBeGreaterThan(-1);
|
||||||
|
expect(pageHtml.indexOf('id="contacts-heading"')).toBeLessThan(pageHtml.indexOf('<summary>Add a contact'));
|
||||||
|
expect(pageHtml.match(/<details class="contact-menu" name="contact-tools"/g)).toHaveLength(3);
|
||||||
|
expect(pageHtml).not.toContain('<details class="contact-menu" name="contact-tools" open');
|
||||||
|
|
||||||
const saved = await postManual(app, cookie, { firstName: 'ada', lastName: 'example', email: 'Ada@Example.invalid', phone: '7125550100' });
|
const saved = await postManual(app, cookie, { firstName: 'ada', lastName: 'example', email: 'Ada@Example.invalid', phone: '7125550100' });
|
||||||
expect(saved.status).toBe(303);
|
expect(saved.status).toBe(303);
|
||||||
@@ -521,6 +640,7 @@ describe('contact pages', () => {
|
|||||||
expect(invalidHtml).toContain('Enter a first name.');
|
expect(invalidHtml).toContain('Enter a first name.');
|
||||||
expect(invalidHtml).toContain('Enter an email address.');
|
expect(invalidHtml).toContain('Enter an email address.');
|
||||||
expect(invalidHtml).toContain('Enter a phone number.');
|
expect(invalidHtml).toContain('Enter a phone number.');
|
||||||
|
expect(invalidHtml).toContain('<details class="contact-menu" name="contact-tools" open');
|
||||||
expect(count(db, 'SELECT COUNT(*) AS n FROM contacts')).toBe(2);
|
expect(count(db, 'SELECT COUNT(*) AS n FROM contacts')).toBe(2);
|
||||||
expect(await (await app.request('/')).text()).not.toContain('ada@example.invalid');
|
expect(await (await app.request('/')).text()).not.toContain('ada@example.invalid');
|
||||||
});
|
});
|
||||||
@@ -540,8 +660,9 @@ describe('contact pages', () => {
|
|||||||
const person = await app.request(`/admin/contacts/${contactId}`, { headers: { cookie } });
|
const person = await app.request(`/admin/contacts/${contactId}`, { headers: { cookie } });
|
||||||
const personHtml = await person.text();
|
const personHtml = await person.text();
|
||||||
expect(person.status).toBe(200);
|
expect(person.status).toBe(200);
|
||||||
expect(personHtml).toContain('Correct this contact');
|
expect(personHtml).toContain('Edit contact');
|
||||||
expect(personHtml).toContain('Save this correction');
|
expect(personHtml).toContain('Save contact');
|
||||||
|
expect(personHtml).not.toContain('Correct this contact');
|
||||||
expect(personHtml).toContain('value="Pat"');
|
expect(personHtml).toContain('value="Pat"');
|
||||||
expect(personHtml).toContain('value="-"');
|
expect(personHtml).toContain('value="-"');
|
||||||
expect(personHtml).toContain('value="pat@example.invalid"');
|
expect(personHtml).toContain('value="pat@example.invalid"');
|
||||||
@@ -739,6 +860,23 @@ function rowMarkup(html: string, name: string): string {
|
|||||||
return li < 0 || at < 0 ? '' : html.slice(li, at);
|
return li < 0 || at < 0 ? '' : html.slice(li, at);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sectionHtml(html: string, start: string, end: string): string {
|
||||||
|
const at = html.indexOf(start);
|
||||||
|
const stop = html.indexOf(end, at + start.length);
|
||||||
|
return at < 0 || stop < 0 ? '' : html.slice(at, stop);
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertSignup(
|
||||||
|
db: Awaited<ReturnType<typeof openDb>>,
|
||||||
|
shiftId: number,
|
||||||
|
person: { name: string; email: string; status?: string },
|
||||||
|
) {
|
||||||
|
db.prepare(
|
||||||
|
`INSERT INTO signups (shift_id, name, email, email_norm, group_size, status, created_at, updated_at)
|
||||||
|
VALUES (?, ?, ?, ?, 1, ?, ?, ?)`,
|
||||||
|
).run(shiftId, person.name, person.email, person.email, person.status ?? 'confirmed', NOW, NOW);
|
||||||
|
}
|
||||||
|
|
||||||
function count(db: Awaited<ReturnType<typeof openDb>>, sql: string): number {
|
function count(db: Awaited<ReturnType<typeof openDb>>, sql: string): number {
|
||||||
return (db.prepare(sql).get() as { n: number }).n;
|
return (db.prepare(sql).get() as { n: number }).n;
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-10
@@ -32,15 +32,15 @@ describe('daily weekly refill', () => {
|
|||||||
const ended = insertEvent(db, 'ended', CHICAGO);
|
const ended = insertEvent(db, 'ended', CHICAGO);
|
||||||
insertTemplate(db, ended, 4, '2026-01-15', 0);
|
insertTemplate(db, ended, 4, '2026-01-15', 0);
|
||||||
|
|
||||||
expect(runDueTemplateExpansion(db, BEFORE)).toEqual({ zones: [HONOLULU], created: 9, skipped: [] });
|
expect(runDueTemplateExpansion(db, BEFORE)).toEqual({ zones: [HONOLULU], created: 13, skipped: [] });
|
||||||
expect(shiftCount(db, chicago)).toBe(0);
|
expect(shiftCount(db, chicago)).toBe(0);
|
||||||
expect(shiftCount(db, honolulu)).toBe(9);
|
expect(shiftCount(db, honolulu)).toBe(13);
|
||||||
expect(shiftCount(db, ended)).toBe(0);
|
expect(shiftCount(db, ended)).toBe(0);
|
||||||
expect(marks(db)).toEqual([{ scope: HONOLULU, local_date: '2026-01-14' }]);
|
expect(marks(db)).toEqual([{ scope: HONOLULU, local_date: '2026-01-14' }]);
|
||||||
|
|
||||||
expect(runDueTemplateExpansion(db, AT_ONE).zones).toEqual([CHICAGO]);
|
expect(runDueTemplateExpansion(db, AT_ONE).zones).toEqual([CHICAGO]);
|
||||||
expect(shiftCount(db, chicago)).toBe(9);
|
expect(shiftCount(db, chicago)).toBe(13);
|
||||||
expect(shiftCount(db, honolulu)).toBe(9);
|
expect(shiftCount(db, honolulu)).toBe(13);
|
||||||
expect(shiftCount(db, ended)).toBe(0);
|
expect(shiftCount(db, ended)).toBe(0);
|
||||||
expect(runDueTemplateExpansion(db, AT_ONE)).toEqual({ zones: [], created: 0, skipped: [] });
|
expect(runDueTemplateExpansion(db, AT_ONE)).toEqual({ zones: [], created: 0, skipped: [] });
|
||||||
expect(marks(db)).toEqual([
|
expect(marks(db)).toEqual([
|
||||||
@@ -63,11 +63,11 @@ describe('daily weekly refill', () => {
|
|||||||
runDueTemplateExpansion(db, AT_ONE);
|
runDueTemplateExpansion(db, AT_ONE);
|
||||||
const kept = db.prepare(`SELECT role AS role, cancelled AS cancelled FROM shifts WHERE occurrence_date = '2026-01-15'`).get();
|
const kept = db.prepare(`SELECT role AS role, cancelled AS cancelled FROM shifts WHERE occurrence_date = '2026-01-15'`).get();
|
||||||
expect(kept).toEqual({ role: 'Kept', cancelled: 1 });
|
expect(kept).toEqual({ role: 'Kept', cancelled: 1 });
|
||||||
expect(lastDate(db, eventId)).toBe('2026-03-12');
|
expect(lastDate(db, eventId)).toBe('2026-04-09');
|
||||||
|
|
||||||
runDueTemplateExpansion(db, NEXT_WEEK);
|
runDueTemplateExpansion(db, NEXT_WEEK);
|
||||||
expect(lastDate(db, eventId)).toBe('2026-03-19');
|
expect(lastDate(db, eventId)).toBe('2026-04-16');
|
||||||
expect(shiftCount(db, eventId)).toBe(10);
|
expect(shiftCount(db, eventId)).toBe(14);
|
||||||
expect(db.prepare(`SELECT detail_json AS detail_json FROM audit`).all().map((row) => (row as { detail_json: string }).detail_json).join(' ')).not.toContain('@');
|
expect(db.prepare(`SELECT detail_json AS detail_json FROM audit`).all().map((row) => (row as { detail_json: string }).detail_json).join(' ')).not.toContain('@');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ describe('daily weekly refill', () => {
|
|||||||
} finally {
|
} finally {
|
||||||
console.error = write;
|
console.error = write;
|
||||||
}
|
}
|
||||||
expect(shiftCount(db, chicago)).toBe(9);
|
expect(shiftCount(db, chicago)).toBe(13);
|
||||||
expect(shiftCount(db, broken)).toBe(0);
|
expect(shiftCount(db, broken)).toBe(0);
|
||||||
expect(marks(db).map((row) => row.scope)).toEqual([CHICAGO]);
|
expect(marks(db).map((row) => row.scope)).toEqual([CHICAGO]);
|
||||||
expect(errors.join(' ')).toContain('Not/AZone');
|
expect(errors.join(' ')).toContain('Not/AZone');
|
||||||
@@ -121,9 +121,9 @@ describe('daily weekly refill', () => {
|
|||||||
const eventId = insertEvent(db, 'chicago', CHICAGO);
|
const eventId = insertEvent(db, 'chicago', CHICAGO);
|
||||||
insertTemplate(db, eventId, 4, '2026-01-15');
|
insertTemplate(db, eventId, 4, '2026-01-15');
|
||||||
const runner = startDailyExpansionRunner(db, () => AT_ONE);
|
const runner = startDailyExpansionRunner(db, () => AT_ONE);
|
||||||
expect(shiftCount(db, eventId)).toBe(9);
|
expect(shiftCount(db, eventId)).toBe(13);
|
||||||
runner.stop();
|
runner.stop();
|
||||||
expect(shiftCount(db, eventId)).toBe(9);
|
expect(shiftCount(db, eventId)).toBe(13);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -190,9 +190,9 @@ describe('transactional mail', () => {
|
|||||||
body,
|
body,
|
||||||
});
|
});
|
||||||
expect(saved.status).toBe(303);
|
expect(saved.status).toBe(303);
|
||||||
const home = await (await app.request('/')).text();
|
const home = await (await app.request('/?view=calendar')).text();
|
||||||
expect(home).not.toContain('listed@example.invalid');
|
expect(home).not.toContain('listed@example.invalid');
|
||||||
expect(home).not.toContain('Listed Person');
|
expect(home).toContain('Listed Person');
|
||||||
expect(db.prepare("SELECT status FROM outbox").get()).toEqual({ status: 'pending' });
|
expect(db.prepare("SELECT status FROM outbox").get()).toEqual({ status: 'pending' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+203
-35
@@ -2,11 +2,13 @@ import { mkdtempSync, rmSync } from 'node:fs';
|
|||||||
import { tmpdir } from 'node:os';
|
import { tmpdir } from 'node:os';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { afterEach, describe, expect, it } from 'vitest';
|
import { afterEach, describe, expect, it } from 'vitest';
|
||||||
|
import { listMoveTargets, switchSignup } from '../src/admin/store.js';
|
||||||
import { createApp, publicDirectory } from '../src/app.js';
|
import { createApp, publicDirectory } from '../src/app.js';
|
||||||
import { loadConfig } from '../src/config.js';
|
import { loadConfig } from '../src/config.js';
|
||||||
import { openAppDatabase } from '../src/db.js';
|
import { openAppDatabase } from '../src/db.js';
|
||||||
import { Hono } from 'hono';
|
import { Hono } from 'hono';
|
||||||
import { CONTENT_SECURITY_POLICY, PERMISSIONS_POLICY, securityHeaders, STRICT_TRANSPORT_SECURITY } from '../src/security.js';
|
import { CONTENT_SECURITY_POLICY, PERMISSIONS_POLICY, securityHeaders, STRICT_TRANSPORT_SECURITY } from '../src/security.js';
|
||||||
|
import { reserveSignup } from '../src/signup.js';
|
||||||
import { localShiftToUtc } from '../src/time.js';
|
import { localShiftToUtc } from '../src/time.js';
|
||||||
import { devEnv } from './env.js';
|
import { devEnv } from './env.js';
|
||||||
|
|
||||||
@@ -27,20 +29,28 @@ describe('public pages', () => {
|
|||||||
const html = await home.text();
|
const html = await home.text();
|
||||||
expect(html).toContain('Weekly pantry');
|
expect(html).toContain('Weekly pantry');
|
||||||
expect(html).not.toContain('Upcoming shifts');
|
expect(html).not.toContain('Upcoming shifts');
|
||||||
expect(html).toContain('Open Sorting');
|
expect(html).toContain('>Sign Up</a>');
|
||||||
expect(html).toContain('Full Intake');
|
expect(html).toContain('>List</a>');
|
||||||
|
expect(html).toContain('href="/?view=calendar">Calendar</a>');
|
||||||
|
expect(html).toContain('Sign-up is open through January 14, 2027.');
|
||||||
|
expect(html).toContain('Wednesday Sorting');
|
||||||
|
expect(html).toContain('Wednesday Greeting');
|
||||||
|
expect(html).toContain('Lane Wednesday');
|
||||||
expect(html).toContain('Live Greeting');
|
expect(html).toContain('Live Greeting');
|
||||||
expect(html).toContain('1/3 spots filled');
|
expect(html).toContain('0/2 spots filled');
|
||||||
expect(html).toContain('1/1 spots filled');
|
expect(html).toContain('1/4 spots filled');
|
||||||
expect(html).toContain('9:00 AM');
|
expect(html).toContain('9:00 AM');
|
||||||
expect(html).toContain('CDT');
|
expect(html).toContain('CDT');
|
||||||
expect(html).toContain('October 15');
|
expect(html).toContain('October 14');
|
||||||
expect(html).toContain('October 2026');
|
expect(html).toContain('October 21');
|
||||||
expect(html).toContain('shift-calendar');
|
expect(html).toContain('No one signed up yet.');
|
||||||
expect(html).toContain('class="cal-line"');
|
expect(html).toContain('class="day-card"');
|
||||||
expect(html).toContain('class="cal-hold"');
|
expect(html).toContain('class="shift-pane"');
|
||||||
expect(html).toContain('class="cal-detail"');
|
expect(html.match(/class="day-card"/g)).toHaveLength(2);
|
||||||
expect(html).toContain('>Sun</span>');
|
expect(html.match(/class="shift-pane"/g)).toHaveLength(3);
|
||||||
|
expect(html).not.toContain('shift-calendar');
|
||||||
|
expect(html).not.toContain('Open Sorting');
|
||||||
|
expect(html).not.toContain('Full Intake');
|
||||||
expect(html).toContain('Today');
|
expect(html).toContain('Today');
|
||||||
expect(html).toContain('aria-current="date"');
|
expect(html).toContain('aria-current="date"');
|
||||||
expect(html).toContain('In progress');
|
expect(html).toContain('In progress');
|
||||||
@@ -73,6 +83,7 @@ describe('public pages', () => {
|
|||||||
expect(html).not.toContain('Hidden draft');
|
expect(html).not.toContain('Hidden draft');
|
||||||
expect(html).not.toContain('Secret Person');
|
expect(html).not.toContain('Secret Person');
|
||||||
expect(html).not.toContain('secret.person@example.invalid');
|
expect(html).not.toContain('secret.person@example.invalid');
|
||||||
|
expect(html).not.toContain('lane.wednesday@example.invalid');
|
||||||
expect(html).not.toContain('SECRET-PERSON-NOTE');
|
expect(html).not.toContain('SECRET-PERSON-NOTE');
|
||||||
expect(html).not.toContain('SECRET-SHIFT-NOTE');
|
expect(html).not.toContain('SECRET-SHIFT-NOTE');
|
||||||
expect(html).not.toContain('<form');
|
expect(html).not.toContain('<form');
|
||||||
@@ -81,7 +92,7 @@ describe('public pages', () => {
|
|||||||
expect(html).not.toContain('<script>alert(1)</script>');
|
expect(html).not.toContain('<script>alert(1)</script>');
|
||||||
expect(html).toContain('href="/css/app.css?v=');
|
expect(html).toContain('href="/css/app.css?v=');
|
||||||
expect(html).toContain('href="/brand/tokens.css?v=');
|
expect(html).toContain('href="/brand/tokens.css?v=');
|
||||||
expect(html).toContain(`href="/s/${ids.open}"`);
|
expect(html).toMatch(/href="\/s\/\d+"/);
|
||||||
expect(home.headers.get('content-security-policy')).toBe(CONTENT_SECURITY_POLICY);
|
expect(home.headers.get('content-security-policy')).toBe(CONTENT_SECURITY_POLICY);
|
||||||
expect(home.headers.get('referrer-policy')).toBe('no-referrer');
|
expect(home.headers.get('referrer-policy')).toBe('no-referrer');
|
||||||
expect(home.headers.get('x-content-type-options')).toBe('nosniff');
|
expect(home.headers.get('x-content-type-options')).toBe('nosniff');
|
||||||
@@ -95,12 +106,32 @@ describe('public pages', () => {
|
|||||||
expect(eventHtml).toContain('<script>alert(1)</script>');
|
expect(eventHtml).toContain('<script>alert(1)</script>');
|
||||||
expect(eventHtml).not.toContain('<script>alert(1)</script>');
|
expect(eventHtml).not.toContain('<script>alert(1)</script>');
|
||||||
expect(eventHtml).toContain('Sioux Center, Iowa');
|
expect(eventHtml).toContain('Sioux Center, Iowa');
|
||||||
expect(eventHtml).toContain('October 2026');
|
expect(eventHtml).toContain('Wednesday Sorting');
|
||||||
expect(eventHtml).toContain('shift-calendar');
|
expect(eventHtml).toContain('Lane Wednesday');
|
||||||
expect(eventHtml).toContain('Sign up');
|
expect(eventHtml).toContain('Sign up');
|
||||||
expect(eventHtml).toContain('View shift');
|
expect(eventHtml).not.toContain('shift-calendar');
|
||||||
expect(eventHtml).not.toContain('November 2026');
|
expect(eventHtml).not.toContain('November 2026');
|
||||||
expect(eventHtml).not.toContain('SECRET-PERSON-NOTE');
|
expect(eventHtml).not.toContain('SECRET-PERSON-NOTE');
|
||||||
|
expect(eventHtml).not.toContain('lane.wednesday@example.invalid');
|
||||||
|
|
||||||
|
const calendar = await (await app.request('/?view=calendar')).text();
|
||||||
|
expect(calendar).toContain('shift-calendar');
|
||||||
|
expect(calendar).toContain('October 2026');
|
||||||
|
expect(calendar).toContain('Open Sorting');
|
||||||
|
expect(calendar).toContain('Full Intake');
|
||||||
|
expect(calendar).toContain('1/3 spots filled');
|
||||||
|
expect(calendar).toContain('1/1 spots filled');
|
||||||
|
expect(calendar).toContain('class="cal-line"');
|
||||||
|
expect(calendar).toContain('class="cal-hold"');
|
||||||
|
expect(calendar).toContain('class="cal-detail"');
|
||||||
|
expect(calendar).toContain('>Sun</span>');
|
||||||
|
expect(calendar).toContain('Secret Person');
|
||||||
|
expect(calendar).toContain('Lane Wednesday');
|
||||||
|
expect(calendar).toContain('View shift');
|
||||||
|
expect(calendar).toContain(`href="/s/${ids.open}"`);
|
||||||
|
expect(calendar).not.toContain('secret.person@example.invalid');
|
||||||
|
expect(calendar).not.toContain('SECRET-PERSON-NOTE');
|
||||||
|
expect(calendar).not.toContain('November 2026');
|
||||||
|
|
||||||
const shift = await app.request(`/s/${ids.open}`);
|
const shift = await app.request(`/s/${ids.open}`);
|
||||||
const shiftHtml = await shift.text();
|
const shiftHtml = await shift.text();
|
||||||
@@ -122,6 +153,9 @@ describe('public pages', () => {
|
|||||||
expect(shiftHtml).not.toContain('data-guardian');
|
expect(shiftHtml).not.toContain('data-guardian');
|
||||||
expect(shiftHtml).not.toContain('I am under 18');
|
expect(shiftHtml).not.toContain('I am under 18');
|
||||||
const css = await (await app.request('/css/app.css')).text();
|
const css = await (await app.request('/css/app.css')).text();
|
||||||
|
expect(css).toContain('grid-template-columns: repeat(4, minmax(0, 1fr))');
|
||||||
|
expect(css).toContain('grid-template-columns: repeat(2, minmax(0, 1fr))');
|
||||||
|
expect(css).not.toContain('minmax(16rem, 1fr)');
|
||||||
expect(css).not.toContain('data-under-18');
|
expect(css).not.toContain('data-under-18');
|
||||||
expect(css).not.toContain('data-guardian');
|
expect(css).not.toContain('data-guardian');
|
||||||
expect(shiftHtml).not.toContain('SECRET-SHIFT-NOTE');
|
expect(shiftHtml).not.toContain('SECRET-SHIFT-NOTE');
|
||||||
@@ -253,7 +287,7 @@ describe('public pages', () => {
|
|||||||
expect(await health.json()).toEqual({ ok: true, database: 'ok' });
|
expect(await health.json()).toEqual({ ok: true, database: 'ok' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows one month at a time and cycles between months that have shifts', async () => {
|
it('shows Wednesday cards by default and one calendar month at a time', async () => {
|
||||||
const { app, db } = await buildApp();
|
const { app, db } = await buildApp();
|
||||||
const event = db.prepare(`SELECT id AS id FROM events WHERE slug = 'weekly-pantry'`).get() as { id: number };
|
const event = db.prepare(`SELECT id AS id FROM events WHERE slug = 'weekly-pantry'`).get() as { id: number };
|
||||||
insertShift(db, event.id, 'November Sorting', '2026-11-04', '09:00', '12:00', 4, 0);
|
insertShift(db, event.id, 'November Sorting', '2026-11-04', '09:00', '12:00', 4, 0);
|
||||||
@@ -261,37 +295,162 @@ describe('public pages', () => {
|
|||||||
insertShift(db, event.id, 'December Sorting', '2026-12-02', '09:00', '12:00', 4, 0);
|
insertShift(db, event.id, 'December Sorting', '2026-12-02', '09:00', '12:00', 4, 0);
|
||||||
const html = await (await app.request('/e/weekly-pantry')).text();
|
const html = await (await app.request('/e/weekly-pantry')).text();
|
||||||
const home = await (await app.request('/')).text();
|
const home = await (await app.request('/')).text();
|
||||||
expect(html).toContain('October 2026');
|
expect(html).toContain('Wednesday Sorting');
|
||||||
expect(html).toContain('Next month');
|
expect(html).toContain('November Sorting');
|
||||||
expect(html).not.toContain('Previous month');
|
expect(html).toContain('December Sorting');
|
||||||
expect(html).not.toContain('November 2026');
|
expect(html).not.toContain('Edge Sorting');
|
||||||
expect(html).not.toContain('September');
|
expect(html).not.toContain('Open Sorting');
|
||||||
expect(home).toContain('href="/?month=2026-11"');
|
expect(html).not.toContain('shift-calendar');
|
||||||
expect(home).toContain('Next month');
|
expect(html).not.toContain('Next month');
|
||||||
expect(html).toContain('Open Sorting');
|
expect(home).toContain('href="/?view=calendar"');
|
||||||
expect(html).not.toContain('November Sorting');
|
expect(home).not.toContain('month=2026-11');
|
||||||
expect(html).toContain('href="/e/weekly-pantry?month=2026-11"');
|
|
||||||
expect(html.match(/class="cal-title"/g)).toHaveLength(1);
|
|
||||||
|
|
||||||
const november = await (await app.request('/e/weekly-pantry?month=2026-11')).text();
|
const october = await (await app.request('/e/weekly-pantry?view=calendar')).text();
|
||||||
|
expect(october).toContain('October 2026');
|
||||||
|
expect(october).toContain('Next month');
|
||||||
|
expect(october).not.toContain('Previous month');
|
||||||
|
expect(october).not.toContain('November 2026');
|
||||||
|
expect(october).not.toContain('September');
|
||||||
|
expect(october).toContain('Open Sorting');
|
||||||
|
expect(october).not.toContain('November Sorting');
|
||||||
|
expect(october).toContain('href="/e/weekly-pantry?view=calendar&month=2026-11"');
|
||||||
|
expect(october.match(/class="cal-title"/g)).toHaveLength(1);
|
||||||
|
expect(home).not.toContain('href="/?month=2026-11"');
|
||||||
|
|
||||||
|
const november = await (await app.request('/e/weekly-pantry?view=calendar&month=2026-11')).text();
|
||||||
expect(november).toContain('November 2026');
|
expect(november).toContain('November 2026');
|
||||||
expect(november).toContain('November Sorting');
|
expect(november).toContain('November Sorting');
|
||||||
|
expect(november).toContain('Edge Sorting');
|
||||||
expect(november).not.toContain('Open Sorting');
|
expect(november).not.toContain('Open Sorting');
|
||||||
expect(november).toContain('Previous month');
|
expect(november).toContain('Previous month');
|
||||||
expect(november).toContain('Next month');
|
expect(november).toContain('Next month');
|
||||||
expect(november).toContain('href="/e/weekly-pantry?month=2026-10"');
|
expect(november).toContain('href="/e/weekly-pantry?view=calendar&month=2026-10"');
|
||||||
expect(november).toContain('href="/e/weekly-pantry?month=2026-12"');
|
expect(november).toContain('href="/e/weekly-pantry?view=calendar&month=2026-12"');
|
||||||
expect(november.match(/class="role">Edge Sorting/g)).toHaveLength(1);
|
expect(november.match(/class="role">Edge Sorting/g)).toHaveLength(1);
|
||||||
|
|
||||||
const december = await (await app.request('/e/weekly-pantry?month=2026-12')).text();
|
const december = await (await app.request('/e/weekly-pantry?view=calendar&month=2026-12')).text();
|
||||||
expect(december).toContain('December Sorting');
|
expect(december).toContain('December Sorting');
|
||||||
expect(december).toContain('Previous month');
|
expect(december).toContain('Previous month');
|
||||||
expect(december).not.toContain('Next month');
|
expect(december).not.toContain('Next month');
|
||||||
expect(december).not.toContain('November Sorting');
|
expect(december).not.toContain('November Sorting');
|
||||||
|
|
||||||
const invalid = await (await app.request('/e/weekly-pantry?month=nope')).text();
|
const invalid = await (await app.request('/e/weekly-pantry?view=calendar&month=nope')).text();
|
||||||
expect(invalid).toContain('October 2026');
|
expect(invalid).toContain('October 2026');
|
||||||
expect(invalid).toContain('Open Sorting');
|
expect(invalid).toContain('Open Sorting');
|
||||||
|
|
||||||
|
const cardsDespiteMonth = await (await app.request('/e/weekly-pantry?month=2026-11')).text();
|
||||||
|
expect(cardsDespiteMonth).toContain('Wednesday Sorting');
|
||||||
|
expect(cardsDespiteMonth).not.toContain('shift-calendar');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('lists only the next three months and refuses signup after that', async () => {
|
||||||
|
const { app, db, ids } = await buildApp();
|
||||||
|
const event = db.prepare(`SELECT id AS id FROM events WHERE slug = 'weekly-pantry'`).get() as { id: number };
|
||||||
|
const windowId = insertShift(db, event.id, 'Window Sorting', '2027-01-13', '09:00', '12:00', 3, 0);
|
||||||
|
const deadlineId = insertShift(db, event.id, 'Deadline Sorting', '2027-01-14', '09:00', '12:00', 3, 0);
|
||||||
|
const laterId = insertShift(db, event.id, 'Later Sorting', '2027-01-20', '09:00', '12:00', 3, 0);
|
||||||
|
insertShift(db, event.id, 'Spring Sorting', '2027-04-07', '09:00', '12:00', 3, 0);
|
||||||
|
const mail = {
|
||||||
|
baseUrl: 'http://127.0.0.1:3000',
|
||||||
|
basePath: '',
|
||||||
|
from: 'Hope Food Pantry <volunteer@example.invalid>',
|
||||||
|
replyTo: 'volunteer@example.invalid',
|
||||||
|
};
|
||||||
|
const windowSignup = reserveSignup(db, {
|
||||||
|
shiftId: windowId,
|
||||||
|
name: 'Window Person',
|
||||||
|
email: 'window.person@example.invalid',
|
||||||
|
phone: '712-555-0108',
|
||||||
|
notes: 'WINDOW-NOTE',
|
||||||
|
operationId: 'window-operation',
|
||||||
|
now: NOW,
|
||||||
|
mail,
|
||||||
|
});
|
||||||
|
expect(windowSignup.ok).toBe(true);
|
||||||
|
|
||||||
|
const cards = await (await app.request('/')).text();
|
||||||
|
expect(cards).toContain('Window Sorting');
|
||||||
|
expect(cards).toContain('Window Person');
|
||||||
|
expect(cards).not.toContain('window.person@example.invalid');
|
||||||
|
expect(cards).not.toContain('WINDOW-NOTE');
|
||||||
|
expect(cards).not.toContain('Deadline Sorting');
|
||||||
|
expect(cards).not.toContain('Later Sorting');
|
||||||
|
expect(cards).not.toContain('Spring Sorting');
|
||||||
|
expect(cards).toContain('Sign-up is open through January 14, 2027.');
|
||||||
|
|
||||||
|
const january = await (await app.request('/?view=calendar&month=2027-01')).text();
|
||||||
|
expect(january).toContain('January 2027');
|
||||||
|
expect(january).toContain('Window Sorting');
|
||||||
|
expect(january).toContain('Window Person');
|
||||||
|
expect(january).toContain('Deadline Sorting');
|
||||||
|
expect(january).not.toContain('Later Sorting');
|
||||||
|
expect(january).not.toContain('Spring Sorting');
|
||||||
|
expect(january).not.toContain('Next month');
|
||||||
|
|
||||||
|
const spring = await (await app.request('/?view=calendar&month=2027-04')).text();
|
||||||
|
expect(spring).toContain('October 2026');
|
||||||
|
expect(spring).not.toContain('Spring Sorting');
|
||||||
|
|
||||||
|
const laterPage = await app.request(`/s/${laterId}`);
|
||||||
|
const laterHtml = await laterPage.text();
|
||||||
|
expect(laterPage.status).toBe(200);
|
||||||
|
expect(laterHtml).toContain('Sign-up opens three months before this shift.');
|
||||||
|
expect(laterHtml).not.toContain('<form');
|
||||||
|
const deadlinePage = await (await app.request(`/s/${deadlineId}`)).text();
|
||||||
|
expect(deadlinePage).toContain('<form');
|
||||||
|
expect(deadlinePage).not.toContain('Sign-up opens three months before this shift.');
|
||||||
|
|
||||||
|
const early = reserveSignup(db, {
|
||||||
|
shiftId: laterId,
|
||||||
|
name: 'Later Person',
|
||||||
|
email: 'later.person@example.invalid',
|
||||||
|
phone: '712-555-0109',
|
||||||
|
notes: null,
|
||||||
|
operationId: 'later-operation',
|
||||||
|
now: NOW,
|
||||||
|
mail,
|
||||||
|
});
|
||||||
|
expect(early).toEqual({ ok: false, reason: 'early' });
|
||||||
|
expect(db.prepare("SELECT COUNT(*) AS n FROM signups WHERE email_norm = 'later.person@example.invalid'").get()).toEqual({ n: 0 });
|
||||||
|
|
||||||
|
const targets = listMoveTargets(db, event.id, ids.open, NOW, { publishedOnly: true, signupWindow: true });
|
||||||
|
expect(targets.map((target) => target.id)).not.toContain(laterId);
|
||||||
|
expect(targets.map((target) => target.id)).toContain(deadlineId);
|
||||||
|
const coordinatorTargets = listMoveTargets(db, event.id, ids.open, NOW);
|
||||||
|
expect(coordinatorTargets.map((target) => target.id)).toContain(laterId);
|
||||||
|
|
||||||
|
if (!windowSignup.ok) throw new Error('Window signup was not saved.');
|
||||||
|
const switched = switchSignup(db, windowSignup.signupId, laterId, 'switch-later', NOW, mail);
|
||||||
|
expect(switched.ok).toBe(false);
|
||||||
|
if (!switched.ok) expect(switched.error).toContain('three months');
|
||||||
|
expect(db.prepare('SELECT shift_id AS shift_id, status AS status FROM signups WHERE id = ?').get(windowSignup.signupId)).toEqual({
|
||||||
|
shift_id: windowId,
|
||||||
|
status: 'confirmed',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('leaves a full shift on the list without a link', async () => {
|
||||||
|
const { app, db } = await buildApp();
|
||||||
|
const event = db.prepare(`SELECT id AS id FROM events WHERE slug = 'weekly-pantry'`).get() as { id: number };
|
||||||
|
const full = insertShift(db, event.id, 'Full Wednesday', '2026-10-28', '09:00', '12:00', 1, 0);
|
||||||
|
insertSignup(db, full, { name: 'Full Person', email: 'full.person@example.invalid' });
|
||||||
|
const html = await (await app.request('/')).text();
|
||||||
|
const start = html.indexOf('Full Wednesday');
|
||||||
|
const pane = html.slice(html.lastIndexOf('<section class="shift-pane"', start), html.indexOf('</section>', start));
|
||||||
|
expect(pane).toContain('1/1 spots filled');
|
||||||
|
expect(pane).toContain('class="btn-card is-static"');
|
||||||
|
expect(pane).toContain('>Full</span>');
|
||||||
|
expect(pane).toContain('Not accepting more signups');
|
||||||
|
expect(pane).not.toContain('View shift');
|
||||||
|
expect(pane).not.toContain('href=');
|
||||||
|
expect(pane).not.toContain('right-arrow');
|
||||||
|
expect(html).not.toContain(`href="/s/${full}"`);
|
||||||
|
const calendar = await (await app.request('/?view=calendar&month=2026-10')).text();
|
||||||
|
expect(calendar).toContain(`href="/s/${full}"`);
|
||||||
|
const openStart = html.indexOf('Wednesday Sorting');
|
||||||
|
const openPane = html.slice(html.lastIndexOf('<section class="shift-pane"', openStart), html.indexOf('</section>', openStart));
|
||||||
|
expect(openPane).toContain('>Sign up');
|
||||||
|
expect(openPane).toContain('href="/s/');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows an empty list when nothing is upcoming', async () => {
|
it('shows an empty list when nothing is upcoming', async () => {
|
||||||
@@ -336,6 +495,9 @@ function seedCatalog(db: import('better-sqlite3').Database) {
|
|||||||
});
|
});
|
||||||
const open = insertShift(db, event, 'Open Sorting', '2026-10-15', '09:00', '12:00', 3, 0);
|
const open = insertShift(db, event, 'Open Sorting', '2026-10-15', '09:00', '12:00', 3, 0);
|
||||||
insertSignup(db, open);
|
insertSignup(db, open);
|
||||||
|
const wednesday = insertShift(db, event, 'Wednesday Sorting', '2026-10-21', '09:00', '12:00', 4, 0);
|
||||||
|
insertSignup(db, wednesday, { name: 'Lane Wednesday', email: 'lane.wednesday@example.invalid' });
|
||||||
|
insertShift(db, event, 'Wednesday Greeting', '2026-10-21', '12:00', '15:00', 2, 0);
|
||||||
const full = insertShift(db, event, 'Full Intake', '2026-10-16', '09:00', '12:00', 1, 0);
|
const full = insertShift(db, event, 'Full Intake', '2026-10-16', '09:00', '12:00', 1, 0);
|
||||||
insertSignup(db, full);
|
insertSignup(db, full);
|
||||||
const cancelled = insertShift(db, event, 'Cancelled Distribution', '2026-10-17', '09:00', '12:00', 4, 1);
|
const cancelled = insertShift(db, event, 'Cancelled Distribution', '2026-10-17', '09:00', '12:00', 4, 1);
|
||||||
@@ -386,12 +548,18 @@ function versionedAsset(html: string, file: string): string {
|
|||||||
return `${file}?v=${match[1]}`;
|
return `${file}?v=${match[1]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertSignup(db: import('better-sqlite3').Database, shiftId: number): void {
|
function insertSignup(
|
||||||
|
db: import('better-sqlite3').Database,
|
||||||
|
shiftId: number,
|
||||||
|
person?: { name: string; email: string },
|
||||||
|
): void {
|
||||||
|
const name = person?.name ?? 'Secret Person';
|
||||||
|
const email = person?.email ?? 'secret.person@example.invalid';
|
||||||
db.prepare(
|
db.prepare(
|
||||||
`INSERT INTO signups (
|
`INSERT INTO signups (
|
||||||
shift_id, name, email, email_norm, is_minor, group_size, notes, status, reminders_off, created_at, updated_at
|
shift_id, name, email, email_norm, is_minor, group_size, notes, status, reminders_off, created_at, updated_at
|
||||||
) VALUES (?, 'Secret Person', 'secret.person@example.invalid', 'secret.person@example.invalid', 0, 1, 'SECRET-PERSON-NOTE', 'confirmed', 0, '2026-10-01T15:00:00.000Z', '2026-10-01T15:00:00.000Z')`,
|
) VALUES (?, ?, ?, ?, 0, 1, 'SECRET-PERSON-NOTE', 'confirmed', 0, '2026-10-01T15:00:00.000Z', '2026-10-01T15:00:00.000Z')`,
|
||||||
).run(shiftId);
|
).run(shiftId, name, email, email);
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('security headers', () => {
|
describe('security headers', () => {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ afterEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('weekly template expansion', () => {
|
describe('weekly template expansion', () => {
|
||||||
it('adds the next eight weeks and leaves an existing occurrence alone', async () => {
|
it('adds the next three months and leaves an existing occurrence alone', async () => {
|
||||||
const db = await openDb();
|
const db = await openDb();
|
||||||
const eventId = insertEvent(db, 'weekly', ZONE);
|
const eventId = insertEvent(db, 'weekly', ZONE);
|
||||||
const templateId = insertTemplate(db, eventId, { weekday: 3, startsOn: '2026-10-14' });
|
const templateId = insertTemplate(db, eventId, { weekday: 3, startsOn: '2026-10-14' });
|
||||||
@@ -40,7 +40,7 @@ describe('weekly template expansion', () => {
|
|||||||
).run(eventId);
|
).run(eventId);
|
||||||
|
|
||||||
const first = expandTemplates(db, NOW);
|
const first = expandTemplates(db, NOW);
|
||||||
expect(first).toEqual({ created: 8, templates: 1, skipped: [] });
|
expect(first).toEqual({ created: 13, templates: 1, skipped: [] });
|
||||||
const dates = db
|
const dates = db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT occurrence_date AS occurrence_date, role AS role, capacity AS capacity, cancelled AS cancelled, template_revision AS template_revision
|
`SELECT occurrence_date AS occurrence_date, role AS role, capacity AS capacity, cancelled AS cancelled, template_revision AS template_revision
|
||||||
@@ -57,6 +57,11 @@ describe('weekly template expansion', () => {
|
|||||||
'2026-11-25',
|
'2026-11-25',
|
||||||
'2026-12-02',
|
'2026-12-02',
|
||||||
'2026-12-09',
|
'2026-12-09',
|
||||||
|
'2026-12-16',
|
||||||
|
'2026-12-23',
|
||||||
|
'2026-12-30',
|
||||||
|
'2027-01-06',
|
||||||
|
'2027-01-13',
|
||||||
]);
|
]);
|
||||||
expect(dates[0]).toMatchObject({ role: 'Kept', capacity: 2, cancelled: 1, template_revision: 1 });
|
expect(dates[0]).toMatchObject({ role: 'Kept', capacity: 2, cancelled: 1, template_revision: 1 });
|
||||||
expect(dates.slice(1).every((row) => row.role === 'Sorting' && row.capacity === 6 && row.cancelled === 0)).toBe(true);
|
expect(dates.slice(1).every((row) => row.role === 'Sorting' && row.capacity === 6 && row.cancelled === 0)).toBe(true);
|
||||||
@@ -71,7 +76,7 @@ describe('weekly template expansion', () => {
|
|||||||
};
|
};
|
||||||
expect(audit.coordinator_id).toBeNull();
|
expect(audit.coordinator_id).toBeNull();
|
||||||
expect(audit.detail_json).not.toContain('@');
|
expect(audit.detail_json).not.toContain('@');
|
||||||
expect(JSON.parse(audit.detail_json)).toEqual({ templateId, created: 8 });
|
expect(JSON.parse(audit.detail_json)).toEqual({ templateId, created: 13 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('keeps 9:00 local on both sides of a daylight-saving change', async () => {
|
it('keeps 9:00 local on both sides of a daylight-saving change', async () => {
|
||||||
@@ -143,13 +148,13 @@ describe('add weekly shifts', () => {
|
|||||||
expect(added.headers.get('location')).toBe(`/admin/events/${eventId}?notice=generated`);
|
expect(added.headers.get('location')).toBe(`/admin/events/${eventId}?notice=generated`);
|
||||||
const page = await app.request(added.headers.get('location') ?? '', { headers: { cookie } });
|
const page = await app.request(added.headers.get('location') ?? '', { headers: { cookie } });
|
||||||
const html = await page.text();
|
const html = await page.text();
|
||||||
expect(html).toContain('Weekly shifts for the next eight weeks are on the schedule.');
|
expect(html).toContain('Weekly shifts for the next three months are on the schedule.');
|
||||||
expect(html).toContain('Add weekly shifts');
|
expect(html).toContain('Add weekly shifts');
|
||||||
expect(count(db, 'SELECT COUNT(*) AS n FROM shifts')).toBe(9);
|
expect(count(db, 'SELECT COUNT(*) AS n FROM shifts')).toBe(14);
|
||||||
|
|
||||||
const repeat = await postGenerate(app, eventId, cookie);
|
const repeat = await postGenerate(app, eventId, cookie);
|
||||||
expect(repeat.headers.get('location')).toBe(`/admin/events/${eventId}?notice=generated`);
|
expect(repeat.headers.get('location')).toBe(`/admin/events/${eventId}?notice=generated`);
|
||||||
expect(count(db, 'SELECT COUNT(*) AS n FROM shifts')).toBe(9);
|
expect(count(db, 'SELECT COUNT(*) AS n FROM shifts')).toBe(14);
|
||||||
expect(count(db, "SELECT COUNT(*) AS n FROM audit WHERE action = 'template.expand'")).toBe(1);
|
expect(count(db, "SELECT COUNT(*) AS n FROM audit WHERE action = 'template.expand'")).toBe(1);
|
||||||
|
|
||||||
const none = await postGenerate(app, empty, cookie);
|
const none = await postGenerate(app, empty, cookie);
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import { isWithinSignupWindow, signupDeadline, signupDeadlineLabel } from '../src/signup-window.js';
|
||||||
|
|
||||||
|
describe('signup window', () => {
|
||||||
|
it('opens signup through the same local date three months ahead', () => {
|
||||||
|
expect(signupDeadline('2026-10-14')).toBe('2027-01-14');
|
||||||
|
expect(signupDeadlineLabel('2026-10-14')).toBe('January 14, 2027');
|
||||||
|
expect(isWithinSignupWindow('2027-01-14', '2026-10-14')).toBe(true);
|
||||||
|
expect(isWithinSignupWindow('2027-01-15', '2026-10-14')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses the last valid day when the later month is shorter', () => {
|
||||||
|
expect(signupDeadline('2026-01-31')).toBe('2026-04-30');
|
||||||
|
expect(isWithinSignupWindow('2026-04-30', '2026-01-31')).toBe(true);
|
||||||
|
expect(isWithinSignupWindow('2026-05-01', '2026-01-31')).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -77,14 +77,14 @@ describe('weekly template editing', () => {
|
|||||||
const generated = await postGenerate(app, eventId, cookie);
|
const generated = await postGenerate(app, eventId, cookie);
|
||||||
expect(generated.status).toBe(303);
|
expect(generated.status).toBe(303);
|
||||||
const wednesdays = count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Sorting'");
|
const wednesdays = count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Sorting'");
|
||||||
expect(wednesdays).toBe(9);
|
expect(wednesdays).toBe(14);
|
||||||
|
|
||||||
const friday = await postTemplate(app, eventId, cookie, { weekday: '5', role: 'Intake', capacity: '4' });
|
const friday = await postTemplate(app, eventId, cookie, { weekday: '5', role: 'Intake', capacity: '4' });
|
||||||
expect(friday.headers.get('location')).toBe(`/admin/events/${eventId}?notice=template-saved`);
|
expect(friday.headers.get('location')).toBe(`/admin/events/${eventId}?notice=template-saved`);
|
||||||
await postGenerate(app, eventId, cookie);
|
await postGenerate(app, eventId, cookie);
|
||||||
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Sorting'")).toBe(wednesdays);
|
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Sorting'")).toBe(wednesdays);
|
||||||
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Intake' AND capacity = 4")).toBe(8);
|
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Intake' AND capacity = 4")).toBe(13);
|
||||||
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE template_revision = 1")).toBe(wednesdays + 8);
|
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE template_revision = 1")).toBe(wednesdays + 13);
|
||||||
|
|
||||||
const templateId = (
|
const templateId = (
|
||||||
db.prepare("SELECT id AS id FROM shift_templates WHERE role = 'Intake'").get() as { id: number }
|
db.prepare("SELECT id AS id FROM shift_templates WHERE role = 'Intake'").get() as { id: number }
|
||||||
@@ -95,14 +95,14 @@ describe('weekly template editing', () => {
|
|||||||
revision: 2,
|
revision: 2,
|
||||||
role: 'Packing',
|
role: 'Packing',
|
||||||
});
|
});
|
||||||
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Intake'")).toBe(8);
|
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Intake'")).toBe(13);
|
||||||
|
|
||||||
const ended = await postEnd(app, eventId, templateId, cookie);
|
const ended = await postEnd(app, eventId, templateId, cookie);
|
||||||
expect(ended.headers.get('location')).toBe(`/admin/events/${eventId}?notice=template-ended`);
|
expect(ended.headers.get('location')).toBe(`/admin/events/${eventId}?notice=template-ended`);
|
||||||
const page = await app.request(`/admin/events/${eventId}?notice=template-ended`, { headers: { cookie } });
|
const page = await app.request(`/admin/events/${eventId}?notice=template-ended`, { headers: { cookie } });
|
||||||
const html = await page.text();
|
const html = await page.text();
|
||||||
expect(html).toContain('This weekly template has ended. Shifts already on the schedule stay.');
|
expect(html).toContain('This weekly template has ended. Shifts already on the schedule stay.');
|
||||||
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Intake'")).toBe(8);
|
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Intake'")).toBe(13);
|
||||||
expect(count(db, 'SELECT COUNT(*) AS n FROM outbox')).toBe(1);
|
expect(count(db, 'SELECT COUNT(*) AS n FROM outbox')).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user