From 5a373a3b0bfe338e131a7f72ae9a264d4c16fbc6 Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Fri, 31 Jul 2026 11:41:13 +0100 Subject: [PATCH] Unify card selection UI via reusable CardSelection component; fix Buy a Gift Card new-card bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create CardSelection.svelte reusable component encapsulating the standard saved-card list + 'Use a new card' + CardInput pattern with blur-based validation (Luhn, expiry, CVC) — identical to the tip flows and account page. Refactor UserPaymentModal (Make a Payment submodal) to use CardSelection: - Removed its bespoke 'Use a different card' expand/collapse UI and inline validation derivations (parseExpiryParts, isValidLuhn, touched state) - Bound selectedCardId + new card fields to the component - payButtonDisabled now driven by component's onValidityChange callback - Removed now-unused CardInput import, SvelteDate import, formatCardExpiry Fix account 'Buy a Gift Card' bug: 'Use a new card' click did nothing because the auto-select effect immediately re-set buySelectedCard back to the default card. Added buyShowNewCard flag so the effect only auto-selects on initial load; reset after successful new-card purchase so the next purchase re-defaults. --- .../components/payments/CardSelection.svelte | 202 ++++++++++++++++ .../payments/UserPaymentModal.svelte | 227 ++---------------- frontend/src/routes/account/+page.svelte | 37 ++- 3 files changed, 246 insertions(+), 220 deletions(-) create mode 100644 frontend/src/lib/components/payments/CardSelection.svelte diff --git a/frontend/src/lib/components/payments/CardSelection.svelte b/frontend/src/lib/components/payments/CardSelection.svelte new file mode 100644 index 0000000..3f6a9b5 --- /dev/null +++ b/frontend/src/lib/components/payments/CardSelection.svelte @@ -0,0 +1,202 @@ + + +{#if cards.length > 0} +
+ {#each cards as card (card.id)} + + {/each} + + +
+{/if} + +{#if showNewCardForm || cards.length === 0} +
+ + {#if cardError} +

{cardError}

+ {/if} +
+{/if} diff --git a/frontend/src/lib/components/payments/UserPaymentModal.svelte b/frontend/src/lib/components/payments/UserPaymentModal.svelte index 525620c..93e63e5 100644 --- a/frontend/src/lib/components/payments/UserPaymentModal.svelte +++ b/frontend/src/lib/components/payments/UserPaymentModal.svelte @@ -1,6 +1,5 @@