react-web-feature
Recipe and conventions for building features in the MediBooker v2 web app (apps/web, Next.js App Router), which contains the public practice page, the patient portal and the practice dashboard — folde
SKILL.md.claude/skills/react-web-feature/SKILL.md
GitHubReact web feature recipe
Framework: Next.js with the App Router (ADR 0003), self-hosted as a Node.js container. The public practice page is server-rendered and cached; portal and dashboard are signed-in client areas that are never cached.
Structure
apps/web/
src/proxy.ts locale (ar default, en), CSP nonce; sign-in redirect for (patient) and (practice) from A05
src/app/
[locale]/
layout.tsx <html lang dir>, practice theme (--brand-*) and fonts, set on the server
(public)/[slug]/ public practice page: server component, generateMetadata with hreflang, JSON-LD;
free times refreshed on the client (30–60 s); reserved slugs blocked
(patient)/ portal: appointments, book, record, family, settings (sign-in required)
(practice)/practice/ dashboard (base roles STAFF, DOCTOR; practice management, D17); realtime client
sitemap.ts, robots.ts
src/
providers/ QueryClient, i18n, theme, auth (client providers)
features/<feature>/
components/ feature-specific components
hooks/ wrappers around generated query hooks (useBookAppointment, ...)
schemas.ts zod schemas for forms
<feature>.test.tsx
components/ui/ design-system components (same names and props as in Figma)
lib/ API client setup, realtime client, date and format helpers
styles/ tokens.css (generated), globals.css
locales/ar/*.json, locales/en/*.json (Arabic is the default; more locales later)
Server components fetch only public data (the practice page). Everything with personal or health data runs in client components through the generated API client, with no-store; never pass tokens or health data through server-component props.
Rules
- Design system first. Build screens from
components/ui: shadcn/ui components on React Aria (ADR 0007), adapted to the Figma components; names and variants mirror Figma. If a component is missing, look for it in the shadcn registry first (pnpm --filter @medibooker/web exec shadcn search,docs,add: the CLI is an exact-pinned devDependency ofapps/web, so the release-age gate and the lockfile apply;--dry-run/--diffbefore updating an existing one) and adapt it to the Figma spec; never build it inline in a feature. Follow the shadcn composition rules (FieldGroup/Field for forms, items inside their group, a title in every Dialog/Sheet/Drawer, Badge/Alert/Empty/Skeleton/Spinner instead of custom markup, sonner toasts, lucide icons withdata-icon="inline-start|inline-end",classNamefor layout only). Style only with token CSS variables or token-based utility classes; shadcn's variables are mapped to tokens instyles/theme.css; no raw hex/OKLCH values or magic pixel numbers. - Data. Use the generated hooks from
@medibooker/api-clientand their query keys. After a mutation, invalidate the affected queries. Show errors by translating the servercode(errors.SLOT_NOT_AVAILABLE). - Realtime (dashboard). One socket connection per session (
lib/realtime.ts). Onappointment.*andslots.changed, invalidate the matching queries. Announce new bookings with a toast inside anaria-live="polite"region. Payloads contain IDs only; fetch details through the API. - Forms. react-hook-form + zod. Form schemas come from
@medibooker/api-client/zod(ADR 0012), extended in the form only where it needs more. Map problem+jsonerrors[]to the fields. Disable submit while pending, prevent double submits, send anIdempotency-Keyfor bookings. - Auth. Cookie-based; the app never reads tokens. Route guards check the role. The login redirect keeps the return path (no personal data in URLs). The staff dashboard logs out after inactivity (default 15 minutes) with a warning dialog first.
- States. Every data view renders loading (skeleton), empty (Empty State component with the next action), error (message and retry) and success. Optimistic updates only where rollback is trivial, never for booking.
- i18n and formatting. All copy through next-intl (
useTranslations, ADR 0013), keysfeature.screen.elementwith ICU plurals; dates, times and numbers of a practice throughlib/format.ts. Arabic is the default, English the fallback; adding a locale needs only a newlocales/<code>folder. Set<html lang dir>from the active locale. Dates, times and numbers only through helpers inlib/format.ts(Intlwith the active locale, the practice time zone, the configurednumberingSystemandhourCycle). Never concatenate translated fragments. 7a. RTL. Use CSS logical properties only (margin-inline-start,padding-inline,inset-inline-end,text-align: start; Tailwindms-* me-* ps-* pe-* start-* end-* text-start). Usertl:variants only for real exceptions. Mirror directional icons (chevrons, arrows, back/forward, log-out) via anIconprop; never mirror clocks, check marks, media controls or the logo. Wrap LTR snippets inside Arabic text (e-mail, phone, IDs, Latin names) in<bdi>; phone numbers and security-code inputs getdir="ltr". Follow the bidi table indesign-system(Latin token last in Arabic strings,←for "from → to"). Run every Playwright flow inar(RTL) anden(LTR). 7b. Practice theme and breakpoints. Brand colours come only from the--color-*tokens; the practice theme sets--brand-50 … --brand-950on the root, rendered on the server with the page (no flash of the default theme). Never compute or hard-code a brand colour in a component; status colours are fixed (ADR 0002). Breakpoints fromdesign-system: phone below 744 px, tablet 744–1279 px (compact header), desktop from 1280 px. 7c. Public practice page. The(public)route group has no auth, sets no cookies and loads no third-party scripts, fonts or maps. Server-rendered, one URL per locale withhreflang,schema.org/MedicalClinicstructured data, data only fromGET /public/practices/{slug}. No free times there since B07 (D19): "Book online" and the header lead to sign-in or sign-up with the way back to the booking page in the fragment (#next=/{locale}/book/{slug}, a page and no ids), and "Book appointment" goes to that page. The booking page, signed in, chooses the time (GET /practices/{practiceId}/availabilityand…/free-times) and keeps the choice in its own state, never in a URL or in storage. - Accessibility. Semantic HTML first. Dialog, menu, popover, tabs and date picker come from the shadcn/ui components (React Aria underneath; date fields use
@internationalized/date, which also supports Islamic calendars). Visible focus ring from theborder/focustoken, and neveroutline-nonebeside it: in Tailwind 4 that hides the ring (03 §9). A running request isisPendingon the button, notisDisabled, so that the focus stays. Keyboard navigation for the slot grid and the calendar (arrow keys). Move focus to the page heading on route change. Respectprefers-reduced-motion. Check with axe. 8a. Motion (ADR 0008). Animate with GSAP only throughuseGSAP()from@gsap/reactwith ascoperef, plugins registered once inlib/motion/gsap.ts; wrap later callbacks incontextSafe; never call gsap during SSR or import it in a Server Component. Create every animation insidegsap.matchMedia()with(prefers-reduced-motion: no-preference); reduced motion jumps to the end state. Horizontal motion usesinlineX()so it mirrors in RTL. Animate onlytransformandopacity; durations and easings come from the motion tokens. Never hide server-rendered, above-the-fold content until hydration. Primitive open/close states keep shadcn's CSS transitions; hover/focus/pressed stay plain CSS. - Security. No
localStorageorsessionStorageat all (lint, no exception since B07,docs/architecture/03-web.md§13). NodangerouslySetInnerHTML. CSP-safe code. No third-party trackers. Mask insurance numbers. - Performance. Code splitting per route. Virtualize long lists in the dashboard. Size and lazy-load images.
Tests
- Vitest + Testing Library for components and hooks; MSW for API mocks, typed from the OpenAPI types.
- Playwright e2e for the main flows (patient books and cancels; staff checks a patient in and generates slots), with
@axe-core/playwrighton every page. - Query elements by role and label, not by CSS selectors.
Checklist
- Matches the Figma frames (links in the handoff) in light and dark mode; all states present
- Only design-system components and tokens; no hard-coded colours or sizes
- Strings in
aranden; layout checked in RTL and LTR; dates/times in the practice time zone - Keyboard-only and screen-reader pass; axe clean
- Errors mapped from
code; double submit prevented - Lint, typecheck, unit and e2e tests green (commands and results in the handoff)