Fix regression: UserPaymentModal 'Use a new card' overridden by auto-select effect

Move the saved-card auto-select effect INTO CardSelection, where it owns both
cards and showNewCardForm. The effect is guarded by !showNewCardForm so the
'Use a new card' click (selectedCardId = '') is not immediately re-set to the
default card — previously the parent's unguarded effect (moved from the OLD
showNewCardForm guard during the CardSelection refactor) silently charged the
saved default card instead of the newly entered card.

CardSelection mounts fresh each time the modal opens (conditional {#if}
mounting in UserBookingModal and BookingFlow), so the auto-select fires once
on load, exactly like the tip flows' one-shot load-time selection.
This commit is contained in:
2026-08-22 00:34:49 +01:00
parent 5a373a3b0b
commit 73dd2c2dea
2 changed files with 11 additions and 8 deletions
@@ -46,14 +46,6 @@
let stamps = $state(0);
let useLoyalty = $state(false);
// Auto-select first saved card when methods load
$effect(() => {
if (paymentMethods.length > 0 && !selectedCardId) {
const defaultCard = paymentMethods.find((m) => m.is_default) ?? paymentMethods[0];
selectedCardId = defaultCard.id;
}
});
// New card form fields (bound into CardSelection)
let newCardNumber = $state('');
let newCardExpiry = $state('');