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>
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
// The venue's reviews (6R.19, owner 2026-11-22), under Signage → Message & settings: typed in by hand
|
||||
// (who, stars, what they wrote, when, where it was posted) and shown one at a time by the reviews
|
||||
// widget. Not pulled from Google (the owner's choice: no API key, no billing). Saved all at once.
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { ArrowDown, ArrowUp, Plus, Star, Trash2 } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Field, FieldRow, IconButton, Input, Segmented, Spinner, Textarea } from '@xenia/ui'
|
||||
import * as api from './signageApi'
|
||||
import { moved } from './signageLogic'
|
||||
|
||||
const clean = list => list.map(r => ({ name: r.name.trim(), stars: r.stars, text: r.text.trim(), date: r.date || null, source: (r.source || '').trim() || null }))
|
||||
|
||||
export default function ReviewsSettings() {
|
||||
const { t } = useTranslation('manager')
|
||||
const [saved, setSaved] = useState(null)
|
||||
const [list, setList] = useState(null)
|
||||
const [busy, setBusy] = useState(false)
|
||||
useEffect(() => {
|
||||
api.getReviews().then(r => { setSaved(r.reviews); setList(r.reviews) }).catch(err => toast.error(errorMessage(err, t)))
|
||||
}, [t])
|
||||
const dirty = useMemo(() => JSON.stringify(list) !== JSON.stringify(saved), [list, saved])
|
||||
if (!list) return <section className="rounded-card border border-line bg-surface p-4 flex justify-center"><Spinner /></section>
|
||||
const set = (i, patch) => setList(l => l.map((r, j) => (j === i ? { ...r, ...patch } : r)))
|
||||
const bad = list.some(r => !r.name?.trim() || !r.text?.trim())
|
||||
const save = async () => {
|
||||
setBusy(true)
|
||||
try { const r = await api.putReviews(clean(list)); setSaved(r.reviews); setList(r.reviews); toast.success(t('settings.saved')) }
|
||||
catch (err) { toast.error(errorMessage(err, t)) }
|
||||
setBusy(false)
|
||||
}
|
||||
return (
|
||||
<section className="rounded-card border border-line bg-surface p-4 grid gap-3" data-testid="signage-reviews">
|
||||
<div className="flex flex-wrap items-start gap-3">
|
||||
<div className="grid gap-1 flex-1 min-w-[16rem]">
|
||||
<h2 className="text-body font-semibold text-ink">{t('signage.reviews.title')}</h2>
|
||||
<p className="text-label text-ink-2">{t('signage.reviews.hint')}</p>
|
||||
</div>
|
||||
<Button variant="secondary" disabled={!dirty || busy} onClick={() => setList(saved)}>{t('signage.undo')}</Button>
|
||||
<Button loading={busy} disabled={!dirty || bad} onClick={save} data-testid="signage-reviews-save">{t('fees.save')}</Button>
|
||||
</div>
|
||||
{list.length === 0 && <p className="text-label text-ink-3">{t('signage.reviews.none')}</p>}
|
||||
<div className="grid gap-2">
|
||||
{list.map((r, i) => (
|
||||
<div key={i} className="grid gap-2 rounded-control border border-line bg-surface-2 p-3" data-testid="signage-review-row">
|
||||
<div className="flex items-center gap-2">
|
||||
<Segmented value={r.stars} onChange={stars => set(i, { stars })} aria-label={t('signage.reviews.stars')} data-testid="signage-review-stars"
|
||||
options={[1, 2, 3, 4, 5].map(n => ({ value: n, label: String(n), icon: <Star size={14} aria-hidden="true" /> }))} />
|
||||
<span className="flex-1" />
|
||||
<IconButton size="sm" label={t('display.earlier')} disabled={i === 0} onClick={() => setList(l => moved(l, i, i - 1))}><ArrowUp size={14} /></IconButton>
|
||||
<IconButton size="sm" label={t('display.later')} disabled={i === list.length - 1} onClick={() => setList(l => moved(l, i, i + 1))}><ArrowDown size={14} /></IconButton>
|
||||
<IconButton size="sm" tone="danger" label={t('fees.delete')} onClick={() => setList(l => l.filter((_, j) => j !== i))}><Trash2 size={14} /></IconButton>
|
||||
</div>
|
||||
<Field label={t('signage.reviews.text')} error={!r.text?.trim() ? ' ' : undefined}>
|
||||
<Textarea rows={2} value={r.text} maxLength={400} onChange={e => set(i, { text: e.target.value })} data-testid="signage-review-text" />
|
||||
</Field>
|
||||
<FieldRow className="-mx-3 -mb-3" min="11rem">
|
||||
<Field label={t('signage.reviews.name')} error={!r.name?.trim() ? ' ' : undefined}>
|
||||
<Input value={r.name} maxLength={60} onChange={e => set(i, { name: e.target.value })} data-testid="signage-review-name" />
|
||||
</Field>
|
||||
<Field label={t('signage.reviews.source')}>
|
||||
<Input value={r.source || ''} maxLength={40} placeholder="Google" onChange={e => set(i, { source: e.target.value })} />
|
||||
</Field>
|
||||
<Field label={t('signage.reviews.date')}>
|
||||
<Input type="date" value={r.date || ''} onChange={e => set(i, { date: e.target.value || null })} />
|
||||
</Field>
|
||||
</FieldRow>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{list.length < 100 && (
|
||||
<div><Button variant="secondary" icon={<Plus size={14} />} onClick={() => setList(l => [...l, { name: '', stars: 5, text: '', date: null, source: null }])} data-testid="signage-review-add">
|
||||
{t('signage.reviews.add')}
|
||||
</Button></div>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user