diff --git a/web/src/pages/ProductForm.jsx b/web/src/pages/ProductForm.jsx index 15160a7..f2f19f3 100644 --- a/web/src/pages/ProductForm.jsx +++ b/web/src/pages/ProductForm.jsx @@ -289,10 +289,6 @@ export default function ProductForm() { )} - - Nur Einheiten der Art „{selectedUnit ? KIND_LABEL[selectedUnit.kind] : "–"}“ - (passend zur Produkteinheit) plus Packungen. - Gruppe @@ -340,6 +336,8 @@ export default function ProductForm() { function LotsCard({ product, lots, baseShort, warnDays, isAdmin, imageUrl, onChanged, onError }) { const [editId, setEditId] = useState(null); const [draft, setDraft] = useState({ quantity: "", best_before: "" }); + // In welcher Einheit die Menge bearbeitet wird: "unit" oder "package". + const [editUnit, setEditUnit] = useState("unit"); const unitFactor = product?.unit_factor || 1; const unitName = product?.unit_name || baseShort; @@ -357,15 +355,31 @@ function LotsCard({ product, lots, baseShort, warnDays, isAdmin, imageUrl, onCha return parts.join(" · "); } + // Faktor der aktuell im Editor gewählten Eingabeeinheit. + function editFactorOf(mode) { + return mode === "package" && pkgSize > 0 ? pkgSize : unitFactor; + } + const editFactor = editFactorOf(editUnit); + function startEdit(l) { setEditId(l.id); - setDraft({ quantity: l.quantity / primaryFactor, best_before: l.best_before || "" }); + setEditUnit("unit"); + setDraft({ quantity: l.quantity / unitFactor, best_before: l.best_before || "" }); + } + + function changeEditUnit(newMode) { + if (draft.quantity !== "" && newMode !== editUnit) { + const oldF = editFactorOf(editUnit); + const newF = editFactorOf(newMode); + setDraft((d) => ({ ...d, quantity: String((Number(d.quantity) * oldF) / newF) })); + } + setEditUnit(newMode); } async function saveEdit(l) { try { await api.updateLot(l.id, { - quantity: Number(draft.quantity) * primaryFactor, + quantity: Number(draft.quantity) * editFactor, best_before: draft.best_before || null, }); setEditId(null); @@ -412,7 +426,15 @@ function LotsCard({ product, lots, baseShort, warnDays, isAdmin, imageUrl, onCha setDraft({ ...draft, quantity: e.target.value })} style={{ maxWidth: 90, marginTop: 0 }} /> - {primaryLabel} + {pkgSize > 0 ? ( + changeEditUnit(e.target.value)} + style={{ maxWidth: 120, marginTop: 0 }}> + {unitName} + Packung(en) + + ) : ( + {unitName} + )} ) : ( <> @@ -461,10 +483,9 @@ function LotsCard({ product, lots, baseShort, warnDays, isAdmin, imageUrl, onCha - - Mengen in {unitName} - {pkgSize > 0 ? ` (1 Packung = ${fmt(pkgSize)} ${baseShort})` : ""}. - + {pkgSize > 0 && ( + 1 Packung = {fmt(pkgSize)} {baseShort} + )} ); }
- Mengen in {unitName} - {pkgSize > 0 ? ` (1 Packung = ${fmt(pkgSize)} ${baseShort})` : ""}. -
1 Packung = {fmt(pkgSize)} {baseShort}