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, [])
})