|
|
|
@@ -1,15 +1,22 @@
|
|
|
|
|
// Settings → Customer display (plan step 3.4). What the customer displays show between sales,
|
|
|
|
|
// the venue's own style (owner, 2026-11-16): the name, the logo, both, nothing, one image, a
|
|
|
|
|
// slideshow of photos, or a QR code (the venue's ordering link, its QR menu, or any link), with
|
|
|
|
|
// an optional line of text, dark or light. Images are uploaded here (JPG/PNG/WebP/GIF, ≤ 5 MB).
|
|
|
|
|
// Saving reaches every display at once. Backend: /api/display/settings, /api/display/media.
|
|
|
|
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
|
|
|
// Settings → Customer display (plan steps 3.4, 5.3). What the customer displays show between
|
|
|
|
|
// sales is a **look** the venue designs (owner, 2026-11-16: "configurable, so each venue can
|
|
|
|
|
// choose their style"): the name, the logo, both, nothing, one picture, a slideshow, or a QR code
|
|
|
|
|
// (the venue's ordering link, its QR menu, or any link), with an optional line of text, dark or
|
|
|
|
|
// light. A venue can have several looks; one is the default and each display can show its own
|
|
|
|
|
// (also its "Idle screen" in Devices). Pictures come from the media library (Management → Media).
|
|
|
|
|
// Saving reaches the displays that show the look at once.
|
|
|
|
|
// Backend: /api/display/looks, /api/display/displays (routers/customer_display.py).
|
|
|
|
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
|
|
|
|
import toast from 'react-hot-toast'
|
|
|
|
|
import { Check, ImagePlus, Trash2 } from 'lucide-react'
|
|
|
|
|
import { ArrowLeft, ArrowRight, Check, Images, Plus, Star, Trash2, X } from 'lucide-react'
|
|
|
|
|
import { errorMessage } from '@xenia/api'
|
|
|
|
|
import { useTranslation } from '@xenia/i18n'
|
|
|
|
|
import { Button, Field, IconButton, Input, Select, Spinner } from '@xenia/ui'
|
|
|
|
|
import { Button, Dialog, Field, IconButton, Input, Select, Spinner, Switch } from '@xenia/ui'
|
|
|
|
|
import client from '../../../api/client'
|
|
|
|
|
import MediaField from '../../media/MediaField'
|
|
|
|
|
import MediaPicker from '../../media/MediaPicker'
|
|
|
|
|
import { imageOf } from '../../media/mediaLogic'
|
|
|
|
|
import { MediaThumb } from '../../media/MediaParts'
|
|
|
|
|
import { useSettings } from './useSettings'
|
|
|
|
|
|
|
|
|
|
const STYLES = ['name', 'logo', 'name_logo', 'blank', 'image', 'slideshow', 'qr']
|
|
|
|
@@ -17,59 +24,53 @@ const STYLES = ['name', 'logo', 'name_logo', 'blank', 'image', 'slideshow', 'qr'
|
|
|
|
|
export default function CustomerDisplaySettings() {
|
|
|
|
|
const { t } = useTranslation('manager')
|
|
|
|
|
const venue = useSettings()
|
|
|
|
|
const [data, setData] = useState(null)
|
|
|
|
|
const [form, setForm] = useState(null)
|
|
|
|
|
const [looks, setLooks] = useState(null)
|
|
|
|
|
const [displays, setDisplays] = useState([])
|
|
|
|
|
const [current, setCurrent] = useState(null) // the look being edited (id)
|
|
|
|
|
const [form, setForm] = useState(null) // its config
|
|
|
|
|
const [pics, setPics] = useState({}) // media id → image {id, name, thumb, card, full}
|
|
|
|
|
const [lookName, setLookName] = useState('')
|
|
|
|
|
const [busy, setBusy] = useState(false)
|
|
|
|
|
const [name, setName] = useState(null)
|
|
|
|
|
const fileRef = useRef(null)
|
|
|
|
|
const [venueName, setVenueName] = useState(null)
|
|
|
|
|
const [adding, setAdding] = useState(false)
|
|
|
|
|
const [confirmDelete, setConfirmDelete] = useState(false)
|
|
|
|
|
|
|
|
|
|
const load = useCallback(async () => {
|
|
|
|
|
const open = useCallback(look => {
|
|
|
|
|
setCurrent(look.id)
|
|
|
|
|
setForm(look.config)
|
|
|
|
|
setLookName(look.name)
|
|
|
|
|
setPics(p => ({ ...p, ...Object.fromEntries(Object.entries(look.pictures || {}).map(([k, v]) => [Number(k), v])) }))
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
const load = useCallback(async (pick) => {
|
|
|
|
|
try {
|
|
|
|
|
const { data: d } = await client.get('/api/display/settings')
|
|
|
|
|
setData(d)
|
|
|
|
|
setForm(f => f ?? d.idle)
|
|
|
|
|
} catch (err) { toast.error(errorMessage(err, t)) }
|
|
|
|
|
}, [t])
|
|
|
|
|
useEffect(() => { load() }, [load])
|
|
|
|
|
const [{ data: ls }, { data: ds }] = await Promise.all([client.get('/api/display/looks'), client.get('/api/display/displays')])
|
|
|
|
|
setLooks(ls)
|
|
|
|
|
setDisplays(ds)
|
|
|
|
|
const target = ls.find(l => l.id === pick) || null
|
|
|
|
|
if (target) open(target)
|
|
|
|
|
return ls
|
|
|
|
|
} catch (err) { toast.error(errorMessage(err, t)); return null }
|
|
|
|
|
}, [t, open])
|
|
|
|
|
useEffect(() => { load().then(ls => { if (ls?.length) open(ls[0]) }) }, [load, open])
|
|
|
|
|
|
|
|
|
|
const look = looks?.find(l => l.id === current)
|
|
|
|
|
const dirty = useMemo(() => look && (JSON.stringify(look.config) !== JSON.stringify(form) || lookName.trim() !== look.name), [look, form, lookName])
|
|
|
|
|
if (!looks || !form || !look || venue.loading) return <div className="py-8 flex justify-center"><Spinner /></div>
|
|
|
|
|
|
|
|
|
|
if (!data || !form || venue.loading) return <div className="py-8 flex justify-center"><Spinner /></div>
|
|
|
|
|
const set = (k, v) => setForm(f => ({ ...f, [k]: v }))
|
|
|
|
|
const media = data.media
|
|
|
|
|
const needs = { logo: ['logo', 'name_logo'], image: ['image'], slides: ['slideshow'], qr: ['qr'] }
|
|
|
|
|
const shows = part => needs[part].includes(form.style)
|
|
|
|
|
const shows = part => ({ logo: ['logo', 'name_logo'], image: ['image'], slides: ['slideshow'], qr: ['qr'] })[part].includes(form.style)
|
|
|
|
|
const picOf = id => (id ? pics[id] ?? null : null)
|
|
|
|
|
const setPic = (key, image) => { if (image) setPics(p => ({ ...p, [image.id]: image })); set(key, image?.id ?? null) }
|
|
|
|
|
|
|
|
|
|
const save = async () => {
|
|
|
|
|
const act = async (fn, done, pick = current) => {
|
|
|
|
|
setBusy(true)
|
|
|
|
|
try {
|
|
|
|
|
const { data: d } = await client.put('/api/display/settings', form)
|
|
|
|
|
setData(d)
|
|
|
|
|
setForm(d.idle)
|
|
|
|
|
toast.success(t('settings.saved'))
|
|
|
|
|
} catch (err) { toast.error(errorMessage(err, t)) }
|
|
|
|
|
try { await fn(); if (done) toast.success(done); await load(pick) } catch (err) { toast.error(errorMessage(err, t)) }
|
|
|
|
|
setBusy(false)
|
|
|
|
|
}
|
|
|
|
|
const upload = async e => {
|
|
|
|
|
const files = [...(e.target.files ?? [])]
|
|
|
|
|
e.target.value = ''
|
|
|
|
|
for (const file of files) {
|
|
|
|
|
const body = new FormData()
|
|
|
|
|
body.append('file', file)
|
|
|
|
|
try {
|
|
|
|
|
const { data: m } = await client.post('/api/display/media', body)
|
|
|
|
|
setData(d => ({ ...d, media: [...d.media, m] }))
|
|
|
|
|
if (form.style === 'slideshow') setForm(f => ({ ...f, slides: [...f.slides, m.name] }))
|
|
|
|
|
} catch (err) { toast.error(errorMessage(err, t)) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const remove = async m => {
|
|
|
|
|
try {
|
|
|
|
|
await client.delete(`/api/display/media/${m.name}`)
|
|
|
|
|
setData(d => ({ ...d, media: d.media.filter(x => x.name !== m.name) }))
|
|
|
|
|
setForm(f => ({ ...f, logo: f.logo === m.name ? null : f.logo, image: f.image === m.name ? null : f.image,
|
|
|
|
|
slides: f.slides.filter(n => n !== m.name) }))
|
|
|
|
|
} catch (err) { toast.error(errorMessage(err, t)) }
|
|
|
|
|
}
|
|
|
|
|
const toggleSlide = n => set('slides', form.slides.includes(n) ? form.slides.filter(x => x !== n) : [...form.slides, n])
|
|
|
|
|
const save = () => act(() => client.put(`/api/display/looks/${look.id}`, { name: lookName.trim() || look.name, config: form }), t('settings.saved'))
|
|
|
|
|
const lookLabel = l => `${l.name}${l.is_default ? ` (${t('display.looks.default')})` : ''}`
|
|
|
|
|
const defaultLook = looks.find(l => l.is_default)
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<section className="bg-surface border border-line rounded-card shadow-raised grid gap-5 p-5" data-testid="settings-display">
|
|
|
|
@@ -78,101 +79,210 @@ export default function CustomerDisplaySettings() {
|
|
|
|
|
<p className="text-label text-ink-2">{t('display.intro')}</p>
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
<div className="grid gap-2" role="radiogroup" aria-label={t('display.style')}>
|
|
|
|
|
<span className="text-label font-medium text-ink-2">{t('display.style')}</span>
|
|
|
|
|
<div className="grid gap-2" style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(10rem, 1fr))' }}>
|
|
|
|
|
{STYLES.map(s => (
|
|
|
|
|
<button key={s} type="button" role="radio" aria-checked={form.style === s} onClick={() => set('style', s)} data-testid={`display-style-${s}`}
|
|
|
|
|
className={`p-3 rounded-control border text-left grid gap-0.5 transition-colors duration-fast
|
|
|
|
|
${form.style === s ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line bg-surface-2 text-ink hover:bg-surface-3'}`}>
|
|
|
|
|
<span className="text-body font-medium flex items-center gap-1.5">{form.style === s && <Check size={14} aria-hidden="true" />}{t(`display.styles.${s}.name`)}</span>
|
|
|
|
|
<span className="text-caption text-ink-2">{t(`display.styles.${s}.hint`)}</span>
|
|
|
|
|
{/* the looks */}
|
|
|
|
|
<div className="grid gap-2">
|
|
|
|
|
<span className="text-label font-medium text-ink-2">{t('display.looks.title')}</span>
|
|
|
|
|
<div className="flex flex-wrap gap-2" role="tablist" aria-label={t('display.looks.title')}>
|
|
|
|
|
{looks.map(l => (
|
|
|
|
|
<button key={l.id} type="button" role="tab" aria-selected={l.id === current} data-testid="display-look" data-name={l.name}
|
|
|
|
|
onClick={() => (dirty && !window.confirm(t('display.looks.discard')) ? null : open(l))}
|
|
|
|
|
className={`px-3 py-2 rounded-control border text-label font-medium flex items-center gap-1.5 transition-colors duration-fast
|
|
|
|
|
${l.id === current ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line bg-surface-2 text-ink hover:bg-surface-3'}`}>
|
|
|
|
|
{l.is_default && <Star size={14} aria-label={t('display.looks.default')} />}
|
|
|
|
|
{l.name}
|
|
|
|
|
<span className="text-caption text-ink-3 font-normal">{t('display.looks.screens', { count: l.displays.length })}</span>
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
<Button size="sm" variant="ghost" icon={<Plus size={14} />} onClick={() => setAdding(true)} data-testid="display-look-new">{t('display.looks.new')}</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="grid gap-3 sm:grid-cols-2">
|
|
|
|
|
<div className="flex items-start gap-2">
|
|
|
|
|
<Field label={t('display.venueName')} hint={t('display.venueNameHint')} className="flex-1">
|
|
|
|
|
<Input value={name ?? venue.get('venue.name', '')} onChange={e => setName(e.target.value)} maxLength={80} data-testid="display-venue-name" />
|
|
|
|
|
{/* the look being edited */}
|
|
|
|
|
<div className="grid gap-5 rounded-card border border-line p-4" data-testid="display-look-editor" data-id={look.id}>
|
|
|
|
|
<div className="flex flex-wrap items-end gap-2">
|
|
|
|
|
<Field label={t('display.looks.name')} className="flex-1 min-w-[12rem]">
|
|
|
|
|
<Input value={lookName} maxLength={60} onChange={e => setLookName(e.target.value)} data-testid="display-look-name" />
|
|
|
|
|
</Field>
|
|
|
|
|
<Button variant="secondary" className="mt-7" disabled={name == null || venue.saving} data-testid="display-venue-name-save"
|
|
|
|
|
onClick={() => { venue.save('venue.name', name.trim()); setName(null) }}>{t('fees.save')}</Button>
|
|
|
|
|
{look.is_default
|
|
|
|
|
? <span className="text-label text-ink-2 flex items-center gap-1 h-control"><Star size={14} aria-hidden="true" />{t('display.looks.isDefault')}</span>
|
|
|
|
|
: <>
|
|
|
|
|
<Button variant="secondary" disabled={busy} onClick={() => act(() => client.post(`/api/display/looks/${look.id}/default`), t('display.looks.madeDefault'))}
|
|
|
|
|
data-testid="display-look-default">{t('display.looks.makeDefault')}</Button>
|
|
|
|
|
<IconButton variant="ghost" label={t('fees.delete')} disabled={busy} onClick={() => setConfirmDelete(true)} data-testid="display-look-delete"><Trash2 size={16} /></IconButton>
|
|
|
|
|
</>}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="grid gap-2" role="radiogroup" aria-label={t('display.style')}>
|
|
|
|
|
<span className="text-label font-medium text-ink-2">{t('display.style')}</span>
|
|
|
|
|
<div className="grid gap-2" style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(10rem, 1fr))' }}>
|
|
|
|
|
{STYLES.map(s => (
|
|
|
|
|
<button key={s} type="button" role="radio" aria-checked={form.style === s} onClick={() => set('style', s)} data-testid={`display-style-${s}`}
|
|
|
|
|
className={`p-3 rounded-control border text-left grid gap-0.5 transition-colors duration-fast
|
|
|
|
|
${form.style === s ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line bg-surface-2 text-ink hover:bg-surface-3'}`}>
|
|
|
|
|
<span className="text-body font-medium flex items-center gap-1.5">{form.style === s && <Check size={14} aria-hidden="true" />}{t(`display.styles.${s}.name`)}</span>
|
|
|
|
|
<span className="text-caption text-ink-2">{t(`display.styles.${s}.hint`)}</span>
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{form.style !== 'blank' && (
|
|
|
|
|
<Field label={t('display.message')} hint={t('display.messageHint')}>
|
|
|
|
|
<Input value={form.message ?? ''} onChange={e => set('message', e.target.value)} maxLength={120} data-testid="display-message" />
|
|
|
|
|
</Field>
|
|
|
|
|
)}
|
|
|
|
|
<Field label={t('display.theme')}>
|
|
|
|
|
<Select value={form.theme} onChange={e => set('theme', e.target.value)} data-testid="display-theme">
|
|
|
|
|
<option value="dark">{t('display.themes.dark')}</option>
|
|
|
|
|
<option value="light">{t('display.themes.light')}</option>
|
|
|
|
|
</Select>
|
|
|
|
|
</Field>
|
|
|
|
|
{shows('slides') && (
|
|
|
|
|
<Field label={t('display.slideSeconds')}>
|
|
|
|
|
<Input inputMode="numeric" value={String(form.slide_seconds)} data-testid="display-slide-seconds"
|
|
|
|
|
onChange={e => set('slide_seconds', Number(e.target.value.replace(/\D/g, '')) || 0)} />
|
|
|
|
|
</Field>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{shows('qr') && (
|
|
|
|
|
<div className="grid gap-3 sm:grid-cols-2">
|
|
|
|
|
<Field label={t('display.qrTarget')}>
|
|
|
|
|
<Select value={form.qr_target} onChange={e => set('qr_target', e.target.value)} data-testid="display-qr-target">
|
|
|
|
|
{['ordering', 'menu', 'custom'].map(q => <option key={q} value={q}>{t(`display.qrTargets.${q}`)}</option>)}
|
|
|
|
|
</Select>
|
|
|
|
|
</Field>
|
|
|
|
|
{form.qr_target === 'custom' && (
|
|
|
|
|
<Field label={t('display.qrUrl')}>
|
|
|
|
|
<Input value={form.qr_url ?? ''} onChange={e => set('qr_url', e.target.value)} placeholder="https://" data-testid="display-qr-url" />
|
|
|
|
|
{form.style !== 'blank' && (
|
|
|
|
|
<Field label={t('display.message')} hint={t('display.messageHint')}>
|
|
|
|
|
<Input value={form.message ?? ''} onChange={e => set('message', e.target.value)} maxLength={120} data-testid="display-message" />
|
|
|
|
|
</Field>
|
|
|
|
|
)}
|
|
|
|
|
<Field label={t('display.qrCaption')}>
|
|
|
|
|
<Input value={form.qr_caption ?? ''} onChange={e => set('qr_caption', e.target.value)} maxLength={80} data-testid="display-qr-caption" />
|
|
|
|
|
<Field label={t('display.theme')}>
|
|
|
|
|
<Select value={form.theme} onChange={e => set('theme', e.target.value)} data-testid="display-theme">
|
|
|
|
|
<option value="dark">{t('display.themes.dark')}</option>
|
|
|
|
|
<option value="light">{t('display.themes.light')}</option>
|
|
|
|
|
</Select>
|
|
|
|
|
</Field>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{(shows('logo') || shows('image') || shows('slides')) && (
|
|
|
|
|
<div className="grid gap-3">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<span className="flex-1 text-label font-medium text-ink-2">
|
|
|
|
|
{t(shows('logo') ? 'display.pickLogo' : shows('image') ? 'display.pickImage' : 'display.pickSlides')}
|
|
|
|
|
</span>
|
|
|
|
|
<input ref={fileRef} type="file" accept="image/jpeg,image/png,image/webp,image/gif" multiple className="hidden" onChange={upload} data-testid="display-upload" />
|
|
|
|
|
<Button size="sm" variant="secondary" icon={<ImagePlus size={16} />} onClick={() => fileRef.current?.click()}>{t('display.upload')}</Button>
|
|
|
|
|
</div>
|
|
|
|
|
{media.length === 0 ? (
|
|
|
|
|
<p className="text-label text-ink-3">{t('display.noImages')}</p>
|
|
|
|
|
) : (
|
|
|
|
|
<ul className="grid gap-3" style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(9rem, 1fr))' }} data-testid="display-media">
|
|
|
|
|
{media.map(m => {
|
|
|
|
|
const chosen = shows('logo') ? form.logo === m.name : shows('image') ? form.image === m.name : form.slides.includes(m.name)
|
|
|
|
|
const pick = () => (shows('logo') ? set('logo', m.name) : shows('image') ? set('image', m.name) : toggleSlide(m.name))
|
|
|
|
|
return (
|
|
|
|
|
<li key={m.name} className={`relative rounded-control border-2 overflow-hidden ${chosen ? 'border-accent' : 'border-line'}`}>
|
|
|
|
|
<button type="button" onClick={pick} aria-pressed={chosen} className="block w-full aspect-video bg-surface-2" data-testid="display-media-pick">
|
|
|
|
|
<img src={m.url} alt="" className="w-full h-full object-contain" />
|
|
|
|
|
</button>
|
|
|
|
|
{chosen && shows('slides') && (
|
|
|
|
|
<span className="absolute top-1 left-1 min-w-6 h-6 px-1 rounded-full bg-accent text-accent-fg text-caption font-bold flex items-center justify-center">
|
|
|
|
|
{form.slides.indexOf(m.name) + 1}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
<IconButton size="sm" variant="secondary" label={t('fees.delete')} className="absolute top-1 right-1" onClick={() => remove(m)}><Trash2 size={14} /></IconButton>
|
|
|
|
|
</li>
|
|
|
|
|
)
|
|
|
|
|
})}
|
|
|
|
|
</ul>
|
|
|
|
|
{shows('slides') && (
|
|
|
|
|
<Field label={t('display.slideSeconds')}>
|
|
|
|
|
<Input inputMode="numeric" value={String(form.slide_seconds)} data-testid="display-slide-seconds"
|
|
|
|
|
onChange={e => set('slide_seconds', Number(e.target.value.replace(/\D/g, '')) || 0)} />
|
|
|
|
|
</Field>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<div><Button onClick={save} loading={busy} data-testid="display-save">{t('fees.save')}</Button></div>
|
|
|
|
|
{shows('qr') && (
|
|
|
|
|
<div className="grid gap-3 sm:grid-cols-2">
|
|
|
|
|
<Field label={t('display.qrTarget')}>
|
|
|
|
|
<Select value={form.qr_target} onChange={e => set('qr_target', e.target.value)} data-testid="display-qr-target">
|
|
|
|
|
{['ordering', 'menu', 'custom'].map(q => <option key={q} value={q}>{t(`display.qrTargets.${q}`)}</option>)}
|
|
|
|
|
</Select>
|
|
|
|
|
</Field>
|
|
|
|
|
{form.qr_target === 'custom' && (
|
|
|
|
|
<Field label={t('display.qrUrl')}>
|
|
|
|
|
<Input value={form.qr_url ?? ''} onChange={e => set('qr_url', e.target.value)} placeholder="https://" data-testid="display-qr-url" />
|
|
|
|
|
</Field>
|
|
|
|
|
)}
|
|
|
|
|
<Field label={t('display.qrCaption')}>
|
|
|
|
|
<Input value={form.qr_caption ?? ''} onChange={e => set('qr_caption', e.target.value)} maxLength={80} data-testid="display-qr-caption" />
|
|
|
|
|
</Field>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{shows('logo') && <MediaField value={picOf(form.logo)} onChange={img => setPic('logo', img)} label={t('display.pickLogo')} testid="display-logo" />}
|
|
|
|
|
{shows('image') && <MediaField value={picOf(form.image)} onChange={img => setPic('image', img)} label={t('display.pickImage')} testid="display-image" />}
|
|
|
|
|
{shows('slides') && <Slides ids={form.slides} pics={pics} onChange={(ids, more) => { if (more) setPics(p => ({ ...p, ...more })); set('slides', ids) }} />}
|
|
|
|
|
|
|
|
|
|
<div className="flex gap-2 items-center">
|
|
|
|
|
<Button onClick={save} loading={busy} data-testid="display-save">{t('fees.save')}</Button>
|
|
|
|
|
{dirty && <span className="text-label text-ink-3">{t('display.looks.unsaved')}</span>}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* which display shows which look */}
|
|
|
|
|
<div className="grid gap-2" data-testid="display-screens">
|
|
|
|
|
<span className="text-label font-medium text-ink-2">{t('display.looks.whichScreen')}</span>
|
|
|
|
|
{displays.length === 0 ? <p className="text-label text-ink-3">{t('display.looks.noScreens')}</p> : (
|
|
|
|
|
<ul className="grid gap-2">
|
|
|
|
|
{displays.map(d => (
|
|
|
|
|
<li key={d.id} className="flex flex-wrap items-center gap-3">
|
|
|
|
|
<span className="text-body text-ink min-w-[10rem]">{d.name}</span>
|
|
|
|
|
<Select value={d.look_id == null ? '' : String(d.look_id)} aria-label={t('display.looks.lookFor', { name: d.name })} data-testid={`display-assign-${d.id}`}
|
|
|
|
|
onChange={e => act(() => client.put(`/api/display/displays/${d.id}/look`, { look_id: e.target.value ? Number(e.target.value) : null }), t('settings.saved'))}
|
|
|
|
|
options={[{ value: '', label: t('display.looks.followDefault', { name: defaultLook?.name ?? '' }) },
|
|
|
|
|
...looks.map(l => ({ value: String(l.id), label: lookLabel(l) }))]} />
|
|
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex items-start gap-2 max-w-xl">
|
|
|
|
|
<Field label={t('display.venueName')} hint={t('display.venueNameHint')} className="flex-1">
|
|
|
|
|
<Input value={venueName ?? venue.get('venue.name', '')} onChange={e => setVenueName(e.target.value)} maxLength={80} data-testid="display-venue-name" />
|
|
|
|
|
</Field>
|
|
|
|
|
<Button variant="secondary" className="mt-7" disabled={venueName == null || venue.saving} data-testid="display-venue-name-save"
|
|
|
|
|
onClick={() => { venue.save('venue.name', venueName.trim()); setVenueName(null) }}>{t('fees.save')}</Button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{adding && <NewLook looks={looks} current={look} onClose={() => setAdding(false)}
|
|
|
|
|
onCreate={async body => {
|
|
|
|
|
setBusy(true)
|
|
|
|
|
try {
|
|
|
|
|
const { data } = await client.post('/api/display/looks', body)
|
|
|
|
|
setAdding(false)
|
|
|
|
|
toast.success(t('display.looks.created'))
|
|
|
|
|
await load(data.id)
|
|
|
|
|
} catch (err) { toast.error(errorMessage(err, t)) }
|
|
|
|
|
setBusy(false)
|
|
|
|
|
}} />}
|
|
|
|
|
|
|
|
|
|
{confirmDelete && (
|
|
|
|
|
<Dialog open size="sm" title={t('display.looks.deleteTitle', { name: look.name })} onClose={() => setConfirmDelete(false)}
|
|
|
|
|
footer={<>
|
|
|
|
|
<Button variant="secondary" onClick={() => setConfirmDelete(false)}>{t('fees.cancel')}</Button>
|
|
|
|
|
<Button variant="danger" loading={busy} data-testid="display-look-delete-confirm"
|
|
|
|
|
onClick={() => act(() => client.delete(`/api/display/looks/${look.id}`), t('display.looks.deleted'), defaultLook?.id)
|
|
|
|
|
.then(() => setConfirmDelete(false))}>{t('fees.delete')}</Button>
|
|
|
|
|
</>}>
|
|
|
|
|
<p className="text-body text-ink-2">{t('display.looks.deleteBody', { name: defaultLook?.name ?? '' })}</p>
|
|
|
|
|
</Dialog>
|
|
|
|
|
)}
|
|
|
|
|
</section>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** The slideshow's pictures, in order: move, remove, add from the library (several at once). */
|
|
|
|
|
function Slides({ ids, pics, onChange }) {
|
|
|
|
|
const { t } = useTranslation('manager')
|
|
|
|
|
const [picking, setPicking] = useState(false)
|
|
|
|
|
const move = (i, d) => { const next = [...ids]; [next[i], next[i + d]] = [next[i + d], next[i]]; onChange(next) }
|
|
|
|
|
return (
|
|
|
|
|
<div className="grid gap-2" data-testid="display-slides">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<span className="flex-1 text-label font-medium text-ink-2">{t('display.pickSlides')}</span>
|
|
|
|
|
<Button size="sm" variant="secondary" icon={<Images size={14} />} onClick={() => setPicking(true)} data-testid="display-slides-add">{t('display.addSlides')}</Button>
|
|
|
|
|
</div>
|
|
|
|
|
{ids.length === 0 ? <p className="text-label text-ink-3">{t('display.noSlides')}</p> : (
|
|
|
|
|
<ol className="grid gap-3" style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(8.5rem, 1fr))' }}>
|
|
|
|
|
{ids.map((id, i) => (
|
|
|
|
|
<li key={`${id}:${i}`} className="relative rounded-control border border-line overflow-hidden bg-surface-2" data-testid="display-slide-item" data-id={id}>
|
|
|
|
|
<MediaThumb item={pics[id]} className="w-full aspect-video" />
|
|
|
|
|
<span className="absolute top-1 left-1 min-w-6 h-6 px-1 rounded-full bg-accent text-accent-fg text-caption font-bold flex items-center justify-center">{i + 1}</span>
|
|
|
|
|
<span className="block px-2 pt-1 text-caption text-ink-2 truncate" title={pics[id]?.name}>{pics[id]?.name}</span>
|
|
|
|
|
<div className="flex items-center justify-between px-1 pb-1 gap-1">
|
|
|
|
|
<IconButton size="sm" variant="ghost" label={t('display.earlier')} disabled={i === 0} onClick={() => move(i, -1)}><ArrowLeft size={14} /></IconButton>
|
|
|
|
|
<IconButton size="sm" variant="ghost" label={t('display.later')} disabled={i === ids.length - 1} onClick={() => move(i, 1)}><ArrowRight size={14} /></IconButton>
|
|
|
|
|
<IconButton size="sm" variant="ghost" label={t('media.removePhoto')} onClick={() => onChange(ids.filter((_, j) => j !== i))}><X size={14} /></IconButton>
|
|
|
|
|
</div>
|
|
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
</ol>
|
|
|
|
|
)}
|
|
|
|
|
{picking && <MediaPicker open multiple onClose={() => setPicking(false)}
|
|
|
|
|
onPickMany={items => {
|
|
|
|
|
const more = Object.fromEntries(items.map(it => [it.id, imageOf(it)]).filter(([, v]) => v))
|
|
|
|
|
onChange([...ids, ...items.map(it => it.id).filter(id => more[id])], more)
|
|
|
|
|
setPicking(false)
|
|
|
|
|
}} />}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** A new look: a name, empty or a copy of the one on screen. */
|
|
|
|
|
function NewLook({ looks, current, onClose, onCreate }) {
|
|
|
|
|
const { t } = useTranslation('manager')
|
|
|
|
|
const [name, setName] = useState('')
|
|
|
|
|
const [copy, setCopy] = useState(true)
|
|
|
|
|
const taken = looks.some(l => l.name.toLowerCase() === name.trim().toLowerCase())
|
|
|
|
|
return (
|
|
|
|
|
<Dialog open size="sm" title={t('display.looks.new')} onClose={onClose}
|
|
|
|
|
footer={<>
|
|
|
|
|
<Button variant="secondary" onClick={onClose}>{t('fees.cancel')}</Button>
|
|
|
|
|
<Button disabled={!name.trim() || taken} data-testid="display-look-create"
|
|
|
|
|
onClick={() => onCreate({ name: name.trim(), ...(copy ? { copy_of: current.id } : {}) })}>{t('display.looks.create')}</Button>
|
|
|
|
|
</>}>
|
|
|
|
|
<div className="grid gap-3">
|
|
|
|
|
<Field label={t('display.looks.name')} error={taken ? t('display.looks.taken') : undefined}>
|
|
|
|
|
<Input value={name} autoFocus maxLength={60} onChange={e => setName(e.target.value)} placeholder={t('display.looks.namePlaceholder')} data-testid="display-look-new-name" />
|
|
|
|
|
</Field>
|
|
|
|
|
<Switch checked={copy} onChange={setCopy} label={t('display.looks.copyOf', { name: current.name })} />
|
|
|
|
|
</div>
|
|
|
|
|
</Dialog>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|