From 6d84e43330cc779f0e1a848b2e658e9862b394b4 Mon Sep 17 00:00:00 2001 From: bonamin Date: Tue, 17 Nov 2026 17:50:52 +0200 Subject: [PATCH] feat(manager): customer display looks: several, a default, one per display; pictures from the library (platform-v2 step 5.3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settings → Customer display lists the looks (default starred, how many displays each), edits one (logo / picture with MediaField, the slideshow's pictures picked several at a time, reordered, removed), new look (empty or a copy), make default, delete, and "Which display shows which look". The Devices page offers the looks for a display's Idle screen. MediaPicker: `multiple`. Co-Authored-By: Claude Opus 5.5 --- .../sections/CustomerDisplaySettings.jsx | 374 +++++++++++------- .../src/pages/media/MediaParts.jsx | 7 +- .../src/pages/media/MediaPicker.jsx | 22 +- .../src/pages/platform/DeviceConfigFields.jsx | 5 +- .../src/pages/platform/devicesLogic.js | 5 +- packages/i18n/locales/el/manager.json | 45 ++- packages/i18n/locales/en/manager.json | 45 ++- 7 files changed, 343 insertions(+), 160 deletions(-) diff --git a/manager_dashboard/src/pages/Settings/sections/CustomerDisplaySettings.jsx b/manager_dashboard/src/pages/Settings/sections/CustomerDisplaySettings.jsx index 6f06e03..fa4554d 100644 --- a/manager_dashboard/src/pages/Settings/sections/CustomerDisplaySettings.jsx +++ b/manager_dashboard/src/pages/Settings/sections/CustomerDisplaySettings.jsx @@ -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
- if (!data || !form || venue.loading) return
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 (
@@ -78,101 +79,210 @@ export default function CustomerDisplaySettings() {

{t('display.intro')}

-
- {t('display.style')} -
- {STYLES.map(s => ( - ))} +
-
-
- - setName(e.target.value)} maxLength={80} data-testid="display-venue-name" /> + {/* the look being edited */} +
+
+ + setLookName(e.target.value)} data-testid="display-look-name" /> - + {look.is_default + ? + : <> + + setConfirmDelete(true)} data-testid="display-look-delete"> + } +
+ +
+ {t('display.style')} +
+ {STYLES.map(s => ( + + ))} +
- {form.style !== 'blank' && ( - - set('message', e.target.value)} maxLength={120} data-testid="display-message" /> - - )} - - - - {shows('slides') && ( - - set('slide_seconds', Number(e.target.value.replace(/\D/g, '')) || 0)} /> - - )} -
- {shows('qr') && (
- - - - {form.qr_target === 'custom' && ( - - set('qr_url', e.target.value)} placeholder="https://" data-testid="display-qr-url" /> + {form.style !== 'blank' && ( + + set('message', e.target.value)} maxLength={120} data-testid="display-message" /> )} - - set('qr_caption', e.target.value)} maxLength={80} data-testid="display-qr-caption" /> + + -
- )} - - {(shows('logo') || shows('image') || shows('slides')) && ( -
-
- - {t(shows('logo') ? 'display.pickLogo' : shows('image') ? 'display.pickImage' : 'display.pickSlides')} - - - -
- {media.length === 0 ? ( -

{t('display.noImages')}

- ) : ( -
    - {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 ( -
  • - - {chosen && shows('slides') && ( - - {form.slides.indexOf(m.name) + 1} - - )} - remove(m)}> -
  • - ) - })} -
+ {shows('slides') && ( + + set('slide_seconds', Number(e.target.value.replace(/\D/g, '')) || 0)} /> + )}
- )} -
+ {shows('qr') && ( +
+ + + + {form.qr_target === 'custom' && ( + + set('qr_url', e.target.value)} placeholder="https://" data-testid="display-qr-url" /> + + )} + + set('qr_caption', e.target.value)} maxLength={80} data-testid="display-qr-caption" /> + +
+ )} + + {shows('logo') && setPic('logo', img)} label={t('display.pickLogo')} testid="display-logo" />} + {shows('image') && setPic('image', img)} label={t('display.pickImage')} testid="display-image" />} + {shows('slides') && { if (more) setPics(p => ({ ...p, ...more })); set('slides', ids) }} />} + +
+ + {dirty && {t('display.looks.unsaved')}} +
+
+ + {/* which display shows which look */} +
+ {t('display.looks.whichScreen')} + {displays.length === 0 ?

{t('display.looks.noScreens')}

: ( +
    + {displays.map(d => ( +
  • + {d.name} + setVenueName(e.target.value)} maxLength={80} data-testid="display-venue-name" /> + + +
+ + {adding && 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 && ( + setConfirmDelete(false)} + footer={<> + + + }> +

{t('display.looks.deleteBody', { name: defaultLook?.name ?? '' })}

+
+ )}
) } + +/** 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 ( +
+
+ {t('display.pickSlides')} + +
+ {ids.length === 0 ?

{t('display.noSlides')}

: ( +
    + {ids.map((id, i) => ( +
  1. + + {i + 1} + {pics[id]?.name} +
    + move(i, -1)}> + move(i, 1)}> + onChange(ids.filter((_, j) => j !== i))}> +
    +
  2. + ))} +
+ )} + {picking && 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) + }} />} +
+ ) +} + +/** 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 ( + + + + }> +
+ + setName(e.target.value)} placeholder={t('display.looks.namePlaceholder')} data-testid="display-look-new-name" /> + + +
+
+ ) +} diff --git a/manager_dashboard/src/pages/media/MediaParts.jsx b/manager_dashboard/src/pages/media/MediaParts.jsx index 29bcca1..ae64a15 100644 --- a/manager_dashboard/src/pages/media/MediaParts.jsx +++ b/manager_dashboard/src/pages/media/MediaParts.jsx @@ -18,16 +18,17 @@ export function MediaThumb({ item, className }) { return setBroken(true)} className={cx('object-cover bg-surface-3', className)} /> } -/** A grid of library items; `selectedId` marks one (the picker). */ -export function MediaGrid({ items, onOpen, selectedId, testid = 'media-grid' }) { +/** A grid of library items; `selectedId` marks one, `selectedIds` (a Set) several (the picker). */ +export function MediaGrid({ items, onOpen, selectedId, selectedIds, testid = 'media-grid' }) { const meta = useMediaMeta() return (