diff --git a/README.md b/README.md index db6f11e..cdcf86d 100644 --- a/README.md +++ b/README.md @@ -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. -**Contacts**, on the coordinator page, keeps a list of people. Saving someone there 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 email updates that person. A different email stays a separate person, even when the name matches. A blank phone does not erase a phone already saved. 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. **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. Typing a walk-in who is not on the list does not add them to it. +**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 blank phone does not erase a phone already saved. 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. **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. diff --git a/migrations/006_contact_name.sql b/migrations/006_contact_name.sql new file mode 100644 index 0000000..99d6765 --- /dev/null +++ b/migrations/006_contact_name.sql @@ -0,0 +1,59 @@ +-- A contact is one name at one email address. +-- Two different names can share an email and stay two contacts. +-- The signup retention job does not clear this table. + +CREATE TABLE contacts_next ( + id INTEGER PRIMARY KEY, + first_name TEXT NOT NULL CHECK ( + length(trim(first_name)) > 0 + AND length(first_name) <= 80 + AND instr(first_name, char(10)) = 0 + AND instr(first_name, char(13)) = 0 + ), + last_name TEXT NOT NULL CHECK ( + length(trim(last_name)) > 0 + AND length(last_name) <= 80 + AND instr(last_name, char(10)) = 0 + AND instr(last_name, char(13)) = 0 + ), + email TEXT NOT NULL, + email_norm TEXT NOT NULL CHECK ( + email_norm = lower(email_norm) + AND instr(email_norm, ' ') = 0 + AND instr(email_norm, '@') > 1 + AND instr(email_norm, char(10)) = 0 + AND instr(email_norm, char(13)) = 0 + ), + phone TEXT NULL CHECK ( + phone IS NULL + OR ( + length(phone) BETWEEN 1 AND 40 + AND instr(phone, char(10)) = 0 + AND instr(phone, char(13)) = 0 + ) + ), + created_at TEXT NOT NULL CHECK ( + created_at GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9]Z' + ), + updated_at TEXT NOT NULL CHECK ( + updated_at GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9]Z' + ), + CHECK (length(first_name) + length(last_name) + 1 <= 80) +); + +INSERT INTO contacts_next (id, first_name, last_name, email, email_norm, phone, created_at, updated_at) +SELECT id, first_name, last_name, email, email_norm, phone, created_at, updated_at FROM contacts; + +DROP TABLE contacts; +ALTER TABLE contacts_next RENAME TO contacts; + +CREATE UNIQUE INDEX contacts_one_name_per_email + ON contacts (first_name COLLATE NOCASE, last_name COLLATE NOCASE, email_norm); + +UPDATE contacts +SET phone = substr(phone, 1, 3) || '-' || substr(phone, 4, 3) || '-' || substr(phone, 7, 4) +WHERE phone GLOB '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'; + +UPDATE contacts +SET phone = substr(phone, 2, 3) || '-' || substr(phone, 5, 3) || '-' || substr(phone, 8, 4) +WHERE phone GLOB '1[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'; diff --git a/src/admin-http.tsx b/src/admin-http.tsx index 546d065..ab70f7d 100644 --- a/src/admin-http.tsx +++ b/src/admin-http.tsx @@ -86,8 +86,11 @@ import { loadContacts, parseContactSkips, removeContact, + saveManualContact, walkInFromContact, type ContactImportSummary, + type ContactManualErrors, + type ContactManualValues, } from './contacts.js'; import { dateStamp, exportDateRange, exportEventRoster, exportShiftRoster } from './export.js'; import { originAllowed } from './origin.js'; @@ -139,6 +142,7 @@ export function registerAdmin(app: Hono, services: AdminServices): void { app.post(appPath(config, '/admin/settings'), (c) => submitSettings(c, services)); app.post(appPath(config, '/admin/export'), (c) => submitExportRange(c, services)); app.get(appPath(config, '/admin/contacts'), (c) => showContacts(c, services)); + app.post(appPath(config, '/admin/contacts/new'), (c) => submitNewContact(c, services)); app.post(appPath(config, '/admin/contacts/import'), (c) => submitImportContacts(c, services)); app.post(appPath(config, '/admin/contacts/export'), (c) => submitExportContacts(c, services)); app.get(appPath(config, '/admin/contacts/:id/remove'), (c) => showRemoveContact(c, services)); @@ -343,7 +347,12 @@ async function submitExportShift(c: Context, services: AdminServices): Promise, { account: session, status: options?.status ?? 200 }, ); } +async function submitNewContact(c: Context, services: AdminServices): Promise { + const session = await postedSession(c, services); + if (session instanceof Response) return session; + const values = { + firstName: textField(session.body, 'first_name'), + lastName: textField(session.body, 'last_name'), + email: textField(session.body, 'email'), + phone: textField(session.body, 'phone'), + }; + try { + const saved = saveManualContact(services.db, session.coordinatorId, values, services.now()); + if (!saved.ok) return showContacts(c, services, { status: 400, manual: { values, errors: saved.errors } }); + const notice = saved.status === 'added' ? 'contact-saved' : saved.status === 'changed' ? 'contact-updated' : 'contact-matched'; + return c.redirect(appPath(services.config, `/admin/contacts?notice=${notice}`), 303); + } catch (err) { + return saveFailed(c, services, session, err); + } +} + async function submitImportContacts(c: Context, services: AdminServices): Promise { const session = await postedSession(c, services); if (session instanceof Response) return session; @@ -1452,7 +1481,10 @@ function knownNotice(value: string | undefined): string | undefined { value === 'template-removed' || value === 'event-removed' || value === 'settings-saved' || - value === 'contact-removed' + value === 'contact-removed' || + value === 'contact-saved' || + value === 'contact-updated' || + value === 'contact-matched' ) { return value; } diff --git a/src/admin-pages.tsx b/src/admin-pages.tsx index eb8f9f9..e70b1b3 100644 --- a/src/admin-pages.tsx +++ b/src/admin-pages.tsx @@ -4,7 +4,15 @@ import { spotsSentence } from './schedule.js'; import type { EventValues, ShiftValues, TemplateValues } from './admin/forms.js'; import type { SettingsErrors, SettingsForm } from './settings.js'; import type { AppConfig } from './config.js'; -import { CONTACT_LIST_PAGE, contactImportSentence, contactSkipSentence, type Contact, type ContactImportSummary } from './contacts.js'; +import { + CONTACT_LIST_PAGE, + contactImportSentence, + contactSkipSentence, + type Contact, + type ContactImportSummary, + type ContactManualErrors, + type ContactManualValues, +} from './contacts.js'; import type { SignupErrors, SignupValues } from './signup-form.js'; import { addLocalDays, todayInZone } from './time.js'; import { appPath } from './url.js'; @@ -315,8 +323,10 @@ export function ContactsPage(props: { notice?: string; summary?: ContactImportSummary; importError?: string; + manual?: { values: ContactManualValues; errors: ContactManualErrors }; confirm?: ConfirmPrompt; }) { + const manual = props.manual ?? { values: { firstName: '', lastName: '', email: '', phone: '' }, errors: {} }; const heading = props.total === 0 ? 'Saved contacts' @@ -343,13 +353,23 @@ export function ContactsPage(props: { ) : null} {hiddenSkips > 0 ?

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

: null}

- Saving someone here does not sign them up for a shift. Importing this list does not take a spot and does not send email. Choose a name to add that person to an open shift. Old signups lose their details after the retention period. This list stays until you remove someone. + 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 add that person to an open shift. Old signups lose their details after the retention period. This list stays until you remove someone.

+