Skip to content

feat(events): manager registration notifications + per-event routing - #594

Merged
Ardnived merged 17 commits into
mainfrom
feat/manager-registration-notifications
Jul 20, 2026
Merged

Ardnived merged 17 commits into
mainfrom
feat/manager-registration-notifications

Conversation

@Ardnived

@Ardnived Ardnived commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • When a seeker registers for a Sahaj-Atlas event, the event manager (or a per-event override address) now gets a notification email — sent on the Immediate cadence, best-effort so a send failure never breaks the 201. It forwards the registrant's answers to the event's registration questions and offers a Reply CTA (a mailto: pre-filled with a quoted recap) next to View event.
  • Adds the Registration-tab routing fields + resolveRegistrationRecipient (the recipient+cadence seam the scheduled-digest follow-up reuses), and types + validates the registration questions (keys ⊆ EVENT_REGISTRATION_QUESTIONS, string answers → a 400 on a bad payload).
  • New shared email primitives — EmailLayout.SectionHeading + BrandButtonRow (+ the earlier DetailRow) — reused by both the registration and verification templates for a consistent look.

Changes of note

  • src/lib/registrations/questions.ts (new) — the shared registration-questions contract (EVENT_REGISTRATION_QUESTIONS, RegistrationQuestions, RegistrationAnswer, validateRegistrationQuestions, buildRegistrationAnswers), so Registrations no longer cross-imports from the Events collection.
  • src/collections/Events/endpoints/registerForEvent.ts — resolves the recipient after payload.create and sends the manager notice on Immediate (its own best-effort try/catch, independent of the registrant confirmation).
  • src/lib/notifications/ — resolveRegistrationRecipient + sendRegistrationNotification; pickChannel parameterised by notification key (verification path unchanged).
  • src/emails/ — EventRegistrationEmail + shared SectionHeading / BrandButtonRow in EmailLayout; verification email repointed at the shared primitives.
  • scripts/preview-registration-notification-emails.ts — Ethereal preview for the notice, all states.

Migration

  • src/migrations/20260720_141351_event_registration_notification_fields.ts — adds registration_notification_email + registration_notification_frequency to events and _events_v (drafts) + the frequency enum. No data transformed. Reversible.

§4 summary-frequency gap (decision)

The override select omits Daily Summary / Weekly Summary until the scheduled-digest follow-up ships, so every selectable override cadence acts deterministically today (Immediate sends now, Never never sends) — no silent gap. The resolver still returns all four cadences; a manager's own summary preference is stored but sends nothing here (documented known gap), to be picked up by the digest run. Not a silent fall-back to immediate.

Test results

  • Unit: 817 passed — resolver branches, buildRegistrationAnswers / validateRegistrationQuestions, and EventRegistrationEmail + buildReplyBody render.
  • Integration: event-registration.int.spec.ts 31 passed — immediate send, override routing (manager gets no copy), override-blank → manager, summary/Never no-send, unresolvable manager, throwing send keeps 201, answers forwarded, unknown-key → 400.
  • Lint ✓ · Typecheck ✓.
  • Reviews: /simplify (4 agents → lifted the questions domain into src/lib), /code-review (high, correctness clean), /security-review (no issues — mailto injection-safe, validator blocks prototype keys).

Notes for reviewer

  • The questions-key enforcement is strict — Registrations.questions now rejects (400) any key not in EVENT_REGISTRATION_QUESTIONS. The Atlas widget already submits those keys (traced in sydevs/SahajAtlasWeb#60, filed to confirm before merge); flagging in case the live widget is out of sync.
  • The verification email's section-heading spacing is now shared with the registration email (a deliberate consistency change via the shared SectionHeading); its notification logic is untouched.
  • Two intentional test-approach deviations: int mail capture uses vi.spyOn(payload, 'sendEmail') (the pattern this file already uses — a second createTestEnvironment* per file is disallowed); "manager with no email" is unreachable via the real endpoint (auth requires one), so it's covered by the resolver unit test, with the endpoint's no-recipient → no-send path int-tested via a failed manager lookup.
  • jsonSchema was avoided for the questions validation — Payload compiles it to an Ajv new Function() validator that throws under Cloudflare's codegen ban (see translationsField); a pure-JS validate enforces the same.

Closes #588

🤖 Generated with Claude Code

Ardnived and others added 8 commits July 20, 2026 07:10
Add getFrequencyOptions + REGISTRATION_OVERRIDE_FREQUENCY_OPTIONS +
DEFAULT_REGISTRATION_FREQUENCY, sourced from NOTIFICATION_TYPES so the
per-event registration-notification fields can't drift from the shared
single source of truth. The override options omit the not-yet-delivered
summary cadences.

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The verification email's local DetailRow (plus its label/value column
styles) becomes a shared EmailLayout export so the registration
notification can reuse the same fact-table row. EventVerificationEmail
now imports it; its rendered output is unchanged.

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Adds a shared row on the Registration tab: registrationNotificationEmail
(email, shown for sahaj-atlas events) routes registration updates to an
address other than the manager, and registrationNotificationFrequency
(shown only when an override is set) picks the cadence. Options derive
from the shared NOTIFICATION_TYPES config; summaries are omitted until
the digest run exists.

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Adds registration_notification_email + registration_notification_frequency
to events and _events_v (drafts enabled), plus the frequency enum. Fully
reversible.

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add a pure resolver that returns the registration-notification target,
display name, channel, and frequency. An override address replaces the
manager and forces the email channel; otherwise the manager is reached
via pickChannel (now parameterised by notification key) at the
event_registration cadence. The frequency is returned, not acted on, so
the immediate send and the future digest run share this seam.

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
New EventRegistrationEmail (EmailLayout + BrandButton + styles +
DetailRow, Sahaj Atlas brand) shows the event, registrant, and session
with a link to the event in the admin. sendRegistrationNotification
renders + sends it; a non-email channel is stub-logged like the
verification reminders, and a real send failure throws so the 201 policy
stays at the call site.

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
registerForEvent now resolves the notification recipient after the
registration is created and, when the cadence is Immediate, sends the
manager (or override address) a notification. Best-effort and independent
of the registrant confirmation: a failure is logged and the response
stays 201. Adds int coverage for immediate send, override routing (manager
gets no copy), summary/Never no-send, an unresolvable manager, and a
throwing send. (Also tidies import order in the two new modules.)

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add the manager registration-notice template to the template table, note
DetailRow is now a shared EmailLayout export, and record the informational
manager-mail variant alongside the alert/itinerary archetypes.

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-594 July 20, 2026 15:16 Destroyed
Adds scripts/preview-registration-notification-emails.ts — drives the real
sendRegistrationNotification() path through an Ethereal transport to render
EventRegistrationEmail in its meaningful states (named manager, override
address with neutral greeting, no session, long title). Documents it in the
scripts + email rules.

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@railway-app

railway-app Bot commented Jul 20, 2026

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-594 environment in sahajcloud

Service Status Web Updated (UTC)
SahajCloud ✅ Success (View Logs) Web Jul 20, 2026 at 3:18 pm

Ardnived and others added 6 commits July 20, 2026 09:16
Placeholder ("Event Manager") + a description that spells out the field
redirects new-registration updates away from the manager.

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Three updates to the manager registration notification:
- Rename the "Session" row to "Start date".
- Forward the registrant's answers to the event's registration questions,
  labelled from EVENT_REGISTRATION_QUESTIONS (buildRegistrationAnswers) and
  rendered as a "Registration answers" section.
- Add a primary "Reply to <registrant>" mailto CTA (View event demoted to
  secondary).

Adds buildRegistrationAnswers + its unit test, extends the render + int
coverage, and updates the Ethereal preview script.

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Put Reply and View event side by side via a new shared BrandButtonRow
  (EmailLayout), factoring the variant style out of BrandButton.
- Reply is a mailto pre-filled with a quoted recap of the registration
  (event, start date, and the forwarded Q&A) so the seeker sees the
  context — a mailto can't set In-Reply-To, so it can't thread into the
  confirmation email; the quote stands in for the chain. Exports
  buildReplyBody + a unit test.
- Clarify the stale `questions`-key comments: answers are keyed by the
  event's EVENT_REGISTRATION_QUESTIONS names, which buildRegistrationAnswers
  resolves to labels.

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Payload embeds admin.description as JSDoc on the generated types; picks up
the registrationNotificationEmail copy tweak and the clarified
Registrations.questions description.

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add RegistrationQuestions (Partial<Record<question name, string>>) and a
pure-JS validateRegistrationQuestions, both derived from
EVENT_REGISTRATION_QUESTIONS, and wire the validator onto the
Registrations.questions field. A bad payload (unknown key or non-string
answer) throws a ValidationError, which the register endpoint surfaces as
a 400. Pure-JS validate rather than jsonSchema — Payload compiles the
latter to an Ajv new Function() validator that throws under Cloudflare's
codegen ban (see translationsField).

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Add a shared EmailLayout.SectionHeading (uppercase section label) and
  use it in both the registration and verification emails; the
  registration email gains an "Event details" heading above its table, so
  both sections now have consistent headers and top margin.
- BrandButtonRow centers its buttons together (inline in a centered cell)
  instead of spreading them across the width.
- Redesign the Reply mailto's quoted recap: one block per topic (event
  facts, then each Q&A) separated by blank quoted lines, question above
  its answer.

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Ardnived and others added 2 commits July 20, 2026 11:31
Move EVENT_REGISTRATION_QUESTIONS + RegistrationQuestions +
RegistrationAnswer + validateRegistrationQuestions + buildRegistrationAnswers
out of Events/eventOptions.ts into src/lib/registrations/questions.ts, so
Registrations no longer cross-imports from the Events collection (the
project-structure rule's cross-owner-import violation). RegistrationAnswer
is now defined once (the email imports it from src/lib). Also simplify
buildRegistrationAnswers to a two-loop form (drops the seen-set, the push
helper, and the QUESTION_LABELS map).

Refs #588

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-594 July 20, 2026 18:38 Destroyed
@Ardnived
Ardnived merged commit 1a6e702 into main Jul 20, 2026
2 checks passed
@Ardnived
Ardnived deleted the feat/manager-registration-notifications branch July 20, 2026 18:46
Ardnived added a commit to sydevs/SahajAtlasWeb that referenced this pull request Jul 20, 2026
…ON_QUESTIONS (#63)

* chore(types): resync payload-types from SahajCloud main

Regenerated via `pnpm types:cms`. SahajCloud main has advanced broadly since
the last sync — this refreshes ~20 interfaces (locale enums now include en-AU/
hu/nl and pt-BR casing, Region.eventDefaults dropped, User/Frame/Form/Client
shape updates, and the Registration.questions doc comment now names the
EVENT_REGISTRATION_QUESTIONS keys).

Typechecks cleanly; we don't reference any of the removed/renamed fields. Done
here so #60 can derive the registration-question key set from the freshly
synced Event['registrationQuestions'].

Refs #60

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(registration): constrain questions payload to the CMS question keys

The registration `questions` payload was typed loosely as
`z.record(z.string())`. SahajCloud now validates it (PR sydevs/SahajCloud#594):
keys must be EVENT_REGISTRATION_QUESTIONS members and values strings, else the
register endpoint 400s. Align the client to that contract before it ships.

- Derive `RegistrationQuestionName` from the synced `Event['registrationQuestions']`
  CMS type (not a hardcoded list). A `satisfies Record<RegistrationQuestionName, …>`
  on `RegistrationQuestionsSchema` fails the build if a `types:cms` resync adds or
  drops a question, and `REGISTRATION_QUESTION_NAMES` / `RegistrationQuestionNameSchema`
  derive from that schema's shape — one guarded source of truth.
- Tighten `RegistrationSchema.questions` to `z.record(RegistrationQuestionNameSchema,
  z.string())`, which rejects unknown keys / non-string values client-side, mirroring
  the server.
- Narrow `enabledQuestions()` and the RegistrationForm `questions` prop from
  `string[]` to `RegistrationQuestionName[]` so `register(\`questions.<name>\`)` stays
  type-checked against the tightened schema (behaviour unchanged — same ordered subset).
- Cover the contract in the type tests: valid subset, empty-string answer (an
  enabled-but-unanswered question), omitted questions, unknown key, non-string value.

Closes #60

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* test(types): drop tautological question-names assertion

Per the /simplify pass: `REGISTRATION_QUESTION_NAMES` *is* `Object.keys(
RegistrationQuestionsSchema.shape)`, so asserting them equal compared a value to
itself and could never fail. The concrete-list assertion already pins the key
set + order.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-594 — 2c70458a Deployed Jul 20, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(events): manager registration notifications + per-event routing

1 participant