feat(manager,waiter): money and weights typed with a comma or a dot everywhere
Owner 2026-11-23 (plan 6F.2): new DecimalInput / MoneyInput in @xenia/ui (keeps what is typed,
reports a number, null when empty, NaN when not a number) on parseNumber. The waiter app's starting
cash, weighed quantity and typed prices were type=number + parseFloat (a Greek keypad's comma was
dropped: 12,50 became 12 or nothing); now text fields read with parseNumber, and a wrong starting
cash shows a message. The manager's price rules, deals and order-total condition use the new
fields; every Number(x.replace(',', '.')) now reads through parseNumber (1.234,50 too). Guard test
packages/i18n/tests/typed-numbers.test.mjs refuses parseFloat, .replace(',', '.') and decimal
type=number fields in the apps. e2e: shift close with 20,50, waiter starting cash 25,50.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
// evaluated by the backend's engine (local_backend/services/fees.py, the same file the cloud
|
||||
// runs); this file only turns forms into request bodies and rules into readable lines.
|
||||
// Pure: unit-tested in Node (tests/fees.test.mjs).
|
||||
import { parseNumber } from '@xenia/i18n/number'
|
||||
|
||||
export const ACTIONS = ['set', 'add', 'percent', 'free', 'minimum']
|
||||
export const DAYS = [0, 1, 2, 3, 4, 5, 6] // Monday = 0
|
||||
|
||||
const num = v => (v === '' || v == null ? null : Number(String(v).replace(',', '.')))
|
||||
const num = v => (v === '' || v == null ? null : (parseNumber(String(v)) ?? NaN))
|
||||
|
||||
/** Postcodes typed with commas, semicolons or new lines → a tidy list without duplicates. */
|
||||
export function parsePostcodes(text) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import toast from 'react-hot-toast'
|
||||
import { Ban, CreditCard, Percent, Printer, Receipt } from 'lucide-react'
|
||||
import { useCan, useModule } from '@xenia/access'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { parseNumber, useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, EmptyState, Field, Input, cx } from '@xenia/ui'
|
||||
import client from '../../api/client'
|
||||
import { Pill } from '../overview/parts'
|
||||
@@ -123,7 +123,7 @@ function DiscountDialog({ orderId, itemIds, amount, onClose, onDone }) {
|
||||
const { formatMoney } = useFormat()
|
||||
const [pct, setPct] = useState('10')
|
||||
const [note, setNote] = useState('')
|
||||
const value = Number(String(pct).replace(',', '.'))
|
||||
const value = parseNumber(String(pct)) ?? NaN
|
||||
const ok = value > 0 && value <= 100
|
||||
const apply = useMutation({
|
||||
mutationFn: () => client.post(`/api/orders/${orderId}/items/discount`, { item_ids: itemIds, discount_percent: value, note: note.trim() || null }),
|
||||
|
||||
@@ -9,7 +9,7 @@ import toast from 'react-hot-toast'
|
||||
import { Plus } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, EmptyState, Field, Input, Select, Spinner, Switch } from '@xenia/ui'
|
||||
import { Button, DecimalInput, Dialog, EmptyState, Field, Input, Select, Spinner, Switch } from '@xenia/ui'
|
||||
import { useLiveQuery } from '../../live/useLiveQuery'
|
||||
import * as api from './pricingApi'
|
||||
import { ColourPicker, ConditionList, Missing, PickSeveral, RuleCard, Segmented, TabHead, TagPicker, TargetList } from './PricingParts'
|
||||
@@ -145,8 +145,8 @@ function DealDialog({ deal, catalog, rules, busy, onClose, onSave }) {
|
||||
)}
|
||||
{['set_price', 'add_amount', 'add_percent'].includes(a) && (
|
||||
<Field label={t(`pricing.actions.valueLabel.${a === 'set_price' ? 'set' : a}`)} hint={a !== 'set_price' ? t('pricing.actions.minusHint') : undefined}>
|
||||
<Input type="number" step={a === 'add_percent' ? 1 : 0.1} className="w-36" value={Number.isFinite(f.action_value) ? f.action_value : ''}
|
||||
onChange={e => set('action_value', e.target.value === '' ? NaN : Number(e.target.value))} />
|
||||
<DecimalInput allowNegative decimals={2} suffix={a === 'add_percent' ? '%' : '€'} className="w-36" value={f.action_value}
|
||||
onChange={v => set('action_value', v ?? NaN)} />
|
||||
</Field>
|
||||
)}
|
||||
<ColourPicker value={f.color} onChange={v => set('color', v)} label={t('pricing.colour')} />
|
||||
|
||||
@@ -12,7 +12,7 @@ import toast from 'react-hot-toast'
|
||||
import { Layers, Plus } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, EmptyState, Field, InfoTip, Input, Select, Spinner, Switch } from '@xenia/ui'
|
||||
import { Button, DecimalInput, Dialog, EmptyState, Field, InfoTip, Input, Select, Spinner, Switch } from '@xenia/ui'
|
||||
import { useLiveQuery } from '../../live/useLiveQuery'
|
||||
import * as api from './pricingApi'
|
||||
import { ColourPicker, ConditionList, Missing, RuleCard, Segmented, TabHead, TargetList } from './PricingParts'
|
||||
@@ -147,8 +147,8 @@ function RuleDialog({ rule, catalog, busy, onClose, onSave }) {
|
||||
options={MODIFIER_ACTIONS.map(v => ({ value: v, label: t(`pricing.actions.${v}`) }))} />
|
||||
<div className="grid sm:grid-cols-2 gap-3">
|
||||
<Field label={t(`pricing.actions.valueLabel.${f.action_type}`)} hint={f.action_type !== 'set' ? t('pricing.actions.minusHint') : undefined}>
|
||||
<Input type="number" step={f.action_type === 'add_percent' ? 1 : 0.1} value={Number.isFinite(f.action_value) ? f.action_value : ''}
|
||||
onChange={e => set('action_value', e.target.value === '' ? NaN : Number(e.target.value))} data-testid="pricing-rule-value" />
|
||||
<DecimalInput allowNegative decimals={2} suffix={f.action_type === 'add_percent' ? '%' : '€'} value={f.action_value}
|
||||
onChange={v => set('action_value', v ?? NaN)} data-testid="pricing-rule-value" />
|
||||
</Field>
|
||||
{f.action_type === 'add_percent' && (
|
||||
<Field label={t('pricing.rules.rounding')}>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useState } from 'react'
|
||||
import { ArrowDown, ArrowUp, Check, Pencil, Plus, Power, Trash2, X } from 'lucide-react'
|
||||
import { SALES_POINTS, normalizeSalesPoints } from '@xenia/access'
|
||||
import { latin, useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dropdown, IconButton, Input, Select, cx } from '@xenia/ui'
|
||||
import { Button, Dropdown, IconButton, Input, MoneyInput, Select, cx } from '@xenia/ui'
|
||||
import { COLOURS } from './useCatalog'
|
||||
import { OLD_PLACEHOLDERS, WEEKDAYS, blankCondition, conditionComplete, toggleIn } from './pricingLogic'
|
||||
|
||||
@@ -202,7 +202,13 @@ function ConditionFields({ cond, onChange, catalog }) {
|
||||
case 'specific_date': return <DateList value={p.dates ?? []} onChange={v => set('dates', v)} />
|
||||
case 'day_of_week': return <DayPicker value={p.days ?? []} onChange={v => set('days', v)} />
|
||||
case 'min_item_quantity': return <label className="flex items-center gap-2 text-label text-ink-2">{num('min', 1, 1)}{t('pricing.condition.ofTheDish')}</label>
|
||||
case 'min_order_value': return <label className="flex items-center gap-2 text-label text-ink-2">{num('min', 0, 0.5)}{t('pricing.condition.orderTotal')}</label>
|
||||
case 'min_order_value': return (
|
||||
<label className="flex items-center gap-2 text-label text-ink-2">
|
||||
<MoneyInput size="sm" className="w-32" value={p.min ?? null} aria-label={t('pricing.condition.fields.min_order_value')}
|
||||
onChange={v => set('min', Number.isFinite(v) ? v : null)} />
|
||||
{t('pricing.condition.orderTotal')}
|
||||
</label>
|
||||
)
|
||||
case 'min_category_qty': return (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{num('min', 1, 1)}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// (modifier) and a deal, what they send to the server, what's missing before they can be saved,
|
||||
// and their one-line summaries. Tested in tests/pricing-logic.test.mjs.
|
||||
// The server's engine: local_backend/services/pricing.py (conditions AND-ed, targets OR-ed).
|
||||
import { parseNumber } from '@xenia/i18n/number'
|
||||
|
||||
export const WEEKDAYS = [0, 1, 2, 3, 4, 5, 6] // Monday = 0, as the server counts
|
||||
|
||||
@@ -226,9 +227,9 @@ export const COUNT_LIMITS = new Set(['max_items_per_shift', 'max_items_per_workd
|
||||
|
||||
/** A limit typed in a box: '' = no limit; a comma works as the decimal point. null when it isn't a number ≥ 0. */
|
||||
export function parseLimit(text, count = false) {
|
||||
const s = String(text ?? '').trim().replace(',', '.')
|
||||
const s = String(text ?? '').trim()
|
||||
if (s === '') return { ok: true, value: null }
|
||||
const v = Number(s)
|
||||
const v = parseNumber(s) ?? NaN
|
||||
if (!Number.isFinite(v) || v < 0 || (count && !Number.isInteger(v))) return { ok: false, value: null }
|
||||
return { ok: true, value: v }
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useState } from 'react'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import toast from 'react-hot-toast'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { parseNumber, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, EmptyState, Page, Pane, Spinner } from '@xenia/ui'
|
||||
import { Package } from 'lucide-react'
|
||||
import client from '../../api/client'
|
||||
@@ -23,7 +23,7 @@ import { emptyProduct } from './editor/formLogic'
|
||||
import { NO_FILTERS, SCOPES, applyFilters, bulkCategories, groupProducts, isArchived, isCategoryScope, listedIn, scopeProducts, subsOf } from './productsLogic'
|
||||
|
||||
const EVENTS = ['products_changed']
|
||||
const number = v => (v === '' ? null : Number(String(v).replace(',', '.')))
|
||||
const number = v => (v === '' ? null : (parseNumber(String(v)) ?? NaN))
|
||||
|
||||
export default function ProductsPage() {
|
||||
const { t } = useTranslation('manager')
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// with a price: printed in its own SERVICE section and counted in the takings.
|
||||
import { useState } from 'react'
|
||||
import { DEFAULT_LANGUAGE } from '@xenia/access'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { parseNumber, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, Field } from '@xenia/ui'
|
||||
import { PrepZonesField } from './InfoTabs'
|
||||
import { LanguagePicker, TrInput } from './LanguageFields'
|
||||
@@ -19,7 +19,7 @@ export default function ServiceItemDialog({ product, prepZones, saving, onSave,
|
||||
const [lang, setLang] = useState(DEFAULT_LANGUAGE)
|
||||
const set = (k, v) => setForm(f => ({ ...f, [k]: v }))
|
||||
const isNew = !product.id
|
||||
const paid = Number(String(form.base_price ?? '').replace(',', '.')) > 0
|
||||
const paid = (parseNumber(String(form.base_price ?? '')) ?? 0) > 0
|
||||
return (
|
||||
<EditLang.Provider value={editLangOf(lang, venue)}>
|
||||
<Dialog open size="md" onClose={onClose}
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
// language picker picks which language the fields edit; "Default" is the venue's language.
|
||||
import { SALES_POINTS } from '@xenia/access/salesPoints'
|
||||
import { MENU_LANGUAGES, shownText } from '@xenia/access/menuLanguages'
|
||||
import { parseNumber } from '@xenia/i18n/number'
|
||||
|
||||
export const UNITS = ['piece', 'portion', 'kg', 'liter', 'gram', 'ml']
|
||||
export const WEIGHED = new Set(['kg', 'liter', 'gram', 'ml'])
|
||||
export const LISTS = { quick: 'quick_options', ingredient: 'ingredients', option: 'options', pref: 'preference_sets' }
|
||||
|
||||
const num = v => (v === '' || v == null ? 0 : Number(String(v).replace(',', '.')) || 0)
|
||||
const num = v => (v === '' || v == null ? 0 : parseNumber(String(v)) || 0)
|
||||
const sub = s => ({ name: s.name ?? '', tr: { ...(s.translations ?? {}) }, extra_cost: s.extra_cost ?? 0, is_default: !!s.is_default, allow_multiple: !!s.allow_multiple, is_compact: !!s.is_compact })
|
||||
const field = (tr, k) => Object.fromEntries(Object.entries(tr ?? {}).filter(([, v]) => v?.[k]).map(([l, v]) => [l, v[k]]))
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// language picked at the top of the editor.
|
||||
import { useState } from 'react'
|
||||
import { ChevronDown, ChevronUp, Heart, Minus, Pencil, Plus, Trash2 } from 'lucide-react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { parseNumber, useTranslation } from '@xenia/i18n'
|
||||
import { Button, FilterChip, IconButton, cx } from '@xenia/ui'
|
||||
import { TrInput } from './LanguageFields'
|
||||
import { useEditLang } from './editLang'
|
||||
@@ -12,7 +12,7 @@ import { labelIn } from './formLogic'
|
||||
/** A price with − / + of 0.10 (negative allowed for choices that lower the price). */
|
||||
export function PriceInput({ value, onChange, allowNegative = false, size = 'md', className, label, ...rest }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const n = Number(String(value ?? '').replace(',', '.')) || 0
|
||||
const n = parseNumber(String(value ?? '')) || 0
|
||||
const step = d => {
|
||||
const next = Math.round((n + d) * 100) / 100
|
||||
onChange(allowNegative ? next : Math.max(0, next))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// The staff page as plain data (plan step 6.11), tested in tests/staff.test.mjs.
|
||||
import { parseNumber } from '@xenia/i18n/number'
|
||||
|
||||
/** The roles in the order the page lists them (backend roles.py); names are i18n `roles.*`. */
|
||||
export const ROLES = ['owner', 'store_manager', 'staff_manager', 'chef', 'assistant_chef', 'barista', 'barman', 'waiter', 'assistant_waiter', 'custom']
|
||||
@@ -58,8 +59,9 @@ export function staffProblems(form, isNew) {
|
||||
if (!form.full_name.trim()) out.push('full_name')
|
||||
if (!form.nickname.trim()) out.push('nickname')
|
||||
if (!/^[^\s]{2,}$/.test(form.username.trim())) out.push('username')
|
||||
const rate = String(form.hourly_rate).trim().replace(',', '.')
|
||||
if (rate && !(Number(rate) >= 0)) out.push('hourly_rate')
|
||||
const rate = String(form.hourly_rate ?? '').trim()
|
||||
const rateValue = rate ? parseNumber(rate) : null
|
||||
if (rate && !(rateValue != null && rateValue >= 0)) out.push('hourly_rate')
|
||||
if (isNew && !validPin(form.pin)) out.push('pin')
|
||||
if (isNew && form.password && !validPassword(form.password)) out.push('password')
|
||||
return out
|
||||
@@ -68,11 +70,11 @@ export function staffProblems(form, isNew) {
|
||||
/** POST /api/waiters/ (new) or PUT /api/waiters/{id} (edit). */
|
||||
export function staffBody(form, isNew) {
|
||||
const text = v => (v ?? '').trim() || null
|
||||
const rate = String(form.hourly_rate).trim().replace(',', '.')
|
||||
const rate = String(form.hourly_rate ?? '').trim()
|
||||
const body = {
|
||||
full_name: form.full_name.trim(), nickname: form.nickname.trim(), username: form.username.trim(), role: form.role,
|
||||
mobile_phone: text(form.mobile_phone), email: text(form.email), note: text(form.note),
|
||||
hourly_rate: rate ? Number(rate) : null, language: form.language || '',
|
||||
hourly_rate: rate ? parseNumber(rate, { decimals: 2 }) : null, language: form.language || '',
|
||||
}
|
||||
if (isNew) {
|
||||
body.pin = form.pin
|
||||
|
||||
Reference in New Issue
Block a user