Skip to content

Convert router-touching classes to function components#707

Merged
rzueger merged 5 commits intodevelopfrom
refactor/router-prework
Apr 17, 2026
Merged

Convert router-touching classes to function components#707
rzueger merged 5 commits intodevelopfrom
refactor/router-prework

Conversation

@rzueger
Copy link
Copy Markdown
Member

@rzueger rzueger commented Apr 17, 2026

Summary

Pre-work for the upcoming react-router-dom v6 upgrade. Converts five
components that use legacy router APIs (withRouter, match via route
injection, this.props.history) to function components using v5's own
hooks. Once this lands, the v6 migration becomes a mechanical swap
(useHistoryuseNavigate, <Switch><Routes>, etc.) without
needing synthetic-prop shims or a local withRouter adapter.

Covered in this PR:

  • LoginPage — swap withRouter for useLocation.
  • MovementsPage — class → function; useHistory for the guest/kiosk
    redirect; early-return null avoids flashing the movement list.
  • ArrivalPaymentPage — class → function; useParams + mount effect.
  • AdminPage — class → function; useState for tabs, useHistory
    for the non-admin redirect.
  • PaymentMethod — class → function; useLocation + useTranslation.
    Adds an initialized state gate so the ?success=true return path
    from hosted checkout doesn't briefly show the selector before the
    success screen.

MovementWizard is the last remaining class that reads match.params
and will land in a follow-up PR.

Test plan

  • Login flow works (email token + guest-only query string paths).
  • /movements as a regular user renders; as guest/kiosk redirects
    to / without flashing the list.
  • /arrival/:key/payment shows loading spinner then Finish.
  • /admin as admin: all enabled tabs render, switching works.
  • /admin as non-admin: redirects to /.
  • Feature-flag-hidden admin tabs (invoice-recipients,
    guest-access, kiosk-access, import, privacy) hide/show
    correctly per __CONF__ and redux tokens.
  • Arrival finish: select method → submit → completes.
  • Arrival finish with single enabled method: auto-confirms.
  • Return from hosted checkout (?success=true): lands on success
    screen with no flash of the selector.
  • Cancel card payment button still dispatches cancelCardPayment.
  • npm run typecheck clean.
  • npm test passes.

rzueger added 5 commits April 17, 2026 09:54
Drop the withRouter HOC in favor of the useLocation hook.
Prep for the react-router-dom v6 upgrade, where withRouter is
removed.
Replace class component and withRouter-injected history with
useHistory hook and useEffect. Guest and kiosk users get an
early-return null to avoid flashing the movement list before
the redirect fires.

Prep for the react-router-dom v6 upgrade.
Replace class and match-prop read with useParams, swap
componentWillMount init chain for a mount useEffect, and
replace withTranslation HOC with the useTranslation hook.
The existing loading spinner already masks the first-render
flicker between effect scheduling and redux update.

Prep for the react-router-dom v6 upgrade.
Replace class state with useState, withRouter-injected history
with useHistory, and componentWillMount admin-guard with a
mount useEffect. Non-admins see a brief empty header before
the redirect fires; acceptable since the class already gated
the inner Content on the admin check.

Prep for the react-router-dom v6 upgrade.
Replace class with a function component using useLocation and
useTranslation hooks, and move the componentWillMount init
logic into a mount useEffect.

Add an 'initialized' state gate that renders a loading spinner
until the effect runs. Without it, the ?success=true return
path from the hosted checkout would briefly show the payment
method selector before re-rendering into the success screen.

Prep for the react-router-dom v6 upgrade.
@rzueger rzueger merged commit 2c9bfa2 into develop Apr 17, 2026
2 checks passed
@rzueger rzueger deleted the refactor/router-prework branch April 17, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant