@burdenoff/microfe-healthybowl 2026.810.4 → 2026.810.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
2
+ import { useCallback as t, useState as n } from "react";
3
+ import { gql as r } from "@apollo/client";
4
+ import { useMutation as i } from "@apollo/client/react";
5
+ //#region src/healthybowl/hooks/useHarvestInventory.ts
6
+ var a = r`
7
+ mutation HealthyBowlLinkHarvestToInventory($input: LinkHarvestToInventoryInput!) {
8
+ linkHealthyBowlHarvestToInventory(input: $input) {
9
+ id
10
+ productId
11
+ }
12
+ }
13
+ `;
14
+ function o() {
15
+ let { workspaceId: r } = e(), o = { workspaceId: r }, [s, c] = n(() => /* @__PURE__ */ new Set()), [l] = i(a);
16
+ return {
17
+ linkToInventory: t(async (e, t) => {
18
+ c((t) => new Set(t).add(e));
19
+ try {
20
+ return (await l({ variables: { input: {
21
+ id: e,
22
+ productCategory: t,
23
+ context: o
24
+ } } })).data?.linkHealthyBowlHarvestToInventory?.productId ?? null;
25
+ } finally {
26
+ c((t) => {
27
+ let n = new Set(t);
28
+ return n.delete(e), n;
29
+ });
30
+ }
31
+ }, [l, r]),
32
+ isLinking: t((e) => s.has(e), [s])
33
+ };
34
+ }
35
+ //#endregion
36
+ export { o as useHarvestInventory };
37
+
38
+ //# sourceMappingURL=useHarvestInventory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHarvestInventory.js","names":[],"sources":["../../../src/healthybowl/hooks/useHarvestInventory.ts"],"sourcesContent":["/**\n * Harvest → inventory linkage (BOFF-6095).\n *\n * `addToInventory` is a create-time-only flag and the main harvest form never sent it, so produce\n * recorded through the primary route was stranded outside inventory permanently. This hook is the\n * way back in: it links an already-recorded harvest to sellable stock.\n *\n * Mirrors the raw-`gql` pattern used by {@link usePlanExecution} — the offline codegen doesn't type\n * these operations, so they're hand-written documents executed directly against the live gateway.\n * @module healthybowl\n */\nimport { useCallback, useState } from 'react';\nimport { gql } from '@apollo/client';\nimport { useMutation } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\n\nconst LINK_HARVEST_TO_INVENTORY = gql`\n mutation HealthyBowlLinkHarvestToInventory($input: LinkHarvestToInventoryInput!) {\n linkHealthyBowlHarvestToInventory(input: $input) {\n id\n productId\n }\n }\n`;\n\ninterface LinkResult {\n linkHealthyBowlHarvestToInventory?: { id?: string; productId?: string | null };\n}\n\n/**\n * Exposes a single action: bank a recorded harvest into inventory.\n *\n * `isLinking(id)` reports whether that specific harvest is in flight, so a list disables only the\n * row being linked. This tracks a SET rather than one id: with a single id, linking card A and then\n * card B meant A's completion cleared the flag while B was still in flight, re-enabling B's button\n * mid-request. The server side is idempotent by `HarvestRecord.productId` and its stamp is a\n * compare-and-set, so a stray second click could not double-bank — but the UI should not invite one.\n */\nexport function useHarvestInventory() {\n const { workspaceId } = useHealthyBowl();\n const context = { workspaceId };\n const [linkingIds, setLinkingIds] = useState<ReadonlySet<string>>(() => new Set());\n const [linkMutation] = useMutation<LinkResult>(LINK_HARVEST_TO_INVENTORY);\n\n const linkToInventory = useCallback(\n async (harvestId: string, productCategory?: string) => {\n setLinkingIds((prev) => new Set(prev).add(harvestId));\n try {\n const res = await linkMutation({\n variables: { input: { id: harvestId, productCategory, context } },\n });\n return res.data?.linkHealthyBowlHarvestToInventory?.productId ?? null;\n } finally {\n setLinkingIds((prev) => {\n const next = new Set(prev);\n next.delete(harvestId);\n return next;\n });\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [linkMutation, workspaceId]\n );\n\n const isLinking = useCallback((harvestId: string) => linkingIds.has(harvestId), [linkingIds]);\n\n return { linkToInventory, isLinking };\n}\n"],"mappings":";;;;;AAgBA,IAAM,IAA4B,CAAG;;;;;;;;AAsBrC,SAAgB,IAAsB;CACpC,IAAM,EAAE,mBAAgB,GAAgB,EAClC,IAAU,EAAE,gBAAa,EACzB,CAAC,GAAY,KAAiB,wBAAoC,IAAI,KAAK,CAAC,EAC5E,CAAC,KAAgB,EAAwB,EAA0B;AAwBzE,QAAO;EAAE,iBAtBe,EACtB,OAAO,GAAmB,MAA6B;AACrD,MAAe,MAAS,IAAI,IAAI,EAAK,CAAC,IAAI,EAAU,CAAC;AACrD,OAAI;AAIF,YAHY,MAAM,EAAa,EAC7B,WAAW,EAAE,OAAO;KAAE,IAAI;KAAW;KAAiB;KAAS,EAAE,EAClE,CAAC,EACS,MAAM,mCAAmC,aAAa;aACzD;AACR,OAAe,MAAS;KACtB,IAAM,IAAO,IAAI,IAAI,EAAK;AAE1B,YADA,EAAK,OAAO,EAAU,EACf;MACP;;KAIN,CAAC,GAAc,EAAY,CAC5B;EAIyB,WAFR,GAAa,MAAsB,EAAW,IAAI,EAAU,EAAE,CAAC,EAAW,CAAC;EAExD"}
@@ -78,6 +78,9 @@ var wt = a`
78
78
  harvestDate
79
79
  pricePerUnit
80
80
  storageLocation
81
+ # BOFF-6095 — set once the harvest has been banked into inventory. Drives whether the
82
+ # harvest page offers "Add to inventory" or reports that it is already stock.
83
+ productId
81
84
  }
82
85
  updatedAt
83
86
  }