Render Brex's selection and error dialogs through shared components

Merged
JA
1d ago
+663-195

Summary

Provider kit Track B, B5a: Brex's account-selection dialogs and its two error dialogs render through shared components. select_accounts and select_existing_account share one ProviderItem::AccountSelectionComponent; _api_error and _setup_required become ProviderItem::ApiErrorComponent and ProviderItem::SetupRequiredComponent. The move itself leaves the HTML unchanged, checked against snapshots taken before the change. A separate commit then switches the dialogs' hand-built alert and Cancel link to DS primitives (see Screenshots).

Part of #5003 (Track B, item 5, first of two slices: B5a selection pages, B5b setup page).

Stacked on #5233. Fork pre-flight: jaysbeekay/sure#723 (same branch, same commit; its CI, Gatekeeper review and screenshot history live there).

What changed

  • ProviderItem::AccountSelectionComponent: the two Brex selection templates differed in seven lines (title, description, form URL, hidden field, checkbox or radio, cancel path, button label), so one component covers both. It picks between them by whether an account: is given. Messages come from the provider's existing select_accounts.* / select_existing_account.* keys, including configure_name_in_<key>; field names come from the provider key (<key>_item_id, <key>_account_id).
  • The provider turns its API payloads into AccountSelectionComponent::Options (id, name, metadata). Brex does it in a new brex_account_options helper, built on its existing brex_account_display / brex_account_metadata.
  • ProviderItem::ApiErrorComponent and ProviderItem::SetupRequiredComponent: the two dialogs, with messages from <key>_items.api_error.* / setup_required.*.
  • The four Brex views keep their names, ivars and locals and render the components; the controller is unchanged.

Screenshots

The move (first commit) changes nothing visible. The DS commit (8fb320136) renders the API error and setup-required messages as DS::Alert (error and warning variants) and the Cancel as a secondary DS::Link, as AGENTS.md and the design-system guide ask. Before is this branch without that commit; after is with it. 1400px and 390px wide.

BeforeAfter
Select accounts, desktop
Select accounts, phone
API error, desktop
API error, phone
Setup required, desktop
Setup required, phone

Demo data

No demo data needed: no new records.

Migration notes

No migration.

Verification

  • Snapshots: five renders of the original views, recorded before the change, with the same normalisation as B4:

    • select accounts;
    • select accounts where no account has a name (Brex always supplies a default name, so the test stubs BrexAccount.name_for to reach the "cannot import" path, with no return_to);
    • select an existing account;
    • the API error;
    • setup required.

    ProviderItem::SelectionComponentsTest asserts the views still render each one, and that they render through the three components; the latter fails without the change (uninitialized constant ProviderItem::AccountSelectionComponent).

  • Snapshot provenance (re-checked 2026-11-17): the five original snapshot tests, plus the new mixed-names one, were run against the old Brex templates on up/provider-kit-panel, before this slice: all pass (the only error is the wiring test, since the components don't exist there).

  • Review fixes (2026-11-17): a test for the API error's fallback link with no return path; a snapshot where one account is named and one is not (recorded from the old template); then the DS commit, which re-records the six affected snapshots on purpose. Each re-recorded diff is the alert block or the Cancel link and nothing else.

  • Existing tests unchanged: BrexItemsControllerTest, BrexItemsProviderKitTest and the Brex helper tests pass unedited.

  • Mutations, each caught: the radio button's field name; the hidden connection id's field name; the submit enabled with no nameable account; the wrong cancel path; the "configure the name in Brex" message key; the API error ignoring its return path; the checkbox's field name.

  • bin/rails test (full, at the B5a commit): 16,300 runs, 0 failures; the same 8 ReleaseNotesWorkflowTest errors (no node in the test image).

  • bin/rubocop, erb_lint on the changed templates and bin/brakeman: no offenses or warnings.

  • Diff with copy detection (git diff -C against B4b): non-test +238 / -195.

  • Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.

Blast radius

  • ProviderItemsController renders brex_items/select_accounts, brex_items/select_existing_account, brex_items/setup_required and brex_items/api_error with the same ivars and locals; unchanged.
  • Siblings: the other providers' selection and error dialogs keep their own templates for now.

Summary by cubic

Renders Brex's account-selection, API-error, and setup-required dialogs through shared ProviderItem components. select_accounts and select_existing_account share one AccountSelectionComponent, which picks between them by whether an account: is passed; _api_error and _setup_required become ApiErrorComponent and SetupRequiredComponent. Messages and field names derive from the provider key, so the Brex views keep their names, ivars, and locals; a new brex_account_options helper turns Brex's API payloads into the component's options.

The refactor leaves the rendered HTML unchanged, pinned by snapshots recorded from the old templates. A follow-up commit is a deliberate visual change: the dialogs' alerts and Cancel links render through DS::Alert and DS::Link instead of hand-built markup, with only the affected snapshots re-recorded.

Tests stub the product name so an environment-set PRODUCT_NAME doesn't drift snapshot output, and check the API-error dialog's issue spacing on the raw render. Other providers' dialogs keep their own templates for now.

  • API-error dialog falls back to Provider Settings when no return path is given.
  • Accounts with blank names render as disabled and cannot be selected.

Summary by CodeRabbit

  • New Features
    • Added account-linking dialogs for selecting one or multiple Brex accounts, with unnamed accounts marked as unavailable until configured.
    • Added Brex connection-error and setup-required dialogs with guidance and a link to Provider Settings.