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:
2026-11-23 07:08:54 +02:00
co-authored by Claude Opus 5.5
parent e708202f3a
commit e3f4f3eeee
27 changed files with 216 additions and 46 deletions
+2 -1
View File
@@ -29,7 +29,8 @@
"startQuestion": "Θέλεις να ξεκινήσεις τη βάρδια σου;",
"startingCash": "Αρχικά μετρητά (προαιρετικό)",
"starting": "Εκκίνηση…",
"startShift": "Έναρξη Βάρδιας"
"startShift": "Έναρξη Βάρδιας",
"badAmount": "Γράψτε ένα ποσό, π.χ. 50 ή 50,00."
},
"nav": {
"tables": "Τραπέζια",
+2 -1
View File
@@ -29,7 +29,8 @@
"startQuestion": "Start your shift?",
"startingCash": "Starting cash (optional)",
"starting": "Starting…",
"startShift": "Start shift"
"startShift": "Start shift",
"badAmount": "Type an amount, e.g. 50 or 50,00."
},
"nav": {
"tables": "Tables",
@@ -0,0 +1,46 @@
// Guard (plan 6F.2, owner 2026-11-23): numbers people type are read with parseNumber (a comma or
// a dot for the decimals, "1.234,50" too), never with parseFloat / Number(x.replace(',', '.')),
// and a field for money or a weight is never <input type="number"> with a decimal step: a phone's
// Greek keypad types a comma, which such a field silently drops ("12,50" became 12 or nothing).
// Use DecimalInput / MoneyInput (@xenia/ui) or a text field with inputMode="decimal" + parseNumber.
import assert from 'node:assert/strict'
import { readdirSync, readFileSync, statSync } from 'node:fs'
import path from 'node:path'
import { test } from 'node:test'
import { fileURLToPath } from 'node:url'
const CS = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..')
const ROOTS = ['manager_dashboard/src', 'waiter_pwa/src', 'terminal/src', 'packages/ui/src']
// reading CSS lengths, not typed numbers (the older TVs' layer)
const SKIP = new Set(['terminal/src/compat.js'])
function* files(dir) {
for (const name of readdirSync(dir)) {
const p = path.join(dir, name)
if (statSync(p).isDirectory()) yield* files(p)
else if (/\.(jsx?|mjs)$/.test(name)) yield p
}
}
const RULES = [
[/\bparseFloat\(/, 'parseFloat'],
[/\.replace\(\s*['"],['"]\s*,\s*['"]\.['"]\s*\)/, ".replace(',', '.')"],
[/type=["']number["'][^>]*\bstep=(?:["']0?\.\d|\{[^}]*\b0?\.\d)/, 'type="number" with a decimal step'],
]
test('typed numbers are read with parseNumber, never parseFloat or a type="number" decimal field', () => {
const bad = []
for (const root of ROOTS) {
for (const file of files(path.join(CS, root))) {
const rel = path.relative(CS, file).replace(/\\/g, '/')
if (SKIP.has(rel)) continue
const text = readFileSync(file, 'utf8')
// a JSX element can span lines: look at each tag as one piece
const flat = text.replace(/<input\b[^>]*>/gs, m => m.replace(/\s+/g, ' '))
flat.split('\n').forEach((line, i) => {
for (const [re, what] of RULES) if (re.test(line)) bad.push(`${rel}:${i + 1} ${what}`)
})
}
}
assert.deepEqual(bad, [])
})
+1
View File
@@ -20,6 +20,7 @@
"test": "node --test \"tests/*.test.mjs\""
},
"peerDependencies": {
"@xenia/i18n": "*",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"qrcode.react": "^4.2.0"
+3
View File
@@ -501,6 +501,9 @@
font: inherit; font-size: var(--x-text-body); text-align: center; font-variant-numeric: tabular-nums;
}
.x-number__suffix { align-self: center; padding-right: var(--x-space-1); color: var(--x-ink-3); font-size: var(--x-text-label); }
/* DecimalInput / MoneyInput (6F.2): the number frame without − / +, text from the left */
.x-decimal__input { text-align: left; padding: 0 var(--x-space-3); }
.x-decimal__suffix { padding-right: var(--x-space-3); }
/* ── Slider (2026-11-21): framed like a field, its value beside it ──────────────── */
.x-slider {
@@ -0,0 +1,50 @@
import { useEffect, useRef, useState } from 'react'
import { cx } from '../internal/cx.js'
import { readDecimal } from './decimal.js'
const shown = v => (v == null || Number.isNaN(v) ? '' : String(v))
/**
* A number with decimals typed with a comma or a dot (owner 2026-11-23, plan 6F.2): "12,50",
* "12.50" and "1.234,50" all work, on every keyboard (a phone's Greek keypad has only a comma).
* The field keeps what is being typed ("12," on the way to "12,50") and reports a number:
* onChange(number) a number onChange(null) empty onChange(NaN) not a number (show an error)
* Never `type="number"` + parseFloat for money or quantities: those read "12,50" as 12 or nothing.
*
* <DecimalInput value={kg} onChange={setKg} decimals={3} suffix="kg" />
* decimals: rounds what is reported; allowNegative (default false); suffix: shown at the end.
*/
export function DecimalInput({ value, onChange, decimals, allowNegative = false, suffix, size = 'md', invalid = false, disabled = false, className, inputClassName, ...rest }) {
const [text, setText] = useState(() => shown(value))
const [focus, setFocus] = useState(false)
const reported = useRef(value)
// a value set from outside (a reset, − / + elsewhere) replaces the text; our own report doesn't
useEffect(() => {
if (Object.is(value, reported.current)) return
reported.current = value
setText(shown(value))
}, [value])
const bad = invalid || Number.isNaN(value)
return (
<span className={cx('x-number', 'x-decimal', `x-number--${size}`, bad && 'x-number--invalid', focus && 'x-number--focus', disabled && 'x-number--disabled', className)}>
<input type="text" inputMode="decimal" autoComplete="off" className={cx('x-number__input', 'x-decimal__input', inputClassName)} value={text} disabled={disabled}
aria-invalid={bad || undefined}
onChange={e => {
const s = e.target.value
setText(s)
const out = readDecimal(s, { decimals, allowNegative })
reported.current = out
onChange?.(out, s)
}}
onFocus={e => { setFocus(true); e.target.select() }}
onBlur={() => setFocus(false)}
{...rest} />
{suffix && <span className="x-number__suffix x-decimal__suffix" aria-hidden="true">{suffix}</span>}
</span>
)
}
/** An amount of money: DecimalInput with cents and "€" (6F.2). */
export function MoneyInput({ suffix = '€', ...rest }) {
return <DecimalInput decimals={2} suffix={suffix} {...rest} />
}
+9
View File
@@ -0,0 +1,9 @@
import { parseNumber } from '@xenia/i18n/number'
/** What a DecimalInput reports for the typed text (6F.2): a number, null (empty) or NaN (not a number). */
export function readDecimal(text, { decimals, allowNegative = false } = {}) {
const s = String(text ?? '')
if (s.trim() === '') return null
const n = parseNumber(s, { decimals, allowNegative })
return n == null ? NaN : n
}
+2
View File
@@ -18,6 +18,8 @@ export { ToastProvider } from './components/Toast.jsx'
export { useToast } from './components/toastContext.js'
export { PinPad } from './components/PinPad.jsx'
export { INFOTIP_HOVER_MS, InfoTip } from './components/InfoTip.jsx'
export { DecimalInput, MoneyInput } from './components/DecimalInput.jsx'
export { readDecimal } from './components/decimal.js'
export { EmptyState } from './components/EmptyState.jsx'
export { Spinner } from './components/Spinner.jsx'
export { Field, Input, Textarea, Select } from './components/Field.jsx'
+21
View File
@@ -0,0 +1,21 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { readDecimal } from '../src/components/decimal.js'
test('money typed with a comma or a dot (6F.2)', () => {
assert.equal(readDecimal('12,50', { decimals: 2 }), 12.5)
assert.equal(readDecimal('12.50', { decimals: 2 }), 12.5)
assert.equal(readDecimal('1.234,50', { decimals: 2 }), 1234.5)
assert.equal(readDecimal('0,05', { decimals: 2 }), 0.05)
assert.equal(readDecimal('€ 7,3', { decimals: 2 }), 7.3)
assert.equal(readDecimal('0,125', { decimals: 3 }), 0.125)
})
test('empty is null, nonsense is NaN, negatives only when allowed', () => {
assert.equal(readDecimal(''), null)
assert.equal(readDecimal(' '), null)
assert.ok(Number.isNaN(readDecimal('abc')))
assert.ok(Number.isNaN(readDecimal('12,5,0')))
assert.ok(Number.isNaN(readDecimal('-2,5')))
assert.equal(readDecimal('-2,5', { allowNegative: true }), -2.5)
})