Skip to content

feat(widget): add a report-issue modal with turnstile captcha #79

Closed

Description

@Ardnived

Summary

There is no way for a viewer to tell us something is wrong — a venue whose
address is stale, a class that no longer runs, or a crash sitting behind
ErrorFallback. Add a Report Issue contact form in a small ephemeral modal,
reachable from the settings cog and as a CTA on the error states, protected by a
Cloudflare Turnstile captcha. This ticket builds the whole client surface and
stops at the network boundary: submit shows the assembled payload in an
alert(). The shared POST /api/contact-admin endpoint lands in
sydevs/SahajCloud#602 and is wired up in #80.

The modal is deliberately not part of the drawer stack: it is ephemeral local
state, it does not appear in the URL, resolveStack never sees it, and opening
or closing it must not push or pop history (.claude/rules/i18n-and-state.md).

Proposed changes

Modal primitive — add a Modal atom (src/components/atoms/Modal/) over
@radix-ui/react-dialog (already a dependency via vaul, not yet used directly).
Radix owns focus trap / Esc / scroll lock; we own the Tailwind skin, matching the
Drawer atom's tokens. It must portal through overlayContainer()
(src/lib/overlay.ts) so it inherits the brand theme when embedded — the same
call SettingsMenu makes.

The form — a ReportIssueForm organism (src/components/organisms/ReportIssueForm/),
react-hook-form + zodResolver over a new ReportSchema in src/types/report.ts,
following RegistrationForm (src/components/organisms/RegistrationForm/RegistrationForm.tsx):

  • email — optional, z.string().email(); helper text says we can only reply if
    it's filled in. Used as Reply-To server-side.
  • message — required, 10–5000 chars, Textarea atom.
  • Turnstile widget, then submit / cancel.
  • Auto-attached context the viewer doesn't type, built by a pure
    buildReportContext() helper in src/lib/report.ts: widget path
    (location.pathname), host page URL (window.location.href), active locale,
    client name from the ['client', apiKey] cache, navigator.userAgent, and the
    error message when opened from an error CTA.

Captcha — a useTurnstile() hook (src/hooks/use-turnstile.ts) that lazily
injects https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit
on first open, renders explicitly into a ref'd container, passes theme from
useTheme() and language from useLocale(), and removes the widget on close.
Hand-rolled rather than adding @marsidev/react-turnstile — it's ~40 lines and
keeps the embedded bundle lean. Site key from a new VITE_TURNSTILE_SITE_KEY
(a Turnstile site key is public, so it belongs in the committed .env; dev,
Ladle and CI use Cloudflare's always-passes test key 1x00000000000000000000AA).

Open state — the triggers live in three unrelated places, so hold the open
state in a small zustand store (or context) and mount the modal host in
src/App.tsx outside <ErrorBoundary> (App.tsx:69-77), so it still opens
while the boundary is rendering ErrorFallback.

Entry points

  1. A "Report an issue" row in SettingsMenu
    (src/components/molecules/SettingsMenu/SettingsMenu.tsx) — a plain
    DropdownMenu.Item below the language/theme submenus.
  2. A CTA button on ErrorFallback
    (src/components/molecules/Fallbacks/Fallbacks.tsx:27), passing the thrown
    message as report context.
  3. The same CTA on DrawerErrorFallback (src/views/shared.tsx:328), beside the
    existing retry / see-nearby buttons.

Submit (temporary) — window.alert(JSON.stringify(payload, null, 2)) behind
a clearly-marked TODO(#80), then render the thank-you state, so the
follow-up only has to swap in the mutation.

Degradation — if the Turnstile script fails to load (a host page's CSP may
omit challenges.cloudflare.com in script-src/frame-src), replace the submit
control with an Alert and a mailto:[email protected] link rather than
leaving a form that can't be sent.

i18n — new common.report.* keys (title, description, email/message labels
and placeholders, submit, sent, captcha-blocked, plus the settings-menu label)
added across all locales with pnpm i18n:add, not en-only.

Acceptance criteria

  • A "Report an issue" item in the settings menu opens the modal, over both
    the map and the map-less (?map=0) layout, in LTR and RTL
  • The error CTA opens the same modal from both the app-level ErrorFallback
    and the in-drawer DrawerErrorFallback, with the error message carried
    into the report context
  • Opening/closing the modal changes neither the URL nor history length, and
    the drawer stack behind it is untouched; Esc / backdrop / cancel all close it
  • Submit is disabled until the message validates and a Turnstile token is
    present; an invalid email blocks submit with an inline message
  • Submitting shows an alert() containing email, message, turnstile token and
    the full auto-context, then the modal shows the thank-you state
  • The modal renders themed (light/dark, brand colours) when embedded — i.e. it
    portals through overlayContainer(), not document.body
  • With the Turnstile script blocked, the form shows the fallback notice + a
    mailto:[email protected] link instead of a dead submit button
  • Unit tests (node lane): ReportSchema accepts/rejects the boundary cases
    and buildReportContext() returns the expected shape; the form body renders
    via renderToStaticMarkup
  • Ladle stories for the modal (default, validation error, captcha-blocked,
    thank-you), using the Turnstile test site key
  • common.report.* keys present in every public/locales/<lng>/common.json
  • Lint + typecheck + pnpm test:run + pnpm ladle:build pass

Non-goals

Files affected

  • src/components/atoms/Modal/ (new), src/components/atoms/index.ts
  • src/components/organisms/ReportIssueForm/ (new), src/components/organisms/index.ts
  • src/components/molecules/SettingsMenu/SettingsMenu.tsx
  • src/components/molecules/Fallbacks/Fallbacks.tsx, src/views/shared.tsx
  • src/hooks/use-turnstile.ts, src/lib/report.ts, src/types/report.ts (new)
  • src/config/store.ts, src/App.tsx
  • .env, .claude/docs/environment.md, public/locales/*/common.json

References

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

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions