fix: booking duration calculation, tip page auth, and UI polish across frontend
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -5,10 +5,11 @@
|
||||
import { toast } from 'svelte-sonner';
|
||||
import * as Modal from '$lib/components/ui/dialog';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import * as Textarea from '$lib/components/ui/textarea';
|
||||
import * as Label from '$lib/components/ui/label';
|
||||
import DatePicker from '$lib/components/booking/DatePicker.svelte';
|
||||
import PaymentModal from '$lib/components/payments/PaymentModal.svelte';
|
||||
import UserPaymentModal from '$lib/components/payments/UserPaymentModal.svelte';
|
||||
import type { Booking, WorkingHoursDay, AvailableHoursDay } from '$lib/types/booking';
|
||||
import { extractBookedSlots, getLunchProtectionForSlots } from '$lib/lunchProtection';
|
||||
|
||||
@@ -42,8 +43,10 @@
|
||||
const maxCalendarDate = new CalendarDate(maxDate.getFullYear(), maxDate.getMonth() + 1, maxDate.getDate());
|
||||
let reschedulePlaceholder = $state<CalendarDate>(minDate);
|
||||
|
||||
// IMPORTANT: Use override_duration_minutes when present — services may have been
|
||||
// customised at booking time. Showing base values misleads users about what was booked.
|
||||
let totalDuration = $derived(
|
||||
selectedBooking?.services?.reduce((sum, service) => sum + (service.duration_minutes || 0), 0) || 0
|
||||
selectedBooking?.services?.reduce((sum, service) => sum + (service.override_duration_minutes ?? service.duration_minutes ?? 0), 0) || 0
|
||||
);
|
||||
|
||||
const rescheduleLunchProtection = $derived(() => {
|
||||
@@ -106,8 +109,85 @@
|
||||
['confirmed', 'pending'].includes(selectedBooking.status)
|
||||
);
|
||||
|
||||
let isCompleted = $derived(selectedBooking?.status === 'completed');
|
||||
|
||||
let showPaymentModal = $state(false);
|
||||
|
||||
let showTipModal = $state(false);
|
||||
let tipAmount = $state<number>(0);
|
||||
let selectedTipPreset = $state<number | null>(null);
|
||||
let customTipInput = $state('');
|
||||
let tipProcessing = $state(false);
|
||||
|
||||
let canSaveCards = $derived(
|
||||
authStore.currentUser?.role === 'verified_email' ||
|
||||
authStore.currentUser?.role === 'affiliate'
|
||||
);
|
||||
|
||||
let tipPresets = $derived(selectedBooking ? [
|
||||
{ pct: 10, amount: Math.round(selectedBooking.total_amount * 0.10 * 100) / 100 },
|
||||
{ pct: 15, amount: Math.round(selectedBooking.total_amount * 0.15 * 100) / 100 },
|
||||
{ pct: 20, amount: Math.round(selectedBooking.total_amount * 0.20 * 100) / 100 }
|
||||
] : []);
|
||||
|
||||
function selectTipPreset(amount: number) {
|
||||
selectedTipPreset = amount;
|
||||
customTipInput = '';
|
||||
tipAmount = amount;
|
||||
}
|
||||
|
||||
function handleCustomTip(e: Event) {
|
||||
const input = e.target as HTMLInputElement;
|
||||
const cleaned = input.value.replace(/[^0-9.]/g, '');
|
||||
const firstDot = cleaned.indexOf('.');
|
||||
let sanitized: string;
|
||||
if (firstDot !== -1) {
|
||||
const integerPart = cleaned.substring(0, firstDot);
|
||||
const decimalPart = cleaned.substring(firstDot + 1).replace(/\./g, '');
|
||||
sanitized = integerPart + '.' + decimalPart;
|
||||
} else {
|
||||
sanitized = cleaned;
|
||||
}
|
||||
if (/^\d+(\.\d{0,2})?$/.test(sanitized) || sanitized === '') {
|
||||
customTipInput = sanitized;
|
||||
}
|
||||
selectedTipPreset = null;
|
||||
tipAmount = parseFloat(customTipInput) || 0;
|
||||
}
|
||||
|
||||
async function submitTip() {
|
||||
if (!selectedBooking) return;
|
||||
if (tipAmount <= 0) {
|
||||
toast.error('Please select a tip amount');
|
||||
return;
|
||||
}
|
||||
tipProcessing = true;
|
||||
try {
|
||||
const response = await fetch(`/api/bookings/${selectedBooking.id}/tip`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${authStore.currentToken}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
amount: Math.round(tipAmount * 100),
|
||||
card_token: 'placeholder'
|
||||
})
|
||||
});
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
throw new Error(errorText || 'Tip payment failed');
|
||||
}
|
||||
toast.success('Thank you for your tip!');
|
||||
showTipModal = false;
|
||||
fetchBookingDetails();
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : 'Tip payment failed');
|
||||
} finally {
|
||||
tipProcessing = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handlePaymentComplete() {
|
||||
toast.success('Payment completed');
|
||||
showPaymentModal = false;
|
||||
@@ -244,6 +324,23 @@
|
||||
return slots.length === 0;
|
||||
}
|
||||
|
||||
function formatPaymentMethod(method: string): string {
|
||||
switch (method) {
|
||||
case 'in_person_card':
|
||||
return 'Card, In-person';
|
||||
case 'online_square':
|
||||
return 'Card, Online';
|
||||
case 'cash':
|
||||
return 'Cash';
|
||||
case 'giftcard':
|
||||
return 'Gift Card';
|
||||
case 'discount':
|
||||
return 'Discount';
|
||||
default:
|
||||
return method.replace(/_/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
function formatTime(time: string): string {
|
||||
const parts = time.split(':').map(Number);
|
||||
const hours = parts[0];
|
||||
@@ -587,8 +684,8 @@
|
||||
<div class="mt-1 text-sm text-gray-600">{service.service_description}</div>
|
||||
{/if}
|
||||
<div class="mt-2 flex items-center justify-between text-sm">
|
||||
<span class="text-gray-600">{service.duration_minutes} min</span>
|
||||
<span class="font-semibold">£{service.price?.toFixed(2) || '0.00'}</span>
|
||||
<span class="text-gray-600">{service.override_duration_minutes ?? service.duration_minutes} min</span>
|
||||
<span class="font-semibold">£{(service.override_price ?? service.price ?? 0).toFixed(2)}</span>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
@@ -634,7 +731,7 @@
|
||||
{/if}
|
||||
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm text-gray-600">Total Amount</span>
|
||||
<span class="text-sm text-gray-600">{selectedBooking.amount_paid > selectedBooking.total_amount ? 'Pre-tip Subtotal' : 'Total Amount'}</span>
|
||||
<span class="font-semibold">£{selectedBooking.total_amount.toFixed(2)}</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
@@ -643,18 +740,18 @@
|
||||
>£{selectedBooking.amount_paid.toFixed(2)}</span
|
||||
>
|
||||
</div>
|
||||
<div class="flex items-center justify-between border-t border-gray-300 pt-2">
|
||||
<span class="font-medium text-gray-900">
|
||||
{isFutureBooking ? 'Estimated Subtotal' : 'Amount Due'}
|
||||
</span>
|
||||
<span
|
||||
class="text-lg font-bold {selectedBooking.amount_due > 0
|
||||
? 'text-red-600'
|
||||
: 'text-green-600'}"
|
||||
>
|
||||
£{selectedBooking.amount_due.toFixed(2)}
|
||||
</span>
|
||||
</div>
|
||||
{#if selectedBooking.amount_due > 0}
|
||||
<div class="flex items-center justify-between border-t border-gray-300 pt-2">
|
||||
<span class="font-medium text-gray-900">
|
||||
{isFutureBooking ? 'Estimated Subtotal' : 'Amount Due'}
|
||||
</span>
|
||||
<span
|
||||
class="text-lg font-bold text-red-600"
|
||||
>
|
||||
£{selectedBooking.amount_due.toFixed(2)}
|
||||
</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -669,9 +766,7 @@
|
||||
<div class="flex items-start justify-between">
|
||||
<div class="flex-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="font-medium capitalize"
|
||||
>{payment.payment_method.replace('_', ' ')}</span
|
||||
>
|
||||
<span class="font-medium">{formatPaymentMethod(payment.payment_method)}</span>
|
||||
<span
|
||||
class="inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium
|
||||
{payment.status === 'completed'
|
||||
@@ -685,7 +780,10 @@
|
||||
</div>
|
||||
<div class="mt-1 text-xs text-gray-500">
|
||||
{payment.payment_type.charAt(0).toUpperCase() +
|
||||
payment.payment_type.slice(1)}
|
||||
payment.payment_type.slice(1)} payment
|
||||
{#if payment.card_last4}
|
||||
, Card ending in {payment.card_last4}
|
||||
{/if}
|
||||
</div>
|
||||
{#if payment.is_vat_applicable}
|
||||
<div class="mt-2 text-xs text-gray-600">
|
||||
@@ -853,18 +951,14 @@
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
{#if selectedBooking}
|
||||
{#if isCompleted}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="flex-1"
|
||||
onclick={() => {
|
||||
if (selectedBooking) {
|
||||
window.open(`/api/bookings/${selectedBooking.id}/calendar`, '_blank');
|
||||
}
|
||||
}}
|
||||
class="flex-1 hover:bg-fuchsia-50"
|
||||
variant="outline"
|
||||
onclick={() => (showTipModal = true)}
|
||||
>
|
||||
Add to Calendar
|
||||
Leave a Tip
|
||||
</Button>
|
||||
{/if}
|
||||
{#if depositOutstanding}
|
||||
@@ -891,10 +985,11 @@
|
||||
</Modal.Root>
|
||||
|
||||
{#if showPaymentModal && selectedBooking}
|
||||
<PaymentModal
|
||||
<UserPaymentModal
|
||||
booking={selectedBooking}
|
||||
onClose={() => (showPaymentModal = false)}
|
||||
onComplete={handlePaymentComplete}
|
||||
canSaveCards={canSaveCards}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
@@ -925,3 +1020,66 @@
|
||||
</Modal.Footer>
|
||||
</Modal.Content>
|
||||
</Modal.Root>
|
||||
|
||||
<Modal.Root open={showTipModal} onOpenChange={(v) => {
|
||||
if (!v) {
|
||||
showTipModal = false;
|
||||
tipAmount = 0;
|
||||
selectedTipPreset = null;
|
||||
customTipInput = '';
|
||||
}
|
||||
}}>
|
||||
<Modal.Content class="max-w-sm">
|
||||
<Modal.Header>
|
||||
<Modal.Title>Leave a Tip</Modal.Title>
|
||||
<Modal.Description>Show your appreciation for great service</Modal.Description>
|
||||
</Modal.Header>
|
||||
|
||||
<div class="px-4 pb-4 space-y-4">
|
||||
<div class="grid grid-cols-3 gap-3">
|
||||
{#each tipPresets as preset (preset.pct)}
|
||||
<button
|
||||
class="rounded-lg border border-input bg-background py-3 text-center font-semibold transition-colors hover:bg-fuchsia-50 {selectedTipPreset === preset.amount ? 'bg-fuchsia-100' : ''}"
|
||||
onclick={() => selectTipPreset(preset.amount)}
|
||||
type="button"
|
||||
>
|
||||
<div>£{preset.amount.toFixed(2)}</div>
|
||||
<div class="text-xs font-normal text-gray-500">{preset.pct}%</div>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="custom-tip" class="text-sm font-medium text-gray-700">Or enter custom amount</label>
|
||||
<div class="relative mt-1">
|
||||
<span class="absolute left-3 top-1/2 -translate-y-1/2 text-gray-500">£</span>
|
||||
<Input
|
||||
id="custom-tip"
|
||||
type="text"
|
||||
inputmode="decimal"
|
||||
step="0.01"
|
||||
min="0"
|
||||
placeholder="0.00"
|
||||
class="pl-7"
|
||||
value={customTipInput}
|
||||
oninput={handleCustomTip}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Modal.Footer>
|
||||
<Button variant="outline" onclick={() => (showTipModal = false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
class="hover:bg-fuchsia-50"
|
||||
onclick={submitTip}
|
||||
disabled={tipAmount <= 0 || tipProcessing}
|
||||
loading={tipProcessing}
|
||||
>
|
||||
{tipProcessing ? 'Processing...' : `Pay Tip £${tipAmount.toFixed(2)}`}
|
||||
</Button>
|
||||
</Modal.Footer>
|
||||
</Modal.Content>
|
||||
</Modal.Root>
|
||||
|
||||
@@ -18,8 +18,11 @@
|
||||
let showApprovalModal = $state(false);
|
||||
|
||||
// Calculate total duration from services
|
||||
// IMPORTANT: Use override_duration_minutes when present — services may have been
|
||||
// customised at booking time (discounts, extended sessions). Showing base values
|
||||
// misleads admins about what was actually booked.
|
||||
let totalDuration = $derived(
|
||||
selectedBooking?.services?.reduce((sum, service) => sum + (service.duration_minutes || 0), 0) ||
|
||||
selectedBooking?.services?.reduce((sum, service) => sum + (service.override_duration_minutes ?? service.duration_minutes ?? 0), 0) ||
|
||||
0
|
||||
);
|
||||
|
||||
@@ -278,8 +281,8 @@
|
||||
<div class="mt-1 text-sm text-gray-600">{service.service_description}</div>
|
||||
{/if}
|
||||
<div class="mt-2 flex items-center justify-between text-sm">
|
||||
<span class="text-gray-600">{service.duration_minutes} min</span>
|
||||
<span class="font-semibold">£{service.price?.toFixed(2) || '0.00'}</span>
|
||||
<span class="text-gray-600">{service.override_duration_minutes ?? service.duration_minutes} min</span>
|
||||
<span class="font-semibold">£{(service.override_price ?? service.price ?? 0).toFixed(2)}</span>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
@@ -410,9 +413,15 @@
|
||||
<div class="flex items-start justify-between">
|
||||
<div class="flex-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="font-medium capitalize"
|
||||
>{payment.payment_method.replace('_', ' ')}</span
|
||||
>
|
||||
<span class="font-medium">
|
||||
{#if payment.payment_method === 'online_square'}Online
|
||||
{:else if payment.payment_method === 'in_person_card'}Card Machine
|
||||
{:else if payment.payment_method === 'cash'}Cash
|
||||
{:else if payment.payment_method === 'giftcard'}Gift Card
|
||||
{:else if payment.payment_method === 'discount'}Discount
|
||||
{:else}{payment.payment_method.replace('_', ' ')}
|
||||
{/if}
|
||||
</span>
|
||||
<span
|
||||
class="inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium
|
||||
{payment.status === 'completed'
|
||||
@@ -428,7 +437,10 @@
|
||||
</div>
|
||||
<div class="mt-1 text-xs text-gray-500">
|
||||
{payment.payment_type.charAt(0).toUpperCase() +
|
||||
payment.payment_type.slice(1)}
|
||||
payment.payment_type.slice(1)} payment
|
||||
{#if payment.card_last4}
|
||||
, Card ending in {payment.card_last4}
|
||||
{/if}
|
||||
</div>
|
||||
{#if payment.vendor_code || payment.invoice_number}
|
||||
<div class="mt-1 text-xs text-gray-500">
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import * as Card from '$lib/components/ui/card';
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { Checkbox } from '$lib/components/ui/checkbox';
|
||||
import { Separator } from '$lib/components/ui/separator';
|
||||
import * as Modal from '$lib/components/ui/dialog';
|
||||
import * as AlertDialog from '$lib/components/ui/alert-dialog';
|
||||
@@ -523,11 +524,7 @@
|
||||
<tr class="border-t">
|
||||
<td class="py-2">{weekdayLabel(row.weekday)}</td>
|
||||
<td class="py-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked={row.is_open}
|
||||
class="h-4 w-4 rounded border-gray-300 bg-gray-100"
|
||||
/>
|
||||
<Checkbox bind:checked={row.is_open} />
|
||||
</td>
|
||||
<td class="py-2">
|
||||
<Input
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import * as Card from '$lib/components/ui/card';
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { Checkbox } from '$lib/components/ui/checkbox';
|
||||
import * as Modal from '$lib/components/ui/dialog';
|
||||
import * as AlertDialog from '$lib/components/ui/alert-dialog';
|
||||
import { Skeleton } from '$lib/components/ui/skeleton';
|
||||
@@ -475,11 +476,7 @@
|
||||
<tr class="border-t">
|
||||
<td class="py-2 text-sm">{weekdayLabel(row.weekday)}</td>
|
||||
<td class="py-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked={row.is_open}
|
||||
class="h-4 w-4 rounded border-gray-300 bg-gray-100 text-primary focus:ring-primary"
|
||||
/>
|
||||
<Checkbox bind:checked={row.is_open} />
|
||||
</td>
|
||||
<td class="py-2">
|
||||
<Input
|
||||
|
||||
@@ -13,7 +13,11 @@
|
||||
</script>
|
||||
|
||||
<div class="flex justify-between">
|
||||
<Button variant="outline" disabled={!canBack} onclick={() => dispatch('back')}>Back</Button>
|
||||
{#if canBack}
|
||||
<Button variant="outline" onclick={() => dispatch('back')}>Back</Button>
|
||||
{:else}
|
||||
<div></div>
|
||||
{/if}
|
||||
|
||||
{#if showSubmit}
|
||||
<Button
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
import DatePicker from '$lib/components/booking/DatePicker.svelte';
|
||||
import TimeSlotPicker from '$lib/components/booking/TimeSlotPicker.svelte';
|
||||
import ServiceSelector from '$lib/components/booking/ServiceSelector.svelte';
|
||||
import UserPaymentModal from '$lib/components/payments/UserPaymentModal.svelte';
|
||||
import {
|
||||
extractBookedSlots,
|
||||
getLunchProtectionForSlots,
|
||||
@@ -33,7 +34,9 @@
|
||||
Service,
|
||||
CustomerInfo,
|
||||
WorkingHoursDay,
|
||||
AvailableHoursDay
|
||||
AvailableHoursDay,
|
||||
BookingService,
|
||||
BookingStatus
|
||||
} from '$lib/types/booking';
|
||||
|
||||
// =============== State Management ===============
|
||||
@@ -73,6 +76,11 @@
|
||||
let depositPaid = $state(false);
|
||||
let showPaymentForm = $state(false);
|
||||
|
||||
let depositCardFormValid = $derived(
|
||||
selectedPaymentMethod !== null ||
|
||||
(showNewCardForm && newCardNumber.replace(/\s/g, '').length >= 13 && /^\d{2}\/\d{2}$/.test(newCardExpiry) && newCardCVC.length >= 3)
|
||||
);
|
||||
|
||||
// Confirmation state
|
||||
let confirmedBooking = $state<{
|
||||
id: string;
|
||||
@@ -81,6 +89,8 @@
|
||||
notes: string;
|
||||
} | null>(null);
|
||||
|
||||
let showPayEarlyModal = $state(false);
|
||||
|
||||
// =============== Payment Functions ===============
|
||||
async function fetchUserDepositsRequired() {
|
||||
if (!authStore.isAuthenticated) {
|
||||
@@ -90,7 +100,6 @@
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/user', {
|
||||
credentials: 'include',
|
||||
headers: authStore.currentToken ? { Authorization: `Bearer ${authStore.currentToken}` } : {}
|
||||
});
|
||||
if (response.ok) {
|
||||
@@ -114,7 +123,6 @@
|
||||
try {
|
||||
// Check for pending bookings
|
||||
const pendingResp = await fetch('/api/bookings?status=pending&perPage=1', {
|
||||
credentials: 'include',
|
||||
headers: authStore.currentToken ? { Authorization: `Bearer ${authStore.currentToken}` } : {}
|
||||
});
|
||||
if (pendingResp.ok) {
|
||||
@@ -128,7 +136,6 @@
|
||||
|
||||
// Check for confirmed bookings
|
||||
const confirmedResp = await fetch('/api/bookings?status=confirmed&perPage=1', {
|
||||
credentials: 'include',
|
||||
headers: authStore.currentToken ? { Authorization: `Bearer ${authStore.currentToken}` } : {}
|
||||
});
|
||||
if (confirmedResp.ok) {
|
||||
@@ -152,13 +159,16 @@
|
||||
paymentMethodsLoading = true;
|
||||
try {
|
||||
const response = await fetch('/api/user/payment-methods', {
|
||||
credentials: 'include',
|
||||
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: any) => m.is_default) ?? paymentMethods[0];
|
||||
selectedPaymentMethod = defaultCard.id;
|
||||
}
|
||||
} else {
|
||||
paymentMethods = [];
|
||||
}
|
||||
@@ -222,6 +232,20 @@
|
||||
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(() => {
|
||||
if (currentStep === 1 && authStore.isAuthenticated) {
|
||||
@@ -945,6 +969,14 @@
|
||||
selectedDate ? getDayWithOrdinal(selectedDate) : undefined
|
||||
);
|
||||
|
||||
let depositRequired = $derived(calculateDepositRequired());
|
||||
let totalSteps = $derived(depositRequired ? 5 : 4);
|
||||
let stepLabels = $derived(
|
||||
depositRequired
|
||||
? ['Service', 'Date & Time', 'Details', 'Payment', 'Confirmation']
|
||||
: ['Service', 'Date & Time', 'Details', 'Confirmation']
|
||||
);
|
||||
|
||||
// =============== Navigation ===============
|
||||
async function nextStep() {
|
||||
// Step 2 -> Step 3: Re-validate slot, then reserve
|
||||
@@ -955,7 +987,7 @@
|
||||
if (!reserved) return;
|
||||
}
|
||||
|
||||
// Step 3 -> Step 4 (if deposit required) or Step 5 (submit booking)
|
||||
// Step 3 -> Step 4 (if deposit required) or Step 4 (confirmation, if no deposit)
|
||||
if (currentStep === 3) {
|
||||
if (calculateDepositRequired()) {
|
||||
currentStep = 4;
|
||||
@@ -965,13 +997,14 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 4 -> Step 5 (submit booking)
|
||||
if (currentStep === 4) {
|
||||
// Step 4: if deposit required, this is payment step -> submit booking -> step 5
|
||||
// Step 4: if no deposit, this is confirmation step -> nothing
|
||||
if (currentStep === 4 && calculateDepositRequired()) {
|
||||
await submitAndProceed();
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentStep < 5) {
|
||||
if (currentStep < (depositRequired ? 5 : 4)) {
|
||||
currentStep++;
|
||||
setTimeout(() => {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
@@ -1074,7 +1107,7 @@
|
||||
start_time: booking.start_time,
|
||||
notes: booking.notes || ''
|
||||
};
|
||||
currentStep = 5;
|
||||
currentStep = depositRequired ? 5 : 4;
|
||||
setTimeout(() => {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
}, 50);
|
||||
@@ -1163,7 +1196,7 @@
|
||||
|
||||
<StepIndicator
|
||||
{currentStep}
|
||||
steps={['Service', 'Date & Time', 'Details', 'Payment', 'Confirmation']}
|
||||
steps={stepLabels}
|
||||
/>
|
||||
|
||||
<!-- Step 1: Service Selection -->
|
||||
@@ -1459,14 +1492,20 @@
|
||||
onclick={nextStep}
|
||||
class="bg-primary text-primary-foreground"
|
||||
>
|
||||
{reservationExpired ? 'Reservation Expired' : 'Next: Review & Payment'}
|
||||
{#if reservationExpired}
|
||||
Reservation Expired
|
||||
{:else if depositRequired}
|
||||
Next: Payment
|
||||
{:else}
|
||||
Confirm Booking
|
||||
{/if}
|
||||
</Button>
|
||||
</Card.Footer>
|
||||
</Card.Root>
|
||||
{/if}
|
||||
|
||||
<!-- Step 4: Deposit Payment (only shown if deposit required) -->
|
||||
{#if currentStep === 4}
|
||||
{#if currentStep === 4 && depositRequired}
|
||||
<Card.Root>
|
||||
<Card.Header>
|
||||
<Card.Title>Pay Your Deposit</Card.Title>
|
||||
@@ -1579,7 +1618,10 @@
|
||||
<Label for="cardNumber">Card Number</Label>
|
||||
<Input
|
||||
id="cardNumber"
|
||||
bind:value={newCardNumber}
|
||||
type="text"
|
||||
inputmode="numeric"
|
||||
value={newCardNumber}
|
||||
oninput={(e) => (newCardNumber = formatDepositCardNumber((e.target as HTMLInputElement).value))}
|
||||
placeholder="1234 5678 9012 3456"
|
||||
maxlength={19}
|
||||
/>
|
||||
@@ -1589,14 +1631,17 @@
|
||||
<Label for="cardExpiry">Expiry (MM/YY)</Label>
|
||||
<Input
|
||||
id="cardExpiry"
|
||||
bind:value={newCardExpiry}
|
||||
type="text"
|
||||
inputmode="numeric"
|
||||
value={newCardExpiry}
|
||||
oninput={(e) => (newCardExpiry = formatDepositExpiry((e.target as HTMLInputElement).value))}
|
||||
placeholder="MM/YY"
|
||||
maxlength={5}
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<Label for="cardCVC">CVC</Label>
|
||||
<Input id="cardCVC" bind:value={newCardCVC} placeholder="123" maxlength={4} />
|
||||
<Input id="cardCVC" type="text" inputmode="numeric" bind:value={newCardCVC} placeholder="123" maxlength={4} />
|
||||
</div>
|
||||
</div>
|
||||
{#if authStore.isAuthenticated}
|
||||
@@ -1623,8 +1668,7 @@
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
disabled={isProcessingPayment ||
|
||||
(!selectedPaymentMethod && !newCardNumber && !showNewCardForm)}
|
||||
disabled={isProcessingPayment || !depositCardFormValid}
|
||||
onclick={() => processPayment(calculateDepositAmount())}
|
||||
class="bg-primary text-primary-foreground"
|
||||
>
|
||||
@@ -1641,14 +1685,14 @@
|
||||
onclick={nextStep}
|
||||
class="bg-primary text-primary-foreground"
|
||||
>
|
||||
{isSubmitting ? 'Processing...' : 'Skip Payment'}
|
||||
{isSubmitting ? 'Processing...' : 'Continue'}
|
||||
</Button>
|
||||
</Card.Footer>
|
||||
</Card.Root>
|
||||
{/if}
|
||||
|
||||
<!-- Step 5: Confirmation -->
|
||||
{#if currentStep === 5}
|
||||
<!-- Step 5: Confirmation (or Step 4 if no deposit required) -->
|
||||
{#if currentStep === 5 || (currentStep === 4 && !depositRequired)}
|
||||
{#if confirmedBooking}
|
||||
{@const isRequested = confirmedBooking.notes && confirmedBooking.notes.length > 0}
|
||||
{@const bookingDate = new SvelteDate(confirmedBooking.start_time)}
|
||||
@@ -1764,8 +1808,7 @@
|
||||
You can pay when you arrive, or pay ahead of time to speed things up.
|
||||
</p>
|
||||
<Button
|
||||
onclick={() =>
|
||||
(window.location.href = `/booking-confirmed/${confirmedBooking!.id}`)}
|
||||
onclick={() => (showPayEarlyModal = true)}
|
||||
class="bg-emerald-600 text-white hover:bg-emerald-700"
|
||||
>
|
||||
Pay Early
|
||||
@@ -1775,7 +1818,7 @@
|
||||
</Card.Content>
|
||||
<Card.Footer class="flex justify-center">
|
||||
<Button
|
||||
onclick={() => (window.location.href = authStore.isAuthenticated ? '/account' : '/')}
|
||||
onclick={() => (window.location.href = authStore.isAuthenticated ? '/schedule' : '/')}
|
||||
class="w-full"
|
||||
>
|
||||
{authStore.isAuthenticated ? 'View My Bookings' : 'Return Home'}
|
||||
@@ -1795,4 +1838,37 @@
|
||||
</Card.Root>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if showPayEarlyModal && confirmedBooking}
|
||||
{@const booking = confirmedBooking}
|
||||
<UserPaymentModal
|
||||
booking={{
|
||||
id: booking.id,
|
||||
status: booking.status as BookingStatus,
|
||||
start_time: booking.start_time,
|
||||
notes: booking.notes,
|
||||
services: selectedServices.map((s) => ({
|
||||
booking_id: booking.id,
|
||||
service_id: s.id,
|
||||
service_name: s.name,
|
||||
price: s.price,
|
||||
duration_minutes: s.duration_minutes
|
||||
})) as BookingService[],
|
||||
total_amount: getTotalPrice(),
|
||||
amount_paid: 0,
|
||||
amount_due: getTotalPrice(),
|
||||
deposit_required: false,
|
||||
deposit_paid: true,
|
||||
payments: [],
|
||||
duration_minutes: getTotalDuration(),
|
||||
created_at: new Date().toISOString(),
|
||||
updated_at: new Date().toISOString()
|
||||
}}
|
||||
onClose={() => (showPayEarlyModal = false)}
|
||||
onComplete={() => {
|
||||
showPayEarlyModal = false;
|
||||
}}
|
||||
canSaveCards={authStore.currentUser?.role === 'verified_email' || authStore.currentUser?.role === 'affiliate'}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
service_description?: string;
|
||||
price?: number;
|
||||
duration_minutes?: number;
|
||||
override_price?: number;
|
||||
override_duration_minutes?: number;
|
||||
}>;
|
||||
duration_minutes: number;
|
||||
total_amount: number;
|
||||
@@ -318,7 +320,7 @@
|
||||
<div class="text-xs text-gray-600">{service.service_description}</div>
|
||||
{/if}
|
||||
<div class="mt-1 flex items-center justify-between text-xs text-gray-500">
|
||||
<span>{service.duration_minutes} mins</span>
|
||||
<span>{service.override_duration_minutes ?? service.duration_minutes} mins</span>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
Reference in New Issue
Block a user