moved page rendering to a different service and access is now behind
admin.DOMAIN www.DOMAIN db.DOMAIN
This commit is contained in:
parent
c7f6b30b87
commit
1027da989e
126 changed files with 6356 additions and 1516 deletions
10
packages/shared/package.json
Normal file
10
packages/shared/package.json
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "@eva/shared",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"./types": "./src/types.ts",
|
||||
"./calendar": "./src/calendar.ts"
|
||||
}
|
||||
}
|
||||
199
packages/shared/src/calendar.ts
Normal file
199
packages/shared/src/calendar.ts
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
import type { CalendarEventRecord, ContentBlock } from './types';
|
||||
|
||||
type UnknownRecord = Record<string, unknown>;
|
||||
|
||||
export type CalendarDay = {
|
||||
date: Date;
|
||||
dateKey: string;
|
||||
dayNumber: number;
|
||||
inMonth: boolean;
|
||||
isToday: boolean;
|
||||
};
|
||||
|
||||
export type CalendarMonth = {
|
||||
date: Date;
|
||||
label: string;
|
||||
days: CalendarDay[];
|
||||
};
|
||||
|
||||
export function hasUpcomingCalendarBlock(blocks: ContentBlock[] = []) {
|
||||
return blocks.some((block) => block.type === 'upcoming_calendar');
|
||||
}
|
||||
|
||||
export function toDateInput(value?: string | null) {
|
||||
if (!value) return '';
|
||||
return value.slice(0, 10);
|
||||
}
|
||||
|
||||
export function toDatetimeInput(value?: string | null) {
|
||||
if (!value) return '';
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return value.slice(0, 16);
|
||||
const offset = date.getTimezoneOffset();
|
||||
const local = new Date(date.getTime() - offset * 60_000);
|
||||
return local.toISOString().slice(0, 16);
|
||||
}
|
||||
|
||||
export function dateInputToPocketBase(value: string, allDay = true) {
|
||||
if (!value) return '';
|
||||
if (!allDay && value.includes('T')) {
|
||||
return new Date(value).toISOString();
|
||||
}
|
||||
return `${value.slice(0, 10)} 00:00:00.000Z`;
|
||||
}
|
||||
|
||||
export function parseEventDate(value?: string | null) {
|
||||
if (!value) return null;
|
||||
const datePart = value.slice(0, 10);
|
||||
const [year, month, day] = datePart.split('-').map(Number);
|
||||
if (!year || !month || !day) return null;
|
||||
return new Date(year, month - 1, day);
|
||||
}
|
||||
|
||||
export function dateKey(date: Date) {
|
||||
const year = date.getFullYear();
|
||||
const month = `${date.getMonth() + 1}`.padStart(2, '0');
|
||||
const day = `${date.getDate()}`.padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
|
||||
export function addDays(date: Date, days: number) {
|
||||
const copy = new Date(date);
|
||||
copy.setDate(copy.getDate() + days);
|
||||
return copy;
|
||||
}
|
||||
|
||||
export function addMonths(date: Date, months: number) {
|
||||
return new Date(date.getFullYear(), date.getMonth() + months, 1);
|
||||
}
|
||||
|
||||
export function startOfMonth(date = new Date()) {
|
||||
return new Date(date.getFullYear(), date.getMonth(), 1);
|
||||
}
|
||||
|
||||
export function endOfMonth(date = new Date()) {
|
||||
return new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
||||
}
|
||||
|
||||
export function getUpcomingCalendarRange(reference = new Date()) {
|
||||
const start = startOfMonth(reference);
|
||||
const end = endOfMonth(addMonths(reference, 1));
|
||||
return { start, end };
|
||||
}
|
||||
|
||||
export function createCalendarMonth(monthDate: Date, reference = new Date()): CalendarMonth {
|
||||
const first = startOfMonth(monthDate);
|
||||
const monthEnd = endOfMonth(monthDate);
|
||||
const gridStart = addDays(first, -first.getDay());
|
||||
const gridEnd = addDays(monthEnd, 6 - monthEnd.getDay());
|
||||
const todayKey = dateKey(reference);
|
||||
const days: CalendarDay[] = [];
|
||||
|
||||
for (let day = new Date(gridStart); day <= gridEnd; day = addDays(day, 1)) {
|
||||
days.push({
|
||||
date: new Date(day),
|
||||
dateKey: dateKey(day),
|
||||
dayNumber: day.getDate(),
|
||||
inMonth: day.getMonth() === first.getMonth(),
|
||||
isToday: dateKey(day) === todayKey
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
date: first,
|
||||
label: first.toLocaleDateString(undefined, { month: 'long', year: 'numeric' }),
|
||||
days
|
||||
};
|
||||
}
|
||||
|
||||
export function getCurrentAndNextMonths(reference = new Date()) {
|
||||
const current = startOfMonth(reference);
|
||||
return [createCalendarMonth(current, reference), createCalendarMonth(addMonths(current, 1), reference)];
|
||||
}
|
||||
|
||||
export function rangesOverlap(startA: Date, endA: Date, startB: Date, endB: Date) {
|
||||
return startA <= endB && endA >= startB;
|
||||
}
|
||||
|
||||
export function eventRange(event: Pick<CalendarEventRecord, 'start' | 'end'>) {
|
||||
const start = parseEventDate(event.start) || new Date();
|
||||
const end = parseEventDate(event.end) || start;
|
||||
return end < start ? { start: end, end: start } : { start, end };
|
||||
}
|
||||
|
||||
export function eventOverlapsDay(event: CalendarEventRecord, day: Date) {
|
||||
const { start, end } = eventRange(event);
|
||||
return rangesOverlap(start, end, day, day);
|
||||
}
|
||||
|
||||
export function eventOverlapsRange(event: CalendarEventRecord, start: Date, end: Date) {
|
||||
const range = eventRange(event);
|
||||
return rangesOverlap(range.start, range.end, start, end);
|
||||
}
|
||||
|
||||
export function normalizeEvent(record: UnknownRecord): CalendarEventRecord {
|
||||
return {
|
||||
id: String(record.id || ''),
|
||||
name: String(record.name || ''),
|
||||
start: String(record.start || ''),
|
||||
end: record.end ? String(record.end) : '',
|
||||
description: record.description ? String(record.description) : '',
|
||||
color: String(record.color || '#8a9a7b'),
|
||||
link: record.link ? String(record.link) : '',
|
||||
categories: normalizeCategories(record.categories),
|
||||
published: Boolean(record.published),
|
||||
allDay: record.allDay !== false
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeCategories(value: unknown): string[] {
|
||||
if (Array.isArray(value)) {
|
||||
return [...new Set(value.map((item) => String(item).trim()).filter(Boolean))];
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
return [...new Set(value.split(',').map((item) => item.trim()).filter(Boolean))];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
export function categoriesToText(categories: string[] = []) {
|
||||
return categories.join(', ');
|
||||
}
|
||||
|
||||
export function extractCategories(events: CalendarEventRecord[]) {
|
||||
return [...new Set(events.flatMap((event) => event.categories || []))].sort((a, b) => a.localeCompare(b));
|
||||
}
|
||||
|
||||
export function eventMatchesCategories(event: CalendarEventRecord, categories: string[] = []) {
|
||||
if (!categories.length) return true;
|
||||
return event.categories?.some((category) => categories.includes(category));
|
||||
}
|
||||
|
||||
export function sortEvents(events: CalendarEventRecord[]) {
|
||||
return [...events].sort((a, b) => {
|
||||
const startA = parseEventDate(a.start)?.getTime() ?? 0;
|
||||
const startB = parseEventDate(b.start)?.getTime() ?? 0;
|
||||
return startA - startB || a.name.localeCompare(b.name);
|
||||
});
|
||||
}
|
||||
|
||||
export function formatEventDateRange(event: CalendarEventRecord) {
|
||||
const start = parseEventDate(event.start);
|
||||
const end = parseEventDate(event.end);
|
||||
if (!start) return '';
|
||||
const formatter = new Intl.DateTimeFormat(undefined, { month: 'short', day: 'numeric' });
|
||||
if (!end || dateKey(start) === dateKey(end)) return formatter.format(start);
|
||||
return `${formatter.format(start)} – ${formatter.format(end)}`;
|
||||
}
|
||||
|
||||
export function normalizeLink(link?: string) {
|
||||
const value = String(link || '').trim();
|
||||
if (!value) return '';
|
||||
if (value.startsWith('/') || value.startsWith('#') || value.startsWith('mailto:') || value.startsWith('tel:')) return value;
|
||||
if (/^https?:\/\//i.test(value)) return value;
|
||||
return `/${value.replace(/^\/+/, '')}`;
|
||||
}
|
||||
|
||||
export function isExternalLink(link?: string) {
|
||||
return /^https?:\/\//i.test(String(link || ''));
|
||||
}
|
||||
218
packages/shared/src/types.ts
Normal file
218
packages/shared/src/types.ts
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
export type BlockType =
|
||||
| 'text'
|
||||
| 'image_text'
|
||||
| 'timeline'
|
||||
| 'hero'
|
||||
| 'button'
|
||||
| 'spacer'
|
||||
| 'testimonials'
|
||||
| 'upcoming_calendar'
|
||||
| 'shop'
|
||||
| 'checkout';
|
||||
|
||||
export type BlockBackground = {
|
||||
type: 'none' | 'color' | 'image';
|
||||
color: string;
|
||||
imageUrl: string;
|
||||
attachment: 'scroll' | 'fixed';
|
||||
overlay: boolean;
|
||||
overlayOpacity: number; // 0–100
|
||||
};
|
||||
|
||||
export type BlockForeground = {
|
||||
mode: 'default' | 'custom';
|
||||
headingColor: string;
|
||||
subheadingColor: string;
|
||||
textColor: string;
|
||||
};
|
||||
|
||||
export type ContentBlock = {
|
||||
id: string;
|
||||
type: BlockType;
|
||||
data: Record<string, any>;
|
||||
};
|
||||
|
||||
export type PageRecord = {
|
||||
id: string;
|
||||
slug: string;
|
||||
title: string;
|
||||
blocks: ContentBlock[];
|
||||
published: boolean;
|
||||
};
|
||||
|
||||
export type CalendarEventRecord = {
|
||||
id: string;
|
||||
name: string;
|
||||
start: string;
|
||||
end?: string;
|
||||
description?: string;
|
||||
color: string;
|
||||
link?: string;
|
||||
categories: string[];
|
||||
published: boolean;
|
||||
allDay: boolean;
|
||||
};
|
||||
|
||||
export type UpcomingCalendarBlockData = {
|
||||
title?: string;
|
||||
categories?: string[];
|
||||
};
|
||||
|
||||
export type HeaderGlobal = {
|
||||
logo: { url: string; alt: string };
|
||||
navLinks: { label: string; href: string }[];
|
||||
ctaButton: { label: string; href: string };
|
||||
homePage: string;
|
||||
};
|
||||
|
||||
export type FooterGlobal = {
|
||||
businessName: string;
|
||||
tagline: string;
|
||||
address: string;
|
||||
phone: string;
|
||||
email: string;
|
||||
socialLinks: { platform: string; url: string }[];
|
||||
copyrightText: string;
|
||||
};
|
||||
|
||||
export const defaultHeader: HeaderGlobal = {
|
||||
logo: { url: '', alt: 'Massage studio logo' },
|
||||
navLinks: [
|
||||
{ label: 'Home', href: '/' },
|
||||
{ label: 'About', href: '/about' },
|
||||
{ label: 'Services', href: '/services' }
|
||||
],
|
||||
ctaButton: { label: 'Book Now', href: '/book' },
|
||||
homePage: 'home'
|
||||
};
|
||||
|
||||
export const defaultFooter: FooterGlobal = {
|
||||
businessName: 'Eva Shafik Massage',
|
||||
tagline: 'Warm, restorative massage therapy for everyday wellbeing.',
|
||||
address: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
socialLinks: [{ platform: 'instagram', url: '' }],
|
||||
copyrightText: `© ${new Date().getFullYear()} Eva Shafik Massage. All rights reserved.`
|
||||
};
|
||||
|
||||
// ── Commerce types ─────────────────────────────────────────────────────
|
||||
|
||||
export type ItemType = 'item' | 'item_with_time';
|
||||
|
||||
export type ItemRecord = {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
price: number;
|
||||
image: string; // media record id
|
||||
imageUrl: string; // resolved URL (populated by server load)
|
||||
type: ItemType;
|
||||
stock: number | null;
|
||||
duration: number | null; // minutes, for item_with_time
|
||||
active: boolean;
|
||||
};
|
||||
|
||||
export type SlotStatus = 'available' | 'held' | 'booked';
|
||||
|
||||
export type SlotRecord = {
|
||||
id: string;
|
||||
item: string; // item id
|
||||
start: string;
|
||||
end: string;
|
||||
status: SlotStatus;
|
||||
heldUntil: string | null;
|
||||
order: string | null;
|
||||
notes: string;
|
||||
};
|
||||
|
||||
export type BasketStatus = 'active' | 'completed' | 'abandoned';
|
||||
|
||||
export type BasketLine = {
|
||||
id: string;
|
||||
basket: string;
|
||||
item: string;
|
||||
slot: string | null;
|
||||
quantity: number;
|
||||
lineType: 'item' | 'slot';
|
||||
// Expanded fields (populated server-side)
|
||||
itemName?: string;
|
||||
itemPrice?: number;
|
||||
itemImageUrl?: string;
|
||||
slotStart?: string;
|
||||
slotEnd?: string;
|
||||
};
|
||||
|
||||
export type Basket = {
|
||||
id: string;
|
||||
status: BasketStatus;
|
||||
expiresAt: string;
|
||||
email: string | null;
|
||||
customerDetails: CustomerDetails | null;
|
||||
stripePaymentIntentId: string | null;
|
||||
lines: BasketLine[];
|
||||
};
|
||||
|
||||
export type CustomerDetails = {
|
||||
name: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
notes: string;
|
||||
};
|
||||
|
||||
export type OrderRecord = {
|
||||
id: string;
|
||||
basket: string;
|
||||
email: string;
|
||||
customerDetails: CustomerDetails;
|
||||
total: number;
|
||||
status: 'pending' | 'paid' | 'refunded';
|
||||
stripePaymentIntentId: string;
|
||||
createdAt: string;
|
||||
lines?: OrderLine[];
|
||||
};
|
||||
|
||||
export type OrderLine = {
|
||||
id: string;
|
||||
order: string;
|
||||
item: string;
|
||||
slot: string | null;
|
||||
quantity: number;
|
||||
lineType: 'item' | 'slot';
|
||||
name: string;
|
||||
price: number;
|
||||
start: string | null;
|
||||
};
|
||||
|
||||
// ── Block data types ──────────────────────────────────────────────────
|
||||
|
||||
export type ShopBlockData = {
|
||||
title?: string;
|
||||
itemTypeFilter?: 'all' | ItemType;
|
||||
itemIds?: string[];
|
||||
layout?: 'grid' | 'list';
|
||||
};
|
||||
|
||||
export type CheckoutBlockData = {
|
||||
title?: string;
|
||||
heading?: string;
|
||||
notesLabel?: string;
|
||||
};
|
||||
|
||||
export type ColorsGlobal = {
|
||||
background: string;
|
||||
heading: string;
|
||||
subheading: string;
|
||||
text: string;
|
||||
primary: string;
|
||||
accent: string;
|
||||
};
|
||||
|
||||
export const defaultColors: ColorsGlobal = {
|
||||
background: '#faf8f5',
|
||||
heading: '#2c2c2c',
|
||||
subheading: '#4a4a4a',
|
||||
text: '#2c2c2c',
|
||||
primary: '#8a9a7b',
|
||||
accent: '#c9825f'
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue