Skip to content

Event submission preview — render a user-submission proposal from postMessage #163

Description

@Ardnived

Reconciled with sydevs/SahajCloud#695 on 2026-09-06, settled against shipped source on
2026-09-16.
That issue deletes event-submissions and folds event proposals into one
user-submissions collection as type: 'proposal'. Two consequences for this ticket: the preview
route now targets a different collection slug, and the submit-payload half moved to #195
(see §2). Phase 3 merged as sydevs/SahajCloud#801, so the three points #695 left open are now
answered below from that source.

Why

SahajCloud reshapes event proposals so a manager reviews one as a proposal to judge rather than a
form to edit: one Events-shaped patch, a diff of what would change, and a live preview of the
resulting event.

Since sydevs/SahajCloud#695, a proposal is no longer its own collection. It is a row on
user-submissions with type: 'proposal', carrying event (nullable for a new-event proposal) and
proposed (a nested Events diff). The cutover is hard — event-submissions stops existing, and this
repo releases together with #695's Phase 3.

What is left on this repo is the preview route. The submit payload is #195's work now.

1. Preview route — render from postMessage, not a fetch

The admin's live-preview iframe will load:

{ATLAS_URL}/preview?collection=user-submissions&id=<id>&locale=<code>&live-preview=<Ed25519 token>

Composed in SahajCloud's src/plugins/formBuilder/index.ts, and only for data.type === 'proposal'
— the other intake types resolve to the explanation page instead. The credential is the #208 token,
verified against a committed public key; SAHAJCLOUD_PREVIEW_SECRET is retired.

Unlike collection=events, this route must not fetch the document by id. Two reasons, and #695
hardened the second one:

  • A new-event proposal has no Event id to fetch.
  • user-submissions joins RESTRICTED_COLLECTIONS, and #695 grants API clients create only, full
    stop — no update or read of any kind
    . A fetch is not a 403 risk, it is a certain 403. The preview
    secret cannot help: it unlocks drafts for collections a client can already read, and a client can
    read none of these.

Instead the event data arrives via Payload's own live-preview channel. The admin posts the full
document form state into the iframe
(@payloadcms/ui/dist/elements/LivePreview/Window/index.js:52):

const values = reduceFieldsToValues(formState, true)
const message = { type: 'payload-live-preview', collectionSlug, data: values }
iframeRef.current.contentWindow?.postMessage(message, url)

The row carries a virtual previewEvent field holding the merged Event object (target event +
proposed, or newEventDefaults + proposed for a new event), so data.previewEvent is a
ready-to-render event. Subscribe with @payloadcms/live-preview's subscribe() (or useLivePreview
from @payloadcms/live-preview-react) and render from that.

previewEvent is confirmed on SahajCloud main (src/collections/UserSubmissions/fields.ts:443):
a virtual JSON field, admin.hidden so the value reaches form state without rendering on the page,
computed by computePreviewEvent (hooks/computeReviewFields.ts:93) for type: 'proposal' only.
No client-side merge is needed.

Notes:

  • Show a skeleton until the first message arrives — there is no initial fetch to render from.
  • Relationship hydration by id still works and is still needed: previewEvent.region and
    previewEvent.images come through as ids, and both Regions and Images are readable by
    sahaj-atlas-client. No access change required.
  • ⚠ src/config/live-preview/protocol.ts still pins the old slug —
    export type LivePreviewCollection = 'event-submissions', and readLivePreviewParams nulls
    anything that is not that literal, so the /preview arm matches nothing the CMS sends. Nothing
    breaks today, because the atlas has never rendered a proposal preview. Fixing it belongs here.
  • The existing collection=events and collection=regions preview paths are unaffected.

2. Submit payload — owned by #195 now

Moved. #195 item 3 migrates the proposal call site to
POST /api/user-submissions with:

{ "type": "proposal", "event": 651, "proposed": { /* Events diff */ },
  "senderEmail": "…", "submissionData": [ /* submitter name, note */ ] }

submitterInfo does not survive — #695 deletes it with the collection, and the submitter's address
becomes the real senderEmail column while name and note become submissionData pairs.
regionHint does survive, as its own user-submissions column (see Open questions 2).
Turnstile stays in the x-turnstile-token header.

One detail #195 does not spell out, kept here as the contract reference: proposed is keyed by
real Events field names, and schedule is the real scheduleFields group — firstDate (UTC ISO)
plus firstDate_tz (IANA), then recurrenceType / interval / weekdays / endingType /
untilDate / endTime as applicable. The old { scheduleType: 'one-off' | 'weekly', startDate, startTime, endTime, weekdays, timezone } vocabulary is retired, and the CMS-side
mapSubmissionSchedule() translator is deleted, so whatever is sent is what gets stored. An unknown
key in proposed is refused with a 400 naming the key, validated at the collection against the live
Events config. Fold this paragraph into #195 when that ticket is implemented.

3. The message carries PII — read previewEvent and nothing else

Payload posts the whole document form state, not a curated payload. Under #695 that state carries
more than it used to: senderEmail (the submitter's real address, now a first-class column), the
submissionData pairs (name, note), the user relationship, uuid, screeningResult and
activityLog. SahajCloud has accepted that rather than drop live preview: it is a targeted
postMessage to our own origin, inside a logged-in manager's browser, and the alternative removes the
feature. The containment is therefore this route's job:

  • Render only data.previewEvent. Treat every other key on the message as absent. Nothing else in
    the payload has a legitimate use here.
  • Never log the message — no console.log(data), no error reporter breadcrumb, no analytics event
    carrying it. A whole-payload log puts a submitter's email into Sentry.
  • Never persist it — no localStorage / sessionStorage / cache / service-worker write, and never
    round-trip it to a server.
  • Check the origin before trusting a message, per @payloadcms/live-preview's own
    subscribe({ serverURL }) handling.
  • If a skeleton or error state needs to say something about the source, say "submission" — don't
    surface the submitter's name.

Worth a comment in the handler saying why, so a later refactor doesn't widen it back out to "just
render the whole message".

Scope

  • /preview handles collection=user-submissions, rendering from the payload-live-preview
    postMessage with a skeleton until the first message
  • LivePreviewCollection in src/config/live-preview/protocol.ts names user-submissions
  • Confirm relationship hydration still resolves region / images from the pushed ids
  • The handler reads only previewEvent, verifies the message origin, and neither logs nor
    persists the payload (see §3)
  • Confirm nothing still references event-submissions or the retired preview slug

Removed from scope, now #195's: the submit body, the scheduleFields emission, the field-name audit,
and the legacy-shape sweep.

Open questions — settled 2026-09-16 against SahajCloud main

  1. Does previewEvent survive? Yes. src/collections/UserSubmissions/fields.ts:443 — a virtual
    JSON field on user-submissions, admin.hidden, computed by computePreviewEvent for
    type: 'proposal' only. This route renders it; it does not merge event + proposed itself.
  2. Where does regionHint go? It stays, as its own column. fields.ts:656 keeps it a
    system-access JSON field ({ country, state, anchorRegion }) conditioned on
    type === 'proposal' — not a submissionData pair. It is load-bearing on the CMS side:
    lifecycle/review.ts:159 resolves a region from it, and jobs/DeliverSubmissions/deliverProposal.ts
    routes a proposal to the nearest manager up that region. Removing it would cost a screening input,
    so it is one moving part worth keeping.
  3. Is #641 superseded? No. It merged, and #695 carries its elements into the unified
    user-submissions rather than dropping them.

Ship order

sydevs/SahajCloud#695 Phase 3 merged as sydevs/SahajCloud#801, which deleted event-submissions
and created the user-submissions slug this route reads, so the gate is lifted. #195 carries the
submit half. ⚠ Phase 3 shipped without its consumers: POST /api/user-messages and
POST /api/events/{id}/register are gone (404 in production) while this repo's main still calls
both in src/config/api/mutate.ts — #195's work, and more urgent than this ticket.

🤖 Written by the sydevs autonomous loop — see what this is

Activity

  1. added theissue type on Aug 28, 2026
  2. Ardnived commented on Sep 6, 2026

    @Ardnived
    ContributorAuthor

    @sydevs-bot Update this ticket's description to reconcile these changes with the currently in-progress consolidation of EventSubmissions into FormSubmissions/UserSubmissions.

  3. changed the title [-]Event submission preview + Events-shaped submit payload[/-] [+]Event submission preview — render a user-submission proposal from postMessage[/+] on Sep 7, 2026
  4. sydevs-bot commented on Sep 7, 2026

    @sydevs-bot
    Contributor

    Reconciled against #695 and #195. Body rewritten, and §2 moves out.

    • §2 is feat(api): migrate widget intakes to unified form-submissions #195's item 3. It already specifies {type:'proposal', event?, proposed, senderEmail, submissionData}. I kept only what feat(api): migrate widget intakes to unified form-submissions #195 omits: proposed's scheduleFields vocabulary and the unknown-key 400.
    • event-submissions is deleted. A proposal is a user-submissions row, type: 'proposal'. The preview URL becomes collection=user-submissions.
    • "Do not fetch" is now certain, not cautious. #695 makes clients create-only on a RESTRICTED collection, with no read at any depth.
    • §3's PII list grew. senderEmail is a real column now, beside submissionData, user, uuid, screeningResult and activityLog.

    Three things #695 leaves open. I flagged them rather than assume:

    1. previewEvent is absent from #695's column table. Does the merged-event virtual field survive?
    2. regionHint has no stated home. #695 only says it dies with the collection.
    3. #641 is still this ticket's tracker, but #695 deletes its collection without mentioning it. Superseded?

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  5. Ardnived commented on Sep 7, 2026

    @Ardnived
    ContributorAuthor

    @sydevs-bot Here are answers to the open questions. Revise the issue description accordingly.

    1. previewEvent will not survive. Merge on the client side
    2. Is regionHint necessary in SahajCloud? Review both sides of the equation. If it is, it belongs in submissionData. That's definitely where submitterInfo belongs. I'd prefer to get rid of regionHint just to have one less moving part, but only if that doesn't create more complications or problems.
    3. SahajCloud#641 has already been merged. SahajCloud#695 does delete the collection, but it incorporates many of the elements of that collection into the new unified UserSubmissions
  6. 14 remaining items

  7. added
    bot:working
    and removed
    bot:working
    on Sep 16, 2026
  8. sydevs-bot commented on Sep 16, 2026

    @sydevs-bot
    Contributor

    Two of your three answers were overtaken by what Phase 3 shipped (SahajCloud#801, merged after you wrote them). Checked against SahajCloud main:

    1. previewEvent survives. UserSubmissions/fields.ts:443 — virtual JSON, admin.hidden, computed by computePreviewEvent for type: 'proposal' only, so it reaches form state and the iframe. No client-side merge needed.
    2. regionHint stays as its own column, not a submissionData pair (fields.ts:656). lifecycle/review.ts:159 resolves the region from it, and deliverProposal.ts routes a proposal to the nearest manager up that region. Dropping it costs a screening input. submitterInfo is gone, as you said.
    3. #641 is not superseded, as you describe.

    Body updated: the three questions are answered inline, the stale &secret= URL is now the #208 token, and the LivePreviewCollection slug mismatch is a scope line.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  9. removed
    bot:working
    on Sep 16, 2026
  10. Ardnived commented on Sep 17, 2026

    @Ardnived
    ContributorAuthor

    @sydevs-bot Answer: Why is this issue labeled as awaiting if it has already been approved and the PR is already created? We should move to tracking work through the PR at this point, so this ticket should no longer be awaiting

  11. added
    bot:working
    and removed on Sep 17, 2026
  12. sydevs-bot commented on Sep 17, 2026

    @sydevs-bot
    Contributor

    You are right, and the label came back by itself. #212 already carries awaiting — non-draft, reviewer requested — so the turn is on the PR.

    Two paths write awaiting on an issue, and they disagree:

    • session-end removes it and sets Status done when an open PR closes the ticket (dispatcher/decide.mjs:374).
    • sweep-awaiting re-adds it to any open, unlocked issue the bot spoke last on (decide.mjs:396). It never reads openPrsClosingIt, which gather.mjs:117 puts on every issue snapshot.

    My 23:33Z comment made the bot the last speaker, so the next sweep pass re-labelled this ticket. Locking it for this run cleared it again, and the sweep will repeat that until the guard lands.

    Filed as sydevs/claude-workflow#106 — one line in sweep-awaiting. An answer run may not push, so it needs a verb there.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  13. removed
    bot:working
    on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    Priority

    Medium

    Hold Until

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions