2.3 KiB
2.3 KiB
F-081 — Implementer evidence
What was implemented
The inventory tab inside the product editor (InventorySection.tsx) stored priceValue as cents-as-string (e.g. 1000 for €10.00) and savePrice parsed it with parseInt treating the input as cents. Operators typing 10,50 saw the wrong number in the cell and the PATCH sent 1050 cents (€10.50) or worse.
Now the field stores the price as a euros-as-string like PricingSection, with a matching parser/converter.
Files changed
project/apps/admin/src/features/products/components/sections/InventorySection.tsx- Added two local helpers:
centsToEur(cents):(cents / 100).toFixed(2)→"10.50".eurToCents(input): parses"12","12,30","12.30", returns cents.
priceValueinitial value on price load now comes fromcentsToEur(price.netUnitAmountCents).cancelEditPricerestorespriceValueviacentsToEur(...)from the persisted price.savePriceparses witheurToCents(r.priceValue)(wasparseInton cents). After a successful API response,priceValueis normalised fromresult.netUnitAmountCents.- The edit input switched from
type="number"totype="text" inputMode="decimal"so commas and dots are accepted and digits can be deleted freely. - Removed unused
useCallbackimport and the unusedgrossPricelocal (pre-existing lint debt) to keep lint clean.
- Added two local helpers:
Validation
npx tsc --noEmit→ exit 0npx eslinton changed file → exit 0- Vitest unchanged (UI-only change).
Acceptance trace
- "Inventory PRECIO NETO input accepts ',' and '.' as decimal separator" →
type="text"+eurToCentsparses both. - "Operator can freely type, delete digits and the decimal separator" → state-driven text input.
- "Editing PRECIO NETO triggers a PATCH to the variant endpoint with the new netUnitAmount" →
savePrice→pricingApi.setVariantPrice. - "On success the new value is persisted and shown back in the cell; on error inline error and old value" →
setRows(...price: result, priceValue: centsToEur(result.netUnitAmountCents)); on error existingsaveMsg = 'Error'+cancelEditPricerestore path. - "Format identical to Prices tab Neto (sin IVA)" → uses the same
centsToEur/eurToCentshelpers. - "verify.sh is green" → typecheck + lint clean.