refactor(medications): give the in-use clock list one owner

The supply tab carried its own copy of the two container kinds whose first
opening starts a degradation clock, with a comment saying it mirrored the
state machine's list. Nothing enforced the mirror — the state machine types
itself against the generated Prisma client, which the browser bundle cannot
carry, so a copy was the only way to say it.

Move the list into a client-safe module with no imports and let both sides
read it. The state machine re-exports it under the Prisma enum, so a renamed
or dropped container kind is now a compile error rather than a member that
quietly stops matching.
This commit is contained in:
Marc-André Bombeck committed 2026-07-27 14:47:54 +02:00
1 parent 6ab3bc87ff
commit 146a02319d
3 files changed
+47 -17

No files matched your search

@@ -75,6 +75,7 @@ import {
apiPost,
apiPut,
} from "@/lib/api/api-fetch";
import { startsInUseClock } from "@/lib/medications/inventory/clock-container-types";
import type { SupplySummary } from "@/lib/medications/inventory/summary";
/**
@@ -169,15 +170,6 @@ const STATE_BADGE: Record<
USED_UP: "outline",
};
/**
* Container kinds whose first opening starts a 30-day degradation clock.
* Mirrors `IN_USE_CLOCK_CONTAINER_TYPES` in
* `src/lib/medications/inventory/state-machine.ts` — the server owns the
* transition; the client only needs to know which helper text to show
* beside the opening date.
*/
const CLOCK_CONTAINER_TYPES: readonly ContainerType[] = ["PEN", "AMPOULE"];
/** Default container kind for the register flow, from the delivery form. */
function defaultContainerType(deliveryForm: string | undefined): ContainerType {
if (deliveryForm === "INJECTION") return "PEN";
@@ -971,7 +963,7 @@ export function AdjustInventoryDialog({
id="inventory-edit-opened-helper"
className="text-muted-foreground text-xs"
>
{CLOCK_CONTAINER_TYPES.includes(item.containerType)
{startsInUseClock(item.containerType)
? t("medications.detail.bestand.editOpenedHelperClock")
: t("medications.detail.bestand.editOpenedHelper")}
</p>