Admin: dashboard at / with income and hours; Site design 2x2 grid
The dashboard shows income (paid orders, by the month they were paid), hours worked and still booked this month, the next 7 days' bookings and a 12-month table. Booked time is counted with overlaps merged, so a group session is one hour of work however many people booked it. Login and the sidebar title now land on the dashboard. Site design: four cards in a three-column grid left Style alone under Header. Two columns on xl (Header|Footer, Colors|Style) and all four side by side from 2xl. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HA82gV9YDZk1XhjJ5LtyAt
This commit is contained in:
parent
312dc5ed3c
commit
bdc040636a
8 changed files with 270 additions and 34 deletions
|
|
@ -22,6 +22,10 @@
|
|||
// Sidebar navigation, grouped by what the studio is doing. Labels are
|
||||
// user-facing names; hrefs keep the original route names.
|
||||
const navGroups = [
|
||||
{
|
||||
title: 'Studio',
|
||||
links: [{ href: '/', label: 'Dashboard' }]
|
||||
},
|
||||
{
|
||||
title: 'Website',
|
||||
links: [
|
||||
|
|
@ -80,7 +84,7 @@
|
|||
<label for="admin-nav" class="btn btn-square btn-ghost" aria-label="Open menu">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="size-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4 6h16M4 12h16M4 18h16" /></svg>
|
||||
</label>
|
||||
<a class="ml-1 text-lg font-bold tracking-tight" href="/pages">Massage CMS</a>
|
||||
<a class="ml-1 text-lg font-bold tracking-tight" href="/">Massage CMS</a>
|
||||
</header>
|
||||
<main class="mx-auto w-full max-w-7xl flex-1 p-4 md:p-8">
|
||||
{@render children()}
|
||||
|
|
@ -90,7 +94,7 @@
|
|||
<div class="drawer-side z-40">
|
||||
<label for="admin-nav" class="drawer-overlay" aria-label="Close menu"></label>
|
||||
<aside class="flex min-h-full w-64 flex-col border-r border-base-300 bg-base-100">
|
||||
<a class="block px-6 pt-6 pb-4 text-lg font-bold tracking-tight" href="/pages">Massage CMS</a>
|
||||
<a class="block px-6 pt-6 pb-4 text-lg font-bold tracking-tight" href="/">Massage CMS</a>
|
||||
<nav class="flex-1" aria-label="Main">
|
||||
<ul class="menu w-full gap-0.5 px-3">
|
||||
{#each navGroups as group (group.title)}
|
||||
|
|
|
|||
7
app-admin/src/routes/+page.server.ts
Normal file
7
app-admin/src/routes/+page.server.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { env } from '$env/dynamic/private';
|
||||
import { loadDashboard } from '$lib/server/dashboard';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ locals }) => ({
|
||||
dashboard: await loadDashboard(locals.pb, env.SITE_TIMEZONE || 'Europe/Oslo')
|
||||
});
|
||||
94
app-admin/src/routes/+page.svelte
Normal file
94
app-admin/src/routes/+page.svelte
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
<script lang="ts">
|
||||
import { DISPLAY_LOCALE, formatInstant, formatPrice } from '$lib/calendar';
|
||||
import { formatDuration } from '$shared/items';
|
||||
|
||||
let { data } = $props();
|
||||
let dashboard = $derived(data.dashboard);
|
||||
|
||||
const hoursFormat = new Intl.NumberFormat(DISPLAY_LOCALE, { maximumFractionDigits: 1 });
|
||||
const hours = (minutes: number) => `${hoursFormat.format(minutes / 60)} h`;
|
||||
const money = (amount: number) => formatPrice(amount, data.currency);
|
||||
// Mid-month noon UTC is inside the same month in every timezone.
|
||||
const monthLabel = (month: string, options: Intl.DateTimeFormatOptions = { month: 'long', year: 'numeric' }) =>
|
||||
formatInstant(`${month}-15T12:00:00Z`, data.timezone, options);
|
||||
const dayLabel = (value: string) => formatInstant(value, data.timezone, { weekday: 'short', day: 'numeric', month: 'short' });
|
||||
const timeLabel = (value: string) => formatInstant(value, data.timezone, { hour: '2-digit', minute: '2-digit' });
|
||||
|
||||
let incomeChange = $derived(dashboard.thisMonth.income - dashboard.lastMonth.income);
|
||||
</script>
|
||||
|
||||
<svelte:head><title>Dashboard | CMS</title></svelte:head>
|
||||
|
||||
<div class="mb-6">
|
||||
<h1 class="text-3xl font-bold">Dashboard</h1>
|
||||
<p class="text-base-content/60">How the studio is doing. Income is paid orders; hours are booked appointment time, with group sessions counted once.</p>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<div class="rounded-box bg-base-100 p-5 shadow">
|
||||
<p class="text-sm text-base-content/60">Income in {monthLabel(dashboard.thisMonth.month, { month: 'long' })}</p>
|
||||
<p class="mt-1 text-3xl font-bold">{money(dashboard.thisMonth.income)}</p>
|
||||
<p class="mt-1 text-sm text-base-content/60">
|
||||
{incomeChange >= 0 ? '+' : '−'}{money(Math.abs(incomeChange))} on {monthLabel(dashboard.lastMonth.month, { month: 'long' })}
|
||||
</p>
|
||||
</div>
|
||||
<div class="rounded-box bg-base-100 p-5 shadow">
|
||||
<p class="text-sm text-base-content/60">Income in {dashboard.thisMonth.month.slice(0, 4)}</p>
|
||||
<p class="mt-1 text-3xl font-bold">{money(dashboard.incomeThisYear)}</p>
|
||||
<p class="mt-1 text-sm text-base-content/60">{dashboard.thisMonth.orders} {dashboard.thisMonth.orders === 1 ? 'order' : 'orders'} this month</p>
|
||||
</div>
|
||||
<div class="rounded-box bg-base-100 p-5 shadow">
|
||||
<p class="text-sm text-base-content/60">Hours worked in {monthLabel(dashboard.thisMonth.month, { month: 'long' })}</p>
|
||||
<p class="mt-1 text-3xl font-bold">{hours(dashboard.minutesDoneThisMonth)}</p>
|
||||
<p class="mt-1 text-sm text-base-content/60">{hours(dashboard.minutesAheadThisMonth)} still booked this month</p>
|
||||
</div>
|
||||
<div class="rounded-box bg-base-100 p-5 shadow">
|
||||
<p class="text-sm text-base-content/60">Next {dashboard.upcomingDays} days</p>
|
||||
<p class="mt-1 text-3xl font-bold">{dashboard.upcoming.length} {dashboard.upcoming.length === 1 ? 'booking' : 'bookings'}</p>
|
||||
<p class="mt-1 text-sm text-base-content/60">{hours(dashboard.upcomingMinutes)} of appointments</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 grid gap-6 xl:grid-cols-2">
|
||||
<section class="rounded-box bg-base-100 p-5 shadow">
|
||||
<h2 class="mb-4 text-2xl font-bold">Coming up</h2>
|
||||
{#if dashboard.upcoming.length}
|
||||
<ul class="divide-y divide-base-300">
|
||||
{#each dashboard.upcoming as booking, i (i)}
|
||||
<li class="flex flex-wrap items-baseline gap-x-3 py-2">
|
||||
<span class="w-28 shrink-0 font-semibold">{dayLabel(booking.start)}</span>
|
||||
<span class="w-24 shrink-0 tabular-nums">{timeLabel(booking.start)} · {formatDuration(booking.minutes)}</span>
|
||||
<span class="min-w-0 flex-1">
|
||||
{booking.name}{#if booking.quantity > 1}<span class="text-base-content/60"> × {booking.quantity}</span>{/if}
|
||||
{#if booking.customer}<span class="block text-sm text-base-content/60">{booking.customer}</span>{/if}
|
||||
</span>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{:else}
|
||||
<p class="text-base-content/60">Nothing booked in the next {dashboard.upcomingDays} days.</p>
|
||||
{/if}
|
||||
<a class="btn btn-sm mt-4" href="/orders">All orders</a>
|
||||
</section>
|
||||
|
||||
<section class="rounded-box bg-base-100 p-5 shadow">
|
||||
<h2 class="mb-4 text-2xl font-bold">Month by month</h2>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table table-sm">
|
||||
<thead>
|
||||
<tr><th>Month</th><th class="text-right">Orders</th><th class="text-right">Income</th><th class="text-right">Hours booked</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each dashboard.months as row (row.month)}
|
||||
<tr class={row.month === dashboard.thisMonth.month ? 'bg-primary/10' : ''}>
|
||||
<td>{monthLabel(row.month)}</td>
|
||||
<td class="text-right tabular-nums">{row.orders}</td>
|
||||
<td class="text-right tabular-nums">{money(row.income)}</td>
|
||||
<td class="text-right tabular-nums">{hours(row.minutes)}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
|
@ -124,7 +124,7 @@
|
|||
<p class="text-base-content/60">The header, footer, colors and style shared by every page of the site.</p>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-6 xl:grid-cols-3">
|
||||
<div class="grid gap-6 xl:grid-cols-2 2xl:grid-cols-4">
|
||||
<form class="flex flex-col rounded-box bg-base-100 p-5 shadow" method="POST" action="?/save" use:enhance={submit}>
|
||||
<input type="hidden" name="id" value={data.header.id} />
|
||||
<input type="hidden" name="section" value="header" />
|
||||
|
|
|
|||
|
|
@ -1,28 +1,28 @@
|
|||
import { fail, redirect } from '@sveltejs/kit';
|
||||
import type { Actions } from './$types';
|
||||
|
||||
export const actions: Actions = {
|
||||
login: async ({ request, locals }) => {
|
||||
const data = await request.formData();
|
||||
const email = String(data.get('email') || '');
|
||||
const password = String(data.get('password') || '');
|
||||
|
||||
try {
|
||||
try {
|
||||
await locals.pb.collection('_superusers').authWithPassword(email, password);
|
||||
} catch {
|
||||
await locals.pb.collection('users').authWithPassword(email, password);
|
||||
}
|
||||
} catch {
|
||||
// One line per failed attempt; the full SDK error object is noise here.
|
||||
console.warn('Admin login failed for', email);
|
||||
return fail(400, { email, message: 'Invalid email or password.' });
|
||||
}
|
||||
|
||||
throw redirect(303, '/pages');
|
||||
},
|
||||
logout: async ({ locals }) => {
|
||||
locals.pb.authStore.clear();
|
||||
throw redirect(303, '/login');
|
||||
}
|
||||
};
|
||||
import { fail, redirect } from '@sveltejs/kit';
|
||||
import type { Actions } from './$types';
|
||||
|
||||
export const actions: Actions = {
|
||||
login: async ({ request, locals }) => {
|
||||
const data = await request.formData();
|
||||
const email = String(data.get('email') || '');
|
||||
const password = String(data.get('password') || '');
|
||||
|
||||
try {
|
||||
try {
|
||||
await locals.pb.collection('_superusers').authWithPassword(email, password);
|
||||
} catch {
|
||||
await locals.pb.collection('users').authWithPassword(email, password);
|
||||
}
|
||||
} catch {
|
||||
// One line per failed attempt; the full SDK error object is noise here.
|
||||
console.warn('Admin login failed for', email);
|
||||
return fail(400, { email, message: 'Invalid email or password.' });
|
||||
}
|
||||
|
||||
throw redirect(303, '/');
|
||||
},
|
||||
logout: async ({ locals }) => {
|
||||
locals.pb.authStore.clear();
|
||||
throw redirect(303, '/login');
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue