@burdenoff/microfe-healthybowl 2026.813.29 → 2026.813.31
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/hooks/useHarvestInventory.js.map +1 -1
- package/dist/healthybowl/pages/financial/FinancierAccessPage.js +178 -144
- package/dist/healthybowl/pages/financial/FinancierAccessPage.js.map +1 -1
- package/dist/healthybowl/pages/financial/financierAccessStatus.js +18 -0
- package/dist/healthybowl/pages/financial/financierAccessStatus.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHarvestInventory.js","names":[],"sources":["../../../src/healthybowl/hooks/useHarvestInventory.ts"],"sourcesContent":["/**\n * Harvest → inventory linkage (BOFF-6095).\n *\n * `addToInventory` is a create-time-only flag and the main harvest form never sent it, so produce\n * recorded through the primary route was stranded outside inventory permanently. This hook is the\n * way back in: it links an already-recorded harvest to sellable stock.\n *\n *
|
|
1
|
+
{"version":3,"file":"useHarvestInventory.js","names":[],"sources":["../../../src/healthybowl/hooks/useHarvestInventory.ts"],"sourcesContent":["/**\n * Harvest → inventory linkage (BOFF-6095).\n *\n * `addToInventory` is a create-time-only flag and the main harvest form never sent it, so produce\n * recorded through the primary route was stranded outside inventory permanently. This hook is the\n * way back in: it links an already-recorded harvest to sellable stock.\n *\n * Uses the generated document and types (BOFF-6307). This previously carried a hand-written `gql`\n * document because the committed supergraph snapshot did not yet contain\n * `linkHealthyBowlHarvestToInventory`, so codegen could not type it however often it ran.\n * @module healthybowl\n */\nimport { useCallback, useState } from 'react';\nimport { useMutation } from '@apollo/client/react';\nimport {\n HealthyBowlLinkHarvestToInventoryDocument,\n type HealthyBowlLinkHarvestToInventoryMutation,\n type HealthyBowlLinkHarvestToInventoryMutationVariables,\n} from '../../generated/wspace-operations';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\n\n/**\n * Exposes a single action: bank a recorded harvest into inventory.\n *\n * `isLinking(id)` reports whether that specific harvest is in flight, so a list disables only the\n * row being linked. This tracks a SET rather than one id: with a single id, linking card A and then\n * card B meant A's completion cleared the flag while B was still in flight, re-enabling B's button\n * mid-request. The server side is idempotent by `HarvestRecord.productId` and its stamp is a\n * compare-and-set, so a stray second click could not double-bank — but the UI should not invite one.\n */\nexport function useHarvestInventory() {\n const { workspaceId } = useHealthyBowl();\n const context = { workspaceId };\n const [linkingIds, setLinkingIds] = useState<ReadonlySet<string>>(() => new Set());\n const [linkMutation] = useMutation<\n HealthyBowlLinkHarvestToInventoryMutation,\n HealthyBowlLinkHarvestToInventoryMutationVariables\n >(HealthyBowlLinkHarvestToInventoryDocument);\n\n const linkToInventory = useCallback(\n async (harvestId: string, productCategory?: string) => {\n setLinkingIds((prev) => new Set(prev).add(harvestId));\n try {\n const res = await linkMutation({\n variables: { input: { id: harvestId, productCategory, context } },\n });\n return res.data?.linkHealthyBowlHarvestToInventory?.productId ?? null;\n } finally {\n setLinkingIds((prev) => {\n const next = new Set(prev);\n next.delete(harvestId);\n return next;\n });\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [linkMutation, workspaceId]\n );\n\n const isLinking = useCallback((harvestId: string) => linkingIds.has(harvestId), [linkingIds]);\n\n return { linkToInventory, isLinking };\n}\n"],"mappings":";;;;;AA8BA,SAAgB,IAAsB;CACpC,IAAM,EAAE,mBAAgB,GAAgB,EAClC,IAAU,EAAE,gBAAa,EACzB,CAAC,GAAY,KAAiB,wBAAoC,IAAI,KAAK,CAAC,EAC5E,CAAC,KAAgB,EAGrB,EAA0C;AAwB5C,QAAO;EAAE,iBAtBe,EACtB,OAAO,GAAmB,MAA6B;AACrD,MAAe,MAAS,IAAI,IAAI,EAAK,CAAC,IAAI,EAAU,CAAC;AACrD,OAAI;AAIF,YAHY,MAAM,EAAa,EAC7B,WAAW,EAAE,OAAO;KAAE,IAAI;KAAW;KAAiB;KAAS,EAAE,EAClE,CAAC,EACS,MAAM,mCAAmC,aAAa;aACzD;AACR,OAAe,MAAS;KACtB,IAAM,IAAO,IAAI,IAAI,EAAK;AAE1B,YADA,EAAK,OAAO,EAAU,EACf;MACP;;KAIN,CAAC,GAAc,EAAY,CAC5B;EAIyB,WAFR,GAAa,MAAsB,EAAW,IAAI,EAAU,EAAE,CAAC,EAAW,CAAC;EAExD"}
|
|
@@ -2,19 +2,20 @@ import { useHealthyBowl as e } from "../../context/HealthyBowlContext.js";
|
|
|
2
2
|
import { useBasePath as t } from "../../hooks/useBasePath.js";
|
|
3
3
|
import { PageLayout as n } from "../../components/PageLayout.js";
|
|
4
4
|
import { StatusBadge as r } from "../../components/StatusBadge.js";
|
|
5
|
-
import { EmptyState as
|
|
6
|
-
import { ToastContainer as
|
|
7
|
-
import { useConfirm as
|
|
5
|
+
import { EmptyState as ee } from "../../components/EmptyState.js";
|
|
6
|
+
import { ToastContainer as i } from "../../components/Toast.js";
|
|
7
|
+
import { useConfirm as a } from "../../components/ConfirmDialog.js";
|
|
8
8
|
import { Breadcrumbs as o } from "../../components/Breadcrumbs.js";
|
|
9
9
|
import { Modal as te } from "../../components/Modal.js";
|
|
10
|
-
import { useGetHealthyBowlFinancierGrantsQuery as
|
|
11
|
-
import { useToast as
|
|
10
|
+
import { useGetHealthyBowlFinancierGrantsQuery as ne, useGrantHealthyBowlFinancierAccessMutation as re, useRevokeHealthyBowlFinancierAccessMutation as s } from "../../../generated/wspace-operations.js";
|
|
11
|
+
import { useToast as c } from "../../hooks/useToast.js";
|
|
12
12
|
import "../../components/index.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
13
|
+
import { financierGrantBadgeState as l, isCountedActive as u } from "./financierAccessStatus.js";
|
|
14
|
+
import { useCallback as ie, useEffect as d, useMemo as f, useState as p } from "react";
|
|
15
|
+
import { useI18n as ae } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
|
|
16
|
+
import { AlertCircle as m, Plus as oe, ShieldCheck as h, Trash2 as g } from "lucide-react";
|
|
17
|
+
import { Fragment as _, jsx as v, jsxs as y } from "react/jsx-runtime";
|
|
18
|
+
import { Button as b, ResponsiveTable as x } from "@burdenoff/fe-libs/ui";
|
|
18
19
|
//#region src/healthybowl/pages/financial/FinancierAccessPage.tsx
|
|
19
20
|
var S = (e) => {
|
|
20
21
|
if (!e) return "—";
|
|
@@ -25,97 +26,116 @@ var S = (e) => {
|
|
|
25
26
|
day: "numeric"
|
|
26
27
|
});
|
|
27
28
|
}, C = (e) => e.length > 14 ? `${e.slice(0, 10)}…` : e, w = () => {
|
|
28
|
-
let { workspaceId: w } = e(), { buildPath:
|
|
29
|
+
let { workspaceId: w } = e(), { buildPath: se } = t(), { toasts: ce, toast: T, dismiss: le } = c(), { t: E } = ae(), ue = a(), { data: D, loading: O, error: k, refetch: A } = ne({
|
|
29
30
|
variables: { context: { workspaceId: w } },
|
|
30
31
|
skip: !w,
|
|
31
32
|
fetchPolicy: "cache-and-network"
|
|
32
|
-
}), [
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
let e = new Set(
|
|
36
|
-
|
|
33
|
+
}), [j] = re(), [M] = s(), [N, P] = p([]), F = f(() => D?.getHealthyBowlFinancierGrants ?? [], [D]);
|
|
34
|
+
d(() => {
|
|
35
|
+
if (O) return;
|
|
36
|
+
let e = new Set(F.map((e) => e.id));
|
|
37
|
+
P((t) => {
|
|
37
38
|
let n = t.filter((t) => !e.has(t.id));
|
|
38
39
|
return n.length === t.length ? t : n;
|
|
39
40
|
});
|
|
40
|
-
}, [
|
|
41
|
-
|
|
41
|
+
}, [O, F]), d(() => {
|
|
42
|
+
P([]);
|
|
42
43
|
}, [w]);
|
|
43
|
-
let
|
|
44
|
+
let I = f(() => {
|
|
44
45
|
let e = /* @__PURE__ */ new Set();
|
|
45
|
-
return [...
|
|
46
|
-
}, [
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
if (!
|
|
50
|
-
|
|
51
|
-
title:
|
|
52
|
-
description:
|
|
46
|
+
return [...F, ...N].filter((t) => e.has(t.id) ? !1 : (e.add(t.id), !0));
|
|
47
|
+
}, [F, N]), L = I.filter((e) => u(e.status, e.expiresAt)), R = I.filter((e) => l(e.status, e.expiresAt) === "EXPIRING_SOON"), [z, B] = p(!1), [V, H] = p(!1), [U, W] = p(null), [G, K] = p(""), [q, J] = p(""), [Y, X] = p(""), Z = () => {
|
|
48
|
+
K(""), J(""), X("");
|
|
49
|
+
}, de = async () => {
|
|
50
|
+
if (!G.trim()) {
|
|
51
|
+
T({
|
|
52
|
+
title: E("healthybowl.financial.financierAccess.toast.idRequired.title", "Financier ID required"),
|
|
53
|
+
description: E("healthybowl.financial.financierAccess.toast.idRequired.description", "Enter the financier’s actor id."),
|
|
53
54
|
variant: "warning"
|
|
54
55
|
});
|
|
55
56
|
return;
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
+
H(!0);
|
|
58
59
|
try {
|
|
59
|
-
let e = (await
|
|
60
|
-
financierActorId:
|
|
61
|
-
financierName:
|
|
60
|
+
let e = (await j({ variables: { input: {
|
|
61
|
+
financierActorId: G.trim(),
|
|
62
|
+
financierName: q.trim() || null,
|
|
62
63
|
scope: "FINANCIAL_SUMMARY",
|
|
63
|
-
expiresAt:
|
|
64
|
+
expiresAt: Y ? new Date(Y).toISOString() : null,
|
|
64
65
|
context: { workspaceId: w }
|
|
65
66
|
} } })).data?.grantHealthyBowlFinancierAccess;
|
|
66
|
-
e &&
|
|
67
|
+
e && P((t) => [{
|
|
67
68
|
id: e.id,
|
|
68
69
|
financierActorId: e.financierActorId,
|
|
69
70
|
financierName: e.financierName,
|
|
70
71
|
status: e.status,
|
|
71
72
|
grantedAt: e.grantedAt,
|
|
72
73
|
scope: "FINANCIAL_SUMMARY",
|
|
73
|
-
expiresAt:
|
|
74
|
-
}, ...t.filter((t) => t.id !== e.id)]),
|
|
75
|
-
title:
|
|
76
|
-
description:
|
|
74
|
+
expiresAt: Y ? new Date(Y).toISOString() : null
|
|
75
|
+
}, ...t.filter((t) => t.id !== e.id)]), T({
|
|
76
|
+
title: E("healthybowl.financial.financierAccess.toast.granted.title", "Access granted"),
|
|
77
|
+
description: E("healthybowl.financial.financierAccess.toast.granted.description", "The financier can now see your risk view."),
|
|
77
78
|
variant: "success"
|
|
78
|
-
}),
|
|
79
|
+
}), B(!1), Z(), await A();
|
|
79
80
|
} catch {
|
|
80
|
-
|
|
81
|
-
title:
|
|
82
|
-
description:
|
|
81
|
+
T({
|
|
82
|
+
title: E("healthybowl.financial.financierAccess.toast.grantFailed.title", "Grant failed"),
|
|
83
|
+
description: E("healthybowl.financial.financierAccess.toast.grantFailed.description", "Could not grant access. Please try again."),
|
|
83
84
|
variant: "error"
|
|
84
85
|
});
|
|
85
86
|
} finally {
|
|
86
|
-
|
|
87
|
+
H(!1);
|
|
87
88
|
}
|
|
88
|
-
},
|
|
89
|
-
if (await
|
|
90
|
-
|
|
89
|
+
}, Q = async (e) => {
|
|
90
|
+
if (await ue({ message: E("healthybowl.financial.financierAccess.confirm.revoke", "Revoke {{name}}’s access to your farm’s financial view? They will immediately lose access.", { name: e.financierName || E("healthybowl.financial.financierAccess.confirm.thisFinancier", "this financier") }) })) {
|
|
91
|
+
W(e.id);
|
|
91
92
|
try {
|
|
92
|
-
await
|
|
93
|
+
await M({ variables: {
|
|
93
94
|
id: e.id,
|
|
94
95
|
context: { workspaceId: w }
|
|
95
|
-
} }),
|
|
96
|
-
title:
|
|
97
|
-
description:
|
|
96
|
+
} }), T({
|
|
97
|
+
title: E("healthybowl.financial.financierAccess.toast.revoked.title", "Access revoked"),
|
|
98
|
+
description: E("healthybowl.financial.financierAccess.toast.revoked.description", "{{name}} can no longer see your farm.", { name: e.financierName || E("healthybowl.financial.financierAccess.toast.revoked.financierFallback", "Financier") }),
|
|
98
99
|
variant: "success"
|
|
99
|
-
}),
|
|
100
|
+
}), P((t) => t.filter((t) => t.id !== e.id)), await A();
|
|
100
101
|
} catch {
|
|
101
|
-
|
|
102
|
-
title:
|
|
103
|
-
description:
|
|
102
|
+
T({
|
|
103
|
+
title: E("healthybowl.financial.financierAccess.toast.revokeFailed.title", "Revoke failed"),
|
|
104
|
+
description: E("healthybowl.financial.financierAccess.toast.revokeFailed.description", "Could not revoke access. Please try again."),
|
|
104
105
|
variant: "error"
|
|
105
106
|
});
|
|
106
107
|
} finally {
|
|
107
|
-
|
|
108
|
+
W(null);
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
|
-
},
|
|
111
|
+
}, $ = ie((e) => {
|
|
112
|
+
switch (e) {
|
|
113
|
+
case "ACTIVE": return {
|
|
114
|
+
label: E("healthybowl.financial.financierAccess.status.active", "Active"),
|
|
115
|
+
variant: "success"
|
|
116
|
+
};
|
|
117
|
+
case "EXPIRING_SOON": return {
|
|
118
|
+
label: E("healthybowl.financial.financierAccess.status.expiringSoon", "Expiring soon"),
|
|
119
|
+
variant: "warning"
|
|
120
|
+
};
|
|
121
|
+
case "EXPIRED": return {
|
|
122
|
+
label: E("healthybowl.financial.financierAccess.status.expired", "Expired"),
|
|
123
|
+
variant: "muted"
|
|
124
|
+
};
|
|
125
|
+
case "REVOKED": return {
|
|
126
|
+
label: E("healthybowl.financial.financierAccess.status.revoked", "Revoked"),
|
|
127
|
+
variant: "muted"
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}, [E]), fe = f(() => [
|
|
111
131
|
{
|
|
112
132
|
key: "financier",
|
|
113
|
-
header:
|
|
133
|
+
header: E("healthybowl.financial.financierAccess.table.headers.financier", "Financier"),
|
|
114
134
|
priority: "primary",
|
|
115
|
-
cell: (e) => /* @__PURE__ */
|
|
135
|
+
cell: (e) => /* @__PURE__ */ y(_, { children: [/* @__PURE__ */ v("p", {
|
|
116
136
|
className: "font-medium text-text-primary",
|
|
117
|
-
children: e.financierName ||
|
|
118
|
-
}), /* @__PURE__ */
|
|
137
|
+
children: e.financierName || E("healthybowl.financial.financierAccess.table.unnamedFinancier", "Unnamed financier")
|
|
138
|
+
}), /* @__PURE__ */ v("p", {
|
|
119
139
|
className: "font-mono text-xs text-text-secondary",
|
|
120
140
|
title: e.financierActorId,
|
|
121
141
|
children: C(e.financierActorId)
|
|
@@ -123,175 +143,189 @@ var S = (e) => {
|
|
|
123
143
|
},
|
|
124
144
|
{
|
|
125
145
|
key: "scope",
|
|
126
|
-
header:
|
|
146
|
+
header: E("healthybowl.financial.financierAccess.table.headers.scope", "Scope"),
|
|
127
147
|
priority: "secondary",
|
|
128
|
-
cell: () => /* @__PURE__ */
|
|
148
|
+
cell: () => /* @__PURE__ */ y("span", {
|
|
129
149
|
className: "inline-flex items-center gap-1 text-xs text-text-secondary",
|
|
130
150
|
children: [
|
|
131
|
-
/* @__PURE__ */
|
|
151
|
+
/* @__PURE__ */ v(h, { className: "h-3.5 w-3.5" }),
|
|
132
152
|
" ",
|
|
133
|
-
|
|
153
|
+
E("healthybowl.financial.financierAccess.table.scopeFinancialSummary", "Financial summary")
|
|
134
154
|
]
|
|
135
155
|
})
|
|
136
156
|
},
|
|
137
157
|
{
|
|
138
158
|
key: "granted",
|
|
139
|
-
header:
|
|
159
|
+
header: E("healthybowl.financial.financierAccess.table.headers.granted", "Granted"),
|
|
140
160
|
priority: "secondary",
|
|
141
161
|
cellClassName: "text-text-secondary",
|
|
142
162
|
cell: (e) => S(e.grantedAt)
|
|
143
163
|
},
|
|
144
164
|
{
|
|
145
165
|
key: "expires",
|
|
146
|
-
header:
|
|
166
|
+
header: E("healthybowl.financial.financierAccess.table.headers.expires", "Expires"),
|
|
147
167
|
priority: "secondary",
|
|
148
168
|
cellClassName: "text-text-secondary",
|
|
149
169
|
cell: (e) => S(e.expiresAt)
|
|
150
170
|
},
|
|
151
171
|
{
|
|
152
172
|
key: "status",
|
|
153
|
-
header:
|
|
173
|
+
header: E("healthybowl.financial.financierAccess.table.headers.status", "Status"),
|
|
154
174
|
priority: "secondary",
|
|
155
|
-
cell: (e) =>
|
|
156
|
-
label: e.status,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
175
|
+
cell: (e) => {
|
|
176
|
+
let { label: t, variant: n } = $(l(e.status, e.expiresAt));
|
|
177
|
+
return /* @__PURE__ */ v(r, {
|
|
178
|
+
label: t,
|
|
179
|
+
variant: n,
|
|
180
|
+
dot: !0
|
|
181
|
+
});
|
|
182
|
+
}
|
|
160
183
|
},
|
|
161
184
|
{
|
|
162
185
|
key: "action",
|
|
163
|
-
header:
|
|
186
|
+
header: E("healthybowl.financial.financierAccess.table.headers.action", "Action"),
|
|
164
187
|
priority: "secondary",
|
|
165
188
|
headerClassName: "text-end",
|
|
166
189
|
cellClassName: "text-end",
|
|
167
|
-
cell: (e) => /* @__PURE__ */ b
|
|
190
|
+
cell: (e) => /* @__PURE__ */ y(b, {
|
|
168
191
|
variant: "destructive",
|
|
169
192
|
size: "sm",
|
|
170
|
-
onClick: () =>
|
|
171
|
-
disabled:
|
|
193
|
+
onClick: () => Q(e),
|
|
194
|
+
disabled: U === e.id,
|
|
172
195
|
children: [
|
|
173
|
-
/* @__PURE__ */
|
|
196
|
+
/* @__PURE__ */ v(g, { className: "h-3.5 w-3.5" }),
|
|
174
197
|
" ",
|
|
175
|
-
|
|
198
|
+
U === e.id ? E("healthybowl.financial.financierAccess.actions.revoking", "Revoking…") : E("healthybowl.financial.financierAccess.actions.revoke", "Revoke")
|
|
176
199
|
]
|
|
177
200
|
})
|
|
178
201
|
}
|
|
179
202
|
], [
|
|
180
|
-
|
|
181
|
-
|
|
203
|
+
E,
|
|
204
|
+
U,
|
|
205
|
+
Q,
|
|
182
206
|
$
|
|
183
207
|
]);
|
|
184
|
-
return /* @__PURE__ */
|
|
185
|
-
title:
|
|
186
|
-
description:
|
|
208
|
+
return /* @__PURE__ */ y(n, {
|
|
209
|
+
title: E("healthybowl.financial.financierAccess.title", "Financier Access"),
|
|
210
|
+
description: E("healthybowl.financial.financierAccess.description", "Grant a bank, lender, or cooperative scoped read access to your farm’s financial risk view — and revoke it anytime"),
|
|
187
211
|
purpose: "Let a bank, lender or cooperative see a read-only view of your farm's financial health — handy when applying for a loan or grant — and pull that access back the moment you no longer need it.",
|
|
188
|
-
actions: /* @__PURE__ */ b
|
|
189
|
-
onClick: () =>
|
|
212
|
+
actions: /* @__PURE__ */ y(b, {
|
|
213
|
+
onClick: () => B(!0),
|
|
190
214
|
children: [
|
|
191
|
-
/* @__PURE__ */
|
|
215
|
+
/* @__PURE__ */ v(oe, { className: "h-4 w-4" }),
|
|
192
216
|
" ",
|
|
193
|
-
|
|
217
|
+
E("healthybowl.financial.financierAccess.actions.grant", "Grant Access")
|
|
194
218
|
]
|
|
195
219
|
}),
|
|
196
220
|
children: [
|
|
197
|
-
/* @__PURE__ */
|
|
198
|
-
label:
|
|
199
|
-
href:
|
|
200
|
-
}, { label:
|
|
201
|
-
|
|
221
|
+
/* @__PURE__ */ v(o, { items: [{
|
|
222
|
+
label: E("healthybowl.financial.financierAccess.breadcrumbs.financial", "Financial"),
|
|
223
|
+
href: se("financial")
|
|
224
|
+
}, { label: E("healthybowl.financial.financierAccess.breadcrumbs.financierAccess", "Financier Access") }] }),
|
|
225
|
+
O && I.length === 0 ? /* @__PURE__ */ v("p", {
|
|
202
226
|
className: "text-sm text-text-secondary",
|
|
203
|
-
children:
|
|
204
|
-
}) :
|
|
227
|
+
children: E("healthybowl.financial.financierAccess.loading", "Loading grants…")
|
|
228
|
+
}) : k && I.length === 0 ? /* @__PURE__ */ y("div", {
|
|
205
229
|
className: "flex items-center gap-2 rounded-lg border border-border-subtle bg-bg-surface p-5 text-sm text-text-secondary",
|
|
206
230
|
children: [
|
|
207
|
-
/* @__PURE__ */
|
|
231
|
+
/* @__PURE__ */ v(m, { className: "h-4 w-4" }),
|
|
208
232
|
" ",
|
|
209
|
-
|
|
233
|
+
E("healthybowl.financial.financierAccess.error", "Financier grants aren’t available right now.")
|
|
210
234
|
]
|
|
211
|
-
}) :
|
|
235
|
+
}) : I.length === 0 ? /* @__PURE__ */ v(ee, {
|
|
212
236
|
illustration: "empty-people",
|
|
213
|
-
title:
|
|
214
|
-
description:
|
|
215
|
-
}) : /* @__PURE__ */ y(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
237
|
+
title: E("healthybowl.financial.financierAccess.emptyState.title", "No financier has access"),
|
|
238
|
+
description: E("healthybowl.financial.financierAccess.emptyState.description", "Grant a financier scoped access to share your farm’s financial standing for credit or lending.")
|
|
239
|
+
}) : /* @__PURE__ */ y(_, { children: [
|
|
240
|
+
/* @__PURE__ */ v("p", {
|
|
241
|
+
className: "mb-2 text-sm text-text-secondary",
|
|
242
|
+
children: E("healthybowl.financial.financierAccess.activeCount", "{{count}} active grant(s)", { count: L.length })
|
|
243
|
+
}),
|
|
244
|
+
R.length > 0 && /* @__PURE__ */ y("div", {
|
|
245
|
+
className: "mb-4 flex items-center gap-2 rounded-lg border border-status-warning-border bg-status-warning-bg px-4 py-3 text-sm text-status-warning-text",
|
|
246
|
+
children: [/* @__PURE__ */ v(m, { className: "h-4 w-4 shrink-0" }), /* @__PURE__ */ v("span", { children: E("healthybowl.financial.financierAccess.banner.expiringSoon", "{{count}} financier grant(s) are expiring within 30 days — review and revoke access you no longer need.", { count: R.length }) })]
|
|
247
|
+
}),
|
|
248
|
+
/* @__PURE__ */ v("div", {
|
|
249
|
+
className: "overflow-hidden rounded-lg border border-border-subtle bg-bg-surface",
|
|
250
|
+
children: /* @__PURE__ */ v(x, {
|
|
251
|
+
columns: fe,
|
|
252
|
+
data: I,
|
|
253
|
+
rowKey: (e) => String(e.id)
|
|
254
|
+
})
|
|
221
255
|
})
|
|
222
|
-
}),
|
|
223
|
-
/* @__PURE__ */
|
|
224
|
-
open:
|
|
256
|
+
] }),
|
|
257
|
+
/* @__PURE__ */ v(te, {
|
|
258
|
+
open: z,
|
|
225
259
|
onClose: () => {
|
|
226
|
-
|
|
260
|
+
B(!1), Z();
|
|
227
261
|
},
|
|
228
|
-
title:
|
|
229
|
-
description:
|
|
230
|
-
footer: /* @__PURE__ */
|
|
262
|
+
title: E("healthybowl.financial.financierAccess.modal.title", "Grant Financier Access"),
|
|
263
|
+
description: E("healthybowl.financial.financierAccess.modal.description", "Share a scoped, read-only financial summary of your farm. The financier never joins your workspace, and you can revoke this anytime."),
|
|
264
|
+
footer: /* @__PURE__ */ y(_, { children: [/* @__PURE__ */ v(b, {
|
|
231
265
|
variant: "outline",
|
|
232
266
|
onClick: () => {
|
|
233
|
-
|
|
267
|
+
B(!1), Z();
|
|
234
268
|
},
|
|
235
269
|
className: "text-text-secondary",
|
|
236
|
-
children:
|
|
237
|
-
}), /* @__PURE__ */
|
|
238
|
-
onClick:
|
|
239
|
-
disabled:
|
|
240
|
-
children:
|
|
270
|
+
children: E("healthybowl.common.cancel", "Cancel")
|
|
271
|
+
}), /* @__PURE__ */ v(b, {
|
|
272
|
+
onClick: de,
|
|
273
|
+
disabled: V,
|
|
274
|
+
children: V ? E("healthybowl.financial.financierAccess.actions.granting", "Granting…") : E("healthybowl.financial.financierAccess.actions.grant", "Grant Access")
|
|
241
275
|
})] }),
|
|
242
|
-
children: /* @__PURE__ */
|
|
276
|
+
children: /* @__PURE__ */ y("div", {
|
|
243
277
|
className: "grid gap-4",
|
|
244
278
|
children: [
|
|
245
|
-
/* @__PURE__ */
|
|
246
|
-
/* @__PURE__ */
|
|
279
|
+
/* @__PURE__ */ y("div", { children: [
|
|
280
|
+
/* @__PURE__ */ v("label", {
|
|
247
281
|
className: "text-sm font-medium text-text-primary",
|
|
248
|
-
children:
|
|
282
|
+
children: E("healthybowl.financial.financierAccess.form.fields.actorId.label", "Financier Actor ID *")
|
|
249
283
|
}),
|
|
250
|
-
/* @__PURE__ */
|
|
284
|
+
/* @__PURE__ */ v("input", {
|
|
251
285
|
type: "text",
|
|
252
|
-
value:
|
|
253
|
-
onChange: (e) =>
|
|
254
|
-
placeholder:
|
|
286
|
+
value: G,
|
|
287
|
+
onChange: (e) => K(e.target.value),
|
|
288
|
+
placeholder: E("healthybowl.financial.financierAccess.form.fields.actorId.placeholder", "The financier’s platform user id"),
|
|
255
289
|
className: "mt-1 w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 font-mono text-sm text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]"
|
|
256
290
|
}),
|
|
257
|
-
/* @__PURE__ */
|
|
291
|
+
/* @__PURE__ */ v("p", {
|
|
258
292
|
className: "mt-1 text-xs text-text-secondary",
|
|
259
|
-
children:
|
|
293
|
+
children: E("healthybowl.financial.financierAccess.form.fields.actorId.helperText", "Only this actor will be able to read your scoped financial summary.")
|
|
260
294
|
})
|
|
261
295
|
] }),
|
|
262
|
-
/* @__PURE__ */
|
|
296
|
+
/* @__PURE__ */ y("div", { children: [/* @__PURE__ */ v("label", {
|
|
263
297
|
className: "text-sm font-medium text-text-primary",
|
|
264
|
-
children:
|
|
265
|
-
}), /* @__PURE__ */
|
|
298
|
+
children: E("healthybowl.financial.financierAccess.form.fields.name.label", "Financier Name")
|
|
299
|
+
}), /* @__PURE__ */ v("input", {
|
|
266
300
|
type: "text",
|
|
267
|
-
value:
|
|
268
|
-
onChange: (e) =>
|
|
269
|
-
placeholder:
|
|
301
|
+
value: q,
|
|
302
|
+
onChange: (e) => J(e.target.value),
|
|
303
|
+
placeholder: E("healthybowl.financial.financierAccess.form.fields.name.placeholder", "e.g., Rural Credit Cooperative"),
|
|
270
304
|
className: "mt-1 w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]"
|
|
271
305
|
})] }),
|
|
272
|
-
/* @__PURE__ */
|
|
273
|
-
/* @__PURE__ */
|
|
306
|
+
/* @__PURE__ */ y("div", { children: [
|
|
307
|
+
/* @__PURE__ */ v("label", {
|
|
274
308
|
className: "text-sm font-medium text-text-primary",
|
|
275
|
-
children:
|
|
309
|
+
children: E("healthybowl.financial.financierAccess.form.fields.expires.label", "Expires (optional)")
|
|
276
310
|
}),
|
|
277
|
-
/* @__PURE__ */
|
|
311
|
+
/* @__PURE__ */ v("input", {
|
|
278
312
|
type: "date",
|
|
279
|
-
value:
|
|
313
|
+
value: Y,
|
|
280
314
|
min: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
|
|
281
|
-
onChange: (e) =>
|
|
315
|
+
onChange: (e) => X(e.target.value),
|
|
282
316
|
className: "mt-1 w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]"
|
|
283
317
|
}),
|
|
284
|
-
/* @__PURE__ */
|
|
318
|
+
/* @__PURE__ */ v("p", {
|
|
285
319
|
className: "mt-1 text-xs text-text-secondary",
|
|
286
|
-
children:
|
|
320
|
+
children: E("healthybowl.financial.financierAccess.form.fields.expires.helperText", "Leave blank for access that lasts until you revoke it.")
|
|
287
321
|
})
|
|
288
322
|
] })
|
|
289
323
|
]
|
|
290
324
|
})
|
|
291
325
|
}),
|
|
292
|
-
/* @__PURE__ */
|
|
293
|
-
toasts:
|
|
294
|
-
onDismiss:
|
|
326
|
+
/* @__PURE__ */ v(i, {
|
|
327
|
+
toasts: ce,
|
|
328
|
+
onDismiss: le
|
|
295
329
|
})
|
|
296
330
|
]
|
|
297
331
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FinancierAccessPage.js","names":[],"sources":["../../../../src/healthybowl/pages/financial/FinancierAccessPage.tsx"],"sourcesContent":["import { useState, useEffect, useMemo, type FC } from 'react';\nimport { Plus, ShieldCheck, Trash2, AlertCircle } from 'lucide-react';\nimport { PageLayout, StatusBadge, EmptyState, Modal, Breadcrumbs, useConfirm } from '../../components';\nimport { ToastContainer } from '../../components/Toast';\nimport { Button, ResponsiveTable, type ResponsiveTableColumn } from '@burdenoff/fe-libs/ui';\nimport { useToast } from '../../hooks/useToast';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { useHealthyBowl } from '../../context/HealthyBowlContext';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\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 const { t } = useI18n();\n const confirm = useConfirm();\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({\n title: t('healthybowl.financial.financierAccess.toast.idRequired.title', 'Financier ID required'),\n description: t(\n 'healthybowl.financial.financierAccess.toast.idRequired.description',\n 'Enter the financier’s actor id.'\n ),\n variant: 'warning',\n });\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({\n title: t('healthybowl.financial.financierAccess.toast.granted.title', 'Access granted'),\n description: t(\n 'healthybowl.financial.financierAccess.toast.granted.description',\n 'The financier can now see your risk view.'\n ),\n variant: 'success',\n });\n setShowGrant(false);\n resetForm();\n await refetch();\n } catch {\n toast({\n title: t('healthybowl.financial.financierAccess.toast.grantFailed.title', 'Grant failed'),\n description: t(\n 'healthybowl.financial.financierAccess.toast.grantFailed.description',\n 'Could not grant access. Please try again.'\n ),\n variant: 'error',\n });\n } finally {\n setSubmitting(false);\n }\n };\n\n const handleRevoke = async (grant: FinancierGrant) => {\n if (\n !(await confirm({\n message: t(\n 'healthybowl.financial.financierAccess.confirm.revoke',\n 'Revoke {{name}}’s access to your farm’s financial view? They will immediately lose access.',\n {\n name:\n grant.financierName || t('healthybowl.financial.financierAccess.confirm.thisFinancier', 'this financier'),\n }\n ),\n }))\n ) {\n return;\n }\n setRevokingId(grant.id);\n try {\n await revokeAccess({ variables: { id: grant.id, context: { workspaceId } } });\n toast({\n title: t('healthybowl.financial.financierAccess.toast.revoked.title', 'Access revoked'),\n description: t(\n 'healthybowl.financial.financierAccess.toast.revoked.description',\n '{{name}} can no longer see your farm.',\n {\n name:\n grant.financierName ||\n t('healthybowl.financial.financierAccess.toast.revoked.financierFallback', 'Financier'),\n }\n ),\n variant: 'success',\n });\n setOptimisticGrants((prev) => prev.filter((g) => g.id !== grant.id));\n await refetch();\n } catch {\n toast({\n title: t('healthybowl.financial.financierAccess.toast.revokeFailed.title', 'Revoke failed'),\n description: t(\n 'healthybowl.financial.financierAccess.toast.revokeFailed.description',\n 'Could not revoke access. Please try again.'\n ),\n variant: 'error',\n });\n } finally {\n setRevokingId(null);\n }\n };\n\n const columns: ResponsiveTableColumn<FinancierGrant>[] = useMemo(\n () => [\n {\n key: 'financier',\n header: t('healthybowl.financial.financierAccess.table.headers.financier', 'Financier'),\n priority: 'primary',\n cell: (g) => (\n <>\n <p className=\"font-medium text-text-primary\">\n {g.financierName ||\n t('healthybowl.financial.financierAccess.table.unnamedFinancier', 'Unnamed financier')}\n </p>\n <p className=\"font-mono text-xs text-text-secondary\" title={g.financierActorId}>\n {shortActor(g.financierActorId)}\n </p>\n </>\n ),\n },\n {\n key: 'scope',\n header: t('healthybowl.financial.financierAccess.table.headers.scope', 'Scope'),\n priority: 'secondary',\n cell: () => (\n <span className=\"inline-flex items-center gap-1 text-xs text-text-secondary\">\n <ShieldCheck className=\"h-3.5 w-3.5\" />{' '}\n {t('healthybowl.financial.financierAccess.table.scopeFinancialSummary', 'Financial summary')}\n </span>\n ),\n },\n {\n key: 'granted',\n header: t('healthybowl.financial.financierAccess.table.headers.granted', 'Granted'),\n priority: 'secondary',\n cellClassName: 'text-text-secondary',\n cell: (g) => formatDate(g.grantedAt),\n },\n {\n key: 'expires',\n header: t('healthybowl.financial.financierAccess.table.headers.expires', 'Expires'),\n priority: 'secondary',\n cellClassName: 'text-text-secondary',\n cell: (g) => formatDate(g.expiresAt),\n },\n {\n key: 'status',\n header: t('healthybowl.financial.financierAccess.table.headers.status', 'Status'),\n priority: 'secondary',\n cell: (g) => <StatusBadge label={g.status} variant=\"success\" dot />,\n },\n {\n key: 'action',\n header: t('healthybowl.financial.financierAccess.table.headers.action', 'Action'),\n priority: 'secondary',\n headerClassName: 'text-end',\n cellClassName: 'text-end',\n cell: (g) => (\n <Button variant=\"destructive\" size=\"sm\" onClick={() => handleRevoke(g)} disabled={revokingId === g.id}>\n <Trash2 className=\"h-3.5 w-3.5\" />{' '}\n {revokingId === g.id\n ? t('healthybowl.financial.financierAccess.actions.revoking', 'Revoking…')\n : t('healthybowl.financial.financierAccess.actions.revoke', 'Revoke')}\n </Button>\n ),\n },\n ],\n [t, revokingId, handleRevoke]\n );\n\n return (\n <PageLayout\n title={t('healthybowl.financial.financierAccess.title', 'Financier Access')}\n description={t(\n 'healthybowl.financial.financierAccess.description',\n 'Grant a bank, lender, or cooperative scoped read access to your farm’s financial risk view — and revoke it anytime'\n )}\n purpose=\"Let a bank, lender or cooperative see a read-only view of your farm's financial health — handy when applying for a loan or grant — and pull that access back the moment you no longer need it.\"\n actions={\n <Button onClick={() => setShowGrant(true)}>\n <Plus className=\"h-4 w-4\" /> {t('healthybowl.financial.financierAccess.actions.grant', 'Grant Access')}\n </Button>\n }\n >\n <Breadcrumbs\n items={[\n {\n label: t('healthybowl.financial.financierAccess.breadcrumbs.financial', 'Financial'),\n href: buildPath('financial'),\n },\n { label: t('healthybowl.financial.financierAccess.breadcrumbs.financierAccess', 'Financier Access') },\n ]}\n />\n\n {loading && grants.length === 0 ? (\n <p className=\"text-sm text-text-secondary\">\n {t('healthybowl.financial.financierAccess.loading', 'Loading grants…')}\n </p>\n ) : error && grants.length === 0 ? (\n <div className=\"flex items-center gap-2 rounded-lg border border-border-subtle bg-bg-surface p-5 text-sm text-text-secondary\">\n <AlertCircle className=\"h-4 w-4\" />{' '}\n {t('healthybowl.financial.financierAccess.error', 'Financier grants aren’t available right now.')}\n </div>\n ) : activeGrants.length === 0 ? (\n <EmptyState\n illustration=\"empty-people\"\n title={t('healthybowl.financial.financierAccess.emptyState.title', 'No financier has access')}\n description={t(\n 'healthybowl.financial.financierAccess.emptyState.description',\n 'Grant a financier scoped access to share your farm’s financial standing for credit or lending.'\n )}\n />\n ) : (\n <div className=\"overflow-hidden rounded-lg border border-border-subtle bg-bg-surface\">\n <ResponsiveTable<FinancierGrant> columns={columns} data={activeGrants} rowKey={(g) => String(g.id)} />\n </div>\n )}\n\n <Modal\n open={showGrant}\n onClose={() => {\n setShowGrant(false);\n resetForm();\n }}\n title={t('healthybowl.financial.financierAccess.modal.title', 'Grant Financier Access')}\n description={t(\n 'healthybowl.financial.financierAccess.modal.description',\n 'Share a scoped, read-only financial summary of your farm. The financier never joins your workspace, and you can revoke this anytime.'\n )}\n footer={\n <>\n <Button\n variant=\"outline\"\n onClick={() => {\n setShowGrant(false);\n resetForm();\n }}\n className=\"text-text-secondary\"\n >\n {t('healthybowl.common.cancel', 'Cancel')}\n </Button>\n <Button onClick={handleGrant} disabled={submitting}>\n {submitting\n ? t('healthybowl.financial.financierAccess.actions.granting', 'Granting…')\n : t('healthybowl.financial.financierAccess.actions.grant', 'Grant Access')}\n </Button>\n </>\n }\n >\n <div className=\"grid gap-4\">\n <div>\n <label className=\"text-sm font-medium text-text-primary\">\n {t('healthybowl.financial.financierAccess.form.fields.actorId.label', 'Financier Actor ID *')}\n </label>\n <input\n type=\"text\"\n value={financierActorId}\n onChange={(e) => setFinancierActorId(e.target.value)}\n placeholder={t(\n 'healthybowl.financial.financierAccess.form.fields.actorId.placeholder',\n 'The financier’s platform user id'\n )}\n className=\"mt-1 w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 font-mono text-sm text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]\"\n />\n <p className=\"mt-1 text-xs text-text-secondary\">\n {t(\n 'healthybowl.financial.financierAccess.form.fields.actorId.helperText',\n 'Only this actor will be able to read your scoped financial summary.'\n )}\n </p>\n </div>\n <div>\n <label className=\"text-sm font-medium text-text-primary\">\n {t('healthybowl.financial.financierAccess.form.fields.name.label', 'Financier Name')}\n </label>\n <input\n type=\"text\"\n value={financierName}\n onChange={(e) => setFinancierName(e.target.value)}\n placeholder={t(\n 'healthybowl.financial.financierAccess.form.fields.name.placeholder',\n 'e.g., Rural Credit Cooperative'\n )}\n className=\"mt-1 w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]\"\n />\n </div>\n <div>\n <label className=\"text-sm font-medium text-text-primary\">\n {t('healthybowl.financial.financierAccess.form.fields.expires.label', 'Expires (optional)')}\n </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-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]\"\n />\n <p className=\"mt-1 text-xs text-text-secondary\">\n {t(\n 'healthybowl.financial.financierAccess.form.fields.expires.helperText',\n 'Leave blank for access that lasts until you revoke it.'\n )}\n </p>\n </div>\n </div>\n </Modal>\n\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoCA,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,gBAAY,GAAU,EACvC,EAAE,SAAM,GAAS,EACjB,KAAU,IAAY,EAEtB,EAAE,SAAM,YA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sBAAK,IAAI,MAAM,EAAC,aAAa,CAAC,MAAM,GAAG,GAAG;QAC1C,WAAW,MAAM,EAAa,EAAE,OAAO,MAAM;QAC7C,WAAU;QACV,CAAA;OACF,kBAAC,KAAD;QAAG,WAAU;kBACV,EACC,wEACA,yDACD;QACC,CAAA;OACA,EAAA,CAAA;MACF;;IACA,CAAA;GAER,kBAAC,GAAD;IAAwB;IAAQ,WAAW;IAAW,CAAA;GAC3C"}
|
|
1
|
+
{"version":3,"file":"FinancierAccessPage.js","names":[],"sources":["../../../../src/healthybowl/pages/financial/FinancierAccessPage.tsx"],"sourcesContent":["import { useState, useEffect, useMemo, useCallback, type FC } from 'react';\nimport { Plus, ShieldCheck, Trash2, AlertCircle } from 'lucide-react';\nimport { PageLayout, StatusBadge, EmptyState, Modal, Breadcrumbs, useConfirm } from '../../components';\nimport { ToastContainer } from '../../components/Toast';\nimport { Button, ResponsiveTable, type ResponsiveTableColumn } from '@burdenoff/fe-libs/ui';\nimport { useToast } from '../../hooks/useToast';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { useHealthyBowl } from '../../context/HealthyBowlContext';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport {\n useGetHealthyBowlFinancierGrantsQuery,\n useGrantHealthyBowlFinancierAccessMutation,\n useRevokeHealthyBowlFinancierAccessMutation,\n} from '../../../generated/wspace-operations';\nimport { financierGrantBadgeState, isCountedActive, type FinancierGrantBadgeState } from './financierAccessStatus';\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 const { t } = useI18n();\n const confirm = useConfirm();\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 // Excludes EXPIRED (past expiresAt, even though the server status is still\n // ACTIVE) so a lapsed grant doesn't inflate the \"active\" banner/count.\n const activeGrants = grants.filter((g) => isCountedActive(g.status, g.expiresAt));\n const expiringSoonGrants = grants.filter((g) => financierGrantBadgeState(g.status, g.expiresAt) === 'EXPIRING_SOON');\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({\n title: t('healthybowl.financial.financierAccess.toast.idRequired.title', 'Financier ID required'),\n description: t(\n 'healthybowl.financial.financierAccess.toast.idRequired.description',\n 'Enter the financier’s actor id.'\n ),\n variant: 'warning',\n });\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({\n title: t('healthybowl.financial.financierAccess.toast.granted.title', 'Access granted'),\n description: t(\n 'healthybowl.financial.financierAccess.toast.granted.description',\n 'The financier can now see your risk view.'\n ),\n variant: 'success',\n });\n setShowGrant(false);\n resetForm();\n await refetch();\n } catch {\n toast({\n title: t('healthybowl.financial.financierAccess.toast.grantFailed.title', 'Grant failed'),\n description: t(\n 'healthybowl.financial.financierAccess.toast.grantFailed.description',\n 'Could not grant access. Please try again.'\n ),\n variant: 'error',\n });\n } finally {\n setSubmitting(false);\n }\n };\n\n const handleRevoke = async (grant: FinancierGrant) => {\n if (\n !(await confirm({\n message: t(\n 'healthybowl.financial.financierAccess.confirm.revoke',\n 'Revoke {{name}}’s access to your farm’s financial view? They will immediately lose access.',\n {\n name:\n grant.financierName || t('healthybowl.financial.financierAccess.confirm.thisFinancier', 'this financier'),\n }\n ),\n }))\n ) {\n return;\n }\n setRevokingId(grant.id);\n try {\n await revokeAccess({ variables: { id: grant.id, context: { workspaceId } } });\n toast({\n title: t('healthybowl.financial.financierAccess.toast.revoked.title', 'Access revoked'),\n description: t(\n 'healthybowl.financial.financierAccess.toast.revoked.description',\n '{{name}} can no longer see your farm.',\n {\n name:\n grant.financierName ||\n t('healthybowl.financial.financierAccess.toast.revoked.financierFallback', 'Financier'),\n }\n ),\n variant: 'success',\n });\n setOptimisticGrants((prev) => prev.filter((g) => g.id !== grant.id));\n await refetch();\n } catch {\n toast({\n title: t('healthybowl.financial.financierAccess.toast.revokeFailed.title', 'Revoke failed'),\n description: t(\n 'healthybowl.financial.financierAccess.toast.revokeFailed.description',\n 'Could not revoke access. Please try again.'\n ),\n variant: 'error',\n });\n } finally {\n setRevokingId(null);\n }\n };\n\n const badgeForState = useCallback(\n (\n state: FinancierGrantBadgeState\n ): {\n label: string;\n variant: 'success' | 'warning' | 'muted';\n } => {\n switch (state) {\n case 'ACTIVE':\n return { label: t('healthybowl.financial.financierAccess.status.active', 'Active'), variant: 'success' };\n case 'EXPIRING_SOON':\n return {\n label: t('healthybowl.financial.financierAccess.status.expiringSoon', 'Expiring soon'),\n variant: 'warning',\n };\n case 'EXPIRED':\n return { label: t('healthybowl.financial.financierAccess.status.expired', 'Expired'), variant: 'muted' };\n case 'REVOKED':\n return { label: t('healthybowl.financial.financierAccess.status.revoked', 'Revoked'), variant: 'muted' };\n }\n },\n [t]\n );\n\n const columns: ResponsiveTableColumn<FinancierGrant>[] = useMemo(\n () => [\n {\n key: 'financier',\n header: t('healthybowl.financial.financierAccess.table.headers.financier', 'Financier'),\n priority: 'primary',\n cell: (g) => (\n <>\n <p className=\"font-medium text-text-primary\">\n {g.financierName ||\n t('healthybowl.financial.financierAccess.table.unnamedFinancier', 'Unnamed financier')}\n </p>\n <p className=\"font-mono text-xs text-text-secondary\" title={g.financierActorId}>\n {shortActor(g.financierActorId)}\n </p>\n </>\n ),\n },\n {\n key: 'scope',\n header: t('healthybowl.financial.financierAccess.table.headers.scope', 'Scope'),\n priority: 'secondary',\n cell: () => (\n <span className=\"inline-flex items-center gap-1 text-xs text-text-secondary\">\n <ShieldCheck className=\"h-3.5 w-3.5\" />{' '}\n {t('healthybowl.financial.financierAccess.table.scopeFinancialSummary', 'Financial summary')}\n </span>\n ),\n },\n {\n key: 'granted',\n header: t('healthybowl.financial.financierAccess.table.headers.granted', 'Granted'),\n priority: 'secondary',\n cellClassName: 'text-text-secondary',\n cell: (g) => formatDate(g.grantedAt),\n },\n {\n key: 'expires',\n header: t('healthybowl.financial.financierAccess.table.headers.expires', 'Expires'),\n priority: 'secondary',\n cellClassName: 'text-text-secondary',\n cell: (g) => formatDate(g.expiresAt),\n },\n {\n key: 'status',\n header: t('healthybowl.financial.financierAccess.table.headers.status', 'Status'),\n priority: 'secondary',\n cell: (g) => {\n const { label, variant } = badgeForState(financierGrantBadgeState(g.status, g.expiresAt));\n return <StatusBadge label={label} variant={variant} dot />;\n },\n },\n {\n key: 'action',\n header: t('healthybowl.financial.financierAccess.table.headers.action', 'Action'),\n priority: 'secondary',\n headerClassName: 'text-end',\n cellClassName: 'text-end',\n cell: (g) => (\n <Button variant=\"destructive\" size=\"sm\" onClick={() => handleRevoke(g)} disabled={revokingId === g.id}>\n <Trash2 className=\"h-3.5 w-3.5\" />{' '}\n {revokingId === g.id\n ? t('healthybowl.financial.financierAccess.actions.revoking', 'Revoking…')\n : t('healthybowl.financial.financierAccess.actions.revoke', 'Revoke')}\n </Button>\n ),\n },\n ],\n [t, revokingId, handleRevoke, badgeForState]\n );\n\n return (\n <PageLayout\n title={t('healthybowl.financial.financierAccess.title', 'Financier Access')}\n description={t(\n 'healthybowl.financial.financierAccess.description',\n 'Grant a bank, lender, or cooperative scoped read access to your farm’s financial risk view — and revoke it anytime'\n )}\n purpose=\"Let a bank, lender or cooperative see a read-only view of your farm's financial health — handy when applying for a loan or grant — and pull that access back the moment you no longer need it.\"\n actions={\n <Button onClick={() => setShowGrant(true)}>\n <Plus className=\"h-4 w-4\" /> {t('healthybowl.financial.financierAccess.actions.grant', 'Grant Access')}\n </Button>\n }\n >\n <Breadcrumbs\n items={[\n {\n label: t('healthybowl.financial.financierAccess.breadcrumbs.financial', 'Financial'),\n href: buildPath('financial'),\n },\n { label: t('healthybowl.financial.financierAccess.breadcrumbs.financierAccess', 'Financier Access') },\n ]}\n />\n\n {loading && grants.length === 0 ? (\n <p className=\"text-sm text-text-secondary\">\n {t('healthybowl.financial.financierAccess.loading', 'Loading grants…')}\n </p>\n ) : error && grants.length === 0 ? (\n <div className=\"flex items-center gap-2 rounded-lg border border-border-subtle bg-bg-surface p-5 text-sm text-text-secondary\">\n <AlertCircle className=\"h-4 w-4\" />{' '}\n {t('healthybowl.financial.financierAccess.error', 'Financier grants aren’t available right now.')}\n </div>\n ) : grants.length === 0 ? (\n <EmptyState\n illustration=\"empty-people\"\n title={t('healthybowl.financial.financierAccess.emptyState.title', 'No financier has access')}\n description={t(\n 'healthybowl.financial.financierAccess.emptyState.description',\n 'Grant a financier scoped access to share your farm’s financial standing for credit or lending.'\n )}\n />\n ) : (\n <>\n <p className=\"mb-2 text-sm text-text-secondary\">\n {t('healthybowl.financial.financierAccess.activeCount', '{{count}} active grant(s)', {\n count: activeGrants.length,\n })}\n </p>\n {expiringSoonGrants.length > 0 && (\n <div className=\"mb-4 flex items-center gap-2 rounded-lg border border-status-warning-border bg-status-warning-bg px-4 py-3 text-sm text-status-warning-text\">\n <AlertCircle className=\"h-4 w-4 shrink-0\" />\n <span>\n {t(\n 'healthybowl.financial.financierAccess.banner.expiringSoon',\n '{{count}} financier grant(s) are expiring within 30 days — review and revoke access you no longer need.',\n { count: expiringSoonGrants.length }\n )}\n </span>\n </div>\n )}\n <div className=\"overflow-hidden rounded-lg border border-border-subtle bg-bg-surface\">\n <ResponsiveTable<FinancierGrant> columns={columns} data={grants} rowKey={(g) => String(g.id)} />\n </div>\n </>\n )}\n\n <Modal\n open={showGrant}\n onClose={() => {\n setShowGrant(false);\n resetForm();\n }}\n title={t('healthybowl.financial.financierAccess.modal.title', 'Grant Financier Access')}\n description={t(\n 'healthybowl.financial.financierAccess.modal.description',\n 'Share a scoped, read-only financial summary of your farm. The financier never joins your workspace, and you can revoke this anytime.'\n )}\n footer={\n <>\n <Button\n variant=\"outline\"\n onClick={() => {\n setShowGrant(false);\n resetForm();\n }}\n className=\"text-text-secondary\"\n >\n {t('healthybowl.common.cancel', 'Cancel')}\n </Button>\n <Button onClick={handleGrant} disabled={submitting}>\n {submitting\n ? t('healthybowl.financial.financierAccess.actions.granting', 'Granting…')\n : t('healthybowl.financial.financierAccess.actions.grant', 'Grant Access')}\n </Button>\n </>\n }\n >\n <div className=\"grid gap-4\">\n <div>\n <label className=\"text-sm font-medium text-text-primary\">\n {t('healthybowl.financial.financierAccess.form.fields.actorId.label', 'Financier Actor ID *')}\n </label>\n <input\n type=\"text\"\n value={financierActorId}\n onChange={(e) => setFinancierActorId(e.target.value)}\n placeholder={t(\n 'healthybowl.financial.financierAccess.form.fields.actorId.placeholder',\n 'The financier’s platform user id'\n )}\n className=\"mt-1 w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 font-mono text-sm text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]\"\n />\n <p className=\"mt-1 text-xs text-text-secondary\">\n {t(\n 'healthybowl.financial.financierAccess.form.fields.actorId.helperText',\n 'Only this actor will be able to read your scoped financial summary.'\n )}\n </p>\n </div>\n <div>\n <label className=\"text-sm font-medium text-text-primary\">\n {t('healthybowl.financial.financierAccess.form.fields.name.label', 'Financier Name')}\n </label>\n <input\n type=\"text\"\n value={financierName}\n onChange={(e) => setFinancierName(e.target.value)}\n placeholder={t(\n 'healthybowl.financial.financierAccess.form.fields.name.placeholder',\n 'e.g., Rural Credit Cooperative'\n )}\n className=\"mt-1 w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]\"\n />\n </div>\n <div>\n <label className=\"text-sm font-medium text-text-primary\">\n {t('healthybowl.financial.financierAccess.form.fields.expires.label', 'Expires (optional)')}\n </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-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]\"\n />\n <p className=\"mt-1 text-xs text-text-secondary\">\n {t(\n 'healthybowl.financial.financierAccess.form.fields.expires.helperText',\n 'Leave blank for access that lasts until you revoke it.'\n )}\n </p>\n </div>\n </div>\n </Modal>\n\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;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;MACN,kBAAC,OAAD,EAAA,UAAA;OACE,kBAAC,SAAD;QAAO,WAAU;kBACd,EAAE,mEAAmE,qBAAqB;QACrF,CAAA;OACR,kBAAC,SAAD;QACE,MAAK;QACL,OAAO;QACP,sBAAK,IAAI,MAAM,EAAC,aAAa,CAAC,MAAM,GAAG,GAAG;QAC1C,WAAW,MAAM,EAAa,EAAE,OAAO,MAAM;QAC7C,WAAU;QACV,CAAA;OACF,kBAAC,KAAD;QAAG,WAAU;kBACV,EACC,wEACA,yDACD;QACC,CAAA;OACA,EAAA,CAAA;MACF;;IACA,CAAA;GAER,kBAAC,GAAD;IAAwB;IAAQ,WAAW;IAAW,CAAA;GAC3C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var e = 1440 * 60 * 1e3;
|
|
2
|
+
function t(t, n = /* @__PURE__ */ new Date()) {
|
|
3
|
+
if (!t) return "ACTIVE";
|
|
4
|
+
let r = new Date(t).getTime();
|
|
5
|
+
if (Number.isNaN(r)) return "ACTIVE";
|
|
6
|
+
let i = n.getTime();
|
|
7
|
+
return r <= i ? "EXPIRED" : (r - i) / e <= 30 ? "EXPIRING_SOON" : "ACTIVE";
|
|
8
|
+
}
|
|
9
|
+
function n(e, n, r = /* @__PURE__ */ new Date()) {
|
|
10
|
+
return e.toUpperCase() === "ACTIVE" ? t(n, r) : "REVOKED";
|
|
11
|
+
}
|
|
12
|
+
function r(e, n, r = /* @__PURE__ */ new Date()) {
|
|
13
|
+
return e.toUpperCase() === "ACTIVE" && t(n, r) !== "EXPIRED";
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { n as financierGrantBadgeState, r as isCountedActive };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=financierAccessStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"financierAccessStatus.js","names":[],"sources":["../../../../src/healthybowl/pages/financial/financierAccessStatus.ts"],"sourcesContent":["/**\n * BOFF-6191 — farmer-side expiry surface for `FinancierAccessGrant`.\n *\n * `FinancierGrantStatus` is a Postgres enum with only `ACTIVE` | `REVOKED` —\n * EXPIRING_SOON / EXPIRED are never persisted, only derived here from\n * `expiresAt` vs \"now\" so the status column stops rendering a grant whose\n * expiry date has already passed as green ACTIVE.\n */\n\nexport type FinancierGrantEffectiveState = 'ACTIVE' | 'EXPIRING_SOON' | 'EXPIRED';\n\n/** A grant expiring within this many days surfaces the review banner. */\nexport const EXPIRING_SOON_WINDOW_DAYS = 30;\n\nconst MS_PER_DAY = 24 * 60 * 60 * 1000;\n\n/**\n * Derives ACTIVE | EXPIRING_SOON | EXPIRED from `expiresAt` alone. Only\n * meaningful for a grant whose server `status` is ACTIVE — a REVOKED grant\n * gets its own badge via `financierGrantBadgeState` below, never this.\n */\nexport function effectiveGrantState(\n expiresAt: string | null | undefined,\n now: Date = new Date()\n): FinancierGrantEffectiveState {\n if (!expiresAt) return 'ACTIVE'; // no expiry set => lasts until revoked\n const expiryMs = new Date(expiresAt).getTime();\n if (Number.isNaN(expiryMs)) return 'ACTIVE'; // malformed date must never read as EXPIRED\n const nowMs = now.getTime();\n if (expiryMs <= nowMs) return 'EXPIRED';\n const daysUntilExpiry = (expiryMs - nowMs) / MS_PER_DAY;\n return daysUntilExpiry <= EXPIRING_SOON_WINDOW_DAYS ? 'EXPIRING_SOON' : 'ACTIVE';\n}\n\n/**\n * Full badge state including the server-side REVOKED case, for callers (the\n * status column) that render every row regardless of server `status`.\n */\nexport type FinancierGrantBadgeState = FinancierGrantEffectiveState | 'REVOKED';\n\nexport function financierGrantBadgeState(\n status: string,\n expiresAt: string | null | undefined,\n now: Date = new Date()\n): FinancierGrantBadgeState {\n if (status.toUpperCase() !== 'ACTIVE') return 'REVOKED';\n return effectiveGrantState(expiresAt, now);\n}\n\n/**\n * Grants counted for the banner/count purposes only — server ACTIVE and not\n * past its expiry. EXPIRING_SOON still counts (it hasn't lapsed yet); EXPIRED\n * does not, even though its server `status` is still ACTIVE.\n */\nexport function isCountedActive(status: string, expiresAt: string | null | undefined, now: Date = new Date()): boolean {\n return status.toUpperCase() === 'ACTIVE' && effectiveGrantState(expiresAt, now) !== 'EXPIRED';\n}\n"],"mappings":"AAcA,IAAM,IAAa,OAAU,KAAK;AAOlC,SAAgB,EACd,GACA,oBAAY,IAAI,MAAM,EACQ;AAC9B,KAAI,CAAC,EAAW,QAAO;CACvB,IAAM,IAAW,IAAI,KAAK,EAAU,CAAC,SAAS;AAC9C,KAAI,OAAO,MAAM,EAAS,CAAE,QAAO;CACnC,IAAM,IAAQ,EAAI,SAAS;AAG3B,QAFI,KAAY,IAAc,aACL,IAAW,KAAS,KAAA,KACS,kBAAkB;;AAS1E,SAAgB,EACd,GACA,GACA,oBAAY,IAAI,MAAM,EACI;AAE1B,QADI,EAAO,aAAa,KAAK,WACtB,EAAoB,GAAW,EAAI,GADI;;AAShD,SAAgB,EAAgB,GAAgB,GAAsC,oBAAY,IAAI,MAAM,EAAW;AACrH,QAAO,EAAO,aAAa,KAAK,YAAY,EAAoB,GAAW,EAAI,KAAK"}
|
package/package.json
CHANGED