Files
xenia-pos-local/manager_dashboard/src/pages/signage/SignageSettingsTab.jsx
T
bonaminandClaude Opus 5.5 189bd2777b feat(signage): reviews typed in by hand and their widget; Add a widget at the top of the widgets, the list in layers (new widgets on top)
Reviews (name, stars, text, date, where) under Signage -> Message & settings, shown
one at a time by the reviews widget (a minimum of stars, seconds each); not pulled
from Google (owner's choice). The widgets section: one "Add a widget" menu at its
top instead of a button per kind; the cards are layers, the top one drawn over the
others, so a new widget goes on top; the arrows bring forward / send backward.
Plan 6R.19, F-113.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 14:21:17 +02:00

97 lines
5.9 KiB
React

// Signage → Message & settings (plan step 5.6c; renamed in owner review 5, 2026-11-21): the message
// of the day (one place for every screen, at once; also on the Overview), the weather's town (picked
// from a search; the weather needs internet, and without it the widget is simply hidden on the TVs)
// and the venue's badges for menu boards (BadgesSettings).
import { useCallback, useEffect, useState } from 'react'
import toast from 'react-hot-toast'
import { CloudOff, RefreshCw, Search } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useFormat, useLanguage, useTranslation } from '@xenia/i18n'
import { Button, Dropdown, Field, Input, Spinner } from '@xenia/ui'
import BadgesSettings from './BadgesSettings'
import ReviewsSettings from './ReviewsSettings'
import MessageOfTheDay from './MessageOfTheDay'
import PerformanceSettings from './PerformanceSettings'
import * as api from './signageApi'
export default function SignageSettingsTab() {
const { t } = useTranslation('manager')
const { formatDateTime } = useFormat()
const { language: lang } = useLanguage()
const [status, setStatus] = useState(null)
const [q, setQ] = useState('')
const [places, setPlaces] = useState(null)
const [units, setUnits] = useState('celsius')
const [busy, setBusy] = useState(false)
const load = useCallback(async () => {
try {
const w = await api.weatherStatus()
setStatus(w)
if (w.place?.units) setUnits(w.place.units)
} catch (err) { toast.error(errorMessage(err, t)); setStatus(s => s || {}) }
}, [t])
useEffect(() => { load() }, [load])
const act = async (fn, done) => {
setBusy(true)
try { const r = await fn(); if (done) toast.success(done); return r } catch (err) { toast.error(errorMessage(err, t)); return null } finally { setBusy(false) }
}
if (status === null) return <div className="flex justify-center p-6"><Spinner /></div>
const w = status?.weather
return (
<div className="grid gap-5 max-w-5xl" data-testid="signage-settings">
<section className="rounded-card border border-line bg-surface p-4 grid gap-3">
<h2 className="text-body font-semibold text-ink">{t('signage.settings.message')}</h2>
<p className="text-label text-ink-2">{t('signage.settings.messageHint')}</p>
<MessageOfTheDay />
</section>
<section className="rounded-card border border-line bg-surface p-4 grid gap-3" data-testid="signage-weather">
<h2 className="text-body font-semibold text-ink">{t('signage.settings.weather')}</h2>
<p className="text-label text-ink-2 flex items-start gap-1.5"><CloudOff size={16} className="shrink-0 mt-0.5" aria-hidden="true" />{t('signage.settings.weatherHint')}</p>
{status?.place ? (
<div className="grid gap-1 text-label" data-testid="signage-weather-place">
<span className="text-ink"><strong>{status.place.name}</strong> · {t(`signage.settings.units.${status.place.units}`)}</span>
{w ? <span className="text-ink-2" data-testid="signage-weather-now">{t('signage.settings.now', { temp: Math.round(w.temperature), unit: status.place.units === 'fahrenheit' ? '°F' : '°C', at: status.fetched_at ? formatDateTime(new Date(status.fetched_at * 1000)) : '' })}</span>
: <span className="text-warning-ink" data-testid="signage-weather-none">{t(status.error ? 'signage.settings.noForecast' : 'signage.settings.waiting')}</span>}
<div className="flex gap-2 pt-1">
<Button size="sm" variant="secondary" icon={<RefreshCw size={14} />} disabled={busy} onClick={() => act(api.refreshWeather).then(r => r && setStatus(r))}>{t('signage.settings.refresh')}</Button>
<Button size="sm" variant="ghost" disabled={busy} onClick={() => act(api.forgetWeatherPlace, t('settings.saved')).then(r => r && setStatus(r))}>{t('signage.settings.forget')}</Button>
</div>
</div>
) : <p className="text-label text-ink-3">{t('signage.settings.noPlace')}</p>}
<div className="grid gap-2">
<div className="flex gap-2 items-end flex-wrap">
<Field label={t('signage.settings.town')} className="flex-1 min-w-[12rem]">
<Input value={q} onChange={e => setQ(e.target.value)} placeholder={t('signage.settings.townPlaceholder')} data-testid="signage-weather-search" />
</Field>
<Field label={t('signage.settings.unitsLabel')}>
<Dropdown value={units} onChange={setUnits} options={['celsius', 'fahrenheit'].map(u => ({ value: u, label: t(`signage.settings.units.${u}`) }))} />
</Field>
<Button variant="secondary" icon={<Search size={16} />} disabled={busy || q.trim().length < 2} data-testid="signage-weather-find"
onClick={() => act(() => api.weatherPlaces(q.trim(), lang === 'el' ? 'el' : 'en')).then(r => r && setPlaces(r))}>{t('signage.settings.find')}</Button>
</div>
{places && (places.length === 0 ? <p className="text-label text-ink-3">{t('media.noMatch')}</p> : (
<ul className="grid gap-1" data-testid="signage-weather-places">
{places.map((p, i) => (
<li key={i}>
<button type="button" className="w-full text-left px-2 py-1.5 rounded-control hover:bg-surface-2 text-label text-ink" data-testid="signage-weather-place-pick"
onClick={() => act(() => api.setWeatherPlace({ name: p.name, latitude: p.latitude, longitude: p.longitude, units }), t('settings.saved'))
.then(r => { if (r) { setStatus(r); setPlaces(null); setQ('') } })}>
<strong>{p.name}</strong> <span className="text-ink-3">{[p.region, p.country].filter(Boolean).join(', ')}</span>
</button>
</li>
))}
</ul>
))}
</div>
</section>
<BadgesSettings />
<ReviewsSettings />
<PerformanceSettings />
</div>
)
}