#291. A plan switch (Upgrade, Downgrade, or Pay for this plan on a granted tier's card) was confirmed in a panel at the top of the Plans section, above the cards and away from the button that opened it. It now confirms in the same dialog as Cancel plan and Resume plan. The button opens the dialog at once, titled with the panel's question ("Switch to Pro?", or "Pay for Pro?" on the granted tier's own card), and the dialog's body loads from the switch's preview route, because the charge it states comes from Stripe at that moment. Keep current plan closes the dialog and sends nothing. An answer that belongs in the dialog stays there: a declined card, a payment awaiting the bank's approval, stale figures; focus moves to the new form. An answer that lands outside closes it: the switch made or refused, or a plan withdrawn after the page loaded. A load that fails closes the dialog with the error toast; a commit that fails (403 or 5xx, which the pages' htmx config does not swap) leaves it open with the toast. Closing the dialog while its body loads aborts the load, and the aborted load shows no toast. The shared dialog gains a region the loaded form lives in; the forms library renders a preview that leaves by the dialog without a box of its own; the lint accepts `data-action-load` as a trigger's route. No string is added or reworded. docs/design-system.md, docs/operator-ux-conventions.md and docs/stripe.md say the same. Tests: TestSwitchAnswersNameTheirRegion, TestPlanMoveTitle, TestSwitchControlOpensTheSharedDialog, TestConfirmModalCarriesTheLoadedRegion, TestPreviewInTheDialogRendersNoBox, and the walkthrough TestSwitchDialogWalkthrough (seven steps in a browser, among them a load answered offline, a load closed mid-flight, and a commit answered 503 by the browser so nothing reaches Stripe). The walkthrough resets the application database, so it runs only with SWITCH_DIALOG_WALK=1, as the merchant-disclosure sheet runs only when asked; make test skips it. 35 goldens change: every member plans golden loses one blank line, the switch controls of 12 lose their hx-* attributes for the dialog's, and the plan move form's golden loses its box. Full suite on reset databases: 5249 passed, 16 skipped, none failed. Sandbox walk on this commit, all twelve steps passed: the dialog opens at once and loads Stripe's figure ($20.00 equal to the preview's amount_due); Keep current plan sends nothing; Cancel plan shows its own form; offline the dialog closes with the toast; stale figures, a declined card and a payment awaiting approval stay in the dialog with focus on the new form; the made switch closes it and Max is current; a plan withdrawn in another session refuses in the Plans region; Pay for this plan reads "Pay for Max?". make screens: no page this commit touches changed. Three operator captures differ for other reasons: person detail and invoice detail show new ids, because the demo snapshot was rebuilt when the previous landing added a FedWiki migration, and the domains list's age column counts one more day (#120). Not walked by the walkthrough, with the reason: a request in flight at a chosen moment (the dialog closed while the commit runs, another switch opened) and a page restored from the browser's cache; a load answered 400 and a commit the switch refuses answer through the same close rule as the withdrawn plan and the made switch that the walkthrough and the hand walk cover. Breaks, all CAUGHT (19 test records): - own card titled as a switch (title test) - own card titled as a switch (control test) - setMove leaves the title unset - control loads without the price (control test) - control loads without the price (render test) - control loads the switch's route - heading left in the message - current tier's name unescaped - refused preview left in the dialog - confirmation answered into the Plans region (a declined switch) - confirmation answered into the Plans region (a stale switch) - confirmation answered into the Plans region (a switch awaiting approval) - decline answered 200 - way out a link again - commit's description dropped - region renamed in the partial - box rule removed - box rule widened to every kind - box rule widened to every way out Breaks of the walkthrough, all CAUGHT (8 records, each building and booting the app from the edited tree): - the close not deferred - the abort on close dropped - the cancelled mark ignored by the toast - the load not sent - the loaded region left showing under a static trigger - the close on an answer outside the dialog removed - the failed commit closing the dialog - the way out a link again Seen by no test: renderConfirmation without its describeCommit call (the database tests' handlers carry no Stripe key fingerprint, so the line is never shown there; describeCommit itself is pinned); data-action-load dropped from the lint's condition (no template interpolates a route into it); the spinner and aria-busy not set, and the focus after a stay-open answer not moved, which only the hand walk reaches, because the walkthrough stops before any Stripe write.
53 lines
2.4 KiB
Go
53 lines
2.4 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
|
|
|
|
package server
|
|
|
|
import (
|
|
"git.coopcloud.tech/wiki-cafe/member-console/internal/forms"
|
|
)
|
|
|
|
// shell.confirm (design D4, D12; docs/design-system.md "Confirm modal";
|
|
// task 5.6). The one shared confirmation dialog every destructive action on
|
|
// both surfaces opens through (shell_confirm_modal.html, driven by
|
|
// static/confirm-action-modal.js): one dialog, reused by every trigger, its
|
|
// title, body text, hidden fields, endpoint and commit class all
|
|
// reassigned by the script from the trigger's own data-action-*
|
|
// attributes at the moment it opens (design-system.md's trigger-contract
|
|
// table).
|
|
//
|
|
// Because one dialog serves many different mutations, this declaration
|
|
// carries no Fields of its own; CheckInvariants exempts the Confirm kind
|
|
// from the "declares no fields" rule for exactly this reason (a Field
|
|
// would have to belong to one trigger's shape, and every trigger's shape
|
|
// differs). The hidden fields a trigger needs are appended straight into
|
|
// the rendered <form> by the script itself, from data-action-fields; the
|
|
// body text is written into the form's Message region, which the Confirm
|
|
// kind renders unconditionally, empty at rest, so the script always has
|
|
// somewhere to write it (forms.FormView.MessageID's doc; app.css collapses
|
|
// it while empty).
|
|
//
|
|
// Method and Path below are never dispatched: the script rewrites
|
|
// hx-post/hx-delete, hx-target and hx-swap on every open, from the
|
|
// trigger's own attributes, before any submission can reach the network.
|
|
// They exist only because the invariants require a route-shaped value;
|
|
// "/partials/confirm" names no real handler and no route registers it.
|
|
//
|
|
// Nothing in this package reads the returned spec: internal/web's
|
|
// shellConfirmForm template function looks it up by name, because
|
|
// internal/web cannot import this package.
|
|
var _ = forms.Register(forms.FormSpec{
|
|
Name: "shell.confirm",
|
|
Kind: forms.KindConfirm,
|
|
Family: forms.Stacked,
|
|
Method: "POST",
|
|
Path: "/partials/confirm",
|
|
Commit: "Confirm",
|
|
WayOut: forms.DismissModal("Cancel"),
|
|
})
|
|
|
|
// confirmLoadedRegion is the selector of the shared dialog's loaded region
|
|
// (shell_confirm_modal.html), which an answer that renders a loaded
|
|
// confirmation names in HX-Retarget.
|
|
const confirmLoadedRegion = "#confirmActionModalLoaded"
|