refactor: extract Stepper, useMerchantSession, DisconnectWalletMenu, and FormErrorBanner - #143
Open
davidugorji wants to merge 2 commits into
Open
Conversation
Extract four duplicated or page-local concerns from the register and
sign-in flows into reusable units:
- Stepper (src/components/stepper.tsx) replaces the inline stepMeta
.map() progress indicator in RegisterClient. Accepts steps and
currentStep; markup and classes are unchanged.
- useMerchantSession (src/hooks/use-merchant-session.ts) wraps
getMerchantSessionAddress, returns { walletAddress, isLoading } and
performs the /sign-in redirect internally. RegisterClient now uses
the hook instead of its own useEffect.
- clearMerchantSession + DisconnectWalletMenu give merchants a way to
clear MERCHANT_SESSION_KEY from the UI. The Topbar wallet pill is now
the dropdown trigger, and MerchantSessionGuard applies the session
guard to the whole (dashboard) route group so /dashboard redirects
back to /sign-in once the session is cleared.
- FormErrorBanner wraps a new Alert primitive and replaces the
duplicated destructive-banner markup in RegisterClient and
SignInClient. Rendered classes are identical, so there is no visual
change.
Adds unit tests for the stepper, hook, disconnect menu, and error
banner.
next build failed on main at the lint gate with four errors unrelated to this branch's changes. Fixed mechanically so CI can pass: - payment/[id]/page.tsx: drop unused reject param - api-key-reveal.tsx: use optional catch binding for unused error - InvoiceRowActions.test.tsx: drop unused waitFor import - ProfileDetailsForm.test.tsx: @ts-ignore -> @ts-expect-error
|
@davidugorji Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extracts four shared units out of the merchant register and sign-in flows.
Closes #116
Closes #112
Closes #115
Closes #122
#116 — Stepper
src/components/stepper.tsxacceptssteps: { step, label, icon }[]andcurrentStep.RegisterClientrenders<Stepper steps={stepMeta} currentStep={step} />in place of the inline.map()overstepMeta. Markup, classes, and the active/inactive branch are copied verbatim, so the indicator is pixel-identical.#112 — useMerchantSession
src/hooks/use-merchant-session.tswrapsgetMerchantSessionAddressfromsrc/lib/merchant-storage.ts, returns{ walletAddress, isLoading }, and performs therouter.replace("/sign-in")redirect internally.RegisterClient's inlineuseEffectand itswalletAddressstate are removed in favour of the hook; its existing loading spinner branch is untouched, so visiting/registerwithout a session still redirects exactly as before.#115 — DisconnectWalletMenu
clearMerchantSession()added tosrc/lib/merchant-storage.ts, removingMERCHANT_SESSION_KEYfromsessionStorage.src/components/disconnect-wallet-menu.tsxuses the RadixDropdownMenu(same import style asInvoiceRowActions) with a single "Disconnect wallet" item that clears the session and redirects to/sign-in.Topbarwallet pill is now the dropdown trigger, keeping the same truncated-address presentation.MerchantSessionGuardappliesuseMerchantSessionto the whole(dashboard)route group, which is what makes the acceptance criterion hold: after disconnecting,/dashboardredirects straight back to/sign-in. The group layout stays a server component, so per-pagemetadataexports are unaffected.#122 — FormErrorBanner
The issue refers to "the more general Alert primitive", but no
Alertexisted in the repo yet, so this adds a minimalsrc/components/ui/alert.tsxfollowing the existingbutton.tsxcva pattern. Itsdestructivevariant resolves to exactlyrounded-lg border border-destructive/30 bg-destructive/10 p-3 text-sm text-destructive— the class string previously duplicated in both pages.src/components/form-error-banner.tsxtakesmessage: string | null, returnsnullwhen the message is null, and accepts aclassNamefor the differing spacing (mt-5inRegisterClient,mb-4inSignInClient). Both pages now render through it with no visual change.Out-of-scope fix
next buildalready failed onmainat the lint gate with four errors unrelated to this work. They are fixed mechanically in a separate commit (968b5f5) so CI on this PR can pass — drop that commit if you'd rather handle it separately:payment/[id]/page.tsx— unusedrejectparamapi-key-reveal.tsx— unusederrorbindingInvoiceRowActions.test.tsx— unusedwaitForimportProfileDetailsForm.test.tsx—@ts-ignore→@ts-expect-errorTesting
Four new test files cover the stepper's label rendering and active-step highlighting, the hook's redirect and no-redirect paths, the disconnect menu clearing
sessionStorageand redirecting, and the banner's null/rendered/className behaviour.npx tsc --noEmit— cleannpx vitest run— 36 passed (11 files)npx next lint— 0 errorsnpx prettier --check .— cleannpx next build— succeeds