feat: add email verification, profile pictures, deposits, and calendar

export
Backend:
- Add email verification code generation and verification endpoints
- Add profile picture upload with S3 storage and image processing
- Add deposit_required field to users with 48h advance booking
  requirement
- Add loyalty stamps that accumulate on completed bookings
- Auto-transition bookings: confirmed → in_progress → completed
- Add booking cancellation handler with no-show detection
- Add ICS calendar file download endpoint for bookings
- Sync bookings to CalDAV on confirmation
  Frontend:
- Add schedule page route
- Add avatar and image-cropper UI components
- Update shadcn-svelte components (button, dialog)
- Add "Add to Calendar" button in booking modal
  Database:
- Add verification_codes table
- Add profile_pic_url, loyalty_stamps, deposits_required to users
- Various schema updates
This commit is contained in:
2026-02-21 18:48:29 +00:00
parent 88d8469180
commit 970cc5554d
48 changed files with 1984 additions and 175 deletions
+152
View File
@@ -28,6 +28,8 @@
import { Separator } from '$lib/components/ui/separator';
import * as AlertDialog from '$lib/components/ui/alert-dialog';
import { Skeleton } from '$lib/components/ui/skeleton';
import * as Dialog from '$lib/components/ui/dialog';
import Cropper from 'svelte-easy-crop';
// =============== Auth & Page State ===============
let pageState = $state<'loading' | 'authorized' | 'unauthorized'>('loading');
@@ -80,6 +82,96 @@
let userData = $state<User | null>(null);
let loadingUser = $state(true);
let stamps = $state(0);
let uploadingPic = $state(false);
// Image cropper state
let cropDialogOpen = $state(false);
let cropImageUrl = $state('');
let cropArea = $state<{ x: number; y: number; width: number; height: number } | null>(null);
let crop = $state({ x: 0, y: 0 });
let zoom = $state(1);
let previewUrl = $state('');
function handleFileSelect(e: Event) {
const input = e.target as HTMLInputElement;
const file = input.files?.[0];
if (file) {
cropImageUrl = URL.createObjectURL(file);
cropDialogOpen = true;
}
}
async function handleCropSave() {
if (!cropArea || !cropImageUrl) return;
const img = new Image();
img.src = cropImageUrl;
await new Promise(resolve => { img.onload = resolve; });
const canvas = document.createElement('canvas');
canvas.width = 350;
canvas.height = 350;
const ctx = canvas.getContext('2d');
if (!ctx) return;
ctx.drawImage(
img,
cropArea.x, cropArea.y, cropArea.width, cropArea.height,
0, 0, 350, 350
);
canvas.toBlob((blob) => {
if (!blob) return;
const url = URL.createObjectURL(blob);
previewUrl = url;
handleProfilePicUpload(blob).then(() => {
URL.revokeObjectURL(cropImageUrl);
cropImageUrl = '';
cropArea = null;
cropDialogOpen = false;
});
}, 'image/jpeg', 0.9);
}
function handleCropCancel() {
if (cropImageUrl) {
URL.revokeObjectURL(cropImageUrl);
}
cropImageUrl = '';
cropArea = null;
cropDialogOpen = false;
}
async function handleProfilePicUpload(blob: Blob) {
uploadingPic = true;
try {
const formData = new FormData();
formData.append('file', blob, 'profile.jpg');
const uploadResponse = await fetch('/api/user/profile-picture', {
method: 'POST',
headers: {
Authorization: `Bearer ${authStore.currentToken}`
},
body: formData
});
if (uploadResponse.ok) {
const data = await uploadResponse.json();
if (userData) {
userData.profilePicUrl = data.url;
}
toast.success('Profile picture updated');
} else {
toast.error('Failed to upload profile picture');
}
} catch (err) {
console.error('Upload error:', err);
toast.error('Failed to upload profile picture');
} finally {
uploadingPic = false;
}
}
// =============== Phone Edit Mode ===============
let editingPhone = $state(false);
@@ -607,6 +699,66 @@
<Card.Description>Your personal details and account information</Card.Description>
</Card.Header>
<Card.Content class="space-y-4">
{#if userData}
{@const initials = userData.firstName && userData.lastName ? userData.firstName.split(' ').map(n => n[0]).join('') + userData.lastName.split(' ').map(n => n[0]).join('') : ''}
{@const hasImage = !!userData.profilePicUrl || !!previewUrl}
{@const displayUrl = previewUrl || userData.profilePicUrl || ''}
<div class="flex flex-col items-center gap-4">
{#if hasImage || initials}
{#if hasImage}
<img src={displayUrl} alt="Profile" class="h-24 w-24 rounded-full object-cover ring-4 ring-blue-200" />
{:else}
<div class="flex h-24 w-24 items-center justify-center rounded-full bg-gray-200 text-3xl font-bold text-gray-600 ring-4 ring-blue-200">
{initials}
</div>
{/if}
{:else}
<div class="flex h-24 w-24 items-center justify-center rounded-full bg-gray-200 ring-4 ring-blue-200">
<svg xmlns="http://www.w3.org/2000/svg" class="h-10 w-10 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
</svg>
</div>
{/if}
<Button variant="outline" onclick={() => document.getElementById('profile-pic-input')?.click()}>
Upload profile picture
</Button>
<input
id="profile-pic-input"
type="file"
accept="image/*"
class="hidden"
onchange={handleFileSelect}
/>
</div>
{/if}
<Dialog.Root bind:open={cropDialogOpen}>
<Dialog.Content class="max-w-lg">
<Dialog.Header>
<Dialog.Title>Crop Profile Picture</Dialog.Title>
</Dialog.Header>
<div class="relative h-64 w-full">
{#if cropImageUrl}
<Cropper
image={cropImageUrl}
aspect={1}
cropShape="round"
showGrid={false}
bind:crop
bind:zoom
oncropcomplete={(e) => {
cropArea = e.pixels;
}}
/>
{/if}
</div>
<Dialog.Footer>
<Button variant="outline" onclick={handleCropCancel}>Cancel</Button>
<Button onclick={handleCropSave}>Save</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
{#if loadingUser}
{#each Array(6) as _, i (i)}
<Skeleton class="h-12 w-full" />
+55 -8
View File
@@ -1,15 +1,62 @@
<script lang="ts">
import ContactCard from '$lib/components/layout/ContactCard.svelte';
import { onMount } from 'svelte';
type ContactInfo = {
name: string;
role: string;
phone: string;
email: string;
profilePicUrl?: string;
};
let contact = $state<ContactInfo | null>(null);
let loading = $state(true);
onMount(async () => {
try {
const res = await fetch('/api/contact');
if (res.ok) {
contact = await res.json();
}
} catch (err) {
console.error('Failed to load contact info:', err);
} finally {
loading = false;
}
});
</script>
<section class="py-12">
<h1 class="mb-8 text-center text-2xl font-semibold">Contact Me</h1>
<ContactCard
name="Chelsea Russell"
role="Owner / Beauty Specialist"
phone="+44 8008135"
email="chelsea@emailaddress.com"
instagram="crussell"
address="Business Centre, Office Street, Work"
/>
{#if loading}
<div class="mx-auto max-w-sm animate-pulse rounded-lg border-2 border-gray-200 bg-white p-6">
<div class="mb-4 flex justify-center">
<div class="h-24 w-24 rounded-full bg-gray-200"></div>
</div>
<div class="mb-4 text-center">
<div class="mx-auto mb-2 h-6 w-40 rounded bg-gray-200"></div>
<div class="mx-auto h-4 w-32 rounded bg-gray-200"></div>
</div>
</div>
{:else if contact}
<ContactCard
name={contact.name}
role={contact.role}
phone={contact.phone}
email={contact.email}
instagram="crussell"
address="Business Centre, Office Street, Work"
profileImage={contact.profilePicUrl || 'https://images.icon-icons.com/5/PNG/256/MSN_messenger_user_156.png'}
/>
{:else}
<ContactCard
name="Chelsea Russell"
role="Owner / Beauty Specialist"
phone="+44 8008135"
email="chelsea@emailaddress.com"
instagram="crussell"
address="Business Centre, Office Street, Work"
/>
{/if}
</section>
+167
View File
@@ -0,0 +1,167 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { authStore } from '$lib/stores/auth.svelte';
import { browser } from '$app/environment';
import { toast } from 'svelte-sonner';
import { SvelteDate } from 'svelte/reactivity';
import UserBookingModal from '$lib/components/account/UserBookingModal.svelte';
import { Button } from '$lib/components/ui/button';
import * as Card from '$lib/components/ui/card';
let pageState = $state<'loading' | 'authorized' | 'unauthorized'>('loading');
let bookings = $state<any[]>([]);
let loading = $state(false);
let selectedBookingId = $state<string | null>(null);
let showBookingModal = $state(false);
$effect(() => {
if (!browser) return;
if (authStore.isLoading) {
pageState = 'loading';
return;
}
if (!authStore.isAuthenticated) {
pageState = 'unauthorized';
goto('/login', { replaceState: true });
return;
}
pageState = 'authorized';
fetchBookings();
});
async function fetchBookings() {
loading = true;
try {
const today = new Date().toISOString().split('T')[0];
const response = await fetch(`/api/bookings?start_date=${today}&per_page=50&page=1`, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${authStore.currentToken}`
}
});
if (!response.ok) {
toast.error('Failed to load bookings');
return;
}
const data = await response.json();
const now = new Date();
bookings = (data.bookings || [])
.filter((b: any) => {
const startTime = new Date(b.start_time);
const endTime = new Date(startTime.getTime() + (b.duration_minutes || 0) * 60000);
return endTime > now;
})
.sort(
(a: any, b: any) => new Date(a.start_time).getTime() - new Date(b.start_time).getTime()
);
} catch (err) {
console.error('Error fetching bookings:', err);
toast.error('Network error');
} finally {
loading = false;
}
}
function openBooking(id: string) {
selectedBookingId = id;
showBookingModal = true;
}
const statusColors: Record<string, string> = {
pending: 'bg-yellow-100 text-yellow-800',
confirmed: 'bg-green-100 text-green-800',
in_progress: 'bg-blue-100 text-blue-800',
completed: 'bg-gray-100 text-gray-800'
};
</script>
{#if pageState === 'loading'}
<div class="mx-auto max-w-4xl p-6">
<div class="animate-pulse space-y-4">
<div class="h-8 w-48 rounded bg-gray-200"></div>
<div class="h-64 rounded bg-gray-200"></div>
</div>
</div>
{:else if pageState === 'unauthorized'}
<div class="mx-auto max-w-4xl p-6 text-center">
<p>Please log in to view your schedule.</p>
</div>
{:else}
<div class="mx-auto max-w-4xl p-6">
<h1 class="mb-6 text-2xl font-bold">My Schedule</h1>
{#if loading}
<div class="text-center">Loading...</div>
{:else if bookings.length === 0}
<Card.Root>
<Card.Header>
<Card.Title>No Upcoming Appointments</Card.Title>
<Card.Description>You don't have any upcoming appointments.</Card.Description>
</Card.Header>
<Card.Content>
<Button href="/book">Book an Appointment</Button>
</Card.Content>
</Card.Root>
{:else}
<div class="space-y-4">
{#each bookings as booking (booking.id)}
<Card.Root>
<Card.Header class="flex flex-row items-center justify-between pb-2">
<div>
<Card.Title class="text-lg">
{new SvelteDate(booking.start_time).toLocaleDateString('en-GB', {
weekday: 'long',
day: 'numeric',
month: 'long',
year: 'numeric'
})}
</Card.Title>
<Card.Description>
{new SvelteDate(booking.start_time).toLocaleTimeString('en-GB', {
hour: 'numeric',
minute: '2-digit'
})}
{#if booking.duration_minutes}
<span class="text-gray-500"> · {booking.duration_minutes} min</span>
{/if}
</Card.Description>
</div>
<span
class="rounded-full px-2 py-1 text-xs font-medium {statusColors[booking.status] ||
'bg-gray-100 text-gray-800'}"
>
{booking.status}
</span>
</Card.Header>
<Card.Content>
<div class="flex items-center justify-between">
<div>
{#if booking.services && booking.services.length > 0}
<p class="font-medium">
{booking.services.map((s: any) => s.service_name).join(', ')}
</p>
{/if}
{#if booking.total_amount}
<p class="text-sm text-gray-500">£{booking.total_amount.toFixed(2)}</p>
{/if}
</div>
<div class="flex gap-2">
<Button size="sm" onclick={() => openBooking(booking.id)}>View Details</Button>
</div>
</div>
</Card.Content>
</Card.Root>
{/each}
</div>
{/if}
</div>
{/if}
<UserBookingModal bind:open={showBookingModal} bookingId={selectedBookingId || ''} />