style: fix prefer-const and prettier formatting issues
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
defaultPaymentType?: 'full' | 'partial' | 'deposit';
|
||||
}
|
||||
|
||||
let { booking, onClose, onComplete, canSaveCards = true, defaultPaymentType }: Props = $props();
|
||||
const { booking, onClose, onComplete, canSaveCards = true, defaultPaymentType }: Props = $props();
|
||||
|
||||
type PaymentStatus = 'idle' | 'processing' | 'polling' | 'success' | 'error';
|
||||
|
||||
@@ -140,9 +140,9 @@
|
||||
return { month, year };
|
||||
}
|
||||
|
||||
let expiryParts = $derived(parseExpiryParts(newCardExpiry));
|
||||
const expiryParts = $derived(parseExpiryParts(newCardExpiry));
|
||||
|
||||
let isExpiryInPast = $derived(
|
||||
const isExpiryInPast = $derived(
|
||||
expiryParts !== null &&
|
||||
(() => {
|
||||
const expiryDate = new SvelteDate(expiryParts.year, expiryParts.month);
|
||||
@@ -150,7 +150,7 @@
|
||||
})()
|
||||
);
|
||||
|
||||
let hasInvalidMonth = $derived(/^\d{2}\/\d{2}$/.test(newCardExpiry) && expiryParts === null);
|
||||
const hasInvalidMonth = $derived(/^\d{2}\/\d{2}$/.test(newCardExpiry) && expiryParts === null);
|
||||
|
||||
function isValidLuhn(cardNumber: string): boolean {
|
||||
const s = cardNumber.replace(/\D/g, '');
|
||||
@@ -168,17 +168,17 @@
|
||||
return sum % 10 === 0 && s.length >= 13 && s.length <= 19;
|
||||
}
|
||||
|
||||
let cardFormValid = $derived(
|
||||
const cardFormValid = $derived(
|
||||
isValidLuhn(newCardNumber) && expiryParts !== null && newCardCVC.length >= 3 && !isExpiryInPast
|
||||
);
|
||||
|
||||
let cardSelected = $derived(
|
||||
const cardSelected = $derived(
|
||||
(selectedPaymentMethod !== null && paymentMethods.length > 0) ||
|
||||
(showNewCardForm && cardFormValid) ||
|
||||
(paymentMethods.length === 0 && cardFormValid)
|
||||
);
|
||||
|
||||
let cardValidationError = $derived(
|
||||
const cardValidationError = $derived(
|
||||
!cardSelected
|
||||
? selectedPaymentMethod === null && paymentMethods.length > 0 && !showNewCardForm
|
||||
? 'Please select a card'
|
||||
@@ -211,12 +211,12 @@
|
||||
} | null>(null);
|
||||
|
||||
// Derived values
|
||||
let depositOutstanding = $derived(booking.deposit_required && !booking.deposit_paid);
|
||||
const depositOutstanding = $derived(booking.deposit_required && !booking.deposit_paid);
|
||||
|
||||
// Auto-select a sensible default payment type based on the booking's deposit
|
||||
// state. The backend will split the charge into deposit + non-deposit records
|
||||
// when appropriate, so this choice mainly controls the button label and amount.
|
||||
let defaultType = $derived(defaultPaymentType ?? (depositOutstanding ? 'deposit' : 'full'));
|
||||
const defaultType = $derived(defaultPaymentType ?? (depositOutstanding ? 'deposit' : 'full'));
|
||||
let paymentType = $state<'full' | 'partial' | 'deposit'>('full');
|
||||
$effect(() => {
|
||||
paymentType = defaultType as 'full' | 'partial' | 'deposit';
|
||||
@@ -230,35 +230,35 @@
|
||||
let lockInterval: ReturnType<typeof setInterval> | null = null;
|
||||
let countdownInterval: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
let servicesSubtotal = $derived(
|
||||
const servicesSubtotal = $derived(
|
||||
(booking.services ?? []).reduce((sum, s) => sum + (s.price || 0), 0)
|
||||
);
|
||||
let discountSum = $derived(
|
||||
const discountSum = $derived(
|
||||
(booking.discounts ?? []).reduce((sum, d) => sum + d.discount_amount, 0)
|
||||
);
|
||||
|
||||
let totalPaid = $derived(
|
||||
const totalPaid = $derived(
|
||||
booking.payments
|
||||
?.filter((p) => p.status === 'completed')
|
||||
.reduce((sum, p) => sum + p.amount, 0) || 0
|
||||
);
|
||||
|
||||
let amountRemaining = $derived(booking.total_amount - totalPaid);
|
||||
const amountRemaining = $derived(booking.total_amount - totalPaid);
|
||||
|
||||
let loyaltyEligible = $derived(
|
||||
const loyaltyEligible = $derived(
|
||||
stamps >= 10 &&
|
||||
!(booking.discounts ?? []).some((d) => d.discount_source === 'loyalty') &&
|
||||
booking.total_amount > 0 &&
|
||||
booking.amount_paid === 0
|
||||
);
|
||||
|
||||
let loyaltyDiscount = $derived(
|
||||
const loyaltyDiscount = $derived(
|
||||
useLoyalty ? Math.round(booking.total_amount * 100 * LOYALTY_DISCOUNT_RATE) : 0
|
||||
);
|
||||
|
||||
// Deposit policy warning text — dynamic based on booking state
|
||||
let expectedDepositPercent = $derived(booking.deposit_required ? 20 : 0);
|
||||
let depositPolicyWarning = $derived<string | null>(
|
||||
const expectedDepositPercent = $derived(booking.deposit_required ? 20 : 0);
|
||||
const depositPolicyWarning = $derived<string | null>(
|
||||
{
|
||||
get text(): string | null {
|
||||
if (!booking.deposit_required && totalPaid === 0 && booking.amount_due <= 0) return null;
|
||||
@@ -273,12 +273,12 @@
|
||||
}.text
|
||||
);
|
||||
|
||||
let isScenarioA = $derived(depositOutstanding);
|
||||
const isScenarioA = $derived(depositOutstanding);
|
||||
|
||||
let isScenarioB = $derived(!depositOutstanding && totalPaid < booking.total_amount);
|
||||
const isScenarioB = $derived(!depositOutstanding && totalPaid < booking.total_amount);
|
||||
|
||||
let partialAmountNum = $derived(partialAmount === '' ? 0 : parseFloat(partialAmount));
|
||||
let partialAmountValid = $derived(
|
||||
const partialAmountNum = $derived(partialAmount === '' ? 0 : parseFloat(partialAmount));
|
||||
const partialAmountValid = $derived(
|
||||
paymentType === 'partial' &&
|
||||
partialAmount !== '' &&
|
||||
!isNaN(partialAmountNum) &&
|
||||
@@ -287,7 +287,7 @@
|
||||
/^\d+(\.\d{0,2})?$/.test(partialAmount)
|
||||
);
|
||||
|
||||
let partialValidationError = $derived(
|
||||
const partialValidationError = $derived(
|
||||
paymentType === 'partial' && !partialAmountValid
|
||||
? partialAmount === ''
|
||||
? 'Enter an amount'
|
||||
@@ -301,14 +301,14 @@
|
||||
: null
|
||||
);
|
||||
|
||||
let payButtonDisabled = $derived(
|
||||
const payButtonDisabled = $derived(
|
||||
status === 'processing' ||
|
||||
!cardSelected ||
|
||||
(paymentType === 'partial' && !partialAmountValid) ||
|
||||
(booking.status === 'pending_release' && (lockTimer <= 0 || !lockAcquired))
|
||||
);
|
||||
|
||||
let payButtonError = $derived(
|
||||
const payButtonError = $derived(
|
||||
status === 'processing'
|
||||
? null
|
||||
: !cardSelected
|
||||
|
||||
Reference in New Issue
Block a user