diff --git a/src/app/stock/page.tsx b/src/app/stock/page.tsx index 010c65f..24801ee 100755 --- a/src/app/stock/page.tsx +++ b/src/app/stock/page.tsx @@ -91,6 +91,16 @@ export default function StockPage() { const [toppingUp, setToppingUp] = useState(null); /** Which vial is being emptied into a nasal spray bottle. */ const [transferring, setTransferring] = useState(null); + /** + * Which row is having its tablet size set. + * + * Needed because a pack can exist before anyone said how big one tablet is: + * added before the compound was marked as tablets, or imported, or added + * while the compound was still described as a powder. Without a way to say it + * afterwards the pack is stuck, countable by nothing, and the form for + * logging a dose can only say that the size is missing. + */ + const [sizing, setSizing] = useState(null); const now = Date.now(); /* @@ -357,7 +367,33 @@ export default function StockPage() { solution it can never be. */ onReconstitute={isPack(v) ? undefined : () => setReconstituting(v.id)} + tabletCompound={findPeptide(custom, v.peptideId)?.preparation === "tablet"} + onSetTabletSize={() => setSizing(v.id)} /> + {sizing === v.id && ( + setSizing(null)} + onSave={(mgEach, tabletsInPack) => { + /* + Every vial in the group, unlike the buttons beside it, + which act on the oldest one alone. Those change one + vial's state and the group is meant to split. This + changes what the row has always been, so writing it to + one member would break the group into a pack with a + size and a shelf of identical packs without one. + */ + for (const target of group ? group.vials : [v]) { + updateVial(target.id, { + container: "pack", + mgPerTablet: mgEach, + strengthMg: packStrengthMg(mgEach, tabletsInPack), + }); + } + setSizing(null); + }} + /> + )} {reconstituting === v.id && ( void; onFinish?: () => void; + /** Whether the library says this compound comes as tablets. */ + tabletCompound?: boolean; + onSetTabletSize?: () => void; }) { const { t } = useLang(); const st = vialStatus(vial, now); @@ -703,6 +744,18 @@ function VialRow({ {t("stock_to_spray")} )} + {/* + Offered for a pack, and also for an ordinary row of a compound the + library calls tablets, which is how a row added before anyone said + so becomes a pack at all. Without the second case the size could + only ever be set at the moment of adding, and a pack added the day + before the compound was marked as tablets was stuck for good. + */} + {onSetTabletSize && (pack || tabletCompound) && ( + + )} {onFinish && ( + + + + ); +} + function TopUpForm({ vial, bottles, diff --git a/src/components/LogDoseSheet.tsx b/src/components/LogDoseSheet.tsx index 3f66cbd..0576545 100755 --- a/src/components/LogDoseSheet.tsx +++ b/src/components/LogDoseSheet.tsx @@ -567,9 +567,17 @@ export function LogDoseSheet({ 0 - ? t("log_per_tablet_hint", { dose: formatDose(mcgPerTablet(vial)) }) - : t("log_no_tablet_size") + /* + Three states, three sentences. The first version said "add + the tablet size to the pack" whether or not there was a pack + to add it to, which reads as an instruction with nowhere to + carry it out. + */ + !vial + ? t("log_no_pack_in_stock") + : mcgPerTablet(vial) > 0 + ? t("log_per_tablet_hint", { dose: formatDose(mcgPerTablet(vial)) }) + : t("log_no_tablet_size") } >