feat(manager): online ordering settings in tabs beside Test an order; expense lines and documents
- Online orders -> Settings: takeaway / delivery / any time side by side (wrapping, with room), the days of the week apart; fee rules, delivery areas and fee settings (the fee line) as tabs on the left, Test an order on the right; a rule's switch at the far right, equal padding, 'Order price from' / 'Total items count from' in the rule editor. - Expenses: the dialog lists what was bought (quantity, price before VAT, VAT; they make the total, with net / VAT / total) and keeps documents (attach a PDF or photo, open, remove; picked for a new expense, uploaded when it's saved); a paperclip in the list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,12 +7,13 @@
|
||||
// win. The cloud applies the same rules at checkout (the same engine), so "Test an order"
|
||||
// shows exactly what a customer will be charged. No rules = no fee.
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { useSearchParams } from 'react-router-dom'
|
||||
import toast from 'react-hot-toast'
|
||||
import { ArrowDown, ArrowUp, MapPin, Pencil, Plus, Trash2, Truck } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { SALES_POINTS } from '@xenia/access'
|
||||
import { Button, Dialog, EmptyState, Field, IconButton, Input, Select, Spinner, Switch } from '@xenia/ui'
|
||||
import { Button, Dialog, EmptyState, Field, IconButton, Input, Select, Spinner, Switch, Tabs } from '@xenia/ui'
|
||||
import client from '../../api/client'
|
||||
import FeeProductCard from './FeeProductCard'
|
||||
import OrderingLink from './OrderingLink'
|
||||
@@ -27,6 +28,9 @@ export default function FeesPage() {
|
||||
const [data, setData] = useState(null)
|
||||
const [error, setError] = useState(null)
|
||||
const [dialog, setDialog] = useState(null) // { kind: 'area' | 'rule', item? } | { kind: 'delete', what, item }
|
||||
const [params, setParams] = useSearchParams()
|
||||
const section = ['rules', 'areas', 'settings'].includes(params.get('fees')) ? params.get('fees') : 'rules'
|
||||
const setSection = v => setParams(p => { const n = new URLSearchParams(p); n.set('fees', v); return n }, { replace: true })
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
@@ -65,54 +69,57 @@ export default function FeesPage() {
|
||||
<p className="text-body text-ink-2 max-w-3xl">{t('fees.intro')}</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6 lg:grid-cols-[1fr_22rem] items-start">
|
||||
<section className="grid gap-3" aria-labelledby="fee-rules">
|
||||
<div className="flex items-center gap-2">
|
||||
<h2 id="fee-rules" className="flex-1 text-title font-semibold text-ink">{t('fees.rules')}</h2>
|
||||
<Button icon={<Plus size={16} />} onClick={() => setDialog({ kind: 'rule' })} data-testid="rule-add">{t('fees.addRule')}</Button>
|
||||
</div>
|
||||
{data.rules.length === 0 ? (
|
||||
<EmptyState icon={<Truck size={28} />} title={t('fees.noRules')} description={t('fees.noRulesBody')} />
|
||||
) : (
|
||||
<ol className="grid gap-2" data-testid="rules">
|
||||
{data.rules.map((r, i) => (
|
||||
<RuleRow key={r.id} rule={r} n={i + 1} areaNames={areaNames} first={i === 0} last={i === data.rules.length - 1}
|
||||
onMove={step => act(() => client.put('/api/connect/fees/rules/order', moveRule(data.rules, r.id, step)))}
|
||||
onToggle={on => act(() => client.put(`/api/connect/fees/rules/${r.id}`, { ...ruleBody(ruleToForm(r)), is_active: on }))}
|
||||
onEdit={() => setDialog({ kind: 'rule', item: r })}
|
||||
onDelete={() => setDialog({ kind: 'delete', what: 'rule', item: r })} />
|
||||
))}
|
||||
</ol>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<div className="grid gap-6">
|
||||
<section className="grid gap-3" aria-labelledby="fee-areas">
|
||||
<div className="flex items-center gap-2">
|
||||
<h2 id="fee-areas" className="flex-1 text-title font-semibold text-ink">{t('fees.areas')}</h2>
|
||||
<Button variant="secondary" icon={<Plus size={16} />} onClick={() => setDialog({ kind: 'area' })} data-testid="area-add">{t('fees.addArea')}</Button>
|
||||
</div>
|
||||
{data.areas.length === 0 ? (
|
||||
<p className="text-label text-ink-2">{t('fees.noAreas')}</p>
|
||||
{/* left: the fee rules, the areas and the fee's settings as tabs; right: test an order (2026-11-20) */}
|
||||
<div className="grid gap-6 xl:grid-cols-[minmax(0,3fr)_minmax(19rem,1fr)] items-start">
|
||||
<section className="rounded-card border border-line bg-surface shadow-raised min-w-0" data-testid="fees-sections">
|
||||
<Tabs className="px-card" value={section} onChange={setSection}
|
||||
tabs={[
|
||||
{ id: 'rules', label: t('fees.rules'), badge: data.rules.length || null, testId: 'fees-tab-rules' },
|
||||
{ id: 'areas', label: t('fees.areas'), badge: data.areas.length || null, testId: 'fees-tab-areas' },
|
||||
{ id: 'settings', label: t('fees.settings'), testId: 'fees-tab-settings' },
|
||||
]}
|
||||
end={section === 'rules' ? <Button size="sm" icon={<Plus size={16} />} onClick={() => setDialog({ kind: 'rule' })} data-testid="rule-add">{t('fees.addRule')}</Button>
|
||||
: section === 'areas' ? <Button size="sm" icon={<Plus size={16} />} onClick={() => setDialog({ kind: 'area' })} data-testid="area-add">{t('fees.addArea')}</Button>
|
||||
: null} />
|
||||
<div className="p-card">
|
||||
{section === 'rules' && (data.rules.length === 0 ? (
|
||||
<EmptyState icon={<Truck size={28} />} title={t('fees.noRules')} description={t('fees.noRulesBody')} />
|
||||
) : (
|
||||
<ul className="grid gap-2" data-testid="areas">
|
||||
<ol className="grid gap-3" data-testid="rules">
|
||||
{data.rules.map((r, i) => (
|
||||
<RuleRow key={r.id} rule={r} n={i + 1} areaNames={areaNames} first={i === 0} last={i === data.rules.length - 1}
|
||||
onMove={step => act(() => client.put('/api/connect/fees/rules/order', moveRule(data.rules, r.id, step)))}
|
||||
onToggle={on => act(() => client.put(`/api/connect/fees/rules/${r.id}`, { ...ruleBody(ruleToForm(r)), is_active: on }))}
|
||||
onEdit={() => setDialog({ kind: 'rule', item: r })}
|
||||
onDelete={() => setDialog({ kind: 'delete', what: 'rule', item: r })} />
|
||||
))}
|
||||
</ol>
|
||||
))}
|
||||
{section === 'areas' && (data.areas.length === 0 ? (
|
||||
<EmptyState icon={<MapPin size={28} />} title={t('fees.noAreas')} />
|
||||
) : (
|
||||
<ul className="grid gap-3" data-testid="areas">
|
||||
{data.areas.map(a => (
|
||||
<li key={a.id} className="p-3 rounded-card border border-line bg-surface flex items-start gap-2" data-testid="area">
|
||||
<MapPin size={16} className="mt-0.5 text-ink-3 shrink-0" aria-hidden="true" />
|
||||
<li key={a.id} className="px-card py-card-y rounded-card border border-line bg-surface flex items-center gap-3" data-testid="area">
|
||||
<MapPin size={16} className="text-ink-3 shrink-0" aria-hidden="true" />
|
||||
<span className="flex-1 min-w-0">
|
||||
<span className={`block text-body font-medium ${a.is_active ? 'text-ink' : 'text-ink-3 line-through'}`}>{a.name}</span>
|
||||
<span className="block text-caption text-ink-2 truncate">{a.postcodes.length ? a.postcodes.join(', ') : t('fees.byNameOnly')}</span>
|
||||
</span>
|
||||
<IconButton size="sm" variant="ghost" label={t('fees.edit')} onClick={() => setDialog({ kind: 'area', item: a })}><Pencil size={16} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" label={t('fees.delete')} onClick={() => setDialog({ kind: 'delete', what: 'area', item: a })}><Trash2 size={16} /></IconButton>
|
||||
<span className="flex gap-1.5">
|
||||
<IconButton size="sm" variant="ghost" tone="accent" label={t('fees.edit')} onClick={() => setDialog({ kind: 'area', item: a })}><Pencil size={16} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" tone="danger" label={t('fees.delete')} onClick={() => setDialog({ kind: 'delete', what: 'area', item: a })}><Trash2 size={16} /></IconButton>
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
<TestOrder areas={data.areas} />
|
||||
{data.fee_product && <FeeProductCard key={JSON.stringify(data.fee_product)} product={data.fee_product} onSaved={load} />}
|
||||
</div>
|
||||
))}
|
||||
{section === 'settings' && (data.fee_product
|
||||
? <FeeProductCard key={JSON.stringify(data.fee_product)} product={data.fee_product} onSaved={load} />
|
||||
: <EmptyState title={t('fees.noSettings')} />)}
|
||||
</div>
|
||||
</section>
|
||||
<TestOrder areas={data.areas} />
|
||||
</div>
|
||||
|
||||
{dialog?.kind === 'area' && (
|
||||
@@ -149,15 +156,15 @@ function RuleRow({ rule, n, areaNames, first, last, onMove, onToggle, onEdit, on
|
||||
const params = p => ({ ...p, min: p.min, max: p.max, minMoney: p.min != null ? formatMoney(p.min) : '', maxMoney: p.max != null ? formatMoney(p.max) : '',
|
||||
days: (p.days ?? []).map(x => t(`fees.dayShort.${x}`)).join(', ') })
|
||||
return (
|
||||
<li className={`p-3 rounded-card border border-line bg-surface grid gap-1.5 ${rule.is_active ? '' : 'opacity-60'}`} data-testid="rule" data-rule={rule.id}>
|
||||
<li className={`px-card py-card-y rounded-card border border-line bg-surface grid gap-2 ${rule.is_active ? '' : 'opacity-60'}`} data-testid="rule" data-rule={rule.id}>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-caption font-semibold text-ink-3 w-5">{n}</span>
|
||||
<span className="flex-1 min-w-0 text-body font-semibold text-ink truncate">{rule.name}</span>
|
||||
<IconButton size="sm" variant="ghost" label={t('fees.up')} disabled={first} onClick={() => onMove(-1)}><ArrowUp size={16} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" label={t('fees.down')} disabled={last} onClick={() => onMove(1)}><ArrowDown size={16} /></IconButton>
|
||||
<Switch checked={rule.is_active} onChange={onToggle} aria-label={t('fees.active')} />
|
||||
<IconButton size="sm" variant="ghost" label={t('fees.edit')} onClick={onEdit}><Pencil size={16} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" label={t('fees.delete')} onClick={onDelete}><Trash2 size={16} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" tone="accent" label={t('fees.edit')} onClick={onEdit}><Pencil size={16} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" tone="danger" label={t('fees.delete')} onClick={onDelete}><Trash2 size={16} /></IconButton>
|
||||
<Switch className="ml-2" checked={rule.is_active} onChange={onToggle} aria-label={t('fees.active')} />
|
||||
</div>
|
||||
<div className="pl-7 text-label text-ink-2 grid gap-0.5">
|
||||
<span>
|
||||
@@ -330,7 +337,7 @@ function TestOrder({ areas }) {
|
||||
setBusy(false)
|
||||
}
|
||||
return (
|
||||
<section className="p-4 rounded-card border border-line bg-surface-2 grid gap-3" aria-labelledby="fee-test" data-testid="fee-test">
|
||||
<section className="p-card rounded-card border border-line bg-surface shadow-raised grid gap-3" aria-labelledby="fee-test" data-testid="fee-test">
|
||||
<h2 id="fee-test" className="text-title font-semibold text-ink">{t('fees.test')}</h2>
|
||||
<Field label={t('fees.testSalesPoint')}>
|
||||
<Select value={form.sales_point} onChange={e => set('sales_point', e.target.value)}>
|
||||
|
||||
Reference in New Issue
Block a user