@burdenoff/microfe-healthybowl 2026.710.19 → 2026.710.21
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.
- package/dist/generated/wspace-operations.js +476 -318
- package/dist/generated/wspace-operations.js.map +1 -1
- package/dist/generated/wspace-types.js.map +1 -1
- package/dist/healthybowl/HealthyBowlRoot.js +99 -82
- package/dist/healthybowl/HealthyBowlRoot.js.map +1 -1
- package/dist/healthybowl/HealthyBowlRoutes.js +103 -79
- package/dist/healthybowl/HealthyBowlRoutes.js.map +1 -1
- package/dist/healthybowl/hooks/useHealthyBowlData.js +2 -0
- package/dist/healthybowl/hooks/useHealthyBowlData.js.map +1 -1
- package/dist/healthybowl/hooks/useTracePortal.js +138 -0
- package/dist/healthybowl/hooks/useTracePortal.js.map +1 -0
- package/dist/healthybowl/index.js +1 -0
- package/dist/healthybowl/offline/OfflineStatusPill.js +30 -0
- package/dist/healthybowl/offline/OfflineStatusPill.js.map +1 -0
- package/dist/healthybowl/offline/OfflineSyncProvider.js +235 -0
- package/dist/healthybowl/offline/OfflineSyncProvider.js.map +1 -0
- package/dist/healthybowl/offline/geolocation.js +31 -0
- package/dist/healthybowl/offline/geolocation.js.map +1 -0
- package/dist/healthybowl/offline/graphql.js +89 -0
- package/dist/healthybowl/offline/graphql.js.map +1 -0
- package/dist/healthybowl/offline/network.js +43 -0
- package/dist/healthybowl/offline/network.js.map +1 -0
- package/dist/healthybowl/offline/observationMeta.js +107 -0
- package/dist/healthybowl/offline/observationMeta.js.map +1 -0
- package/dist/healthybowl/offline/store.js +120 -0
- package/dist/healthybowl/offline/store.js.map +1 -0
- package/dist/healthybowl/offline/syncEngine.js +141 -0
- package/dist/healthybowl/offline/syncEngine.js.map +1 -0
- package/dist/healthybowl/offline/types.js +15 -0
- package/dist/healthybowl/offline/types.js.map +1 -0
- package/dist/healthybowl/pages/field-capture/CaptureObservationForm.js +272 -0
- package/dist/healthybowl/pages/field-capture/CaptureObservationForm.js.map +1 -0
- package/dist/healthybowl/pages/field-capture/ConflictReviewPage.js +200 -0
- package/dist/healthybowl/pages/field-capture/ConflictReviewPage.js.map +1 -0
- package/dist/healthybowl/pages/field-capture/FieldCapturePage.js +60 -0
- package/dist/healthybowl/pages/field-capture/FieldCapturePage.js.map +1 -0
- package/dist/healthybowl/pages/field-capture/OfflineSettingsPage.js +217 -0
- package/dist/healthybowl/pages/field-capture/OfflineSettingsPage.js.map +1 -0
- package/dist/healthybowl/pages/field-capture/PendingSyncPage.js +80 -0
- package/dist/healthybowl/pages/field-capture/PendingSyncPage.js.map +1 -0
- package/dist/healthybowl/pages/field-capture/SyncHistoryPage.js +130 -0
- package/dist/healthybowl/pages/field-capture/SyncHistoryPage.js.map +1 -0
- package/dist/healthybowl/pages/field-capture/SyncQueuePanel.js +112 -0
- package/dist/healthybowl/pages/field-capture/SyncQueuePanel.js.map +1 -0
- package/dist/healthybowl/pages/traceability/PrintLabelDialog.js +296 -0
- package/dist/healthybowl/pages/traceability/PrintLabelDialog.js.map +1 -0
- package/dist/healthybowl/pages/traceability/QRCodesPage.js +450 -103
- package/dist/healthybowl/pages/traceability/QRCodesPage.js.map +1 -1
- package/dist/healthybowl/pages/traceability/TracePortalSettingsPage.js +249 -0
- package/dist/healthybowl/pages/traceability/TracePortalSettingsPage.js.map +1 -0
- package/dist/healthybowl/public/PublicTraceJourney.js +192 -0
- package/dist/healthybowl/public/PublicTraceJourney.js.map +1 -0
- package/dist/healthybowl/public/PublicTraceNotFound.js +55 -0
- package/dist/healthybowl/public/PublicTraceNotFound.js.map +1 -0
- package/dist/healthybowl/public/PublicTracePage.js +46 -0
- package/dist/healthybowl/public/PublicTracePage.js.map +1 -0
- package/dist/index.js +4 -3
- package/package.json +1 -1
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { cn as e } from "../../utils/helpers.js";
|
|
2
|
+
import { useOfflineSync as t } from "../../offline/OfflineSyncProvider.js";
|
|
3
|
+
import { OBSERVATION_TYPES as n, typeMeta as r } from "../../offline/observationMeta.js";
|
|
4
|
+
import { captureGps as i, formatGps as a } from "../../offline/geolocation.js";
|
|
5
|
+
import { useCallback as o, useEffect as s, useMemo as c, useRef as l, useState as u } from "react";
|
|
6
|
+
import { Camera as d, Loader2 as f, MapPin as ee, WifiOff as te, X as p } from "lucide-react";
|
|
7
|
+
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
8
|
+
import { Button as g, Select as _, SelectContent as v, SelectItem as y, SelectTrigger as b, SelectValue as x, Textarea as S } from "@burdenoff/fe-libs/ui";
|
|
9
|
+
//#region src/healthybowl/pages/field-capture/CaptureObservationForm.tsx
|
|
10
|
+
var C = () => {
|
|
11
|
+
let { fields: C, settings: w, capture: T, online: E } = t(), D = l(null), [O, k] = u("PEST"), [A, j] = u(""), [M, N] = u(""), [P, F] = u(""), [I, L] = u(""), [R, z] = u("kg"), [B, V] = u(""), [H, U] = u([]), [W, ne] = u(null), [re, G] = u(!1), [K, q] = u(!1), [ie, J] = u(!1), Y = c(() => C.find((e) => e.id === A), [C, A]), X = l(H);
|
|
12
|
+
X.current = H;
|
|
13
|
+
let Z = o(async () => {
|
|
14
|
+
w.autoStampGps && (G(!0), ne(await i({ highAccuracy: w.highAccuracyGps })), G(!1));
|
|
15
|
+
}, [w.autoStampGps, w.highAccuracyGps]);
|
|
16
|
+
s(() => {
|
|
17
|
+
Z();
|
|
18
|
+
}, [Z]), s(() => () => {
|
|
19
|
+
X.current.forEach((e) => URL.revokeObjectURL(e.url));
|
|
20
|
+
}, []);
|
|
21
|
+
let ae = o((e) => {
|
|
22
|
+
let t = Array.from(e.target.files ?? []);
|
|
23
|
+
D.current && (D.current.value = ""), t.length !== 0 && U((e) => [...e, ...t.slice(0, 8 - e.length).map((e) => ({
|
|
24
|
+
file: e,
|
|
25
|
+
url: URL.createObjectURL(e)
|
|
26
|
+
}))]);
|
|
27
|
+
}, []), oe = o((e) => {
|
|
28
|
+
U((t) => {
|
|
29
|
+
let n = t.find((t) => t.url === e);
|
|
30
|
+
return n && URL.revokeObjectURL(n.url), t.filter((t) => t.url !== e);
|
|
31
|
+
});
|
|
32
|
+
}, []), Q = o(() => {
|
|
33
|
+
H.forEach((e) => URL.revokeObjectURL(e.url)), N(""), F(""), L(""), V(""), U([]);
|
|
34
|
+
}, [H]), $ = M.trim().length > 0 || H.length > 0 || I.trim().length > 0, se = o(async () => {
|
|
35
|
+
if (!(!$ || K)) {
|
|
36
|
+
q(!0);
|
|
37
|
+
try {
|
|
38
|
+
await T({
|
|
39
|
+
observationType: O,
|
|
40
|
+
fieldId: A || null,
|
|
41
|
+
fieldName: Y?.name ?? null,
|
|
42
|
+
note: M.trim() || null,
|
|
43
|
+
severity: (O === "PEST" || O === "CROP_HEALTH") && P ? P : null,
|
|
44
|
+
quantity: O === "HARVEST" && I ? Number(I) : null,
|
|
45
|
+
unit: O === "HARVEST" ? R : null,
|
|
46
|
+
cropName: Y?.cropNames?.[0] ?? null,
|
|
47
|
+
animalTag: O === "LIVESTOCK" && B ? B.trim() : null,
|
|
48
|
+
latitude: W?.latitude ?? null,
|
|
49
|
+
longitude: W?.longitude ?? null,
|
|
50
|
+
gpsAccuracy: W?.accuracy ?? null,
|
|
51
|
+
photos: H.map((e) => e.file)
|
|
52
|
+
}), Q(), J(!0), window.setTimeout(() => J(!1), 2500), Z();
|
|
53
|
+
} finally {
|
|
54
|
+
q(!1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, [
|
|
58
|
+
$,
|
|
59
|
+
K,
|
|
60
|
+
O,
|
|
61
|
+
A,
|
|
62
|
+
Y,
|
|
63
|
+
M,
|
|
64
|
+
P,
|
|
65
|
+
I,
|
|
66
|
+
R,
|
|
67
|
+
B,
|
|
68
|
+
W,
|
|
69
|
+
H,
|
|
70
|
+
T,
|
|
71
|
+
Q,
|
|
72
|
+
Z
|
|
73
|
+
]);
|
|
74
|
+
return /* @__PURE__ */ h("div", {
|
|
75
|
+
className: "space-y-4",
|
|
76
|
+
children: [
|
|
77
|
+
/* @__PURE__ */ h("div", {
|
|
78
|
+
className: "flex items-center gap-3 rounded-xl bg-status-success-bgSubtle px-4 py-3",
|
|
79
|
+
children: [/* @__PURE__ */ m(d, { className: "h-5 w-5 text-status-success-text" }), /* @__PURE__ */ m("span", {
|
|
80
|
+
className: "text-base font-semibold text-status-success-text",
|
|
81
|
+
children: "New Field Observation"
|
|
82
|
+
})]
|
|
83
|
+
}),
|
|
84
|
+
/* @__PURE__ */ h("div", {
|
|
85
|
+
className: "space-y-1.5",
|
|
86
|
+
children: [/* @__PURE__ */ m("label", {
|
|
87
|
+
className: "text-xs font-medium text-text-secondary",
|
|
88
|
+
children: "Field"
|
|
89
|
+
}), /* @__PURE__ */ h(_, {
|
|
90
|
+
value: A,
|
|
91
|
+
onValueChange: j,
|
|
92
|
+
children: [/* @__PURE__ */ m(b, { children: /* @__PURE__ */ m(x, { placeholder: "Select a field (optional)" }) }), /* @__PURE__ */ m(v, { children: C.length === 0 ? /* @__PURE__ */ m(y, {
|
|
93
|
+
value: "__none",
|
|
94
|
+
disabled: !0,
|
|
95
|
+
children: "No fields yet"
|
|
96
|
+
}) : C.map((e) => /* @__PURE__ */ h(y, {
|
|
97
|
+
value: e.id,
|
|
98
|
+
children: [e.name, e.cropNames?.length ? ` · ${e.cropNames[0]}` : ""]
|
|
99
|
+
}, e.id)) })]
|
|
100
|
+
})]
|
|
101
|
+
}),
|
|
102
|
+
/* @__PURE__ */ m("div", {
|
|
103
|
+
className: "flex flex-wrap gap-2",
|
|
104
|
+
children: n.map((t) => {
|
|
105
|
+
let n = r(t), i = t === O, a = n.icon;
|
|
106
|
+
return /* @__PURE__ */ h("button", {
|
|
107
|
+
type: "button",
|
|
108
|
+
onClick: () => k(t),
|
|
109
|
+
className: e("inline-flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-sm font-medium transition", i ? "border-transparent bg-action-primary-bg text-action-primary-text shadow-sm" : "border-border-subtle bg-bg-surface text-text-secondary hover:bg-bg-sunken"),
|
|
110
|
+
children: [/* @__PURE__ */ m(a, { className: "h-3.5 w-3.5" }), n.short]
|
|
111
|
+
}, t);
|
|
112
|
+
})
|
|
113
|
+
}),
|
|
114
|
+
/* @__PURE__ */ m(S, {
|
|
115
|
+
value: M,
|
|
116
|
+
onChange: (e) => N(e.target.value),
|
|
117
|
+
rows: 3,
|
|
118
|
+
placeholder: "What did you see? e.g. Aphids seen on 3 tomato rows, east side. Applied neem spray."
|
|
119
|
+
}),
|
|
120
|
+
(O === "PEST" || O === "CROP_HEALTH") && /* @__PURE__ */ h("div", {
|
|
121
|
+
className: "space-y-1.5",
|
|
122
|
+
children: [/* @__PURE__ */ m("label", {
|
|
123
|
+
className: "text-xs font-medium text-text-secondary",
|
|
124
|
+
children: "Severity"
|
|
125
|
+
}), /* @__PURE__ */ h(_, {
|
|
126
|
+
value: P,
|
|
127
|
+
onValueChange: F,
|
|
128
|
+
children: [/* @__PURE__ */ m(b, { children: /* @__PURE__ */ m(x, { placeholder: "Set severity" }) }), /* @__PURE__ */ m(v, { children: [
|
|
129
|
+
"LOW",
|
|
130
|
+
"MEDIUM",
|
|
131
|
+
"HIGH",
|
|
132
|
+
"CRITICAL"
|
|
133
|
+
].map((e) => /* @__PURE__ */ m(y, {
|
|
134
|
+
value: e,
|
|
135
|
+
children: e.charAt(0) + e.slice(1).toLowerCase()
|
|
136
|
+
}, e)) })]
|
|
137
|
+
})]
|
|
138
|
+
}),
|
|
139
|
+
O === "HARVEST" && /* @__PURE__ */ h("div", {
|
|
140
|
+
className: "flex gap-2",
|
|
141
|
+
children: [/* @__PURE__ */ h("div", {
|
|
142
|
+
className: "flex-1 space-y-1.5",
|
|
143
|
+
children: [/* @__PURE__ */ m("label", {
|
|
144
|
+
className: "text-xs font-medium text-text-secondary",
|
|
145
|
+
children: "Quantity"
|
|
146
|
+
}), /* @__PURE__ */ m("input", {
|
|
147
|
+
type: "number",
|
|
148
|
+
inputMode: "decimal",
|
|
149
|
+
value: I,
|
|
150
|
+
onChange: (e) => L(e.target.value),
|
|
151
|
+
placeholder: "42",
|
|
152
|
+
className: "w-full rounded-lg border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]"
|
|
153
|
+
})]
|
|
154
|
+
}), /* @__PURE__ */ h("div", {
|
|
155
|
+
className: "w-28 space-y-1.5",
|
|
156
|
+
children: [/* @__PURE__ */ m("label", {
|
|
157
|
+
className: "text-xs font-medium text-text-secondary",
|
|
158
|
+
children: "Unit"
|
|
159
|
+
}), /* @__PURE__ */ h(_, {
|
|
160
|
+
value: R,
|
|
161
|
+
onValueChange: z,
|
|
162
|
+
children: [/* @__PURE__ */ m(b, { children: /* @__PURE__ */ m(x, {}) }), /* @__PURE__ */ m(v, { children: [
|
|
163
|
+
"kg",
|
|
164
|
+
"quintal",
|
|
165
|
+
"tonne",
|
|
166
|
+
"crates",
|
|
167
|
+
"bunches"
|
|
168
|
+
].map((e) => /* @__PURE__ */ m(y, {
|
|
169
|
+
value: e,
|
|
170
|
+
children: e
|
|
171
|
+
}, e)) })]
|
|
172
|
+
})]
|
|
173
|
+
})]
|
|
174
|
+
}),
|
|
175
|
+
O === "LIVESTOCK" && /* @__PURE__ */ h("div", {
|
|
176
|
+
className: "space-y-1.5",
|
|
177
|
+
children: [/* @__PURE__ */ m("label", {
|
|
178
|
+
className: "text-xs font-medium text-text-secondary",
|
|
179
|
+
children: "Animal tag"
|
|
180
|
+
}), /* @__PURE__ */ m("input", {
|
|
181
|
+
value: B,
|
|
182
|
+
onChange: (e) => V(e.target.value),
|
|
183
|
+
placeholder: "e.g. Cow #17",
|
|
184
|
+
className: "w-full rounded-lg border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]"
|
|
185
|
+
})]
|
|
186
|
+
}),
|
|
187
|
+
/* @__PURE__ */ h("div", { children: [
|
|
188
|
+
/* @__PURE__ */ m("input", {
|
|
189
|
+
ref: D,
|
|
190
|
+
type: "file",
|
|
191
|
+
accept: "image/*",
|
|
192
|
+
capture: "environment",
|
|
193
|
+
multiple: !0,
|
|
194
|
+
className: "hidden",
|
|
195
|
+
onChange: ae
|
|
196
|
+
}),
|
|
197
|
+
/* @__PURE__ */ h("div", {
|
|
198
|
+
className: "flex flex-wrap gap-2",
|
|
199
|
+
children: [H.map((e) => /* @__PURE__ */ h("div", {
|
|
200
|
+
className: "group relative",
|
|
201
|
+
children: [/* @__PURE__ */ m("img", {
|
|
202
|
+
src: e.url,
|
|
203
|
+
alt: "Captured",
|
|
204
|
+
className: "h-20 w-20 rounded-lg border border-border-subtle object-cover"
|
|
205
|
+
}), /* @__PURE__ */ m("button", {
|
|
206
|
+
type: "button",
|
|
207
|
+
onClick: () => oe(e.url),
|
|
208
|
+
"aria-label": "Remove photo",
|
|
209
|
+
className: "absolute -right-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-full border border-border-subtle bg-bg-surface text-text-secondary shadow-sm hover:text-status-error-text",
|
|
210
|
+
children: /* @__PURE__ */ m(p, { className: "h-3 w-3" })
|
|
211
|
+
})]
|
|
212
|
+
}, e.url)), H.length < 8 && /* @__PURE__ */ h("button", {
|
|
213
|
+
type: "button",
|
|
214
|
+
onClick: () => D.current?.click(),
|
|
215
|
+
className: "flex h-20 w-20 flex-col items-center justify-center gap-1 rounded-lg border border-dashed border-border-subtle bg-bg-surface text-text-secondary hover:bg-bg-sunken/60",
|
|
216
|
+
children: [/* @__PURE__ */ m(d, { className: "h-5 w-5" }), /* @__PURE__ */ m("span", {
|
|
217
|
+
className: "text-[10px] leading-tight text-center",
|
|
218
|
+
children: "Add Photo"
|
|
219
|
+
})]
|
|
220
|
+
})]
|
|
221
|
+
}),
|
|
222
|
+
H.length > 0 && /* @__PURE__ */ h("p", {
|
|
223
|
+
className: "mt-1.5 text-xs text-text-secondary",
|
|
224
|
+
children: [
|
|
225
|
+
H.length,
|
|
226
|
+
" photo",
|
|
227
|
+
H.length > 1 ? "s" : "",
|
|
228
|
+
" saved on device — will upload on sync."
|
|
229
|
+
]
|
|
230
|
+
})
|
|
231
|
+
] }),
|
|
232
|
+
/* @__PURE__ */ h("div", {
|
|
233
|
+
className: "flex items-center gap-2 rounded-lg bg-bg-sunken/60 px-3 py-2 text-sm text-text-secondary",
|
|
234
|
+
children: [/* @__PURE__ */ m(ee, { className: "h-4 w-4 shrink-0" }), re ? /* @__PURE__ */ h("span", {
|
|
235
|
+
className: "flex items-center gap-1.5",
|
|
236
|
+
children: [/* @__PURE__ */ m(f, { className: "h-3.5 w-3.5 animate-spin" }), " Getting location…"]
|
|
237
|
+
}) : W ? /* @__PURE__ */ h("span", { children: [
|
|
238
|
+
a(W.latitude, W.longitude),
|
|
239
|
+
" ",
|
|
240
|
+
/* @__PURE__ */ h("span", {
|
|
241
|
+
className: "text-text-tertiary",
|
|
242
|
+
children: [
|
|
243
|
+
"· ±",
|
|
244
|
+
Math.round(W.accuracy),
|
|
245
|
+
" m · auto-captured"
|
|
246
|
+
]
|
|
247
|
+
})
|
|
248
|
+
] }) : /* @__PURE__ */ m("button", {
|
|
249
|
+
type: "button",
|
|
250
|
+
onClick: () => void Z(),
|
|
251
|
+
className: "underline underline-offset-2",
|
|
252
|
+
children: "Stamp GPS location"
|
|
253
|
+
})]
|
|
254
|
+
}),
|
|
255
|
+
/* @__PURE__ */ h(g, {
|
|
256
|
+
onClick: () => void se(),
|
|
257
|
+
disabled: !$ || K,
|
|
258
|
+
className: "w-full",
|
|
259
|
+
size: "lg",
|
|
260
|
+
children: [K ? /* @__PURE__ */ m(f, { className: "mr-2 h-4 w-4 animate-spin" }) : E ? null : /* @__PURE__ */ m(te, { className: "mr-2 h-4 w-4" }), E ? "Save observation" : "Save (offline)"]
|
|
261
|
+
}),
|
|
262
|
+
/* @__PURE__ */ m("p", {
|
|
263
|
+
className: "text-center text-xs text-text-secondary",
|
|
264
|
+
children: ie ? "Saved locally — will sync when online." : "Saved locally first — syncs automatically when online."
|
|
265
|
+
})
|
|
266
|
+
]
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
//#endregion
|
|
270
|
+
export { C as CaptureObservationForm };
|
|
271
|
+
|
|
272
|
+
//# sourceMappingURL=CaptureObservationForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CaptureObservationForm.js","names":[],"sources":["../../../../src/healthybowl/pages/field-capture/CaptureObservationForm.tsx"],"sourcesContent":["/**\n * Capture Observation form (BOFF-2883).\n *\n * Fully usable with ZERO connectivity: writes go to the local outbox (IndexedDB)\n * via `useOfflineSync().capture`, not straight to the gateway. Photos are held\n * locally and GPS is auto-stamped offline; both travel with the record on sync.\n */\nimport { useCallback, useEffect, useMemo, useRef, useState, type FC } from 'react';\nimport { Camera, MapPin, Loader2, X, WifiOff } from 'lucide-react';\nimport { Button, Textarea, Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@burdenoff/fe-libs/ui';\nimport { useOfflineSync, type CaptureInput } from '../../offline/OfflineSyncProvider';\nimport { OBSERVATION_TYPES, typeMeta } from '../../offline/observationMeta';\nimport type { ObservationType } from '../../offline/types';\nimport { captureGps, formatGps } from '../../offline/geolocation';\nimport { cn } from '../../utils/helpers';\n\ninterface LocalPhotoFile {\n file: File;\n url: string;\n}\n\nexport const CaptureObservationForm: FC = () => {\n const { fields, settings, capture, online } = useOfflineSync();\n const fileInputRef = useRef<HTMLInputElement>(null);\n\n const [type, setType] = useState<ObservationType>('PEST');\n const [fieldId, setFieldId] = useState<string>('');\n const [note, setNote] = useState('');\n const [severity, setSeverity] = useState('');\n const [quantity, setQuantity] = useState('');\n const [unit, setUnit] = useState('kg');\n const [animalTag, setAnimalTag] = useState('');\n const [photos, setPhotos] = useState<LocalPhotoFile[]>([]);\n const [gps, setGps] = useState<{ latitude: number; longitude: number; accuracy: number } | null>(null);\n const [gpsBusy, setGpsBusy] = useState(false);\n const [saving, setSaving] = useState(false);\n const [justSaved, setJustSaved] = useState(false);\n\n const selectedField = useMemo(() => fields.find((f) => f.id === fieldId), [fields, fieldId]);\n\n // Mirror the latest photos in a ref so the unmount cleanup revokes the CURRENT\n // set of object URLs (not the mount-time snapshot).\n const photosRef = useRef<LocalPhotoFile[]>(photos);\n photosRef.current = photos;\n\n // Auto-stamp GPS on mount (best-effort; works offline).\n const stampGps = useCallback(async () => {\n if (!settings.autoStampGps) return;\n setGpsBusy(true);\n const fix = await captureGps({ highAccuracy: settings.highAccuracyGps });\n setGps(fix);\n setGpsBusy(false);\n }, [settings.autoStampGps, settings.highAccuracyGps]);\n\n useEffect(() => {\n void stampGps();\n }, [stampGps]);\n\n // Revoke object URLs on unmount to avoid leaks (reads the latest set via the ref).\n useEffect(\n () => () => {\n photosRef.current.forEach((p) => URL.revokeObjectURL(p.url));\n },\n []\n );\n\n const onFiles = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {\n const files = Array.from(e.target.files ?? []);\n if (fileInputRef.current) fileInputRef.current.value = '';\n if (files.length === 0) return;\n setPhotos((prev) => [\n ...prev,\n ...files.slice(0, 8 - prev.length).map((file) => ({ file, url: URL.createObjectURL(file) })),\n ]);\n }, []);\n\n const removePhoto = useCallback((url: string) => {\n setPhotos((prev) => {\n const target = prev.find((p) => p.url === url);\n if (target) URL.revokeObjectURL(target.url);\n return prev.filter((p) => p.url !== url);\n });\n }, []);\n\n const reset = useCallback(() => {\n photos.forEach((p) => URL.revokeObjectURL(p.url));\n setNote('');\n setSeverity('');\n setQuantity('');\n setAnimalTag('');\n setPhotos([]);\n }, [photos]);\n\n const canSave = note.trim().length > 0 || photos.length > 0 || quantity.trim().length > 0;\n\n const onSave = useCallback(async () => {\n if (!canSave || saving) return;\n setSaving(true);\n try {\n const input: CaptureInput = {\n observationType: type,\n fieldId: fieldId || null,\n fieldName: selectedField?.name ?? null,\n note: note.trim() || null,\n severity: (type === 'PEST' || type === 'CROP_HEALTH') && severity ? severity : null,\n quantity: type === 'HARVEST' && quantity ? Number(quantity) : null,\n unit: type === 'HARVEST' ? unit : null,\n cropName: selectedField?.cropNames?.[0] ?? null,\n animalTag: type === 'LIVESTOCK' && animalTag ? animalTag.trim() : null,\n latitude: gps?.latitude ?? null,\n longitude: gps?.longitude ?? null,\n gpsAccuracy: gps?.accuracy ?? null,\n photos: photos.map((p) => p.file),\n };\n await capture(input);\n reset();\n setJustSaved(true);\n window.setTimeout(() => setJustSaved(false), 2500);\n void stampGps();\n } finally {\n setSaving(false);\n }\n }, [\n canSave,\n saving,\n type,\n fieldId,\n selectedField,\n note,\n severity,\n quantity,\n unit,\n animalTag,\n gps,\n photos,\n capture,\n reset,\n stampGps,\n ]);\n\n return (\n <div className=\"space-y-4\">\n {/* Header ribbon */}\n <div className=\"flex items-center gap-3 rounded-xl bg-status-success-bgSubtle px-4 py-3\">\n <Camera className=\"h-5 w-5 text-status-success-text\" />\n <span className=\"text-base font-semibold text-status-success-text\">New Field Observation</span>\n </div>\n\n {/* Field selector */}\n <div className=\"space-y-1.5\">\n <label className=\"text-xs font-medium text-text-secondary\">Field</label>\n <Select value={fieldId} onValueChange={setFieldId}>\n <SelectTrigger>\n <SelectValue placeholder=\"Select a field (optional)\" />\n </SelectTrigger>\n <SelectContent>\n {fields.length === 0 ? (\n <SelectItem value=\"__none\" disabled>\n No fields yet\n </SelectItem>\n ) : (\n fields.map((f) => (\n <SelectItem key={f.id} value={f.id}>\n {f.name}\n {f.cropNames?.length ? ` · ${f.cropNames[0]}` : ''}\n </SelectItem>\n ))\n )}\n </SelectContent>\n </Select>\n </div>\n\n {/* Quick-type chips */}\n <div className=\"flex flex-wrap gap-2\">\n {OBSERVATION_TYPES.map((t) => {\n const meta = typeMeta(t);\n const active = t === type;\n const Icon = meta.icon;\n return (\n <button\n key={t}\n type=\"button\"\n onClick={() => setType(t)}\n className={cn(\n 'inline-flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-sm font-medium transition',\n active\n ? 'border-transparent bg-action-primary-bg text-action-primary-text shadow-sm'\n : 'border-border-subtle bg-bg-surface text-text-secondary hover:bg-bg-sunken'\n )}\n >\n <Icon className=\"h-3.5 w-3.5\" />\n {meta.short}\n </button>\n );\n })}\n </div>\n\n {/* Note */}\n <Textarea\n value={note}\n onChange={(e) => setNote(e.target.value)}\n rows={3}\n placeholder=\"What did you see? e.g. Aphids seen on 3 tomato rows, east side. Applied neem spray.\"\n />\n\n {/* Type-specific facets */}\n {(type === 'PEST' || type === 'CROP_HEALTH') && (\n <div className=\"space-y-1.5\">\n <label className=\"text-xs font-medium text-text-secondary\">Severity</label>\n <Select value={severity} onValueChange={setSeverity}>\n <SelectTrigger>\n <SelectValue placeholder=\"Set severity\" />\n </SelectTrigger>\n <SelectContent>\n {['LOW', 'MEDIUM', 'HIGH', 'CRITICAL'].map((s) => (\n <SelectItem key={s} value={s}>\n {s.charAt(0) + s.slice(1).toLowerCase()}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </div>\n )}\n {type === 'HARVEST' && (\n <div className=\"flex gap-2\">\n <div className=\"flex-1 space-y-1.5\">\n <label className=\"text-xs font-medium text-text-secondary\">Quantity</label>\n <input\n type=\"number\"\n inputMode=\"decimal\"\n value={quantity}\n onChange={(e) => setQuantity(e.target.value)}\n placeholder=\"42\"\n className=\"w-full rounded-lg border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]\"\n />\n </div>\n <div className=\"w-28 space-y-1.5\">\n <label className=\"text-xs font-medium text-text-secondary\">Unit</label>\n <Select value={unit} onValueChange={setUnit}>\n <SelectTrigger>\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n {['kg', 'quintal', 'tonne', 'crates', 'bunches'].map((u) => (\n <SelectItem key={u} value={u}>\n {u}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </div>\n </div>\n )}\n {type === 'LIVESTOCK' && (\n <div className=\"space-y-1.5\">\n <label className=\"text-xs font-medium text-text-secondary\">Animal tag</label>\n <input\n value={animalTag}\n onChange={(e) => setAnimalTag(e.target.value)}\n placeholder=\"e.g. Cow #17\"\n className=\"w-full rounded-lg border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]\"\n />\n </div>\n )}\n\n {/* Photos */}\n <div>\n <input\n ref={fileInputRef}\n type=\"file\"\n accept=\"image/*\"\n // `capture` opens the rear camera on mobile; harmless on desktop.\n capture=\"environment\"\n multiple\n className=\"hidden\"\n onChange={onFiles}\n />\n <div className=\"flex flex-wrap gap-2\">\n {photos.map((p) => (\n <div key={p.url} className=\"group relative\">\n <img\n src={p.url}\n alt=\"Captured\"\n className=\"h-20 w-20 rounded-lg border border-border-subtle object-cover\"\n />\n <button\n type=\"button\"\n onClick={() => removePhoto(p.url)}\n aria-label=\"Remove photo\"\n className=\"absolute -right-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-full border border-border-subtle bg-bg-surface text-text-secondary shadow-sm hover:text-status-error-text\"\n >\n <X className=\"h-3 w-3\" />\n </button>\n </div>\n ))}\n {photos.length < 8 && (\n <button\n type=\"button\"\n onClick={() => fileInputRef.current?.click()}\n className=\"flex h-20 w-20 flex-col items-center justify-center gap-1 rounded-lg border border-dashed border-border-subtle bg-bg-surface text-text-secondary hover:bg-bg-sunken/60\"\n >\n <Camera className=\"h-5 w-5\" />\n <span className=\"text-[10px] leading-tight text-center\">Add Photo</span>\n </button>\n )}\n </div>\n {photos.length > 0 && (\n <p className=\"mt-1.5 text-xs text-text-secondary\">\n {photos.length} photo{photos.length > 1 ? 's' : ''} saved on device — will upload on sync.\n </p>\n )}\n </div>\n\n {/* GPS */}\n <div className=\"flex items-center gap-2 rounded-lg bg-bg-sunken/60 px-3 py-2 text-sm text-text-secondary\">\n <MapPin className=\"h-4 w-4 shrink-0\" />\n {gpsBusy ? (\n <span className=\"flex items-center gap-1.5\">\n <Loader2 className=\"h-3.5 w-3.5 animate-spin\" /> Getting location…\n </span>\n ) : gps ? (\n <span>\n {formatGps(gps.latitude, gps.longitude)}{' '}\n <span className=\"text-text-tertiary\">· ±{Math.round(gps.accuracy)} m · auto-captured</span>\n </span>\n ) : (\n <button type=\"button\" onClick={() => void stampGps()} className=\"underline underline-offset-2\">\n Stamp GPS location\n </button>\n )}\n </div>\n\n {/* Save */}\n <Button onClick={() => void onSave()} disabled={!canSave || saving} className=\"w-full\" size=\"lg\">\n {saving ? (\n <Loader2 className=\"mr-2 h-4 w-4 animate-spin\" />\n ) : !online ? (\n <WifiOff className=\"mr-2 h-4 w-4\" />\n ) : null}\n {online ? 'Save observation' : 'Save (offline)'}\n </Button>\n <p className=\"text-center text-xs text-text-secondary\">\n {justSaved\n ? 'Saved locally — will sync when online.'\n : 'Saved locally first — syncs automatically when online.'}\n </p>\n </div>\n );\n};\n"],"mappings":";;;;;;;;;AAqBA,IAAa,UAAmC;CAC9C,IAAM,EAAE,WAAQ,aAAU,YAAS,cAAW,GAAgB,EACxD,IAAe,EAAyB,KAAK,EAE7C,CAAC,GAAM,KAAW,EAA0B,OAAO,EACnD,CAAC,GAAS,KAAc,EAAiB,GAAG,EAC5C,CAAC,GAAM,KAAW,EAAS,GAAG,EAC9B,CAAC,GAAU,KAAe,EAAS,GAAG,EACtC,CAAC,GAAU,KAAe,EAAS,GAAG,EACtC,CAAC,GAAM,KAAW,EAAS,KAAK,EAChC,CAAC,GAAW,KAAgB,EAAS,GAAG,EACxC,CAAC,GAAQ,KAAa,EAA2B,EAAE,CAAC,EACpD,CAAC,GAAK,MAAU,EAA2E,KAAK,EAChG,CAAC,IAAS,KAAc,EAAS,GAAM,EACvC,CAAC,GAAQ,KAAa,EAAS,GAAM,EACrC,CAAC,IAAW,KAAgB,EAAS,GAAM,EAE3C,IAAgB,QAAc,EAAO,MAAM,MAAM,EAAE,OAAO,EAAQ,EAAE,CAAC,GAAQ,EAAQ,CAAC,EAItF,IAAY,EAAyB,EAAO;AAClD,GAAU,UAAU;CAGpB,IAAM,IAAW,EAAY,YAAY;AAClC,IAAS,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CAAA,CACjE;QAEP;;IACL,EAAO,SAAS,KACf,kBAAC,KAAD;KAAG,WAAU;eAAb;MACG,EAAO;MAAO;MAAO,EAAO,SAAS,IAAI,MAAM;MAAG;MACjD;;IAEF,EAAA,CAAA;GAGN,kBAAC,OAAD;IAAK,WAAU;cAAf,CACE,kBAAC,IAAD,EAAQ,WAAU,oBAAqB,CAAA,EACtC,KACC,kBAAC,QAAD;KAAM,WAAU;eAAhB,CACE,kBAAC,GAAD,EAAS,WAAU,4BAA6B,CAAA,EAAA,qBAC3C;SACL,IACF,kBAAC,QAAD,EAAA,UAAA;KACG,EAAU,EAAI,UAAU,EAAI,UAAU;KAAE;KACzC,kBAAC,QAAD;MAAM,WAAU;gBAAhB;OAAqC;OAAI,KAAK,MAAM,EAAI,SAAS;OAAC;OAAyB;;KACtF,EAAA,CAAA,GAEP,kBAAC,UAAD;KAAQ,MAAK;KAAS,eAAe,KAAK,GAAU;KAAE,WAAU;eAA+B;KAEtF,CAAA,CAEP;;GAGN,kBAAC,GAAD;IAAQ,eAAe,KAAK,IAAQ;IAAE,UAAU,CAAC,KAAW;IAAQ,WAAU;IAAS,MAAK;cAA5F,CACG,IACC,kBAAC,GAAD,EAAS,WAAU,6BAA8B,CAAA,GAC9C,IAED,OADF,kBAAC,IAAD,EAAS,WAAU,gBAAiB,CAAA,EAErC,IAAS,qBAAqB,iBACxB;;GACT,kBAAC,KAAD;IAAG,WAAU;cACV,KACG,2CACA;IACF,CAAA;GACA"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { useBasePath as e } from "../../hooks/useBasePath.js";
|
|
2
|
+
import { PageLayout as t } from "../../components/PageLayout.js";
|
|
3
|
+
import { useOfflineSync as n } from "../../offline/OfflineSyncProvider.js";
|
|
4
|
+
import { typeMeta as r } from "../../offline/observationMeta.js";
|
|
5
|
+
import { useMemo as i, useState as a } from "react";
|
|
6
|
+
import { Loader2 as o, ShieldAlert as s } from "lucide-react";
|
|
7
|
+
import { useNavigate as c, useParams as l } from "react-router-dom";
|
|
8
|
+
import { jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
9
|
+
import { Button as f } from "@burdenoff/fe-libs/ui";
|
|
10
|
+
//#region src/healthybowl/pages/field-capture/ConflictReviewPage.tsx
|
|
11
|
+
var p = [
|
|
12
|
+
{
|
|
13
|
+
key: "fieldName",
|
|
14
|
+
label: "Field"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
key: "note",
|
|
18
|
+
label: "Note"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
key: "severity",
|
|
22
|
+
label: "Severity"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
key: "quantity",
|
|
26
|
+
label: "Count / Qty"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: "unit",
|
|
30
|
+
label: "Unit"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "cropName",
|
|
34
|
+
label: "Crop"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
key: "animalTag",
|
|
38
|
+
label: "Animal"
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
function m(e) {
|
|
42
|
+
return e == null || e === "" ? "—" : String(e);
|
|
43
|
+
}
|
|
44
|
+
var h = ({ title: e, subtitle: t, record: n, other: r, side: i, rows: a }) => /* @__PURE__ */ d("div", {
|
|
45
|
+
className: "flex-1 rounded-xl border border-border-subtle bg-bg-surface p-4",
|
|
46
|
+
children: [
|
|
47
|
+
/* @__PURE__ */ u("p", {
|
|
48
|
+
className: "text-sm font-semibold text-text-primary",
|
|
49
|
+
children: e
|
|
50
|
+
}),
|
|
51
|
+
/* @__PURE__ */ u("p", {
|
|
52
|
+
className: "mb-3 text-xs text-text-tertiary",
|
|
53
|
+
children: t
|
|
54
|
+
}),
|
|
55
|
+
/* @__PURE__ */ u("dl", {
|
|
56
|
+
className: "space-y-2",
|
|
57
|
+
children: a.map((e) => {
|
|
58
|
+
let t = p.find((t) => t.key === e)?.label ?? e, a = m(n[e]) !== m(r[e]);
|
|
59
|
+
return /* @__PURE__ */ d("div", {
|
|
60
|
+
className: `flex items-start justify-between gap-3 rounded-lg px-2 py-1.5 ${a ? "bg-status-warning-bgSubtle" : ""}`,
|
|
61
|
+
children: [/* @__PURE__ */ u("dt", {
|
|
62
|
+
className: "text-xs font-medium text-text-secondary",
|
|
63
|
+
children: t
|
|
64
|
+
}), /* @__PURE__ */ u("dd", {
|
|
65
|
+
className: `text-right text-sm ${a ? i === "server" ? "font-semibold text-status-warning-text" : "font-semibold text-text-primary" : "text-text-primary"}`,
|
|
66
|
+
children: m(n[e])
|
|
67
|
+
})]
|
|
68
|
+
}, e);
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
]
|
|
72
|
+
}), g = () => {
|
|
73
|
+
let { clientId: g = "" } = l(), _ = decodeURIComponent(g), v = c(), { buildPath: y } = e(), { observations: b, resolve: x } = n(), [S, C] = a(null), w = i(() => b.find((e) => e.clientId === _), [b, _]), T = w?.serverVersion, E = w ? {
|
|
74
|
+
fieldName: w.fieldName,
|
|
75
|
+
note: w.note,
|
|
76
|
+
severity: w.severity,
|
|
77
|
+
quantity: w.quantity,
|
|
78
|
+
unit: w.unit,
|
|
79
|
+
cropName: w.cropName,
|
|
80
|
+
animalTag: w.animalTag
|
|
81
|
+
} : {}, D = T ? {
|
|
82
|
+
fieldName: T.fieldName,
|
|
83
|
+
note: T.note,
|
|
84
|
+
severity: T.severity,
|
|
85
|
+
quantity: T.quantity,
|
|
86
|
+
unit: T.unit,
|
|
87
|
+
cropName: T.cropName,
|
|
88
|
+
animalTag: T.animalTag
|
|
89
|
+
} : {}, O = p.map((e) => e.key).filter((e) => m(E[e]) !== "—" || m(D[e]) !== "—"), k = async (e) => {
|
|
90
|
+
if (w) {
|
|
91
|
+
C(e);
|
|
92
|
+
try {
|
|
93
|
+
await x(_, e, e === "KEEP_SERVER" ? void 0 : {
|
|
94
|
+
note: e === "MERGE" ? w.note ?? T?.note ?? null : w.note,
|
|
95
|
+
severity: e === "MERGE" ? w.severity ?? T?.severity ?? null : w.severity,
|
|
96
|
+
quantity: e === "MERGE" ? w.quantity ?? T?.quantity ?? null : w.quantity,
|
|
97
|
+
unit: w.unit,
|
|
98
|
+
cropName: w.cropName,
|
|
99
|
+
animalTag: w.animalTag,
|
|
100
|
+
fieldId: w.fieldId,
|
|
101
|
+
latitude: w.latitude,
|
|
102
|
+
longitude: w.longitude,
|
|
103
|
+
photoFileIds: w.photoFileIds
|
|
104
|
+
}), v(y("field-capture/pending"));
|
|
105
|
+
} catch {} finally {
|
|
106
|
+
C(null);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
if (!w || w.status !== "CONFLICT" || !T) return /* @__PURE__ */ u(t, {
|
|
111
|
+
title: "Sync Conflict",
|
|
112
|
+
description: "Review & resolve a record that changed on the server.",
|
|
113
|
+
children: /* @__PURE__ */ d("div", {
|
|
114
|
+
className: "rounded-2xl border border-border-subtle bg-bg-surface px-6 py-12 text-center",
|
|
115
|
+
children: [/* @__PURE__ */ d("p", {
|
|
116
|
+
className: "text-sm text-text-secondary",
|
|
117
|
+
children: ["This record has no pending conflict", w ? " — it may already be resolved." : "."]
|
|
118
|
+
}), /* @__PURE__ */ u(f, {
|
|
119
|
+
variant: "outline",
|
|
120
|
+
className: "mt-4",
|
|
121
|
+
onClick: () => v(y("field-capture/pending")),
|
|
122
|
+
children: "Back to Pending Sync"
|
|
123
|
+
})]
|
|
124
|
+
})
|
|
125
|
+
});
|
|
126
|
+
let A = r(w.observationType);
|
|
127
|
+
return /* @__PURE__ */ u(t, {
|
|
128
|
+
title: "Sync Conflict — Review & Resolve",
|
|
129
|
+
description: "This record changed on the server since you captured it.",
|
|
130
|
+
children: /* @__PURE__ */ d("div", {
|
|
131
|
+
className: "rounded-2xl border border-border-subtle bg-bg-surface p-5",
|
|
132
|
+
children: [
|
|
133
|
+
/* @__PURE__ */ d("div", {
|
|
134
|
+
className: "mb-4 flex items-center gap-2",
|
|
135
|
+
children: [/* @__PURE__ */ u("span", {
|
|
136
|
+
className: "flex h-8 w-8 items-center justify-center rounded-lg bg-status-warning-bgSubtle",
|
|
137
|
+
children: /* @__PURE__ */ u(s, { className: "h-4 w-4 text-status-warning-text" })
|
|
138
|
+
}), /* @__PURE__ */ d("div", { children: [/* @__PURE__ */ d("p", {
|
|
139
|
+
className: "text-sm font-semibold text-text-primary",
|
|
140
|
+
children: [A.label, w.fieldName ? ` — ${w.fieldName}` : ""]
|
|
141
|
+
}), /* @__PURE__ */ u("p", {
|
|
142
|
+
className: "text-xs text-text-tertiary",
|
|
143
|
+
children: "Side-by-side comparison · diff view"
|
|
144
|
+
})] })]
|
|
145
|
+
}),
|
|
146
|
+
/* @__PURE__ */ d("div", {
|
|
147
|
+
className: "flex flex-col gap-4 md:flex-row",
|
|
148
|
+
children: [/* @__PURE__ */ u(h, {
|
|
149
|
+
title: "Your offline version",
|
|
150
|
+
subtitle: `captured ${new Date(w.capturedAt).toLocaleString(void 0, {
|
|
151
|
+
hour: "2-digit",
|
|
152
|
+
minute: "2-digit"
|
|
153
|
+
})}, offline`,
|
|
154
|
+
record: E,
|
|
155
|
+
other: D,
|
|
156
|
+
side: "mine",
|
|
157
|
+
rows: O
|
|
158
|
+
}), /* @__PURE__ */ u(h, {
|
|
159
|
+
title: "Server version",
|
|
160
|
+
subtitle: `v${T.version}${T.createdBy, ""} · updated on the server`,
|
|
161
|
+
record: D,
|
|
162
|
+
other: E,
|
|
163
|
+
side: "server",
|
|
164
|
+
rows: O
|
|
165
|
+
})]
|
|
166
|
+
}),
|
|
167
|
+
/* @__PURE__ */ d("div", {
|
|
168
|
+
className: "mt-5 flex flex-wrap justify-end gap-2",
|
|
169
|
+
children: [
|
|
170
|
+
/* @__PURE__ */ d(f, {
|
|
171
|
+
variant: "outline",
|
|
172
|
+
disabled: S !== null,
|
|
173
|
+
onClick: () => void k("KEEP_SERVER"),
|
|
174
|
+
children: [S === "KEEP_SERVER" ? /* @__PURE__ */ u(o, { className: "mr-2 h-4 w-4 animate-spin" }) : null, "Keep Server"]
|
|
175
|
+
}),
|
|
176
|
+
/* @__PURE__ */ d(f, {
|
|
177
|
+
variant: "outline",
|
|
178
|
+
disabled: S !== null,
|
|
179
|
+
onClick: () => void k("KEEP_MINE"),
|
|
180
|
+
children: [S === "KEEP_MINE" ? /* @__PURE__ */ u(o, { className: "mr-2 h-4 w-4 animate-spin" }) : null, "Keep Mine"]
|
|
181
|
+
}),
|
|
182
|
+
/* @__PURE__ */ d(f, {
|
|
183
|
+
disabled: S !== null,
|
|
184
|
+
onClick: () => void k("MERGE"),
|
|
185
|
+
children: [S === "MERGE" ? /* @__PURE__ */ u(o, { className: "mr-2 h-4 w-4 animate-spin" }) : null, "Merge & Sync"]
|
|
186
|
+
})
|
|
187
|
+
]
|
|
188
|
+
}),
|
|
189
|
+
/* @__PURE__ */ u("p", {
|
|
190
|
+
className: "mt-3 text-center text-xs text-text-tertiary",
|
|
191
|
+
children: "Conflict detected via clientMutationId — no duplicate was created."
|
|
192
|
+
})
|
|
193
|
+
]
|
|
194
|
+
})
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
//#endregion
|
|
198
|
+
export { g as ConflictReviewPage };
|
|
199
|
+
|
|
200
|
+
//# sourceMappingURL=ConflictReviewPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConflictReviewPage.js","names":[],"sources":["../../../../src/healthybowl/pages/field-capture/ConflictReviewPage.tsx"],"sourcesContent":["/**\n * Sync Conflict — Review & Resolve (BOFF-2883).\n *\n * A record changed on the server since it was captured offline. Rather than\n * silently overwriting, we show a side-by-side diff of the local (\"Your offline\n * version\") and server versions and let the farmer Keep Mine / Keep Server /\n * Merge. Detected via the idempotent clientId — no duplicate was ever created.\n */\nimport { useMemo, useState, type FC } from 'react';\nimport { useNavigate, useParams } from 'react-router-dom';\nimport { ShieldAlert, Loader2 } from 'lucide-react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { PageLayout } from '../../components/PageLayout';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { useOfflineSync } from '../../offline/OfflineSyncProvider';\nimport { typeMeta } from '../../offline/observationMeta';\nimport type { LocalObservation, ServerObservation } from '../../offline/types';\n\ntype FieldKey = 'fieldName' | 'note' | 'severity' | 'quantity' | 'unit' | 'cropName' | 'animalTag';\n\nconst DIFF_FIELDS: Array<{ key: FieldKey; label: string }> = [\n { key: 'fieldName', label: 'Field' },\n { key: 'note', label: 'Note' },\n { key: 'severity', label: 'Severity' },\n { key: 'quantity', label: 'Count / Qty' },\n { key: 'unit', label: 'Unit' },\n { key: 'cropName', label: 'Crop' },\n { key: 'animalTag', label: 'Animal' },\n];\n\nfunction val(v: unknown): string {\n if (v === null || v === undefined || v === '') return '—';\n return String(v);\n}\n\nconst DiffColumn: FC<{\n title: string;\n subtitle: string;\n record: Partial<Record<FieldKey, unknown>>;\n other: Partial<Record<FieldKey, unknown>>;\n side: 'mine' | 'server';\n rows: FieldKey[];\n}> = ({ title, subtitle, record, other, side, rows }) => (\n <div className=\"flex-1 rounded-xl border border-border-subtle bg-bg-surface p-4\">\n <p className=\"text-sm font-semibold text-text-primary\">{title}</p>\n <p className=\"mb-3 text-xs text-text-tertiary\">{subtitle}</p>\n <dl className=\"space-y-2\">\n {rows.map((key) => {\n const label = DIFF_FIELDS.find((f) => f.key === key)?.label ?? key;\n const changed = val(record[key]) !== val(other[key]);\n return (\n <div\n key={key}\n className={`flex items-start justify-between gap-3 rounded-lg px-2 py-1.5 ${\n changed ? 'bg-status-warning-bgSubtle' : ''\n }`}\n >\n <dt className=\"text-xs font-medium text-text-secondary\">{label}</dt>\n <dd\n className={`text-right text-sm ${\n changed\n ? side === 'server'\n ? 'font-semibold text-status-warning-text'\n : 'font-semibold text-text-primary'\n : 'text-text-primary'\n }`}\n >\n {val(record[key])}\n </dd>\n </div>\n );\n })}\n </dl>\n </div>\n);\n\nexport const ConflictReviewPage: FC = () => {\n const { clientId = '' } = useParams();\n const decodedId = decodeURIComponent(clientId);\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n const { observations, resolve } = useOfflineSync();\n const [busy, setBusy] = useState<'KEEP_MINE' | 'KEEP_SERVER' | 'MERGE' | null>(null);\n\n const obs: LocalObservation | undefined = useMemo(\n () => observations.find((o) => o.clientId === decodedId),\n [observations, decodedId]\n );\n const server: ServerObservation | null | undefined = obs?.serverVersion;\n\n const mineRecord: Partial<Record<FieldKey, unknown>> = obs\n ? {\n fieldName: obs.fieldName,\n note: obs.note,\n severity: obs.severity,\n quantity: obs.quantity,\n unit: obs.unit,\n cropName: obs.cropName,\n animalTag: obs.animalTag,\n }\n : {};\n const serverRecord: Partial<Record<FieldKey, unknown>> = server\n ? {\n fieldName: server.fieldName,\n note: server.note,\n severity: server.severity,\n quantity: server.quantity,\n unit: server.unit,\n cropName: server.cropName,\n animalTag: server.animalTag,\n }\n : {};\n\n // Only show fields that exist on either side (keep the diff tight).\n const rows = DIFF_FIELDS.map((f) => f.key).filter((k) => val(mineRecord[k]) !== '—' || val(serverRecord[k]) !== '—');\n\n const onResolve = async (resolution: 'KEEP_MINE' | 'KEEP_SERVER' | 'MERGE') => {\n if (!obs) return;\n setBusy(resolution);\n try {\n const values =\n resolution === 'KEEP_SERVER'\n ? undefined\n : {\n // MERGE prefers my value, falling back to the server's where I have none.\n note: resolution === 'MERGE' ? (obs.note ?? server?.note ?? null) : obs.note,\n severity: resolution === 'MERGE' ? (obs.severity ?? server?.severity ?? null) : obs.severity,\n quantity: resolution === 'MERGE' ? (obs.quantity ?? server?.quantity ?? null) : obs.quantity,\n unit: obs.unit,\n cropName: obs.cropName,\n animalTag: obs.animalTag,\n fieldId: obs.fieldId,\n latitude: obs.latitude,\n longitude: obs.longitude,\n photoFileIds: obs.photoFileIds,\n };\n await resolve(decodedId, resolution, values);\n navigate(buildPath('field-capture/pending'));\n } catch {\n // toast already surfaced by the provider; stay on the page to retry.\n } finally {\n setBusy(null);\n }\n };\n\n if (!obs || obs.status !== 'CONFLICT' || !server) {\n return (\n <PageLayout title=\"Sync Conflict\" description=\"Review & resolve a record that changed on the server.\">\n <div className=\"rounded-2xl border border-border-subtle bg-bg-surface px-6 py-12 text-center\">\n <p className=\"text-sm text-text-secondary\">\n This record has no pending conflict{obs ? ' — it may already be resolved.' : '.'}\n </p>\n <Button variant=\"outline\" className=\"mt-4\" onClick={() => navigate(buildPath('field-capture/pending'))}>\n Back to Pending Sync\n </Button>\n </div>\n </PageLayout>\n );\n }\n\n const meta = typeMeta(obs.observationType);\n\n return (\n <PageLayout\n title=\"Sync Conflict — Review & Resolve\"\n description=\"This record changed on the server since you captured it.\"\n >\n <div className=\"rounded-2xl border border-border-subtle bg-bg-surface p-5\">\n <div className=\"mb-4 flex items-center gap-2\">\n <span className=\"flex h-8 w-8 items-center justify-center rounded-lg bg-status-warning-bgSubtle\">\n <ShieldAlert className=\"h-4 w-4 text-status-warning-text\" />\n </span>\n <div>\n <p className=\"text-sm font-semibold text-text-primary\">\n {meta.label}\n {obs.fieldName ? ` — ${obs.fieldName}` : ''}\n </p>\n <p className=\"text-xs text-text-tertiary\">Side-by-side comparison · diff view</p>\n </div>\n </div>\n\n <div className=\"flex flex-col gap-4 md:flex-row\">\n <DiffColumn\n title=\"Your offline version\"\n subtitle={`captured ${new Date(obs.capturedAt).toLocaleString(undefined, { hour: '2-digit', minute: '2-digit' })}, offline`}\n record={mineRecord}\n other={serverRecord}\n side=\"mine\"\n rows={rows}\n />\n <DiffColumn\n title=\"Server version\"\n subtitle={`v${server.version}${server.createdBy ? '' : ''} · updated on the server`}\n record={serverRecord}\n other={mineRecord}\n side=\"server\"\n rows={rows}\n />\n </div>\n\n <div className=\"mt-5 flex flex-wrap justify-end gap-2\">\n <Button variant=\"outline\" disabled={busy !== null} onClick={() => void onResolve('KEEP_SERVER')}>\n {busy === 'KEEP_SERVER' ? <Loader2 className=\"mr-2 h-4 w-4 animate-spin\" /> : null}\n Keep Server\n </Button>\n <Button variant=\"outline\" disabled={busy !== null} onClick={() => void onResolve('KEEP_MINE')}>\n {busy === 'KEEP_MINE' ? <Loader2 className=\"mr-2 h-4 w-4 animate-spin\" /> : null}\n Keep Mine\n </Button>\n <Button disabled={busy !== null} onClick={() => void onResolve('MERGE')}>\n {busy === 'MERGE' ? <Loader2 className=\"mr-2 h-4 w-4 animate-spin\" /> : null}\n Merge & Sync\n </Button>\n </div>\n <p className=\"mt-3 text-center text-xs text-text-tertiary\">\n Conflict detected via clientMutationId — no duplicate was created.\n </p>\n </div>\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;AAoBA,IAAM,IAAuD;CAC3D;EAAE,KAAK;EAAa,OAAO;EAAS;CACpC;EAAE,KAAK;EAAQ,OAAO;EAAQ;CAC9B;EAAE,KAAK;EAAY,OAAO;EAAY;CACtC;EAAE,KAAK;EAAY,OAAO;EAAe;CACzC;EAAE,KAAK;EAAQ,OAAO;EAAQ;CAC9B;EAAE,KAAK;EAAY,OAAO;EAAQ;CAClC;EAAE,KAAK;EAAa,OAAO;EAAU;CACtC;AAED,SAAS,EAAI,GAAoB;AAE/B,QADI,KAAM,QAA2B,MAAM,KAAW,MAC/C,OAAO,EAAE;;AAGlB,IAAM,KAOA,EAAE,UAAO,aAAU,WAAQ,UAAO,SAAM,cAC5C,kBAAC,OAAD;CAAK,WAAU;WAAf;EACE,kBAAC,KAAD;GAAG,WAAU;aAA2C;GAAU,CAAA;EAClE,kBAAC,KAAD;GAAG,WAAU;aAAmC;GAAa,CAAA;EAC7D,kBAAC,MAAD;GAAI,WAAU;aACX,EAAK,KAAK,MAAQ;IACjB,IAAM,IAAQ,EAAY,MAAM,MAAM,EAAE,QAAQ,EAAI,EAAE,SAAS,GACzD,IAAU,EAAI,EAAO,GAAK,KAAK,EAAI,EAAM,GAAK;AACpD,WACE,kBAAC,OAAD;KAEE,WAAW,iEACT,IAAU,+BAA+B;eAH7C,CAME,kBAAC,MAAD;MAAI,WAAU;g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AAO,WAAY,GAAQ;MAC1D,QAAQ;MACR,OAAO;MACP,MAAK;MACC;MACN,CAAA,CACE;;IAEN,kBAAC,OAAD;KAAK,WAAU;eAAf;MACE,kBAAC,GAAD;OAAQ,SAAQ;OAAU,UAAU,MAAS;OAAM,eAAe,KAAK,EAAU,cAAc;iBAA/F,CACG,MAAS,gBAAgB,kBAAC,GAAD,EAAS,WAAU,6BAA8B,CAAA,GAAG,MAAK,cAE5E;;MACT,kBAAC,GAAD;OAAQ,SAAQ;OAAU,UAAU,MAAS;OAAM,eAAe,KAAK,EAAU,YAAY;iBAA7F,CACG,MAAS,cAAc,kBAAC,GAAD,EAAS,WAAU,6BAA8B,CAAA,GAAG,MAAK,YAE1E;;MACT,kBAAC,GAAD;OAAQ,UAAU,MAAS;OAAM,eAAe,KAAK,EAAU,QAAQ;iBAAvE,CACG,MAAS,UAAU,kBAAC,GAAD,EAAS,WAAU,6BAA8B,CAAA,GAAG,MAAK,eAEtE;;MACL;;IACN,kBAAC,KAAD;KAAG,WAAU;eAA8C;KAEvD,CAAA;IACA;;EACK,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useBasePath as e } from "../../hooks/useBasePath.js";
|
|
2
|
+
import { PageLayout as t } from "../../components/PageLayout.js";
|
|
3
|
+
import { OfflineStatusPill as n } from "../../offline/OfflineStatusPill.js";
|
|
4
|
+
import { CaptureObservationForm as r } from "./CaptureObservationForm.js";
|
|
5
|
+
import { SyncQueuePanel as i } from "./SyncQueuePanel.js";
|
|
6
|
+
import { History as a, ListChecks as o, Settings2 as s } from "lucide-react";
|
|
7
|
+
import { Link as c } from "react-router-dom";
|
|
8
|
+
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
9
|
+
import { Card as d, CardContent as f } from "@burdenoff/fe-libs/ui";
|
|
10
|
+
//#region src/healthybowl/pages/field-capture/FieldCapturePage.tsx
|
|
11
|
+
var p = () => {
|
|
12
|
+
let { buildPath: t } = e(), n = "inline-flex items-center gap-1.5 rounded-lg border border-border-subtle bg-bg-surface px-3 py-1.5 text-sm font-medium text-text-secondary transition hover:bg-bg-sunken";
|
|
13
|
+
return /* @__PURE__ */ u("div", {
|
|
14
|
+
className: "flex flex-wrap gap-2",
|
|
15
|
+
children: [
|
|
16
|
+
/* @__PURE__ */ u(c, {
|
|
17
|
+
to: t("field-capture/pending"),
|
|
18
|
+
className: n,
|
|
19
|
+
children: [/* @__PURE__ */ l(o, { className: "h-4 w-4" }), " Pending Sync"]
|
|
20
|
+
}),
|
|
21
|
+
/* @__PURE__ */ u(c, {
|
|
22
|
+
to: t("field-capture/history"),
|
|
23
|
+
className: n,
|
|
24
|
+
children: [/* @__PURE__ */ l(a, { className: "h-4 w-4" }), " History"]
|
|
25
|
+
}),
|
|
26
|
+
/* @__PURE__ */ u(c, {
|
|
27
|
+
to: t("field-capture/settings"),
|
|
28
|
+
className: n,
|
|
29
|
+
children: [/* @__PURE__ */ l(s, { className: "h-4 w-4" }), " Settings"]
|
|
30
|
+
})
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
}, m = () => /* @__PURE__ */ u(t, {
|
|
34
|
+
title: "Field Data Capture",
|
|
35
|
+
titleAccent: "Capture",
|
|
36
|
+
description: "Record what you see in the field — even with no signal. Every entry is saved on your device and uploads itself the moment you're back online.",
|
|
37
|
+
actions: /* @__PURE__ */ l(p, {}),
|
|
38
|
+
hero: !0,
|
|
39
|
+
purpose: "Log pest sightings, crop-health notes, soil notes, harvest counts and livestock checks — with photos and GPS — fully offline. Writes go to a local queue and sync automatically on reconnect, with no duplicates and honest conflict review.",
|
|
40
|
+
children: [/* @__PURE__ */ l(n, {}), /* @__PURE__ */ u("div", {
|
|
41
|
+
className: "grid gap-5 lg:grid-cols-[minmax(0,1fr)_380px]",
|
|
42
|
+
children: [/* @__PURE__ */ l(d, { children: /* @__PURE__ */ u(f, {
|
|
43
|
+
className: "pt-5",
|
|
44
|
+
children: [/* @__PURE__ */ l("h2", {
|
|
45
|
+
className: "mb-4 text-lg font-semibold text-text-primary",
|
|
46
|
+
children: "Capture Observation"
|
|
47
|
+
}), /* @__PURE__ */ l(r, {})]
|
|
48
|
+
}) }), /* @__PURE__ */ u("div", {
|
|
49
|
+
className: "space-y-3",
|
|
50
|
+
children: [/* @__PURE__ */ l(i, { limit: 8 }), /* @__PURE__ */ l("p", {
|
|
51
|
+
className: "px-1 text-center text-xs text-text-tertiary",
|
|
52
|
+
children: "Works fully offline · syncs automatically on reconnect"
|
|
53
|
+
})]
|
|
54
|
+
})]
|
|
55
|
+
})]
|
|
56
|
+
});
|
|
57
|
+
//#endregion
|
|
58
|
+
export { m as FieldCapturePage };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=FieldCapturePage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldCapturePage.js","names":[],"sources":["../../../../src/healthybowl/pages/field-capture/FieldCapturePage.tsx"],"sourcesContent":["/**\n * Field Data Capture — Offline Mode (BOFF-2883), the headline screen.\n *\n * Left: the offline-first Capture Observation form. Right: the live Sync Queue.\n * A persistent connectivity pill sits at the top. Everything works with zero\n * connectivity and drains automatically on reconnect.\n */\nimport { type FC } from 'react';\nimport { Link } from 'react-router-dom';\nimport { History, Settings2, ListChecks } from 'lucide-react';\nimport { Card, CardContent } from '@burdenoff/fe-libs/ui';\nimport { PageLayout } from '../../components/PageLayout';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { OfflineStatusPill } from '../../offline/OfflineStatusPill';\nimport { CaptureObservationForm } from './CaptureObservationForm';\nimport { SyncQueuePanel } from './SyncQueuePanel';\n\nconst HeaderActions: FC = () => {\n const { buildPath } = useBasePath();\n const item =\n 'inline-flex items-center gap-1.5 rounded-lg border border-border-subtle bg-bg-surface px-3 py-1.5 text-sm font-medium text-text-secondary transition hover:bg-bg-sunken';\n return (\n <div className=\"flex flex-wrap gap-2\">\n <Link to={buildPath('field-capture/pending')} className={item}>\n <ListChecks className=\"h-4 w-4\" /> Pending Sync\n </Link>\n <Link to={buildPath('field-capture/history')} className={item}>\n <History className=\"h-4 w-4\" /> History\n </Link>\n <Link to={buildPath('field-capture/settings')} className={item}>\n <Settings2 className=\"h-4 w-4\" /> Settings\n </Link>\n </div>\n );\n};\n\nexport const FieldCapturePage: FC = () => {\n return (\n <PageLayout\n title=\"Field Data Capture\"\n titleAccent=\"Capture\"\n description=\"Record what you see in the field — even with no signal. Every entry is saved on your device and uploads itself the moment you're back online.\"\n actions={<HeaderActions />}\n hero\n purpose=\"Log pest sightings, crop-health notes, soil notes, harvest counts and livestock checks — with photos and GPS — fully offline. Writes go to a local queue and sync automatically on reconnect, with no duplicates and honest conflict review.\"\n >\n <OfflineStatusPill />\n\n <div className=\"grid gap-5 lg:grid-cols-[minmax(0,1fr)_380px]\">\n <Card>\n <CardContent className=\"pt-5\">\n <h2 className=\"mb-4 text-lg font-semibold text-text-primary\">Capture Observation</h2>\n <CaptureObservationForm />\n </CardContent>\n </Card>\n\n <div className=\"space-y-3\">\n <SyncQueuePanel limit={8} />\n <p className=\"px-1 text-center text-xs text-text-tertiary\">\n Works fully offline · syncs automatically on reconnect\n </p>\n </div>\n </div>\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;AAiBA,IAAM,UAA0B;CAC9B,IAAM,EAAE,iBAAc,GAAa,EAC7B,IACJ;AACF,QACE,kBAAC,OAAD;EAAK,WAAU;YAAf;GACE,kBAAC,GAAD;IAAM,IAAI,EAAU,wBAAwB;IAAE,WAAW;cAAzD,CACE,kBAAC,GAAD,EAAY,WAAU,WAAY,CAAA,EAAA,gBAC7B;;GACP,kBAAC,GAAD;IAAM,IAAI,EAAU,wBAAwB;IAAE,WAAW;cAAzD,CACE,kBAAC,GAAD,EAAS,WAAU,WAAY,CAAA,EAAA,WAC1B;;GACP,kBAAC,GAAD;IAAM,IAAI,EAAU,yBAAyB;IAAE,WAAW;cAA1D,CACE,kBAAC,GAAD,EAAW,WAAU,WAAY,CAAA,EAAA,YAC5B;;GACH;;GAIG,UAET,kBAAC,GAAD;CACE,OAAM;CACN,aAAY;CACZ,aAAY;CACZ,SAAS,kBAAC,GAAD,EAAiB,CAAA;CAC1B,MAAA;CACA,SAAQ;WANV,CAQE,kBAAC,GAAD,EAAqB,CAAA,EAErB,kBAAC,OAAD;EAAK,WAAU;YAAf,CACE,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD;GAAa,WAAU;aAAvB,CACE,kBAAC,MAAD;IAAI,WAAU;cAA+C;IAAwB,CAAA,EACrF,kBAAC,GAAD,EAA0B,CAAA,CACd;MACT,CAAA,EAEP,kBAAC,OAAD;GAAK,WAAU;aAAf,CACE,kBAAC,GAAD,EAAgB,OAAO,GAAK,CAAA,EAC5B,kBAAC,KAAD;IAAG,WAAU;cAA8C;IAEvD,CAAA,CACA;KACF;IACK"}
|