@burdenoff/microfe-healthybowl 2026.610.1 → 2026.610.2
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/healthybowl/pages/crops/CropDetailsPage.js +34 -27
- package/dist/healthybowl/pages/crops/CropDetailsPage.js.map +1 -1
- package/dist/healthybowl/pages/financial/FinancierAccessPage.js +124 -101
- package/dist/healthybowl/pages/financial/FinancierAccessPage.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,14 +7,15 @@ import { ErrorState as a } from "../../components/ErrorState.js";
|
|
|
7
7
|
import { ToastContainer as ee } from "../../components/Toast.js";
|
|
8
8
|
import { Breadcrumbs as te } from "../../components/Breadcrumbs.js";
|
|
9
9
|
import { Modal as ne } from "../../components/Modal.js";
|
|
10
|
+
import { HBEntityTags as re } from "../../components/HBEntityTags.js";
|
|
10
11
|
import "../../components/index.js";
|
|
11
|
-
import { useHealthyBowlData as
|
|
12
|
-
import { useToast as
|
|
13
|
-
import { isNative as
|
|
14
|
-
import { useEffect as
|
|
15
|
-
import { AlertTriangle as
|
|
16
|
-
import { useNavigate as
|
|
17
|
-
import { Fragment as
|
|
12
|
+
import { useHealthyBowlData as o } from "../../hooks/useHealthyBowlData.js";
|
|
13
|
+
import { useToast as s } from "../../hooks/useToast.js";
|
|
14
|
+
import { isNative as c, nativeConfirm as l, nativeNotify as u, nativeToast as d } from "../../../utils/nativeBridge.js";
|
|
15
|
+
import { useEffect as f, useState as p } from "react";
|
|
16
|
+
import { AlertTriangle as ie, ArrowLeft as ae, Calendar as m, Droplets as oe, Edit as se, Leaf as h, MapPin as g, Sprout as _, Sun as ce, Trash2 as le, TrendingUp as v } from "lucide-react";
|
|
17
|
+
import { useNavigate as ue, useParams as de } from "react-router-dom";
|
|
18
|
+
import { Fragment as fe, jsx as y, jsxs as b } from "react/jsx-runtime";
|
|
18
19
|
//#region src/healthybowl/pages/crops/CropDetailsPage.tsx
|
|
19
20
|
var x = (e) => {
|
|
20
21
|
switch (e) {
|
|
@@ -23,7 +24,7 @@ var x = (e) => {
|
|
|
23
24
|
case "fair": return "warning";
|
|
24
25
|
default: return "error";
|
|
25
26
|
}
|
|
26
|
-
},
|
|
27
|
+
}, pe = (e) => {
|
|
27
28
|
switch (e) {
|
|
28
29
|
case "harvest_ready": return "success";
|
|
29
30
|
case "growing":
|
|
@@ -38,12 +39,12 @@ var x = (e) => {
|
|
|
38
39
|
"Fruiting",
|
|
39
40
|
"Mature"
|
|
40
41
|
], C = () => {
|
|
41
|
-
let { crops: C, fields:
|
|
42
|
-
|
|
42
|
+
let { crops: C, fields: me, errors: w, updateCrop: T, deleteCrop: E } = o(), { cropId: D } = de(), O = ue(), { buildPath: k } = e(), { toasts: A, toast: j, dismiss: M } = s(), [N, P] = p(!1), [F, I] = p(!1), [L, R] = p(() => C.find((e) => e.id === D));
|
|
43
|
+
f(() => {
|
|
43
44
|
let e = C.find((e) => e.id === D);
|
|
44
45
|
e && R(e);
|
|
45
46
|
}, [C, D]);
|
|
46
|
-
let [z, B] =
|
|
47
|
+
let [z, B] = p(""), [V, H] = p(""), [U, W] = p(""), [G, K] = p(""), [q, J] = p(""), [Y, X] = p("good"), he = () => {
|
|
47
48
|
L && (B(L.name), H(L.variety), W(L.category), K(String(L.yieldEstimate)), J(L.expectedHarvestDate), X(L.healthStatus), P(!0));
|
|
48
49
|
};
|
|
49
50
|
if (!L) return /* @__PURE__ */ y(n, {
|
|
@@ -58,7 +59,7 @@ var x = (e) => {
|
|
|
58
59
|
})
|
|
59
60
|
})
|
|
60
61
|
});
|
|
61
|
-
let Z =
|
|
62
|
+
let Z = me.find((e) => e.id === L.field || e.name === L.fieldName), Q = S.indexOf(L.growthStage), $ = L.daysToHarvest, ge = Z ? Math.round(L.yieldEstimate / Z.area) : L.yieldEstimate;
|
|
62
63
|
return L ? /* @__PURE__ */ b(n, {
|
|
63
64
|
title: L.name,
|
|
64
65
|
description: `${L.variety} - ${L.category}`,
|
|
@@ -66,13 +67,13 @@ var x = (e) => {
|
|
|
66
67
|
className: "flex items-center gap-2",
|
|
67
68
|
children: [
|
|
68
69
|
/* @__PURE__ */ b("button", {
|
|
69
|
-
onClick:
|
|
70
|
+
onClick: he,
|
|
70
71
|
className: "inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50",
|
|
71
|
-
children: [/* @__PURE__ */ y(
|
|
72
|
+
children: [/* @__PURE__ */ y(se, { className: "h-4 w-4" }), " Edit"]
|
|
72
73
|
}),
|
|
73
74
|
/* @__PURE__ */ b("button", {
|
|
74
75
|
onClick: async () => {
|
|
75
|
-
if (L && await
|
|
76
|
+
if (L && await l({
|
|
76
77
|
title: "Delete crop?",
|
|
77
78
|
message: `${L.name} will be permanently removed.`,
|
|
78
79
|
okButtonTitle: "Delete",
|
|
@@ -84,7 +85,7 @@ var x = (e) => {
|
|
|
84
85
|
title: "Crop deleted",
|
|
85
86
|
description: `${L.name} has been removed.`,
|
|
86
87
|
variant: "success"
|
|
87
|
-
}),
|
|
88
|
+
}), c() && (d("Crop deleted"), u("success")), O(k("crops"));
|
|
88
89
|
} catch (e) {
|
|
89
90
|
j({
|
|
90
91
|
title: "Delete failed",
|
|
@@ -96,12 +97,12 @@ var x = (e) => {
|
|
|
96
97
|
},
|
|
97
98
|
disabled: F,
|
|
98
99
|
className: "inline-flex items-center gap-1.5 rounded-md border border-destructive px-3 py-2 text-sm text-destructive hover:bg-destructive/10 disabled:opacity-60",
|
|
99
|
-
children: [/* @__PURE__ */ y(
|
|
100
|
+
children: [/* @__PURE__ */ y(le, { className: "h-4 w-4" }), " Delete"]
|
|
100
101
|
}),
|
|
101
102
|
/* @__PURE__ */ b("button", {
|
|
102
103
|
onClick: () => O(k("crops")),
|
|
103
104
|
className: "inline-flex items-center gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50",
|
|
104
|
-
children: [/* @__PURE__ */ y(
|
|
105
|
+
children: [/* @__PURE__ */ y(ae, { className: "h-4 w-4" }), " Back"]
|
|
105
106
|
})
|
|
106
107
|
]
|
|
107
108
|
}),
|
|
@@ -115,7 +116,7 @@ var x = (e) => {
|
|
|
115
116
|
children: [
|
|
116
117
|
/* @__PURE__ */ y(r, {
|
|
117
118
|
label: (L.status ?? "unknown").replace("_", " "),
|
|
118
|
-
variant:
|
|
119
|
+
variant: pe(L.status ?? "unknown"),
|
|
119
120
|
dot: !0
|
|
120
121
|
}),
|
|
121
122
|
/* @__PURE__ */ y(r, {
|
|
@@ -133,6 +134,12 @@ var x = (e) => {
|
|
|
133
134
|
})
|
|
134
135
|
]
|
|
135
136
|
}),
|
|
137
|
+
/* @__PURE__ */ y(re, {
|
|
138
|
+
entityType: "CROP",
|
|
139
|
+
entityId: L.id,
|
|
140
|
+
tags: L.entityTags ?? [],
|
|
141
|
+
className: "mt-1"
|
|
142
|
+
}),
|
|
136
143
|
/* @__PURE__ */ b("div", {
|
|
137
144
|
className: "grid grid-cols-1 gap-6 lg:grid-cols-3",
|
|
138
145
|
children: [/* @__PURE__ */ b("div", {
|
|
@@ -142,7 +149,7 @@ var x = (e) => {
|
|
|
142
149
|
className: "rounded-lg border border-border bg-card p-6",
|
|
143
150
|
children: [/* @__PURE__ */ b("h3", {
|
|
144
151
|
className: "mb-4 flex items-center gap-2 text-sm font-semibold text-foreground",
|
|
145
|
-
children: [/* @__PURE__ */ y(
|
|
152
|
+
children: [/* @__PURE__ */ y(ce, { className: "h-4 w-4 text-warning" }), " Crop Overview"]
|
|
146
153
|
}), /* @__PURE__ */ y("div", {
|
|
147
154
|
className: "grid grid-cols-2 gap-4 md:grid-cols-4",
|
|
148
155
|
children: [
|
|
@@ -152,12 +159,12 @@ var x = (e) => {
|
|
|
152
159
|
value: L.category
|
|
153
160
|
},
|
|
154
161
|
{
|
|
155
|
-
icon:
|
|
162
|
+
icon: m,
|
|
156
163
|
label: "Season",
|
|
157
164
|
value: L.season
|
|
158
165
|
},
|
|
159
166
|
{
|
|
160
|
-
icon:
|
|
167
|
+
icon: h,
|
|
161
168
|
label: "Growth Stage",
|
|
162
169
|
value: L.growthStage
|
|
163
170
|
},
|
|
@@ -226,7 +233,7 @@ var x = (e) => {
|
|
|
226
233
|
children: [
|
|
227
234
|
/* @__PURE__ */ b("h3", {
|
|
228
235
|
className: "mb-4 flex items-center gap-2 text-sm font-semibold text-foreground",
|
|
229
|
-
children: [/* @__PURE__ */ y(
|
|
236
|
+
children: [/* @__PURE__ */ y(m, { className: "h-4 w-4 text-info" }), " Timeline"]
|
|
230
237
|
}),
|
|
231
238
|
/* @__PURE__ */ b("div", {
|
|
232
239
|
className: "grid grid-cols-1 gap-4 md:grid-cols-2",
|
|
@@ -366,7 +373,7 @@ var x = (e) => {
|
|
|
366
373
|
className: "mt-3 rounded-lg bg-warning/10 p-3",
|
|
367
374
|
children: /* @__PURE__ */ b("div", {
|
|
368
375
|
className: "flex items-start gap-2",
|
|
369
|
-
children: [/* @__PURE__ */ y(
|
|
376
|
+
children: [/* @__PURE__ */ y(ie, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-warning" }), /* @__PURE__ */ y("p", {
|
|
370
377
|
className: "text-xs text-warning",
|
|
371
378
|
children: "This crop needs attention. Check for potential issues."
|
|
372
379
|
})]
|
|
@@ -394,7 +401,7 @@ var x = (e) => {
|
|
|
394
401
|
className: "mt-2 text-xs text-muted-foreground",
|
|
395
402
|
children: [
|
|
396
403
|
"~",
|
|
397
|
-
|
|
404
|
+
ge,
|
|
398
405
|
" ",
|
|
399
406
|
L.yieldUnit,
|
|
400
407
|
" per ",
|
|
@@ -420,7 +427,7 @@ var x = (e) => {
|
|
|
420
427
|
/* @__PURE__ */ b("button", {
|
|
421
428
|
onClick: () => O(k("weather")),
|
|
422
429
|
className: "flex w-full items-center gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50",
|
|
423
|
-
children: [/* @__PURE__ */ y(
|
|
430
|
+
children: [/* @__PURE__ */ y(oe, { className: "h-4 w-4 text-muted-foreground" }), " Check Weather"]
|
|
424
431
|
}),
|
|
425
432
|
Z && /* @__PURE__ */ b("button", {
|
|
426
433
|
onClick: () => O(k(`crops/fields/${Z.id}`)),
|
|
@@ -444,7 +451,7 @@ var x = (e) => {
|
|
|
444
451
|
title: `Edit ${L.name}`,
|
|
445
452
|
description: "Update crop details",
|
|
446
453
|
size: "lg",
|
|
447
|
-
footer: /* @__PURE__ */ b(
|
|
454
|
+
footer: /* @__PURE__ */ b(fe, { children: [/* @__PURE__ */ y("button", {
|
|
448
455
|
onClick: () => P(!1),
|
|
449
456
|
className: "rounded-md border border-border px-4 py-2 text-sm text-muted-foreground hover:text-foreground",
|
|
450
457
|
children: "Cancel"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CropDetailsPage.js","names":[],"sources":["../../../../src/healthybowl/pages/crops/CropDetailsPage.tsx"],"sourcesContent":["import { useState, useEffect, type FC } from 'react';\nimport { useParams, useNavigate } from 'react-router-dom';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport {\n ArrowLeft,\n Calendar,\n MapPin,\n Sprout,\n Edit,\n Trash2,\n Droplets,\n Sun,\n AlertTriangle,\n TrendingUp,\n Leaf,\n} from 'lucide-react';\nimport { PageLayout, StatusBadge, EmptyState, ErrorState, Breadcrumbs, Modal } from '../../components';\nimport { useHealthyBowlData } from '../../hooks/useHealthyBowlData';\nimport { formatDate } from '../../utils/helpers';\nimport { useToast } from '../../hooks/useToast';\nimport { ToastContainer } from '../../components/Toast';\nimport type { Crop, HealthStatus } from '../../types';\nimport { isNative, nativeConfirm, nativeNotify, nativeToast } from '../../../utils/nativeBridge';\n\nconst healthVariant = (s: string) => {\n switch (s) {\n case 'excellent':\n return 'success' as const;\n case 'good':\n return 'info' as const;\n case 'fair':\n return 'warning' as const;\n default:\n return 'error' as const;\n }\n};\n\nconst statusVariant = (s: string) => {\n switch (s) {\n case 'harvest_ready':\n return 'success' as const;\n case 'growing':\n case 'fruiting':\n return 'info' as const;\n case 'planted':\n return 'muted' as const;\n default:\n return 'default' as const;\n }\n};\n\nconst stages = ['Seedling', 'Vegetative', 'Flowering', 'Fruiting', 'Mature'];\n\nexport const CropDetailsPage: FC = () => {\n const { crops, fields, errors, updateCrop, deleteCrop } = useHealthyBowlData();\n\n const { cropId } = useParams<{ cropId: string }>();\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n const { toasts, toast, dismiss } = useToast();\n const [showEditModal, setShowEditModal] = useState(false);\n const [submitting, setSubmitting] = useState(false);\n\n const [localCrop, setLocalCrop] = useState<Crop | undefined>(() => crops.find((c) => c.id === cropId));\n\n useEffect(() => {\n const found = crops.find((c) => c.id === cropId);\n if (found) setLocalCrop(found);\n }, [crops, cropId]);\n\n // Edit form controlled state\n const [editName, setEditName] = useState('');\n const [editVariety, setEditVariety] = useState('');\n const [editCategory, setEditCategory] = useState('');\n const [editYieldEstimate, setEditYieldEstimate] = useState('');\n const [editExpectedHarvestDate, setEditExpectedHarvestDate] = useState('');\n const [editHealthStatus, setEditHealthStatus] = useState<HealthStatus>('good');\n\n const openEditModal = () => {\n if (!localCrop) return;\n setEditName(localCrop.name);\n setEditVariety(localCrop.variety);\n setEditCategory(localCrop.category);\n setEditYieldEstimate(String(localCrop.yieldEstimate));\n setEditExpectedHarvestDate(localCrop.expectedHarvestDate);\n setEditHealthStatus(localCrop.healthStatus);\n setShowEditModal(true);\n };\n\n if (!localCrop) {\n return (\n <PageLayout title=\"Crop Not Found\">\n {errors.crops ? (\n <ErrorState />\n ) : (\n <EmptyState\n title=\"Crop not found\"\n description=\"The crop you are looking for does not exist.\"\n action={\n <button\n onClick={() => navigate(buildPath('crops'))}\n className=\"rounded-md bg-primary px-4 py-2 text-sm text-primary-foreground\"\n >\n Back to Crops\n </button>\n }\n />\n )}\n </PageLayout>\n );\n }\n\n const field = fields.find((f) => f.id === localCrop.field || f.name === localCrop.fieldName);\n const stageIndex = stages.indexOf(localCrop.growthStage);\n const daysUntilHarvest = localCrop.daysToHarvest;\n const yieldPerAcre = field ? Math.round(localCrop.yieldEstimate / field.area) : localCrop.yieldEstimate;\n\n const handleDelete = async () => {\n if (!localCrop) return;\n const confirmed = await nativeConfirm({\n title: 'Delete crop?',\n message: `${localCrop.name} will be permanently removed.`,\n okButtonTitle: 'Delete',\n cancelButtonTitle: 'Cancel',\n });\n if (confirmed === false) return;\n setSubmitting(true);\n try {\n await deleteCrop(localCrop.id);\n toast({ title: 'Crop deleted', description: `${localCrop.name} has been removed.`, variant: 'success' });\n if (isNative()) {\n void nativeToast('Crop deleted');\n void nativeNotify('success');\n }\n navigate(buildPath('crops'));\n } catch (err) {\n toast({ title: 'Delete failed', description: String(err), variant: 'error' });\n setSubmitting(false);\n }\n };\n\n const handleSaveEdit = async () => {\n if (!localCrop) return;\n if (!editName.trim()) {\n toast({ title: 'Missing required fields', description: 'Crop name is required.', variant: 'warning' });\n return;\n }\n setSubmitting(true);\n try {\n await updateCrop({\n id: localCrop.id,\n name: editName.trim(),\n variety: editVariety,\n category: editCategory,\n yieldEstimate: editYieldEstimate ? Number(editYieldEstimate) : undefined,\n expectedHarvestDate: editExpectedHarvestDate || undefined,\n healthStatus: editHealthStatus,\n });\n toast({ title: 'Crop updated', description: `${editName.trim()} details have been saved.`, variant: 'success' });\n setShowEditModal(false);\n } catch (err) {\n toast({ title: 'Update failed', description: String(err), variant: 'error' });\n } finally {\n setSubmitting(false);\n }\n };\n\n if (!localCrop) {\n return (\n <PageLayout title=\"Crop Not Found\" description=\"The requested crop could not be found.\">\n <div className=\"flex flex-col items-center justify-center py-12 text-center\">\n <p className=\"text-muted-foreground\">This crop may have been removed or the ID is invalid.</p>\n <button\n onClick={() => navigate(buildPath('crops'))}\n className=\"mt-4 rounded-md bg-primary px-4 py-2 text-sm text-primary-foreground\"\n >\n Back to Crops\n </button>\n </div>\n </PageLayout>\n );\n }\n\n return (\n <PageLayout\n title={localCrop.name}\n description={`${localCrop.variety} - ${localCrop.category}`}\n actions={\n <div className=\"flex items-center gap-2\">\n <button\n onClick={openEditModal}\n className=\"inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50\"\n >\n <Edit className=\"h-4 w-4\" /> Edit\n </button>\n <button\n onClick={handleDelete}\n disabled={submitting}\n className=\"inline-flex items-center gap-1.5 rounded-md border border-destructive px-3 py-2 text-sm text-destructive hover:bg-destructive/10 disabled:opacity-60\"\n >\n <Trash2 className=\"h-4 w-4\" /> Delete\n </button>\n <button\n onClick={() => navigate(buildPath('crops'))}\n className=\"inline-flex items-center gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50\"\n >\n <ArrowLeft className=\"h-4 w-4\" /> Back\n </button>\n </div>\n }\n >\n <Breadcrumbs items={[{ label: 'Crops', href: buildPath('crops') }, { label: localCrop.name }]} />\n\n {/* Status Row */}\n <div className=\"flex flex-wrap items-center gap-3\">\n <StatusBadge\n label={(localCrop.status ?? 'unknown').replace('_', ' ')}\n variant={statusVariant(localCrop.status ?? 'unknown')}\n dot\n />\n <StatusBadge label={localCrop.healthStatus} variant={healthVariant(localCrop.healthStatus)} dot />\n {localCrop.organicCertified && <StatusBadge label=\"Organic Certified\" variant=\"success\" />}\n <StatusBadge label={localCrop.season} variant=\"muted\" />\n </div>\n\n <div className=\"grid grid-cols-1 gap-6 lg:grid-cols-3\">\n {/* Main Content */}\n <div className=\"space-y-6 lg:col-span-2\">\n {/* Overview */}\n <div className=\"rounded-lg border border-border bg-card p-6\">\n <h3 className=\"mb-4 flex items-center gap-2 text-sm font-semibold text-foreground\">\n <Sun className=\"h-4 w-4 text-warning\" /> Crop Overview\n </h3>\n <div className=\"grid grid-cols-2 gap-4 md:grid-cols-4\">\n {[\n { icon: Sprout, label: 'Category', value: localCrop.category },\n { icon: Calendar, label: 'Season', value: localCrop.season },\n { icon: Leaf, label: 'Growth Stage', value: localCrop.growthStage },\n { icon: MapPin, label: 'Field', value: localCrop.fieldName },\n ].map(({ icon: Icon, label, value }) => (\n <div key={label}>\n <div className=\"flex items-center gap-1 text-muted-foreground\">\n <Icon className=\"h-3.5 w-3.5\" />\n <span className=\"text-xs\">{label}</span>\n </div>\n <p className=\"mt-1 text-sm font-semibold capitalize text-foreground\">{value}</p>\n </div>\n ))}\n </div>\n </div>\n\n {/* Field Info */}\n {field && (\n <div className=\"rounded-lg border border-border bg-card p-6\">\n <h3 className=\"mb-4 flex items-center gap-2 text-sm font-semibold text-foreground\">\n <MapPin className=\"h-4 w-4 text-success\" /> Field Details\n </h3>\n <div className=\"grid grid-cols-2 gap-4 md:grid-cols-4\">\n <div>\n <span className=\"text-xs text-muted-foreground\">Field</span>\n <p className=\"text-sm font-semibold text-foreground\">{field.name}</p>\n </div>\n <div>\n <span className=\"text-xs text-muted-foreground\">Area</span>\n <p className=\"text-sm font-semibold text-foreground\">\n {field.area} {field.unit}\n </p>\n </div>\n <div>\n <span className=\"text-xs text-muted-foreground\">Soil Type</span>\n <p className=\"text-sm font-semibold text-foreground\">{field.soilType}</p>\n </div>\n <div>\n <span className=\"text-xs text-muted-foreground\">Irrigation</span>\n <p className=\"text-sm font-semibold text-foreground\">{field.irrigationType}</p>\n </div>\n </div>\n </div>\n )}\n\n {/* Timeline */}\n <div className=\"rounded-lg border border-border bg-card p-6\">\n <h3 className=\"mb-4 flex items-center gap-2 text-sm font-semibold text-foreground\">\n <Calendar className=\"h-4 w-4 text-info\" /> Timeline\n </h3>\n <div className=\"grid grid-cols-1 gap-4 md:grid-cols-2\">\n <div>\n <span className=\"text-xs text-muted-foreground\">Planted On</span>\n <p className=\"text-sm font-semibold text-foreground\">{formatDate(localCrop.plantingDate)}</p>\n </div>\n <div>\n <span className=\"text-xs text-muted-foreground\">Expected Harvest</span>\n <p className=\"text-sm font-semibold text-foreground\">{formatDate(localCrop.expectedHarvestDate)}</p>\n </div>\n </div>\n <div className=\"mt-4\">\n {daysUntilHarvest > 0 ? (\n <div className=\"rounded-lg bg-info/10 p-3\">\n <p className=\"text-sm text-info\">\n <span className=\"font-bold\">{daysUntilHarvest} days</span> until expected harvest\n </p>\n </div>\n ) : (\n <div className=\"rounded-lg bg-success-subtle p-3\">\n <p className=\"text-sm font-bold text-success\">Ready for harvest!</p>\n </div>\n )}\n </div>\n </div>\n\n {/* Growth Progress */}\n <div className=\"rounded-lg border border-border bg-card p-6\">\n <div className=\"flex items-center justify-between\">\n <h3 className=\"text-sm font-semibold text-foreground\">Growth Progress</h3>\n <span className=\"text-lg font-bold text-foreground\">{localCrop.progress}%</span>\n </div>\n <div className=\"mt-3 h-4 rounded-full bg-muted\">\n <div className=\"h-4 rounded-full bg-primary transition-all\" style={{ width: `${localCrop.progress}%` }} />\n </div>\n\n {/* Growth Stage Timeline */}\n <div className=\"mt-6\">\n <h4 className=\"mb-3 text-xs font-medium text-muted-foreground\">Growth Stage</h4>\n <div className=\"flex items-center\">\n {stages.map((stage, i) => (\n <div key={stage} className=\"flex flex-1 flex-col items-center gap-1.5\">\n <div className=\"flex w-full items-center\">\n <div\n className={`h-0.5 flex-1 ${i === 0 ? 'bg-transparent' : i <= stageIndex ? 'bg-primary' : 'bg-muted'}`}\n />\n <div\n className={`h-4 w-4 shrink-0 rounded-full border-2 ${i <= stageIndex ? 'border-primary bg-primary' : 'border-muted bg-background'}`}\n >\n {i <= stageIndex && (\n <div className=\"flex h-full items-center justify-center\">\n <div className=\"h-1.5 w-1.5 rounded-full bg-primary-foreground\" />\n </div>\n )}\n </div>\n <div\n className={`h-0.5 flex-1 ${i === stages.length - 1 ? 'bg-transparent' : i < stageIndex ? 'bg-primary' : 'bg-muted'}`}\n />\n </div>\n <span\n className={`text-center text-xs ${i <= stageIndex ? 'font-medium text-foreground' : 'text-muted-foreground'}`}\n >\n {stage}\n </span>\n </div>\n ))}\n </div>\n </div>\n </div>\n </div>\n\n {/* Sidebar */}\n <div className=\"space-y-6\">\n {/* Health Status Card */}\n <div className=\"rounded-lg border border-border bg-card p-6\">\n <h3 className=\"mb-4 text-sm font-semibold text-foreground\">Current Status</h3>\n <div className=\"space-y-3\">\n <div className=\"flex items-center justify-between\">\n <span className=\"text-xs text-muted-foreground\">Health</span>\n <StatusBadge label={localCrop.healthStatus} variant={healthVariant(localCrop.healthStatus)} />\n </div>\n <div className=\"flex items-center justify-between\">\n <span className=\"text-xs text-muted-foreground\">Growth Stage</span>\n <span className=\"text-xs font-medium text-foreground\">{localCrop.growthStage}</span>\n </div>\n <div className=\"flex items-center justify-between\">\n <span className=\"text-xs text-muted-foreground\">Organic</span>\n <span className=\"text-xs font-medium text-foreground\">{localCrop.organicCertified ? 'Yes' : 'No'}</span>\n </div>\n </div>\n {localCrop.healthStatus === 'fair' && (\n <div className=\"mt-3 rounded-lg bg-warning/10 p-3\">\n <div className=\"flex items-start gap-2\">\n <AlertTriangle className=\"mt-0.5 h-3.5 w-3.5 shrink-0 text-warning\" />\n <p className=\"text-xs text-warning\">This crop needs attention. Check for potential issues.</p>\n </div>\n </div>\n )}\n </div>\n\n {/* Yield Estimation */}\n <div className=\"rounded-lg border border-border bg-card p-6\">\n <h3 className=\"mb-4 flex items-center gap-2 text-sm font-semibold text-foreground\">\n <TrendingUp className=\"h-4 w-4 text-success\" /> Yield Estimation\n </h3>\n <div className=\"text-center\">\n <p className=\"text-3xl font-bold text-success\">{(localCrop.yieldEstimate ?? 0).toLocaleString()}</p>\n <p className=\"text-xs text-muted-foreground\">{localCrop.yieldUnit ?? 'units'} expected</p>\n {field && (\n <p className=\"mt-2 text-xs text-muted-foreground\">\n ~{yieldPerAcre} {localCrop.yieldUnit} per {(field.unit ?? '').replace(/s$/, '')}\n </p>\n )}\n </div>\n </div>\n\n {/* Quick Actions */}\n <div className=\"rounded-lg border border-border bg-card p-6\">\n <h3 className=\"mb-4 text-sm font-semibold text-foreground\">Quick Actions</h3>\n <div className=\"space-y-2\">\n <button\n onClick={() => navigate(buildPath('analytics'))}\n className=\"flex w-full items-center gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50\"\n >\n <TrendingUp className=\"h-4 w-4 text-muted-foreground\" /> View Analytics\n </button>\n <button\n onClick={() => navigate(buildPath('weather'))}\n className=\"flex w-full items-center gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50\"\n >\n <Droplets className=\"h-4 w-4 text-muted-foreground\" /> Check Weather\n </button>\n {field && (\n <button\n onClick={() => navigate(buildPath(`crops/fields/${field.id}`))}\n className=\"flex w-full items-center gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50\"\n >\n <MapPin className=\"h-4 w-4 text-muted-foreground\" /> View Field\n </button>\n )}\n <button\n onClick={() => navigate(buildPath('crops'))}\n className=\"flex w-full items-center gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50\"\n >\n <Sprout className=\"h-4 w-4 text-muted-foreground\" /> All Crops\n </button>\n </div>\n </div>\n </div>\n </div>\n\n {/* Edit Modal */}\n <Modal\n open={showEditModal}\n onClose={() => setShowEditModal(false)}\n title={`Edit ${localCrop.name}`}\n description=\"Update crop details\"\n size=\"lg\"\n footer={\n <>\n <button\n onClick={() => setShowEditModal(false)}\n className=\"rounded-md border border-border px-4 py-2 text-sm text-muted-foreground hover:text-foreground\"\n >\n Cancel\n </button>\n <button\n onClick={handleSaveEdit}\n disabled={submitting}\n className=\"rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-60\"\n >\n {submitting ? 'Saving...' : 'Save Changes'}\n </button>\n </>\n }\n >\n <div className=\"grid gap-4 sm:grid-cols-2\">\n <div>\n <label className=\"text-sm font-medium text-foreground\">Crop Name</label>\n <input\n value={editName}\n onChange={(e) => setEditName(e.target.value)}\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n </div>\n <div>\n <label className=\"text-sm font-medium text-foreground\">Variety</label>\n <input\n value={editVariety}\n onChange={(e) => setEditVariety(e.target.value)}\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n </div>\n <div>\n <label className=\"text-sm font-medium text-foreground\">Category</label>\n <input\n value={editCategory}\n onChange={(e) => setEditCategory(e.target.value)}\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n </div>\n <div>\n <label className=\"text-sm font-medium text-foreground\">Yield Estimate ({localCrop.yieldUnit})</label>\n <input\n type=\"number\"\n value={editYieldEstimate}\n onChange={(e) => setEditYieldEstimate(e.target.value)}\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n </div>\n <div>\n <label className=\"text-sm font-medium text-foreground\">Expected Harvest</label>\n <input\n type=\"date\"\n value={editExpectedHarvestDate}\n onChange={(e) => setEditExpectedHarvestDate(e.target.value)}\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n </div>\n <div>\n <label className=\"text-sm font-medium text-foreground\">Health Status</label>\n <select\n value={editHealthStatus}\n onChange={(e) => setEditHealthStatus(e.target.value as HealthStatus)}\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n >\n <option value=\"excellent\">Excellent</option>\n <option value=\"good\">Good</option>\n <option value=\"fair\">Fair</option>\n <option value=\"poor\">Poor</option>\n <option value=\"critical\">Critical</option>\n </select>\n </div>\n </div>\n </Modal>\n\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,IAAM,KAAiB,MAAc;AACnC,SAAQ,GAAR;EACE,KAAK,YACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,QACE,QAAO;;GAIP,MAAiB,MAAc;A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aAAY;YAC7C,kBAAC,OAAD;GAAK,WAAU;aAAf,CACE,kBAAC,KAAD;IAAG,WAAU;cAAwB;IAAyD,CAAA,EAC9F,kBAAC,UAAD;IACE,eAAe,EAAS,EAAU,QAAQ,CAAC;IAC3C,WAAU;cACX;IAEQ,CAAA,CACL;;EACK,CAAA"}
|
|
1
|
+
{"version":3,"file":"CropDetailsPage.js","names":[],"sources":["../../../../src/healthybowl/pages/crops/CropDetailsPage.tsx"],"sourcesContent":["import { useState, useEffect, type FC } from 'react';\nimport { useParams, useNavigate } from 'react-router-dom';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport {\n ArrowLeft,\n Calendar,\n MapPin,\n Sprout,\n Edit,\n Trash2,\n Droplets,\n Sun,\n AlertTriangle,\n TrendingUp,\n Leaf,\n} from 'lucide-react';\nimport { PageLayout, StatusBadge, EmptyState, ErrorState, Breadcrumbs, Modal, HBEntityTags } from '../../components';\nimport { useHealthyBowlData } from '../../hooks/useHealthyBowlData';\nimport { formatDate } from '../../utils/helpers';\nimport { useToast } from '../../hooks/useToast';\nimport { ToastContainer } from '../../components/Toast';\nimport type { Crop, HealthStatus } from '../../types';\nimport { isNative, nativeConfirm, nativeNotify, nativeToast } from '../../../utils/nativeBridge';\n\nconst healthVariant = (s: string) => {\n switch (s) {\n case 'excellent':\n return 'success' as const;\n case 'good':\n return 'info' as const;\n case 'fair':\n return 'warning' as const;\n default:\n return 'error' as const;\n }\n};\n\nconst statusVariant = (s: string) => {\n switch (s) {\n case 'harvest_ready':\n return 'success' as const;\n case 'growing':\n case 'fruiting':\n return 'info' as const;\n case 'planted':\n return 'muted' as const;\n default:\n return 'default' as const;\n }\n};\n\nconst stages = ['Seedling', 'Vegetative', 'Flowering', 'Fruiting', 'Mature'];\n\nexport const CropDetailsPage: FC = () => {\n const { crops, fields, errors, updateCrop, deleteCrop } = useHealthyBowlData();\n\n const { cropId } = useParams<{ cropId: string }>();\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n const { toasts, toast, dismiss } = useToast();\n const [showEditModal, setShowEditModal] = useState(false);\n const [submitting, setSubmitting] = useState(false);\n\n const [localCrop, setLocalCrop] = useState<Crop | undefined>(() => crops.find((c) => c.id === cropId));\n\n useEffect(() => {\n const found = crops.find((c) => c.id === cropId);\n if (found) setLocalCrop(found);\n }, [crops, cropId]);\n\n // Edit form controlled state\n const [editName, setEditName] = useState('');\n const [editVariety, setEditVariety] = useState('');\n const [editCategory, setEditCategory] = useState('');\n const [editYieldEstimate, setEditYieldEstimate] = useState('');\n const [editExpectedHarvestDate, setEditExpectedHarvestDate] = useState('');\n const [editHealthStatus, setEditHealthStatus] = useState<HealthStatus>('good');\n\n const openEditModal = () => {\n if (!localCrop) return;\n setEditName(localCrop.name);\n setEditVariety(localCrop.variety);\n setEditCategory(localCrop.category);\n setEditYieldEstimate(String(localCrop.yieldEstimate));\n setEditExpectedHarvestDate(localCrop.expectedHarvestDate);\n setEditHealthStatus(localCrop.healthStatus);\n setShowEditModal(true);\n };\n\n if (!localCrop) {\n return (\n <PageLayout title=\"Crop Not Found\">\n {errors.crops ? (\n <ErrorState />\n ) : (\n <EmptyState\n title=\"Crop not found\"\n description=\"The crop you are looking for does not exist.\"\n action={\n <button\n onClick={() => navigate(buildPath('crops'))}\n className=\"rounded-md bg-primary px-4 py-2 text-sm text-primary-foreground\"\n >\n Back to Crops\n </button>\n }\n />\n )}\n </PageLayout>\n );\n }\n\n const field = fields.find((f) => f.id === localCrop.field || f.name === localCrop.fieldName);\n const stageIndex = stages.indexOf(localCrop.growthStage);\n const daysUntilHarvest = localCrop.daysToHarvest;\n const yieldPerAcre = field ? Math.round(localCrop.yieldEstimate / field.area) : localCrop.yieldEstimate;\n\n const handleDelete = async () => {\n if (!localCrop) return;\n const confirmed = await nativeConfirm({\n title: 'Delete crop?',\n message: `${localCrop.name} will be permanently removed.`,\n okButtonTitle: 'Delete',\n cancelButtonTitle: 'Cancel',\n });\n if (confirmed === false) return;\n setSubmitting(true);\n try {\n await deleteCrop(localCrop.id);\n toast({ title: 'Crop deleted', description: `${localCrop.name} has been removed.`, variant: 'success' });\n if (isNative()) {\n void nativeToast('Crop deleted');\n void nativeNotify('success');\n }\n navigate(buildPath('crops'));\n } catch (err) {\n toast({ title: 'Delete failed', description: String(err), variant: 'error' });\n setSubmitting(false);\n }\n };\n\n const handleSaveEdit = async () => {\n if (!localCrop) return;\n if (!editName.trim()) {\n toast({ title: 'Missing required fields', description: 'Crop name is required.', variant: 'warning' });\n return;\n }\n setSubmitting(true);\n try {\n await updateCrop({\n id: localCrop.id,\n name: editName.trim(),\n variety: editVariety,\n category: editCategory,\n yieldEstimate: editYieldEstimate ? Number(editYieldEstimate) : undefined,\n expectedHarvestDate: editExpectedHarvestDate || undefined,\n healthStatus: editHealthStatus,\n });\n toast({ title: 'Crop updated', description: `${editName.trim()} details have been saved.`, variant: 'success' });\n setShowEditModal(false);\n } catch (err) {\n toast({ title: 'Update failed', description: String(err), variant: 'error' });\n } finally {\n setSubmitting(false);\n }\n };\n\n if (!localCrop) {\n return (\n <PageLayout title=\"Crop Not Found\" description=\"The requested crop could not be found.\">\n <div className=\"flex flex-col items-center justify-center py-12 text-center\">\n <p className=\"text-muted-foreground\">This crop may have been removed or the ID is invalid.</p>\n <button\n onClick={() => navigate(buildPath('crops'))}\n className=\"mt-4 rounded-md bg-primary px-4 py-2 text-sm text-primary-foreground\"\n >\n Back to Crops\n </button>\n </div>\n </PageLayout>\n );\n }\n\n return (\n <PageLayout\n title={localCrop.name}\n description={`${localCrop.variety} - ${localCrop.category}`}\n actions={\n <div className=\"flex items-center gap-2\">\n <button\n onClick={openEditModal}\n className=\"inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50\"\n >\n <Edit className=\"h-4 w-4\" /> Edit\n </button>\n <button\n onClick={handleDelete}\n disabled={submitting}\n className=\"inline-flex items-center gap-1.5 rounded-md border border-destructive px-3 py-2 text-sm text-destructive hover:bg-destructive/10 disabled:opacity-60\"\n >\n <Trash2 className=\"h-4 w-4\" /> Delete\n </button>\n <button\n onClick={() => navigate(buildPath('crops'))}\n className=\"inline-flex items-center gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50\"\n >\n <ArrowLeft className=\"h-4 w-4\" /> Back\n </button>\n </div>\n }\n >\n <Breadcrumbs items={[{ label: 'Crops', href: buildPath('crops') }, { label: localCrop.name }]} />\n\n {/* Status Row */}\n <div className=\"flex flex-wrap items-center gap-3\">\n <StatusBadge\n label={(localCrop.status ?? 'unknown').replace('_', ' ')}\n variant={statusVariant(localCrop.status ?? 'unknown')}\n dot\n />\n <StatusBadge label={localCrop.healthStatus} variant={healthVariant(localCrop.healthStatus)} dot />\n {localCrop.organicCertified && <StatusBadge label=\"Organic Certified\" variant=\"success\" />}\n <StatusBadge label={localCrop.season} variant=\"muted\" />\n </div>\n\n {/* Structured tags — entity-owned, persists to the crop's tagsV2 via setHealthyBowlEntityTags.\n Editable here so the crop View/Edit surfaces what the backend already stores. */}\n <HBEntityTags entityType=\"CROP\" entityId={localCrop.id} tags={localCrop.entityTags ?? []} className=\"mt-1\" />\n\n <div className=\"grid grid-cols-1 gap-6 lg:grid-cols-3\">\n {/* Main Content */}\n <div className=\"space-y-6 lg:col-span-2\">\n {/* Overview */}\n <div className=\"rounded-lg border border-border bg-card p-6\">\n <h3 className=\"mb-4 flex items-center gap-2 text-sm font-semibold text-foreground\">\n <Sun className=\"h-4 w-4 text-warning\" /> Crop Overview\n </h3>\n <div className=\"grid grid-cols-2 gap-4 md:grid-cols-4\">\n {[\n { icon: Sprout, label: 'Category', value: localCrop.category },\n { icon: Calendar, label: 'Season', value: localCrop.season },\n { icon: Leaf, label: 'Growth Stage', value: localCrop.growthStage },\n { icon: MapPin, label: 'Field', value: localCrop.fieldName },\n ].map(({ icon: Icon, label, value }) => (\n <div key={label}>\n <div className=\"flex items-center gap-1 text-muted-foreground\">\n <Icon className=\"h-3.5 w-3.5\" />\n <span className=\"text-xs\">{label}</span>\n </div>\n <p className=\"mt-1 text-sm font-semibold capitalize text-foreground\">{value}</p>\n </div>\n ))}\n </div>\n </div>\n\n {/* Field Info */}\n {field && (\n <div className=\"rounded-lg border border-border bg-card p-6\">\n <h3 className=\"mb-4 flex items-center gap-2 text-sm font-semibold text-foreground\">\n <MapPin className=\"h-4 w-4 text-success\" /> Field Details\n </h3>\n <div className=\"grid grid-cols-2 gap-4 md:grid-cols-4\">\n <div>\n <span className=\"text-xs text-muted-foreground\">Field</span>\n <p className=\"text-sm font-semibold text-foreground\">{field.name}</p>\n </div>\n <div>\n <span className=\"text-xs text-muted-foreground\">Area</span>\n <p className=\"text-sm font-semibold text-foreground\">\n {field.area} {field.unit}\n </p>\n </div>\n <div>\n <span className=\"text-xs text-muted-foreground\">Soil Type</span>\n <p className=\"text-sm font-semibold text-foreground\">{field.soilType}</p>\n </div>\n <div>\n <span className=\"text-xs text-muted-foreground\">Irrigation</span>\n <p className=\"text-sm font-semibold text-foreground\">{field.irrigationType}</p>\n </div>\n </div>\n </div>\n )}\n\n {/* Timeline */}\n <div className=\"rounded-lg border border-border bg-card p-6\">\n <h3 className=\"mb-4 flex items-center gap-2 text-sm font-semibold text-foreground\">\n <Calendar className=\"h-4 w-4 text-info\" /> Timeline\n </h3>\n <div className=\"grid grid-cols-1 gap-4 md:grid-cols-2\">\n <div>\n <span className=\"text-xs text-muted-foreground\">Planted On</span>\n <p className=\"text-sm font-semibold text-foreground\">{formatDate(localCrop.plantingDate)}</p>\n </div>\n <div>\n <span className=\"text-xs text-muted-foreground\">Expected Harvest</span>\n <p className=\"text-sm font-semibold text-foreground\">{formatDate(localCrop.expectedHarvestDate)}</p>\n </div>\n </div>\n <div className=\"mt-4\">\n {daysUntilHarvest > 0 ? (\n <div className=\"rounded-lg bg-info/10 p-3\">\n <p className=\"text-sm text-info\">\n <span className=\"font-bold\">{daysUntilHarvest} days</span> until expected harvest\n </p>\n </div>\n ) : (\n <div className=\"rounded-lg bg-success-subtle p-3\">\n <p className=\"text-sm font-bold text-success\">Ready for harvest!</p>\n </div>\n )}\n </div>\n </div>\n\n {/* Growth Progress */}\n <div className=\"rounded-lg border border-border bg-card p-6\">\n <div className=\"flex items-center justify-between\">\n <h3 className=\"text-sm font-semibold text-foreground\">Growth Progress</h3>\n <span className=\"text-lg font-bold text-foreground\">{localCrop.progress}%</span>\n </div>\n <div className=\"mt-3 h-4 rounded-full bg-muted\">\n <div className=\"h-4 rounded-full bg-primary transition-all\" style={{ width: `${localCrop.progress}%` }} />\n </div>\n\n {/* Growth Stage Timeline */}\n <div className=\"mt-6\">\n <h4 className=\"mb-3 text-xs font-medium text-muted-foreground\">Growth Stage</h4>\n <div className=\"flex items-center\">\n {stages.map((stage, i) => (\n <div key={stage} className=\"flex flex-1 flex-col items-center gap-1.5\">\n <div className=\"flex w-full items-center\">\n <div\n className={`h-0.5 flex-1 ${i === 0 ? 'bg-transparent' : i <= stageIndex ? 'bg-primary' : 'bg-muted'}`}\n />\n <div\n className={`h-4 w-4 shrink-0 rounded-full border-2 ${i <= stageIndex ? 'border-primary bg-primary' : 'border-muted bg-background'}`}\n >\n {i <= stageIndex && (\n <div className=\"flex h-full items-center justify-center\">\n <div className=\"h-1.5 w-1.5 rounded-full bg-primary-foreground\" />\n </div>\n )}\n </div>\n <div\n className={`h-0.5 flex-1 ${i === stages.length - 1 ? 'bg-transparent' : i < stageIndex ? 'bg-primary' : 'bg-muted'}`}\n />\n </div>\n <span\n className={`text-center text-xs ${i <= stageIndex ? 'font-medium text-foreground' : 'text-muted-foreground'}`}\n >\n {stage}\n </span>\n </div>\n ))}\n </div>\n </div>\n </div>\n </div>\n\n {/* Sidebar */}\n <div className=\"space-y-6\">\n {/* Health Status Card */}\n <div className=\"rounded-lg border border-border bg-card p-6\">\n <h3 className=\"mb-4 text-sm font-semibold text-foreground\">Current Status</h3>\n <div className=\"space-y-3\">\n <div className=\"flex items-center justify-between\">\n <span className=\"text-xs text-muted-foreground\">Health</span>\n <StatusBadge label={localCrop.healthStatus} variant={healthVariant(localCrop.healthStatus)} />\n </div>\n <div className=\"flex items-center justify-between\">\n <span className=\"text-xs text-muted-foreground\">Growth Stage</span>\n <span className=\"text-xs font-medium text-foreground\">{localCrop.growthStage}</span>\n </div>\n <div className=\"flex items-center justify-between\">\n <span className=\"text-xs text-muted-foreground\">Organic</span>\n <span className=\"text-xs font-medium text-foreground\">{localCrop.organicCertified ? 'Yes' : 'No'}</span>\n </div>\n </div>\n {localCrop.healthStatus === 'fair' && (\n <div className=\"mt-3 rounded-lg bg-warning/10 p-3\">\n <div className=\"flex items-start gap-2\">\n <AlertTriangle className=\"mt-0.5 h-3.5 w-3.5 shrink-0 text-warning\" />\n <p className=\"text-xs text-warning\">This crop needs attention. Check for potential issues.</p>\n </div>\n </div>\n )}\n </div>\n\n {/* Yield Estimation */}\n <div className=\"rounded-lg border border-border bg-card p-6\">\n <h3 className=\"mb-4 flex items-center gap-2 text-sm font-semibold text-foreground\">\n <TrendingUp className=\"h-4 w-4 text-success\" /> Yield Estimation\n </h3>\n <div className=\"text-center\">\n <p className=\"text-3xl font-bold text-success\">{(localCrop.yieldEstimate ?? 0).toLocaleString()}</p>\n <p className=\"text-xs text-muted-foreground\">{localCrop.yieldUnit ?? 'units'} expected</p>\n {field && (\n <p className=\"mt-2 text-xs text-muted-foreground\">\n ~{yieldPerAcre} {localCrop.yieldUnit} per {(field.unit ?? '').replace(/s$/, '')}\n </p>\n )}\n </div>\n </div>\n\n {/* Quick Actions */}\n <div className=\"rounded-lg border border-border bg-card p-6\">\n <h3 className=\"mb-4 text-sm font-semibold text-foreground\">Quick Actions</h3>\n <div className=\"space-y-2\">\n <button\n onClick={() => navigate(buildPath('analytics'))}\n className=\"flex w-full items-center gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50\"\n >\n <TrendingUp className=\"h-4 w-4 text-muted-foreground\" /> View Analytics\n </button>\n <button\n onClick={() => navigate(buildPath('weather'))}\n className=\"flex w-full items-center gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50\"\n >\n <Droplets className=\"h-4 w-4 text-muted-foreground\" /> Check Weather\n </button>\n {field && (\n <button\n onClick={() => navigate(buildPath(`crops/fields/${field.id}`))}\n className=\"flex w-full items-center gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50\"\n >\n <MapPin className=\"h-4 w-4 text-muted-foreground\" /> View Field\n </button>\n )}\n <button\n onClick={() => navigate(buildPath('crops'))}\n className=\"flex w-full items-center gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-muted/50\"\n >\n <Sprout className=\"h-4 w-4 text-muted-foreground\" /> All Crops\n </button>\n </div>\n </div>\n </div>\n </div>\n\n {/* Edit Modal */}\n <Modal\n open={showEditModal}\n onClose={() => setShowEditModal(false)}\n title={`Edit ${localCrop.name}`}\n description=\"Update crop details\"\n size=\"lg\"\n footer={\n <>\n <button\n onClick={() => setShowEditModal(false)}\n className=\"rounded-md border border-border px-4 py-2 text-sm text-muted-foreground hover:text-foreground\"\n >\n Cancel\n </button>\n <button\n onClick={handleSaveEdit}\n disabled={submitting}\n className=\"rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-60\"\n >\n {submitting ? 'Saving...' : 'Save Changes'}\n </button>\n </>\n }\n >\n <div className=\"grid gap-4 sm:grid-cols-2\">\n <div>\n <label className=\"text-sm font-medium text-foreground\">Crop Name</label>\n <input\n value={editName}\n onChange={(e) => setEditName(e.target.value)}\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n </div>\n <div>\n <label className=\"text-sm font-medium text-foreground\">Variety</label>\n <input\n value={editVariety}\n onChange={(e) => setEditVariety(e.target.value)}\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n </div>\n <div>\n <label className=\"text-sm font-medium text-foreground\">Category</label>\n <input\n value={editCategory}\n onChange={(e) => setEditCategory(e.target.value)}\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n </div>\n <div>\n <label className=\"text-sm font-medium text-foreground\">Yield Estimate ({localCrop.yieldUnit})</label>\n <input\n type=\"number\"\n value={editYieldEstimate}\n onChange={(e) => setEditYieldEstimate(e.target.value)}\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n </div>\n <div>\n <label className=\"text-sm font-medium text-foreground\">Expected Harvest</label>\n <input\n type=\"date\"\n value={editExpectedHarvestDate}\n onChange={(e) => setEditExpectedHarvestDate(e.target.value)}\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n </div>\n <div>\n <label className=\"text-sm font-medium text-foreground\">Health Status</label>\n <select\n value={editHealthStatus}\n onChange={(e) => setEditHealthStatus(e.target.value as HealthStatus)}\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n >\n <option value=\"excellent\">Excellent</option>\n <option value=\"good\">Good</option>\n <option value=\"fair\">Fair</option>\n <option value=\"poor\">Poor</option>\n <option value=\"critical\">Critical</option>\n </select>\n </div>\n </div>\n </Modal>\n\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwBA,IAAM,KAAiB,MAAc;AACnC,SAAQ,GAAR;EACE,KAAK,YACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,QACE,QAAO;;GAIP,MAAiB,MAAc;AACnC,SAAQ,GAAR;EACE,KAAK,gBACH,QAAO;EACT,KAAK;EACL,KAAK,WACH,QAAO;EACT,K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AAD;EAAY,OAAM;EAAiB,aAAY;YAC7C,kBAAC,OAAD;GAAK,WAAU;aAAf,CACE,kBAAC,KAAD;IAAG,WAAU;cAAwB;IAAyD,CAAA,EAC9F,kBAAC,UAAD;IACE,eAAe,EAAS,EAAU,QAAQ,CAAC;IAC3C,WAAU;cACX;IAEQ,CAAA,CACL;;EACK,CAAA"}
|
|
@@ -9,11 +9,11 @@ import { Modal as s } from "../../components/Modal.js";
|
|
|
9
9
|
import { useGetHealthyBowlFinancierGrantsQuery as c, useGrantHealthyBowlFinancierAccessMutation as l, useRevokeHealthyBowlFinancierAccessMutation as u } from "../../../generated/wspace-operations.js";
|
|
10
10
|
import "../../components/index.js";
|
|
11
11
|
import { useToast as d } from "../../hooks/useToast.js";
|
|
12
|
-
import {
|
|
13
|
-
import { AlertCircle as
|
|
14
|
-
import { Fragment as
|
|
12
|
+
import { useEffect as f, useMemo as p, useState as m } from "react";
|
|
13
|
+
import { AlertCircle as h, Landmark as g, Plus as _, ShieldCheck as v, Trash2 as y } from "lucide-react";
|
|
14
|
+
import { Fragment as b, jsx as x, jsxs as S } from "react/jsx-runtime";
|
|
15
15
|
//#region src/healthybowl/pages/financial/FinancierAccessPage.tsx
|
|
16
|
-
var
|
|
16
|
+
var C = (e) => {
|
|
17
17
|
if (!e) return "—";
|
|
18
18
|
let t = new Date(e).getTime();
|
|
19
19
|
return Number.isNaN(t) ? "—" : new Date(t).toLocaleDateString(void 0, {
|
|
@@ -21,169 +21,192 @@ var x = (e) => {
|
|
|
21
21
|
month: "short",
|
|
22
22
|
day: "numeric"
|
|
23
23
|
});
|
|
24
|
-
},
|
|
25
|
-
let { workspaceId:
|
|
26
|
-
variables: { context: { workspaceId:
|
|
27
|
-
skip: !
|
|
24
|
+
}, w = (e) => e.length > 14 ? `${e.slice(0, 10)}…` : e, T = () => {
|
|
25
|
+
let { workspaceId: T } = e(), { buildPath: E } = t(), { toasts: D, toast: O, dismiss: k } = d(), { data: A, loading: j, error: M, refetch: N } = c({
|
|
26
|
+
variables: { context: { workspaceId: T } },
|
|
27
|
+
skip: !T,
|
|
28
28
|
fetchPolicy: "cache-and-network"
|
|
29
|
-
}), [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
}), [P] = l(), [F] = u(), [I, L] = m([]), R = p(() => A?.getHealthyBowlFinancierGrants ?? [], [A]);
|
|
30
|
+
f(() => {
|
|
31
|
+
if (j) return;
|
|
32
|
+
let e = new Set(R.map((e) => e.id));
|
|
33
|
+
L((t) => {
|
|
34
|
+
let n = t.filter((t) => !e.has(t.id));
|
|
35
|
+
return n.length === t.length ? t : n;
|
|
36
|
+
});
|
|
37
|
+
}, [j, R]), f(() => {
|
|
38
|
+
L([]);
|
|
39
|
+
}, [T]);
|
|
40
|
+
let z = p(() => {
|
|
41
|
+
let e = /* @__PURE__ */ new Set();
|
|
42
|
+
return [...R, ...I].filter((t) => e.has(t.id) ? !1 : (e.add(t.id), !0));
|
|
43
|
+
}, [R, I]), B = z.filter((e) => e.status.toUpperCase() === "ACTIVE"), [V, H] = m(!1), [U, W] = m(!1), [G, K] = m(null), [q, J] = m(""), [Y, X] = m(""), [Z, Q] = m(""), $ = () => {
|
|
44
|
+
J(""), X(""), Q("");
|
|
45
|
+
}, ee = async () => {
|
|
46
|
+
if (!q.trim()) {
|
|
47
|
+
O({
|
|
34
48
|
title: "Financier ID required",
|
|
35
49
|
description: "Enter the financier’s actor id.",
|
|
36
50
|
variant: "warning"
|
|
37
51
|
});
|
|
38
52
|
return;
|
|
39
53
|
}
|
|
40
|
-
|
|
54
|
+
W(!0);
|
|
41
55
|
try {
|
|
42
|
-
await
|
|
43
|
-
financierActorId:
|
|
44
|
-
financierName:
|
|
56
|
+
let e = (await P({ variables: { input: {
|
|
57
|
+
financierActorId: q.trim(),
|
|
58
|
+
financierName: Y.trim() || null,
|
|
45
59
|
scope: "FINANCIAL_SUMMARY",
|
|
46
|
-
expiresAt:
|
|
47
|
-
context: { workspaceId:
|
|
48
|
-
} } })
|
|
60
|
+
expiresAt: Z ? new Date(Z).toISOString() : null,
|
|
61
|
+
context: { workspaceId: T }
|
|
62
|
+
} } })).data?.grantHealthyBowlFinancierAccess;
|
|
63
|
+
e && L((t) => [{
|
|
64
|
+
id: e.id,
|
|
65
|
+
financierActorId: e.financierActorId,
|
|
66
|
+
financierName: e.financierName,
|
|
67
|
+
status: e.status,
|
|
68
|
+
grantedAt: e.grantedAt,
|
|
69
|
+
scope: "FINANCIAL_SUMMARY",
|
|
70
|
+
expiresAt: Z ? new Date(Z).toISOString() : null
|
|
71
|
+
}, ...t.filter((t) => t.id !== e.id)]), O({
|
|
49
72
|
title: "Access granted",
|
|
50
73
|
description: "The financier can now see your risk view.",
|
|
51
74
|
variant: "success"
|
|
52
|
-
}),
|
|
75
|
+
}), H(!1), $(), await N();
|
|
53
76
|
} catch {
|
|
54
|
-
|
|
77
|
+
O({
|
|
55
78
|
title: "Grant failed",
|
|
56
79
|
description: "Could not grant access. Please try again.",
|
|
57
80
|
variant: "error"
|
|
58
81
|
});
|
|
59
82
|
} finally {
|
|
60
|
-
|
|
83
|
+
W(!1);
|
|
61
84
|
}
|
|
62
|
-
},
|
|
85
|
+
}, te = async (e) => {
|
|
63
86
|
if (window.confirm(`Revoke ${e.financierName || "this financier"}’s access to your farm’s financial view? They will immediately lose access.`)) {
|
|
64
|
-
|
|
87
|
+
K(e.id);
|
|
65
88
|
try {
|
|
66
|
-
await
|
|
89
|
+
await F({ variables: {
|
|
67
90
|
id: e.id,
|
|
68
|
-
context: { workspaceId:
|
|
69
|
-
} }),
|
|
91
|
+
context: { workspaceId: T }
|
|
92
|
+
} }), O({
|
|
70
93
|
title: "Access revoked",
|
|
71
94
|
description: `${e.financierName || "Financier"} can no longer see your farm.`,
|
|
72
95
|
variant: "success"
|
|
73
|
-
}), await
|
|
96
|
+
}), L((t) => t.filter((t) => t.id !== e.id)), await N();
|
|
74
97
|
} catch {
|
|
75
|
-
|
|
98
|
+
O({
|
|
76
99
|
title: "Revoke failed",
|
|
77
100
|
description: "Could not revoke access. Please try again.",
|
|
78
101
|
variant: "error"
|
|
79
102
|
});
|
|
80
103
|
} finally {
|
|
81
|
-
|
|
104
|
+
K(null);
|
|
82
105
|
}
|
|
83
106
|
}
|
|
84
107
|
};
|
|
85
|
-
return /* @__PURE__ */
|
|
108
|
+
return /* @__PURE__ */ S(n, {
|
|
86
109
|
title: "Financier Access",
|
|
87
110
|
description: "Grant a bank, lender, or cooperative scoped read access to your farm’s financial risk view — and revoke it anytime",
|
|
88
|
-
actions: /* @__PURE__ */
|
|
89
|
-
onClick: () =>
|
|
111
|
+
actions: /* @__PURE__ */ S("button", {
|
|
112
|
+
onClick: () => H(!0),
|
|
90
113
|
className: "flex items-center gap-1.5 rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90",
|
|
91
|
-
children: [/* @__PURE__ */
|
|
114
|
+
children: [/* @__PURE__ */ x(_, { className: "h-4 w-4" }), " Grant Access"]
|
|
92
115
|
}),
|
|
93
116
|
children: [
|
|
94
|
-
/* @__PURE__ */
|
|
117
|
+
/* @__PURE__ */ x(o, { items: [{
|
|
95
118
|
label: "Financial",
|
|
96
|
-
href:
|
|
119
|
+
href: E("financial")
|
|
97
120
|
}, { label: "Financier Access" }] }),
|
|
98
|
-
|
|
121
|
+
j && z.length === 0 ? /* @__PURE__ */ x("p", {
|
|
99
122
|
className: "text-sm text-muted-foreground",
|
|
100
123
|
children: "Loading grants…"
|
|
101
|
-
}) :
|
|
124
|
+
}) : M && z.length === 0 ? /* @__PURE__ */ S("div", {
|
|
102
125
|
className: "flex items-center gap-2 rounded-lg border border-border bg-card p-5 text-sm text-muted-foreground",
|
|
103
|
-
children: [/* @__PURE__ */
|
|
104
|
-
}) :
|
|
126
|
+
children: [/* @__PURE__ */ x(h, { className: "h-4 w-4" }), " Financier grants aren't available right now."]
|
|
127
|
+
}) : B.length === 0 ? /* @__PURE__ */ x(i, {
|
|
105
128
|
title: "No financier has access",
|
|
106
129
|
description: "Grant a financier scoped access to share your farm’s financial standing for credit or lending.",
|
|
107
|
-
icon: /* @__PURE__ */
|
|
108
|
-
}) : /* @__PURE__ */
|
|
130
|
+
icon: /* @__PURE__ */ x(g, { className: "h-12 w-12 text-muted-foreground" })
|
|
131
|
+
}) : /* @__PURE__ */ x("div", {
|
|
109
132
|
className: "overflow-hidden rounded-lg border border-border bg-card",
|
|
110
|
-
children: /* @__PURE__ */
|
|
133
|
+
children: /* @__PURE__ */ S("table", {
|
|
111
134
|
className: "w-full text-sm",
|
|
112
|
-
children: [/* @__PURE__ */
|
|
135
|
+
children: [/* @__PURE__ */ x("thead", { children: /* @__PURE__ */ S("tr", {
|
|
113
136
|
className: "border-b border-border text-left text-xs text-muted-foreground",
|
|
114
137
|
children: [
|
|
115
|
-
/* @__PURE__ */
|
|
138
|
+
/* @__PURE__ */ x("th", {
|
|
116
139
|
className: "px-4 py-3 font-medium",
|
|
117
140
|
children: "Financier"
|
|
118
141
|
}),
|
|
119
|
-
/* @__PURE__ */
|
|
142
|
+
/* @__PURE__ */ x("th", {
|
|
120
143
|
className: "px-4 py-3 font-medium",
|
|
121
144
|
children: "Scope"
|
|
122
145
|
}),
|
|
123
|
-
/* @__PURE__ */
|
|
146
|
+
/* @__PURE__ */ x("th", {
|
|
124
147
|
className: "px-4 py-3 font-medium",
|
|
125
148
|
children: "Granted"
|
|
126
149
|
}),
|
|
127
|
-
/* @__PURE__ */
|
|
150
|
+
/* @__PURE__ */ x("th", {
|
|
128
151
|
className: "px-4 py-3 font-medium",
|
|
129
152
|
children: "Expires"
|
|
130
153
|
}),
|
|
131
|
-
/* @__PURE__ */
|
|
154
|
+
/* @__PURE__ */ x("th", {
|
|
132
155
|
className: "px-4 py-3 font-medium",
|
|
133
156
|
children: "Status"
|
|
134
157
|
}),
|
|
135
|
-
/* @__PURE__ */
|
|
158
|
+
/* @__PURE__ */ x("th", {
|
|
136
159
|
className: "px-4 py-3 text-right font-medium",
|
|
137
160
|
children: "Action"
|
|
138
161
|
})
|
|
139
162
|
]
|
|
140
|
-
}) }), /* @__PURE__ */
|
|
163
|
+
}) }), /* @__PURE__ */ x("tbody", { children: B.map((e) => /* @__PURE__ */ S("tr", {
|
|
141
164
|
className: "border-b border-border/50 last:border-0",
|
|
142
165
|
children: [
|
|
143
|
-
/* @__PURE__ */
|
|
166
|
+
/* @__PURE__ */ S("td", {
|
|
144
167
|
className: "px-4 py-3",
|
|
145
|
-
children: [/* @__PURE__ */
|
|
168
|
+
children: [/* @__PURE__ */ x("p", {
|
|
146
169
|
className: "font-medium text-foreground",
|
|
147
170
|
children: e.financierName || "Unnamed financier"
|
|
148
|
-
}), /* @__PURE__ */
|
|
171
|
+
}), /* @__PURE__ */ x("p", {
|
|
149
172
|
className: "font-mono text-xs text-muted-foreground",
|
|
150
173
|
title: e.financierActorId,
|
|
151
|
-
children:
|
|
174
|
+
children: w(e.financierActorId)
|
|
152
175
|
})]
|
|
153
176
|
}),
|
|
154
|
-
/* @__PURE__ */
|
|
177
|
+
/* @__PURE__ */ x("td", {
|
|
155
178
|
className: "px-4 py-3",
|
|
156
|
-
children: /* @__PURE__ */
|
|
179
|
+
children: /* @__PURE__ */ S("span", {
|
|
157
180
|
className: "inline-flex items-center gap-1 text-xs text-muted-foreground",
|
|
158
|
-
children: [/* @__PURE__ */
|
|
181
|
+
children: [/* @__PURE__ */ x(v, { className: "h-3.5 w-3.5" }), " Financial summary"]
|
|
159
182
|
})
|
|
160
183
|
}),
|
|
161
|
-
/* @__PURE__ */
|
|
184
|
+
/* @__PURE__ */ x("td", {
|
|
162
185
|
className: "px-4 py-3 text-muted-foreground",
|
|
163
|
-
children:
|
|
186
|
+
children: C(e.grantedAt)
|
|
164
187
|
}),
|
|
165
|
-
/* @__PURE__ */
|
|
188
|
+
/* @__PURE__ */ x("td", {
|
|
166
189
|
className: "px-4 py-3 text-muted-foreground",
|
|
167
|
-
children:
|
|
190
|
+
children: C(e.expiresAt)
|
|
168
191
|
}),
|
|
169
|
-
/* @__PURE__ */
|
|
192
|
+
/* @__PURE__ */ x("td", {
|
|
170
193
|
className: "px-4 py-3",
|
|
171
|
-
children: /* @__PURE__ */
|
|
194
|
+
children: /* @__PURE__ */ x(r, {
|
|
172
195
|
label: e.status,
|
|
173
196
|
variant: "success",
|
|
174
197
|
dot: !0
|
|
175
198
|
})
|
|
176
199
|
}),
|
|
177
|
-
/* @__PURE__ */
|
|
200
|
+
/* @__PURE__ */ x("td", {
|
|
178
201
|
className: "px-4 py-3 text-right",
|
|
179
|
-
children: /* @__PURE__ */
|
|
180
|
-
onClick: () =>
|
|
181
|
-
disabled:
|
|
202
|
+
children: /* @__PURE__ */ S("button", {
|
|
203
|
+
onClick: () => te(e),
|
|
204
|
+
disabled: G === e.id,
|
|
182
205
|
className: "inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs text-destructive hover:bg-destructive/10 disabled:opacity-60",
|
|
183
206
|
children: [
|
|
184
|
-
/* @__PURE__ */ y
|
|
207
|
+
/* @__PURE__ */ x(y, { className: "h-3.5 w-3.5" }),
|
|
185
208
|
" ",
|
|
186
|
-
|
|
209
|
+
G === e.id ? "Revoking…" : "Revoke"
|
|
187
210
|
]
|
|
188
211
|
})
|
|
189
212
|
})
|
|
@@ -191,68 +214,68 @@ var x = (e) => {
|
|
|
191
214
|
}, e.id)) })]
|
|
192
215
|
})
|
|
193
216
|
}),
|
|
194
|
-
/* @__PURE__ */
|
|
195
|
-
open:
|
|
217
|
+
/* @__PURE__ */ x(s, {
|
|
218
|
+
open: V,
|
|
196
219
|
onClose: () => {
|
|
197
|
-
|
|
220
|
+
H(!1), $();
|
|
198
221
|
},
|
|
199
222
|
title: "Grant Financier Access",
|
|
200
223
|
description: "Share a scoped, read-only financial summary of your farm. The financier never joins your workspace, and you can revoke this anytime.",
|
|
201
|
-
footer: /* @__PURE__ */ b
|
|
224
|
+
footer: /* @__PURE__ */ S(b, { children: [/* @__PURE__ */ x("button", {
|
|
202
225
|
onClick: () => {
|
|
203
|
-
|
|
226
|
+
H(!1), $();
|
|
204
227
|
},
|
|
205
228
|
className: "rounded-md border border-border px-4 py-2 text-sm text-muted-foreground hover:text-foreground",
|
|
206
229
|
children: "Cancel"
|
|
207
|
-
}), /* @__PURE__ */
|
|
208
|
-
onClick:
|
|
209
|
-
disabled:
|
|
230
|
+
}), /* @__PURE__ */ x("button", {
|
|
231
|
+
onClick: ee,
|
|
232
|
+
disabled: U,
|
|
210
233
|
className: "rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-60",
|
|
211
|
-
children:
|
|
234
|
+
children: U ? "Granting…" : "Grant Access"
|
|
212
235
|
})] }),
|
|
213
|
-
children: /* @__PURE__ */
|
|
236
|
+
children: /* @__PURE__ */ S("div", {
|
|
214
237
|
className: "grid gap-4",
|
|
215
238
|
children: [
|
|
216
|
-
/* @__PURE__ */
|
|
217
|
-
/* @__PURE__ */
|
|
239
|
+
/* @__PURE__ */ S("div", { children: [
|
|
240
|
+
/* @__PURE__ */ x("label", {
|
|
218
241
|
className: "text-sm font-medium text-foreground",
|
|
219
242
|
children: "Financier Actor ID *"
|
|
220
243
|
}),
|
|
221
|
-
/* @__PURE__ */
|
|
244
|
+
/* @__PURE__ */ x("input", {
|
|
222
245
|
type: "text",
|
|
223
|
-
value:
|
|
224
|
-
onChange: (e) =>
|
|
246
|
+
value: q,
|
|
247
|
+
onChange: (e) => J(e.target.value),
|
|
225
248
|
placeholder: "The financier’s platform user id",
|
|
226
249
|
className: "mt-1 w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
|
|
227
250
|
}),
|
|
228
|
-
/* @__PURE__ */
|
|
251
|
+
/* @__PURE__ */ x("p", {
|
|
229
252
|
className: "mt-1 text-xs text-muted-foreground",
|
|
230
253
|
children: "Only this actor will be able to read your scoped financial summary."
|
|
231
254
|
})
|
|
232
255
|
] }),
|
|
233
|
-
/* @__PURE__ */
|
|
256
|
+
/* @__PURE__ */ S("div", { children: [/* @__PURE__ */ x("label", {
|
|
234
257
|
className: "text-sm font-medium text-foreground",
|
|
235
258
|
children: "Financier Name"
|
|
236
|
-
}), /* @__PURE__ */
|
|
259
|
+
}), /* @__PURE__ */ x("input", {
|
|
237
260
|
type: "text",
|
|
238
|
-
value:
|
|
239
|
-
onChange: (e) =>
|
|
261
|
+
value: Y,
|
|
262
|
+
onChange: (e) => X(e.target.value),
|
|
240
263
|
placeholder: "e.g., Rural Credit Cooperative",
|
|
241
264
|
className: "mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
|
|
242
265
|
})] }),
|
|
243
|
-
/* @__PURE__ */
|
|
244
|
-
/* @__PURE__ */
|
|
266
|
+
/* @__PURE__ */ S("div", { children: [
|
|
267
|
+
/* @__PURE__ */ x("label", {
|
|
245
268
|
className: "text-sm font-medium text-foreground",
|
|
246
269
|
children: "Expires (optional)"
|
|
247
270
|
}),
|
|
248
|
-
/* @__PURE__ */
|
|
271
|
+
/* @__PURE__ */ x("input", {
|
|
249
272
|
type: "date",
|
|
250
|
-
value:
|
|
273
|
+
value: Z,
|
|
251
274
|
min: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
|
|
252
|
-
onChange: (e) =>
|
|
275
|
+
onChange: (e) => Q(e.target.value),
|
|
253
276
|
className: "mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring"
|
|
254
277
|
}),
|
|
255
|
-
/* @__PURE__ */
|
|
278
|
+
/* @__PURE__ */ x("p", {
|
|
256
279
|
className: "mt-1 text-xs text-muted-foreground",
|
|
257
280
|
children: "Leave blank for access that lasts until you revoke it."
|
|
258
281
|
})
|
|
@@ -260,14 +283,14 @@ var x = (e) => {
|
|
|
260
283
|
]
|
|
261
284
|
})
|
|
262
285
|
}),
|
|
263
|
-
/* @__PURE__ */
|
|
264
|
-
toasts:
|
|
265
|
-
onDismiss:
|
|
286
|
+
/* @__PURE__ */ x(a, {
|
|
287
|
+
toasts: D,
|
|
288
|
+
onDismiss: k
|
|
266
289
|
})
|
|
267
290
|
]
|
|
268
291
|
});
|
|
269
292
|
};
|
|
270
293
|
//#endregion
|
|
271
|
-
export {
|
|
294
|
+
export { T as FinancierAccessPage };
|
|
272
295
|
|
|
273
296
|
//# sourceMappingURL=FinancierAccessPage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FinancierAccessPage.js","names":[],"sources":["../../../../src/healthybowl/pages/financial/FinancierAccessPage.tsx"],"sourcesContent":["import { useState, type FC } from 'react';\nimport { Landmark, Plus, ShieldCheck, Trash2, AlertCircle } from 'lucide-react';\nimport { PageLayout, StatusBadge, EmptyState, Modal, Breadcrumbs } from '../../components';\nimport { ToastContainer } from '../../components/Toast';\nimport { useToast } from '../../hooks/useToast';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { useHealthyBowl } from '../../context/HealthyBowlContext';\nimport {\n useGetHealthyBowlFinancierGrantsQuery,\n useGrantHealthyBowlFinancierAccessMutation,\n useRevokeHealthyBowlFinancierAccessMutation,\n} from '../../../generated/wspace-operations';\n\n/**\n * UC-14 — B2B2C financier bridge (farmer side).\n *\n * The farmer decides which financier (bank / lender / cooperative) may see a\n * scoped, read-only financial summary of their farm — and can revoke it at any\n * time. Each grant is a `FinancierAccessGrant` row; the financier never becomes\n * a workspace member. This is the consent surface for the financier portfolio\n * view (`FinancierPage`).\n */\n\n/** Shape we render from the svc (generated types are `@ts-nocheck`). */\ninterface FinancierGrant {\n id: string;\n financierActorId: string;\n financierName?: string | null;\n scope: string;\n status: string;\n grantedAt: string;\n expiresAt?: string | null;\n}\n\nconst formatDate = (iso?: string | null): string => {\n if (!iso) return '—';\n const ts = new Date(iso).getTime();\n if (Number.isNaN(ts)) return '—';\n return new Date(ts).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });\n};\n\nconst shortActor = (id: string): string => (id.length > 14 ? `${id.slice(0, 10)}…` : id);\n\nexport const FinancierAccessPage: FC = () => {\n const { workspaceId } = useHealthyBowl();\n const { buildPath } = useBasePath();\n const { toasts, toast, dismiss } = useToast();\n\n const { data, loading, error, refetch } = useGetHealthyBowlFinancierGrantsQuery({\n variables: { context: { workspaceId } },\n skip: !workspaceId,\n fetchPolicy: 'cache-and-network',\n });\n const [grantAccess] = useGrantHealthyBowlFinancierAccessMutation();\n const [revokeAccess] = useRevokeHealthyBowlFinancierAccessMutation();\n\n const grants: FinancierGrant[] = data?.getHealthyBowlFinancierGrants ?? [];\n const activeGrants = grants.filter((g) => g.status.toUpperCase() === 'ACTIVE');\n\n const [showGrant, setShowGrant] = useState(false);\n const [submitting, setSubmitting] = useState(false);\n const [revokingId, setRevokingId] = useState<string | null>(null);\n const [financierActorId, setFinancierActorId] = useState('');\n const [financierName, setFinancierName] = useState('');\n const [expiresAt, setExpiresAt] = useState('');\n\n const resetForm = () => {\n setFinancierActorId('');\n setFinancierName('');\n setExpiresAt('');\n };\n\n const handleGrant = async () => {\n if (!financierActorId.trim()) {\n toast({ title: 'Financier ID required', description: 'Enter the financier’s actor id.', variant: 'warning' });\n return;\n }\n setSubmitting(true);\n try {\n await grantAccess({\n variables: {\n input: {\n financierActorId: financierActorId.trim(),\n financierName: financierName.trim() || null,\n scope: 'FINANCIAL_SUMMARY',\n expiresAt: expiresAt ? new Date(expiresAt).toISOString() : null,\n context: { workspaceId },\n },\n },\n });\n toast({ title: 'Access granted', description: 'The financier can now see your risk view.', variant: 'success' });\n setShowGrant(false);\n resetForm();\n await refetch();\n } catch {\n toast({ title: 'Grant failed', description: 'Could not grant access. Please try again.', variant: 'error' });\n } finally {\n setSubmitting(false);\n }\n };\n\n const handleRevoke = async (grant: FinancierGrant) => {\n if (\n !window.confirm(\n `Revoke ${grant.financierName || 'this financier'}’s access to your farm’s financial view? They will immediately lose access.`\n )\n ) {\n return;\n }\n setRevokingId(grant.id);\n try {\n await revokeAccess({ variables: { id: grant.id, context: { workspaceId } } });\n toast({\n title: 'Access revoked',\n description: `${grant.financierName || 'Financier'} can no longer see your farm.`,\n variant: 'success',\n });\n await refetch();\n } catch {\n toast({ title: 'Revoke failed', description: 'Could not revoke access. Please try again.', variant: 'error' });\n } finally {\n setRevokingId(null);\n }\n };\n\n return (\n <PageLayout\n title=\"Financier Access\"\n description=\"Grant a bank, lender, or cooperative scoped read access to your farm’s financial risk view — and revoke it anytime\"\n actions={\n <button\n onClick={() => setShowGrant(true)}\n className=\"flex items-center gap-1.5 rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90\"\n >\n <Plus className=\"h-4 w-4\" /> Grant Access\n </button>\n }\n >\n <Breadcrumbs items={[{ label: 'Financial', href: buildPath('financial') }, { label: 'Financier Access' }]} />\n\n {loading && grants.length === 0 ? (\n <p className=\"text-sm text-muted-foreground\">Loading grants…</p>\n ) : error && grants.length === 0 ? (\n <div className=\"flex items-center gap-2 rounded-lg border border-border bg-card p-5 text-sm text-muted-foreground\">\n <AlertCircle className=\"h-4 w-4\" /> Financier grants aren't available right now.\n </div>\n ) : activeGrants.length === 0 ? (\n <EmptyState\n title=\"No financier has access\"\n description=\"Grant a financier scoped access to share your farm’s financial standing for credit or lending.\"\n icon={<Landmark className=\"h-12 w-12 text-muted-foreground\" />}\n />\n ) : (\n <div className=\"overflow-hidden rounded-lg border border-border bg-card\">\n <table className=\"w-full text-sm\">\n <thead>\n <tr className=\"border-b border-border text-left text-xs text-muted-foreground\">\n <th className=\"px-4 py-3 font-medium\">Financier</th>\n <th className=\"px-4 py-3 font-medium\">Scope</th>\n <th className=\"px-4 py-3 font-medium\">Granted</th>\n <th className=\"px-4 py-3 font-medium\">Expires</th>\n <th className=\"px-4 py-3 font-medium\">Status</th>\n <th className=\"px-4 py-3 text-right font-medium\">Action</th>\n </tr>\n </thead>\n <tbody>\n {activeGrants.map((g) => (\n <tr key={g.id} className=\"border-b border-border/50 last:border-0\">\n <td className=\"px-4 py-3\">\n <p className=\"font-medium text-foreground\">{g.financierName || 'Unnamed financier'}</p>\n <p className=\"font-mono text-xs text-muted-foreground\" title={g.financierActorId}>\n {shortActor(g.financierActorId)}\n </p>\n </td>\n <td className=\"px-4 py-3\">\n <span className=\"inline-flex items-center gap-1 text-xs text-muted-foreground\">\n <ShieldCheck className=\"h-3.5 w-3.5\" /> Financial summary\n </span>\n </td>\n <td className=\"px-4 py-3 text-muted-foreground\">{formatDate(g.grantedAt)}</td>\n <td className=\"px-4 py-3 text-muted-foreground\">{formatDate(g.expiresAt)}</td>\n <td className=\"px-4 py-3\">\n <StatusBadge label={g.status} variant=\"success\" dot />\n </td>\n <td className=\"px-4 py-3 text-right\">\n <button\n onClick={() => handleRevoke(g)}\n disabled={revokingId === g.id}\n className=\"inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs text-destructive hover:bg-destructive/10 disabled:opacity-60\"\n >\n <Trash2 className=\"h-3.5 w-3.5\" /> {revokingId === g.id ? 'Revoking…' : 'Revoke'}\n </button>\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n )}\n\n <Modal\n open={showGrant}\n onClose={() => {\n setShowGrant(false);\n resetForm();\n }}\n title=\"Grant Financier Access\"\n description=\"Share a scoped, read-only financial summary of your farm. The financier never joins your workspace, and you can revoke this anytime.\"\n footer={\n <>\n <button\n onClick={() => {\n setShowGrant(false);\n resetForm();\n }}\n className=\"rounded-md border border-border px-4 py-2 text-sm text-muted-foreground hover:text-foreground\"\n >\n Cancel\n </button>\n <button\n onClick={handleGrant}\n disabled={submitting}\n className=\"rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-60\"\n >\n {submitting ? 'Granting…' : 'Grant Access'}\n </button>\n </>\n }\n >\n <div className=\"grid gap-4\">\n <div>\n <label className=\"text-sm font-medium text-foreground\">Financier Actor ID *</label>\n <input\n type=\"text\"\n value={financierActorId}\n onChange={(e) => setFinancierActorId(e.target.value)}\n placeholder=\"The financier’s platform user id\"\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n <p className=\"mt-1 text-xs text-muted-foreground\">\n Only this actor will be able to read your scoped financial summary.\n </p>\n </div>\n <div>\n <label className=\"text-sm font-medium text-foreground\">Financier Name</label>\n <input\n type=\"text\"\n value={financierName}\n onChange={(e) => setFinancierName(e.target.value)}\n placeholder=\"e.g., Rural Credit Cooperative\"\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n </div>\n <div>\n <label className=\"text-sm font-medium text-foreground\">Expires (optional)</label>\n <input\n type=\"date\"\n value={expiresAt}\n min={new Date().toISOString().slice(0, 10)}\n onChange={(e) => setExpiresAt(e.target.value)}\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n <p className=\"mt-1 text-xs text-muted-foreground\">Leave blank for access that lasts until you revoke it.</p>\n </div>\n </div>\n </Modal>\n\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AAkCA,IAAM,KAAc,MAAgC;AAClD,KAAI,CAAC,EAAK,QAAO;CACjB,IAAM,IAAK,IAAI,KAAK,EAAI,CAAC,SAAS;AAElC,QADI,OAAO,MAAM,EAAG,GAAS,MACtB,IAAI,KAAK,EAAG,CAAC,mBAAmB,KAAA,GAAW;EAAE,MAAM;EAAW,OAAO;EAAS,KAAK;EAAW,CAAC;GAGlG,KAAc,MAAwB,EAAG,SAAS,KAAK,GAAG,EAAG,MAAM,GAAG,GAAG,CAAC,KAAK,GAExE,UAAgC;CAC3C,IAAM,EAAE,m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}
|
|
1
|
+
{"version":3,"file":"FinancierAccessPage.js","names":[],"sources":["../../../../src/healthybowl/pages/financial/FinancierAccessPage.tsx"],"sourcesContent":["import { useState, useEffect, useMemo, type FC } from 'react';\nimport { Landmark, Plus, ShieldCheck, Trash2, AlertCircle } from 'lucide-react';\nimport { PageLayout, StatusBadge, EmptyState, Modal, Breadcrumbs } from '../../components';\nimport { ToastContainer } from '../../components/Toast';\nimport { useToast } from '../../hooks/useToast';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { useHealthyBowl } from '../../context/HealthyBowlContext';\nimport {\n useGetHealthyBowlFinancierGrantsQuery,\n useGrantHealthyBowlFinancierAccessMutation,\n useRevokeHealthyBowlFinancierAccessMutation,\n} from '../../../generated/wspace-operations';\n\n/**\n * UC-14 — B2B2C financier bridge (farmer side).\n *\n * The farmer decides which financier (bank / lender / cooperative) may see a\n * scoped, read-only financial summary of their farm — and can revoke it at any\n * time. Each grant is a `FinancierAccessGrant` row; the financier never becomes\n * a workspace member. This is the consent surface for the financier portfolio\n * view (`FinancierPage`).\n */\n\n/** Shape we render from the svc (generated types are `@ts-nocheck`). */\ninterface FinancierGrant {\n id: string;\n financierActorId: string;\n financierName?: string | null;\n scope: string;\n status: string;\n grantedAt: string;\n expiresAt?: string | null;\n}\n\nconst formatDate = (iso?: string | null): string => {\n if (!iso) return '—';\n const ts = new Date(iso).getTime();\n if (Number.isNaN(ts)) return '—';\n return new Date(ts).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });\n};\n\nconst shortActor = (id: string): string => (id.length > 14 ? `${id.slice(0, 10)}…` : id);\n\nexport const FinancierAccessPage: FC = () => {\n const { workspaceId } = useHealthyBowl();\n const { buildPath } = useBasePath();\n const { toasts, toast, dismiss } = useToast();\n\n const { data, loading, error, refetch } = useGetHealthyBowlFinancierGrantsQuery({\n variables: { context: { workspaceId } },\n skip: !workspaceId,\n fetchPolicy: 'cache-and-network',\n });\n const [grantAccess] = useGrantHealthyBowlFinancierAccessMutation();\n const [revokeAccess] = useRevokeHealthyBowlFinancierAccessMutation();\n\n const [optimisticGrants, setOptimisticGrants] = useState<FinancierGrant[]>([]);\n const queryGrants: FinancierGrant[] = useMemo(() => data?.getHealthyBowlFinancierGrants ?? [], [data]);\n\n // Once the authoritative query reflects an optimistic row (by id), retire the\n // optimistic copy: from then on the server result is the single source of\n // truth, so a later server-side change (e.g. a revoke from another session)\n // can't be masked by a stale overlay. Offline — where the refetch may never\n // surface the row — the overlay legitimately persists as a bridge.\n useEffect(() => {\n if (loading) return; // act only on a settled authoritative result, not mid-fetch\n const serverIds = new Set(queryGrants.map((g) => g.id));\n setOptimisticGrants((prev) => {\n const next = prev.filter((g) => !serverIds.has(g.id));\n return next.length === prev.length ? prev : next; // no-op (stable ref) when nothing reconciled\n });\n }, [loading, queryGrants]);\n\n // A workspace switch invalidates optimistic rows from the previous workspace:\n // clear them so a prior workspace's financier can't bleed into this one's grant\n // table (multi-tenant isolation), and so a revoke can't fire with a stale id.\n useEffect(() => {\n setOptimisticGrants([]);\n }, [workspaceId]);\n\n // A just-granted row shows immediately even before the (occasionally slow/flaky offline)\n // refetch surfaces it. Dedupe by id with the server copy winning, so the optimistic overlay\n // is transient and self-clears once reconciled (above) or on reload.\n const grants: FinancierGrant[] = useMemo(() => {\n const seen = new Set<string>();\n return [...queryGrants, ...optimisticGrants].filter((g) => {\n if (seen.has(g.id)) return false;\n seen.add(g.id);\n return true;\n });\n }, [queryGrants, optimisticGrants]);\n const activeGrants = grants.filter((g) => g.status.toUpperCase() === 'ACTIVE');\n\n const [showGrant, setShowGrant] = useState(false);\n const [submitting, setSubmitting] = useState(false);\n const [revokingId, setRevokingId] = useState<string | null>(null);\n const [financierActorId, setFinancierActorId] = useState('');\n const [financierName, setFinancierName] = useState('');\n const [expiresAt, setExpiresAt] = useState('');\n\n const resetForm = () => {\n setFinancierActorId('');\n setFinancierName('');\n setExpiresAt('');\n };\n\n const handleGrant = async () => {\n if (!financierActorId.trim()) {\n toast({ title: 'Financier ID required', description: 'Enter the financier’s actor id.', variant: 'warning' });\n return;\n }\n setSubmitting(true);\n try {\n const result = await grantAccess({\n variables: {\n input: {\n financierActorId: financierActorId.trim(),\n financierName: financierName.trim() || null,\n scope: 'FINANCIAL_SUMMARY',\n expiresAt: expiresAt ? new Date(expiresAt).toISOString() : null,\n context: { workspaceId },\n },\n },\n });\n // Surface the new grant in the table immediately (refetch reconciles + wins by id).\n const created = result.data?.grantHealthyBowlFinancierAccess;\n if (created) {\n setOptimisticGrants((prev) => [\n {\n id: created.id,\n financierActorId: created.financierActorId,\n financierName: created.financierName,\n status: created.status,\n grantedAt: created.grantedAt,\n // scope/expiresAt aren't in the grant mutation's response selection, so\n // they can't be read from `created`. scope is a fixed design constant\n // (the input always sends FINANCIAL_SUMMARY) and expiresAt mirrors the\n // value just submitted; both are transient — the server copy wins once\n // the query reconciles (see the prune effect above).\n scope: 'FINANCIAL_SUMMARY',\n expiresAt: expiresAt ? new Date(expiresAt).toISOString() : null,\n },\n ...prev.filter((g) => g.id !== created.id),\n ]);\n }\n toast({ title: 'Access granted', description: 'The financier can now see your risk view.', variant: 'success' });\n setShowGrant(false);\n resetForm();\n await refetch();\n } catch {\n toast({ title: 'Grant failed', description: 'Could not grant access. Please try again.', variant: 'error' });\n } finally {\n setSubmitting(false);\n }\n };\n\n const handleRevoke = async (grant: FinancierGrant) => {\n if (\n !window.confirm(\n `Revoke ${grant.financierName || 'this financier'}’s access to your farm’s financial view? They will immediately lose access.`\n )\n ) {\n return;\n }\n setRevokingId(grant.id);\n try {\n await revokeAccess({ variables: { id: grant.id, context: { workspaceId } } });\n toast({\n title: 'Access revoked',\n description: `${grant.financierName || 'Financier'} can no longer see your farm.`,\n variant: 'success',\n });\n setOptimisticGrants((prev) => prev.filter((g) => g.id !== grant.id));\n await refetch();\n } catch {\n toast({ title: 'Revoke failed', description: 'Could not revoke access. Please try again.', variant: 'error' });\n } finally {\n setRevokingId(null);\n }\n };\n\n return (\n <PageLayout\n title=\"Financier Access\"\n description=\"Grant a bank, lender, or cooperative scoped read access to your farm’s financial risk view — and revoke it anytime\"\n actions={\n <button\n onClick={() => setShowGrant(true)}\n className=\"flex items-center gap-1.5 rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90\"\n >\n <Plus className=\"h-4 w-4\" /> Grant Access\n </button>\n }\n >\n <Breadcrumbs items={[{ label: 'Financial', href: buildPath('financial') }, { label: 'Financier Access' }]} />\n\n {loading && grants.length === 0 ? (\n <p className=\"text-sm text-muted-foreground\">Loading grants…</p>\n ) : error && grants.length === 0 ? (\n <div className=\"flex items-center gap-2 rounded-lg border border-border bg-card p-5 text-sm text-muted-foreground\">\n <AlertCircle className=\"h-4 w-4\" /> Financier grants aren't available right now.\n </div>\n ) : activeGrants.length === 0 ? (\n <EmptyState\n title=\"No financier has access\"\n description=\"Grant a financier scoped access to share your farm’s financial standing for credit or lending.\"\n icon={<Landmark className=\"h-12 w-12 text-muted-foreground\" />}\n />\n ) : (\n <div className=\"overflow-hidden rounded-lg border border-border bg-card\">\n <table className=\"w-full text-sm\">\n <thead>\n <tr className=\"border-b border-border text-left text-xs text-muted-foreground\">\n <th className=\"px-4 py-3 font-medium\">Financier</th>\n <th className=\"px-4 py-3 font-medium\">Scope</th>\n <th className=\"px-4 py-3 font-medium\">Granted</th>\n <th className=\"px-4 py-3 font-medium\">Expires</th>\n <th className=\"px-4 py-3 font-medium\">Status</th>\n <th className=\"px-4 py-3 text-right font-medium\">Action</th>\n </tr>\n </thead>\n <tbody>\n {activeGrants.map((g) => (\n <tr key={g.id} className=\"border-b border-border/50 last:border-0\">\n <td className=\"px-4 py-3\">\n <p className=\"font-medium text-foreground\">{g.financierName || 'Unnamed financier'}</p>\n <p className=\"font-mono text-xs text-muted-foreground\" title={g.financierActorId}>\n {shortActor(g.financierActorId)}\n </p>\n </td>\n <td className=\"px-4 py-3\">\n <span className=\"inline-flex items-center gap-1 text-xs text-muted-foreground\">\n <ShieldCheck className=\"h-3.5 w-3.5\" /> Financial summary\n </span>\n </td>\n <td className=\"px-4 py-3 text-muted-foreground\">{formatDate(g.grantedAt)}</td>\n <td className=\"px-4 py-3 text-muted-foreground\">{formatDate(g.expiresAt)}</td>\n <td className=\"px-4 py-3\">\n <StatusBadge label={g.status} variant=\"success\" dot />\n </td>\n <td className=\"px-4 py-3 text-right\">\n <button\n onClick={() => handleRevoke(g)}\n disabled={revokingId === g.id}\n className=\"inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs text-destructive hover:bg-destructive/10 disabled:opacity-60\"\n >\n <Trash2 className=\"h-3.5 w-3.5\" /> {revokingId === g.id ? 'Revoking…' : 'Revoke'}\n </button>\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n )}\n\n <Modal\n open={showGrant}\n onClose={() => {\n setShowGrant(false);\n resetForm();\n }}\n title=\"Grant Financier Access\"\n description=\"Share a scoped, read-only financial summary of your farm. The financier never joins your workspace, and you can revoke this anytime.\"\n footer={\n <>\n <button\n onClick={() => {\n setShowGrant(false);\n resetForm();\n }}\n className=\"rounded-md border border-border px-4 py-2 text-sm text-muted-foreground hover:text-foreground\"\n >\n Cancel\n </button>\n <button\n onClick={handleGrant}\n disabled={submitting}\n className=\"rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-60\"\n >\n {submitting ? 'Granting…' : 'Grant Access'}\n </button>\n </>\n }\n >\n <div className=\"grid gap-4\">\n <div>\n <label className=\"text-sm font-medium text-foreground\">Financier Actor ID *</label>\n <input\n type=\"text\"\n value={financierActorId}\n onChange={(e) => setFinancierActorId(e.target.value)}\n placeholder=\"The financier’s platform user id\"\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n <p className=\"mt-1 text-xs text-muted-foreground\">\n Only this actor will be able to read your scoped financial summary.\n </p>\n </div>\n <div>\n <label className=\"text-sm font-medium text-foreground\">Financier Name</label>\n <input\n type=\"text\"\n value={financierName}\n onChange={(e) => setFinancierName(e.target.value)}\n placeholder=\"e.g., Rural Credit Cooperative\"\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n </div>\n <div>\n <label className=\"text-sm font-medium text-foreground\">Expires (optional)</label>\n <input\n type=\"date\"\n value={expiresAt}\n min={new Date().toISOString().slice(0, 10)}\n onChange={(e) => setExpiresAt(e.target.value)}\n className=\"mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n <p className=\"mt-1 text-xs text-muted-foreground\">Leave blank for access that lasts until you revoke it.</p>\n </div>\n </div>\n </Modal>\n\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AAkCA,IAAM,KAAc,MAAgC;AAClD,KAAI,CAAC,EAAK,QAAO;CACjB,IAAM,IAAK,IAAI,KAAK,EAAI,CAAC,SAAS;AAElC,QADI,OAAO,MAAM,EAAG,GAAS,MACtB,IAAI,KAAK,EAAG,CAAC,mBAAmB,KAAA,GAAW;EAAE,MAAM;EAAW,OAAO;EAAS,KAAK;EAAW,CAAC;GAGlG,KAAc,MAAwB,EAAG,SAAS,KAAK,GAAG,EAAG,MAAM,GAAG,GAAG,CAAC,KAAK,GAExE,UAAgC;CAC3C,IAAM,EAAE,mBAAgB,GAAgB,EAClC,EAAE,iBAAc,GAAa,EAC7B,EAAE,WAAQ,UAAO,eAAY,GAAU,EAEvC,EAAE,SAAM,YAAS,UAAO,eAAY,EAAsC;EAC9E,WAAW,EAAE,SAAS,EAAE,gBAAa,EAAE;EACvC,MAAM,CAAC;EACP,aAAa;EACd,CAAC,EACI,CAAC,KAAe,GAA4C,EAC5D,CAAC,KAAgB,GAA6C,EAE9D,CA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