Repository navigation
Description
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 asReply-Toserver-side.message— required, 10–5000 chars,Textareaatom.- Turnstile widget, then submit / cancel.
- Auto-attached context the viewer doesn't type, built by a pure
buildReportContext()helper insrc/lib/report.ts: widget path
(location.pathname), host page URL (window.location.href), activelocale,
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
- A "Report an issue" row in
SettingsMenu
(src/components/molecules/SettingsMenu/SettingsMenu.tsx) — a plain
DropdownMenu.Itembelow the language/theme submenus. - A CTA button on
ErrorFallback
(src/components/molecules/Fallbacks/Fallbacks.tsx:27), passing the thrown
message as report context. - 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-drawerDrawerErrorFallback, 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 throughoverlayContainer(), notdocument.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):
ReportSchemaaccepts/rejects the boundary cases
andbuildReportContext()returns the expected shape; the form body renders
viarenderToStaticMarkup - Ladle stories for the modal (default, validation error, captcha-blocked,
thank-you), using the Turnstile test site key -
common.report.*keys present in everypublic/locales/<lng>/common.json - Lint + typecheck +
pnpm test:run+pnpm ladle:buildpass
Non-goals
- No real network submission (that's feat(widget): submit issue reports to the SahajCloud endpoint #80), no persisted report, no analytics
event (feat(widget): instrument event surfaces + evaluate TelemetryDeck #51 owns instrumentation), no drawer/URL integration.
Files affected
src/components/atoms/Modal/(new),src/components/atoms/index.tssrc/components/organisms/ReportIssueForm/(new),src/components/organisms/index.tssrc/components/molecules/SettingsMenu/SettingsMenu.tsxsrc/components/molecules/Fallbacks/Fallbacks.tsx,src/views/shared.tsxsrc/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
- Backend (shared
/api/contact-admin): feat(api): add a captcha-gated contact-admin endpoint SahajCloud#602 ·
Follow-up wiring: feat(widget): submit issue reports to the SahajCloud endpoint #80 - Turnstile client-side rendering + test keys: https://developers.cloudflare.com/turnstile/
Metadata
Metadata
Assignees
Labels
Type
Fields
Hold Until
Activity
feat(widget): add a report-issue modal with turnstile captcha (#81)