style: fix no-unused-vars -- prefix unused catch bindings, remove dead code, suppress template-use false positives
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
import { Textarea } from '$lib/components/ui/textarea/index.js';
|
||||
import CharCounter from '$lib/components/ui/CharCounter.svelte';
|
||||
import { Separator } from '$lib/components/ui/separator/index.js';
|
||||
import { Checkbox } from '$lib/components/ui/checkbox/index.js';
|
||||
import { PhoneInput } from '$lib/components/ui/phone-input/index.js';
|
||||
import { isValidUKPhone, toE164UK } from '$lib/utils/phone';
|
||||
// INTENTIONAL: We use the browser's local timezone (getLocalTimeZone) because Crussell is a UK-only
|
||||
@@ -26,7 +25,6 @@
|
||||
import { ensureBusinessInfo, getBusinessInfo } from '$lib/stores/businessInfo.svelte';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { SvelteDate } from 'svelte/reactivity';
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
// Components
|
||||
import BookingActions from '$lib/components/booking/BookingActions.svelte';
|
||||
@@ -42,7 +40,6 @@
|
||||
import {
|
||||
extractBookedSlots,
|
||||
getLunchProtectionForSlots,
|
||||
type TimeSlot
|
||||
} from '$lib/lunchProtection';
|
||||
import { formatLocalDateTime, getLondonTodayCalendarDate } from '$lib/utils/timeSlots';
|
||||
|
||||
@@ -79,13 +76,13 @@
|
||||
phone: '',
|
||||
specialRequests: ''
|
||||
});
|
||||
let isSubmitting = $state(false);
|
||||
let _isSubmitting = $state(false);
|
||||
let idempotencyKey = $state<string>('');
|
||||
|
||||
// =============== Payment State ===============
|
||||
let userDepositsRequired = $state<number>(0);
|
||||
let hasActiveBooking = $state<boolean>(false);
|
||||
let activeBookingCheckDone = $state<boolean>(false);
|
||||
let _activeBookingCheckDone = $state<boolean>(false);
|
||||
let paymentMethods = $state<
|
||||
Array<{ id: string; brand: string; last4: string; expiry_month: number; expiry_year: number }>
|
||||
>([]);
|
||||
@@ -98,11 +95,11 @@
|
||||
let newCardNumber = $state('');
|
||||
let newCardExpiry = $state('');
|
||||
let newCardCVC = $state('');
|
||||
const saveCardForFuture = $state(false);
|
||||
const _saveCardForFuture = $state(false);
|
||||
|
||||
// Payment flow state
|
||||
let depositPaid = $state(false);
|
||||
let showPaymentForm = $state(false);
|
||||
let _showPaymentForm = $state(false);
|
||||
|
||||
const depositCardFormValid = $derived(
|
||||
selectedPaymentMethod !== null ||
|
||||
@@ -213,7 +210,7 @@
|
||||
const user = await response.json();
|
||||
userDepositsRequired = user.deposits_required ?? 0;
|
||||
}
|
||||
} catch (err) {
|
||||
} catch (_err) {
|
||||
userDepositsRequired = 0;
|
||||
}
|
||||
}
|
||||
@@ -221,11 +218,11 @@
|
||||
async function fetchActiveBookingStatus() {
|
||||
if (!authStore.isAuthenticated) {
|
||||
hasActiveBooking = false;
|
||||
activeBookingCheckDone = true;
|
||||
_activeBookingCheckDone = true;
|
||||
return;
|
||||
}
|
||||
|
||||
activeBookingCheckDone = false;
|
||||
_activeBookingCheckDone = false;
|
||||
try {
|
||||
// Check for pending bookings
|
||||
const pendingResp = await fetch('/api/bookings?status=pending&perPage=1', {
|
||||
@@ -235,7 +232,7 @@
|
||||
const data = await pendingResp.json();
|
||||
if (data.bookings && data.bookings.length > 0) {
|
||||
hasActiveBooking = true;
|
||||
activeBookingCheckDone = true;
|
||||
_activeBookingCheckDone = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -248,42 +245,13 @@
|
||||
const data = await confirmedResp.json();
|
||||
hasActiveBooking = data.bookings && data.bookings.length > 0;
|
||||
}
|
||||
} catch (err) {
|
||||
} catch (_err) {
|
||||
hasActiveBooking = false;
|
||||
} finally {
|
||||
activeBookingCheckDone = true;
|
||||
_activeBookingCheckDone = true;
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchPaymentMethods() {
|
||||
if (!authStore.isAuthenticated) {
|
||||
paymentMethods = [];
|
||||
return;
|
||||
}
|
||||
|
||||
paymentMethodsLoading = true;
|
||||
try {
|
||||
const response = await fetch('/api/user/payment-methods', {
|
||||
headers: authStore.currentToken ? { Authorization: `Bearer ${authStore.currentToken}` } : {}
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
paymentMethods = data.payment_methods ?? [];
|
||||
if (paymentMethods.length > 0 && !selectedPaymentMethod) {
|
||||
const defaultCard =
|
||||
paymentMethods.find((m) => 'is_default' in m && m.is_default) ?? paymentMethods[0];
|
||||
selectedPaymentMethod = defaultCard.id;
|
||||
}
|
||||
} else {
|
||||
paymentMethods = [];
|
||||
}
|
||||
} catch (err) {
|
||||
paymentMethods = [];
|
||||
} finally {
|
||||
paymentMethodsLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function calculateDepositRequired(): boolean {
|
||||
if (!selectedDate || !selectedTime) return false;
|
||||
@@ -311,7 +279,7 @@
|
||||
discountPreview = data;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
} catch (_err) {
|
||||
console.error('Failed to fetch discount preview:', err);
|
||||
}
|
||||
}
|
||||
@@ -364,7 +332,7 @@
|
||||
const text = await response.text();
|
||||
toast.warning(text || 'Payment failed — you can pay again from your booking details.');
|
||||
}
|
||||
} catch (err) {
|
||||
} catch (_err) {
|
||||
toast.error(
|
||||
'An error occurred. Your booking may still be confirmed — check your appointments.'
|
||||
);
|
||||
@@ -375,35 +343,14 @@
|
||||
|
||||
let paymentAttempted = $state(false);
|
||||
|
||||
function handlePayNow() {
|
||||
showPaymentForm = true;
|
||||
if (authStore.isAuthenticated) {
|
||||
fetchPaymentMethods();
|
||||
}
|
||||
}
|
||||
|
||||
function handleSkipPayment() {
|
||||
depositPaid = false;
|
||||
nextStep();
|
||||
}
|
||||
|
||||
|
||||
function formatCardExpiry(month: number, year: number): string {
|
||||
return `${String(month).padStart(2, '0')}/${year.toString().slice(-2)}`;
|
||||
}
|
||||
|
||||
function formatDepositCardNumber(value: string): string {
|
||||
const digits = value.replace(/\D/g, '').substring(0, 16);
|
||||
const groups = digits.match(/.{1,4}/g);
|
||||
return groups ? groups.join(' ') : digits;
|
||||
}
|
||||
|
||||
function formatDepositExpiry(value: string): string {
|
||||
const digits = value.replace(/\D/g, '').substring(0, 4);
|
||||
if (digits.length >= 3) {
|
||||
return digits.substring(0, 2) + '/' + digits.substring(2);
|
||||
}
|
||||
return digits;
|
||||
}
|
||||
|
||||
// Fetch user deposit and active booking status when step 1 is reached
|
||||
$effect(() => {
|
||||
@@ -414,15 +361,15 @@
|
||||
});
|
||||
|
||||
// =============== Slot Reservation System ===============
|
||||
let reservationId = $state<string | null>(null);
|
||||
let _reservationId = $state<string | null>(null);
|
||||
let reservationExpiresAt = $state<Date | null>(null);
|
||||
let reservationCountdown = $state<string>('');
|
||||
let reservationExpired = $state(false);
|
||||
let isReserving = $state(false);
|
||||
let _isReserving = $state(false);
|
||||
|
||||
// =============== Slot Reservation Functions ===============
|
||||
async function reserveSlot() {
|
||||
isReserving = true;
|
||||
_isReserving = true;
|
||||
try {
|
||||
if (!selectedDate || !selectedTime) {
|
||||
toast.error('Please select a date and time');
|
||||
@@ -442,7 +389,7 @@
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
const _errorText = await response.text();
|
||||
if (response.status === 429) {
|
||||
toast.error('Too many active reservations. Please wait or log in.');
|
||||
} else if (response.status === 409) {
|
||||
@@ -455,16 +402,16 @@
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
reservationId = data.id;
|
||||
_reservationId = data.id;
|
||||
reservationExpiresAt = new Date(data.expires_at);
|
||||
reservationExpired = false;
|
||||
startCountdown();
|
||||
return true;
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
toast.error('Network error while reserving slot.');
|
||||
return false;
|
||||
} finally {
|
||||
isReserving = false;
|
||||
_isReserving = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,7 +430,7 @@
|
||||
if (diff <= 0) {
|
||||
reservationCountdown = '00:00';
|
||||
reservationExpired = true;
|
||||
reservationId = null;
|
||||
_reservationId = null;
|
||||
reservationExpiresAt = null;
|
||||
toast.error('Your reservation has expired. Please select a new time slot.');
|
||||
return;
|
||||
@@ -550,7 +497,7 @@
|
||||
} else {
|
||||
toast.error('Failed to load services');
|
||||
}
|
||||
} catch (err) {
|
||||
} catch (_err) {
|
||||
toast.error('Network error loading services');
|
||||
} finally {
|
||||
servicesLoading = false;
|
||||
@@ -760,7 +707,7 @@
|
||||
// MERGE instead of replace — preserves data from previously loaded months
|
||||
workingHours = { ...workingHours, ...whMap };
|
||||
availableHours = { ...availableHours, ...ahMap };
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
// Clean up loadingMonths for the range
|
||||
for (let i = 0; i < months; i++) {
|
||||
let mYear = startDate.year;
|
||||
@@ -860,7 +807,7 @@
|
||||
|
||||
availableHoursCache[monthKey] = availableHoursMap;
|
||||
availableHours = { ...availableHours, ...availableHoursMap };
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
if (!selectedDate) {
|
||||
selectedDate = minDate;
|
||||
}
|
||||
@@ -1362,7 +1309,7 @@
|
||||
}
|
||||
|
||||
async function submitAndProceed() {
|
||||
isSubmitting = true;
|
||||
_isSubmitting = true;
|
||||
try {
|
||||
if (!idempotencyKey) {
|
||||
// Generate UUID v4 manually for environments where crypto.randomUUID() is unavailable
|
||||
@@ -1385,7 +1332,7 @@
|
||||
|
||||
if (!selectedDate || !selectedTime) {
|
||||
toast.error('Please select a date and time');
|
||||
isSubmitting = false;
|
||||
_isSubmitting = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1410,13 +1357,13 @@
|
||||
});
|
||||
|
||||
if (!guestResponse.ok) {
|
||||
const errorText = await guestResponse.text();
|
||||
const _errorText = await guestResponse.text();
|
||||
if (guestResponse.status === 409) {
|
||||
toast.error('Email already registered — please log in to book.');
|
||||
} else {
|
||||
toast.error('Failed to create guest account. Please try again.');
|
||||
}
|
||||
isSubmitting = false;
|
||||
_isSubmitting = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1507,10 +1454,10 @@
|
||||
toast.error('Failed to submit booking: ' + errorMessage);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
toast.error('Network error. Please check your connection and try again.');
|
||||
} finally {
|
||||
isSubmitting = false;
|
||||
_isSubmitting = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1550,7 +1497,7 @@
|
||||
)) &&
|
||||
!reservationExpired
|
||||
);
|
||||
const canProceedStep4 = $derived(true);
|
||||
const _canProceedStep4 = $derived(true);
|
||||
</script>
|
||||
|
||||
<div class="mx-auto max-w-4xl p-6">
|
||||
|
||||
Reference in New Issue
Block a user