feat(signage): new widgets (shape, scrolling text, countdown, opening hours, Wi-Fi, contact details); the venue's opening hours on the server, edited on the Schedule page
Shapes: rectangle, circle, triangle, polygon, star or own corners, fill or gradient, border. Countdown: to a time every day or a date, from now / a span before / a set time, in venue time (the slide shows what is left right now). Opening hours, Wi-Fi (with a join-the-network code) and contact details read the venue's identity and opening hours (GET/PUT /api/identity/hours; Schedule -> Opening hours, shaded on its timeline); the editor warns with a link when they're missing. Plan 6R.15, F-112. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
// The venue's opening hours (6R.15, owner 2026-11-22): each day closed or open in up to three spans
|
||||
// (a span may pass midnight), and a note. Kept on the server (PUT /api/identity/hours): the
|
||||
// schedule's timeline shades them and signage's opening hours widget shows them.
|
||||
import { useState } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { Copy, Plus, Trash2 } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, Field, IconButton, Input, Spinner } from '@xenia/ui'
|
||||
import client from '../../api/client'
|
||||
import { HOURS_KEY, useHours } from '../../shell/useIdentity'
|
||||
import { hoursValid } from './scheduleLogic'
|
||||
|
||||
const MONDAY = '2026-11-16'
|
||||
|
||||
export default function OpeningHoursDialog({ onClose }) {
|
||||
const { data } = useHours()
|
||||
return data ? <HoursForm saved={data} onClose={onClose} /> : <Dialog open size="md" onClose={onClose}><div className="py-8 flex justify-center"><Spinner /></div></Dialog>
|
||||
}
|
||||
|
||||
function HoursForm({ saved, onClose }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const fmt = useFormat()
|
||||
const qc = useQueryClient()
|
||||
const [days, setDays] = useState(() => saved.days.map(d => d.map(x => ({ ...x }))))
|
||||
const [note, setNote] = useState(saved.note || '')
|
||||
const [busy, setBusy] = useState(false)
|
||||
const dayName = i => fmt.formatDateTime(`2026-11-${16 + i}T12:00:00Z`, { weekday: 'long' })
|
||||
const setDay = (i, spans) => setDays(ds => ds.map((d, j) => (j === i ? spans : d)))
|
||||
const ok = hoursValid(days)
|
||||
const save = async () => {
|
||||
setBusy(true)
|
||||
try {
|
||||
const { data } = await client.put('/api/identity/hours', { days, note: note.trim() || null })
|
||||
qc.setQueryData(HOURS_KEY, data)
|
||||
toast.success(t('schedule.openingSaved'))
|
||||
onClose()
|
||||
} catch (err) { toast.error(errorMessage(err, t)) }
|
||||
setBusy(false)
|
||||
}
|
||||
return (
|
||||
<Dialog open size="lg" onClose={onClose} title={t('schedule.openingTitle')} description={t('schedule.openingIntro')}
|
||||
footer={<>
|
||||
<Button variant="secondary" onClick={onClose}>{t('schedule.back')}</Button>
|
||||
<Button loading={busy} disabled={!ok} onClick={save} data-testid="opening-save">{t('schedule.save')}</Button>
|
||||
</>}>
|
||||
<div className="grid gap-2" data-testid="opening-hours" data-monday={MONDAY}>
|
||||
{days.map((spans, i) => (
|
||||
<div key={i} className="grid gap-2 sm:grid-cols-[9rem_minmax(0,1fr)] items-start border-b border-line pb-2" data-testid="opening-day" data-day={i}>
|
||||
<span className="text-body font-medium text-ink capitalize pt-2.5">{dayName(i)}</span>
|
||||
<div className="grid gap-1.5">
|
||||
{spans.length === 0 && <span className="text-label text-ink-3 pt-2.5">{t('schedule.closedDay')}</span>}
|
||||
{spans.map((x, k) => (
|
||||
<div key={k} className="flex items-center gap-2">
|
||||
<Input type="time" value={x.from} aria-label={t('schedule.opens')} className="w-32" data-testid="opening-from"
|
||||
onChange={e => setDay(i, spans.map((y, n) => (n === k ? { ...y, from: e.target.value } : y)))} />
|
||||
<span className="text-ink-3">–</span>
|
||||
<Input type="time" value={x.to} aria-label={t('schedule.closes')} className="w-32" data-testid="opening-to"
|
||||
onChange={e => setDay(i, spans.map((y, n) => (n === k ? { ...y, to: e.target.value } : y)))} />
|
||||
<IconButton size="sm" tone="danger" label={t('schedule.removeSpan')} onClick={() => setDay(i, spans.filter((_, n) => n !== k))}><Trash2 size={15} /></IconButton>
|
||||
</div>
|
||||
))}
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{spans.length < 3 && (
|
||||
<Button size="sm" variant="secondary" icon={<Plus size={14} />} data-testid="opening-add"
|
||||
onClick={() => setDay(i, [...spans, spans.length ? { from: '18:00', to: '23:00' } : { from: '12:00', to: '23:00' }])}>
|
||||
{t(spans.length ? 'schedule.addSpan' : 'schedule.openThisDay')}
|
||||
</Button>
|
||||
)}
|
||||
{i === 0 && (
|
||||
<Button size="sm" variant="ghost" icon={<Copy size={14} />} data-testid="opening-copy" onClick={() => setDays(ds => ds.map(() => spans.map(x => ({ ...x }))))}>
|
||||
{t('schedule.copyToAll')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<Field label={t('schedule.openingNote')} hint={t('schedule.openingNoteHint')}>
|
||||
<Input value={note} maxLength={120} onChange={e => setNote(e.target.value)} />
|
||||
</Field>
|
||||
{!ok && <p className="text-label text-danger-ink">{t('schedule.openingInvalid')}</p>}
|
||||
</div>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
import { useMemo, useState } from 'react'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import toast from 'react-hot-toast'
|
||||
import { ChevronLeft, ChevronRight, Plus, Settings2 } from 'lucide-react'
|
||||
import { ChevronLeft, ChevronRight, Clock, Plus, Settings2 } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Button, EmptyState, IconButton, Page, PageHeader, Segmented, Spinner, cx } from '@xenia/ui'
|
||||
@@ -15,7 +15,10 @@ import client from '../../api/client'
|
||||
import { useLiveQuery } from '../../live/useLiveQuery'
|
||||
import ShiftDialog from './ShiftDialog'
|
||||
import ViewDialog from './ViewDialog'
|
||||
import { addDays, gridOf, hourMarks, inOpening, loadView, placeOnDay, saveView, shiftState, weekDays, weekStartOf, weekTotals } from './scheduleLogic'
|
||||
import OpeningHoursDialog from './OpeningHoursDialog'
|
||||
import { useHours } from '../../shell/useIdentity'
|
||||
import { useSearchParams } from 'react-router-dom'
|
||||
import { addDays, gridOf, hourMarks, inSpans, weekdayOf, loadView, placeOnDay, saveView, shiftState, weekDays, weekStartOf, weekTotals } from './scheduleLogic'
|
||||
|
||||
const STATE = {
|
||||
planned: 'border-info bg-info-soft text-info-ink',
|
||||
@@ -33,6 +36,10 @@ export default function SchedulePage() {
|
||||
const [start, setStart] = useState(() => weekStartOf(today, loadView().mondayFirst))
|
||||
const [editing, setEditing] = useState(null) // { date, userId, shift? }
|
||||
const [settings, setSettings] = useState(false)
|
||||
const [params, setParams] = useSearchParams()
|
||||
const hoursOpen = params.get('hours') === '1'
|
||||
const setHoursOpen = on => setParams(p => { const n = new URLSearchParams(p); if (on) n.set('hours', '1'); else n.delete('hours'); return n }, { replace: true })
|
||||
const { data: hours } = useHours()
|
||||
const setView = next => { setViewState(next); saveView(next) }
|
||||
|
||||
const { data, isPending } = useLiveQuery({
|
||||
@@ -67,6 +74,7 @@ export default function SchedulePage() {
|
||||
<Button variant="secondary" onClick={() => setStart(weekStartOf(today, view.mondayFirst))}>{t('schedule.thisWeek')}</Button>
|
||||
<IconButton variant="secondary" label={t('schedule.next')} onClick={() => setStart(s => addDays(s, 7))} data-testid="schedule-next"><ChevronRight size={16} /></IconButton>
|
||||
</span>
|
||||
<Button variant="secondary" icon={<Clock size={16} />} onClick={() => setHoursOpen(true)} data-testid="schedule-opening">{t('schedule.openingButton')}</Button>
|
||||
<IconButton variant="secondary" label={t('schedule.settings')} onClick={() => setSettings(true)}><Settings2 size={16} /></IconButton>
|
||||
</>} />
|
||||
|
||||
@@ -121,7 +129,7 @@ export default function SchedulePage() {
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<HoursView days={days} today={today} people={people} scheduled={scheduled} view={view} dayLabel={dayLabel} dateLabel={dateLabel}
|
||||
<HoursView days={days} today={today} people={people} scheduled={scheduled} view={view} hours={hours} dayLabel={dayLabel} dateLabel={dateLabel}
|
||||
onAdd={d => setEditing({ date: d, userId: null })} onOpen={(d, s) => setEditing({ date: d, userId: s.user_id, shift: s })} />
|
||||
)}
|
||||
|
||||
@@ -134,13 +142,14 @@ export default function SchedulePage() {
|
||||
{editing && <ShiftDialog people={people} scheduled={scheduled} {...editing}
|
||||
onClose={() => setEditing(null)} onDelete={id => { remove.mutate(id); setEditing(null) }}
|
||||
onSaved={() => { setEditing(null); qc.invalidateQueries({ queryKey: ['schedule-week'] }) }} />}
|
||||
{hoursOpen && <OpeningHoursDialog onClose={() => setHoursOpen(false)} />}
|
||||
{settings && <ViewDialog view={view} onClose={() => setSettings(false)}
|
||||
onSave={next => { if (next.mondayFirst !== view.mondayFirst) setStart(weekStartOf(start, next.mondayFirst)); setView(next); setSettings(false) }} />}
|
||||
</Page>
|
||||
)
|
||||
}
|
||||
|
||||
function HoursView({ days, today, people, scheduled, view, dayLabel, dateLabel, onAdd, onOpen }) {
|
||||
function HoursView({ days, today, people, scheduled, view, hours, dayLabel, dateLabel, onAdd, onOpen }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const marks = hourMarks(view.firstHour)
|
||||
const nameOf = id => people.find(p => p.id === id)?.nickname || people.find(p => p.id === id)?.name || `#${id}`
|
||||
@@ -160,7 +169,7 @@ function HoursView({ days, today, people, scheduled, view, dayLabel, dateLabel,
|
||||
</div>
|
||||
<div className="relative w-full cursor-copy" style={{ height: 24 * HOUR_PX }} onClick={() => onAdd(d)} title={t('schedule.addOn', { day: dayLabel(d) })} data-testid="schedule-day">
|
||||
{marks.map((h, i) => (
|
||||
<span key={h} className={cx('absolute inset-x-0 border-t', h === 0 ? 'border-info' : 'border-line', inOpening(h, view.open, view.close) && 'bg-accent-soft/40')}
|
||||
<span key={h} className={cx('absolute inset-x-0 border-t', h === 0 ? 'border-info' : 'border-line', inSpans(h, hours?.days?.[weekdayOf(d)]) && 'bg-accent-soft/40')}
|
||||
style={{ top: i * HOUR_PX, height: HOUR_PX }} aria-hidden="true" />
|
||||
))}
|
||||
{shifts.map(s => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// How this browser shows the schedule (plan step 6.11): the week's first day, the timeline's
|
||||
// first hour, the opening hours shaded on it. Nothing here changes the schedule itself.
|
||||
// first hour. Nothing here changes the schedule itself (the opening hours are the venue's: OpeningHoursDialog).
|
||||
import { useState } from 'react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, Field, Input, Select } from '@xenia/ui'
|
||||
import { Button, Dialog, Field, Select } from '@xenia/ui'
|
||||
|
||||
export default function ViewDialog({ view, onClose, onSave }) {
|
||||
const { t } = useTranslation('manager')
|
||||
@@ -23,10 +23,6 @@ export default function ViewDialog({ view, onClose, onSave }) {
|
||||
<Select value={String(v.firstHour)} onChange={e => set('firstHour', Number(e.target.value))}
|
||||
options={Array.from({ length: 24 }, (_, h) => ({ value: String(h), label: `${String(h).padStart(2, '0')}:00` }))} />
|
||||
</Field>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Field label={t('schedule.opens')} hint={t('schedule.openingHint')}><Input type="time" value={v.open} onChange={e => set('open', e.target.value)} /></Field>
|
||||
<Field label={t('schedule.closes')}><Input type="time" value={v.close} onChange={e => set('close', e.target.value)} /></Field>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
)
|
||||
|
||||
@@ -100,8 +100,17 @@ export function inOpening(hour, open, close) {
|
||||
return a <= b ? hour >= a && hour < b : hour >= a || hour < b
|
||||
}
|
||||
|
||||
/** Is an hour mark inside any of a day's opening spans ([{from, to}], 6R.15: the venue's hours, kept on the server)? */
|
||||
export const inSpans = (hour, spans) => (spans || []).some(x => inOpening(hour, x.from, x.to))
|
||||
|
||||
/** Monday 0 … Sunday 6 of a "YYYY-MM-DD". */
|
||||
export const weekdayOf = d => (new Date(`${d}T12:00:00Z`).getUTCDay() + 6) % 7
|
||||
|
||||
/** Opening hours that can be saved: every span has both times and they differ. */
|
||||
export const hoursValid = days => days.every(d => d.every(x => /^\d\d:\d\d$/.test(x.from || '') && /^\d\d:\d\d$/.test(x.to || '') && x.from !== x.to))
|
||||
|
||||
/** The schedule's view settings kept in this browser (a per-viewer convenience). */
|
||||
export const VIEW_DEFAULTS = { view: 'people', mondayFirst: true, firstHour: 6, open: '', close: '' }
|
||||
export const VIEW_DEFAULTS = { view: 'people', mondayFirst: true, firstHour: 6 }
|
||||
const VIEW_KEY = 'xenia:schedule:view'
|
||||
export function loadView(storage = globalThis.localStorage) {
|
||||
try { return { ...VIEW_DEFAULTS, ...JSON.parse(storage?.getItem(VIEW_KEY) || '{}') } } catch { return { ...VIEW_DEFAULTS } }
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
// The settings of the widgets added in 6R.15 (owner 2026-11-22): a shape, a scrolling text, a
|
||||
// countdown, the opening hours, the guests' Wi-Fi and the contact details. The last three read the
|
||||
// venue (Settings → Identity, the Schedule page's opening hours): when that is missing the card says
|
||||
// so with a link to where it is set. Used by WidgetsEditor (its row and the part under it).
|
||||
import { Link } from 'react-router-dom'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { ColourField, Dropdown, Field, Input, Notice, NumberInput, Segmented, Slider, Switch } from '@xenia/ui'
|
||||
import { useHours, useIdentity } from '../../shell/useIdentity'
|
||||
import { CONTACT_KEYS, WIDGET_COLOURS } from './signageLogic'
|
||||
|
||||
const SHAPES = ['rectangle', 'circle', 'triangle', 'polygon', 'star', 'custom']
|
||||
const isDate = v => !!v && v.length > 5
|
||||
|
||||
/** On the widget's row (where / size / alignment): its main choices. */
|
||||
export function MoreInlineFields({ w, set }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const k = 'signage.widgets'
|
||||
if (w.kind === 'shape') {
|
||||
return (<>
|
||||
<Field label={t(`${k}.shape.kind`)}>
|
||||
<Dropdown value={w.shape || 'rectangle'} onChange={shape => set({ shape })} data-testid="signage-widget-shape"
|
||||
options={SHAPES.map(x => ({ value: x, label: t(`${k}.shape.kinds.${x}`) }))} />
|
||||
</Field>
|
||||
{(w.shape === 'polygon' || w.shape === 'star') && (
|
||||
<Field label={t(w.shape === 'star' ? `${k}.shape.points` : `${k}.shape.sides`)}>
|
||||
<NumberInput value={w.shape_sides ?? 6} min={3} max={12} onChange={v => set({ shape_sides: v ?? 3 })} data-testid="signage-widget-shape-sides" />
|
||||
</Field>
|
||||
)}
|
||||
</>)
|
||||
}
|
||||
if (w.kind === 'ticker') {
|
||||
return (<>
|
||||
<Field label={t(`${k}.ticker.text`)} className="col-span-2">
|
||||
<Input value={w.text || ''} maxLength={500} onChange={e => set({ text: e.target.value || null })} data-testid="signage-widget-ticker-text" />
|
||||
</Field>
|
||||
<Field label={t(`${k}.ticker.direction`)}>
|
||||
<Segmented fill value={w.ticker_direction || 'left'} onChange={ticker_direction => set({ ticker_direction })}
|
||||
options={['left', 'right'].map(v => ({ value: v, label: t(`${k}.ticker.directions.${v}`) }))} />
|
||||
</Field>
|
||||
</>)
|
||||
}
|
||||
if (w.kind === 'countdown') {
|
||||
const to = w.countdown_to || ''
|
||||
return (<>
|
||||
<Field label={t(`${k}.countdown.title`)}>
|
||||
<Input value={w.text || ''} maxLength={80} placeholder={t(`${k}.countdown.titlePlaceholder`)} onChange={e => set({ text: e.target.value || null })} />
|
||||
</Field>
|
||||
<Field label={t(`${k}.countdown.ends`)}>
|
||||
<Segmented fill value={isDate(to) ? 'date' : 'daily'} data-testid="signage-widget-countdown-mode"
|
||||
onChange={m => set({ countdown_to: m === 'date' ? `${new Date().toISOString().slice(0, 10)}T${to.slice(-5) || '17:00'}` : (to.slice(-5) || '17:00') })}
|
||||
options={['daily', 'date'].map(v => ({ value: v, label: t(`${k}.countdown.modes.${v}`) }))} />
|
||||
</Field>
|
||||
<Field label={t(isDate(to) ? `${k}.countdown.at` : `${k}.countdown.everyDayAt`)}>
|
||||
<Input type={isDate(to) ? 'datetime-local' : 'time'} value={to} data-testid="signage-widget-countdown-to"
|
||||
onChange={e => set({ countdown_to: e.target.value ? e.target.value.slice(0, isDate(to) ? 16 : 5) : null })} />
|
||||
</Field>
|
||||
</>)
|
||||
}
|
||||
if (w.kind === 'hours') {
|
||||
return (<>
|
||||
<Field label={t(`${k}.hours.style`)}>
|
||||
<Segmented fill value={w.hours_style || 'week'} onChange={hours_style => set({ hours_style })} data-testid="signage-widget-hours-style"
|
||||
options={['week', 'today'].map(v => ({ value: v, label: t(`${k}.hours.styles.${v}`) }))} />
|
||||
</Field>
|
||||
<Field label={t(`${k}.countdown.title`)}>
|
||||
<Input value={w.text || ''} maxLength={80} placeholder={t(`${k}.hours.titlePlaceholder`)} onChange={e => set({ text: e.target.value || null })} />
|
||||
</Field>
|
||||
</>)
|
||||
}
|
||||
if (w.kind === 'wifi') {
|
||||
return (
|
||||
<Field label={t(`${k}.wifi.shows`)} className="col-span-2">
|
||||
<div className="flex gap-2 flex-wrap">
|
||||
<Switch boxed className="h-control" checked={w.wifi_qr !== false} onChange={on => set({ wifi_qr: on })} label={t(`${k}.wifi.qr`)} data-testid="signage-widget-wifi-qr" />
|
||||
<Switch boxed className="h-control" checked={w.wifi_password !== false} onChange={on => set({ wifi_password: on })} label={t(`${k}.wifi.password`)} />
|
||||
</div>
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
if (w.kind === 'contact') {
|
||||
return (
|
||||
<Field label={t(`${k}.contact.shows`)} className="col-span-2">
|
||||
<Dropdown multiple value={w.contact_fields || ['phone', 'website', 'instagram']} onChange={contact_fields => set({ contact_fields })} data-testid="signage-widget-contact-fields"
|
||||
allLabel={t(`${k}.contact.none`)} options={CONTACT_KEYS.map(x => ({ value: x, label: t(`identity.contact.${x}`) }))} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/** Under the row: what needs more room, and what the venue still has to set. */
|
||||
export function MoreBelowFields({ w, set }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const { data: identity } = useIdentity()
|
||||
const { data: hours } = useHours()
|
||||
const k = 'signage.widgets'
|
||||
if (w.kind === 'shape') {
|
||||
return (
|
||||
<div className="grid gap-4 items-end grid-cols-[repeat(auto-fill,minmax(11rem,1fr))]">
|
||||
{w.shape === 'custom' && (
|
||||
<Field label={t(`${k}.shape.custom`)} hint={t(`${k}.shape.customHint`)} className="col-span-2">
|
||||
<Input value={w.shape_points || ''} maxLength={600} placeholder="50,0 100,100 0,100" onChange={e => set({ shape_points: e.target.value || null })} data-testid="signage-widget-shape-points" />
|
||||
</Field>
|
||||
)}
|
||||
<ColourField label={t(`${k}.shape.fill`)} value={w.fill || WIDGET_COLOURS.shape} onChange={fill => set({ fill })} testId="signage-widget-fill" />
|
||||
<ColourField label={t(`${k}.shape.fillTo`)} value={w.fill_to || WIDGET_COLOURS.shape} onChange={fill_to => set({ fill_to })} testId="signage-widget-fill-to"
|
||||
auto={{ label: t(`${k}.shape.oneColour`), on: !w.fill_to, pick: () => set({ fill_to: null }) }} />
|
||||
{w.fill_to && <Slider label={t(`${k}.shape.angle`)} value={w.fill_angle ?? 180} min={0} max={345} step={15} suffix="°" onChange={fill_angle => set({ fill_angle })} />}
|
||||
<ColourField label={t(`${k}.shape.stroke`)} value={w.stroke || WIDGET_COLOURS.text} onChange={stroke => set({ stroke, stroke_width: w.stroke_width || 4 })} testId="signage-widget-stroke"
|
||||
auto={{ label: t(`${k}.shape.noStroke`), on: !w.stroke || !w.stroke_width, pick: () => set({ stroke: null, stroke_width: 0 }) }} />
|
||||
{w.stroke && w.stroke_width > 0 && <Slider label={t(`${k}.shape.strokeWidth`)} value={w.stroke_width} min={1} max={20} onChange={stroke_width => set({ stroke_width })} />}
|
||||
{w.shape === 'star' && <Slider label={t(`${k}.shape.inner`)} value={w.shape_inner ?? 45} min={15} max={90} step={5} suffix="%" onChange={shape_inner => set({ shape_inner })} />}
|
||||
{(w.shape || 'rectangle') === 'rectangle' && <Slider label={t(`${k}.shape.radius`)} value={w.radius || 0} min={0} max={50} suffix="%" onChange={radius => set({ radius })} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
if (w.kind === 'ticker') {
|
||||
return <Slider label={t(`${k}.ticker.speed`)} value={w.ticker_speed || 4} min={1} max={10} onChange={ticker_speed => set({ ticker_speed })} testId="signage-widget-ticker-speed" />
|
||||
}
|
||||
if (w.kind === 'countdown') {
|
||||
const start = w.countdown_start || 'now'
|
||||
return (
|
||||
<div className="grid gap-4 items-end grid-cols-[repeat(auto-fill,minmax(11rem,1fr))]">
|
||||
<Field label={t(`${k}.countdown.starts`)}>
|
||||
<Dropdown value={start} onChange={countdown_start => set({ countdown_start, ...(countdown_start === 'at' && !w.countdown_at ? { countdown_at: (w.countdown_to || '15:00').slice(-5) } : {}) })}
|
||||
data-testid="signage-widget-countdown-start" options={['now', 'before', 'at'].map(v => ({ value: v, label: t(`${k}.countdown.startModes.${v}`) }))} />
|
||||
</Field>
|
||||
{start === 'before' && (
|
||||
<Field label={t(`${k}.countdown.minutesBefore`)}>
|
||||
<NumberInput value={w.countdown_before ?? 120} min={1} max={10080} suffix={t(`${k}.countdown.min`)} onChange={v => set({ countdown_before: v ?? 1 })} data-testid="signage-widget-countdown-before" />
|
||||
</Field>
|
||||
)}
|
||||
{start === 'at' && (
|
||||
<Field label={t(`${k}.countdown.startsAt`)}>
|
||||
<Input type={isDate(w.countdown_to) ? 'datetime-local' : 'time'} value={w.countdown_at || ''} onChange={e => set({ countdown_at: e.target.value || null })} />
|
||||
</Field>
|
||||
)}
|
||||
{start !== 'now' && (
|
||||
<Field label={t(`${k}.countdown.waiting`)}>
|
||||
<Dropdown value={w.countdown_waiting || 'full'} onChange={countdown_waiting => set({ countdown_waiting })}
|
||||
options={['full', 'hide'].map(v => ({ value: v, label: t(`${k}.countdown.waitingModes.${v}`) }))} />
|
||||
</Field>
|
||||
)}
|
||||
<Field label={t(`${k}.countdown.done`)} hint={t(`${k}.countdown.doneHint`)}>
|
||||
<Input value={w.countdown_done || ''} maxLength={80} placeholder={t(`${k}.countdown.donePlaceholder`)} onChange={e => set({ countdown_done: e.target.value || null, countdown_done_hide: !e.target.value })} />
|
||||
</Field>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
if (w.kind === 'hours') {
|
||||
return (
|
||||
<div className="grid gap-3">
|
||||
<Switch checked={w.hours_group !== false} onChange={hours_group => set({ hours_group })} label={t(`${k}.hours.group`)} description={t(`${k}.hours.groupHint`)} />
|
||||
{hours && !hours.set && (
|
||||
<Notice tone="warning" title={t(`${k}.hours.missing`)} data-testid="signage-widget-hours-missing">
|
||||
<Link to="/management/schedule?hours=1" className="text-accent-ink font-medium underline">{t(`${k}.hours.setThem`)}</Link>
|
||||
</Notice>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
if (w.kind === 'wifi' || w.kind === 'contact') {
|
||||
const missing = w.kind === 'wifi' ? identity && !identity.wifi?.ssid : identity && !(w.contact_fields || ['phone', 'website', 'instagram']).some(x => identity.contact?.[x])
|
||||
return missing
|
||||
? (
|
||||
<Notice tone="warning" title={t(`${k}.${w.kind}.missing`)} data-testid={`signage-widget-${w.kind}-missing`}>
|
||||
<Link to="/settings?tab=identity" className="text-accent-ink font-medium underline">{t(`${k}.fromIdentity`)}</Link>
|
||||
</Notice>
|
||||
)
|
||||
: <p className="text-caption text-ink-3 -mt-2">{t(`${k}.${w.kind}.hint`)} <Link to="/settings?tab=identity" className="text-accent-ink underline">{t(`${k}.fromIdentity`)}</Link></p>
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -18,11 +18,14 @@
|
||||
// has every setting a slide's widget has, aligned both ways in its place or moved and sized there on
|
||||
// the preview (Custom); the message of the day changed from its widget. The picked widget is a path
|
||||
// ("2", "2.1.0": see WidgetCanvas).
|
||||
// 6R.15 (owner 2026-11-22): a shape, a scrolling text, a countdown, the opening hours, Wi-Fi and contact
|
||||
// details (MoreWidgetFields).
|
||||
// Up to the venue's limit (10 recommended; Signage → Message & settings → Performance).
|
||||
import { Fragment, useEffect, useRef, useState } from 'react'
|
||||
import {
|
||||
AlignCenter, AlignLeft, AlignRight, AlignVerticalJustifyCenter, AlignVerticalJustifyEnd, AlignVerticalJustifyStart, ArrowDown, ArrowUp, Bold, Italic, Palette, RotateCcw, Underline, BookImage, CalendarDays, ChevronDown, Clock, CloudSun, Columns3, GripVertical,
|
||||
ImageIcon, LayoutList, MessageSquare, Plus, QrCode, Rows3, Store, Trash2, Type, UtensilsCrossed,
|
||||
CalendarClock, Contact, MoveHorizontal, Shapes, Timer, Wifi,
|
||||
} from 'lucide-react'
|
||||
import { cellWidgets, evenShares, setShare } from '@xenia/signage'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
@@ -31,12 +34,14 @@ import MessageOfTheDay from './MessageOfTheDay'
|
||||
import { usePerformance } from './usePerformance'
|
||||
import * as api from './signageApi'
|
||||
import MenuEditor from './MenuEditor'
|
||||
import { MoreBelowFields as MoreBelow, MoreInlineFields as MoreInline } from './MoreWidgetFields'
|
||||
import { MediaPick, Section } from './SignageFields'
|
||||
import {
|
||||
CELL_KINDS, cellWidget, fillPlace, FONT_KEYS, WIDGET_COLOURS, moved, newWidget, pickedAfterMove, presetWidget, WEATHER_CHOICES, weatherChoice, WIDGET_KINDS, WIDGET_POSITIONS,
|
||||
} from './signageLogic'
|
||||
|
||||
const ICON = { logo: ImageIcon, name: Store, date: CalendarDays, clock: Clock, message: MessageSquare, text: Type, qr: QrCode, weather: CloudSun, menu: UtensilsCrossed, hstack: Columns3, vstack: Rows3 }
|
||||
const ICON = { logo: ImageIcon, name: Store, date: CalendarDays, clock: Clock, message: MessageSquare, text: Type, qr: QrCode, weather: CloudSun, menu: UtensilsCrossed, hstack: Columns3, vstack: Rows3,
|
||||
shape: Shapes, ticker: MoveHorizontal, countdown: Timer, hours: CalendarClock, wifi: Wifi, contact: Contact }
|
||||
const iconOf = w => (w.kind === 'stack' ? (w.direction === 'column' ? Rows3 : Columns3) : ICON[w.kind] || LayoutList)
|
||||
const kindLabel = (t, w) => t(`signage.widgets.kinds.${w.kind === 'stack' ? (w.direction === 'column' ? 'vstack' : 'hstack') : w.kind}`)
|
||||
const ROW = 'grid gap-4 items-end grid-cols-[repeat(auto-fill,minmax(11rem,1fr))]'
|
||||
@@ -177,7 +182,7 @@ function VerticalField({ w, set }) {
|
||||
}
|
||||
|
||||
// which widgets have text (their colour, font, style and size), a QR code's own colours, a plate
|
||||
const TEXT_KINDS = ['name', 'date', 'clock', 'message', 'text', 'qr', 'weather']
|
||||
const TEXT_KINDS = ['name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'ticker', 'countdown', 'hours', 'wifi', 'contact']
|
||||
|
||||
/**
|
||||
* A widget's own look (owner review 5), folded under "Text and colours": its colour (text and
|
||||
@@ -187,7 +192,7 @@ const TEXT_KINDS = ['name', 'date', 'clock', 'message', 'text', 'qr', 'weather']
|
||||
function LookFields({ w, set }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [open, setOpen] = useState(false)
|
||||
if (w.kind === 'menu' || w.kind === 'stack') return null
|
||||
if (w.kind === 'menu' || w.kind === 'stack' || w.kind === 'shape') return null
|
||||
const text = TEXT_KINDS.includes(w.kind)
|
||||
const changed = !!(w.colour || w.background_colour || w.font || w.bold != null || w.italic || w.underline || (w.text_size && w.text_size !== 100) || w.qr_colour || w.qr_background)
|
||||
const styles = [w.bold !== false && 'bold', w.italic && 'italic', w.underline && 'underline'].filter(Boolean)
|
||||
@@ -218,7 +223,7 @@ function LookFields({ w, set }) {
|
||||
</Field>
|
||||
<Slider label={t('signage.widgets.textSize')} value={w.text_size || 100} min={50} max={200} step={10} suffix="%" onChange={text_size => set({ text_size })} testId="signage-widget-text-size" />
|
||||
</>}
|
||||
{w.kind === 'qr' && <>
|
||||
{(w.kind === 'qr' || w.kind === 'wifi') && <>
|
||||
<ColourField label={t('signage.widgets.qrColour')} value={w.qr_colour || WIDGET_COLOURS.qr} onChange={qr_colour => set({ qr_colour })} testId="signage-widget-qr-colour" opacity={false} />
|
||||
<ColourField label={t('signage.widgets.qrBackground')} value={w.qr_background || WIDGET_COLOURS.qrBackground} onChange={qr_background => set({ qr_background })} testId="signage-widget-qr-background" />
|
||||
</>}
|
||||
@@ -249,6 +254,7 @@ function MessageHint() {
|
||||
/** The options only some widgets have, on the same row as where / size / alignment. */
|
||||
function InlineFields({ w, set }) {
|
||||
const { t } = useTranslation('manager')
|
||||
if (['shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact'].includes(w.kind)) return <MoreInline w={w} set={set} />
|
||||
if (w.kind === 'message') {
|
||||
return (
|
||||
<Field label={t('signage.widgets.ownText')} className="col-span-2">
|
||||
@@ -305,6 +311,7 @@ function InlineFields({ w, set }) {
|
||||
/** What needs more room, under the row: the picture, hints, the QR's own link, a menu's list, a stack's parts. */
|
||||
function BelowFields({ w, set, media, onMedia, extras, path, depth, selected, onSelect }) {
|
||||
const { t } = useTranslation('manager')
|
||||
if (['shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact'].includes(w.kind)) return <MoreBelow w={w} set={set} />
|
||||
if (w.kind === 'logo') {
|
||||
return <MediaPick kind="image" value={w.media_id} entry={media[String(w.media_id)]} testid="signage-widget-logo"
|
||||
onChange={item => { onMedia(item); set({ media_id: item.id }) }} />
|
||||
|
||||
@@ -137,9 +137,9 @@ export function mediaLookup(map) {
|
||||
|
||||
// ── menu boards and widgets (5.6b) ───────────────────────────────────────────
|
||||
|
||||
export const WIDGET_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'menu']
|
||||
export const WIDGET_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'menu', 'shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact']
|
||||
/** What a stack's part can show (2026-11-21): a widget, a stack one level deep, a library slide. */
|
||||
export const CELL_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'menu']
|
||||
export const CELL_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'menu', 'shape', 'ticker', 'countdown', 'hours', 'wifi', 'contact']
|
||||
|
||||
/** A new widget of a kind ('hstack' / 'vstack': a stack side by side / one over the other), where it
|
||||
* usually goes: a menu or a stack in a box of its own (they fill a box). */
|
||||
@@ -151,16 +151,24 @@ export function newWidget(kind) {
|
||||
if (kind === 'menu') {
|
||||
return { kind, position: 'custom', size: 'custom', align: 'auto', box: { x: 55, y: 10, w: 40, h: 80 }, board: { select: 'all', columns: 1, sales_point: 'in_store' } }
|
||||
}
|
||||
return { kind, position: kind === 'message' || kind === 'text' ? 'bottom-bar' : 'top-right', size: 'medium', align: 'auto',
|
||||
...(kind === 'text' ? { text: '' } : {}) }
|
||||
if (kind === 'shape') return { kind, position: 'custom', size: 'custom', align: 'auto', box: { x: 40, y: 30, w: 20, h: 35 }, shape: 'rectangle', radius: 10 }
|
||||
return { kind, position: NEW_PLACE[kind] || 'top-right', size: 'medium', align: 'auto',
|
||||
...(kind === 'text' || kind === 'ticker' ? { text: '' } : {}), ...(kind === 'countdown' ? { countdown_to: '17:00' } : {}) }
|
||||
}
|
||||
|
||||
/** The contact details a contact widget can show (routers/identity.py Contact, signage ContactKey). */
|
||||
export const CONTACT_KEYS = ['phone', 'phone2', 'email', 'address', 'website', 'google', 'facebook', 'instagram', 'tiktok', 'tripadvisor', 'whatsapp', 'viber']
|
||||
|
||||
// where a new widget goes (6R.15 kinds; the others top right, texts in the bottom bar)
|
||||
const NEW_PLACE = { message: 'bottom-bar', text: 'bottom-bar', ticker: 'bottom-bar', countdown: 'top-center', hours: 'top-left', wifi: 'bottom-right', contact: 'bottom-left' }
|
||||
|
||||
/** A widget put in a stack's part: only what it shows (a part has no corner, size or box). */
|
||||
export function cellWidget(kind) {
|
||||
if (kind === 'hstack' || kind === 'vstack') {
|
||||
return { kind: 'stack', direction: kind === 'hstack' ? 'row' : 'column', align: 'auto', cells: [{ share: 50 }, { share: 50 }] }
|
||||
}
|
||||
return { kind, align: 'auto', ...(kind === 'menu' ? { board: { select: 'all', columns: 1, sales_point: 'in_store' } } : {}), ...(kind === 'text' ? { text: '' } : {}) }
|
||||
return { kind, align: 'auto', ...(kind === 'menu' ? { board: { select: 'all', columns: 1, sales_point: 'in_store' } } : {}), ...(kind === 'text' || kind === 'ticker' ? { text: '' } : {}),
|
||||
...(kind === 'countdown' ? { countdown_to: '17:00' } : {}) }
|
||||
}
|
||||
|
||||
/** The weather's days, as one choice: from (0 today, 1 tomorrow, 2 the day after) and how many. */
|
||||
@@ -388,7 +396,7 @@ export function toggleMonthDay(line, key) {
|
||||
/** A menu's colours until the venue picks its own (the TV's data, as the player draws them). */
|
||||
export const MENU_COLOURS = { accent: '#f59e0b', text: '#ffffff', newBadge: '#38bdf8' }
|
||||
/** A widget's colours before the venue picks its own (owner review 5). */
|
||||
export const WIDGET_COLOURS = { text: '#ffffff', plate: '#00000080', qr: '#000000', qrBackground: '#ffffff' }
|
||||
export const WIDGET_COLOURS = { text: '#ffffff', plate: '#00000080', qr: '#000000', qrBackground: '#ffffff', shape: '#f59e0b' }
|
||||
|
||||
/** A menu's look as new ("Reset the look", owner review 4): every part back to the board's. */
|
||||
export const MENU_LOOK_DEFAULTS = {
|
||||
|
||||
@@ -5,6 +5,13 @@ import client from '../api/client'
|
||||
|
||||
export const IDENTITY_KEY = ['identity']
|
||||
|
||||
/** The venue's opening hours (6R.15): { days: [[{from, to}]…7], note, set }; edited on the Schedule page. */
|
||||
export const HOURS_KEY = ['opening-hours']
|
||||
export function useHours() {
|
||||
const can = useCan('core.dashboard.access')
|
||||
return useQuery({ queryKey: HOURS_KEY, queryFn: () => client.get('/api/identity/hours').then(r => r.data), enabled: !!can, staleTime: 60_000 })
|
||||
}
|
||||
|
||||
/** The venue's identity ({ name, slogan, colours, logos, wifi, contact }); data undefined while it loads. */
|
||||
export function useIdentity() {
|
||||
const can = useCan('core.dashboard.access')
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
customKeys, filterStaff, groupCounts, groupOf, staffBody, staffForm, staffProblems, validPin, zonesBody, zonesOf, zonesSummary,
|
||||
} from '../src/pages/staff/staffLogic.js'
|
||||
import {
|
||||
addDays, clashWith, gridOf, hourMarks, hoursOf, inOpening, loadView, overlaps, placeOnDay, saveView, shiftState, weekDays, weekStartOf, weekTotals,
|
||||
addDays, clashWith, gridOf, hourMarks, hoursOf, hoursValid, inOpening, inSpans, loadView, overlaps, placeOnDay, saveView, shiftState, weekDays, weekStartOf, weekTotals,
|
||||
} from '../src/pages/schedule/scheduleLogic.js'
|
||||
|
||||
const staff = [
|
||||
@@ -79,6 +79,12 @@ test('shifts: hours past midnight, clashes, the grid, states, totals, the timeli
|
||||
assert.equal(hourMarks(22)[2], 0)
|
||||
assert.equal(inOpening(23, '18:00', '02:00'), true)
|
||||
assert.equal(inOpening(3, '18:00', '02:00'), false)
|
||||
// the venue's hours, several spans a day (6R.15)
|
||||
assert.equal(inSpans(13, [{ from: '12:00', to: '15:00' }, { from: '18:00', to: '23:00' }]), true)
|
||||
assert.equal(inSpans(16, [{ from: '12:00', to: '15:00' }, { from: '18:00', to: '23:00' }]), false)
|
||||
assert.equal(inSpans(10, undefined), false)
|
||||
assert.equal(hoursValid([[{ from: '12:00', to: '15:00' }], []]), true)
|
||||
assert.equal(hoursValid([[{ from: '12:00', to: '' }]]), false)
|
||||
})
|
||||
|
||||
test('the view settings stay in this browser and survive a broken store', () => {
|
||||
|
||||
Reference in New Issue
Block a user