@burdenoff/microfe-healthybowl 2026.719.2 → 2026.720.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/HealthyBowlRoutes.js +76 -68
- package/dist/healthybowl/HealthyBowlRoutes.js.map +1 -1
- package/dist/healthybowl/hooks/useHealthyBowlCompliance.js.map +1 -1
- package/dist/healthybowl/hooks/useHealthyBowlContracts.js +227 -0
- package/dist/healthybowl/hooks/useHealthyBowlContracts.js.map +1 -0
- package/dist/healthybowl/hooks/useHealthyBowlMandiPrices.js +176 -0
- package/dist/healthybowl/hooks/useHealthyBowlMandiPrices.js.map +1 -0
- package/dist/healthybowl/hooks/useHealthyBowlSustainability.js.map +1 -1
- package/dist/healthybowl/pages/contracts/ContractsPage.js +524 -0
- package/dist/healthybowl/pages/contracts/ContractsPage.js.map +1 -0
- package/dist/healthybowl/pages/contracts/contract-forms/CreateContractModal.js +151 -0
- package/dist/healthybowl/pages/contracts/contract-forms/CreateContractModal.js.map +1 -0
- package/dist/healthybowl/pages/contracts/contract-forms/DeliveryActionModal.js +130 -0
- package/dist/healthybowl/pages/contracts/contract-forms/DeliveryActionModal.js.map +1 -0
- package/dist/healthybowl/pages/contracts/contract-forms/InviteFarmModal.js +103 -0
- package/dist/healthybowl/pages/contracts/contract-forms/InviteFarmModal.js.map +1 -0
- package/dist/healthybowl/pages/contracts/contract-forms/RecordDeliveryModal.js +118 -0
- package/dist/healthybowl/pages/contracts/contract-forms/RecordDeliveryModal.js.map +1 -0
- package/dist/healthybowl/pages/market/MarketPricesPage.js +554 -0
- package/dist/healthybowl/pages/market/MarketPricesPage.js.map +1 -0
- package/dist/healthybowl/pages/market/market-prices/AddWatchModal.js +119 -0
- package/dist/healthybowl/pages/market/market-prices/AddWatchModal.js.map +1 -0
- package/dist/healthybowl/pages/market/market-prices/PriceAlertRuleModal.js +168 -0
- package/dist/healthybowl/pages/market/market-prices/PriceAlertRuleModal.js.map +1 -0
- package/dist/healthybowl/utils/contracts.js +76 -0
- package/dist/healthybowl/utils/contracts.js.map +1 -0
- package/dist/healthybowl/utils/mandiPrices.js +104 -0
- package/dist/healthybowl/utils/mandiPrices.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
|
|
2
|
+
import { useCallback as t, useMemo as n } from "react";
|
|
3
|
+
import { gql as r } from "@apollo/client";
|
|
4
|
+
import { useMutation as i, useQuery as a } from "@apollo/client/react";
|
|
5
|
+
//#region src/healthybowl/hooks/useHealthyBowlContracts.ts
|
|
6
|
+
var o = "00000000-0000-0000-0000-000000000001", s = [], c = "\n id\n crop\n variety\n quotaQty\n unit\n qualitySpec\n pricingModel\n agreedPrice\n deliverySchedule\n inputSupportTerms\n documentFileId\n status\n acceptedFarmCount\n createdAt\n", l = "\n id\n contractId\n crop\n farmWorkspaceId\n farmName\n allocationQty\n status\n invitedAt\n acceptedAt\n", u = "\n id\n contractId\n assignmentId\n farmWorkspaceId\n farmName\n deliveryWindow\n windowDate\n committedQty\n deliveredQty\n acceptedQty\n rejectedQty\n harvestRecordId\n orderId\n gradeResult\n valuedAmount\n status\n settledAt\n createdAt\n", d = "\n contractId\n crop\n status\n quotaQty\n deliveredQty\n acceptedQty\n fulfilmentPct\n agreedPrice\n unit\n contractedFarms\n rejectRatePct\n settlementDue\n health\n", f = "\n assignmentId\n contractId\n crop\n sponsorWorkspaceId\n quotaQty\n unit\n agreedPrice\n qualitySpec\n status\n deliveredQty\n acceptedQty\n paymentsReceived\n", p = r`
|
|
7
|
+
query GetHealthyBowlContractDashboard($context: ContextInput!) {
|
|
8
|
+
getHealthyBowlContractDashboard(context: $context) {
|
|
9
|
+
activeContracts
|
|
10
|
+
contractedFarms
|
|
11
|
+
avgFulfilmentPct
|
|
12
|
+
settlementDue
|
|
13
|
+
contracts { ${d} }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`, m = r`
|
|
17
|
+
query GetHealthyBowlFarmingContracts($context: ContextInput!) {
|
|
18
|
+
getHealthyBowlFarmingContracts(context: $context) { ${c} }
|
|
19
|
+
}
|
|
20
|
+
`, h = r`
|
|
21
|
+
query GetMyHealthyBowlContractInvitations {
|
|
22
|
+
getMyHealthyBowlContractInvitations { ${l} }
|
|
23
|
+
}
|
|
24
|
+
`, g = r`
|
|
25
|
+
query GetMyHealthyBowlContractObligations {
|
|
26
|
+
getMyHealthyBowlContractObligations { ${f} }
|
|
27
|
+
}
|
|
28
|
+
`, _ = r`
|
|
29
|
+
query GetHealthyBowlContractAssignments($contractId: ID!, $context: ContextInput!) {
|
|
30
|
+
getHealthyBowlContractAssignments(contractId: $contractId, context: $context) { ${l} }
|
|
31
|
+
}
|
|
32
|
+
`, v = r`
|
|
33
|
+
query GetHealthyBowlContractDeliveries($contractId: ID!, $context: ContextInput!) {
|
|
34
|
+
getHealthyBowlContractDeliveries(contractId: $contractId, context: $context) { ${u} }
|
|
35
|
+
}
|
|
36
|
+
`, y = r`
|
|
37
|
+
mutation CreateHealthyBowlFarmingContract($input: CreateHealthyBowlFarmingContractInput!) {
|
|
38
|
+
createHealthyBowlFarmingContract(input: $input) { ${c} }
|
|
39
|
+
}
|
|
40
|
+
`, b = r`
|
|
41
|
+
mutation ActivateHealthyBowlFarmingContract($id: ID!, $context: ContextInput!) {
|
|
42
|
+
activateHealthyBowlFarmingContract(id: $id, context: $context) { ${c} }
|
|
43
|
+
}
|
|
44
|
+
`, x = r`
|
|
45
|
+
mutation InviteHealthyBowlContractFarm($input: InviteHealthyBowlContractFarmInput!) {
|
|
46
|
+
inviteHealthyBowlContractFarm(input: $input) { ${l} }
|
|
47
|
+
}
|
|
48
|
+
`, S = r`
|
|
49
|
+
mutation AcceptHealthyBowlContractAssignment($id: ID!, $context: ContextInput!) {
|
|
50
|
+
acceptHealthyBowlContractAssignment(id: $id, context: $context) { ${l} }
|
|
51
|
+
}
|
|
52
|
+
`, C = r`
|
|
53
|
+
mutation RevokeHealthyBowlContractAssignment($id: ID!, $context: ContextInput!) {
|
|
54
|
+
revokeHealthyBowlContractAssignment(id: $id, context: $context)
|
|
55
|
+
}
|
|
56
|
+
`, w = r`
|
|
57
|
+
mutation RecordHealthyBowlContractDelivery($input: RecordHealthyBowlContractDeliveryInput!) {
|
|
58
|
+
recordHealthyBowlContractDelivery(input: $input) { ${u} }
|
|
59
|
+
}
|
|
60
|
+
`, T = r`
|
|
61
|
+
mutation AcceptHealthyBowlContractDelivery($input: AcceptHealthyBowlContractDeliveryInput!) {
|
|
62
|
+
acceptHealthyBowlContractDelivery(input: $input) { ${u} }
|
|
63
|
+
}
|
|
64
|
+
`, E = r`
|
|
65
|
+
mutation SettleHealthyBowlContractDelivery($input: SettleHealthyBowlContractDeliveryInput!) {
|
|
66
|
+
settleHealthyBowlContractDelivery(input: $input) { ${u} }
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
function D() {
|
|
70
|
+
let { workspaceId: r } = e(), c = r || o, l = n(() => ({ workspaceId: c }), [c]), u = a(p, {
|
|
71
|
+
variables: { context: l },
|
|
72
|
+
fetchPolicy: "cache-and-network"
|
|
73
|
+
}), d = a(m, {
|
|
74
|
+
variables: { context: l },
|
|
75
|
+
fetchPolicy: "cache-and-network"
|
|
76
|
+
}), f = a(h, { fetchPolicy: "cache-and-network" }), _ = a(g, { fetchPolicy: "cache-and-network" }), v = u.refetch, D = d.refetch, O = f.refetch, k = _.refetch, A = t(async (...e) => {
|
|
77
|
+
await Promise.all(e.map((e) => e().catch(() => void 0)));
|
|
78
|
+
}, []), [j] = i(y), [M] = i(b), [N] = i(x), [P] = i(S), [F] = i(C), [I] = i(w), [L] = i(T), [R] = i(E), z = t((e) => ({
|
|
79
|
+
...e,
|
|
80
|
+
context: l
|
|
81
|
+
}), [l]), B = t(() => A(v, D), [
|
|
82
|
+
A,
|
|
83
|
+
v,
|
|
84
|
+
D
|
|
85
|
+
]), V = t(() => A(O, k), [
|
|
86
|
+
A,
|
|
87
|
+
O,
|
|
88
|
+
k
|
|
89
|
+
]);
|
|
90
|
+
return {
|
|
91
|
+
dashboard: u.data?.getHealthyBowlContractDashboard ?? null,
|
|
92
|
+
contracts: d.data?.getHealthyBowlFarmingContracts ?? s,
|
|
93
|
+
invitations: f.data?.getMyHealthyBowlContractInvitations ?? [],
|
|
94
|
+
obligations: _.data?.getMyHealthyBowlContractObligations ?? [],
|
|
95
|
+
loading: d.loading || u.loading,
|
|
96
|
+
error: d.error ?? u.error ?? null,
|
|
97
|
+
invitationsLoading: f.loading,
|
|
98
|
+
obligationsLoading: _.loading,
|
|
99
|
+
refetchAll: t(() => A(v, D, O, k), [
|
|
100
|
+
A,
|
|
101
|
+
v,
|
|
102
|
+
D,
|
|
103
|
+
O,
|
|
104
|
+
k
|
|
105
|
+
]),
|
|
106
|
+
refetchSponsor: B,
|
|
107
|
+
refetchFarmer: V,
|
|
108
|
+
createContract: t(async (e) => {
|
|
109
|
+
let t = await j({ variables: { input: z(e) } });
|
|
110
|
+
if (t.error) throw t.error;
|
|
111
|
+
return await B(), t.data?.createHealthyBowlFarmingContract ?? null;
|
|
112
|
+
}, [
|
|
113
|
+
j,
|
|
114
|
+
z,
|
|
115
|
+
B
|
|
116
|
+
]),
|
|
117
|
+
activateContract: t(async (e) => {
|
|
118
|
+
let t = await M({ variables: {
|
|
119
|
+
id: e,
|
|
120
|
+
context: l
|
|
121
|
+
} });
|
|
122
|
+
if (t.error) throw t.error;
|
|
123
|
+
await B();
|
|
124
|
+
}, [
|
|
125
|
+
M,
|
|
126
|
+
l,
|
|
127
|
+
B
|
|
128
|
+
]),
|
|
129
|
+
inviteFarm: t(async (e) => {
|
|
130
|
+
let t = await N({ variables: { input: z(e) } });
|
|
131
|
+
if (t.error) throw t.error;
|
|
132
|
+
return await B(), t.data?.inviteHealthyBowlContractFarm ?? null;
|
|
133
|
+
}, [
|
|
134
|
+
N,
|
|
135
|
+
z,
|
|
136
|
+
B
|
|
137
|
+
]),
|
|
138
|
+
acceptAssignment: t(async (e) => {
|
|
139
|
+
let t = await P({ variables: {
|
|
140
|
+
id: e,
|
|
141
|
+
context: l
|
|
142
|
+
} });
|
|
143
|
+
if (t.error) throw t.error;
|
|
144
|
+
await V();
|
|
145
|
+
}, [
|
|
146
|
+
P,
|
|
147
|
+
l,
|
|
148
|
+
V
|
|
149
|
+
]),
|
|
150
|
+
revokeAssignment: t(async (e) => {
|
|
151
|
+
let t = await F({ variables: {
|
|
152
|
+
id: e,
|
|
153
|
+
context: l
|
|
154
|
+
} });
|
|
155
|
+
if (t.error) throw t.error;
|
|
156
|
+
await A(v, D, O, k);
|
|
157
|
+
}, [
|
|
158
|
+
F,
|
|
159
|
+
l,
|
|
160
|
+
A,
|
|
161
|
+
v,
|
|
162
|
+
D,
|
|
163
|
+
O,
|
|
164
|
+
k
|
|
165
|
+
]),
|
|
166
|
+
recordDelivery: t(async (e) => {
|
|
167
|
+
let t = await I({ variables: { input: z(e) } });
|
|
168
|
+
if (t.error) throw t.error;
|
|
169
|
+
return await B(), t.data?.recordHealthyBowlContractDelivery ?? null;
|
|
170
|
+
}, [
|
|
171
|
+
I,
|
|
172
|
+
z,
|
|
173
|
+
B
|
|
174
|
+
]),
|
|
175
|
+
gradeDelivery: t(async (e) => {
|
|
176
|
+
let t = await L({ variables: { input: z(e) } });
|
|
177
|
+
if (t.error) throw t.error;
|
|
178
|
+
return await B(), t.data?.acceptHealthyBowlContractDelivery ?? null;
|
|
179
|
+
}, [
|
|
180
|
+
L,
|
|
181
|
+
z,
|
|
182
|
+
B
|
|
183
|
+
]),
|
|
184
|
+
settleDelivery: t(async (e) => {
|
|
185
|
+
let t = await R({ variables: { input: z(e) } });
|
|
186
|
+
if (t.error) throw t.error;
|
|
187
|
+
return await A(v, D, k), t.data?.settleHealthyBowlContractDelivery ?? null;
|
|
188
|
+
}, [
|
|
189
|
+
R,
|
|
190
|
+
z,
|
|
191
|
+
A,
|
|
192
|
+
v,
|
|
193
|
+
D,
|
|
194
|
+
k
|
|
195
|
+
]),
|
|
196
|
+
context: l
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function O(r) {
|
|
200
|
+
let { workspaceId: i } = e(), s = i || o, c = n(() => ({ workspaceId: s }), [s]), l = !r, u = a(_, {
|
|
201
|
+
variables: {
|
|
202
|
+
contractId: r ?? "",
|
|
203
|
+
context: c
|
|
204
|
+
},
|
|
205
|
+
skip: l,
|
|
206
|
+
fetchPolicy: "cache-and-network"
|
|
207
|
+
}), d = a(v, {
|
|
208
|
+
variables: {
|
|
209
|
+
contractId: r ?? "",
|
|
210
|
+
context: c
|
|
211
|
+
},
|
|
212
|
+
skip: l,
|
|
213
|
+
fetchPolicy: "cache-and-network"
|
|
214
|
+
}), f = u.refetch, p = d.refetch, m = t(async () => {
|
|
215
|
+
await Promise.all([f().catch(() => void 0), p().catch(() => void 0)]);
|
|
216
|
+
}, [f, p]);
|
|
217
|
+
return {
|
|
218
|
+
assignments: u.data?.getHealthyBowlContractAssignments ?? [],
|
|
219
|
+
deliveries: d.data?.getHealthyBowlContractDeliveries ?? [],
|
|
220
|
+
loading: u.loading || d.loading,
|
|
221
|
+
refetch: m
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
export { O as useHealthyBowlContractDetail, D as useHealthyBowlContracts };
|
|
226
|
+
|
|
227
|
+
//# sourceMappingURL=useHealthyBowlContracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHealthyBowlContracts.js","names":[],"sources":["../../../src/healthybowl/hooks/useHealthyBowlContracts.ts"],"sourcesContent":["/**\n * Contract & Managed Farming (#29 · BOFF-4718) — data hook.\n *\n * Documents are declared inline with `gql` (not `src/operations/wspace/*.graphql`) because\n * codegen validates operations against the committed `graphql/wspace.graphql` snapshot, which\n * doesn't carry the contract subgraph yet (schema:pull needs a live gateway) — the same escape\n * hatch the mandi / sensor hooks use. Types mirror the deployed `wspace-healthybowl-svc`\n * contract schema (see ../utils/contracts.ts).\n *\n * Sponsor reads (dashboard, contracts) + farmer reads (my invitations/obligations) share one\n * hook; the two context-scoped queries pass `context: ContextInput!`, the two self-scoped\n * \"my …\" queries rely on the shell's workspace-token transport scoping. Reads are\n * cache-and-network; every write refetches the lists it invalidates.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport { gql } from '@apollo/client';\nimport { useMutation, useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\nimport type {\n ContractAssignment,\n ContractDashboard,\n ContractDelivery,\n ContractObligation,\n FarmingContract,\n} from '../utils/contracts';\n\nconst FALLBACK_WORKSPACE_ID = '00000000-0000-0000-0000-000000000001';\nconst EMPTY_CONTRACTS: FarmingContract[] = [];\n\ninterface HbContext {\n workspaceId: string;\n}\n\n// ── field fragments ──\nconst CONTRACT_FIELDS = `\n id\n crop\n variety\n quotaQty\n unit\n qualitySpec\n pricingModel\n agreedPrice\n deliverySchedule\n inputSupportTerms\n documentFileId\n status\n acceptedFarmCount\n createdAt\n`;\n\nconst ASSIGNMENT_FIELDS = `\n id\n contractId\n crop\n farmWorkspaceId\n farmName\n allocationQty\n status\n invitedAt\n acceptedAt\n`;\n\nconst DELIVERY_FIELDS = `\n id\n contractId\n assignmentId\n farmWorkspaceId\n farmName\n deliveryWindow\n windowDate\n committedQty\n deliveredQty\n acceptedQty\n rejectedQty\n harvestRecordId\n orderId\n gradeResult\n valuedAmount\n status\n settledAt\n createdAt\n`;\n\nconst CARD_FIELDS = `\n contractId\n crop\n status\n quotaQty\n deliveredQty\n acceptedQty\n fulfilmentPct\n agreedPrice\n unit\n contractedFarms\n rejectRatePct\n settlementDue\n health\n`;\n\nconst OBLIGATION_FIELDS = `\n assignmentId\n contractId\n crop\n sponsorWorkspaceId\n quotaQty\n unit\n agreedPrice\n qualitySpec\n status\n deliveredQty\n acceptedQty\n paymentsReceived\n`;\n\n// ── queries ──\nconst GET_DASHBOARD = gql`\n query GetHealthyBowlContractDashboard($context: ContextInput!) {\n getHealthyBowlContractDashboard(context: $context) {\n activeContracts\n contractedFarms\n avgFulfilmentPct\n settlementDue\n contracts { ${CARD_FIELDS} }\n }\n }\n`;\nconst GET_CONTRACTS = gql`\n query GetHealthyBowlFarmingContracts($context: ContextInput!) {\n getHealthyBowlFarmingContracts(context: $context) { ${CONTRACT_FIELDS} }\n }\n`;\nconst GET_INVITATIONS = gql`\n query GetMyHealthyBowlContractInvitations {\n getMyHealthyBowlContractInvitations { ${ASSIGNMENT_FIELDS} }\n }\n`;\nconst GET_OBLIGATIONS = gql`\n query GetMyHealthyBowlContractObligations {\n getMyHealthyBowlContractObligations { ${OBLIGATION_FIELDS} }\n }\n`;\nconst GET_ASSIGNMENTS = gql`\n query GetHealthyBowlContractAssignments($contractId: ID!, $context: ContextInput!) {\n getHealthyBowlContractAssignments(contractId: $contractId, context: $context) { ${ASSIGNMENT_FIELDS} }\n }\n`;\nconst GET_DELIVERIES = gql`\n query GetHealthyBowlContractDeliveries($contractId: ID!, $context: ContextInput!) {\n getHealthyBowlContractDeliveries(contractId: $contractId, context: $context) { ${DELIVERY_FIELDS} }\n }\n`;\n\n// ── mutations ──\nconst CREATE_CONTRACT = gql`\n mutation CreateHealthyBowlFarmingContract($input: CreateHealthyBowlFarmingContractInput!) {\n createHealthyBowlFarmingContract(input: $input) { ${CONTRACT_FIELDS} }\n }\n`;\nconst ACTIVATE_CONTRACT = gql`\n mutation ActivateHealthyBowlFarmingContract($id: ID!, $context: ContextInput!) {\n activateHealthyBowlFarmingContract(id: $id, context: $context) { ${CONTRACT_FIELDS} }\n }\n`;\nconst INVITE_FARM = gql`\n mutation InviteHealthyBowlContractFarm($input: InviteHealthyBowlContractFarmInput!) {\n inviteHealthyBowlContractFarm(input: $input) { ${ASSIGNMENT_FIELDS} }\n }\n`;\nconst ACCEPT_ASSIGNMENT = gql`\n mutation AcceptHealthyBowlContractAssignment($id: ID!, $context: ContextInput!) {\n acceptHealthyBowlContractAssignment(id: $id, context: $context) { ${ASSIGNMENT_FIELDS} }\n }\n`;\nconst REVOKE_ASSIGNMENT = gql`\n mutation RevokeHealthyBowlContractAssignment($id: ID!, $context: ContextInput!) {\n revokeHealthyBowlContractAssignment(id: $id, context: $context)\n }\n`;\nconst RECORD_DELIVERY = gql`\n mutation RecordHealthyBowlContractDelivery($input: RecordHealthyBowlContractDeliveryInput!) {\n recordHealthyBowlContractDelivery(input: $input) { ${DELIVERY_FIELDS} }\n }\n`;\nconst GRADE_DELIVERY = gql`\n mutation AcceptHealthyBowlContractDelivery($input: AcceptHealthyBowlContractDeliveryInput!) {\n acceptHealthyBowlContractDelivery(input: $input) { ${DELIVERY_FIELDS} }\n }\n`;\nconst SETTLE_DELIVERY = gql`\n mutation SettleHealthyBowlContractDelivery($input: SettleHealthyBowlContractDeliveryInput!) {\n settleHealthyBowlContractDelivery(input: $input) { ${DELIVERY_FIELDS} }\n }\n`;\n\nexport function useHealthyBowlContracts() {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || FALLBACK_WORKSPACE_ID;\n const ctx = useMemo<HbContext>(() => ({ workspaceId: effectiveWorkspaceId }), [effectiveWorkspaceId]);\n\n const dashboardQuery = useQuery<{ getHealthyBowlContractDashboard: ContractDashboard }, { context: HbContext }>(\n GET_DASHBOARD,\n { variables: { context: ctx }, fetchPolicy: 'cache-and-network' }\n );\n const contractsQuery = useQuery<{ getHealthyBowlFarmingContracts: FarmingContract[] }, { context: HbContext }>(\n GET_CONTRACTS,\n { variables: { context: ctx }, fetchPolicy: 'cache-and-network' }\n );\n const invitationsQuery = useQuery<{ getMyHealthyBowlContractInvitations: ContractAssignment[] }>(GET_INVITATIONS, {\n fetchPolicy: 'cache-and-network',\n });\n const obligationsQuery = useQuery<{ getMyHealthyBowlContractObligations: ContractObligation[] }>(GET_OBLIGATIONS, {\n fetchPolicy: 'cache-and-network',\n });\n\n const refetchDashboard = dashboardQuery.refetch;\n const refetchContracts = contractsQuery.refetch;\n const refetchInvitations = invitationsQuery.refetch;\n const refetchObligations = obligationsQuery.refetch;\n\n const reconcile = useCallback(async (...refetchers: Array<() => Promise<unknown>>) => {\n await Promise.all(refetchers.map((run) => run().catch(() => undefined)));\n }, []);\n\n const [createContractMutation] = useMutation<\n { createHealthyBowlFarmingContract: FarmingContract },\n { input: Record<string, unknown> }\n >(CREATE_CONTRACT);\n const [activateContractMutation] = useMutation(ACTIVATE_CONTRACT);\n const [inviteFarmMutation] = useMutation<\n { inviteHealthyBowlContractFarm: ContractAssignment },\n { input: Record<string, unknown> }\n >(INVITE_FARM);\n const [acceptAssignmentMutation] = useMutation(ACCEPT_ASSIGNMENT);\n const [revokeAssignmentMutation] = useMutation(REVOKE_ASSIGNMENT);\n const [recordDeliveryMutation] = useMutation<\n { recordHealthyBowlContractDelivery: ContractDelivery },\n { input: Record<string, unknown> }\n >(RECORD_DELIVERY);\n const [gradeDeliveryMutation] = useMutation<\n { acceptHealthyBowlContractDelivery: ContractDelivery },\n { input: Record<string, unknown> }\n >(GRADE_DELIVERY);\n const [settleDeliveryMutation] = useMutation<\n { settleHealthyBowlContractDelivery: ContractDelivery },\n { input: Record<string, unknown> }\n >(SETTLE_DELIVERY);\n\n const withCtx = useCallback((input: Record<string, unknown>) => ({ ...input, context: ctx }), [ctx]);\n\n const refetchSponsor = useCallback(\n () => reconcile(refetchDashboard, refetchContracts),\n [reconcile, refetchDashboard, refetchContracts]\n );\n const refetchFarmer = useCallback(\n () => reconcile(refetchInvitations, refetchObligations),\n [reconcile, refetchInvitations, refetchObligations]\n );\n\n return {\n dashboard: dashboardQuery.data?.getHealthyBowlContractDashboard ?? null,\n contracts: contractsQuery.data?.getHealthyBowlFarmingContracts ?? EMPTY_CONTRACTS,\n invitations: invitationsQuery.data?.getMyHealthyBowlContractInvitations ?? [],\n obligations: obligationsQuery.data?.getMyHealthyBowlContractObligations ?? [],\n\n loading: contractsQuery.loading || dashboardQuery.loading,\n error: contractsQuery.error ?? dashboardQuery.error ?? null,\n invitationsLoading: invitationsQuery.loading,\n obligationsLoading: obligationsQuery.loading,\n\n refetchAll: useCallback(\n () => reconcile(refetchDashboard, refetchContracts, refetchInvitations, refetchObligations),\n [reconcile, refetchDashboard, refetchContracts, refetchInvitations, refetchObligations]\n ),\n refetchSponsor,\n refetchFarmer,\n\n createContract: useCallback(\n async (input: Record<string, unknown>): Promise<FarmingContract | null> => {\n const res = await createContractMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await refetchSponsor();\n return res.data?.createHealthyBowlFarmingContract ?? null;\n },\n [createContractMutation, withCtx, refetchSponsor]\n ),\n activateContract: useCallback(\n async (id: string) => {\n const res = await activateContractMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await refetchSponsor();\n },\n [activateContractMutation, ctx, refetchSponsor]\n ),\n inviteFarm: useCallback(\n async (input: Record<string, unknown>): Promise<ContractAssignment | null> => {\n const res = await inviteFarmMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await refetchSponsor();\n return res.data?.inviteHealthyBowlContractFarm ?? null;\n },\n [inviteFarmMutation, withCtx, refetchSponsor]\n ),\n acceptAssignment: useCallback(\n async (id: string) => {\n const res = await acceptAssignmentMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await refetchFarmer();\n },\n [acceptAssignmentMutation, ctx, refetchFarmer]\n ),\n revokeAssignment: useCallback(\n async (id: string) => {\n const res = await revokeAssignmentMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await reconcile(refetchDashboard, refetchContracts, refetchInvitations, refetchObligations);\n },\n [\n revokeAssignmentMutation,\n ctx,\n reconcile,\n refetchDashboard,\n refetchContracts,\n refetchInvitations,\n refetchObligations,\n ]\n ),\n recordDelivery: useCallback(\n async (input: Record<string, unknown>): Promise<ContractDelivery | null> => {\n const res = await recordDeliveryMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await refetchSponsor();\n return res.data?.recordHealthyBowlContractDelivery ?? null;\n },\n [recordDeliveryMutation, withCtx, refetchSponsor]\n ),\n gradeDelivery: useCallback(\n async (input: Record<string, unknown>): Promise<ContractDelivery | null> => {\n const res = await gradeDeliveryMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await refetchSponsor();\n return res.data?.acceptHealthyBowlContractDelivery ?? null;\n },\n [gradeDeliveryMutation, withCtx, refetchSponsor]\n ),\n settleDelivery: useCallback(\n async (input: Record<string, unknown>): Promise<ContractDelivery | null> => {\n const res = await settleDeliveryMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchDashboard, refetchContracts, refetchObligations);\n return res.data?.settleHealthyBowlContractDelivery ?? null;\n },\n [settleDeliveryMutation, withCtx, reconcile, refetchDashboard, refetchContracts, refetchObligations]\n ),\n\n context: ctx,\n };\n}\n\n/** Lazy per-contract detail: assignments + deliveries for the selected contract (drawer). */\nexport function useHealthyBowlContractDetail(contractId: string | null) {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || FALLBACK_WORKSPACE_ID;\n const ctx = useMemo<HbContext>(() => ({ workspaceId: effectiveWorkspaceId }), [effectiveWorkspaceId]);\n const skip = !contractId;\n\n const assignmentsQuery = useQuery<\n { getHealthyBowlContractAssignments: ContractAssignment[] },\n { contractId: string; context: HbContext }\n >(GET_ASSIGNMENTS, {\n variables: { contractId: contractId ?? '', context: ctx },\n skip,\n fetchPolicy: 'cache-and-network',\n });\n const deliveriesQuery = useQuery<\n { getHealthyBowlContractDeliveries: ContractDelivery[] },\n { contractId: string; context: HbContext }\n >(GET_DELIVERIES, {\n variables: { contractId: contractId ?? '', context: ctx },\n skip,\n fetchPolicy: 'cache-and-network',\n });\n\n const refetchAssignments = assignmentsQuery.refetch;\n const refetchDeliveries = deliveriesQuery.refetch;\n const refetch = useCallback(async () => {\n await Promise.all([refetchAssignments().catch(() => undefined), refetchDeliveries().catch(() => undefined)]);\n }, [refetchAssignments, refetchDeliveries]);\n\n return {\n assignments: assignmentsQuery.data?.getHealthyBowlContractAssignments ?? [],\n deliveries: deliveriesQuery.data?.getHealthyBowlContractDeliveries ?? [],\n loading: assignmentsQuery.loading || deliveriesQuery.loading,\n refetch,\n };\n}\n\nexport type {\n ContractAssignment,\n ContractDashboard,\n ContractDelivery,\n ContractObligation,\n FarmingContract,\n} from '../utils/contracts';\n"],"mappings":";;;;;AA2BA,IAAM,IAAwB,wCACxB,IAAqC,EAAE,EAOvC,IAAkB,wMAiBlB,IAAoB,uHAYpB,IAAkB,wQAqBlB,IAAc,wLAgBd,IAAoB,iLAgBpB,IAAgB,CAAG;;;;;;;oBAOL,EAAY;;;GAI1B,IAAgB,CAAG;;0DAEiC,EAAgB;;GAGpE,IAAkB,CAAG;;4CAEiB,EAAkB;;GAGxD,IAAkB,CAAG;;4CAEiB,EAAkB;;GAGxD,IAAkB,CAAG;;sFAE2D,EAAkB;;GAGlG,IAAiB,CAAG;;qFAE2D,EAAgB;;GAK/F,IAAkB,CAAG;;wDAE6B,EAAgB;;GAGlE,IAAoB,CAAG;;uEAE0C,EAAgB;;GAGjF,IAAc,CAAG;;qDAE8B,EAAkB;;GAGjE,IAAoB,CAAG;;wEAE2C,EAAkB;;GAGpF,IAAoB,CAAG;;;;GAKvB,IAAkB,CAAG;;yDAE8B,EAAgB;;GAGnE,IAAiB,CAAG;;yDAE+B,EAAgB;;GAGnE,IAAkB,CAAG;;yDAE8B,EAAgB;;;AAIzE,SAAgB,IAA0B;CACxC,IAAM,EAAE,mBAAgB,GAAgB,EAClC,IAAuB,KAAe,GACtC,IAAM,SAA0B,EAAE,aAAa,GAAsB,GAAG,CAAC,EAAqB,CAAC,EAE/F,IAAiB,EACrB,GACA;EAAE,WAAW,EAAE,SAAS,GAAK;EAAE,aAAa;EAAqB,CAClE,EACK,IAAiB,EACrB,GACA;EAAE,WAAW,EAAE,SAAS,GAAK;EAAE,aAAa;EAAqB,CAClE,EACK,IAAmB,EAAwE,GAAiB,EAChH,aAAa,qBACd,CAAC,EACI,IAAm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AqC,EAAE;EAC3E,YAAY,EAAgB,MAAM,oCAAoC,EAAE;EACxE,SAAS,EAAiB,WAAW,EAAgB;EACrD;EACD"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
|
|
2
|
+
import { groupPricesByCommodity as t } from "../utils/mandiPrices.js";
|
|
3
|
+
import { useCallback as n, useMemo as r } from "react";
|
|
4
|
+
import { gql as i } from "@apollo/client";
|
|
5
|
+
import { useMutation as a, useQuery as o } from "@apollo/client/react";
|
|
6
|
+
//#region src/healthybowl/hooks/useHealthyBowlMandiPrices.ts
|
|
7
|
+
var s = "00000000-0000-0000-0000-000000000001", c = [], l = "\n commodity\n variety\n marketName\n district\n state\n minPrice\n modalPrice\n maxPrice\n arrivalQty\n unit\n priceDate\n source\n", u = "\n date\n label\n minPrice\n modalPrice\n maxPrice\n", d = "\n id\n commodity\n marketName\n district\n state\n", f = "\n id\n commodity\n marketName\n comparator\n threshold\n enabled\n", p = "\n id\n commodity\n marketName\n comparator\n severity\n title\n message\n value\n threshold\n status\n read\n timestamp\n actionUrl\n", m = i`
|
|
8
|
+
query GetHealthyBowlMandiPrices($context: ContextInput!, $filter: HealthyBowlMandiPriceFilterInput) {
|
|
9
|
+
getHealthyBowlMandiPrices(context: $context, filter: $filter) { ${l} }
|
|
10
|
+
}
|
|
11
|
+
`, h = i`
|
|
12
|
+
query GetHealthyBowlMandiPriceTrend(
|
|
13
|
+
$context: ContextInput!
|
|
14
|
+
$commodity: String!
|
|
15
|
+
$marketName: String
|
|
16
|
+
$days: Int
|
|
17
|
+
) {
|
|
18
|
+
getHealthyBowlMandiPriceTrend(context: $context, commodity: $commodity, marketName: $marketName, days: $days) {
|
|
19
|
+
${u}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
`, g = i`
|
|
23
|
+
query GetHealthyBowlPriceWatches($context: ContextInput!) {
|
|
24
|
+
getHealthyBowlPriceWatches(context: $context) { ${d} }
|
|
25
|
+
}
|
|
26
|
+
`, _ = i`
|
|
27
|
+
query GetHealthyBowlPriceAlertRules($context: ContextInput!) {
|
|
28
|
+
getHealthyBowlPriceAlertRules(context: $context) { ${f} }
|
|
29
|
+
}
|
|
30
|
+
`, v = i`
|
|
31
|
+
query GetHealthyBowlPriceAlerts($context: ContextInput!) {
|
|
32
|
+
getHealthyBowlPriceAlerts(context: $context) { ${p} }
|
|
33
|
+
}
|
|
34
|
+
`, y = i`
|
|
35
|
+
mutation CreateHealthyBowlPriceWatch($input: CreateHealthyBowlPriceWatchInput!) {
|
|
36
|
+
createHealthyBowlPriceWatch(input: $input) { ${d} }
|
|
37
|
+
}
|
|
38
|
+
`, b = i`
|
|
39
|
+
mutation DeleteHealthyBowlPriceWatch($id: ID!, $context: ContextInput!) {
|
|
40
|
+
deleteHealthyBowlPriceWatch(context: $context, id: $id)
|
|
41
|
+
}
|
|
42
|
+
`, x = i`
|
|
43
|
+
mutation CreateHealthyBowlPriceAlertRule($input: CreateHealthyBowlPriceAlertRuleInput!) {
|
|
44
|
+
createHealthyBowlPriceAlertRule(input: $input) { ${f} }
|
|
45
|
+
}
|
|
46
|
+
`, S = i`
|
|
47
|
+
mutation UpdateHealthyBowlPriceAlertRule($input: UpdateHealthyBowlPriceAlertRuleInput!) {
|
|
48
|
+
updateHealthyBowlPriceAlertRule(input: $input) { ${f} }
|
|
49
|
+
}
|
|
50
|
+
`, C = i`
|
|
51
|
+
mutation DeleteHealthyBowlPriceAlertRule($id: ID!, $context: ContextInput!) {
|
|
52
|
+
deleteHealthyBowlPriceAlertRule(context: $context, id: $id)
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
function w(i = {}) {
|
|
56
|
+
let { workspaceId: l } = e(), u = l || s, d = r(() => ({ workspaceId: u }), [u]), f = i.filter, p = o(m, {
|
|
57
|
+
variables: {
|
|
58
|
+
context: d,
|
|
59
|
+
filter: f
|
|
60
|
+
},
|
|
61
|
+
fetchPolicy: "cache-and-network"
|
|
62
|
+
}), h = o(g, {
|
|
63
|
+
variables: { context: d },
|
|
64
|
+
fetchPolicy: "cache-and-network"
|
|
65
|
+
}), w = o(_, {
|
|
66
|
+
variables: { context: d },
|
|
67
|
+
fetchPolicy: "cache-and-network"
|
|
68
|
+
}), T = o(v, {
|
|
69
|
+
variables: { context: d },
|
|
70
|
+
fetchPolicy: "cache-and-network"
|
|
71
|
+
}), E = p.refetch, D = h.refetch, O = w.refetch, k = T.refetch, A = n(async (...e) => {
|
|
72
|
+
await Promise.all(e.map((e) => e().catch(() => void 0)));
|
|
73
|
+
}, []), [j] = a(y), [M] = a(b), [N] = a(x), [P] = a(S), [F] = a(C), I = n((e) => ({
|
|
74
|
+
...e,
|
|
75
|
+
context: d
|
|
76
|
+
}), [d]), L = r(() => p.data?.getHealthyBowlMandiPrices ?? c, [p.data]);
|
|
77
|
+
return {
|
|
78
|
+
prices: L,
|
|
79
|
+
commodities: r(() => t(L), [L]),
|
|
80
|
+
watches: h.data?.getHealthyBowlPriceWatches ?? [],
|
|
81
|
+
alertRules: w.data?.getHealthyBowlPriceAlertRules ?? [],
|
|
82
|
+
alerts: T.data?.getHealthyBowlPriceAlerts ?? [],
|
|
83
|
+
loading: p.loading,
|
|
84
|
+
error: p.error ?? null,
|
|
85
|
+
watchesLoading: h.loading,
|
|
86
|
+
rulesLoading: w.loading,
|
|
87
|
+
alertsLoading: T.loading,
|
|
88
|
+
refetchAll: n(() => A(E, D, O, k), [
|
|
89
|
+
A,
|
|
90
|
+
E,
|
|
91
|
+
D,
|
|
92
|
+
O,
|
|
93
|
+
k
|
|
94
|
+
]),
|
|
95
|
+
createWatch: n(async (e) => {
|
|
96
|
+
let t = await j({ variables: { input: I(e) } });
|
|
97
|
+
if (t.error) throw t.error;
|
|
98
|
+
return await A(D), t.data?.createHealthyBowlPriceWatch ?? null;
|
|
99
|
+
}, [
|
|
100
|
+
j,
|
|
101
|
+
I,
|
|
102
|
+
A,
|
|
103
|
+
D
|
|
104
|
+
]),
|
|
105
|
+
deleteWatch: n(async (e) => {
|
|
106
|
+
let t = await M({ variables: {
|
|
107
|
+
id: e,
|
|
108
|
+
context: d
|
|
109
|
+
} });
|
|
110
|
+
if (t.error) throw t.error;
|
|
111
|
+
await A(D);
|
|
112
|
+
}, [
|
|
113
|
+
M,
|
|
114
|
+
d,
|
|
115
|
+
A,
|
|
116
|
+
D
|
|
117
|
+
]),
|
|
118
|
+
createRule: n(async (e) => {
|
|
119
|
+
let t = await N({ variables: { input: I(e) } });
|
|
120
|
+
if (t.error) throw t.error;
|
|
121
|
+
return await A(O, k), t.data?.createHealthyBowlPriceAlertRule ?? null;
|
|
122
|
+
}, [
|
|
123
|
+
N,
|
|
124
|
+
I,
|
|
125
|
+
A,
|
|
126
|
+
O,
|
|
127
|
+
k
|
|
128
|
+
]),
|
|
129
|
+
updateRule: n(async (e) => {
|
|
130
|
+
let t = await P({ variables: { input: I(e) } });
|
|
131
|
+
if (t.error) throw t.error;
|
|
132
|
+
return await A(O, k), t.data?.updateHealthyBowlPriceAlertRule ?? null;
|
|
133
|
+
}, [
|
|
134
|
+
P,
|
|
135
|
+
I,
|
|
136
|
+
A,
|
|
137
|
+
O,
|
|
138
|
+
k
|
|
139
|
+
]),
|
|
140
|
+
deleteRule: n(async (e) => {
|
|
141
|
+
let t = await F({ variables: {
|
|
142
|
+
id: e,
|
|
143
|
+
context: d
|
|
144
|
+
} });
|
|
145
|
+
if (t.error) throw t.error;
|
|
146
|
+
await A(O);
|
|
147
|
+
}, [
|
|
148
|
+
F,
|
|
149
|
+
d,
|
|
150
|
+
A,
|
|
151
|
+
O
|
|
152
|
+
]),
|
|
153
|
+
context: d
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function T(t = {}) {
|
|
157
|
+
let { workspaceId: n } = e(), i = n || s, a = r(() => ({ workspaceId: i }), [i]), c = t.days ?? 30, l = o(h, {
|
|
158
|
+
variables: {
|
|
159
|
+
context: a,
|
|
160
|
+
commodity: t.commodity ?? "",
|
|
161
|
+
marketName: t.marketName ?? null,
|
|
162
|
+
days: c
|
|
163
|
+
},
|
|
164
|
+
skip: t.skip || !t.commodity,
|
|
165
|
+
fetchPolicy: "cache-and-network"
|
|
166
|
+
});
|
|
167
|
+
return {
|
|
168
|
+
points: l.data?.getHealthyBowlMandiPriceTrend ?? [],
|
|
169
|
+
loading: l.loading,
|
|
170
|
+
error: l.error ?? null
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
export { T as useHealthyBowlMandiPriceTrend, w as useHealthyBowlMandiPrices };
|
|
175
|
+
|
|
176
|
+
//# sourceMappingURL=useHealthyBowlMandiPrices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHealthyBowlMandiPrices.js","names":[],"sources":["../../../src/healthybowl/hooks/useHealthyBowlMandiPrices.ts"],"sourcesContent":["/**\n * Mandi / Market-Price Intelligence — data hook (roadmap #28 · BOFF-4715).\n *\n * Documents are declared inline with `gql` (not `src/operations/wspace/*.graphql`)\n * because codegen validates operations against the committed `graphql/wspace.graphql`\n * snapshot, which doesn't yet carry the mandi subgraph (schema:pull needs a live\n * gateway) — the same escape hatch `useHealthyBowlSensors` / `useDiseaseWarning`\n * use. Types mirror the deployed `wspace-healthybowl-svc` mandi schema.\n *\n * Reads use `cache-and-network`; every write refetches the lists it invalidates.\n * The commodity roll-up is delegated to the pure `groupPricesByCommodity` helper\n * so it stays unit-testable.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport { gql } from '@apollo/client';\nimport { useMutation, useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\nimport {\n groupPricesByCommodity,\n type CommodityRow,\n type MandiPrice,\n type MandiPriceTrendPoint,\n type PriceAlert,\n type PriceAlertRule,\n type PriceWatch,\n} from '../utils/mandiPrices';\n\nconst FALLBACK_WORKSPACE_ID = '00000000-0000-0000-0000-000000000001';\n\n/** Stable empty reference so downstream `useMemo`s don't recompute every render. */\nconst EMPTY_PRICES: MandiPrice[] = [];\n\ninterface HbContext {\n workspaceId: string;\n}\n\n// ── field fragments ─────────────────────────────────────────────────────────\nconst MANDI_PRICE_FIELDS = `\n commodity\n variety\n marketName\n district\n state\n minPrice\n modalPrice\n maxPrice\n arrivalQty\n unit\n priceDate\n source\n`;\n\nconst TREND_POINT_FIELDS = `\n date\n label\n minPrice\n modalPrice\n maxPrice\n`;\n\nconst WATCH_FIELDS = `\n id\n commodity\n marketName\n district\n state\n`;\n\nconst RULE_FIELDS = `\n id\n commodity\n marketName\n comparator\n threshold\n enabled\n`;\n\nconst ALERT_FIELDS = `\n id\n commodity\n marketName\n comparator\n severity\n title\n message\n value\n threshold\n status\n read\n timestamp\n actionUrl\n`;\n\n// ── documents ─────────────────────────────────────────────────────────────────\nconst GET_PRICES = gql`\n query GetHealthyBowlMandiPrices($context: ContextInput!, $filter: HealthyBowlMandiPriceFilterInput) {\n getHealthyBowlMandiPrices(context: $context, filter: $filter) { ${MANDI_PRICE_FIELDS} }\n }\n`;\n\nconst GET_TREND = gql`\n query GetHealthyBowlMandiPriceTrend(\n $context: ContextInput!\n $commodity: String!\n $marketName: String\n $days: Int\n ) {\n getHealthyBowlMandiPriceTrend(context: $context, commodity: $commodity, marketName: $marketName, days: $days) {\n ${TREND_POINT_FIELDS}\n }\n }\n`;\n\nconst GET_WATCHES = gql`\n query GetHealthyBowlPriceWatches($context: ContextInput!) {\n getHealthyBowlPriceWatches(context: $context) { ${WATCH_FIELDS} }\n }\n`;\n\nconst GET_RULES = gql`\n query GetHealthyBowlPriceAlertRules($context: ContextInput!) {\n getHealthyBowlPriceAlertRules(context: $context) { ${RULE_FIELDS} }\n }\n`;\n\nconst GET_ALERTS = gql`\n query GetHealthyBowlPriceAlerts($context: ContextInput!) {\n getHealthyBowlPriceAlerts(context: $context) { ${ALERT_FIELDS} }\n }\n`;\n\nconst CREATE_WATCH = gql`\n mutation CreateHealthyBowlPriceWatch($input: CreateHealthyBowlPriceWatchInput!) {\n createHealthyBowlPriceWatch(input: $input) { ${WATCH_FIELDS} }\n }\n`;\n\nconst DELETE_WATCH = gql`\n mutation DeleteHealthyBowlPriceWatch($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlPriceWatch(context: $context, id: $id)\n }\n`;\n\nconst CREATE_RULE = gql`\n mutation CreateHealthyBowlPriceAlertRule($input: CreateHealthyBowlPriceAlertRuleInput!) {\n createHealthyBowlPriceAlertRule(input: $input) { ${RULE_FIELDS} }\n }\n`;\n\nconst UPDATE_RULE = gql`\n mutation UpdateHealthyBowlPriceAlertRule($input: UpdateHealthyBowlPriceAlertRuleInput!) {\n updateHealthyBowlPriceAlertRule(input: $input) { ${RULE_FIELDS} }\n }\n`;\n\nconst DELETE_RULE = gql`\n mutation DeleteHealthyBowlPriceAlertRule($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlPriceAlertRule(context: $context, id: $id)\n }\n`;\n\nexport interface MandiPriceFilter {\n commodity?: string | null;\n marketName?: string | null;\n district?: string | null;\n state?: string | null;\n}\n\nexport interface UseMandiPricesOptions {\n /** Optional server-side filter; when omitted, all latest prices are returned. */\n filter?: MandiPriceFilter;\n}\n\nexport function useHealthyBowlMandiPrices(options: UseMandiPricesOptions = {}) {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || FALLBACK_WORKSPACE_ID;\n const ctx = useMemo<HbContext>(() => ({ workspaceId: effectiveWorkspaceId }), [effectiveWorkspaceId]);\n const filter = options.filter;\n\n const pricesQuery = useQuery<\n { getHealthyBowlMandiPrices: MandiPrice[] },\n { context: HbContext; filter?: MandiPriceFilter }\n >(GET_PRICES, { variables: { context: ctx, filter }, fetchPolicy: 'cache-and-network' });\n const watchesQuery = useQuery<{ getHealthyBowlPriceWatches: PriceWatch[] }, { context: HbContext }>(GET_WATCHES, {\n variables: { context: ctx },\n fetchPolicy: 'cache-and-network',\n });\n const rulesQuery = useQuery<{ getHealthyBowlPriceAlertRules: PriceAlertRule[] }, { context: HbContext }>(GET_RULES, {\n variables: { context: ctx },\n fetchPolicy: 'cache-and-network',\n });\n const alertsQuery = useQuery<{ getHealthyBowlPriceAlerts: PriceAlert[] }, { context: HbContext }>(GET_ALERTS, {\n variables: { context: ctx },\n fetchPolicy: 'cache-and-network',\n });\n\n const refetchPrices = pricesQuery.refetch;\n const refetchWatches = watchesQuery.refetch;\n const refetchRules = rulesQuery.refetch;\n const refetchAlerts = alertsQuery.refetch;\n\n const reconcile = useCallback(async (...refetchers: Array<() => Promise<unknown>>) => {\n await Promise.all(refetchers.map((run) => run().catch(() => undefined)));\n }, []);\n\n const [createWatchMutation] = useMutation<\n { createHealthyBowlPriceWatch: PriceWatch },\n { input: Record<string, unknown> }\n >(CREATE_WATCH);\n const [deleteWatchMutation] = useMutation(DELETE_WATCH);\n const [createRuleMutation] = useMutation<\n { createHealthyBowlPriceAlertRule: PriceAlertRule },\n { input: Record<string, unknown> }\n >(CREATE_RULE);\n const [updateRuleMutation] = useMutation<\n { updateHealthyBowlPriceAlertRule: PriceAlertRule },\n { input: Record<string, unknown> }\n >(UPDATE_RULE);\n const [deleteRuleMutation] = useMutation(DELETE_RULE);\n\n const withCtx = useCallback((input: Record<string, unknown>) => ({ ...input, context: ctx }), [ctx]);\n\n const prices = useMemo(() => pricesQuery.data?.getHealthyBowlMandiPrices ?? EMPTY_PRICES, [pricesQuery.data]);\n const commodities = useMemo(() => groupPricesByCommodity(prices), [prices]);\n\n return {\n prices,\n /** Latest prices rolled up to one row per commodity. */\n commodities,\n watches: watchesQuery.data?.getHealthyBowlPriceWatches ?? [],\n alertRules: rulesQuery.data?.getHealthyBowlPriceAlertRules ?? [],\n alerts: alertsQuery.data?.getHealthyBowlPriceAlerts ?? [],\n\n loading: pricesQuery.loading,\n error: pricesQuery.error ?? null,\n watchesLoading: watchesQuery.loading,\n rulesLoading: rulesQuery.loading,\n alertsLoading: alertsQuery.loading,\n\n refetchAll: useCallback(\n () => reconcile(refetchPrices, refetchWatches, refetchRules, refetchAlerts),\n [reconcile, refetchPrices, refetchWatches, refetchRules, refetchAlerts]\n ),\n\n createWatch: useCallback(\n async (input: Record<string, unknown>): Promise<PriceWatch | null> => {\n const res = await createWatchMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchWatches);\n return res.data?.createHealthyBowlPriceWatch ?? null;\n },\n [createWatchMutation, withCtx, reconcile, refetchWatches]\n ),\n deleteWatch: useCallback(\n async (id: string) => {\n const res = await deleteWatchMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await reconcile(refetchWatches);\n },\n [deleteWatchMutation, ctx, reconcile, refetchWatches]\n ),\n\n createRule: useCallback(\n async (input: Record<string, unknown>): Promise<PriceAlertRule | null> => {\n const res = await createRuleMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchRules, refetchAlerts);\n return res.data?.createHealthyBowlPriceAlertRule ?? null;\n },\n [createRuleMutation, withCtx, reconcile, refetchRules, refetchAlerts]\n ),\n updateRule: useCallback(\n async (input: Record<string, unknown>): Promise<PriceAlertRule | null> => {\n const res = await updateRuleMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchRules, refetchAlerts);\n return res.data?.updateHealthyBowlPriceAlertRule ?? null;\n },\n [updateRuleMutation, withCtx, reconcile, refetchRules, refetchAlerts]\n ),\n deleteRule: useCallback(\n async (id: string) => {\n const res = await deleteRuleMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await reconcile(refetchRules);\n },\n [deleteRuleMutation, ctx, reconcile, refetchRules]\n ),\n\n context: ctx,\n };\n}\n\nexport type { CommodityRow, MandiPrice, PriceAlert, PriceAlertRule, PriceWatch };\n\n// ── price trend (lazy, per selected commodity) ───────────────────────────────\nexport interface UseTrendOptions {\n commodity?: string;\n marketName?: string | null;\n days?: number;\n skip?: boolean;\n}\n\n/**\n * Loads a per-commodity price trend (a time series of daily observations).\n * Skipped until a commodity is selected, so a wrong/unknown market never fires\n * a request on page load; the caller renders it defensively.\n */\nexport function useHealthyBowlMandiPriceTrend(options: UseTrendOptions = {}) {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || FALLBACK_WORKSPACE_ID;\n const ctx = useMemo<HbContext>(() => ({ workspaceId: effectiveWorkspaceId }), [effectiveWorkspaceId]);\n const days = options.days ?? 30;\n\n const trendQuery = useQuery<\n { getHealthyBowlMandiPriceTrend: MandiPriceTrendPoint[] },\n { context: HbContext; commodity: string; marketName: string | null; days: number }\n >(GET_TREND, {\n variables: {\n context: ctx,\n commodity: options.commodity ?? '',\n marketName: options.marketName ?? null,\n days,\n },\n skip: options.skip || !options.commodity,\n fetchPolicy: 'cache-and-network',\n });\n\n return {\n points: trendQuery.data?.getHealthyBowlMandiPriceTrend ?? [],\n loading: trendQuery.loading,\n error: trendQuery.error ?? null,\n };\n}\n"],"mappings":";;;;;;AA4BA,IAAM,IAAwB,wCAGxB,IAA6B,EAAE,EAO/B,IAAqB,oJAerB,IAAqB,6DAQrB,IAAe,4DAQf,IAAc,6EASd,IAAe,uJAiBf,IAAa,CAAG;;sEAEgD,EAAmB;;GAInF,IAAY,CAAG;;;;;;;;QAQb,EAAmB;;;GAKrB,IAAc,CAAG;;sDAE+B,EAAa;;GAI7D,IAAY,CAAG;;yDAEoC,EAAY;;GAI/D,IAAa,CAAG;;qDAE+B,EAAa;;GAI5D,IAAe,CAAG;;mDAE2B,EAAa;;GAI1D,IAAe,CAAG;;;;GAMlB,IAAc,CAAG;;uDAEgC,EAAY;;GAI7D,IAAc,CAAG;;uDAEgC,EAAY;;GAI7D,IAAc,CAAG;;;;;AAkBvB,SAAgB,EAA0B,IAAiC,EAAE,EAAE;CAC7E,IAAM,EAAE,mBAAgB,GAAgB,EAClC,IAAuB,KAAe,GACtC,IAAM,SAA0B,EAAE,aAAa,GAAsB,GAAG,CAAC,EAAqB,CAAC,EAC/F,IAAS,EAAQ,QAEjB,IAAc,EAGlB,GAAY;EAAE,WAAW;GA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