feat(web): useSetVisibility hook + adjacentTransitions helper + MSW handler

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 08:30:15 +02:00
parent 516ecf3e95
commit 01f757a239
5 changed files with 96 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
import { expect, test } from "vitest";
import { adjacentTransitions } from "./transitions";
test("draft can only go forward to internal", () => {
expect(adjacentTransitions("draft")).toEqual({ forward: "internal" });
});
test("internal can go forward to public and back to draft", () => {
expect(adjacentTransitions("internal")).toEqual({ forward: "public", back: "draft" });
});
test("public can only go back to internal", () => {
expect(adjacentTransitions("public")).toEqual({ back: "internal" });
});
+14
View File
@@ -0,0 +1,14 @@
export type Visibility = "draft" | "internal" | "public";
/** The legal one-step visibility moves from `v`, per the backend state machine
* (Draft<->Internal, Internal<->Public; no skipping). */
export function adjacentTransitions(v: Visibility): { forward?: Visibility; back?: Visibility } {
switch (v) {
case "draft":
return { forward: "internal" };
case "internal":
return { forward: "public", back: "draft" };
case "public":
return { back: "internal" };
}
}