Admin UI consistency: DaisyUI 5 forms, shared modal and setting rows
- Migrate all DaisyUI 4 form markup (form-control, label-text, *-bordered — removed in v5) to v5 fieldset/legend; labels sat inline beside inputs and inputs fell back to a fixed 20rem width. - One Modal component (native <dialog>: Escape, focus trap) for page, event, item and slot editors; destructive actions confirmed everywhere. The page Delete confirm was ignored — returning false from onsubmit doesn't cancel — so Cancel still deleted the page. - Block editor follows the background-picker style throughout: SegmentedControl rows (title-cased options, clearer selected state) and a new ColorField row with reset; image position is Left/Right like the alignment controls. - Globals keep their layout; readable field labels, save feedback without reload, hints wrap. - Pages list: fixed broken Preview link (VITE_PUBLIC_SITE_URL was undefined → "undefined/slug"), shown for published pages only; action column no longer breaks row alignment; empty states on all tables. - Items: image picker instead of a raw media-id field, upload errors shown (were swallowed), prices in the shop currency instead of hard-coded EUR. - Slots/orders/calendar: times shown in the site timezone with a fixed locale (server and browser render the same text). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv
This commit is contained in:
parent
cfe4e2062d
commit
af7b4af5de
16 changed files with 1237 additions and 1211 deletions
|
|
@ -15,6 +15,12 @@
|
|||
--color-primary-content: #ffffff;
|
||||
}
|
||||
|
||||
/* Hint text under form fields: DaisyUI's .label is nowrap, which stretched
|
||||
fields to fit long hints. */
|
||||
.fieldset .label {
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
@theme {
|
||||
--font-sans: 'DM Sans', ui-sans-serif, system-ui, sans-serif;
|
||||
--font-serif: 'Playfair Display', Georgia, serif;
|
||||
|
|
|
|||
33
app-admin/src/lib/admin/Modal.svelte
Normal file
33
app-admin/src/lib/admin/Modal.svelte
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte';
|
||||
|
||||
// Shared dialog for create/edit forms, on the native <dialog> (Escape and
|
||||
// focus trapping for free). No click-outside-to-close: these hold forms,
|
||||
// and a stray click shouldn't throw away what was typed.
|
||||
let {
|
||||
open = $bindable(false),
|
||||
title,
|
||||
wide = false,
|
||||
children
|
||||
}: { open?: boolean; title: string; wide?: boolean; children: Snippet } = $props();
|
||||
|
||||
let dialog: HTMLDialogElement | undefined = $state();
|
||||
|
||||
$effect(() => {
|
||||
if (!dialog) return;
|
||||
if (open && !dialog.open) dialog.showModal();
|
||||
if (!open && dialog.open) dialog.close();
|
||||
});
|
||||
</script>
|
||||
|
||||
<dialog bind:this={dialog} class="modal modal-bottom sm:modal-middle" onclose={() => (open = false)}>
|
||||
<div class={['modal-box', wide && 'sm:max-w-2xl']}>
|
||||
<div class="mb-4 flex items-start justify-between gap-3">
|
||||
<h2 class="text-2xl font-bold">{title}</h2>
|
||||
<button class="btn btn-circle btn-ghost btn-sm" type="button" aria-label="Close" onclick={() => (open = false)}>✕</button>
|
||||
</div>
|
||||
{#if open}
|
||||
{@render children()}
|
||||
{/if}
|
||||
</div>
|
||||
</dialog>
|
||||
13
app-admin/src/lib/admin/confirm.ts
Normal file
13
app-admin/src/lib/admin/confirm.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* `onsubmit` / `onclick` handler that asks for confirmation and cancels the
|
||||
* submit if declined. (Returning `false` from a handler does NOT cancel the
|
||||
* event — it has to call preventDefault.)
|
||||
*
|
||||
* <form onsubmit={confirmSubmit('Delete this page?')}>
|
||||
* <button formaction="?/delete" onclick={confirmSubmit('Delete this event?')}>
|
||||
*/
|
||||
export function confirmSubmit(message: string) {
|
||||
return (event: Event) => {
|
||||
if (!confirm(message)) event.preventDefault();
|
||||
};
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
import RichTextEditor from './RichTextEditor.svelte';
|
||||
import ImageUploader from './ImageUploader.svelte';
|
||||
import SegmentedControl from './SegmentedControl.svelte';
|
||||
import ColorField from './ColorField.svelte';
|
||||
import ShopBlockEditor from './ShopBlockEditor.svelte';
|
||||
import CheckoutBlockEditor from './CheckoutBlockEditor.svelte';
|
||||
|
||||
|
|
@ -47,12 +48,26 @@
|
|||
});
|
||||
}
|
||||
|
||||
function titleCase(value: string | number) {
|
||||
const text = String(value);
|
||||
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||
function updateBackground(patch: Record<string, any>) {
|
||||
if (!block) return;
|
||||
updateData({ _background: { ...(block.data._background || {}), ...patch } });
|
||||
}
|
||||
|
||||
function updateForeground(patch: Record<string, any>) {
|
||||
if (!block) return;
|
||||
updateData({ _foreground: { ...(block.data._foreground || {}), ...patch } });
|
||||
}
|
||||
|
||||
const sizeLabels: Record<string, string> = { xs: 'XS', sm: 'Small', md: 'Medium', lg: 'Large' };
|
||||
</script>
|
||||
|
||||
{#snippet field(label: string, value: string, onInput: (value: string) => void, placeholder = '')}
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">{label}</span>
|
||||
<input class="input w-full" {placeholder} {value} oninput={(e) => onInput(e.currentTarget.value)} />
|
||||
</label>
|
||||
{/snippet}
|
||||
|
||||
{#if !block}
|
||||
<div class="rounded-box bg-base-100 p-8 text-center text-base-content/60 shadow">Select a block to edit.</div>
|
||||
{:else}
|
||||
|
|
@ -62,146 +77,87 @@
|
|||
{#if block.type === 'text'}
|
||||
<RichTextEditor value={block.data.content} onChange={(content) => updateData({ content })} />
|
||||
{:else if block.type === 'image_text'}
|
||||
<ImageUploader url={block.data.url} alt={block.data.alt} onChange={(image) => updateData(image)} />
|
||||
<div class="form-control mt-3">
|
||||
<label class="label cursor-pointer justify-start gap-3">
|
||||
<span class="label-text">Image position</span>
|
||||
<input type="checkbox" class="toggle toggle-primary" checked={block.data.imagePosition === 'right'} onchange={(e) => updateData({ imagePosition: e.currentTarget.checked ? 'right' : 'left' })} />
|
||||
<span class="text-sm text-base-content/60">{block.data.imagePosition === 'right' ? 'Right' : 'Left'}</span>
|
||||
</label>
|
||||
<div class="space-y-4">
|
||||
<ImageUploader url={block.data.url} alt={block.data.alt} onChange={(image) => updateData(image)} />
|
||||
<SegmentedControl label="Image position" options={['left', 'right']} value={block.data.imagePosition === 'right' ? 'right' : 'left'} onChange={(v) => updateData({ imagePosition: v })} />
|
||||
<RichTextEditor value={block.data.content} onChange={(content) => updateData({ content })} />
|
||||
</div>
|
||||
<div class="mt-3"><RichTextEditor value={block.data.content} onChange={(content) => updateData({ content })} /></div>
|
||||
{:else if block.type === 'timeline'}
|
||||
{#each block.data.items || [] as item, i}
|
||||
<div class="rounded-box mb-3 border border-base-300 p-3">
|
||||
<input class="input input-bordered mb-2 w-full" placeholder="Title" value={item.title} oninput={(e) => updateArray('items', i, { title: e.currentTarget.value })} />
|
||||
<textarea class="textarea textarea-bordered w-full" placeholder="Description" value={item.description} oninput={(e) => updateArray('items', i, { description: e.currentTarget.value })}></textarea>
|
||||
<button class="btn btn-error btn-sm mt-2" type="button" onclick={() => removeArrayItem('items', i)}>Remove</button>
|
||||
</div>
|
||||
{/each}
|
||||
<button class="btn" type="button" onclick={() => addArrayItem('items', { title: '', description: '' })}>Add item</button>
|
||||
{:else if block.type === 'hero'}
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Heading</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.heading || ''} oninput={(e) => updateData({ heading: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full mt-3">
|
||||
<div class="label"><span class="label-text">Subheading</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.subheading || ''} oninput={(e) => updateData({ subheading: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full mt-3">
|
||||
<div class="label"><span class="label-text">Button label</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.buttonLabel || ''} oninput={(e) => updateData({ buttonLabel: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full mt-3">
|
||||
<div class="label"><span class="label-text">Button URL</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.buttonUrl || ''} oninput={(e) => updateData({ buttonUrl: e.currentTarget.value })} />
|
||||
</label>
|
||||
{:else if block.type === 'button'}
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Button label</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.label || ''} oninput={(e) => updateData({ label: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">URL</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.href || ''} oninput={(e) => updateData({ href: e.currentTarget.value })} />
|
||||
</label>
|
||||
<div class="form-control mt-5">
|
||||
<SegmentedControl
|
||||
label="Variant"
|
||||
options={['primary', 'secondary']}
|
||||
value={block.data.variant || 'primary'}
|
||||
onChange={(v) => updateData({ variant: v })}
|
||||
/>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<SegmentedControl
|
||||
label="Alignment"
|
||||
options={['left', 'center', 'right']}
|
||||
value={block.data.alignment || 'left'}
|
||||
onChange={(v) => updateData({ alignment: v })}
|
||||
formatLabel={titleCase}
|
||||
/>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<SegmentedControl
|
||||
label="Size"
|
||||
options={['xs', 'sm', 'md', 'lg']}
|
||||
value={block.data.size || 'md'}
|
||||
onChange={(v) => updateData({ size: v })}
|
||||
formatLabel={(v) => String({ xs: 'Extra Small', sm: 'Small', md: 'Medium', lg: 'Large' }[String(v)] || v)}
|
||||
/>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="label-text w-24">Color</span>
|
||||
<div class="flex flex-1 items-center gap-2">
|
||||
<input class="input input-bordered w-10 h-10 p-1 cursor-pointer" type="color" value={block.data.color || 'var(--color-primary)'} oninput={(e) => updateData({ color: e.currentTarget.value })} />
|
||||
<input class="input input-bordered flex-1" placeholder="Leave empty to use global primary" value={block.data.color || ''} oninput={(e) => updateData({ color: e.currentTarget.value })} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{:else if block.type === 'spacer'}
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Height (px)</span></div>
|
||||
<input type="number" class="input input-bordered w-full" value={block.data.height || 64} oninput={(e) => updateData({ height: parseInt(e.currentTarget.value) || 64 })} />
|
||||
</label>
|
||||
</div>
|
||||
{:else if block.type === 'testimonials'}
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Section Title</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
</label>
|
||||
|
||||
<div class="space-y-3">
|
||||
{#each block.data.items || [] as item, i}
|
||||
<div class="rounded-box mb-3 border border-base-300 p-4">
|
||||
<textarea
|
||||
class="textarea textarea-bordered w-full mb-2"
|
||||
placeholder="Testimonial text"
|
||||
rows="3"
|
||||
value={item.text}
|
||||
oninput={(e) => updateArray('items', i, { text: e.currentTarget.value })}
|
||||
></textarea>
|
||||
<input
|
||||
class="input input-bordered w-full"
|
||||
placeholder="Author name"
|
||||
value={item.title}
|
||||
oninput={(e) => updateArray('items', i, { title: e.currentTarget.value })}
|
||||
/>
|
||||
<button class="btn btn-error btn-sm mt-2" type="button" onclick={() => removeArrayItem('items', i)}>Remove</button>
|
||||
<div class="rounded-box border border-base-300 p-3">
|
||||
<div class="mb-2 flex items-center justify-between">
|
||||
<span class="text-sm font-semibold text-base-content/60">Item {i + 1}</span>
|
||||
<button class="btn btn-ghost btn-xs text-error" type="button" onclick={() => removeArrayItem('items', i)}>Remove</button>
|
||||
</div>
|
||||
<input class="input mb-2 w-full" aria-label="Title" placeholder="Title" value={item.title} oninput={(e) => updateArray('items', i, { title: e.currentTarget.value })} />
|
||||
<textarea class="textarea w-full" aria-label="Description" placeholder="Description" value={item.description} oninput={(e) => updateArray('items', i, { description: e.currentTarget.value })}></textarea>
|
||||
</div>
|
||||
{/each}
|
||||
<button class="btn" type="button" onclick={() => addArrayItem('items', { text: '', title: '' })}>Add testimonial</button>
|
||||
<button class="btn btn-sm" type="button" onclick={() => addArrayItem('items', { title: '', description: '' })}>Add item</button>
|
||||
</div>
|
||||
{:else if block.type === 'hero'}
|
||||
{@render field('Heading', block.data.heading || '', (heading) => updateData({ heading }))}
|
||||
{@render field('Subheading', block.data.subheading || '', (subheading) => updateData({ subheading }))}
|
||||
<div class="grid gap-x-4 md:grid-cols-2">
|
||||
{@render field('Button label', block.data.buttonLabel || '', (buttonLabel) => updateData({ buttonLabel }))}
|
||||
{@render field('Button URL', block.data.buttonUrl || '', (buttonUrl) => updateData({ buttonUrl }), '/page or https://…')}
|
||||
</div>
|
||||
{:else if block.type === 'button'}
|
||||
<div class="grid gap-x-4 md:grid-cols-2">
|
||||
{@render field('Button label', block.data.label || '', (label) => updateData({ label }))}
|
||||
{@render field('URL', block.data.href || '', (href) => updateData({ href }), '/page or https://…')}
|
||||
</div>
|
||||
<div class="mt-4 space-y-3">
|
||||
<SegmentedControl label="Variant" options={['primary', 'secondary']} value={block.data.variant || 'primary'} onChange={(v) => updateData({ variant: v })} />
|
||||
<SegmentedControl label="Alignment" options={['left', 'center', 'right']} value={block.data.alignment || 'left'} onChange={(v) => updateData({ alignment: v })} />
|
||||
<SegmentedControl label="Size" options={['xs', 'sm', 'md', 'lg']} value={block.data.size || 'md'} onChange={(v) => updateData({ size: v })} formatLabel={(v) => sizeLabels[String(v)] || String(v)} />
|
||||
<ColorField label="Color" value={block.data.color || ''} fallback="#8a9a7b" placeholder="Site primary color" onChange={(color) => updateData({ color })} />
|
||||
</div>
|
||||
{:else if block.type === 'spacer'}
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Height (px)</span>
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
step="8"
|
||||
class="input w-full"
|
||||
value={block.data.height ?? 64}
|
||||
oninput={(e) => {
|
||||
const height = parseInt(e.currentTarget.value, 10);
|
||||
if (!Number.isNaN(height) && height >= 0) updateData({ height });
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
{:else if block.type === 'testimonials'}
|
||||
{@render field('Section title', block.data.title || '', (title) => updateData({ title }))}
|
||||
<div class="mt-3 space-y-3">
|
||||
{#each block.data.items || [] as item, i}
|
||||
<div class="rounded-box border border-base-300 p-3">
|
||||
<div class="mb-2 flex items-center justify-between">
|
||||
<span class="text-sm font-semibold text-base-content/60">Testimonial {i + 1}</span>
|
||||
<button class="btn btn-ghost btn-xs text-error" type="button" onclick={() => removeArrayItem('items', i)}>Remove</button>
|
||||
</div>
|
||||
<textarea class="textarea mb-2 w-full" aria-label="Testimonial text" placeholder="Testimonial text" rows="3" value={item.text} oninput={(e) => updateArray('items', i, { text: e.currentTarget.value })}></textarea>
|
||||
<input class="input w-full" aria-label="Author name" placeholder="Author name" value={item.title} oninput={(e) => updateArray('items', i, { title: e.currentTarget.value })} />
|
||||
</div>
|
||||
{/each}
|
||||
<button class="btn btn-sm" type="button" onclick={() => addArrayItem('items', { text: '', title: '' })}>Add testimonial</button>
|
||||
</div>
|
||||
{:else if block.type === 'upcoming_calendar'}
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Section title</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
</label>
|
||||
|
||||
<div class="rounded-box border border-base-300 p-4">
|
||||
<div class="mb-3">
|
||||
<h3 class="font-semibold">Category filters</h3>
|
||||
<p class="text-sm text-base-content/60">Choose categories to show in this block. Leave all unchecked to show every published event.</p>
|
||||
{@render field('Section title', block.data.title || '', (title) => updateData({ title }))}
|
||||
<div class="mt-3 rounded-box border border-base-300 p-4">
|
||||
<h3 class="font-semibold">Category filters</h3>
|
||||
<p class="mb-3 text-sm text-base-content/60">Choose categories to show in this block. Leave all unselected to show every published event.</p>
|
||||
{#if eventCategories?.length}
|
||||
<div class="flex flex-wrap gap-2">
|
||||
{#each eventCategories as category}
|
||||
<button type="button" class="btn btn-xs" class:btn-primary={(block.data.categories || []).includes(category)} aria-pressed={(block.data.categories || []).includes(category)} onclick={() => toggleCategory(category)}>{category}</button>
|
||||
{/each}
|
||||
</div>
|
||||
{#if eventCategories?.length}
|
||||
<div class="flex flex-wrap gap-2">
|
||||
{#each eventCategories as category}
|
||||
<label class="btn btn-sm" class:btn-primary={(block.data.categories || []).includes(category)}>
|
||||
<input class="hidden" type="checkbox" checked={(block.data.categories || []).includes(category)} onchange={() => toggleCategory(category)} />
|
||||
{category}
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<p class="text-sm text-base-content/60">No event categories exist yet. Create events in the Calendar admin page first.</p>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<p class="text-sm text-base-content/60">No event categories exist yet. Add categories to events in Calendar first.</p>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if block.type === 'shop'}
|
||||
<ShopBlockEditor {block} {items} {onChange} />
|
||||
|
|
@ -209,92 +165,31 @@
|
|||
<CheckoutBlockEditor {block} {onChange} />
|
||||
{/if}
|
||||
|
||||
<div class="rounded-box border border-base-300 p-4 mt-4">
|
||||
|
||||
<!-- Background Type Selector -->
|
||||
<div class="mb-4">
|
||||
<SegmentedControl
|
||||
label="Background"
|
||||
labelStyle="font-weight: 1000;"
|
||||
options={['none', 'color', 'image']}
|
||||
value={block.data._background?.type || 'none'}
|
||||
onChange={(v) => updateData({ _background: { ...(block.data._background || {}), type: v } })}
|
||||
/>
|
||||
</div>
|
||||
<div class="mt-6 space-y-3 rounded-box border border-base-300 p-4">
|
||||
<SegmentedControl label="Background" strong options={['none', 'color', 'image']} value={block.data._background?.type || 'none'} onChange={(type) => updateBackground({ type })} />
|
||||
|
||||
{#if block.data._background?.type === 'color'}
|
||||
<div class="space-y-3">
|
||||
<label class="form-control">
|
||||
<span class="label-text text-sm">Color</span>
|
||||
<div class="flex items-center gap-2">
|
||||
<input class="input input-bordered w-12 h-10 p-1 cursor-pointer" type="color" value={block.data._background?.color || '#66755d'} oninput={(e) => updateData({ _background: { ...(block.data._background || {}), color: e.currentTarget.value } })} />
|
||||
<input class="input input-bordered flex-1" placeholder="#66755d or sage" value={block.data._background?.color || ''} oninput={(e) => updateData({ _background: { ...(block.data._background || {}), color: e.currentTarget.value } })} />
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
<ColorField label="Color" value={block.data._background?.color || ''} fallback="#66755d" placeholder="#66755d" onChange={(color) => updateBackground({ color })} />
|
||||
{:else if block.data._background?.type === 'image'}
|
||||
<ImageUploader url={block.data._background?.imageUrl || ''} alt={block.data._background?.imageAlt || ''} onChange={(image) => updateBackground({ imageUrl: image.url, imageAlt: image.alt })} />
|
||||
<SegmentedControl label="Attachment" options={['scroll', 'fixed']} value={block.data._background?.attachment || 'scroll'} onChange={(attachment) => updateBackground({ attachment })} />
|
||||
<SegmentedControl
|
||||
label="Overlay"
|
||||
options={[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]}
|
||||
value={block.data._background?.overlay ? (block.data._background?.overlayOpacity ?? 40) : 0}
|
||||
onChange={(v) => updateBackground({ overlay: Number(v) > 0, overlayOpacity: Number(v) })}
|
||||
formatLabel={(v) => (Number(v) === 0 ? 'None' : `${v}%`)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if block.data._background?.type === 'image'}
|
||||
<div class="space-y-4">
|
||||
<ImageUploader url={block.data._background?.imageUrl || ''} alt={block.data._background?.imageAlt || ''} onChange={(image) => updateData({ _background: { ...(block.data._background || {}), imageUrl: image.url, imageAlt: image.alt } })} />
|
||||
<hr class="border-base-300" />
|
||||
|
||||
<SegmentedControl
|
||||
label="Attachment"
|
||||
options={['scroll', 'fixed']}
|
||||
value={block.data._background?.attachment || 'scroll'}
|
||||
onChange={(v) => updateData({ _background: { ...(block.data._background || {}), attachment: v } })}
|
||||
/>
|
||||
|
||||
<SegmentedControl
|
||||
label="Overlay"
|
||||
options={[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]}
|
||||
value={block.data._background?.overlayOpacity ?? 0}
|
||||
onChange={(v) => updateData({ _background: { ...(block.data._background || {}), overlay: true, overlayOpacity: v } })}
|
||||
formatLabel={(v) => `${v}%`}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<hr class="border-base-content/10 my-4" />
|
||||
|
||||
<SegmentedControl
|
||||
label="Foreground"
|
||||
labelStyle="font-weight: 1000;"
|
||||
options={['default', 'custom']}
|
||||
value={block.data._foreground?.mode || 'default'}
|
||||
onChange={(v) => updateData({ _foreground: { ...(block.data._foreground || {}), mode: v } })}
|
||||
/>
|
||||
<SegmentedControl label="Foreground" strong options={['default', 'custom']} value={block.data._foreground?.mode || 'default'} onChange={(mode) => updateForeground({ mode })} />
|
||||
|
||||
{#if block.data._foreground?.mode === 'custom'}
|
||||
<div class="mt-4 space-y-3">
|
||||
<div class="form-control">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="label-text w-24">Heading</span>
|
||||
<div class="flex flex-1 items-center gap-2">
|
||||
<input class="input input-bordered w-10 h-10 p-1 cursor-pointer" type="color" value={block.data._foreground?.headingColor || '#2c2c2c'} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), headingColor: e.currentTarget.value } })} />
|
||||
<input class="input input-bordered flex-1" placeholder="#2c2c2c" value={block.data._foreground?.headingColor || ''} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), headingColor: e.currentTarget.value } })} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="label-text w-24">Sub heading</span>
|
||||
<div class="flex flex-1 items-center gap-2">
|
||||
<input class="input input-bordered w-10 h-10 p-1 cursor-pointer" type="color" value={block.data._foreground?.subheadingColor || '#2c2c2c'} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), subheadingColor: e.currentTarget.value } })} />
|
||||
<input class="input input-bordered flex-1" placeholder="#2c2c2c" value={block.data._foreground?.subheadingColor || ''} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), subheadingColor: e.currentTarget.value } })} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="label-text w-24">Text</span>
|
||||
<div class="flex flex-1 items-center gap-2">
|
||||
<input class="input input-bordered w-10 h-10 p-1 cursor-pointer" type="color" value={block.data._foreground?.textColor || '#2c2c2c'} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), textColor: e.currentTarget.value } })} />
|
||||
<input class="input input-bordered flex-1" placeholder="#2c2c2c" value={block.data._foreground?.textColor || ''} oninput={(e) => updateData({ _foreground: { ...(block.data._foreground || {}), textColor: e.currentTarget.value } })} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<ColorField label="Heading" value={block.data._foreground?.headingColor || ''} fallback="#2c2c2c" onChange={(headingColor) => updateForeground({ headingColor })} />
|
||||
<ColorField label="Subheading" value={block.data._foreground?.subheadingColor || ''} fallback="#4a4a4a" onChange={(subheadingColor) => updateForeground({ subheadingColor })} />
|
||||
<ColorField label="Text" value={block.data._foreground?.textColor || ''} fallback="#2c2c2c" onChange={(textColor) => updateForeground({ textColor })} />
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -15,17 +15,17 @@
|
|||
</script>
|
||||
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Title</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Title</span>
|
||||
<input class="input w-full" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Heading</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.heading || ''} oninput={(e) => updateData({ heading: e.currentTarget.value })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Heading</span>
|
||||
<input class="input w-full" value={block.data.heading || ''} oninput={(e) => updateData({ heading: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Notes label</span></div>
|
||||
<input class="input input-bordered w-full" placeholder="Notes or special requests" value={block.data.notesLabel || ''} oninput={(e) => updateData({ notesLabel: e.currentTarget.value })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Notes label</span>
|
||||
<input class="input w-full" placeholder="Notes or special requests" value={block.data.notesLabel || ''} oninput={(e) => updateData({ notesLabel: e.currentTarget.value })} />
|
||||
</label>
|
||||
<p class="text-sm text-base-content/60">Customer fields (name, email, phone, notes) and the payment flow are fixed and cannot be changed here.</p>
|
||||
</div>
|
||||
|
|
|
|||
37
app-admin/src/lib/admin/editors/ColorField.svelte
Normal file
37
app-admin/src/lib/admin/editors/ColorField.svelte
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<script lang="ts">
|
||||
// Colour setting row: label column, swatch picker, free-text value (hex or
|
||||
// any CSS colour) and a clear button. Empty = "use the default".
|
||||
let {
|
||||
label,
|
||||
value = '',
|
||||
fallback = '#000000',
|
||||
placeholder = 'Default',
|
||||
onChange
|
||||
}: {
|
||||
label: string;
|
||||
value?: string;
|
||||
/** Swatch colour shown while the value is empty or not a hex colour. */
|
||||
fallback?: string;
|
||||
placeholder?: string;
|
||||
onChange: (value: string) => void;
|
||||
} = $props();
|
||||
|
||||
const isHex = (v: string) => /^#[0-9a-f]{6}$/i.test(v);
|
||||
</script>
|
||||
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="w-28 shrink-0 text-sm font-medium">{label}</span>
|
||||
<div class="join flex-1">
|
||||
<input
|
||||
class="input join-item w-12 cursor-pointer p-1"
|
||||
type="color"
|
||||
aria-label="{label} picker"
|
||||
value={isHex(value) ? value : fallback}
|
||||
oninput={(e) => onChange(e.currentTarget.value)}
|
||||
/>
|
||||
<input class="input join-item min-w-0 flex-1 font-mono text-sm" aria-label={label} {placeholder} {value} oninput={(e) => onChange(e.currentTarget.value.trim())} />
|
||||
{#if value}
|
||||
<button class="btn join-item" type="button" aria-label="Reset {label} to default" title="Reset to default" onclick={() => onChange('')}>✕</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
import RichTextEditor from './RichTextEditor.svelte';
|
||||
import ImageUploader from './ImageUploader.svelte';
|
||||
import SegmentedControl from './SegmentedControl.svelte';
|
||||
import ColorField from './ColorField.svelte';
|
||||
|
||||
let { block, primaryColor = '#8a9a7b', onChange = (block: EmailBlock) => {} } = $props<{
|
||||
block: EmailBlock | null;
|
||||
|
|
@ -17,11 +18,6 @@
|
|||
onChange(block);
|
||||
}
|
||||
|
||||
function titleCase(value: string | number) {
|
||||
const text = String(value);
|
||||
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||
}
|
||||
|
||||
const autoFilled: Record<string, string> = {
|
||||
booking_details: 'Filled in automatically with the booked services, date and time, prices and the total paid.',
|
||||
customer_details: "Filled in automatically with the customer's name, email, phone and checkout notes.",
|
||||
|
|
@ -42,46 +38,38 @@
|
|||
<div class="space-y-4">
|
||||
<ImageUploader url={block.data.url} alt={block.data.alt} onChange={(image) => updateData(image)} />
|
||||
<SegmentedControl label="Width" options={[100, 75, 50, 25]} value={Number(block.data.width) || 100} onChange={(v) => updateData({ width: v })} formatLabel={(v) => `${v}%`} />
|
||||
<SegmentedControl label="Alignment" options={['left', 'center', 'right']} value={block.data.alignment || 'center'} onChange={(v) => updateData({ alignment: v })} formatLabel={titleCase} />
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Link (optional)</span></div>
|
||||
<input class="input input-bordered w-full" placeholder="https://… or /page" value={block.data.href || ''} oninput={(e) => updateData({ href: e.currentTarget.value })} />
|
||||
<SegmentedControl label="Alignment" options={['left', 'center', 'right']} value={block.data.alignment || 'center'} onChange={(v) => updateData({ alignment: v })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Link (optional)</span>
|
||||
<input class="input w-full" placeholder="https://… or /page" value={block.data.href || ''} oninput={(e) => updateData({ href: e.currentTarget.value })} />
|
||||
</label>
|
||||
<p class="text-sm text-base-content/60">Images load from the public media server, so they only appear in real inboxes once the site runs on a public domain.</p>
|
||||
</div>
|
||||
{:else if block.type === 'button'}
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Button label</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.label || ''} oninput={(e) => updateData({ label: e.currentTarget.value })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Button label</span>
|
||||
<input class="input w-full" value={block.data.label || ''} oninput={(e) => updateData({ label: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">URL</span></div>
|
||||
<input class="input input-bordered w-full" placeholder={'https://…, /page or {{site_url}}'} value={block.data.href || ''} oninput={(e) => updateData({ href: e.currentTarget.value })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">URL</span>
|
||||
<input class="input w-full" placeholder={'https://…, /page or {{site_url}}'} value={block.data.href || ''} oninput={(e) => updateData({ href: e.currentTarget.value })} />
|
||||
</label>
|
||||
<SegmentedControl label="Alignment" options={['left', 'center', 'right']} value={block.data.alignment || 'center'} onChange={(v) => updateData({ alignment: v })} formatLabel={titleCase} />
|
||||
<div class="form-control">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="label-text w-24">Color</span>
|
||||
<div class="flex flex-1 items-center gap-2">
|
||||
<input class="input input-bordered h-10 w-10 cursor-pointer p-1" type="color" value={block.data.color || primaryColor} oninput={(e) => updateData({ color: e.currentTarget.value })} />
|
||||
<input class="input input-bordered flex-1" placeholder="Leave empty to use global primary" value={block.data.color || ''} oninput={(e) => updateData({ color: e.currentTarget.value })} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<SegmentedControl label="Alignment" options={['left', 'center', 'right']} value={block.data.alignment || 'center'} onChange={(v) => updateData({ alignment: v })} />
|
||||
<ColorField label="Color" value={block.data.color || ''} fallback={primaryColor} placeholder="Site primary color" onChange={(color) => updateData({ color })} />
|
||||
</div>
|
||||
{:else if block.type === 'spacer'}
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Height (px)</span></div>
|
||||
<input type="number" min="0" class="input input-bordered w-full" value={block.data.height ?? 24} oninput={(e) => updateData({ height: parseInt(e.currentTarget.value) || 0 })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Height (px)</span>
|
||||
<input type="number" min="0" class="input w-full" value={block.data.height ?? 24} oninput={(e) => updateData({ height: parseInt(e.currentTarget.value) || 0 })} />
|
||||
</label>
|
||||
{:else if block.type === 'divider'}
|
||||
<p class="text-base-content/60">A thin horizontal line. No settings.</p>
|
||||
{:else}
|
||||
<div class="space-y-3">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Section title</span></div>
|
||||
<input class="input input-bordered w-full" placeholder="Leave empty for no title" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Section title</span>
|
||||
<input class="input w-full" placeholder="Leave empty for no title" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
</label>
|
||||
<p class="text-sm text-base-content/60">{autoFilled[block.type]}</p>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@
|
|||
try {
|
||||
const result = await uploadMedia(file);
|
||||
localUrl = result.url;
|
||||
// Keep a hand-written alt text; otherwise use the one derived from the filename.
|
||||
if (!localAlt) localAlt = result.record?.alt || '';
|
||||
emitChange();
|
||||
} catch (e) {
|
||||
error = e instanceof Error ? e.message : 'Upload failed';
|
||||
|
|
@ -92,14 +94,14 @@
|
|||
/>
|
||||
|
||||
<!-- URL & Alt fields -->
|
||||
<div class="space-y-3">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Image URL</span></div>
|
||||
<input class="input input-bordered w-full" bind:value={localUrl} oninput={() => emitChange()} />
|
||||
<div>
|
||||
<label class="fieldset pt-0">
|
||||
<span class="fieldset-legend">Image URL</span>
|
||||
<input class="input w-full" bind:value={localUrl} oninput={() => emitChange()} />
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Alt text</span></div>
|
||||
<input class="input input-bordered w-full" bind:value={localAlt} oninput={() => emitChange()} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Alt text</span>
|
||||
<input class="input w-full" bind:value={localAlt} oninput={() => emitChange()} />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
<script lang="ts">
|
||||
// One row of mutually exclusive options with an optional label column on
|
||||
// the left — the standard "setting row" in the block editors (see
|
||||
// ColorField for the colour variant; both share the label column width).
|
||||
let {
|
||||
label,
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
formatLabel = (v: string | number) => String(v),
|
||||
labelStyle = '',
|
||||
formatLabel = (v: string | number) => {
|
||||
const text = String(v);
|
||||
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||
},
|
||||
strong = false,
|
||||
class: className = ''
|
||||
}: {
|
||||
label?: string;
|
||||
|
|
@ -13,26 +19,28 @@
|
|||
value: string | number;
|
||||
onChange: (value: string | number) => void;
|
||||
formatLabel?: (value: string | number) => string;
|
||||
labelStyle?: string;
|
||||
/** Bold label, for section-level settings like Background/Foreground. */
|
||||
strong?: boolean;
|
||||
class?: string;
|
||||
} = $props();
|
||||
</script>
|
||||
|
||||
<div class="form-control {className}">
|
||||
<div class="flex items-center justify-between">
|
||||
{#if label}
|
||||
<span class="label-text w-24" style={labelStyle}>{label}</span>
|
||||
{/if}
|
||||
<div class="grid flex-1" style="grid-template-columns: repeat({options.length}, 1fr)">
|
||||
{#each options as option, i}
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm {i === 0 ? 'rounded-r-none' : ''} {i === options.length - 1 ? 'rounded-l-none' : ''} {value === option ? 'btn-active' : ''}"
|
||||
onclick={() => onChange(option)}
|
||||
>
|
||||
{formatLabel(option)}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
<div class="flex items-center gap-3 {className}" role="group" aria-label={label}>
|
||||
{#if label}
|
||||
<span class="w-28 shrink-0 text-sm" class:font-bold={strong} class:font-medium={!strong}>{label}</span>
|
||||
{/if}
|
||||
<div class="join grid flex-1" style="grid-template-columns: repeat({options.length}, minmax(0, 1fr))">
|
||||
{#each options as option}
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm join-item px-1"
|
||||
class:btn-active={value === option}
|
||||
class:btn-primary={value === option}
|
||||
aria-pressed={value === option}
|
||||
onclick={() => onChange(option)}
|
||||
>
|
||||
{formatLabel(option)}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -33,9 +33,9 @@
|
|||
</script>
|
||||
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Title</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Title</span>
|
||||
<input class="input w-full" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
</label>
|
||||
|
||||
<SegmentedControl
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<script lang="ts">
|
||||
import { addMonths, createCalendarMonth, eventOverlapsDay, formatEventDateRange, sortEvents, toDateInput, toDatetimeInput } from '$lib/calendar';
|
||||
import { addMonths, createCalendarMonth, eventOverlapsDay, formatEventDateRange, sortEvents, toDateInput, toZonedDatetimeInput } from '$lib/calendar';
|
||||
import { confirmSubmit } from '$lib/admin/confirm';
|
||||
import Modal from '$lib/admin/Modal.svelte';
|
||||
import type { CalendarEventRecord } from '$lib/types';
|
||||
|
||||
let { data, form } = $props();
|
||||
|
|
@ -24,8 +26,8 @@
|
|||
let month = $derived(createCalendarMonth(viewDate));
|
||||
let action = $derived(draft.id ? '?/update' : '?/create');
|
||||
let dateInputType = $derived(draft.allDay ? 'date' : 'datetime-local');
|
||||
let startValue = $derived(draft.allDay ? toDateInput(draft.start) : toDatetimeInput(draft.start));
|
||||
let endValue = $derived(draft.allDay ? toDateInput(draft.end) : toDatetimeInput(draft.end));
|
||||
let startValue = $derived(draft.allDay ? toDateInput(draft.start) : toZonedDatetimeInput(draft.start, data.timezone));
|
||||
let endValue = $derived(draft.allDay ? toDateInput(draft.end) : toZonedDatetimeInput(draft.end, data.timezone));
|
||||
let allCategories = $derived([...new Set(events.flatMap((event) => event.categories || []))].sort((a, b) => a.localeCompare(b)));
|
||||
|
||||
function eventsForDay(date: Date) {
|
||||
|
|
@ -95,7 +97,7 @@
|
|||
<button class="btn btn-primary" type="button" onclick={() => createEvent()}>Create event</button>
|
||||
</div>
|
||||
|
||||
{#if form?.message}<div class="alert alert-error">{form.message}</div>{/if}
|
||||
{#if form?.message}<div class="alert alert-error" role="alert">{form.message}</div>{/if}
|
||||
|
||||
<div class="rounded-box bg-base-100 p-5 shadow">
|
||||
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||
|
|
@ -110,7 +112,7 @@
|
|||
<div class="mt-2 grid grid-cols-7 gap-2">
|
||||
{#each month.days as day}
|
||||
<div class="min-h-32 rounded-box border border-base-300 bg-base-200/60 p-2" class:opacity-40={!day.inMonth}>
|
||||
<button class="btn btn-ghost btn-xs mb-1" class:btn-primary={day.isToday} type="button" onclick={() => createEvent(day.dateKey)}>{day.dayNumber}</button>
|
||||
<button class="btn btn-circle btn-xs mb-1 {day.isToday ? 'btn-primary' : 'btn-ghost'}" type="button" title="Create an event on this day" aria-current={day.isToday ? 'date' : undefined} onclick={() => createEvent(day.dateKey)}>{day.dayNumber}</button>
|
||||
<div class="space-y-1">
|
||||
{#each eventsForDay(day.date) as event}
|
||||
<button class="w-full rounded-lg px-2 py-1 text-left text-xs font-semibold text-white shadow" style={`background:${event.color || '#8a9a7b'}`} type="button" onclick={() => editEvent(event)}>
|
||||
|
|
@ -130,7 +132,7 @@
|
|||
<table class="table">
|
||||
<thead><tr><th>Name</th><th>Date</th><th>Categories</th><th>Status</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{#each events as event}
|
||||
{#each events as event (event.id)}
|
||||
<tr>
|
||||
<td><span class="mr-2 inline-block h-3 w-3 rounded-full" style={`background:${event.color}`}></span>{event.name}</td>
|
||||
<td>{formatEventDateRange(event)}</td>
|
||||
|
|
@ -138,6 +140,8 @@
|
|||
<td><span class="badge" class:badge-success={event.published}>{event.published ? 'Published' : 'Draft'}</span></td>
|
||||
<td class="text-right"><button class="btn btn-sm" type="button" onclick={() => editEvent(event)}>Edit</button></td>
|
||||
</tr>
|
||||
{:else}
|
||||
<tr><td colspan="5" class="py-10 text-center text-base-content/60">No events yet — click a day or “Create event”.</td></tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -145,92 +149,81 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{#if showEditor}
|
||||
<div class="fixed inset-0 z-50 bg-black/50 p-4">
|
||||
<div class="mx-auto max-h-full max-w-2xl overflow-auto rounded-box bg-base-100 p-6 shadow-xl">
|
||||
<div class="mb-4 flex items-center justify-between gap-3">
|
||||
<h2 class="text-2xl font-bold">{draft.id ? 'Edit event' : 'Create event'}</h2>
|
||||
<button class="btn btn-ghost btn-sm" type="button" onclick={() => (showEditor = false)}>Close</button>
|
||||
</div>
|
||||
<Modal bind:open={showEditor} title={draft.id ? 'Edit event' : 'Create event'} wide>
|
||||
<form method="POST" action={action} class="space-y-1">
|
||||
<input type="hidden" name="id" value={draft.id} />
|
||||
<input type="hidden" name="allDay" value={draft.allDay ? 'true' : 'false'} />
|
||||
<input type="hidden" name="published" value={draft.published ? 'true' : 'false'} />
|
||||
<input type="hidden" name="categories" value={categoryText} />
|
||||
|
||||
<form method="POST" action={action} class="space-y-4">
|
||||
<input type="hidden" name="id" value={draft.id} />
|
||||
<input type="hidden" name="allDay" value={draft.allDay ? 'true' : 'false'} />
|
||||
<input type="hidden" name="published" value={draft.published ? 'true' : 'false'} />
|
||||
<input type="hidden" name="categories" value={categoryText} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Name</span>
|
||||
<input class="input w-full" name="name" required bind:value={draft.name} />
|
||||
</label>
|
||||
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Name</span></div>
|
||||
<input class="input input-bordered w-full" name="name" required bind:value={draft.name} />
|
||||
</label>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Start</span></div>
|
||||
<input class="input input-bordered w-full" type={dateInputType} name="start" required value={startValue} oninput={(e) => (draft = { ...draft, start: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">End optional</span></div>
|
||||
<input class="input input-bordered w-full" type={dateInputType} name="end" value={endValue} oninput={(e) => (draft = { ...draft, end: e.currentTarget.value })} />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<label class="label cursor-pointer justify-start gap-3">
|
||||
<input class="toggle toggle-primary" type="checkbox" bind:checked={draft.allDay} />
|
||||
<span class="label-text">All-day event</span>
|
||||
</label>
|
||||
<label class="label cursor-pointer justify-start gap-3">
|
||||
<input class="toggle toggle-success" type="checkbox" bind:checked={draft.published} />
|
||||
<span class="label-text">Published</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Description</span></div>
|
||||
<textarea class="textarea textarea-bordered min-h-28" name="description" bind:value={draft.description}></textarea>
|
||||
</label>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Color</span></div>
|
||||
<div class="flex gap-2">
|
||||
<input class="input input-bordered h-12 w-14 p-1" type="color" bind:value={draft.color} />
|
||||
<input class="input input-bordered flex-1" name="color" bind:value={draft.color} />
|
||||
</div>
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Link optional</span></div>
|
||||
<input class="input input-bordered w-full" name="link" placeholder="/page or https://..." bind:value={draft.link} />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="rounded-box border border-base-300 p-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Categories comma-separated</span></div>
|
||||
<input class="input input-bordered w-full" value={categoryText} oninput={(e) => syncCategoryText(e.currentTarget.value)} />
|
||||
</label>
|
||||
{#if allCategories.length}
|
||||
<div class="mt-3 flex flex-wrap gap-2">
|
||||
{#each allCategories as category}
|
||||
<button class="btn btn-xs" class:btn-primary={draft.categories.includes(category)} type="button" onclick={() => draft.categories.includes(category) ? removeCategory(category) : addCategory(category)}>{category}</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="flex justify-between gap-2 pt-2">
|
||||
{#if draft.id}
|
||||
<button class="btn btn-error" type="submit" formaction="?/delete">Delete</button>
|
||||
{:else}
|
||||
<span></span>
|
||||
{/if}
|
||||
<div class="flex gap-2">
|
||||
<button class="btn" type="button" onclick={() => (showEditor = false)}>Cancel</button>
|
||||
<button class="btn btn-primary" type="submit">Save event</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="grid gap-x-4 md:grid-cols-2">
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Start{draft.allDay ? '' : ` (${data.timezone})`}</span>
|
||||
<input class="input w-full" type={dateInputType} name="start" required value={startValue} oninput={(e) => (draft = { ...draft, start: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">End <span class="font-normal text-base-content/50">(optional)</span></span>
|
||||
<input class="input w-full" type={dateInputType} name="end" min={startValue} value={endValue} oninput={(e) => (draft = { ...draft, end: e.currentTarget.value })} />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-wrap gap-6 py-2">
|
||||
<label class="label cursor-pointer gap-3 text-base-content">
|
||||
<input class="toggle toggle-primary" type="checkbox" bind:checked={draft.allDay} />
|
||||
All-day event
|
||||
</label>
|
||||
<label class="label cursor-pointer gap-3 text-base-content">
|
||||
<input class="toggle toggle-success" type="checkbox" bind:checked={draft.published} />
|
||||
Published
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Description</span>
|
||||
<textarea class="textarea min-h-28 w-full" name="description" bind:value={draft.description}></textarea>
|
||||
</label>
|
||||
|
||||
<div class="grid gap-x-4 md:grid-cols-2">
|
||||
<div class="fieldset">
|
||||
<span class="fieldset-legend">Color</span>
|
||||
<div class="flex gap-2">
|
||||
<input class="input w-14 cursor-pointer p-1" type="color" aria-label="Pick color" bind:value={draft.color} />
|
||||
<input class="input flex-1 font-mono" name="color" aria-label="Color value" bind:value={draft.color} />
|
||||
</div>
|
||||
</div>
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Link <span class="font-normal text-base-content/50">(optional)</span></span>
|
||||
<input class="input w-full" name="link" placeholder="/page or https://..." bind:value={draft.link} />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="fieldset">
|
||||
<label class="fieldset-legend" for="event-categories">Categories <span class="font-normal text-base-content/50">(comma-separated)</span></label>
|
||||
<input id="event-categories" class="input w-full" value={categoryText} oninput={(e) => syncCategoryText(e.currentTarget.value)} />
|
||||
{#if allCategories.length}
|
||||
<div class="mt-1 flex flex-wrap gap-2">
|
||||
{#each allCategories as category}
|
||||
<button class="btn btn-xs" class:btn-primary={draft.categories.includes(category)} type="button" onclick={() => draft.categories.includes(category) ? removeCategory(category) : addCategory(category)}>{category}</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="modal-action justify-between">
|
||||
{#if draft.id}
|
||||
<button class="btn btn-error btn-outline" type="submit" formaction="?/delete" formnovalidate onclick={confirmSubmit(`Delete the event "${draft.name}"?`)}>Delete</button>
|
||||
{:else}
|
||||
<span></span>
|
||||
{/if}
|
||||
<div class="flex gap-2">
|
||||
<button class="btn" type="button" onclick={() => (showEditor = false)}>Cancel</button>
|
||||
<button class="btn btn-primary" type="submit">Save event</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
|
|
|
|||
|
|
@ -1,96 +1,148 @@
|
|||
<script lang="ts">
|
||||
import { enhance } from '$app/forms';
|
||||
import ImageUploader from '$lib/admin/editors/ImageUploader.svelte';
|
||||
import type { SubmitFunction } from '@sveltejs/kit';
|
||||
|
||||
let { data } = $props();
|
||||
let { data, form } = $props();
|
||||
let header = $state(structuredClone(data.header.data));
|
||||
let footer = $state(structuredClone(data.footer.data));
|
||||
let colors = $state(structuredClone(data.colors.data));
|
||||
let saving = $state('');
|
||||
// Older records may predate the CTA button; the inputs below need an object.
|
||||
header.ctaButton ??= { label: '', href: '' };
|
||||
|
||||
function addHeaderLink() { header.navLinks = [...(header.navLinks || []), { label: '', href: '' }]; }
|
||||
function addSocial() { footer.socialLinks = [...(footer.socialLinks || []), { platform: '', url: '' }]; }
|
||||
|
||||
const footerFields = [
|
||||
{ key: 'businessName', label: 'Business name' },
|
||||
{ key: 'tagline', label: 'Tagline' },
|
||||
{ key: 'address', label: 'Address' },
|
||||
{ key: 'phone', label: 'Phone' },
|
||||
{ key: 'email', label: 'Email', hint: 'Also used as the reply-to and alert address for booking emails.' },
|
||||
{ key: 'copyrightText', label: 'Copyright text' }
|
||||
];
|
||||
|
||||
const colorFields = [
|
||||
{ key: 'background', label: 'Background' },
|
||||
{ key: 'heading', label: 'Headings' },
|
||||
{ key: 'subheading', label: 'Subheadings' },
|
||||
{ key: 'text', label: 'Body text' },
|
||||
{ key: 'primary', label: 'Primary', hint: 'Buttons and links' },
|
||||
{ key: 'accent', label: 'Accent', hint: 'Highlights' }
|
||||
];
|
||||
|
||||
const isHex = (value: unknown) => typeof value === 'string' && /^#[0-9a-f]{6}$/i.test(value);
|
||||
|
||||
const submit: SubmitFunction = ({ formData }) => {
|
||||
saving = String(formData.get('section'));
|
||||
return async ({ update }) => {
|
||||
await update({ reset: false, invalidateAll: false });
|
||||
saving = '';
|
||||
};
|
||||
};
|
||||
</script>
|
||||
|
||||
<svelte:head><title>Globals | CMS</title></svelte:head>
|
||||
|
||||
{#snippet status(section: string)}
|
||||
{#if form?.section === section && form.message}
|
||||
<div class="alert mt-4 py-2 text-sm" class:alert-success={form.ok} class:alert-error={!form.ok} role="status">{form.message}</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
{#snippet saveButton(section: string, label: string)}
|
||||
<div class="flex-grow"></div>
|
||||
{@render status(section)}
|
||||
<button class="btn btn-primary mt-4 w-full" type="submit" disabled={saving !== ''}>
|
||||
{#if saving === section}<span class="loading loading-spinner loading-sm"></span>{/if}
|
||||
{label}
|
||||
</button>
|
||||
{/snippet}
|
||||
|
||||
<div class="mb-6">
|
||||
<h1 class="text-3xl font-bold">Global sections</h1>
|
||||
<p class="text-base-content/60">Edit the site header, footer, and global color settings.</p>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-6 xl:grid-cols-3">
|
||||
<form class="rounded-box bg-base-100 p-5 shadow flex flex-col" method="POST" action="?/save">
|
||||
<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" />
|
||||
<input type="hidden" name="data" value={JSON.stringify(header)} />
|
||||
<h2 class="mb-4 text-2xl font-bold">Header</h2>
|
||||
<h3 class="mb-2 font-bold">Logo</h3>
|
||||
<ImageUploader url={header.logo?.url} alt={header.logo?.alt} onChange={(image) => (header.logo = image)} />
|
||||
<h3 class="mt-6 font-bold">Navigation</h3>
|
||||
{#each header.navLinks || [] as link, i}
|
||||
<div class="my-2 grid grid-cols-[1fr_1fr_auto] gap-2">
|
||||
<input class="input input-bordered" bind:value={link.label} placeholder="Label" />
|
||||
<input class="input input-bordered" bind:value={link.href} placeholder="Href" />
|
||||
<button class="btn btn-error btn-outline" type="button" onclick={() => (header.navLinks = header.navLinks.filter((_: unknown, index: number) => index !== i))}>×</button>
|
||||
<input class="input" aria-label="Link label" bind:value={link.label} placeholder="Label" />
|
||||
<input class="input" aria-label="Link address" bind:value={link.href} placeholder="/page" />
|
||||
<button class="btn btn-error btn-outline btn-square" type="button" aria-label="Remove link" onclick={() => (header.navLinks = header.navLinks.filter((_: unknown, index: number) => index !== i))}>✕</button>
|
||||
</div>
|
||||
{/each}
|
||||
<button class="btn btn-sm" type="button" onclick={addHeaderLink}>Add link</button>
|
||||
<h3 class="mt-6 font-bold">CTA button</h3>
|
||||
<input class="input input-bordered mb-2 w-full" bind:value={header.ctaButton.label} placeholder="Label" />
|
||||
<input class="input input-bordered w-full" bind:value={header.ctaButton.href} placeholder="Href" />
|
||||
<h3 class="mt-6 font-bold">Home page</h3>
|
||||
<select class="select select-bordered w-full" bind:value={header.homePage}>
|
||||
<button class="btn btn-sm mt-1" type="button" onclick={addHeaderLink}>Add link</button>
|
||||
<h3 class="mt-6 mb-2 font-bold">CTA button</h3>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<input class="input w-full" aria-label="Button label" bind:value={header.ctaButton.label} placeholder="Label" />
|
||||
<input class="input w-full" aria-label="Button address" bind:value={header.ctaButton.href} placeholder="/book" />
|
||||
</div>
|
||||
<h3 class="mt-6 mb-2 font-bold">Home page</h3>
|
||||
<select class="select w-full" aria-label="Home page" bind:value={header.homePage}>
|
||||
<option value="">— Select a page —</option>
|
||||
{#each data.pages as page}
|
||||
{#each data.pages as page (page.id)}
|
||||
<option value={page.slug}>{page.title} [{page.slug}]</option>
|
||||
{/each}
|
||||
</select>
|
||||
<p class="text-sm text-base-content/60 mt-1">The page that "/" will redirect to.</p>
|
||||
<div class="flex-grow"></div>
|
||||
<button class="btn btn-primary mt-6 block w-full" type="submit">Save header</button>
|
||||
<p class="mt-1 text-sm text-base-content/60">The page that "/" will redirect to.</p>
|
||||
{@render saveButton('header', 'Save header')}
|
||||
</form>
|
||||
|
||||
<form class="rounded-box bg-base-100 p-5 shadow flex flex-col" method="POST" action="?/save">
|
||||
<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.footer.id} />
|
||||
<input type="hidden" name="section" value="footer" />
|
||||
<input type="hidden" name="data" value={JSON.stringify(footer)} />
|
||||
<h2 class="mb-4 text-2xl font-bold">Footer</h2>
|
||||
{#each ['businessName', 'tagline', 'address', 'phone', 'email', 'copyrightText'] as field}
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">{field}</span></div>
|
||||
<input class="input input-bordered w-full" bind:value={footer[field]} />
|
||||
{#each footerFields as field (field.key)}
|
||||
<label class="fieldset py-1">
|
||||
<span class="fieldset-legend pb-0">{field.label}</span>
|
||||
{#if field.key === 'address'}
|
||||
<textarea class="textarea w-full" rows="2" bind:value={footer[field.key]}></textarea>
|
||||
{:else}
|
||||
<input class="input w-full" type={field.key === 'email' ? 'email' : 'text'} bind:value={footer[field.key]} />
|
||||
{/if}
|
||||
{#if field.hint}<span class="label">{field.hint}</span>{/if}
|
||||
</label>
|
||||
{/each}
|
||||
<h3 class="mt-6 font-bold">Social links</h3>
|
||||
{#each footer.socialLinks || [] as link, i}
|
||||
<div class="my-2 grid grid-cols-[1fr_1fr_auto] gap-2">
|
||||
<input class="input input-bordered" bind:value={link.platform} placeholder="Platform" />
|
||||
<input class="input input-bordered" bind:value={link.url} placeholder="URL" />
|
||||
<button class="btn btn-error btn-outline" type="button" onclick={() => (footer.socialLinks = footer.socialLinks.filter((_: unknown, index: number) => index !== i))}>×</button>
|
||||
<input class="input" aria-label="Platform" bind:value={link.platform} placeholder="Platform" />
|
||||
<input class="input" aria-label="Profile URL" bind:value={link.url} placeholder="https://…" />
|
||||
<button class="btn btn-error btn-outline btn-square" type="button" aria-label="Remove social link" onclick={() => (footer.socialLinks = footer.socialLinks.filter((_: unknown, index: number) => index !== i))}>✕</button>
|
||||
</div>
|
||||
{/each}
|
||||
<button class="btn btn-sm" type="button" onclick={addSocial}>Add social link</button>
|
||||
<div class="flex-grow"></div>
|
||||
<button class="btn btn-primary mt-6 block w-full" type="submit">Save footer</button>
|
||||
<button class="btn btn-sm mt-1" type="button" onclick={addSocial}>Add social link</button>
|
||||
{@render saveButton('footer', 'Save footer')}
|
||||
</form>
|
||||
|
||||
<form class="rounded-box bg-base-100 p-5 shadow flex flex-col" method="POST" action="?/save">
|
||||
<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.colors.id} />
|
||||
<input type="hidden" name="section" value="colors" />
|
||||
<input type="hidden" name="data" value={JSON.stringify(colors)} />
|
||||
<h2 class="mb-4 text-2xl font-bold">Colors</h2>
|
||||
<p class="text-sm text-base-content/60 mb-4">These colors are applied across the site as defaults.</p>
|
||||
{#each [
|
||||
{ key: 'background', label: 'Background color' },
|
||||
{ key: 'heading', label: 'Heading color' },
|
||||
{ key: 'subheading', label: 'Subheading color' },
|
||||
{ key: 'text', label: 'Text color' },
|
||||
{ key: 'primary', label: 'Primary color (buttons, links)' },
|
||||
{ key: 'accent', label: 'Accent color (highlights)' }
|
||||
] as { key, label }}
|
||||
<label class="form-control w-full mb-3">
|
||||
<div class="label"><span class="label-text">{label}</span></div>
|
||||
<p class="mb-2 text-sm text-base-content/60">Default colors for the public site. Individual blocks can override them.</p>
|
||||
{#each colorFields as field (field.key)}
|
||||
<div class="fieldset py-1">
|
||||
<label class="fieldset-legend pb-0" for="color-{field.key}">
|
||||
{field.label}{#if field.hint}<span class="font-normal text-base-content/50">— {field.hint}</span>{/if}
|
||||
</label>
|
||||
<div class="flex gap-2">
|
||||
<input type="color" class="cursor-pointer" bind:value={colors[key]} />
|
||||
<input type="text" class="input input-bordered flex-1 font-mono text-sm" bind:value={colors[key]} />
|
||||
<input type="color" class="input w-14 cursor-pointer p-1" aria-label="{field.label} picker" value={isHex(colors[field.key]) ? colors[field.key] : '#000000'} oninput={(e) => (colors[field.key] = e.currentTarget.value)} />
|
||||
<input id="color-{field.key}" type="text" class="input flex-1 font-mono text-sm" bind:value={colors[field.key]} />
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
{/each}
|
||||
<div class="flex-grow"></div>
|
||||
<button class="btn btn-primary mt-6 block w-full" type="submit">Save colors</button>
|
||||
{@render saveButton('colors', 'Save colors')}
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,15 @@
|
|||
<script lang="ts">
|
||||
import { uploadMedia } from '$lib/pb';
|
||||
import { confirmSubmit } from '$lib/admin/confirm';
|
||||
import Modal from '$lib/admin/Modal.svelte';
|
||||
import type { ItemRecord, ItemType } from '$lib/types';
|
||||
|
||||
let { data, form } = $props();
|
||||
let items = $derived(data.items || []);
|
||||
let showEditor = $state(false);
|
||||
let uploading = $state(false);
|
||||
let uploadError = $state('');
|
||||
let fileInput: HTMLInputElement | undefined = $state();
|
||||
|
||||
type ItemDraft = {
|
||||
id: string;
|
||||
|
|
@ -22,7 +27,7 @@
|
|||
let draft = $state<ItemDraft>(emptyDraft());
|
||||
let action = $derived(draft.id ? '?/update' : '?/create');
|
||||
|
||||
const eur = new Intl.NumberFormat(undefined, { style: 'currency', currency: 'EUR' });
|
||||
let money = $derived(new Intl.NumberFormat('en-GB', { style: 'currency', currency: data.currency }));
|
||||
|
||||
function emptyDraft(): ItemDraft {
|
||||
return { id: '', name: '', description: '', price: 0, image: '', imageUrl: '', type: 'item', stock: '', duration: '', active: true };
|
||||
|
|
@ -30,6 +35,7 @@
|
|||
|
||||
function createItem() {
|
||||
draft = emptyDraft();
|
||||
uploadError = '';
|
||||
showEditor = true;
|
||||
}
|
||||
|
||||
|
|
@ -46,6 +52,7 @@
|
|||
duration: item.duration == null ? '' : String(item.duration),
|
||||
active: item.active
|
||||
};
|
||||
uploadError = '';
|
||||
showEditor = true;
|
||||
}
|
||||
|
||||
|
|
@ -54,16 +61,12 @@
|
|||
const file = input.files?.[0];
|
||||
if (!file) return;
|
||||
uploading = true;
|
||||
uploadError = '';
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('alt', file.name.replace(/\.[^/.]+$/, '').replace(/[-_]/g, ' '));
|
||||
const res = await fetch('/api/upload', { method: 'POST', body: formData });
|
||||
if (!res.ok) throw new Error(`Upload failed (${res.status})`);
|
||||
const result = await res.json();
|
||||
const result = await uploadMedia(file);
|
||||
draft = { ...draft, image: result.record.id, imageUrl: result.url };
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
uploadError = err instanceof Error ? err.message : 'Upload failed.';
|
||||
} finally {
|
||||
uploading = false;
|
||||
input.value = '';
|
||||
|
|
@ -82,30 +85,34 @@
|
|||
<button class="btn btn-primary" type="button" onclick={() => createItem()}>Create item</button>
|
||||
</div>
|
||||
|
||||
{#if form?.message}<div class="alert alert-error">{form.message}</div>{/if}
|
||||
{#if form?.message}<div class="alert alert-error" role="alert">{form.message}</div>{/if}
|
||||
|
||||
<div class="rounded-box bg-base-100 p-5 shadow">
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table">
|
||||
<thead><tr><th>Name</th><th>Type</th><th>Price</th><th>Stock</th><th>Duration</th><th>Status</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{#each items as item}
|
||||
{#each items as item (item.id)}
|
||||
<tr>
|
||||
<td>
|
||||
<div class="flex items-center gap-3">
|
||||
{#if item.imageUrl}
|
||||
<img class="h-10 w-10 rounded-box object-cover" src={item.imageUrl} alt="" />
|
||||
<img class="size-10 rounded-box object-cover" src={item.imageUrl} alt="" />
|
||||
{:else}
|
||||
<div class="size-10 rounded-box bg-base-200"></div>
|
||||
{/if}
|
||||
<span class="font-semibold">{item.name}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td><span class="badge">{item.type === 'item_with_time' ? 'Service' : 'Product'}</span></td>
|
||||
<td>{eur.format(item.price)}</td>
|
||||
<td>{item.type === 'item' ? (item.stock ?? '—') : '—'}</td>
|
||||
<td>{money.format(item.price)}</td>
|
||||
<td>{item.type === 'item' ? (item.stock ?? '∞') : '—'}</td>
|
||||
<td>{item.type === 'item_with_time' ? `${item.duration ?? 0} min` : '—'}</td>
|
||||
<td><span class="badge" class:badge-success={item.active}>{item.active ? 'Active' : 'Inactive'}</span></td>
|
||||
<td class="text-right"><button class="btn btn-sm" type="button" onclick={() => editItem(item)}>Edit</button></td>
|
||||
</tr>
|
||||
{:else}
|
||||
<tr><td colspan="7" class="py-10 text-center text-base-content/60">No items yet — create a service or product.</td></tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -113,87 +120,84 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{#if showEditor}
|
||||
<div class="fixed inset-0 z-50 bg-black/50 p-4">
|
||||
<div class="mx-auto max-h-full max-w-2xl overflow-auto rounded-box bg-base-100 p-6 shadow-xl">
|
||||
<div class="mb-4 flex items-center justify-between gap-3">
|
||||
<h2 class="text-2xl font-bold">{draft.id ? 'Edit item' : 'Create item'}</h2>
|
||||
<button class="btn btn-ghost btn-sm" type="button" onclick={() => (showEditor = false)}>Close</button>
|
||||
</div>
|
||||
<Modal bind:open={showEditor} title={draft.id ? 'Edit item' : 'Create item'} wide>
|
||||
<form method="POST" action={action} class="space-y-1">
|
||||
<input type="hidden" name="id" value={draft.id} />
|
||||
<input type="hidden" name="active" value={draft.active ? 'true' : 'false'} />
|
||||
<input type="hidden" name="image" value={draft.image} />
|
||||
|
||||
<form method="POST" action={action} class="space-y-4">
|
||||
<input type="hidden" name="id" value={draft.id} />
|
||||
<input type="hidden" name="active" value={draft.active ? 'true' : 'false'} />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Name</span>
|
||||
<input class="input w-full" name="name" required bind:value={draft.name} />
|
||||
</label>
|
||||
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Name</span></div>
|
||||
<input class="input input-bordered w-full" name="name" required bind:value={draft.name} />
|
||||
</label>
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Description</span>
|
||||
<textarea class="textarea min-h-28 w-full" name="description" bind:value={draft.description}></textarea>
|
||||
</label>
|
||||
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Description</span></div>
|
||||
<textarea class="textarea textarea-bordered min-h-28" name="description" bind:value={draft.description}></textarea>
|
||||
</label>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Price</span></div>
|
||||
<input class="input input-bordered w-full" type="number" step="0.01" min="0" name="price" required bind:value={draft.price} />
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Type</span></div>
|
||||
<select class="select select-bordered w-full" name="type" bind:value={draft.type}>
|
||||
<option value="item">Product</option>
|
||||
<option value="item_with_time">Service</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{#if draft.type === 'item'}
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Stock</span></div>
|
||||
<input class="input input-bordered w-full" type="number" min="0" step="1" name="stock" placeholder="Unlimited when empty" bind:value={draft.stock} />
|
||||
</label>
|
||||
{:else}
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Duration minutes</span></div>
|
||||
<input class="input input-bordered w-full" type="number" min="0" step="1" name="duration" placeholder="60" bind:value={draft.duration} />
|
||||
</label>
|
||||
{/if}
|
||||
|
||||
<div class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Image</span></div>
|
||||
<div class="flex items-start gap-3">
|
||||
{#if draft.imageUrl}
|
||||
<img class="h-16 w-16 rounded-box object-cover" src={draft.imageUrl} alt="" />
|
||||
{/if}
|
||||
<div class="flex-1 space-y-2">
|
||||
<input class="input input-bordered w-full" name="image" placeholder="Media record id" bind:value={draft.image} />
|
||||
<input class="file-input file-input-bordered file-input-sm w-full" type="file" accept="image/*" disabled={uploading} onchange={onImageSelected} />
|
||||
<p class="text-xs text-base-content/60">
|
||||
{uploading ? 'Uploading…' : 'Upload a file or paste a media record id. A media picker will replace this in a later iteration.'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="label cursor-pointer justify-start gap-3">
|
||||
<input class="toggle toggle-success" type="checkbox" bind:checked={draft.active} />
|
||||
<span class="label-text">Active</span>
|
||||
</label>
|
||||
|
||||
<div class="flex justify-between gap-2 pt-2">
|
||||
{#if draft.id}
|
||||
<button class="btn btn-error" type="submit" formaction="?/delete">Delete</button>
|
||||
{:else}
|
||||
<span></span>
|
||||
{/if}
|
||||
<div class="flex gap-2">
|
||||
<button class="btn" type="button" onclick={() => (showEditor = false)}>Cancel</button>
|
||||
<button class="btn btn-primary" type="submit">Save item</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="grid gap-x-4 md:grid-cols-2">
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Price ({data.currency})</span>
|
||||
<input class="input w-full" type="number" step="0.01" min="0" name="price" required bind:value={draft.price} />
|
||||
</label>
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Type</span>
|
||||
<select class="select w-full" name="type" bind:value={draft.type}>
|
||||
<option value="item">Product</option>
|
||||
<option value="item_with_time">Service (bookable)</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if draft.type === 'item'}
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Stock</span>
|
||||
<input class="input w-full" type="number" min="0" step="1" name="stock" placeholder="Unlimited when empty" bind:value={draft.stock} />
|
||||
</label>
|
||||
{:else}
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Duration (minutes)</span>
|
||||
<input class="input w-full" type="number" min="1" step="1" name="duration" placeholder="60" required bind:value={draft.duration} />
|
||||
</label>
|
||||
{/if}
|
||||
|
||||
<div class="fieldset">
|
||||
<span class="fieldset-legend">Image</span>
|
||||
<div class="flex items-center gap-4">
|
||||
{#if draft.imageUrl}
|
||||
<img class="size-20 rounded-box object-cover shadow" src={draft.imageUrl} alt="" />
|
||||
{:else}
|
||||
<div class="grid size-20 place-items-center rounded-box border-2 border-dashed border-base-300 text-xs text-base-content/40">No image</div>
|
||||
{/if}
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<button class="btn btn-sm" type="button" disabled={uploading} onclick={() => fileInput?.click()}>
|
||||
{#if uploading}<span class="loading loading-spinner loading-xs"></span> Uploading…{:else}{draft.imageUrl ? 'Replace image' : 'Upload image'}{/if}
|
||||
</button>
|
||||
{#if draft.image}
|
||||
<button class="btn btn-ghost btn-sm text-error" type="button" onclick={() => (draft = { ...draft, image: '', imageUrl: '' })}>Remove</button>
|
||||
{/if}
|
||||
</div>
|
||||
<input class="hidden" type="file" accept="image/*" bind:this={fileInput} onchange={onImageSelected} />
|
||||
</div>
|
||||
{#if uploadError}<span class="label text-error">{uploadError}</span>{/if}
|
||||
</div>
|
||||
|
||||
<label class="label mt-2 cursor-pointer gap-3 text-base-content">
|
||||
<input class="toggle toggle-success" type="checkbox" bind:checked={draft.active} />
|
||||
Active <span class="text-base-content/60">— inactive items are hidden from the shop</span>
|
||||
</label>
|
||||
|
||||
<div class="modal-action justify-between">
|
||||
{#if draft.id}
|
||||
<button class="btn btn-error btn-outline" type="submit" formaction="?/delete" formnovalidate onclick={confirmSubmit(`Delete "${draft.name}"?`)}>Delete</button>
|
||||
{:else}
|
||||
<span></span>
|
||||
{/if}
|
||||
<div class="flex gap-2">
|
||||
<button class="btn" type="button" onclick={() => (showEditor = false)}>Cancel</button>
|
||||
<button class="btn btn-primary" type="submit" disabled={uploading}>Save item</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
<script lang="ts">
|
||||
import { enhance } from '$app/forms';
|
||||
import { formatDateTime } from '$lib/calendar';
|
||||
|
||||
let { data, form } = $props();
|
||||
let orders = $derived(data.orders || []);
|
||||
let resending = $state('');
|
||||
|
||||
const eur = new Intl.NumberFormat(undefined, { style: 'currency', currency: 'EUR' });
|
||||
let money = $derived(new Intl.NumberFormat('en-GB', { style: 'currency', currency: data.currency }));
|
||||
</script>
|
||||
|
||||
{#snippet emailStatus(order: (typeof orders)[number], kind: 'customer' | 'client', label: string, sentAt: string)}
|
||||
|
|
@ -23,7 +24,7 @@
|
|||
>
|
||||
<input type="hidden" name="orderId" value={order.id} />
|
||||
<input type="hidden" name="kind" value={kind} />
|
||||
<span class="badge badge-sm" class:badge-success={sentAt} class:badge-ghost={!sentAt} title={sentAt ? new Date(sentAt).toLocaleString() : 'Not sent'}>
|
||||
<span class="badge badge-sm" class:badge-success={sentAt} class:badge-ghost={!sentAt} title={sentAt ? `Sent ${formatDateTime(sentAt, data.timezone)}` : 'Not sent'}>
|
||||
{label}: {sentAt ? 'sent' : 'not sent'}
|
||||
</span>
|
||||
<button class="btn btn-ghost btn-xs" type="submit" disabled={resending !== ''}>
|
||||
|
|
@ -37,14 +38,14 @@
|
|||
<div class="space-y-6">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold">Orders</h1>
|
||||
<p class="text-base-content/60">Confirmed bookings and purchases.</p>
|
||||
<p class="text-base-content/60">Bookings and purchases from the shop.</p>
|
||||
</div>
|
||||
|
||||
{#if orders.length === 0}
|
||||
<div class="rounded-box bg-base-100 p-8 text-center text-base-content/60 shadow">No orders yet.</div>
|
||||
{/if}
|
||||
|
||||
{#each orders as order}
|
||||
{#each orders as order (order.id)}
|
||||
<div class="rounded-box bg-base-100 p-5 shadow">
|
||||
<div class="flex flex-col justify-between gap-3 md:flex-row md:items-center">
|
||||
<div>
|
||||
|
|
@ -52,7 +53,7 @@
|
|||
<p class="text-sm text-base-content/60">
|
||||
{order.email}
|
||||
{#if order.customerDetails?.phone} · {order.customerDetails.phone}{/if}
|
||||
{#if order.created} · {new Date(order.created).toLocaleString()}{/if}
|
||||
{#if order.created} · {formatDateTime(order.created, data.timezone)}{/if}
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
|
|
@ -62,16 +63,16 @@
|
|||
class:badge-warning={order.status === 'pending'}
|
||||
class:badge-error={order.status === 'refunded'}
|
||||
>{order.status}</span>
|
||||
<span class="text-lg font-bold">{eur.format(order.total)}</span>
|
||||
<span class="text-lg font-bold">{money.format(order.total)}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul class="mt-4 space-y-1 border-t border-base-300 pt-4">
|
||||
{#each order.lines as line}
|
||||
<li>
|
||||
{line.quantity}× {line.name} — {eur.format(line.price)}
|
||||
{line.quantity}× {line.name} — {money.format(line.price)}
|
||||
{#if line.lineType === 'slot' && line.start}
|
||||
<span class="block text-sm text-base-content/60">{new Date(line.start).toLocaleString()}</span>
|
||||
<span class="block text-sm text-base-content/60">{formatDateTime(line.start, data.timezone)}</span>
|
||||
{/if}
|
||||
</li>
|
||||
{/each}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,13 @@
|
|||
<script lang="ts">
|
||||
import { env } from '$env/dynamic/public';
|
||||
import { confirmSubmit } from '$lib/admin/confirm';
|
||||
import Modal from '$lib/admin/Modal.svelte';
|
||||
|
||||
let { data, form } = $props();
|
||||
let showCreate = $state(false);
|
||||
|
||||
const siteUrl = (env.PUBLIC_SITE_URL || '').replace(/\/$/, '');
|
||||
const publicUrl = (slug: string) => `${siteUrl}/${slug === 'home' ? '' : slug}`;
|
||||
</script>
|
||||
|
||||
<svelte:head><title>Pages | CMS</title></svelte:head>
|
||||
|
|
@ -9,11 +17,11 @@
|
|||
<h1 class="text-3xl font-bold">Pages</h1>
|
||||
<p class="text-base-content/60">Create, edit, preview, and publish website pages.</p>
|
||||
</div>
|
||||
<button class="btn btn-primary" onclick={() => (document.getElementById('new-page') as HTMLDialogElement)?.showModal()}>New page</button>
|
||||
<button class="btn btn-primary" type="button" onclick={() => (showCreate = true)}>New page</button>
|
||||
</div>
|
||||
|
||||
{#if form?.message}
|
||||
<div class="alert alert-error mb-4">{form.message}</div>
|
||||
<div class="alert alert-error mb-4" role="alert">{form.message}</div>
|
||||
{/if}
|
||||
|
||||
<div class="overflow-x-auto rounded-box bg-base-100 shadow">
|
||||
|
|
@ -22,44 +30,50 @@
|
|||
<tr><th>Slug</th><th>Title</th><th>Status</th><th class="text-right">Actions</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each data.pages as page}
|
||||
{#each data.pages as page (page.id)}
|
||||
<tr>
|
||||
<td class="font-mono">{page.slug}</td>
|
||||
<td>{page.title}</td>
|
||||
<td><span class="badge" class:badge-success={page.published}>{page.published ? 'Published' : 'Draft'}</span></td>
|
||||
<td class="flex justify-end gap-2">
|
||||
<a class="btn btn-sm" href={`/pages/${page.slug}`}>Edit</a>
|
||||
<a class="btn btn-sm" href={`${import.meta.env.VITE_PUBLIC_SITE_URL}/${page.slug === 'home' ? '' : page.slug}`} target="_blank">Preview</a>
|
||||
<form method="POST" action="?/toggle">
|
||||
<input type="hidden" name="id" value={page.id} />
|
||||
<input type="hidden" name="published" value={page.published} />
|
||||
<button class="btn btn-sm btn-outline" type="submit">{page.published ? 'Unpublish' : 'Publish'}</button>
|
||||
</form>
|
||||
<form method="POST" action="?/delete" onsubmit={() => confirm('Delete this page?')}>
|
||||
<input type="hidden" name="id" value={page.id} />
|
||||
<button class="btn btn-sm btn-error btn-outline" type="submit">Delete</button>
|
||||
</form>
|
||||
<td>
|
||||
<div class="flex flex-wrap justify-end gap-2">
|
||||
<a class="btn btn-sm" href={`/pages/${page.slug}`}>Edit</a>
|
||||
{#if siteUrl && page.published}
|
||||
<a class="btn btn-sm" href={publicUrl(page.slug)} target="_blank" rel="noopener" title="Open on the live site">View</a>
|
||||
{/if}
|
||||
<form method="POST" action="?/toggle">
|
||||
<input type="hidden" name="id" value={page.id} />
|
||||
<input type="hidden" name="published" value={page.published} />
|
||||
<button class="btn btn-sm btn-outline" type="submit">{page.published ? 'Unpublish' : 'Publish'}</button>
|
||||
</form>
|
||||
<form method="POST" action="?/delete" onsubmit={confirmSubmit(`Delete the page "${page.title}"? This cannot be undone.`)}>
|
||||
<input type="hidden" name="id" value={page.id} />
|
||||
<button class="btn btn-sm btn-error btn-outline" type="submit">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{:else}
|
||||
<tr><td colspan="4" class="py-10 text-center text-base-content/60">No pages yet — create your first one.</td></tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<dialog id="new-page" class="modal">
|
||||
<form class="modal-box" method="POST" action="?/create">
|
||||
<h2 class="text-2xl font-bold">Create page</h2>
|
||||
<label class="form-control w-full mt-4">
|
||||
<div class="label"><span class="label-text">Slug</span></div>
|
||||
<input class="input input-bordered w-full" name="slug" placeholder="about" required />
|
||||
<Modal bind:open={showCreate} title="Create page">
|
||||
<form method="POST" action="?/create" class="space-y-1">
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Title</span>
|
||||
<input class="input w-full" name="title" placeholder="About" required />
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Title</span></div>
|
||||
<input class="input input-bordered w-full" name="title" placeholder="About" required />
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Slug</span>
|
||||
<input class="input w-full font-mono" name="slug" placeholder="about" required pattern="[A-Za-z0-9 _\-]+" />
|
||||
<span class="label">The page address: {siteUrl || 'your site'}/<em>slug</em></span>
|
||||
</label>
|
||||
<div class="modal-action">
|
||||
<button class="btn" type="button" onclick={() => (document.getElementById('new-page') as HTMLDialogElement)?.close()}>Cancel</button>
|
||||
<button class="btn" type="button" onclick={() => (showCreate = false)}>Cancel</button>
|
||||
<button class="btn btn-primary" type="submit">Create</button>
|
||||
</div>
|
||||
</form>
|
||||
</dialog>
|
||||
</Modal>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
<script lang="ts">
|
||||
import { toDatetimeInput } from '$lib/calendar';
|
||||
import { formatDateTime, formatTime, toZonedDatetimeInput, zonedInputToIso } from '$lib/calendar';
|
||||
import { confirmSubmit } from '$lib/admin/confirm';
|
||||
import Modal from '$lib/admin/Modal.svelte';
|
||||
|
||||
let { data, form } = $props();
|
||||
let items = $derived(data.items || []);
|
||||
let slots = $derived(
|
||||
[...(data.slots || [])].sort((a, b) => new Date(a.start).getTime() - new Date(b.start).getTime())
|
||||
);
|
||||
let slots = $derived(data.slots || []);
|
||||
let showEditor = $state(false);
|
||||
|
||||
type SlotDraft = {
|
||||
|
|
@ -23,14 +23,14 @@
|
|||
let selectedItem = $derived(items.find((item) => item.id === draft.item));
|
||||
let endLabel = $derived.by(() => {
|
||||
if (!selectedItem || !draft.start) return '';
|
||||
const start = new Date(draft.start);
|
||||
if (Number.isNaN(start.getTime())) return '';
|
||||
const end = new Date(start.getTime() + (Number(selectedItem.duration) || 0) * 60_000);
|
||||
return `Ends at ${end.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`;
|
||||
const startIso = zonedInputToIso(draft.start, data.timezone);
|
||||
if (!startIso) return '';
|
||||
const end = new Date(new Date(startIso).getTime() + (Number(selectedItem.duration) || 0) * 60_000);
|
||||
return `Ends at ${formatTime(end.toISOString(), data.timezone)}`;
|
||||
});
|
||||
|
||||
function emptyDraft(): SlotDraft {
|
||||
return { id: '', item: '', start: toDatetimeInput(new Date().toISOString()), status: 'available', heldUntil: '', notes: '' };
|
||||
return { id: '', item: '', start: toZonedDatetimeInput(new Date().toISOString(), data.timezone), status: 'available', heldUntil: '', notes: '' };
|
||||
}
|
||||
|
||||
function createSlot() {
|
||||
|
|
@ -42,7 +42,7 @@
|
|||
draft = {
|
||||
id: slot.id,
|
||||
item: slot.item,
|
||||
start: toDatetimeInput(slot.start),
|
||||
start: toZonedDatetimeInput(slot.start, data.timezone),
|
||||
status: slot.status,
|
||||
heldUntil: slot.heldUntil,
|
||||
notes: slot.notes
|
||||
|
|
@ -57,22 +57,22 @@
|
|||
<div class="flex flex-col justify-between gap-4 md:flex-row md:items-end">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold">Slots</h1>
|
||||
<p class="text-base-content/60">Create bookable time slots for your services.</p>
|
||||
<p class="text-base-content/60">Create bookable time slots for your services. Times are in {data.timezone}.</p>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="button" onclick={() => createSlot()}>Create slot</button>
|
||||
</div>
|
||||
|
||||
{#if form?.message}<div class="alert alert-error">{form.message}</div>{/if}
|
||||
{#if form?.message}<div class="alert alert-error" role="alert">{form.message}</div>{/if}
|
||||
|
||||
<div class="rounded-box bg-base-100 p-5 shadow">
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table">
|
||||
<thead><tr><th>Service</th><th>Date</th><th>Duration</th><th>Status</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{#each slots as slot}
|
||||
{#each slots as slot (slot.id)}
|
||||
<tr>
|
||||
<td><span class="font-semibold">{slot.itemName}</span></td>
|
||||
<td>{new Date(slot.start).toLocaleString()}</td>
|
||||
<td>{formatDateTime(slot.start, data.timezone)}</td>
|
||||
<td>{slot.itemDuration ? `${slot.itemDuration} min` : '—'}</td>
|
||||
<td>
|
||||
<span
|
||||
|
|
@ -83,9 +83,11 @@
|
|||
>{slot.status}</span>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<button class="btn btn-sm" type="button" disabled={slot.status === 'booked'} onclick={() => editSlot(slot)}>Edit</button>
|
||||
<button class="btn btn-sm" type="button" disabled={slot.status === 'booked'} title={slot.status === 'booked' ? 'Booked slots can’t be edited' : undefined} onclick={() => editSlot(slot)}>Edit</button>
|
||||
</td>
|
||||
</tr>
|
||||
{:else}
|
||||
<tr><td colspan="5" class="py-10 text-center text-base-content/60">{items.length ? 'No slots yet — create one so customers can book.' : 'Create a bookable service under Items first.'}</td></tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -93,69 +95,47 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{#if showEditor}
|
||||
<div class="fixed inset-0 z-50 bg-black/50 p-4">
|
||||
<div class="mx-auto max-h-full max-w-2xl overflow-auto rounded-box bg-base-100 p-6 shadow-xl">
|
||||
<div class="mb-4 flex items-center justify-between gap-3">
|
||||
<h2 class="text-2xl font-bold">{draft.id ? 'Edit slot' : 'Create slot'}</h2>
|
||||
<button class="btn btn-ghost btn-sm" type="button" onclick={() => (showEditor = false)}>Close</button>
|
||||
<Modal bind:open={showEditor} title={draft.id ? 'Edit slot' : 'Create slot'}>
|
||||
<form method="POST" action={action} class="space-y-1">
|
||||
<input type="hidden" name="id" value={draft.id} />
|
||||
|
||||
{#if isHeld}
|
||||
<div class="alert alert-warning mb-2 text-sm">
|
||||
This slot is in a customer’s basket{draft.heldUntil ? ` until ${formatTime(draft.heldUntil, data.timezone)}` : ''} — only the notes can be changed.
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<form method="POST" action={action} class="space-y-4">
|
||||
<input type="hidden" name="id" value={draft.id} />
|
||||
<input type="hidden" name="status" value={draft.status} />
|
||||
{#if isHeld}
|
||||
<input type="hidden" name="item" value={draft.item} />
|
||||
<input type="hidden" name="start" value={draft.start} />
|
||||
{/if}
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Service</span>
|
||||
<select class="select w-full" name="item" required disabled={isHeld} bind:value={draft.item}>
|
||||
<option value="" disabled>Select a service…</option>
|
||||
{#each items as item (item.id)}
|
||||
<option value={item.id}>{item.name}{item.duration ? ` (${item.duration} min)` : ''}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
{#if isHeld}
|
||||
<div class="alert alert-warning">
|
||||
This slot is currently held by a basket{draft.heldUntil ? ` (until ${new Date(draft.heldUntil).toLocaleString()})` : ''} — editing start/end is disabled.
|
||||
</div>
|
||||
{/if}
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Start ({data.timezone})</span>
|
||||
<input class="input w-full" type="datetime-local" name="start" required disabled={isHeld} bind:value={draft.start} />
|
||||
{#if endLabel}<span class="label">{endLabel}</span>{/if}
|
||||
</label>
|
||||
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Service</span></div>
|
||||
<select class="select select-bordered w-full" name="item" required disabled={isHeld} bind:value={draft.item}>
|
||||
<option value="" disabled>Select a service…</option>
|
||||
{#each items as item}
|
||||
<option value={item.id}>{item.name}{item.duration ? ` (${item.duration} min)` : ''}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
<label class="fieldset">
|
||||
<span class="fieldset-legend">Notes</span>
|
||||
<textarea class="textarea w-full" name="notes" bind:value={draft.notes}></textarea>
|
||||
</label>
|
||||
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Start</span></div>
|
||||
<input
|
||||
class="input input-bordered w-full"
|
||||
type="datetime-local"
|
||||
name="start"
|
||||
required
|
||||
disabled={isHeld}
|
||||
value={draft.start}
|
||||
oninput={(e) => (draft = { ...draft, start: e.currentTarget.value })}
|
||||
/>
|
||||
</label>
|
||||
{#if endLabel}<p class="text-sm text-base-content/60">{endLabel}</p>{/if}
|
||||
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Notes</span></div>
|
||||
<textarea class="textarea textarea-bordered" name="notes" bind:value={draft.notes}></textarea>
|
||||
</label>
|
||||
|
||||
<div class="flex justify-between gap-2 pt-2">
|
||||
{#if draft.id}
|
||||
<button class="btn btn-error" type="submit" formaction="?/delete">Delete</button>
|
||||
{:else}
|
||||
<span></span>
|
||||
{/if}
|
||||
<div class="flex gap-2">
|
||||
<button class="btn" type="button" onclick={() => (showEditor = false)}>Cancel</button>
|
||||
<button class="btn btn-primary" type="submit">Save slot</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="modal-action justify-between">
|
||||
{#if draft.id && !isHeld}
|
||||
<button class="btn btn-error btn-outline" type="submit" formaction="?/delete" formnovalidate onclick={confirmSubmit('Delete this slot?')}>Delete</button>
|
||||
{:else}
|
||||
<span></span>
|
||||
{/if}
|
||||
<div class="flex gap-2">
|
||||
<button class="btn" type="button" onclick={() => (showEditor = false)}>Cancel</button>
|
||||
<button class="btn btn-primary" type="submit">Save slot</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</form>
|
||||
</Modal>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue