@burdenoff/microfe-healthybowl 2026.813.25 → 2026.813.27

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.
@@ -3,12 +3,13 @@ import { StatusBadge as n } from "./StatusBadge.js";
3
3
  import { useToast as r } from "../hooks/useToast.js";
4
4
  import "./index.js";
5
5
  import { usePlanExecution as ee } from "../hooks/usePlanExecution.js";
6
- import { useMemo as i, useState as a } from "react";
7
- import { Activity as o, CalendarClock as te, PackageCheck as ne, Pencil as re, Sprout as ie, Target as ae, Trash2 as oe, X as se } from "lucide-react";
8
- import { jsx as s, jsxs as c } from "react/jsx-runtime";
9
- import { Button as l, GlassCard as u, Input as d, Select as f, SelectContent as p, SelectItem as m, SelectTrigger as h, SelectValue as g, Textarea as ce } from "@burdenoff/fe-libs/ui";
6
+ import { toActivityPayload as te, toFormFields as ne } from "../utils/planActivityForm.js";
7
+ import { useMemo as re, useState as i } from "react";
8
+ import { Activity as ie, CalendarClock as ae, PackageCheck as oe, Pencil as se, Sprout as a, Target as ce, Trash2 as le, X as ue } from "lucide-react";
9
+ import { jsx as o, jsxs as s } from "react/jsx-runtime";
10
+ import { Button as c, GlassCard as l, Input as u, Select as d, SelectContent as f, SelectItem as p, SelectTrigger as m, SelectValue as h, Textarea as de } from "@burdenoff/fe-libs/ui";
10
11
  //#region src/healthybowl/components/PlanExecutionPanel.tsx
11
- var _ = [
12
+ var g = [
12
13
  {
13
14
  value: "WATERING",
14
15
  label: "Watering"
@@ -49,27 +50,27 @@ var _ = [
49
50
  value: "OTHER",
50
51
  label: "Other"
51
52
  }
52
- ], le = (e) => _.find((t) => t.value === e)?.label ?? e, v = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 10), ue = (e) => {
53
+ ], fe = (e) => g.find((t) => t.value === e)?.label ?? e, _ = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 10), pe = (e) => {
53
54
  let t = Number(e);
54
55
  return Number.isFinite(t) && t > 0 ? t : null;
55
56
  };
56
- function y() {
57
+ function v() {
57
58
  return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `hb-harvest-${Date.now()}-${Math.round(Math.random() * 1e9)}`;
58
59
  }
59
- var b = ({ plan: b, crops: C, onCropChanged: de }) => {
60
- let { toast: w } = r(), { execution: T, loading: fe, setTransplantDate: pe, addActivity: me, updateActivity: he, deleteActivity: ge, recordHarvest: _e } = ee(b.id), E = i(() => {
61
- let e = C.filter((e) => !b.fieldId || e.field === b.fieldId);
62
- return e.length > 0 ? e : C;
63
- }, [C, b.fieldId]), ve = i(() => E.find((e) => e.name === b.cropName)?.id ?? E[0]?.id ?? "", [E, b.cropName]), [D, O] = a(""), [ye, k] = a(!1), be = async () => {
60
+ var y = ({ plan: y, crops: S, onCropChanged: me }) => {
61
+ let { toast: C } = r(), { execution: w, loading: T, setTransplantDate: he, addActivity: ge, updateActivity: _e, deleteActivity: ve, recordHarvest: ye } = ee(y.id), E = re(() => {
62
+ let e = S.filter((e) => !y.fieldId || e.field === y.fieldId);
63
+ return e.length > 0 ? e : S;
64
+ }, [S, y.fieldId]), be = re(() => E.find((e) => e.name === y.cropName)?.id ?? E[0]?.id ?? "", [E, y.cropName]), [D, O] = i(""), [xe, k] = i(!1), Se = async () => {
64
65
  if (D) {
65
66
  k(!0);
66
67
  try {
67
- await pe(D), w({
68
+ await he(D), C({
68
69
  title: "Transplant date set",
69
70
  variant: "success"
70
71
  }), O("");
71
72
  } catch {
72
- w({
73
+ C({
73
74
  title: "Could not set transplant date",
74
75
  variant: "error"
75
76
  });
@@ -77,73 +78,74 @@ var b = ({ plan: b, crops: C, onCropChanged: de }) => {
77
78
  k(!1);
78
79
  }
79
80
  }
80
- }, [A, j] = a("WATERING"), [M, N] = a(v()), [P, F] = a(""), [I, L] = a(""), [R, z] = a(""), [B, V] = a(""), [H, U] = a(!1), [W, G] = a(null), K = () => {
81
- G(null), j("WATERING"), N(v()), F(""), L(""), z(""), V("");
82
- }, xe = (e) => {
83
- G(e.id), j(e.type), N((e.activityDate ?? "").slice(0, 10)), F(e.quantity == null ? "" : String(e.quantity)), L(e.unit ?? ""), z(e.laborHours == null ? "" : String(e.laborHours)), V(e.notes ?? "");
84
- }, Se = async () => {
81
+ }, [A, j] = i("WATERING"), [M, N] = i(_()), [P, F] = i(""), [I, L] = i(""), [R, z] = i(""), [B, V] = i(""), [H, U] = i(!1), [W, G] = i(null), K = () => {
82
+ G(null), j("WATERING"), N(_()), F(""), L(""), z(""), V("");
83
+ }, Ce = (e) => {
84
+ let t = ne(e);
85
+ G(e.id), j(t.type), N(t.date), F(t.quantity), L(t.unit), z(t.labor), V(t.notes);
86
+ }, we = async () => {
85
87
  if (!M) {
86
- w({
88
+ C({
87
89
  title: "Pick an activity date",
88
90
  variant: "error"
89
91
  });
90
92
  return;
91
93
  }
92
94
  U(!0);
93
- let e = {
95
+ let e = te({
94
96
  type: A,
95
- activityDate: M,
96
- quantity: P ? Number(P) : null,
97
- unit: I.trim() || null,
98
- laborHours: R ? Number(R) : null,
99
- notes: B.trim() || null
100
- };
97
+ date: M,
98
+ quantity: P,
99
+ unit: I,
100
+ labor: R,
101
+ notes: B
102
+ });
101
103
  try {
102
- W ? (await he(W, e), w({
104
+ W ? (await _e(W, e), C({
103
105
  title: "Activity updated",
104
106
  variant: "success"
105
- })) : (await me(e), w({
107
+ })) : (await ge(e), C({
106
108
  title: "Activity logged",
107
109
  variant: "success"
108
- })), A === "TRANSPLANT" && de?.(), K();
110
+ })), A === "TRANSPLANT" && me?.(), K();
109
111
  } catch {
110
- w({
112
+ C({
111
113
  title: W ? "Could not update activity" : "Could not log activity",
112
114
  variant: "error"
113
115
  });
114
116
  } finally {
115
117
  U(!1);
116
118
  }
117
- }, Ce = async (e) => {
119
+ }, Te = async (e) => {
118
120
  try {
119
- await ge(e), W === e && K(), w({
121
+ await ve(e), W === e && K(), C({
120
122
  title: "Activity removed",
121
123
  variant: "success"
122
124
  });
123
125
  } catch {
124
- w({
126
+ C({
125
127
  title: "Could not remove activity",
126
128
  variant: "error"
127
129
  });
128
130
  }
129
- }, [we, Te] = a(""), [Ee, De] = a(""), [Oe, ke] = a("kg"), [q, Ae] = a("A"), [je, Me] = a(v()), [J, Ne] = a(""), [Y, Pe] = a(!0), [X, Z] = a(!1), [Fe, Ie] = a(() => y()), Q = we || ve, Le = async () => {
130
- let e = ue(Ee);
131
+ }, [Ee, De] = i(""), [q, Oe] = i(""), [ke, Ae] = i("kg"), [je, Me] = i("A"), [Ne, Pe] = i(_()), [J, Fe] = i(""), [Y, Ie] = i(!0), [X, Z] = i(!1), [Le, Re] = i(() => v()), Q = Ee || be, ze = async () => {
132
+ let e = pe(q);
131
133
  if (!Q) {
132
- w({
134
+ C({
133
135
  title: "Add a crop on this field first",
134
136
  variant: "error"
135
137
  });
136
138
  return;
137
139
  }
138
- if (!b.fieldId) {
139
- w({
140
+ if (!y.fieldId) {
141
+ C({
140
142
  title: "This plan has no field",
141
143
  variant: "error"
142
144
  });
143
145
  return;
144
146
  }
145
147
  if (e == null) {
146
- w({
148
+ C({
147
149
  title: "Enter a harvest quantity",
148
150
  variant: "error"
149
151
  });
@@ -152,22 +154,22 @@ var b = ({ plan: b, crops: C, onCropChanged: de }) => {
152
154
  if (!X) {
153
155
  Z(!0);
154
156
  try {
155
- await _e({
157
+ await ye({
156
158
  cropId: Q,
157
- fieldId: b.fieldId,
159
+ fieldId: y.fieldId,
158
160
  quantity: e,
159
- unit: Oe.trim() || "kg",
160
- quality: q,
161
- harvestDate: je,
161
+ unit: ke.trim() || "kg",
162
+ quality: je,
163
+ harvestDate: Ne,
162
164
  pricePerUnit: J ? Number(J) : null,
163
165
  addToInventory: Y,
164
- clientMutationId: Fe
165
- }), w({
166
+ clientMutationId: Le
167
+ }), C({
166
168
  title: Y ? "Harvest recorded & added to inventory" : "Harvest recorded",
167
169
  variant: "success"
168
- }), De(""), Ne(""), Ie(y());
170
+ }), Oe(""), Fe(""), Re(v());
169
171
  } catch {
170
- w({
172
+ C({
171
173
  title: "Could not record harvest",
172
174
  variant: "error"
173
175
  });
@@ -175,110 +177,110 @@ var b = ({ plan: b, crops: C, onCropChanged: de }) => {
175
177
  Z(!1);
176
178
  }
177
179
  }
178
- }, $ = T?.yieldVariancePct, Re = $ == null ? "—" : `${$ > 0 ? "+" : ""}${t(Math.round($))}%`, ze = $ == null ? "muted" : $ >= 0 ? "success" : "warning";
179
- return /* @__PURE__ */ c("div", {
180
+ }, $ = w?.yieldVariancePct, Be = $ == null ? "—" : `${$ > 0 ? "+" : ""}${t(Math.round($))}%`, Ve = $ == null ? "muted" : $ >= 0 ? "success" : "warning";
181
+ return /* @__PURE__ */ s("div", {
180
182
  className: "space-y-6",
181
183
  "data-testid": "plan-execution-panel",
182
184
  children: [
183
- /* @__PURE__ */ c(u, {
185
+ /* @__PURE__ */ s(l, {
184
186
  treatment: "glass",
185
187
  glow: !0,
186
188
  className: "border-border-seam p-6",
187
189
  children: [
188
- /* @__PURE__ */ c("h3", {
190
+ /* @__PURE__ */ s("h3", {
189
191
  className: "mb-4 flex items-center gap-2 text-sm font-semibold text-text-primary",
190
- children: [/* @__PURE__ */ s(ae, { className: "h-4 w-4 text-info" }), " Execution & yield"]
192
+ children: [/* @__PURE__ */ o(ce, { className: "h-4 w-4 text-info" }), " Execution & yield"]
191
193
  }),
192
- /* @__PURE__ */ c("div", {
194
+ /* @__PURE__ */ s("div", {
193
195
  className: "grid grid-cols-2 gap-4 md:grid-cols-4",
194
196
  children: [
195
- /* @__PURE__ */ s(x, {
197
+ /* @__PURE__ */ o(b, {
196
198
  label: "Planned yield",
197
- value: t(T?.plannedYield ?? b.expectedYield ?? 0),
199
+ value: t(w?.plannedYield ?? y.expectedYield ?? 0),
198
200
  unit: "kg"
199
201
  }),
200
- /* @__PURE__ */ s(x, {
202
+ /* @__PURE__ */ o(b, {
201
203
  label: "Actual yield",
202
- value: t(T?.actualYield ?? 0),
204
+ value: t(w?.actualYield ?? 0),
203
205
  unit: "kg"
204
206
  }),
205
- /* @__PURE__ */ c("div", { children: [/* @__PURE__ */ s("div", {
207
+ /* @__PURE__ */ s("div", { children: [/* @__PURE__ */ o("div", {
206
208
  className: "text-xs text-text-secondary",
207
209
  children: "Variance"
208
- }), /* @__PURE__ */ s("div", {
210
+ }), /* @__PURE__ */ o("div", {
209
211
  className: "mt-1",
210
- children: /* @__PURE__ */ s(n, {
211
- label: Re,
212
- variant: ze
212
+ children: /* @__PURE__ */ o(n, {
213
+ label: Be,
214
+ variant: Ve
213
215
  })
214
216
  })] }),
215
- /* @__PURE__ */ s(x, {
217
+ /* @__PURE__ */ o(b, {
216
218
  label: "Harvests",
217
- value: t(T?.harvestCount ?? 0)
219
+ value: t(w?.harvestCount ?? 0)
218
220
  })
219
221
  ]
220
222
  }),
221
- /* @__PURE__ */ c("div", {
223
+ /* @__PURE__ */ s("div", {
222
224
  className: "mt-5 grid grid-cols-1 gap-4 border-t border-border-subtle pt-4 sm:grid-cols-2",
223
- children: [/* @__PURE__ */ c("div", { children: [
224
- /* @__PURE__ */ c("div", {
225
+ children: [/* @__PURE__ */ s("div", { children: [
226
+ /* @__PURE__ */ s("div", {
225
227
  className: "flex items-center gap-1 text-xs text-text-secondary",
226
- children: [/* @__PURE__ */ s(te, { className: "h-3.5 w-3.5" }), " Transplant date"]
228
+ children: [/* @__PURE__ */ o(ae, { className: "h-3.5 w-3.5" }), " Transplant date"]
227
229
  }),
228
- /* @__PURE__ */ s("div", {
230
+ /* @__PURE__ */ o("div", {
229
231
  className: "mt-1 text-sm font-medium text-text-primary",
230
- children: T?.transplantDate ? e(T.transplantDate) : "Not set"
232
+ children: w?.transplantDate ? e(w.transplantDate) : "Not set"
231
233
  }),
232
- /* @__PURE__ */ c("div", {
234
+ /* @__PURE__ */ s("div", {
233
235
  className: "mt-2 flex items-center gap-2",
234
- children: [/* @__PURE__ */ s(d, {
236
+ children: [/* @__PURE__ */ o(u, {
235
237
  type: "date",
236
238
  value: D,
237
239
  onChange: (e) => O(e.target.value),
238
240
  className: "h-9 w-44",
239
241
  "aria-label": "Transplant date"
240
- }), /* @__PURE__ */ s(l, {
242
+ }), /* @__PURE__ */ o(c, {
241
243
  size: "sm",
242
244
  variant: "outline",
243
- onClick: be,
244
- disabled: !D || ye,
245
- children: T?.transplantDate ? "Update" : "Set"
245
+ onClick: Se,
246
+ disabled: !D || xe,
247
+ children: w?.transplantDate ? "Update" : "Set"
246
248
  })]
247
249
  })
248
- ] }), /* @__PURE__ */ c("div", { children: [/* @__PURE__ */ s("div", {
250
+ ] }), /* @__PURE__ */ s("div", { children: [/* @__PURE__ */ o("div", {
249
251
  className: "text-xs text-text-secondary",
250
252
  children: "Sow / nursery date"
251
- }), /* @__PURE__ */ s("div", {
253
+ }), /* @__PURE__ */ o("div", {
252
254
  className: "mt-1 text-sm font-medium text-text-primary",
253
- children: T?.sowDate ? e(T.sowDate) : "—"
255
+ children: w?.sowDate ? e(w.sowDate) : "—"
254
256
  })] })]
255
257
  })
256
258
  ]
257
259
  }),
258
- /* @__PURE__ */ c(u, {
260
+ /* @__PURE__ */ s(l, {
259
261
  treatment: "glass",
260
262
  className: "border-border-seam p-6",
261
263
  children: [
262
- /* @__PURE__ */ c("h3", {
264
+ /* @__PURE__ */ s("h3", {
263
265
  className: "mb-4 flex items-center gap-2 text-sm font-semibold text-text-primary",
264
- children: [/* @__PURE__ */ s(o, { className: "h-4 w-4 text-info" }), " Activity log"]
266
+ children: [/* @__PURE__ */ o(ie, { className: "h-4 w-4 text-info" }), " Activity log"]
265
267
  }),
266
- T && T.activities.length > 0 ? /* @__PURE__ */ s("ul", {
268
+ w && w.activities.length > 0 ? /* @__PURE__ */ o("ul", {
267
269
  className: "mb-5 space-y-2",
268
- children: T.activities.map((r) => /* @__PURE__ */ c("li", {
269
- className: "flex items-center justify-between gap-3 rounded-lg border border-border-subtle bg-bg-surface px-3 py-2",
270
- children: [/* @__PURE__ */ c("div", {
270
+ children: w.activities.map((r) => /* @__PURE__ */ s("li", {
271
+ className: `flex items-center justify-between gap-3 rounded-lg border px-3 py-2 ${W === r.id ? "border-primary bg-primary/5" : "border-border-subtle bg-bg-surface"}`,
272
+ children: [/* @__PURE__ */ s("div", {
271
273
  className: "min-w-0",
272
- children: [/* @__PURE__ */ c("div", {
274
+ children: [/* @__PURE__ */ s("div", {
273
275
  className: "flex items-center gap-2",
274
- children: [/* @__PURE__ */ s(n, {
275
- label: le(r.type),
276
+ children: [/* @__PURE__ */ o(n, {
277
+ label: fe(r.type),
276
278
  variant: "info"
277
- }), /* @__PURE__ */ s("span", {
279
+ }), /* @__PURE__ */ o("span", {
278
280
  className: "text-xs text-text-secondary",
279
281
  children: e(r.activityDate)
280
282
  })]
281
- }), /* @__PURE__ */ s("div", {
283
+ }), /* @__PURE__ */ o("div", {
282
284
  className: "mt-1 truncate text-xs text-text-secondary",
283
285
  children: [
284
286
  r.quantity == null ? null : `${t(r.quantity)}${r.unit ? ` ${r.unit}` : ""}`,
@@ -286,55 +288,62 @@ var b = ({ plan: b, crops: C, onCropChanged: de }) => {
286
288
  r.notes
287
289
  ].filter(Boolean).join(" · ") || "—"
288
290
  })]
289
- }), /* @__PURE__ */ c("div", {
291
+ }), /* @__PURE__ */ s("div", {
290
292
  className: "flex shrink-0 items-center gap-1",
291
- children: [/* @__PURE__ */ s(l, {
292
- size: "sm",
293
- variant: "ghost",
294
- onClick: () => xe(r),
295
- "aria-label": "Edit activity",
296
- children: /* @__PURE__ */ s(re, { className: "h-4 w-4 text-text-secondary" })
297
- }), /* @__PURE__ */ s(l, {
298
- size: "sm",
299
- variant: "ghost",
300
- onClick: () => Ce(r.id),
301
- "aria-label": "Remove activity",
302
- children: /* @__PURE__ */ s(oe, { className: "h-4 w-4 text-text-secondary" })
303
- })]
293
+ children: [
294
+ W === r.id && /* @__PURE__ */ o("span", {
295
+ className: "mr-1 text-xs font-medium text-primary",
296
+ children: "Editing"
297
+ }),
298
+ /* @__PURE__ */ o(c, {
299
+ size: "sm",
300
+ variant: "ghost",
301
+ onClick: () => Ce(r),
302
+ "aria-label": "Edit activity",
303
+ children: /* @__PURE__ */ o(se, { className: "h-4 w-4 text-text-secondary" })
304
+ }),
305
+ /* @__PURE__ */ o(c, {
306
+ size: "sm",
307
+ variant: "ghost",
308
+ onClick: () => Te(r.id),
309
+ "aria-label": "Remove activity",
310
+ children: /* @__PURE__ */ o(le, { className: "h-4 w-4 text-text-secondary" })
311
+ })
312
+ ]
304
313
  })]
305
314
  }, r.id))
306
- }) : /* @__PURE__ */ s("p", {
315
+ }) : /* @__PURE__ */ o("p", {
307
316
  className: "mb-5 text-sm text-text-secondary",
308
- children: fe ? "Loading activities…" : "No activities logged yet. Record watering, tilling and field work below."
317
+ children: T ? "Loading activities…" : "No activities logged yet. Record watering, tilling and field work below."
309
318
  }),
310
- /* @__PURE__ */ c("div", {
319
+ /* @__PURE__ */ s("div", {
311
320
  className: "grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3",
312
321
  children: [
313
- /* @__PURE__ */ s(S, {
322
+ /* @__PURE__ */ o(x, {
314
323
  label: "Type",
315
- children: /* @__PURE__ */ c(f, {
324
+ children: /* @__PURE__ */ s(d, {
316
325
  value: A,
317
326
  onValueChange: j,
318
- children: [/* @__PURE__ */ s(h, {
327
+ children: [/* @__PURE__ */ o(m, {
319
328
  className: "w-full",
320
- children: /* @__PURE__ */ s(g, {})
321
- }), /* @__PURE__ */ s(p, { children: _.map((e) => /* @__PURE__ */ s(m, {
329
+ children: /* @__PURE__ */ o(h, {})
330
+ }), /* @__PURE__ */ o(f, { children: g.map((e) => /* @__PURE__ */ o(p, {
322
331
  value: e.value,
323
332
  children: e.label
324
333
  }, e.value)) })]
325
334
  })
326
335
  }),
327
- /* @__PURE__ */ s(S, {
336
+ /* @__PURE__ */ o(x, {
328
337
  label: "Date",
329
- children: /* @__PURE__ */ s(d, {
338
+ children: /* @__PURE__ */ o(u, {
330
339
  type: "date",
331
340
  value: M,
332
341
  onChange: (e) => N(e.target.value)
333
342
  })
334
343
  }),
335
- /* @__PURE__ */ s(S, {
344
+ /* @__PURE__ */ o(x, {
336
345
  label: "Quantity",
337
- children: /* @__PURE__ */ s(d, {
346
+ children: /* @__PURE__ */ o(u, {
338
347
  type: "number",
339
348
  min: "0",
340
349
  step: "any",
@@ -343,17 +352,17 @@ var b = ({ plan: b, crops: C, onCropChanged: de }) => {
343
352
  placeholder: "e.g. 20"
344
353
  })
345
354
  }),
346
- /* @__PURE__ */ s(S, {
355
+ /* @__PURE__ */ o(x, {
347
356
  label: "Unit",
348
- children: /* @__PURE__ */ s(d, {
357
+ children: /* @__PURE__ */ o(u, {
349
358
  value: I,
350
359
  onChange: (e) => L(e.target.value),
351
360
  placeholder: "L, kg…"
352
361
  })
353
362
  }),
354
- /* @__PURE__ */ s(S, {
363
+ /* @__PURE__ */ o(x, {
355
364
  label: "Labor (hrs)",
356
- children: /* @__PURE__ */ s(d, {
365
+ children: /* @__PURE__ */ o(u, {
357
366
  type: "number",
358
367
  min: "0",
359
368
  step: "any",
@@ -362,9 +371,9 @@ var b = ({ plan: b, crops: C, onCropChanged: de }) => {
362
371
  placeholder: "e.g. 1.5"
363
372
  })
364
373
  }),
365
- /* @__PURE__ */ s(S, {
374
+ /* @__PURE__ */ o(x, {
366
375
  label: "Notes",
367
- children: /* @__PURE__ */ s(ce, {
376
+ children: /* @__PURE__ */ o(de, {
368
377
  value: B,
369
378
  onChange: (e) => V(e.target.value),
370
379
  rows: 1,
@@ -373,45 +382,45 @@ var b = ({ plan: b, crops: C, onCropChanged: de }) => {
373
382
  })
374
383
  ]
375
384
  }),
376
- /* @__PURE__ */ c("div", {
385
+ /* @__PURE__ */ s("div", {
377
386
  className: "mt-4 flex items-center gap-2",
378
- children: [/* @__PURE__ */ c(l, {
379
- onClick: Se,
387
+ children: [/* @__PURE__ */ s(c, {
388
+ onClick: we,
380
389
  disabled: H,
381
- children: [/* @__PURE__ */ s(o, { className: "h-4 w-4" }), H ? W ? "Saving…" : "Logging…" : W ? "Save changes" : "Log activity"]
382
- }), W && /* @__PURE__ */ c(l, {
390
+ children: [/* @__PURE__ */ o(ie, { className: "h-4 w-4" }), H ? W ? "Saving…" : "Logging…" : W ? "Save changes" : "Log activity"]
391
+ }), W && /* @__PURE__ */ s(c, {
383
392
  variant: "ghost",
384
393
  onClick: K,
385
394
  disabled: H,
386
- children: [/* @__PURE__ */ s(se, { className: "h-4 w-4" }), " Cancel"]
395
+ children: [/* @__PURE__ */ o(ue, { className: "h-4 w-4" }), " Cancel"]
387
396
  })]
388
397
  })
389
398
  ]
390
399
  }),
391
- /* @__PURE__ */ c(u, {
400
+ /* @__PURE__ */ s(l, {
392
401
  treatment: "glass",
393
402
  className: "border-border-seam p-6",
394
403
  children: [
395
- /* @__PURE__ */ c("h3", {
404
+ /* @__PURE__ */ s("h3", {
396
405
  className: "mb-4 flex items-center gap-2 text-sm font-semibold text-text-primary",
397
- children: [/* @__PURE__ */ s(ie, { className: "h-4 w-4 text-info" }), " Harvest & inventory"]
406
+ children: [/* @__PURE__ */ o(a, { className: "h-4 w-4 text-info" }), " Harvest & inventory"]
398
407
  }),
399
- T && T.harvests.length > 0 ? /* @__PURE__ */ s("ul", {
408
+ w && w.harvests.length > 0 ? /* @__PURE__ */ o("ul", {
400
409
  className: "mb-5 space-y-2",
401
- children: T.harvests.map((r) => /* @__PURE__ */ c("li", {
410
+ children: w.harvests.map((r) => /* @__PURE__ */ s("li", {
402
411
  className: "flex items-center justify-between gap-3 rounded-lg border border-border-subtle bg-bg-surface px-3 py-2",
403
- children: [/* @__PURE__ */ c("div", {
412
+ children: [/* @__PURE__ */ s("div", {
404
413
  className: "min-w-0",
405
- children: [/* @__PURE__ */ c("div", {
414
+ children: [/* @__PURE__ */ s("div", {
406
415
  className: "flex items-center gap-2",
407
- children: [/* @__PURE__ */ s("span", {
416
+ children: [/* @__PURE__ */ o("span", {
408
417
  className: "truncate text-sm font-medium text-text-primary",
409
- children: r.cropName || b.cropName
410
- }), /* @__PURE__ */ s(n, {
418
+ children: r.cropName || y.cropName
419
+ }), /* @__PURE__ */ o(n, {
411
420
  label: `Grade ${r.qualityGrade}`,
412
421
  variant: "muted"
413
422
  })]
414
- }), /* @__PURE__ */ c("div", {
423
+ }), /* @__PURE__ */ s("div", {
415
424
  className: "mt-1 text-xs text-text-secondary",
416
425
  children: [
417
426
  t(r.quantity),
@@ -421,114 +430,114 @@ var b = ({ plan: b, crops: C, onCropChanged: de }) => {
421
430
  e(r.harvestDate)
422
431
  ]
423
432
  })]
424
- }), r.productId ? /* @__PURE__ */ c("span", {
433
+ }), r.productId ? /* @__PURE__ */ s("span", {
425
434
  className: "inline-flex items-center gap-1 whitespace-nowrap text-xs font-medium text-status-success-text",
426
- children: [/* @__PURE__ */ s(ne, { className: "h-4 w-4" }), " In inventory"]
427
- }) : /* @__PURE__ */ s(n, {
435
+ children: [/* @__PURE__ */ o(oe, { className: "h-4 w-4" }), " In inventory"]
436
+ }) : /* @__PURE__ */ o(n, {
428
437
  label: r.status,
429
438
  variant: "muted"
430
439
  })]
431
440
  }, r.id))
432
- }) : /* @__PURE__ */ s("p", {
441
+ }) : /* @__PURE__ */ o("p", {
433
442
  className: "mb-5 text-sm text-text-secondary",
434
- children: fe ? "Loading harvests…" : "No harvests recorded against this plan yet."
443
+ children: T ? "Loading harvests…" : "No harvests recorded against this plan yet."
435
444
  }),
436
- /* @__PURE__ */ c("div", {
445
+ /* @__PURE__ */ s("div", {
437
446
  className: "grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3",
438
447
  children: [
439
- /* @__PURE__ */ s(S, {
448
+ /* @__PURE__ */ o(x, {
440
449
  label: "Crop",
441
- children: /* @__PURE__ */ c(f, {
450
+ children: /* @__PURE__ */ s(d, {
442
451
  value: Q,
443
- onValueChange: Te,
444
- children: [/* @__PURE__ */ s(h, {
452
+ onValueChange: De,
453
+ children: [/* @__PURE__ */ o(m, {
445
454
  className: "w-full",
446
- children: /* @__PURE__ */ s(g, { placeholder: "Select crop" })
447
- }), /* @__PURE__ */ s(p, { children: E.map((e) => /* @__PURE__ */ s(m, {
455
+ children: /* @__PURE__ */ o(h, { placeholder: "Select crop" })
456
+ }), /* @__PURE__ */ o(f, { children: E.map((e) => /* @__PURE__ */ o(p, {
448
457
  value: e.id,
449
458
  children: e.variety ? `${e.name} — ${e.variety}` : e.name
450
459
  }, e.id)) })]
451
460
  })
452
461
  }),
453
- /* @__PURE__ */ s(S, {
462
+ /* @__PURE__ */ o(x, {
454
463
  label: "Quantity",
455
- children: /* @__PURE__ */ s(d, {
464
+ children: /* @__PURE__ */ o(u, {
456
465
  type: "number",
457
466
  min: "0",
458
467
  step: "any",
459
- value: Ee,
460
- onChange: (e) => De(e.target.value),
468
+ value: q,
469
+ onChange: (e) => Oe(e.target.value),
461
470
  placeholder: "e.g. 120"
462
471
  })
463
472
  }),
464
- /* @__PURE__ */ s(S, {
473
+ /* @__PURE__ */ o(x, {
465
474
  label: "Unit",
466
- children: /* @__PURE__ */ s(d, {
467
- value: Oe,
468
- onChange: (e) => ke(e.target.value),
475
+ children: /* @__PURE__ */ o(u, {
476
+ value: ke,
477
+ onChange: (e) => Ae(e.target.value),
469
478
  placeholder: "kg"
470
479
  })
471
480
  }),
472
- /* @__PURE__ */ s(S, {
481
+ /* @__PURE__ */ o(x, {
473
482
  label: "Quality",
474
- children: /* @__PURE__ */ c(f, {
475
- value: q,
476
- onValueChange: Ae,
477
- children: [/* @__PURE__ */ s(h, {
483
+ children: /* @__PURE__ */ s(d, {
484
+ value: je,
485
+ onValueChange: Me,
486
+ children: [/* @__PURE__ */ o(m, {
478
487
  className: "w-full",
479
- children: /* @__PURE__ */ s(g, {})
480
- }), /* @__PURE__ */ c(p, { children: [
481
- /* @__PURE__ */ s(m, {
488
+ children: /* @__PURE__ */ o(h, {})
489
+ }), /* @__PURE__ */ s(f, { children: [
490
+ /* @__PURE__ */ o(p, {
482
491
  value: "A",
483
492
  children: "Grade A"
484
493
  }),
485
- /* @__PURE__ */ s(m, {
494
+ /* @__PURE__ */ o(p, {
486
495
  value: "B",
487
496
  children: "Grade B"
488
497
  }),
489
- /* @__PURE__ */ s(m, {
498
+ /* @__PURE__ */ o(p, {
490
499
  value: "C",
491
500
  children: "Grade C"
492
501
  })
493
502
  ] })]
494
503
  })
495
504
  }),
496
- /* @__PURE__ */ s(S, {
505
+ /* @__PURE__ */ o(x, {
497
506
  label: "Harvest date",
498
- children: /* @__PURE__ */ s(d, {
507
+ children: /* @__PURE__ */ o(u, {
499
508
  type: "date",
500
- value: je,
501
- onChange: (e) => Me(e.target.value)
509
+ value: Ne,
510
+ onChange: (e) => Pe(e.target.value)
502
511
  })
503
512
  }),
504
- /* @__PURE__ */ s(S, {
513
+ /* @__PURE__ */ o(x, {
505
514
  label: "Price / unit",
506
- children: /* @__PURE__ */ s(d, {
515
+ children: /* @__PURE__ */ o(u, {
507
516
  type: "number",
508
517
  min: "0",
509
518
  step: "any",
510
519
  value: J,
511
- onChange: (e) => Ne(e.target.value),
520
+ onChange: (e) => Fe(e.target.value),
512
521
  placeholder: "Optional"
513
522
  })
514
523
  })
515
524
  ]
516
525
  }),
517
- /* @__PURE__ */ c("div", {
526
+ /* @__PURE__ */ s("div", {
518
527
  className: "mt-4 flex flex-wrap items-center gap-4",
519
- children: [/* @__PURE__ */ c("label", {
528
+ children: [/* @__PURE__ */ s("label", {
520
529
  className: "flex items-center gap-2 text-sm text-text-primary",
521
- children: [/* @__PURE__ */ s("input", {
530
+ children: [/* @__PURE__ */ o("input", {
522
531
  type: "checkbox",
523
532
  checked: Y,
524
- onChange: (e) => Pe(e.target.checked),
533
+ onChange: (e) => Ie(e.target.checked),
525
534
  className: "h-4 w-4 rounded border-border-subtle"
526
535
  }), "Add harvested quantity to inventory"]
527
- }), /* @__PURE__ */ c(l, {
528
- onClick: Le,
536
+ }), /* @__PURE__ */ s(c, {
537
+ onClick: ze,
529
538
  disabled: X,
530
539
  children: [
531
- /* @__PURE__ */ s(ie, { className: "h-4 w-4" }),
540
+ /* @__PURE__ */ o(a, { className: "h-4 w-4" }),
532
541
  " ",
533
542
  X ? "Recording…" : "Record harvest"
534
543
  ]
@@ -538,23 +547,23 @@ var b = ({ plan: b, crops: C, onCropChanged: de }) => {
538
547
  })
539
548
  ]
540
549
  });
541
- }, x = ({ label: e, value: t, unit: n }) => /* @__PURE__ */ c("div", { children: [/* @__PURE__ */ s("div", {
550
+ }, b = ({ label: e, value: t, unit: n }) => /* @__PURE__ */ s("div", { children: [/* @__PURE__ */ o("div", {
542
551
  className: "text-xs text-text-secondary",
543
552
  children: e
544
- }), /* @__PURE__ */ c("div", {
553
+ }), /* @__PURE__ */ s("div", {
545
554
  className: "mt-1 text-lg font-semibold text-text-primary",
546
- children: [t, n ? /* @__PURE__ */ s("span", {
555
+ children: [t, n ? /* @__PURE__ */ o("span", {
547
556
  className: "ms-1 text-xs font-normal text-text-secondary",
548
557
  children: n
549
558
  }) : null]
550
- })] }), S = ({ label: e, children: t }) => /* @__PURE__ */ c("div", { children: [/* @__PURE__ */ s("label", {
559
+ })] }), x = ({ label: e, children: t }) => /* @__PURE__ */ s("div", { children: [/* @__PURE__ */ o("label", {
551
560
  className: "text-xs font-medium text-text-secondary",
552
561
  children: e
553
- }), /* @__PURE__ */ s("div", {
562
+ }), /* @__PURE__ */ o("div", {
554
563
  className: "mt-1",
555
564
  children: t
556
565
  })] });
557
566
  //#endregion
558
- export { b as PlanExecutionPanel };
567
+ export { y as PlanExecutionPanel };
559
568
 
560
569
  //# sourceMappingURL=PlanExecutionPanel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlanExecutionPanel.js","names":[],"sources":["../../../src/healthybowl/components/PlanExecutionPanel.tsx"],"sourcesContent":["/**\n * Plan-execution panel (roadmap I-7 + I-8).\n *\n * Rendered on the planting-plan detail page. Turns a plan from intent into a\n * tracked execution:\n * • I-7 — set the transplant date and keep a watering/tilling/etc. activity log.\n * • I-8 — record a harvest linked back to this plan (optionally pushed into\n * inventory) and see a live planned-vs-actual yield rollup.\n * @module healthybowl\n */\nimport { useMemo, useState, type FC, type ReactNode } from 'react';\nimport {\n GlassCard,\n Button,\n Input,\n Textarea,\n Select,\n SelectTrigger,\n SelectValue,\n SelectContent,\n SelectItem,\n} from '@burdenoff/fe-libs/ui';\nimport { Activity, Sprout, Target, Trash2, Pencil, X, PackageCheck, CalendarClock } from 'lucide-react';\nimport { StatusBadge } from './';\nimport { useToast } from '../hooks/useToast';\nimport { usePlanExecution, type PlanActivity } from '../hooks/usePlanExecution';\nimport { formatDate, formatNumber } from '../utils/helpers';\nimport type { PlantingPlan, Crop } from '../types';\n\nconst ACTIVITY_TYPES: { value: string; label: string }[] = [\n { value: 'WATERING', label: 'Watering' },\n { value: 'TILLING', label: 'Tilling' },\n { value: 'FERTILIZING', label: 'Fertilizing' },\n { value: 'WEEDING', label: 'Weeding' },\n { value: 'TRANSPLANT', label: 'Transplant' },\n { value: 'SCOUTING', label: 'Scouting' },\n { value: 'MULCHING', label: 'Mulching' },\n { value: 'PEST_CONTROL', label: 'Pest control' },\n { value: 'THINNING', label: 'Thinning' },\n { value: 'OTHER', label: 'Other' },\n];\n\nconst activityLabel = (value: string) => ACTIVITY_TYPES.find((a) => a.value === value)?.label ?? value;\n\nconst todayIso = () => new Date().toISOString().slice(0, 10);\n\nconst parsePositive = (value: string): number | null => {\n const n = Number(value);\n return Number.isFinite(n) && n > 0 ? n : null;\n};\n\n// BOFF-6094 — mirrors the `uid()` fallback already used by the offline sync layer\n// (syncEngine.ts / OfflineSyncProvider.tsx): crypto.randomUUID requires a secure\n// context, so this degrades to a timestamp+random string rather than throwing.\nfunction newClientMutationId(): string {\n return typeof crypto !== 'undefined' && crypto.randomUUID\n ? crypto.randomUUID()\n : `hb-harvest-${Date.now()}-${Math.round(Math.random() * 1e9)}`;\n}\n\ninterface PlanExecutionPanelProps {\n plan: PlantingPlan;\n crops: Crop[];\n /**\n * Called after an activity that can move the linked crop's stage (a TRANSPLANT). The panel\n * refetches its own plan rollup, but the crop lives on the parent page's data (BOFF-6099).\n */\n onCropChanged?: () => void;\n}\n\nexport const PlanExecutionPanel: FC<PlanExecutionPanelProps> = ({ plan, crops, onCropChanged }) => {\n const { toast } = useToast();\n const { execution, loading, setTransplantDate, addActivity, updateActivity, deleteActivity, recordHarvest } =\n usePlanExecution(plan.id);\n\n // Crops that live on this plan's field, for the harvest crop selector.\n const fieldCrops = useMemo(() => {\n const scoped = crops.filter((c) => !plan.fieldId || c.field === plan.fieldId);\n return scoped.length > 0 ? scoped : crops;\n }, [crops, plan.fieldId]);\n\n const defaultCropId = useMemo(() => {\n const byName = fieldCrops.find((c) => c.name === plan.cropName);\n return byName?.id ?? fieldCrops[0]?.id ?? '';\n }, [fieldCrops, plan.cropName]);\n\n // ── Transplant ──────────────────────────────────────────────────────────\n const [transplantInput, setTransplantInput] = useState('');\n const [savingTransplant, setSavingTransplant] = useState(false);\n\n const handleSetTransplant = async () => {\n if (!transplantInput) return;\n setSavingTransplant(true);\n try {\n await setTransplantDate(transplantInput);\n toast({ title: 'Transplant date set', variant: 'success' });\n setTransplantInput('');\n } catch {\n toast({ title: 'Could not set transplant date', variant: 'error' });\n } finally {\n setSavingTransplant(false);\n }\n };\n\n // ── Activity log ──────────────────────────────────────────────────────────\n const [actType, setActType] = useState('WATERING');\n const [actDate, setActDate] = useState(todayIso());\n const [actQuantity, setActQuantity] = useState('');\n const [actUnit, setActUnit] = useState('');\n const [actLabor, setActLabor] = useState('');\n const [actNotes, setActNotes] = useState('');\n const [loggingActivity, setLoggingActivity] = useState(false);\n /** Id of the row being edited; null means the form is logging a NEW activity (BOFF-6099). */\n const [editingId, setEditingId] = useState<string | null>(null);\n\n const resetActivityForm = () => {\n setEditingId(null);\n setActType('WATERING');\n setActDate(todayIso());\n setActQuantity('');\n setActUnit('');\n setActLabor('');\n setActNotes('');\n };\n\n /** Load a logged row back into the shared form so it can be corrected in place. */\n const startEditActivity = (activity: PlanActivity) => {\n setEditingId(activity.id);\n setActType(activity.type);\n // activityDate arrives as an ISO timestamp; <input type=\"date\"> needs bare YYYY-MM-DD.\n setActDate((activity.activityDate ?? '').slice(0, 10));\n setActQuantity(activity.quantity == null ? '' : String(activity.quantity));\n setActUnit(activity.unit ?? '');\n setActLabor(activity.laborHours == null ? '' : String(activity.laborHours));\n setActNotes(activity.notes ?? '');\n };\n\n const handleLogActivity = async () => {\n if (!actDate) {\n toast({ title: 'Pick an activity date', variant: 'error' });\n return;\n }\n setLoggingActivity(true);\n const payload = {\n type: actType,\n activityDate: actDate,\n quantity: actQuantity ? Number(actQuantity) : null,\n unit: actUnit.trim() || null,\n laborHours: actLabor ? Number(actLabor) : null,\n notes: actNotes.trim() || null,\n };\n try {\n if (editingId) {\n await updateActivity(editingId, payload);\n toast({ title: 'Activity updated', variant: 'success' });\n } else {\n await addActivity(payload);\n toast({ title: 'Activity logged', variant: 'success' });\n }\n // Editing into a TRANSPLANT advances the linked crop server-side, so tell the page to\n // refresh the crop it holds — the panel's own refetch only covers the plan rollup.\n if (actType === 'TRANSPLANT') {\n onCropChanged?.();\n }\n resetActivityForm();\n } catch {\n toast({ title: editingId ? 'Could not update activity' : 'Could not log activity', variant: 'error' });\n } finally {\n setLoggingActivity(false);\n }\n };\n\n const handleDeleteActivity = async (id: string) => {\n try {\n await deleteActivity(id);\n if (editingId === id) {\n resetActivityForm();\n }\n toast({ title: 'Activity removed', variant: 'success' });\n } catch {\n toast({ title: 'Could not remove activity', variant: 'error' });\n }\n };\n\n // ── Harvest → inventory ─────────────────────────────────────────────────\n const [harvestCropId, setHarvestCropId] = useState('');\n const [harvestQty, setHarvestQty] = useState('');\n const [harvestUnit, setHarvestUnit] = useState('kg');\n const [harvestQuality, setHarvestQuality] = useState('A');\n const [harvestDate, setHarvestDate] = useState(todayIso());\n const [harvestPrice, setHarvestPrice] = useState('');\n const [addToInventory, setAddToInventory] = useState(true);\n const [recording, setRecording] = useState(false);\n // BOFF-6094 — one idempotency key per harvest-recording attempt, minted on mount and re-minted\n // only after a successful submit. `disabled={recording}` on the button (below) covers the normal\n // double-click case; this key is the backstop for a network-level retry of the SAME click, which\n // `recording` alone cannot catch.\n const [harvestClientMutationId, setHarvestClientMutationId] = useState(() => newClientMutationId());\n\n const effectiveCropId = harvestCropId || defaultCropId;\n\n const handleRecordHarvest = async () => {\n const qty = parsePositive(harvestQty);\n if (!effectiveCropId) {\n toast({ title: 'Add a crop on this field first', variant: 'error' });\n return;\n }\n if (!plan.fieldId) {\n toast({ title: 'This plan has no field', variant: 'error' });\n return;\n }\n if (qty == null) {\n toast({ title: 'Enter a harvest quantity', variant: 'error' });\n return;\n }\n if (recording) return;\n setRecording(true);\n try {\n await recordHarvest({\n cropId: effectiveCropId,\n fieldId: plan.fieldId,\n quantity: qty,\n unit: harvestUnit.trim() || 'kg',\n quality: harvestQuality,\n harvestDate,\n pricePerUnit: harvestPrice ? Number(harvestPrice) : null,\n addToInventory,\n clientMutationId: harvestClientMutationId,\n });\n toast({\n title: addToInventory ? 'Harvest recorded & added to inventory' : 'Harvest recorded',\n variant: 'success',\n });\n setHarvestQty('');\n setHarvestPrice('');\n // Next submit records a NEW harvest, so it needs its own key.\n setHarvestClientMutationId(newClientMutationId());\n } catch {\n toast({ title: 'Could not record harvest', variant: 'error' });\n } finally {\n setRecording(false);\n }\n };\n\n const variance = execution?.yieldVariancePct;\n const varianceLabel = variance == null ? '—' : `${variance > 0 ? '+' : ''}${formatNumber(Math.round(variance))}%`;\n const varianceVariant = variance == null ? 'muted' : variance >= 0 ? 'success' : 'warning';\n\n return (\n <div className=\"space-y-6\" data-testid=\"plan-execution-panel\">\n {/* ── Execution & yield ─────────────────────────────────────────── */}\n <GlassCard treatment=\"glass\" glow className=\"border-border-seam p-6\">\n <h3 className=\"mb-4 flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <Target className=\"h-4 w-4 text-info\" /> Execution &amp; yield\n </h3>\n <div className=\"grid grid-cols-2 gap-4 md:grid-cols-4\">\n <ExecMetric\n label=\"Planned yield\"\n value={formatNumber(execution?.plannedYield ?? plan.expectedYield ?? 0)}\n unit=\"kg\"\n />\n <ExecMetric label=\"Actual yield\" value={formatNumber(execution?.actualYield ?? 0)} unit=\"kg\" />\n <div>\n <div className=\"text-xs text-text-secondary\">Variance</div>\n <div className=\"mt-1\">\n <StatusBadge label={varianceLabel} variant={varianceVariant} />\n </div>\n </div>\n <ExecMetric label=\"Harvests\" value={formatNumber(execution?.harvestCount ?? 0)} />\n </div>\n\n <div className=\"mt-5 grid grid-cols-1 gap-4 border-t border-border-subtle pt-4 sm:grid-cols-2\">\n <div>\n <div className=\"flex items-center gap-1 text-xs text-text-secondary\">\n <CalendarClock className=\"h-3.5 w-3.5\" /> Transplant date\n </div>\n <div className=\"mt-1 text-sm font-medium text-text-primary\">\n {execution?.transplantDate ? formatDate(execution.transplantDate) : 'Not set'}\n </div>\n <div className=\"mt-2 flex items-center gap-2\">\n <Input\n type=\"date\"\n value={transplantInput}\n onChange={(e) => setTransplantInput(e.target.value)}\n className=\"h-9 w-44\"\n aria-label=\"Transplant date\"\n />\n <Button\n size=\"sm\"\n variant=\"outline\"\n onClick={handleSetTransplant}\n disabled={!transplantInput || savingTransplant}\n >\n {execution?.transplantDate ? 'Update' : 'Set'}\n </Button>\n </div>\n </div>\n <div>\n <div className=\"text-xs text-text-secondary\">Sow / nursery date</div>\n <div className=\"mt-1 text-sm font-medium text-text-primary\">\n {execution?.sowDate ? formatDate(execution.sowDate) : '—'}\n </div>\n </div>\n </div>\n </GlassCard>\n\n {/* ── Activity log (I-7) ────────────────────────────────────────── */}\n <GlassCard treatment=\"glass\" className=\"border-border-seam p-6\">\n <h3 className=\"mb-4 flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <Activity className=\"h-4 w-4 text-info\" /> Activity log\n </h3>\n\n {execution && execution.activities.length > 0 ? (\n <ul className=\"mb-5 space-y-2\">\n {execution.activities.map((a) => (\n <li\n key={a.id}\n className=\"flex items-center justify-between gap-3 rounded-lg border border-border-subtle bg-bg-surface px-3 py-2\"\n >\n <div className=\"min-w-0\">\n <div className=\"flex items-center gap-2\">\n <StatusBadge label={activityLabel(a.type)} variant=\"info\" />\n <span className=\"text-xs text-text-secondary\">{formatDate(a.activityDate)}</span>\n </div>\n <div className=\"mt-1 truncate text-xs text-text-secondary\">\n {[\n a.quantity != null ? `${formatNumber(a.quantity)}${a.unit ? ` ${a.unit}` : ''}` : null,\n a.laborHours != null ? `${formatNumber(a.laborHours)} h labor` : null,\n a.notes,\n ]\n .filter(Boolean)\n .join(' · ') || '—'}\n </div>\n </div>\n <div className=\"flex shrink-0 items-center gap-1\">\n <Button size=\"sm\" variant=\"ghost\" onClick={() => startEditActivity(a)} aria-label=\"Edit activity\">\n <Pencil className=\"h-4 w-4 text-text-secondary\" />\n </Button>\n <Button\n size=\"sm\"\n variant=\"ghost\"\n onClick={() => handleDeleteActivity(a.id)}\n aria-label=\"Remove activity\"\n >\n <Trash2 className=\"h-4 w-4 text-text-secondary\" />\n </Button>\n </div>\n </li>\n ))}\n </ul>\n ) : (\n <p className=\"mb-5 text-sm text-text-secondary\">\n {loading\n ? 'Loading activities…'\n : 'No activities logged yet. Record watering, tilling and field work below.'}\n </p>\n )}\n\n <div className=\"grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3\">\n <LabeledField label=\"Type\">\n <Select value={actType} onValueChange={setActType}>\n <SelectTrigger className=\"w-full\">\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n {ACTIVITY_TYPES.map((a) => (\n <SelectItem key={a.value} value={a.value}>\n {a.label}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </LabeledField>\n <LabeledField label=\"Date\">\n <Input type=\"date\" value={actDate} onChange={(e) => setActDate(e.target.value)} />\n </LabeledField>\n <LabeledField label=\"Quantity\">\n <Input\n type=\"number\"\n min=\"0\"\n step=\"any\"\n value={actQuantity}\n onChange={(e) => setActQuantity(e.target.value)}\n placeholder=\"e.g. 20\"\n />\n </LabeledField>\n <LabeledField label=\"Unit\">\n <Input value={actUnit} onChange={(e) => setActUnit(e.target.value)} placeholder=\"L, kg…\" />\n </LabeledField>\n <LabeledField label=\"Labor (hrs)\">\n <Input\n type=\"number\"\n min=\"0\"\n step=\"any\"\n value={actLabor}\n onChange={(e) => setActLabor(e.target.value)}\n placeholder=\"e.g. 1.5\"\n />\n </LabeledField>\n <LabeledField label=\"Notes\">\n <Textarea value={actNotes} onChange={(e) => setActNotes(e.target.value)} rows={1} placeholder=\"Optional\" />\n </LabeledField>\n </div>\n <div className=\"mt-4 flex items-center gap-2\">\n <Button onClick={handleLogActivity} disabled={loggingActivity}>\n <Activity className=\"h-4 w-4\" />\n {loggingActivity ? (editingId ? 'Saving…' : 'Logging…') : editingId ? 'Save changes' : 'Log activity'}\n </Button>\n {editingId && (\n <Button variant=\"ghost\" onClick={resetActivityForm} disabled={loggingActivity}>\n <X className=\"h-4 w-4\" /> Cancel\n </Button>\n )}\n </div>\n </GlassCard>\n\n {/* ── Harvest → inventory (I-8) ─────────────────────────────────── */}\n <GlassCard treatment=\"glass\" className=\"border-border-seam p-6\">\n <h3 className=\"mb-4 flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <Sprout className=\"h-4 w-4 text-info\" /> Harvest &amp; inventory\n </h3>\n\n {execution && execution.harvests.length > 0 ? (\n <ul className=\"mb-5 space-y-2\">\n {execution.harvests.map((h) => (\n <li\n key={h.id}\n className=\"flex items-center justify-between gap-3 rounded-lg border border-border-subtle bg-bg-surface px-3 py-2\"\n >\n <div className=\"min-w-0\">\n <div className=\"flex items-center gap-2\">\n <span className=\"truncate text-sm font-medium text-text-primary\">\n {h.cropName || plan.cropName}\n </span>\n <StatusBadge label={`Grade ${h.qualityGrade}`} variant=\"muted\" />\n </div>\n <div className=\"mt-1 text-xs text-text-secondary\">\n {formatNumber(h.quantity)} {h.unit} · {formatDate(h.harvestDate)}\n </div>\n </div>\n {h.productId ? (\n <span className=\"inline-flex items-center gap-1 whitespace-nowrap text-xs font-medium text-status-success-text\">\n <PackageCheck className=\"h-4 w-4\" /> In inventory\n </span>\n ) : (\n <StatusBadge label={h.status} variant=\"muted\" />\n )}\n </li>\n ))}\n </ul>\n ) : (\n <p className=\"mb-5 text-sm text-text-secondary\">\n {loading ? 'Loading harvests…' : 'No harvests recorded against this plan yet.'}\n </p>\n )}\n\n <div className=\"grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3\">\n <LabeledField label=\"Crop\">\n <Select value={effectiveCropId} onValueChange={setHarvestCropId}>\n <SelectTrigger className=\"w-full\">\n <SelectValue placeholder=\"Select crop\" />\n </SelectTrigger>\n <SelectContent>\n {fieldCrops.map((c) => (\n <SelectItem key={c.id} value={c.id}>\n {c.variety ? `${c.name} — ${c.variety}` : c.name}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </LabeledField>\n <LabeledField label=\"Quantity\">\n <Input\n type=\"number\"\n min=\"0\"\n step=\"any\"\n value={harvestQty}\n onChange={(e) => setHarvestQty(e.target.value)}\n placeholder=\"e.g. 120\"\n />\n </LabeledField>\n <LabeledField label=\"Unit\">\n <Input value={harvestUnit} onChange={(e) => setHarvestUnit(e.target.value)} placeholder=\"kg\" />\n </LabeledField>\n <LabeledField label=\"Quality\">\n <Select value={harvestQuality} onValueChange={setHarvestQuality}>\n <SelectTrigger className=\"w-full\">\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n <SelectItem value=\"A\">Grade A</SelectItem>\n <SelectItem value=\"B\">Grade B</SelectItem>\n <SelectItem value=\"C\">Grade C</SelectItem>\n </SelectContent>\n </Select>\n </LabeledField>\n <LabeledField label=\"Harvest date\">\n <Input type=\"date\" value={harvestDate} onChange={(e) => setHarvestDate(e.target.value)} />\n </LabeledField>\n <LabeledField label=\"Price / unit\">\n <Input\n type=\"number\"\n min=\"0\"\n step=\"any\"\n value={harvestPrice}\n onChange={(e) => setHarvestPrice(e.target.value)}\n placeholder=\"Optional\"\n />\n </LabeledField>\n </div>\n <div className=\"mt-4 flex flex-wrap items-center gap-4\">\n <label className=\"flex items-center gap-2 text-sm text-text-primary\">\n <input\n type=\"checkbox\"\n checked={addToInventory}\n onChange={(e) => setAddToInventory(e.target.checked)}\n className=\"h-4 w-4 rounded border-border-subtle\"\n />\n Add harvested quantity to inventory\n </label>\n <Button onClick={handleRecordHarvest} disabled={recording}>\n <Sprout className=\"h-4 w-4\" /> {recording ? 'Recording…' : 'Record harvest'}\n </Button>\n </div>\n </GlassCard>\n </div>\n );\n};\n\nconst ExecMetric: FC<{ label: string; value: string; unit?: string }> = ({ label, value, unit }) => (\n <div>\n <div className=\"text-xs text-text-secondary\">{label}</div>\n <div className=\"mt-1 text-lg font-semibold text-text-primary\">\n {value}\n {unit ? <span className=\"ms-1 text-xs font-normal text-text-secondary\">{unit}</span> : null}\n </div>\n </div>\n);\n\nconst LabeledField: FC<{ label: string; children: ReactNode }> = ({ label, children }) => (\n <div>\n <label className=\"text-xs font-medium text-text-secondary\">{label}</label>\n <div className=\"mt-1\">{children}</div>\n </div>\n);\n"],"mappings":";;;;;;;;;;AA6BA,IAAM,IAAqD;CACzD;EAAE,OAAO;EAAY,OAAO;EAAY;CACxC;EAAE,OAAO;EAAW,OAAO;EAAW;CACtC;EAAE,OAAO;EAAe,OAAO;EAAe;CAC9C;EAAE,OAAO;EAAW,OAAO;EAAW;CACtC;EAAE,OAAO;EAAc,OAAO;EAAc;CAC5C;EAAE,OAAO;EAAY,OAAO;EAAY;CACxC;EAAE,OAAO;EAAY,OAAO;EAAY;CACxC;EAAE,OAAO;EAAgB,OAAO;EAAgB;CAChD;EAAE,OAAO;EAAY,OAAO;EAAY;CACxC;EAAE,OAAO;EAAS,OAAO;EAAS;CACnC,EAEK,MAAiB,MAAkB,EAAe,MAAM,MAAM,EAAE,UAAU,EAAM,EAAE,SAAS,GAE3F,2BAAiB,IAAI,MAAM,EAAC,aAAa,CAAC,MAAM,GAAG,GAAG,EAEtD,MAAiB,MAAiC;CACtD,IAAM,IAAI,OAAO,EAAM;AACvB,QAAO,OAAO,SAAS,EAAE,IAAI,IAAI,IAAI,I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tsx"],"sourcesContent":["/**\n * Plan-execution panel (roadmap I-7 + I-8).\n *\n * Rendered on the planting-plan detail page. Turns a plan from intent into a\n * tracked execution:\n * • I-7 — set the transplant date and keep a watering/tilling/etc. activity log.\n * • I-8 — record a harvest linked back to this plan (optionally pushed into\n * inventory) and see a live planned-vs-actual yield rollup.\n * @module healthybowl\n */\nimport { useMemo, useState, type FC, type ReactNode } from 'react';\nimport {\n GlassCard,\n Button,\n Input,\n Textarea,\n Select,\n SelectTrigger,\n SelectValue,\n SelectContent,\n SelectItem,\n} from '@burdenoff/fe-libs/ui';\nimport { Activity, Sprout, Target, Trash2, Pencil, X, PackageCheck, CalendarClock } from 'lucide-react';\nimport { StatusBadge } from './';\nimport { useToast } from '../hooks/useToast';\nimport { usePlanExecution, type PlanActivity } from '../hooks/usePlanExecution';\nimport { toFormFields, toActivityPayload } from '../utils/planActivityForm';\nimport { formatDate, formatNumber } from '../utils/helpers';\nimport type { PlantingPlan, Crop } from '../types';\n\nconst ACTIVITY_TYPES: { value: string; label: string }[] = [\n { value: 'WATERING', label: 'Watering' },\n { value: 'TILLING', label: 'Tilling' },\n { value: 'FERTILIZING', label: 'Fertilizing' },\n { value: 'WEEDING', label: 'Weeding' },\n { value: 'TRANSPLANT', label: 'Transplant' },\n { value: 'SCOUTING', label: 'Scouting' },\n { value: 'MULCHING', label: 'Mulching' },\n { value: 'PEST_CONTROL', label: 'Pest control' },\n { value: 'THINNING', label: 'Thinning' },\n { value: 'OTHER', label: 'Other' },\n];\n\nconst activityLabel = (value: string) => ACTIVITY_TYPES.find((a) => a.value === value)?.label ?? value;\n\nconst todayIso = () => new Date().toISOString().slice(0, 10);\n\nconst parsePositive = (value: string): number | null => {\n const n = Number(value);\n return Number.isFinite(n) && n > 0 ? n : null;\n};\n\n// BOFF-6094 — mirrors the `uid()` fallback already used by the offline sync layer\n// (syncEngine.ts / OfflineSyncProvider.tsx): crypto.randomUUID requires a secure\n// context, so this degrades to a timestamp+random string rather than throwing.\nfunction newClientMutationId(): string {\n return typeof crypto !== 'undefined' && crypto.randomUUID\n ? crypto.randomUUID()\n : `hb-harvest-${Date.now()}-${Math.round(Math.random() * 1e9)}`;\n}\n\ninterface PlanExecutionPanelProps {\n plan: PlantingPlan;\n crops: Crop[];\n /**\n * Called after an activity that can move the linked crop's stage (a TRANSPLANT). The panel\n * refetches its own plan rollup, but the crop lives on the parent page's data (BOFF-6099).\n */\n onCropChanged?: () => void;\n}\n\nexport const PlanExecutionPanel: FC<PlanExecutionPanelProps> = ({ plan, crops, onCropChanged }) => {\n const { toast } = useToast();\n const { execution, loading, setTransplantDate, addActivity, updateActivity, deleteActivity, recordHarvest } =\n usePlanExecution(plan.id);\n\n // Crops that live on this plan's field, for the harvest crop selector.\n const fieldCrops = useMemo(() => {\n const scoped = crops.filter((c) => !plan.fieldId || c.field === plan.fieldId);\n return scoped.length > 0 ? scoped : crops;\n }, [crops, plan.fieldId]);\n\n const defaultCropId = useMemo(() => {\n const byName = fieldCrops.find((c) => c.name === plan.cropName);\n return byName?.id ?? fieldCrops[0]?.id ?? '';\n }, [fieldCrops, plan.cropName]);\n\n // ── Transplant ──────────────────────────────────────────────────────────\n const [transplantInput, setTransplantInput] = useState('');\n const [savingTransplant, setSavingTransplant] = useState(false);\n\n const handleSetTransplant = async () => {\n if (!transplantInput) return;\n setSavingTransplant(true);\n try {\n await setTransplantDate(transplantInput);\n toast({ title: 'Transplant date set', variant: 'success' });\n setTransplantInput('');\n } catch {\n toast({ title: 'Could not set transplant date', variant: 'error' });\n } finally {\n setSavingTransplant(false);\n }\n };\n\n // ── Activity log ──────────────────────────────────────────────────────────\n const [actType, setActType] = useState('WATERING');\n const [actDate, setActDate] = useState(todayIso());\n const [actQuantity, setActQuantity] = useState('');\n const [actUnit, setActUnit] = useState('');\n const [actLabor, setActLabor] = useState('');\n const [actNotes, setActNotes] = useState('');\n const [loggingActivity, setLoggingActivity] = useState(false);\n /** Id of the row being edited; null means the form is logging a NEW activity (BOFF-6099). */\n const [editingId, setEditingId] = useState<string | null>(null);\n\n const resetActivityForm = () => {\n setEditingId(null);\n setActType('WATERING');\n setActDate(todayIso());\n setActQuantity('');\n setActUnit('');\n setActLabor('');\n setActNotes('');\n };\n\n /** Load a logged row back into the shared form so it can be corrected in place. */\n const startEditActivity = (activity: PlanActivity) => {\n const f = toFormFields(activity);\n setEditingId(activity.id);\n setActType(f.type);\n setActDate(f.date);\n setActQuantity(f.quantity);\n setActUnit(f.unit);\n setActLabor(f.labor);\n setActNotes(f.notes);\n };\n\n const handleLogActivity = async () => {\n if (!actDate) {\n toast({ title: 'Pick an activity date', variant: 'error' });\n return;\n }\n setLoggingActivity(true);\n const payload = toActivityPayload({\n type: actType,\n date: actDate,\n quantity: actQuantity,\n unit: actUnit,\n labor: actLabor,\n notes: actNotes,\n });\n try {\n if (editingId) {\n await updateActivity(editingId, payload);\n toast({ title: 'Activity updated', variant: 'success' });\n } else {\n await addActivity(payload);\n toast({ title: 'Activity logged', variant: 'success' });\n }\n // Editing into a TRANSPLANT advances the linked crop server-side, so tell the page to\n // refresh the crop it holds — the panel's own refetch only covers the plan rollup.\n if (actType === 'TRANSPLANT') {\n onCropChanged?.();\n }\n resetActivityForm();\n } catch {\n toast({ title: editingId ? 'Could not update activity' : 'Could not log activity', variant: 'error' });\n } finally {\n setLoggingActivity(false);\n }\n };\n\n const handleDeleteActivity = async (id: string) => {\n try {\n await deleteActivity(id);\n if (editingId === id) {\n resetActivityForm();\n }\n toast({ title: 'Activity removed', variant: 'success' });\n } catch {\n toast({ title: 'Could not remove activity', variant: 'error' });\n }\n };\n\n // ── Harvest → inventory ─────────────────────────────────────────────────\n const [harvestCropId, setHarvestCropId] = useState('');\n const [harvestQty, setHarvestQty] = useState('');\n const [harvestUnit, setHarvestUnit] = useState('kg');\n const [harvestQuality, setHarvestQuality] = useState('A');\n const [harvestDate, setHarvestDate] = useState(todayIso());\n const [harvestPrice, setHarvestPrice] = useState('');\n const [addToInventory, setAddToInventory] = useState(true);\n const [recording, setRecording] = useState(false);\n // BOFF-6094 — one idempotency key per harvest-recording attempt, minted on mount and re-minted\n // only after a successful submit. `disabled={recording}` on the button (below) covers the normal\n // double-click case; this key is the backstop for a network-level retry of the SAME click, which\n // `recording` alone cannot catch.\n const [harvestClientMutationId, setHarvestClientMutationId] = useState(() => newClientMutationId());\n\n const effectiveCropId = harvestCropId || defaultCropId;\n\n const handleRecordHarvest = async () => {\n const qty = parsePositive(harvestQty);\n if (!effectiveCropId) {\n toast({ title: 'Add a crop on this field first', variant: 'error' });\n return;\n }\n if (!plan.fieldId) {\n toast({ title: 'This plan has no field', variant: 'error' });\n return;\n }\n if (qty == null) {\n toast({ title: 'Enter a harvest quantity', variant: 'error' });\n return;\n }\n if (recording) return;\n setRecording(true);\n try {\n await recordHarvest({\n cropId: effectiveCropId,\n fieldId: plan.fieldId,\n quantity: qty,\n unit: harvestUnit.trim() || 'kg',\n quality: harvestQuality,\n harvestDate,\n pricePerUnit: harvestPrice ? Number(harvestPrice) : null,\n addToInventory,\n clientMutationId: harvestClientMutationId,\n });\n toast({\n title: addToInventory ? 'Harvest recorded & added to inventory' : 'Harvest recorded',\n variant: 'success',\n });\n setHarvestQty('');\n setHarvestPrice('');\n // Next submit records a NEW harvest, so it needs its own key.\n setHarvestClientMutationId(newClientMutationId());\n } catch {\n toast({ title: 'Could not record harvest', variant: 'error' });\n } finally {\n setRecording(false);\n }\n };\n\n const variance = execution?.yieldVariancePct;\n const varianceLabel = variance == null ? '—' : `${variance > 0 ? '+' : ''}${formatNumber(Math.round(variance))}%`;\n const varianceVariant = variance == null ? 'muted' : variance >= 0 ? 'success' : 'warning';\n\n return (\n <div className=\"space-y-6\" data-testid=\"plan-execution-panel\">\n {/* ── Execution & yield ─────────────────────────────────────────── */}\n <GlassCard treatment=\"glass\" glow className=\"border-border-seam p-6\">\n <h3 className=\"mb-4 flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <Target className=\"h-4 w-4 text-info\" /> Execution &amp; yield\n </h3>\n <div className=\"grid grid-cols-2 gap-4 md:grid-cols-4\">\n <ExecMetric\n label=\"Planned yield\"\n value={formatNumber(execution?.plannedYield ?? plan.expectedYield ?? 0)}\n unit=\"kg\"\n />\n <ExecMetric label=\"Actual yield\" value={formatNumber(execution?.actualYield ?? 0)} unit=\"kg\" />\n <div>\n <div className=\"text-xs text-text-secondary\">Variance</div>\n <div className=\"mt-1\">\n <StatusBadge label={varianceLabel} variant={varianceVariant} />\n </div>\n </div>\n <ExecMetric label=\"Harvests\" value={formatNumber(execution?.harvestCount ?? 0)} />\n </div>\n\n <div className=\"mt-5 grid grid-cols-1 gap-4 border-t border-border-subtle pt-4 sm:grid-cols-2\">\n <div>\n <div className=\"flex items-center gap-1 text-xs text-text-secondary\">\n <CalendarClock className=\"h-3.5 w-3.5\" /> Transplant date\n </div>\n <div className=\"mt-1 text-sm font-medium text-text-primary\">\n {execution?.transplantDate ? formatDate(execution.transplantDate) : 'Not set'}\n </div>\n <div className=\"mt-2 flex items-center gap-2\">\n <Input\n type=\"date\"\n value={transplantInput}\n onChange={(e) => setTransplantInput(e.target.value)}\n className=\"h-9 w-44\"\n aria-label=\"Transplant date\"\n />\n <Button\n size=\"sm\"\n variant=\"outline\"\n onClick={handleSetTransplant}\n disabled={!transplantInput || savingTransplant}\n >\n {execution?.transplantDate ? 'Update' : 'Set'}\n </Button>\n </div>\n </div>\n <div>\n <div className=\"text-xs text-text-secondary\">Sow / nursery date</div>\n <div className=\"mt-1 text-sm font-medium text-text-primary\">\n {execution?.sowDate ? formatDate(execution.sowDate) : '—'}\n </div>\n </div>\n </div>\n </GlassCard>\n\n {/* ── Activity log (I-7) ────────────────────────────────────────── */}\n <GlassCard treatment=\"glass\" className=\"border-border-seam p-6\">\n <h3 className=\"mb-4 flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <Activity className=\"h-4 w-4 text-info\" /> Activity log\n </h3>\n\n {execution && execution.activities.length > 0 ? (\n <ul className=\"mb-5 space-y-2\">\n {execution.activities.map((a) => (\n <li\n key={a.id}\n className={`flex items-center justify-between gap-3 rounded-lg border px-3 py-2 ${\n editingId === a.id ? 'border-primary bg-primary/5' : 'border-border-subtle bg-bg-surface'\n }`}\n >\n <div className=\"min-w-0\">\n <div className=\"flex items-center gap-2\">\n <StatusBadge label={activityLabel(a.type)} variant=\"info\" />\n <span className=\"text-xs text-text-secondary\">{formatDate(a.activityDate)}</span>\n </div>\n <div className=\"mt-1 truncate text-xs text-text-secondary\">\n {[\n a.quantity != null ? `${formatNumber(a.quantity)}${a.unit ? ` ${a.unit}` : ''}` : null,\n a.laborHours != null ? `${formatNumber(a.laborHours)} h labor` : null,\n a.notes,\n ]\n .filter(Boolean)\n .join(' · ') || '—'}\n </div>\n </div>\n <div className=\"flex shrink-0 items-center gap-1\">\n {editingId === a.id && <span className=\"mr-1 text-xs font-medium text-primary\">Editing</span>}\n <Button size=\"sm\" variant=\"ghost\" onClick={() => startEditActivity(a)} aria-label=\"Edit activity\">\n <Pencil className=\"h-4 w-4 text-text-secondary\" />\n </Button>\n <Button\n size=\"sm\"\n variant=\"ghost\"\n onClick={() => handleDeleteActivity(a.id)}\n aria-label=\"Remove activity\"\n >\n <Trash2 className=\"h-4 w-4 text-text-secondary\" />\n </Button>\n </div>\n </li>\n ))}\n </ul>\n ) : (\n <p className=\"mb-5 text-sm text-text-secondary\">\n {loading\n ? 'Loading activities…'\n : 'No activities logged yet. Record watering, tilling and field work below.'}\n </p>\n )}\n\n <div className=\"grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3\">\n <LabeledField label=\"Type\">\n <Select value={actType} onValueChange={setActType}>\n <SelectTrigger className=\"w-full\">\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n {ACTIVITY_TYPES.map((a) => (\n <SelectItem key={a.value} value={a.value}>\n {a.label}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </LabeledField>\n <LabeledField label=\"Date\">\n <Input type=\"date\" value={actDate} onChange={(e) => setActDate(e.target.value)} />\n </LabeledField>\n <LabeledField label=\"Quantity\">\n <Input\n type=\"number\"\n min=\"0\"\n step=\"any\"\n value={actQuantity}\n onChange={(e) => setActQuantity(e.target.value)}\n placeholder=\"e.g. 20\"\n />\n </LabeledField>\n <LabeledField label=\"Unit\">\n <Input value={actUnit} onChange={(e) => setActUnit(e.target.value)} placeholder=\"L, kg…\" />\n </LabeledField>\n <LabeledField label=\"Labor (hrs)\">\n <Input\n type=\"number\"\n min=\"0\"\n step=\"any\"\n value={actLabor}\n onChange={(e) => setActLabor(e.target.value)}\n placeholder=\"e.g. 1.5\"\n />\n </LabeledField>\n <LabeledField label=\"Notes\">\n <Textarea value={actNotes} onChange={(e) => setActNotes(e.target.value)} rows={1} placeholder=\"Optional\" />\n </LabeledField>\n </div>\n <div className=\"mt-4 flex items-center gap-2\">\n <Button onClick={handleLogActivity} disabled={loggingActivity}>\n <Activity className=\"h-4 w-4\" />\n {loggingActivity ? (editingId ? 'Saving…' : 'Logging…') : editingId ? 'Save changes' : 'Log activity'}\n </Button>\n {editingId && (\n <Button variant=\"ghost\" onClick={resetActivityForm} disabled={loggingActivity}>\n <X className=\"h-4 w-4\" /> Cancel\n </Button>\n )}\n </div>\n </GlassCard>\n\n {/* ── Harvest → inventory (I-8) ─────────────────────────────────── */}\n <GlassCard treatment=\"glass\" className=\"border-border-seam p-6\">\n <h3 className=\"mb-4 flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <Sprout className=\"h-4 w-4 text-info\" /> Harvest &amp; inventory\n </h3>\n\n {execution && execution.harvests.length > 0 ? (\n <ul className=\"mb-5 space-y-2\">\n {execution.harvests.map((h) => (\n <li\n key={h.id}\n className=\"flex items-center justify-between gap-3 rounded-lg border border-border-subtle bg-bg-surface px-3 py-2\"\n >\n <div className=\"min-w-0\">\n <div className=\"flex items-center gap-2\">\n <span className=\"truncate text-sm font-medium text-text-primary\">\n {h.cropName || plan.cropName}\n </span>\n <StatusBadge label={`Grade ${h.qualityGrade}`} variant=\"muted\" />\n </div>\n <div className=\"mt-1 text-xs text-text-secondary\">\n {formatNumber(h.quantity)} {h.unit} · {formatDate(h.harvestDate)}\n </div>\n </div>\n {h.productId ? (\n <span className=\"inline-flex items-center gap-1 whitespace-nowrap text-xs font-medium text-status-success-text\">\n <PackageCheck className=\"h-4 w-4\" /> In inventory\n </span>\n ) : (\n <StatusBadge label={h.status} variant=\"muted\" />\n )}\n </li>\n ))}\n </ul>\n ) : (\n <p className=\"mb-5 text-sm text-text-secondary\">\n {loading ? 'Loading harvests…' : 'No harvests recorded against this plan yet.'}\n </p>\n )}\n\n <div className=\"grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3\">\n <LabeledField label=\"Crop\">\n <Select value={effectiveCropId} onValueChange={setHarvestCropId}>\n <SelectTrigger className=\"w-full\">\n <SelectValue placeholder=\"Select crop\" />\n </SelectTrigger>\n <SelectContent>\n {fieldCrops.map((c) => (\n <SelectItem key={c.id} value={c.id}>\n {c.variety ? `${c.name} — ${c.variety}` : c.name}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </LabeledField>\n <LabeledField label=\"Quantity\">\n <Input\n type=\"number\"\n min=\"0\"\n step=\"any\"\n value={harvestQty}\n onChange={(e) => setHarvestQty(e.target.value)}\n placeholder=\"e.g. 120\"\n />\n </LabeledField>\n <LabeledField label=\"Unit\">\n <Input value={harvestUnit} onChange={(e) => setHarvestUnit(e.target.value)} placeholder=\"kg\" />\n </LabeledField>\n <LabeledField label=\"Quality\">\n <Select value={harvestQuality} onValueChange={setHarvestQuality}>\n <SelectTrigger className=\"w-full\">\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n <SelectItem value=\"A\">Grade A</SelectItem>\n <SelectItem value=\"B\">Grade B</SelectItem>\n <SelectItem value=\"C\">Grade C</SelectItem>\n </SelectContent>\n </Select>\n </LabeledField>\n <LabeledField label=\"Harvest date\">\n <Input type=\"date\" value={harvestDate} onChange={(e) => setHarvestDate(e.target.value)} />\n </LabeledField>\n <LabeledField label=\"Price / unit\">\n <Input\n type=\"number\"\n min=\"0\"\n step=\"any\"\n value={harvestPrice}\n onChange={(e) => setHarvestPrice(e.target.value)}\n placeholder=\"Optional\"\n />\n </LabeledField>\n </div>\n <div className=\"mt-4 flex flex-wrap items-center gap-4\">\n <label className=\"flex items-center gap-2 text-sm text-text-primary\">\n <input\n type=\"checkbox\"\n checked={addToInventory}\n onChange={(e) => setAddToInventory(e.target.checked)}\n className=\"h-4 w-4 rounded border-border-subtle\"\n />\n Add harvested quantity to inventory\n </label>\n <Button onClick={handleRecordHarvest} disabled={recording}>\n <Sprout className=\"h-4 w-4\" /> {recording ? 'Recording…' : 'Record harvest'}\n </Button>\n </div>\n </GlassCard>\n </div>\n );\n};\n\nconst ExecMetric: FC<{ label: string; value: string; unit?: string }> = ({ label, value, unit }) => (\n <div>\n <div className=\"text-xs text-text-secondary\">{label}</div>\n <div className=\"mt-1 text-lg font-semibold text-text-primary\">\n {value}\n {unit ? <span className=\"ms-1 text-xs font-normal text-text-secondary\">{unit}</span> : null}\n </div>\n </div>\n);\n\nconst LabeledField: FC<{ label: string; children: ReactNode }> = ({ label, children }) => (\n <div>\n <label className=\"text-xs font-medium text-text-secondary\">{label}</label>\n <div className=\"mt-1\">{children}</div>\n </div>\n);\n"],"mappings":";;;;;;;;;;;AA8BA,IAAM,IAAqD;CACzD;EAAE,OAAO;EAAY,OAAO;EAAY;CACxC;EAAE,OAAO;EAAW,OAAO;EAAW;CACtC;EAAE,OAAO;EAAe,OAAO;EAAe;CAC9C;EAAE,OAAO;EAAW,OAAO;EAAW;CACtC;EAAE,OAAO;EAAc,OAAO;EAAc;CAC5C;EAAE,OAAO;EAAY,OAAO;EAAY;CACxC;EAAE,OAAO;EAAY,OAAO;EAAY;CACxC;EAAE,OAAO;EAAgB,OAAO;EAAgB;CAChD;EAAE,OAAO;EAAY,OAAO;EAAY;CACxC;EAAE,OAAO;EAAS,OAAO;EAAS;CACnC,EAEK,MAAiB,MAAkB,EAAe,MAAM,M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OAAD;CAAK,WAAU;CAAQ;CAAe,CAAA,CAClC,EAAA,CAAA"}
@@ -21,7 +21,7 @@ var a = "FARM", o = "Farm Tasks", s = i`
21
21
  }
22
22
  `;
23
23
  function l(i, l, u) {
24
- let [d, f] = r(null), [p, m] = r(!1), [h, g] = r(null), [_, v] = r(0), y = n(!1), b = e(() => {
24
+ let [d, f] = r(null), [p, m] = r(!1), [h, g] = r(null), [_, v] = r(0), y = n(null), b = e(() => {
25
25
  g(null), f(null), v((e) => e + 1);
26
26
  }, []);
27
27
  return t(() => {
@@ -30,35 +30,38 @@ function l(i, l, u) {
30
30
  return;
31
31
  }
32
32
  let e = !1;
33
- return y.current = !0, m(!0), g(null), (async () => {
34
- try {
35
- let t = (await i.query({
36
- query: s,
37
- variables: { workspaceId: l },
38
- fetchPolicy: "network-only"
39
- })).data?.planmagnetProjects?.items ?? [], n = t.find((e) => e.key === "FARM") ?? t[0];
40
- if (n) {
41
- e || f(n.id);
42
- return;
43
- }
44
- if (!u) throw Error("Cannot create the Farm Tasks project without a current user.");
45
- let r = (await i.mutate({
46
- mutation: c,
47
- variables: { input: {
48
- name: o,
49
- key: a,
50
- ownerId: u,
51
- methodology: "KANBAN"
52
- } }
53
- })).data?.planmagnetCreateProject?.id;
54
- if (!r) throw Error("createProject did not return a project id.");
55
- e || f(r);
56
- } catch (t) {
57
- e || g(t instanceof Error ? t : Error(String(t)));
58
- } finally {
59
- y.current = !1, e || m(!1);
60
- }
61
- })(), () => {
33
+ m(!0), g(null);
34
+ let t = async () => {
35
+ let e = (await i.query({
36
+ query: s,
37
+ variables: { workspaceId: l },
38
+ fetchPolicy: "network-only"
39
+ })).data?.planmagnetProjects?.items ?? [], t = e.find((e) => e.key === "FARM") ?? e[0];
40
+ if (t) return t.id;
41
+ if (!u) throw Error("Cannot create the Farm Tasks project without a current user.");
42
+ let n = await i.mutate({
43
+ mutation: c,
44
+ variables: { input: {
45
+ name: o,
46
+ key: a,
47
+ ownerId: u,
48
+ methodology: "KANBAN"
49
+ } }
50
+ }), r = n.data?.planmagnetCreateProject?.id;
51
+ if (r) return r;
52
+ let d = n.error?.message?.trim();
53
+ throw Error(d ? `Could not create the Farm Tasks project: ${d}` : "Could not create the Farm Tasks project: the server reported success but returned no project id.");
54
+ }, n = `${l}::${u ?? ""}::${_}`;
55
+ return (!y.current || y.current.key !== n) && (y.current = {
56
+ key: n,
57
+ promise: t()
58
+ }), y.current.promise.then((t) => {
59
+ e || f(t);
60
+ }).catch((t) => {
61
+ y.current?.key === n && (y.current = null), e || g(t instanceof Error ? t : Error(String(t)));
62
+ }).finally(() => {
63
+ e || m(!1);
64
+ }), () => {
62
65
  e = !0;
63
66
  };
64
67
  }, [
@@ -1 +1 @@
1
- {"version":3,"file":"useDefaultTaskProject.js","names":[],"sources":["../../../../src/healthybowl/pages/tasks/useDefaultTaskProject.ts"],"sourcesContent":["/**\n * useDefaultTaskProject — resolves the workspace's default PlanMagnet project\n * that Farm Tasks are created in.\n *\n * The embedded `<TasksPageCore/>` (from `@burdenoff/planmagnet-fe-sdk`) needs a\n * non-null `projectId` to enable the create flow (the backend\n * `PlanmagnetCreateWorkItemInput.projectId` is required). HealthyBowl farmers\n * never see PlanMagnet's project concept, so we transparently get-or-create a\n * single per-workspace \"Farm Tasks\" project and hand its id to the SDK.\n *\n * Strategy:\n * 1. Query `planmagnetProjects(workspaceId)` (prefixed composed root).\n * 2. Reuse the first project whose `key` is FARM_TASKS_PROJECT_KEY, else the\n * first project of any kind (a workspace usually has just this one).\n * 3. If none exist, `planmagnetCreateProject` a \"Farm Tasks\" project.\n *\n * BYO-Apollo: takes the workspace Apollo client as an arg (the same client the\n * SDK board uses) so both the project bootstrap and the board hit the same\n * workspaces gateway with identical auth/context.\n *\n * @module healthybowl\n */\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { gql, type ApolloClient } from '@apollo/client';\n\n/**\n * Deterministic key for the single HealthyBowl \"Farm Tasks\" project per\n * workspace. Used both to create the project and to recognise it on re-load so\n * we never create a second one.\n */\nexport const FARM_TASKS_PROJECT_KEY = 'FARM';\nconst FARM_TASKS_PROJECT_NAME = 'Farm Tasks';\n\n// The composed supergraph exposes PlanMagnet project ops under the\n// `planmagnet*` prefix (WorkItem/Project ops are prefixed post-federation).\nconst LIST_PROJECTS = gql`\n query HealthyBowlListTaskProjects($workspaceId: ID!) {\n planmagnetProjects(workspaceId: $workspaceId) {\n items {\n id\n key\n name\n }\n }\n }\n`;\n\nconst CREATE_PROJECT = gql`\n mutation HealthyBowlCreateTaskProject($input: PlanmagnetCreateProjectInput!) {\n planmagnetCreateProject(input: $input) {\n id\n key\n name\n }\n }\n`;\n\ninterface ProjectRow {\n id: string;\n key: string;\n name: string;\n}\n\ninterface ListProjectsData {\n planmagnetProjects: { items: ProjectRow[] } | null;\n}\n\ninterface CreateProjectData {\n planmagnetCreateProject: ProjectRow;\n}\n\nexport interface UseDefaultTaskProjectResult {\n /** The resolved default-project id, or null while resolving / on error. */\n projectId: string | null;\n loading: boolean;\n error: Error | null;\n /** Re-run the get-or-create flow (e.g. after an error). */\n retry: () => void;\n}\n\n/**\n * Resolve (and lazily create) the workspace's default Farm Tasks project.\n *\n * @param client Workspace Apollo client (BYO — same client the SDK board uses).\n * @param workspaceId Active workspace id (empty string = not ready; hook idles).\n * @param ownerId Actor id to own a freshly-created project (current user).\n */\nexport function useDefaultTaskProject(\n client: ApolloClient | null,\n workspaceId: string,\n ownerId: string | undefined\n): UseDefaultTaskProjectResult {\n const [projectId, setProjectId] = useState<string | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [attempt, setAttempt] = useState(0);\n\n // Guards a get-or-create in flight so a re-render (or React 18 double-invoke\n // in dev) can't fire a second createProject and produce a duplicate project.\n const inFlightRef = useRef(false);\n\n const retry = useCallback(() => {\n setError(null);\n setProjectId(null);\n setAttempt((n) => n + 1);\n }, []);\n\n useEffect(() => {\n if (!client || !workspaceId) {\n setLoading(false);\n return;\n }\n\n let cancelled = false;\n inFlightRef.current = true;\n setLoading(true);\n setError(null);\n\n void (async () => {\n try {\n // 1. Look for an existing project (prefer the canonical FARM key).\n const listed = await client.query<ListProjectsData>({\n query: LIST_PROJECTS,\n variables: { workspaceId },\n fetchPolicy: 'network-only',\n });\n const items = listed.data?.planmagnetProjects?.items ?? [];\n const existing = items.find((p) => p.key === FARM_TASKS_PROJECT_KEY) ?? items[0];\n\n if (existing) {\n if (!cancelled) setProjectId(existing.id);\n return;\n }\n\n // 2. None exist — create the default Farm Tasks project. ownerId is\n // required by the backend; without a current user we can't create.\n if (!ownerId) {\n throw new Error('Cannot create the Farm Tasks project without a current user.');\n }\n\n const created = await client.mutate<CreateProjectData>({\n mutation: CREATE_PROJECT,\n variables: {\n input: {\n name: FARM_TASKS_PROJECT_NAME,\n key: FARM_TASKS_PROJECT_KEY,\n ownerId,\n methodology: 'KANBAN',\n },\n },\n });\n const newId = created.data?.planmagnetCreateProject?.id;\n if (!newId) {\n throw new Error('createProject did not return a project id.');\n }\n if (!cancelled) setProjectId(newId);\n } catch (err) {\n if (!cancelled) {\n setError(err instanceof Error ? err : new Error(String(err)));\n }\n } finally {\n inFlightRef.current = false;\n if (!cancelled) setLoading(false);\n }\n })();\n\n return () => {\n cancelled = true;\n };\n // `attempt` is the retry trigger; ownerId/workspaceId/client re-resolve on change.\n }, [client, workspaceId, ownerId, attempt]);\n\n return { projectId, loading, error, retry };\n}\n"],"mappings":";;;AA+BA,IAAa,IAAyB,QAChC,IAA0B,cAI1B,IAAgB,CAAG;;;;;;;;;;GAYnB,IAAiB,CAAG;;;;;;;;;AAwC1B,SAAgB,EACd,GACA,GACA,GAC6B;CAC7B,IAAM,CAAC,GAAW,KAAgB,EAAwB,KAAK,EACzD,CAAC,GAAS,KAAc,EAAS,GAAM,EACvC,CAAC,GAAO,KAAY,EAAuB,KAAK,EAChD,CAAC,GAAS,KAAc,EAAS,EAAE,EAInC,IAAc,EAAO,GAAM,EAE3B,IAAQ,QAAkB;AAG9B,EAFA,EAAS,KAAK,EACd,EAAa,KAAK,EAClB,GAAY,MAAM,IAAI,EAAE;IACvB,EAAE,CAAC;AAmEN,QAjEA,QAAgB;AACd,MAAI,CAAC,KAAU,CAAC,GAAa;AAC3B,KAAW,GAAM;AACjB;;EAGF,IAAI,IAAY;AAqDhB,SApDA,EAAY,UAAU,IACtB,EAAW,GAAK,EAChB,EAAS,KAAK,GAER,YAAY;AAChB,OAAI;IAOF,IAAM,KALS,MAAM,EAAO,MAAwB;KAClD,OAAO;KACP,WAAW,EAAE,gBAAa;KAC1B,aAAa;KACd,CAAC,EACmB,MAAM,oBAAoB,SAAS,EAAE,EACpD,IAAW,EAAM,MAAM,MAAM,EAAE,QAAA,OAA+B,IAAI,EAAM;AAE9E,QAAI,GAAU;AACZ,KAAK,KAAW,EAAa,EAAS,GAAG;AACzC;;AAKF,QAAI,CAAC,EACH,OAAU,MAAM,+DAA+D;IAcjF,IAAM,KAXU,MAAM,EAAO,OAA0B;KACrD,UAAU;KACV,WAAW,EACT,OAAO;MACL,MAAM;MACN,KAAK;MACL;MACA,aAAa;MACd,EACF;KACF,CAAC,EACoB,MAAM,yBAAyB;AACrD,QAAI,CAAC,EACH,OAAU,MAAM,6CAA6C;AAE/D,IAAK,KAAW,EAAa,EAAM;YAC5B,GAAK;AACZ,IAAK,KACH,EAAS,aAAe,QAAQ,IAAU,MAAM,OAAO,EAAI,CAAC,CAAC;aAEvD;AAER,IADA,EAAY,UAAU,IACjB,KAAW,EAAW,GAAM;;MAEjC,QAES;AACX,OAAY;;IAGb;EAAC;EAAQ;EAAa;EAAS;EAAQ,CAAC,EAEpC;EAAE;EAAW;EAAS;EAAO;EAAO"}
1
+ {"version":3,"file":"useDefaultTaskProject.js","names":[],"sources":["../../../../src/healthybowl/pages/tasks/useDefaultTaskProject.ts"],"sourcesContent":["/**\n * useDefaultTaskProject — resolves the workspace's default PlanMagnet project\n * that Farm Tasks are created in.\n *\n * The embedded `<TasksPageCore/>` (from `@burdenoff/planmagnet-fe-sdk`) needs a\n * non-null `projectId` to enable the create flow (the backend\n * `PlanmagnetCreateWorkItemInput.projectId` is required). HealthyBowl farmers\n * never see PlanMagnet's project concept, so we transparently get-or-create a\n * single per-workspace \"Farm Tasks\" project and hand its id to the SDK.\n *\n * Strategy:\n * 1. Query `planmagnetProjects(workspaceId)` (prefixed composed root).\n * 2. Reuse the first project whose `key` is FARM_TASKS_PROJECT_KEY, else the\n * first project of any kind (a workspace usually has just this one).\n * 3. If none exist, `planmagnetCreateProject` a \"Farm Tasks\" project.\n *\n * BYO-Apollo: takes the workspace Apollo client as an arg (the same client the\n * SDK board uses) so both the project bootstrap and the board hit the same\n * workspaces gateway with identical auth/context.\n *\n * @module healthybowl\n */\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { gql, type ApolloClient } from '@apollo/client';\n\n/**\n * Deterministic key for the single HealthyBowl \"Farm Tasks\" project per\n * workspace. Used both to create the project and to recognise it on re-load so\n * we never create a second one.\n */\nexport const FARM_TASKS_PROJECT_KEY = 'FARM';\nconst FARM_TASKS_PROJECT_NAME = 'Farm Tasks';\n\n// The composed supergraph exposes PlanMagnet project ops under the\n// `planmagnet*` prefix (WorkItem/Project ops are prefixed post-federation).\nconst LIST_PROJECTS = gql`\n query HealthyBowlListTaskProjects($workspaceId: ID!) {\n planmagnetProjects(workspaceId: $workspaceId) {\n items {\n id\n key\n name\n }\n }\n }\n`;\n\nconst CREATE_PROJECT = gql`\n mutation HealthyBowlCreateTaskProject($input: PlanmagnetCreateProjectInput!) {\n planmagnetCreateProject(input: $input) {\n id\n key\n name\n }\n }\n`;\n\ninterface ProjectRow {\n id: string;\n key: string;\n name: string;\n}\n\ninterface ListProjectsData {\n planmagnetProjects: { items: ProjectRow[] } | null;\n}\n\ninterface CreateProjectData {\n planmagnetCreateProject: ProjectRow;\n}\n\nexport interface UseDefaultTaskProjectResult {\n /** The resolved default-project id, or null while resolving / on error. */\n projectId: string | null;\n loading: boolean;\n error: Error | null;\n /** Re-run the get-or-create flow (e.g. after an error). */\n retry: () => void;\n}\n\n/**\n * Resolve (and lazily create) the workspace's default Farm Tasks project.\n *\n * @param client Workspace Apollo client (BYO — same client the SDK board uses).\n * @param workspaceId Active workspace id (empty string = not ready; hook idles).\n * @param ownerId Actor id to own a freshly-created project (current user).\n */\nexport function useDefaultTaskProject(\n client: ApolloClient | null,\n workspaceId: string,\n ownerId: string | undefined\n): UseDefaultTaskProjectResult {\n const [projectId, setProjectId] = useState<string | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [attempt, setAttempt] = useState(0);\n\n /**\n * Dedupes the get-or-create across concurrent mounts and React's StrictMode\n * double-invoke, so two resolvers cannot race and create two \"Farm Tasks\"\n * projects for one workspace.\n *\n * ★ This used to be a plain `useRef(false)` that was assigned on entry and\n * cleared in `finally` and **never read** — the comment promised a guard that\n * did not exist (BOFF-6316). Holding the in-flight promise instead of a\n * boolean is what makes it real: a second caller awaits the first rather than\n * being dropped, so cancelling one mount cannot strand the other.\n *\n * Keyed so that changing workspace/owner, or pressing Retry, genuinely\n * re-resolves instead of reusing a stale answer.\n */\n const inFlightRef = useRef<{ key: string; promise: Promise<string> } | null>(null);\n\n const retry = useCallback(() => {\n setError(null);\n setProjectId(null);\n setAttempt((n) => n + 1);\n }, []);\n\n useEffect(() => {\n if (!client || !workspaceId) {\n setLoading(false);\n return;\n }\n\n let cancelled = false;\n setLoading(true);\n setError(null);\n\n const resolveProject = async (): Promise<string> => {\n // 1. Look for an existing project (prefer the canonical FARM key).\n const listed = await client.query<ListProjectsData>({\n query: LIST_PROJECTS,\n variables: { workspaceId },\n fetchPolicy: 'network-only',\n });\n const items = listed.data?.planmagnetProjects?.items ?? [];\n const existing = items.find((p) => p.key === FARM_TASKS_PROJECT_KEY) ?? items[0];\n if (existing) {\n return existing.id;\n }\n\n // 2. None exist — create the default Farm Tasks project. ownerId is\n // required by the backend; without a current user we can't create.\n if (!ownerId) {\n throw new Error('Cannot create the Farm Tasks project without a current user.');\n }\n\n const created = await client.mutate<CreateProjectData>({\n mutation: CREATE_PROJECT,\n variables: {\n input: {\n name: FARM_TASKS_PROJECT_NAME,\n key: FARM_TASKS_PROJECT_KEY,\n ownerId,\n methodology: 'KANBAN',\n },\n },\n });\n\n const newId = created.data?.planmagnetCreateProject?.id;\n if (newId) {\n return newId;\n }\n\n // ★ BOFF-6316. This used to throw a bare \"createProject did not return a\n // project id.\" — the hook's own local disappointment, which told the\n // farmer nothing and hid whatever the gateway actually said. Under\n // `errorPolicy: 'all'` the reason arrives on `result.error` with `data`\n // null, and it was being discarded. Quota refusals, permission denials\n // and network failures all looked identical.\n const reason = created.error?.message?.trim();\n if (reason) {\n throw new Error(`Could not create the Farm Tasks project: ${reason}`);\n }\n // No error AND no id: the mutation reported success but the payload had\n // no id — a genuinely different failure worth naming separately, since it\n // points at the selection set or the resolver rather than at the caller.\n throw new Error(\n 'Could not create the Farm Tasks project: the server reported success but returned no project id.'\n );\n };\n\n const key = `${workspaceId}::${ownerId ?? ''}::${attempt}`;\n if (!inFlightRef.current || inFlightRef.current.key !== key) {\n inFlightRef.current = { key, promise: resolveProject() };\n }\n\n void inFlightRef.current.promise\n .then((id) => {\n if (!cancelled) setProjectId(id);\n })\n .catch((err: unknown) => {\n // Clear the cache so Retry re-runs rather than replaying the rejection.\n if (inFlightRef.current?.key === key) inFlightRef.current = null;\n if (!cancelled) setError(err instanceof Error ? err : new Error(String(err)));\n })\n .finally(() => {\n if (!cancelled) setLoading(false);\n });\n\n return () => {\n cancelled = true;\n };\n // `attempt` is the retry trigger; ownerId/workspaceId/client re-resolve on change.\n }, [client, workspaceId, ownerId, attempt]);\n\n return { projectId, loading, error, retry };\n}\n"],"mappings":";;;AA+BA,IAAa,IAAyB,QAChC,IAA0B,cAI1B,IAAgB,CAAG;;;;;;;;;;GAYnB,IAAiB,CAAG;;;;;;;;;AAwC1B,SAAgB,EACd,GACA,GACA,GAC6B;CAC7B,IAAM,CAAC,GAAW,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GADI,EAAY,SAAS,QAAQ,MAAK,EAAY,UAAU,OACvD,KAAW,EAAS,aAAe,QAAQ,IAAU,MAAM,OAAO,EAAI,CAAC,CAAC;IAC7E,CACD,cAAc;AACb,GAAK,KAAW,EAAW,GAAM;IACjC,QAES;AACX,OAAY;;IAGb;EAAC;EAAQ;EAAa;EAAS;EAAQ,CAAC,EAEpC;EAAE;EAAW;EAAS;EAAO;EAAO"}
@@ -0,0 +1,25 @@
1
+ //#region src/healthybowl/utils/planActivityForm.ts
2
+ function e(e) {
3
+ return {
4
+ type: e.type,
5
+ date: (e.activityDate ?? "").slice(0, 10),
6
+ quantity: e.quantity == null ? "" : String(e.quantity),
7
+ unit: e.unit ?? "",
8
+ labor: e.laborHours == null ? "" : String(e.laborHours),
9
+ notes: e.notes ?? ""
10
+ };
11
+ }
12
+ function t(e) {
13
+ return {
14
+ type: e.type,
15
+ activityDate: e.date,
16
+ quantity: e.quantity ? Number(e.quantity) : null,
17
+ unit: e.unit.trim() || null,
18
+ laborHours: e.labor ? Number(e.labor) : null,
19
+ notes: e.notes.trim() || null
20
+ };
21
+ }
22
+ //#endregion
23
+ export { t as toActivityPayload, e as toFormFields };
24
+
25
+ //# sourceMappingURL=planActivityForm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planActivityForm.js","names":[],"sources":["../../../src/healthybowl/utils/planActivityForm.ts"],"sourcesContent":["/**\n * Conversions between a stored planting activity and the edit form (BOFF-6099).\n *\n * These live here rather than inside `PlanExecutionPanel` so the tests can pin the *actual* code\n * path. The first version of these tests reimplemented both functions, which meant they could\n * keep passing while the component drifted away from them — the tests would have been asserting\n * about a copy, not about the app.\n *\n * Both conversions look trivial and both have a plausible wrong version:\n *\n * - `activityDate` comes back as an ISO timestamp, but `<input type=\"date\">` renders **blank**\n * for anything that is not bare `YYYY-MM-DD`. A blank date then fails the save guard, so the\n * row looks uneditable rather than throwing something diagnosable.\n * - `quantity` / `laborHours` are nullable numbers going into string-valued inputs. `String(null)`\n * puts the literal text \"null\" in the box, and a truthiness check on the parsed number turns a\n * recorded `0` into `null` — losing the difference between \"zero hours\" and \"not recorded\".\n */\n\nexport interface StoredActivityFields {\n type: string;\n activityDate: string | null;\n quantity?: number | null;\n unit?: string | null;\n laborHours?: number | null;\n notes?: string | null;\n}\n\nexport interface ActivityFormFields {\n type: string;\n date: string;\n quantity: string;\n unit: string;\n labor: string;\n notes: string;\n}\n\nexport interface ActivityPayload {\n type: string;\n activityDate: string;\n quantity: number | null;\n unit: string | null;\n laborHours: number | null;\n notes: string | null;\n}\n\n/** Load a stored activity into the form's string-valued state. */\nexport function toFormFields(activity: StoredActivityFields): ActivityFormFields {\n return {\n type: activity.type,\n date: (activity.activityDate ?? '').slice(0, 10),\n quantity: activity.quantity == null ? '' : String(activity.quantity),\n unit: activity.unit ?? '',\n labor: activity.laborHours == null ? '' : String(activity.laborHours),\n notes: activity.notes ?? '',\n };\n}\n\n/** Build the mutation input from the form. Shared by both the create and the edit path. */\nexport function toActivityPayload(fields: ActivityFormFields): ActivityPayload {\n return {\n type: fields.type,\n activityDate: fields.date,\n // Emptiness is checked on the STRING: `Number('0')` is 0, which is falsy, so a truthiness\n // check here would silently drop a recorded zero.\n quantity: fields.quantity ? Number(fields.quantity) : null,\n unit: fields.unit.trim() || null,\n laborHours: fields.labor ? Number(fields.labor) : null,\n notes: fields.notes.trim() || null,\n };\n}\n"],"mappings":";AA8CA,SAAgB,EAAa,GAAoD;AAC/E,QAAO;EACL,MAAM,EAAS;EACf,OAAO,EAAS,gBAAgB,IAAI,MAAM,GAAG,GAAG;EAChD,UAAU,EAAS,YAAY,OAAO,KAAK,OAAO,EAAS,SAAS;EACpE,MAAM,EAAS,QAAQ;EACvB,OAAO,EAAS,cAAc,OAAO,KAAK,OAAO,EAAS,WAAW;EACrE,OAAO,EAAS,SAAS;EAC1B;;AAIH,SAAgB,EAAkB,GAA6C;AAC7E,QAAO;EACL,MAAM,EAAO;EACb,cAAc,EAAO;EAGrB,UAAU,EAAO,WAAW,OAAO,EAAO,SAAS,GAAG;EACtD,MAAM,EAAO,KAAK,MAAM,IAAI;EAC5B,YAAY,EAAO,QAAQ,OAAO,EAAO,MAAM,GAAG;EAClD,OAAO,EAAO,MAAM,MAAM,IAAI;EAC/B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/microfe-healthybowl",
3
- "version": "2026.813.25",
3
+ "version": "2026.813.27",
4
4
  "description": "Burdenoff HealthyBowl Microfrontend - Comprehensive organic farming and agro-foods management platform",
5
5
  "type": "module",
6
6
  "files": [