Skip to content

refactor(components): genericize event panel family + card/story cleanup #25

Closed

Description

@Ardnived

Summary

The component library has drifted: several "organisms" bundle presentation + data + domain logic + dialog chrome into one unit (EventPanel, EventDetails, EventRegistration, EventShare), a few atoms carry molecule/organism-level responsibility (Panel, Fallbacks, LanguageSelector, ThemeSwitch), and 5 stories' Ladle group no longer matches their folder tier.

This is a sweeping, high-risk restructuring that changes component structure without changing the visual result for the user — the only intentional visual addition is a mailing-list consent checkbox on the registration form. The goal: generic, presentational components that take parsed data from their parents; a single reusable dialog/trigger pattern; and a Ladle taxonomy where folder tier == story label. Radix UI throughout.

Packaging: one tracking issue with an ordered, phased checklist. Each phase is a self-contained commit on one branch; batch CI per the 3-phase PR workflow.

Hard constraint — visual parity. Every existing surface must render pixel-identically before/after (Ladle + Playwright screenshot diff). The consent checkbox is the sole exception.

Proposed changes (phased)

Phase A — Switch → Checkbox with two appearances (atoms; unblocks consent)

  • Add dependency @radix-ui/react-checkbox.
  • Rename atoms/Switch/ → atoms/Checkbox/ (Checkbox.tsx, index.ts, Checkbox.stories.tsx); SwitchProps → CheckboxProps.
  • Add appearance: 'switch' | 'checkbox' (default 'switch' so the existing look is the fallback). switch keeps today's @radix-ui/react-switch track/thumb (role="switch"); checkbox renders @radix-ui/react-checkbox with a check indicator (role="checkbox"). Preserve color/size variants + optional trailing children label.
  • Atoms barrel: Switch→Checkbox, SwitchProps→CheckboxProps.
  • Migrate the one consumer — molecules/SearchBar/SearchBar.tsx:94 — to <Checkbox appearance="switch" …/> (must stay pixel-identical to the current toggle).
  • Story shows both appearances.

Phase B — Trigger-based Modal API (atoms; unblocks share + registration dialogs)

  • Extend atoms/Modal/Modal.tsx: add optional trigger?: ReactNode rendered via Dialog.Trigger asChild; make isOpen/onOpenChange optional (uncontrolled when omitted, controlled when supplied — backward compatible). Add a ModalClose export (Dialog.Close asChild) for close-from-inside buttons.
  • This is the single dialog abstraction reused by Phases E and F.

Phase C — EventPanel → EventView + extract generic DetailRow (organisms/molecules)

  • Rename organisms/EventPanel/ → organisms/EventView/ (EventView, EventViewProps; story "Event View" under Organisms). Keep it out of the organisms barrel (still lazy-loaded — the code-split rationale is unchanged).
  • Promote the private EventDetail row (in EventDetails.tsx:189) to a generic molecules/DetailRow/ (icon-slot children + title + content + url? + isExternal?). Export from molecules barrel; add DetailRow.stories.tsx (Molecules).
  • Move EventContactDetails / EventTimingDetails / EventLocationDetails and the detectPlatform / directionsUrl helpers into the EventView/ folder as private subcomponents; EventView owns the ordering rule (contact-highlighted-first when no upcoming date; else timing → location → contact).
  • Delete organisms/EventDetails/ (folder + story). EventView composes DetailRows directly.
  • pages/event.tsx: update the lazy import to @/components/organisms/EventView (m.EventView). Do not rename the page-local EventPanel wrapper function or the other page-local *Panel wrappers.

Phase D — EventImages → generic ImageCarousel; delete Lightbox atom (molecules/atoms)

  • Rename molecules/EventImages/ → molecules/ImageCarousel/. New generic prop: slides: { src: string; alt?: string; caption?: string }[] (returns null when empty). Preserve the Swiper config exactly (autoplay 4000/enabled on >1, loop, EffectFade, dynamic bullets).
  • Fold yet-another-react-lightbox directly into ImageCarousel, behind a React.lazy/dynamic boundary so the YARL chunk + CSS stay out of the main bundle (preserve today's behavior). Delete atoms/Lightbox/ (folder + atoms-barrel export + story). Reproduce the current plugin set + single-slide arrow handling.
  • EventView maps event.images → slides ({ src: img.url, alt: img.alt ?? undefined, caption: img.alt ?? undefined }); the slides.ts/imagesToSlides mapping moves up into EventView.
  • Molecules barrel: EventImages → ImageCarousel; rename story (Molecules).

Phase E — EventRegistration → generic RegistrationForm + consent (organisms)

  • Rename organisms/EventRegistration/ → organisms/RegistrationForm/. Export RegistrationForm = form only, props { eventId, upcomingDates, questions, isOnline, eventTitle, eventUrl, onClose? }. It owns useForm + the createRegistration mutation + submitted/thank-you state + error Alert + online-notice Alert + footer buttons (via ModalClose/onClose), rendering ModalHeader/ModalBody/ModalFooter content. Keep it out of the organisms barrel.
  • Move the external-vs-native decision, the trigger Button, and the upcomingDates / enabledQuestions(event) derivation up into EventView: external → Button as link (no dialog); native (upcomingDates.length > 0) → <Modal trigger={<Button>Register</Button>}><RegistrationForm …/></Modal>. Delete RegistrationButton.
  • Consent checkbox (new, intentional): add <Checkbox appearance="checkbox"> before the privacy-policy note, default unchecked (opt-in). New field subscribe: z.boolean().optional() in src/types/registration.ts; send it in config/api/mutate.ts createRegistration body. Label from a new i18n key registration.mailing_list_consent added to every public/locales/<lng>/events.json (en, fr, …).
  • Simplification to verify: Radix unmounts Dialog.Content on close, so RegistrationForm should reset naturally on reopen — the current manual reset-on-close dance may be removable.
  • Rename story → "Registration Form" (Organisms); show the form inside a Modal, native + external, with consent.
  • Dependency: companion backend ticket on sydevs/SahajCloud to accept the consent flag on POST /events/:id/register (set mailingListSubscribedAt). The widget sends the field regardless; backend ignores it until shipped. (Linked below.)

Phase F — Remove ShareButton/ShareModal; parent composes ShareContent (molecules)

  • Delete ShareButton + private ShareModal; keep ShareContent (+ private CopyField). Rename folder EventShare/ → ShareContent/ and story → "Share Content" (folder = primary export).
  • Molecules barrel: drop ShareButton/ShareButtonProps; keep ShareContent/ShareContentProps.
  • EventView renders the share trigger + <Modal trigger={<Button>Share</Button>}> with the "Invite Friend" header + <ShareContent label={event.title} url={event.webUrl}/> — reproduce today's dialog exactly. RegistrationForm's thank-you keeps using ShareContent.

Phase G — Fold LanguageSelector + ThemeSwitch into Navbar (molecules/atoms)

  • Move atoms/LanguageSelector/ and atoms/ThemeSwitch/ into molecules/Navbar/ as private files; Navbar imports them locally. Remove their stories and their atoms-barrel exports. (Navbar is the only consumer — confirmed.)

Phase H — Card renames + "Molecules / List" group (molecules)

  • molecules/ListItem/ → molecules/RegionCard/ (RegionCard, RegionCardProps). Update molecules barrel + usages in pages/index.tsx, pages/country.tsx, pages/region.tsx.
  • molecules/EventItem/ → molecules/EventCard/ (EventCard, EventCardProps). Update molecules barrel + usage in organisms/EventsList/EventsList.tsx.
  • Story titles for List, RegionCard, EventCard → Molecules / List.

Phase I — Move Fallbacks + Panel to molecules (resolves the tier inversion)

  • Move atoms/Fallbacks/ → molecules/Fallbacks/ and atoms/Panel/ → molecules/Panel/ (Panel imports Fallbacks, so both move together to avoid an atom→molecule dependency). Update barrels + all importers (import { Panel } from '@/components/atoms' → '@/components/molecules' across the ~6 pages; Fallbacks importers: Panel, App.tsx). Story titles → Molecules.

Phase J — Story-taxonomy sweep + docs + Select barrel (cleanup)

  • Fix remaining folder≠label: Map, MapSearch stories → Organisms; SearchBar story → Molecules. After this, folder tier == story label for every story.
  • Export Select, SelectItem, SelectProps, SelectItemProps from the atoms barrel.
  • Docs: STORYBOOK.md — permit Tier / Group nested titles (document Molecules / List). DESIGN_SYSTEM.md — refresh the barrel/exception list (remove Switch/Lightbox/LanguageSelector/ThemeSwitch atom entries; add Checkbox, DetailRow, ImageCarousel, RegionCard, EventCard, RegistrationForm, EventView; note Panel/Fallbacks are now molecules; EventShare → ShareContent-only; document the Modal trigger API).

Cross-cutting

  • Rename/adjust co-located *.test.tsx + *.stories.tsx alongside each moved/renamed component; fix all imports.
  • Reuse existing helpers — src/lib/shape/ (isOnline, nextOccurrence, eventTimeZone, lexicalToHtml), src/lib/events.ts (isSoon) — don't re-implement.

Acceptance criteria

  • Switch renamed to Checkbox with appearance: 'switch' | 'checkbox'; SearchBar toggle is visually unchanged; consent uses role="checkbox".
  • Modal supports a trigger prop (uncontrolled) while remaining backward-compatible with controlled isOpen; both Share and Registration dialogs use it.
  • EventPanel renamed to EventView; generic DetailRow molecule exists; EventDetails deleted; the three detail rows + ordering live in EventView; the rendered event panel is pixel-identical (in-person / online / no-images).
  • EventImages → generic ImageCarousel taking {src, alt?, caption?}[]; atoms/Lightbox deleted; YARL still lazy-loaded (not in the main chunk — verify build output); carousel + lightbox behavior unchanged.
  • RegistrationForm is form-only and config-driven; EventView owns the trigger, external-link case, and Modal wrapper; registration flow (native + external + thank-you/share) unchanged.
  • Consent checkbox present, default unchecked; subscribe in RegistrationSchema + sent in the register body; registration.mailing_list_consent added to all locales; companion sydevs/SahajCloud ticket filed & linked.
  • ShareButton/ShareModal removed; ShareContent composed into a Modal by EventView and reused by the thank-you screen; share dialog unchanged.
  • LanguageSelector + ThemeSwitch are private Navbar subcomponents; their stories + atoms-barrel exports removed; Navbar unchanged.
  • ListItem→RegionCard, EventItem→EventCard; all usages updated; List/RegionCard/EventCard stories grouped under Molecules / List.
  • Fallbacks + Panel moved to molecules with all imports updated; no atom→molecule dependency remains.
  • Every story's folder tier == its Ladle label; Select/SelectItem exported from atoms barrel; STORYBOOK.md + DESIGN_SYSTEM.md updated.
  • pnpm typecheck && pnpm lint && pnpm test:run && pnpm build && pnpm ladle:build all pass; Playwright before/after shows no visual diff except the consent checkbox.

Files affected (representative)

  • Atoms: Switch/→Checkbox/, Modal/Modal.tsx, Lightbox/ (delete), Panel/→molecules, Fallbacks/→molecules, LanguageSelector/+ThemeSwitch/→Navbar, Select/index.ts + atoms barrel, atoms/index.ts.
  • Molecules: EventImages/→ImageCarousel/, EventShare/→ShareContent/, ListItem/→RegionCard/, EventItem/→EventCard/, DetailRow/ (new), Navbar/, SearchBar/SearchBar.tsx, List/*.stories, molecules/index.ts.
  • Organisms: EventPanel/→EventView/, EventDetails/ (delete), EventRegistration/→RegistrationForm/, EventsList/EventsList.tsx, Mapbox/*.stories, organisms/index.ts (NOTE comment).
  • Other: pages/event.tsx, pages/{index,country,region}.tsx (+ Panel importers), src/types/registration.ts, config/api/mutate.ts, public/locales/*/events.json, STORYBOOK.md, DESIGN_SYSTEM.md, package.json.

Verification

  1. pnpm typecheck && pnpm lint && pnpm test:run && pnpm build && pnpm ladle:build.
  2. pnpm build — confirm YARL is still in a separate lazy chunk (grep the dist/ chunk manifest), not the main bundle.
  3. pnpm ladle — eyeball Checkbox (both appearances), DetailRow, ImageCarousel, RegionCard/EventCard under Molecules / List, RegistrationForm-in-Modal, ShareContent-in-Modal, Navbar.
  4. pnpm dev + Playwright MCP on a real event: open an event panel (in-person, online, no-images), the registration dialog (native + external), and the share dialog; screenshot and diff against main — expect no change except the consent checkbox. Toggle the SearchBar filter (must look identical). Submit a registration with consent checked and confirm the payload includes subscribe.

References

  • Rules: .claude/rules/components.md, code-style.md, tests.md, data-layer.md, i18n-and-state.md; DESIGN_SYSTEM.md, STORYBOOK.md.
  • Reuse: src/lib/shape/, src/lib/events.ts, atoms/Modal, atoms/Button, atoms/Select, atoms/Alert, molecules/ShareContent.

Activity

  1. Ardnived commented on Jul 1, 2026

    @Ardnived
    ContributorAuthor

    Backend dependency (Phase E consent): sydevs/SahajCloud#524 — accept the subscribe flag on POST /api/events/:id/register and persist mailingListSubscribedAt. The widget sends the field regardless; consent isn't recorded until that lands.

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