@burdenoff/microfe-brainyrich 2026.825.1 → 2026.827.1
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/brainyrich/components/reuse/DocumentsPanel.d.ts +4 -0
- package/dist/brainyrich/components/reuse/DocumentsPanel.d.ts.map +1 -1
- package/dist/brainyrich/components/reuse/DocumentsPanel.js +150 -99
- package/dist/brainyrich/components/reuse/DocumentsPanel.js.map +1 -1
- package/dist/brainyrich/hooks/useBrainyRichApi.d.ts +176 -0
- package/dist/brainyrich/hooks/useBrainyRichApi.d.ts.map +1 -1
- package/dist/brainyrich/hooks/useBrainyRichApi.js +96 -82
- package/dist/brainyrich/hooks/useBrainyRichApi.js.map +1 -1
- package/dist/brainyrich/pages/AdminFirmPage.d.ts.map +1 -1
- package/dist/brainyrich/pages/AdminFirmPage.js +115 -83
- package/dist/brainyrich/pages/AdminFirmPage.js.map +1 -1
- package/dist/brainyrich/pages/AiAssistantPage.d.ts.map +1 -1
- package/dist/brainyrich/pages/AiAssistantPage.js +251 -230
- package/dist/brainyrich/pages/AiAssistantPage.js.map +1 -1
- package/dist/brainyrich/pages/FirmPage.d.ts.map +1 -1
- package/dist/brainyrich/pages/FirmPage.js +148 -116
- package/dist/brainyrich/pages/FirmPage.js.map +1 -1
- package/dist/brainyrich/pages/PortfoliosPage.d.ts +14 -0
- package/dist/brainyrich/pages/PortfoliosPage.d.ts.map +1 -1
- package/dist/brainyrich/pages/PortfoliosPage.js +530 -353
- package/dist/brainyrich/pages/PortfoliosPage.js.map +1 -1
- package/dist/brainyrich/pages/RiskPage.d.ts.map +1 -1
- package/dist/brainyrich/pages/RiskPage.js +381 -396
- package/dist/brainyrich/pages/RiskPage.js.map +1 -1
- package/dist/brainyrich/pages/_shared.d.ts +21 -0
- package/dist/brainyrich/pages/_shared.d.ts.map +1 -1
- package/dist/brainyrich/pages/_shared.js +66 -31
- package/dist/brainyrich/pages/_shared.js.map +1 -1
- package/package.json +1 -1
|
@@ -14,8 +14,12 @@
|
|
|
14
14
|
* first upload via `createFolder`); no side-effects on read.
|
|
15
15
|
* - list → `getFilesInFolder(folderId, pagination)`
|
|
16
16
|
* - upload (3-step) → `initiateUpload` → S3 `PUT` (byte-progress) → `completeUpload`
|
|
17
|
+
* reachable by click OR by dropping a file on the zone; both take one file,
|
|
18
|
+
* which is exactly what the single-file upload mutation supports.
|
|
17
19
|
* - download → `getFileDownloadUrl(id, expiresIn)` capped at 21600s to
|
|
18
20
|
* avoid the >604800 fleet bug (S3 7-day cap → 500).
|
|
21
|
+
* - delete → `deleteFile(id)` (RBAC `delete`/`file`, enforced at the
|
|
22
|
+
* gateway) behind a confirm step.
|
|
19
23
|
*
|
|
20
24
|
* Presentational + self-contained: owns its hooks, reads the gateway base URL
|
|
21
25
|
* from `useBrainyRich()`, uses fe-libs/ui primitives + semantic tokens.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentsPanel.d.ts","sourceRoot":"","sources":["../../../../src/brainyrich/components/reuse/DocumentsPanel.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"DocumentsPanel.d.ts","sourceRoot":"","sources":["../../../../src/brainyrich/components/reuse/DocumentsPanel.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAyPH,MAAM,WAAW,mBAAmB;IAClC,mFAAmF;IACnF,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,wBAAgB,cAAc,CAAC,EAC7B,UAAU,EACV,QAAQ,EACR,OAAqB,EACrB,WAAmB,GACpB,EAAE,mBAAmB,2CAmNrB"}
|
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
import { useBrainyRich as e } from "../../providers/BrainyRichProvider.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
2
|
+
import { ConfirmDialog as t } from "../ConfirmDialog.js";
|
|
3
|
+
import { formatDate as n } from "../../pages/_shared.js";
|
|
4
|
+
import { wspaceFetch as r, wspaceMutate as i } from "./transport.js";
|
|
5
|
+
import { useCallback as a, useRef as o, useState as s } from "react";
|
|
6
|
+
import { Download as c, FileText as l, Trash2 as u, Upload as d, UploadCloud as f } from "lucide-react";
|
|
7
|
+
import { useMutation as p, useQuery as m, useQueryClient as h } from "@tanstack/react-query";
|
|
8
|
+
import { jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
9
|
+
import { Button as v, Card as y, CardContent as b, Skeleton as x } from "@burdenoff/fe-libs/ui";
|
|
9
10
|
//#region src/brainyrich/components/reuse/DocumentsPanel.tsx
|
|
10
|
-
var
|
|
11
|
+
var S = 21600, C = "id name extension mimeType size createdAt", w = (e, t) => `BrainyRich · ${e} · ${t}`, T = (e, t) => [
|
|
11
12
|
"brainyrich",
|
|
12
13
|
"entity-folder",
|
|
13
14
|
e,
|
|
14
15
|
t
|
|
15
|
-
],
|
|
16
|
+
], E = (e) => [
|
|
16
17
|
"brainyrich",
|
|
17
18
|
"folder-files",
|
|
18
19
|
e ?? "none"
|
|
19
|
-
],
|
|
20
|
-
let { apiGatewayUrl: i } = e(), a =
|
|
21
|
-
return
|
|
22
|
-
queryKey:
|
|
23
|
-
enabled: !!
|
|
24
|
-
queryFn: async () => (await
|
|
20
|
+
], D = (t, n) => {
|
|
21
|
+
let { apiGatewayUrl: i } = e(), a = n ? w(t, n) : "";
|
|
22
|
+
return m({
|
|
23
|
+
queryKey: T(t, n ?? ""),
|
|
24
|
+
enabled: !!n,
|
|
25
|
+
queryFn: async () => (await r("query BraGetFolders($pagination: PaginationInput) {\n getFolders(pagination: $pagination) { folders { id name } }\n }", { pagination: {
|
|
25
26
|
limit: 200,
|
|
26
27
|
offset: 0
|
|
27
28
|
} }, i)).getFolders.folders.find((e) => e.name === a) ?? null
|
|
28
29
|
});
|
|
29
|
-
},
|
|
30
|
-
let { apiGatewayUrl:
|
|
31
|
-
return
|
|
32
|
-
queryKey:
|
|
30
|
+
}, O = (t) => {
|
|
31
|
+
let { apiGatewayUrl: n } = e();
|
|
32
|
+
return m({
|
|
33
|
+
queryKey: E(t),
|
|
33
34
|
enabled: !!t,
|
|
34
|
-
queryFn: async () => (await
|
|
35
|
+
queryFn: async () => (await r(`query BraGetFilesInFolder($folderId: ID, $pagination: PaginationInput) {
|
|
35
36
|
getFilesInFolder(folderId: $folderId, pagination: $pagination) {
|
|
36
|
-
files { ${
|
|
37
|
+
files { ${C} }
|
|
37
38
|
}
|
|
38
39
|
}`, {
|
|
39
40
|
folderId: t,
|
|
@@ -41,10 +42,10 @@ var y = 21600, b = "id name extension mimeType size createdAt", x = (e, t) => `B
|
|
|
41
42
|
limit: 100,
|
|
42
43
|
offset: 0
|
|
43
44
|
}
|
|
44
|
-
},
|
|
45
|
+
}, n)).getFilesInFolder.files
|
|
45
46
|
});
|
|
46
47
|
};
|
|
47
|
-
function
|
|
48
|
+
function k(e, t, n, r) {
|
|
48
49
|
return new Promise((i, a) => {
|
|
49
50
|
let o = new XMLHttpRequest();
|
|
50
51
|
o.open("PUT", e), o.setRequestHeader("Content-Type", n), o.upload.onprogress = (e) => {
|
|
@@ -52,22 +53,22 @@ function E(e, t, n, r) {
|
|
|
52
53
|
}, o.onload = () => o.status >= 200 && o.status < 300 ? i() : a(/* @__PURE__ */ Error(`File storage rejected the upload (HTTP ${o.status}).`)), o.onerror = () => a(/* @__PURE__ */ Error("Network error while uploading the file.")), o.onabort = () => a(/* @__PURE__ */ Error("The upload was cancelled.")), o.send(t);
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
|
-
var
|
|
56
|
-
let { apiGatewayUrl: a } = e(),
|
|
56
|
+
var A = (t, n) => {
|
|
57
|
+
let { apiGatewayUrl: a } = e(), o = h(), [c, l] = s(0);
|
|
57
58
|
return {
|
|
58
|
-
...
|
|
59
|
+
...p({
|
|
59
60
|
mutationFn: async (e) => {
|
|
60
61
|
l(0);
|
|
61
|
-
let o = await
|
|
62
|
+
let o = await r("query BraResolveFolder($pagination: PaginationInput) {\n getFolders(pagination: $pagination) { folders { id name } }\n }", { pagination: {
|
|
62
63
|
limit: 200,
|
|
63
64
|
offset: 0
|
|
64
|
-
} }, a).then((e) => e.getFolders.folders.find((e) => e.name ===
|
|
65
|
-
o ||= (await
|
|
66
|
-
name:
|
|
67
|
-
description: `Documents attached to ${t} ${
|
|
65
|
+
} }, a).then((e) => e.getFolders.folders.find((e) => e.name === w(t, n)));
|
|
66
|
+
o ||= (await i("mutation BraCreateFolder($input: CreateFolderInput!) {\n createFolder(input: $input) { id name }\n }", { input: {
|
|
67
|
+
name: w(t, n),
|
|
68
|
+
description: `Documents attached to ${t} ${n}.`,
|
|
68
69
|
visibility: "WORKSPACE"
|
|
69
70
|
} }, a)).createFolder;
|
|
70
|
-
let s = o.id, c = e.name.lastIndexOf("."), u = c > -1 ? e.name.slice(c + 1) : "", d = e.type || "application/octet-stream", f = String(e.size), p = await
|
|
71
|
+
let s = o.id, c = e.name.lastIndexOf("."), u = c > -1 ? e.name.slice(c + 1) : "", d = e.type || "application/octet-stream", f = String(e.size), p = await i("mutation BraInitiateUpload($input: InitiateUploadInput!) {\n initiateUpload(input: $input) { uploadUrl session { id } }\n }", { input: {
|
|
71
72
|
fileName: e.name,
|
|
72
73
|
extension: u,
|
|
73
74
|
mimeType: d,
|
|
@@ -76,147 +77,182 @@ var D = (t, i) => {
|
|
|
76
77
|
visibility: "WORKSPACE"
|
|
77
78
|
} }, a), { uploadUrl: m } = p.initiateUpload, h = p.initiateUpload.session.id;
|
|
78
79
|
if (!m) throw Error("The file service did not return an upload URL.");
|
|
79
|
-
return await
|
|
80
|
+
return await k(m, e, d, l), await i("mutation BraCompleteUpload($input: CompleteUploadInput!) {\n completeUpload(input: $input) { fileId }\n }", { input: {
|
|
80
81
|
sessionId: h,
|
|
81
82
|
fileSize: f,
|
|
82
83
|
folderId: s
|
|
83
84
|
} }, a), l(100), s;
|
|
84
85
|
},
|
|
85
86
|
onSuccess: (e) => {
|
|
86
|
-
|
|
87
|
+
o.invalidateQueries({ queryKey: T(t, n) }), o.invalidateQueries({ queryKey: E(e) });
|
|
87
88
|
}
|
|
88
89
|
}),
|
|
89
90
|
progress: c
|
|
90
91
|
};
|
|
91
|
-
},
|
|
92
|
+
}, j = () => {
|
|
92
93
|
let { apiGatewayUrl: t } = e();
|
|
93
|
-
return
|
|
94
|
+
return p({ mutationFn: async (e) => (await r("query BraGetFileDownloadUrl($id: ID!, $expiresIn: Int) {\n getFileDownloadUrl(id: $id, expiresIn: $expiresIn)\n }", {
|
|
94
95
|
id: e,
|
|
95
|
-
expiresIn:
|
|
96
|
+
expiresIn: S
|
|
96
97
|
}, t)).getFileDownloadUrl });
|
|
97
|
-
},
|
|
98
|
+
}, M = (t) => {
|
|
99
|
+
let { apiGatewayUrl: n } = e(), r = h();
|
|
100
|
+
return p({
|
|
101
|
+
mutationFn: async (e) => (await i("mutation BraDeleteFile($id: ID!) { deleteFile(id: $id) }", { id: e }, n)).deleteFile,
|
|
102
|
+
onSuccess: () => r.invalidateQueries({ queryKey: E(t) })
|
|
103
|
+
});
|
|
104
|
+
}, N = (e) => {
|
|
98
105
|
let t = Number(e);
|
|
99
106
|
return !Number.isFinite(t) || t <= 0 ? "—" : t < 1024 ? `${t} B` : t < 1024 * 1024 ? `${(t / 1024).toFixed(0)} KB` : `${(t / (1024 * 1024)).toFixed(1)} MB`;
|
|
100
107
|
};
|
|
101
|
-
function
|
|
102
|
-
let
|
|
108
|
+
function P({ entityType: e, entityId: r, heading: i = "Documents", hideHeading: p = !1 }) {
|
|
109
|
+
let m = o(null), h = D(e, r), S = O(h.data?.id), C = A(e, r), w = j(), T = M(h.data?.id), [E, k] = s(!1), [P, F] = s(null), I = a((e) => {
|
|
103
110
|
let t = e.target.files?.[0];
|
|
104
|
-
t &&
|
|
105
|
-
}, [
|
|
106
|
-
|
|
111
|
+
t && C.mutate(t), e.target.value = "";
|
|
112
|
+
}, [C]), L = a((e) => {
|
|
113
|
+
if (e.preventDefault(), k(!1), C.isPending) return;
|
|
114
|
+
let t = e.dataTransfer.files?.[0];
|
|
115
|
+
t && C.mutate(t);
|
|
116
|
+
}, [C]), R = async (e) => {
|
|
117
|
+
let t = await w.mutateAsync(e);
|
|
107
118
|
t && window.open(t, "_blank", "noopener,noreferrer");
|
|
108
|
-
},
|
|
109
|
-
return /* @__PURE__ */
|
|
119
|
+
}, z = h.isLoading || !!h.data && S.isLoading, B = S.data ?? [];
|
|
120
|
+
return /* @__PURE__ */ _("div", {
|
|
110
121
|
className: "space-y-3",
|
|
111
122
|
children: [
|
|
112
|
-
/* @__PURE__ */
|
|
123
|
+
/* @__PURE__ */ _("div", {
|
|
113
124
|
className: "flex items-center justify-between",
|
|
114
|
-
children: [!
|
|
125
|
+
children: [!p && /* @__PURE__ */ _("h3", {
|
|
115
126
|
className: "flex items-center gap-2 text-sm font-semibold text-text-primary",
|
|
116
|
-
children: [/* @__PURE__ */
|
|
127
|
+
children: [/* @__PURE__ */ g(l, {
|
|
117
128
|
className: "size-4",
|
|
118
129
|
"aria-hidden": "true"
|
|
119
|
-
}),
|
|
120
|
-
}), /* @__PURE__ */
|
|
130
|
+
}), i]
|
|
131
|
+
}), /* @__PURE__ */ _("div", {
|
|
121
132
|
className: "ml-auto",
|
|
122
|
-
children: [/* @__PURE__ */
|
|
123
|
-
ref:
|
|
133
|
+
children: [/* @__PURE__ */ g("input", {
|
|
134
|
+
ref: m,
|
|
124
135
|
type: "file",
|
|
125
136
|
className: "sr-only",
|
|
126
137
|
"aria-hidden": "true",
|
|
127
138
|
tabIndex: -1,
|
|
128
|
-
onChange:
|
|
129
|
-
}), /* @__PURE__ */
|
|
139
|
+
onChange: I
|
|
140
|
+
}), /* @__PURE__ */ _(v, {
|
|
130
141
|
type: "button",
|
|
131
142
|
size: "sm",
|
|
132
143
|
variant: "outline",
|
|
133
|
-
onClick: () =>
|
|
134
|
-
disabled:
|
|
135
|
-
children: [/* @__PURE__ */
|
|
144
|
+
onClick: () => m.current?.click(),
|
|
145
|
+
disabled: C.isPending,
|
|
146
|
+
children: [/* @__PURE__ */ g(d, {
|
|
136
147
|
className: "size-4",
|
|
137
148
|
"aria-hidden": "true"
|
|
138
|
-
}),
|
|
149
|
+
}), C.isPending ? `Uploading ${C.progress}%` : "Upload"]
|
|
139
150
|
})]
|
|
140
151
|
})]
|
|
141
152
|
}),
|
|
142
|
-
|
|
153
|
+
C.isPending && /* @__PURE__ */ g("div", {
|
|
143
154
|
className: "h-1.5 w-full overflow-hidden rounded-full bg-bg-sunken",
|
|
144
155
|
role: "progressbar",
|
|
145
156
|
"aria-label": "Upload progress",
|
|
146
|
-
"aria-valuenow":
|
|
157
|
+
"aria-valuenow": C.progress,
|
|
147
158
|
"aria-valuemin": 0,
|
|
148
159
|
"aria-valuemax": 100,
|
|
149
|
-
children: /* @__PURE__ */
|
|
160
|
+
children: /* @__PURE__ */ g("div", {
|
|
150
161
|
className: "h-full rounded-full bg-primary motion-safe:transition-[width] motion-safe:duration-200",
|
|
151
|
-
style: { width: `${
|
|
162
|
+
style: { width: `${C.progress}%` }
|
|
152
163
|
})
|
|
153
164
|
}),
|
|
154
|
-
|
|
165
|
+
/* @__PURE__ */ _("button", {
|
|
166
|
+
type: "button",
|
|
167
|
+
onClick: () => m.current?.click(),
|
|
168
|
+
disabled: C.isPending,
|
|
169
|
+
onDragOver: (e) => {
|
|
170
|
+
e.preventDefault(), C.isPending || k(!0);
|
|
171
|
+
},
|
|
172
|
+
onDragLeave: () => k(!1),
|
|
173
|
+
onDrop: L,
|
|
174
|
+
className: `w-full rounded-lg border border-dashed px-4 py-8 text-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-action-primary-border)] disabled:cursor-not-allowed disabled:opacity-60 ${E ? "border-[var(--color-action-primary-border)] bg-bg-elevated" : "border-border-subtle bg-bg-surface hover:border-[var(--color-action-primary-border)]"}`,
|
|
175
|
+
children: [
|
|
176
|
+
/* @__PURE__ */ g(f, {
|
|
177
|
+
className: "mx-auto mb-2 size-6 text-text-secondary",
|
|
178
|
+
"aria-hidden": "true"
|
|
179
|
+
}),
|
|
180
|
+
/* @__PURE__ */ g("span", {
|
|
181
|
+
className: "block text-sm text-text-primary",
|
|
182
|
+
children: "Drop a statement, KYC or tax document here"
|
|
183
|
+
}),
|
|
184
|
+
/* @__PURE__ */ g("span", {
|
|
185
|
+
className: "mt-0.5 block text-xs text-text-secondary",
|
|
186
|
+
children: "or click to choose one file"
|
|
187
|
+
})
|
|
188
|
+
]
|
|
189
|
+
}),
|
|
190
|
+
z ? /* @__PURE__ */ _("div", {
|
|
155
191
|
className: "space-y-2",
|
|
156
192
|
"aria-busy": "true",
|
|
157
|
-
children: [/* @__PURE__ */
|
|
158
|
-
}) :
|
|
193
|
+
children: [/* @__PURE__ */ g(x, { className: "h-12 w-full rounded-md" }), /* @__PURE__ */ g(x, { className: "h-12 w-full rounded-md" })]
|
|
194
|
+
}) : S.isError ? /* @__PURE__ */ _("p", {
|
|
159
195
|
className: "text-sm text-status-error-text",
|
|
160
196
|
children: [
|
|
161
197
|
"Could not load documents.",
|
|
162
198
|
" ",
|
|
163
|
-
/* @__PURE__ */
|
|
199
|
+
/* @__PURE__ */ g("button", {
|
|
164
200
|
type: "button",
|
|
165
201
|
className: "underline underline-offset-2",
|
|
166
|
-
onClick: () =>
|
|
202
|
+
onClick: () => S.refetch(),
|
|
167
203
|
children: "Retry"
|
|
168
204
|
})
|
|
169
205
|
]
|
|
170
|
-
}) :
|
|
171
|
-
className: "
|
|
172
|
-
children:
|
|
173
|
-
|
|
174
|
-
className: "mx-auto mb-2 size-6 text-text-secondary",
|
|
175
|
-
"aria-hidden": "true"
|
|
176
|
-
}),
|
|
177
|
-
/* @__PURE__ */ p("p", {
|
|
178
|
-
className: "text-sm text-text-primary",
|
|
179
|
-
children: "No documents yet"
|
|
180
|
-
}),
|
|
181
|
-
/* @__PURE__ */ p("p", {
|
|
182
|
-
className: "mt-0.5 text-xs text-text-secondary",
|
|
183
|
-
children: "Upload statements, KYC or tax documents for this record."
|
|
184
|
-
})
|
|
185
|
-
]
|
|
186
|
-
}) : /* @__PURE__ */ p("ul", {
|
|
206
|
+
}) : B.length === 0 ? /* @__PURE__ */ g("p", {
|
|
207
|
+
className: "text-center text-xs text-text-secondary",
|
|
208
|
+
children: "No documents attached to this record yet."
|
|
209
|
+
}) : /* @__PURE__ */ g("ul", {
|
|
187
210
|
className: "space-y-2",
|
|
188
|
-
children:
|
|
211
|
+
children: B.map((e) => /* @__PURE__ */ g("li", { children: /* @__PURE__ */ g(y, { children: /* @__PURE__ */ _(b, {
|
|
189
212
|
className: "flex items-center gap-3 p-3",
|
|
190
213
|
children: [
|
|
191
|
-
/* @__PURE__ */
|
|
214
|
+
/* @__PURE__ */ g("div", {
|
|
192
215
|
className: "flex size-9 shrink-0 items-center justify-center rounded-md bg-bg-sunken text-text-secondary",
|
|
193
|
-
children: /* @__PURE__ */
|
|
216
|
+
children: /* @__PURE__ */ g(l, {
|
|
194
217
|
className: "size-4",
|
|
195
218
|
"aria-hidden": "true"
|
|
196
219
|
})
|
|
197
220
|
}),
|
|
198
|
-
/* @__PURE__ */
|
|
221
|
+
/* @__PURE__ */ _("div", {
|
|
199
222
|
className: "min-w-0 flex-1",
|
|
200
|
-
children: [/* @__PURE__ */
|
|
223
|
+
children: [/* @__PURE__ */ g("p", {
|
|
201
224
|
className: "truncate text-sm font-medium text-text-primary",
|
|
202
225
|
children: e.name
|
|
203
|
-
}), /* @__PURE__ */
|
|
226
|
+
}), /* @__PURE__ */ _("p", {
|
|
204
227
|
className: "text-xs text-text-secondary",
|
|
205
228
|
children: [
|
|
206
|
-
|
|
229
|
+
N(e.size),
|
|
207
230
|
" · ",
|
|
208
|
-
|
|
231
|
+
n(e.createdAt)
|
|
209
232
|
]
|
|
210
233
|
})]
|
|
211
234
|
}),
|
|
212
|
-
/* @__PURE__ */
|
|
235
|
+
/* @__PURE__ */ g(v, {
|
|
213
236
|
type: "button",
|
|
214
237
|
size: "sm",
|
|
215
238
|
variant: "ghost",
|
|
216
239
|
"aria-label": `Download ${e.name}`,
|
|
217
|
-
disabled:
|
|
218
|
-
onClick: () =>
|
|
219
|
-
children: /* @__PURE__ */
|
|
240
|
+
disabled: w.isPending,
|
|
241
|
+
onClick: () => R(e.id),
|
|
242
|
+
children: /* @__PURE__ */ g(c, {
|
|
243
|
+
className: "size-4",
|
|
244
|
+
"aria-hidden": "true"
|
|
245
|
+
})
|
|
246
|
+
}),
|
|
247
|
+
/* @__PURE__ */ g(v, {
|
|
248
|
+
type: "button",
|
|
249
|
+
size: "sm",
|
|
250
|
+
variant: "ghost",
|
|
251
|
+
className: "text-status-error-text hover:text-status-error-text",
|
|
252
|
+
"aria-label": `Delete ${e.name}`,
|
|
253
|
+
disabled: T.isPending,
|
|
254
|
+
onClick: () => F(e),
|
|
255
|
+
children: /* @__PURE__ */ g(u, {
|
|
220
256
|
className: "size-4",
|
|
221
257
|
"aria-hidden": "true"
|
|
222
258
|
})
|
|
@@ -224,14 +260,29 @@ function A({ entityType: e, entityId: n, heading: r = "Documents", hideHeading:
|
|
|
224
260
|
]
|
|
225
261
|
}) }) }, e.id))
|
|
226
262
|
}),
|
|
227
|
-
(
|
|
263
|
+
(C.isError || w.isError || T.isError) && /* @__PURE__ */ g("p", {
|
|
228
264
|
className: "text-sm text-status-error-text",
|
|
229
|
-
children:
|
|
265
|
+
children: C.error instanceof Error ? C.error.message : T.error instanceof Error ? `Could not delete the document. ${T.error.message}` : w.error instanceof Error ? "Could not open the document. Please try again." : "Something went wrong. Please try again."
|
|
266
|
+
}),
|
|
267
|
+
/* @__PURE__ */ g(t, {
|
|
268
|
+
open: P !== null,
|
|
269
|
+
onOpenChange: (e) => {
|
|
270
|
+
e || F(null);
|
|
271
|
+
},
|
|
272
|
+
title: "Delete this document?",
|
|
273
|
+
description: P ? `“${P.name}” will be removed from this record. This cannot be undone.` : void 0,
|
|
274
|
+
confirmLabel: "Delete",
|
|
275
|
+
pendingLabel: "Deleting…",
|
|
276
|
+
destructive: !0,
|
|
277
|
+
pending: T.isPending,
|
|
278
|
+
onConfirm: () => {
|
|
279
|
+
P && T.mutate(P.id, { onSuccess: () => F(null) });
|
|
280
|
+
}
|
|
230
281
|
})
|
|
231
282
|
]
|
|
232
283
|
});
|
|
233
284
|
}
|
|
234
285
|
//#endregion
|
|
235
|
-
export {
|
|
286
|
+
export { P as DocumentsPanel };
|
|
236
287
|
|
|
237
288
|
//# sourceMappingURL=DocumentsPanel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentsPanel.js","names":[],"sources":["../../../../src/brainyrich/components/reuse/DocumentsPanel.tsx"],"sourcesContent":["/**\n * DocumentsPanel — REUSE of `wspace-files-svc` for statement / KYC / tax-doc\n * attachments on Accounts + Households.\n * @module brainyrich/components/reuse/DocumentsPanel\n *\n * A wealth product needs to attach documents (statements, KYC, tax packs) to\n * accounts and households. `wspace-files-svc` has no native entity-owned link on\n * `File`, so we scope documents to an entity via a dedicated, stably-named\n * FOLDER per `(entityType, entityId)` and list its contents. All ops route\n * through the workspace supergraph the MFE already uses.\n *\n * Flow:\n * - resolve folder → `getFolders(filter)` matched by name (created lazily on\n * first upload via `createFolder`); no side-effects on read.\n * - list → `getFilesInFolder(folderId, pagination)`\n * - upload (3-step) → `initiateUpload` → S3 `PUT` (byte-progress) → `completeUpload`\n * - download → `getFileDownloadUrl(id, expiresIn)` capped at 21600s to\n * avoid the >604800 fleet bug (S3 7-day cap → 500).\n *\n * Presentational + self-contained: owns its hooks, reads the gateway base URL\n * from `useBrainyRich()`, uses fe-libs/ui primitives + semantic tokens.\n */\n\nimport { useCallback, useRef, useState } from 'react';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport { Download, FileText, Upload } from 'lucide-react';\nimport { Button, Card, CardContent, Skeleton } from '@burdenoff/fe-libs/ui';\n\nimport { useBrainyRich } from '../../providers/BrainyRichProvider';\nimport { formatDate } from '../../pages/_shared';\nimport { wspaceFetch, wspaceMutate } from './transport';\n\n// Presigned-URL TTL: cap at 21600s (6h). >604800 (S3 7-day) → INTERNAL_SERVER_ERROR.\nconst DOWNLOAD_URL_TTL_SECONDS = 21600;\n\ninterface FilesFolder {\n id: string;\n name: string;\n}\n\ninterface FilesFile {\n id: string;\n name: string;\n extension: string;\n mimeType: string;\n size: string;\n createdAt: string;\n}\n\nconst FILE_FIELDS = 'id name extension mimeType size createdAt';\n\nconst folderName = (entityType: string, entityId: string) =>\n `BrainyRich · ${entityType} · ${entityId}`;\n\nconst folderKey = (entityType: string, entityId: string) =>\n ['brainyrich', 'entity-folder', entityType, entityId] as const;\n\nconst filesKey = (folderId: string | null | undefined) =>\n ['brainyrich', 'folder-files', folderId ?? 'none'] as const;\n\n// ============================================================================\n// Folder resolution (read-only — no lazy creation here)\n// ============================================================================\n\nconst useEntityFolder = (entityType: string, entityId: string | undefined) => {\n const { apiGatewayUrl } = useBrainyRich();\n const wanted = entityId ? folderName(entityType, entityId) : '';\n return useQuery({\n queryKey: folderKey(entityType, entityId ?? ''),\n enabled: Boolean(entityId),\n queryFn: async () => {\n const data = await wspaceFetch<{ getFolders: { folders: FilesFolder[] } }>(\n `query BraGetFolders($pagination: PaginationInput) {\n getFolders(pagination: $pagination) { folders { id name } }\n }`,\n { pagination: { limit: 200, offset: 0 } },\n apiGatewayUrl\n );\n return data.getFolders.folders.find((f) => f.name === wanted) ?? null;\n },\n });\n};\n\nconst useFolderFiles = (folderId: string | null | undefined) => {\n const { apiGatewayUrl } = useBrainyRich();\n return useQuery({\n queryKey: filesKey(folderId),\n enabled: Boolean(folderId),\n queryFn: async () => {\n const data = await wspaceFetch<{ getFilesInFolder: { files: FilesFile[] } }>(\n `query BraGetFilesInFolder($folderId: ID, $pagination: PaginationInput) {\n getFilesInFolder(folderId: $folderId, pagination: $pagination) {\n files { ${FILE_FIELDS} }\n }\n }`,\n { folderId, pagination: { limit: 100, offset: 0 } },\n apiGatewayUrl\n );\n return data.getFilesInFolder.files;\n },\n });\n};\n\n// ============================================================================\n// Upload (3-step platform flow, with lazy folder creation)\n// ============================================================================\n\nfunction putWithProgress(\n url: string,\n file: File,\n contentType: string,\n onProgress: (percent: number) => void\n): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n const xhr = new XMLHttpRequest();\n xhr.open('PUT', url);\n xhr.setRequestHeader('Content-Type', contentType);\n xhr.upload.onprogress = (event) => {\n if (event.lengthComputable) {\n onProgress(Math.round((event.loaded / event.total) * 100));\n }\n };\n xhr.onload = () =>\n xhr.status >= 200 && xhr.status < 300\n ? resolve()\n : reject(new Error(`File storage rejected the upload (HTTP ${xhr.status}).`));\n xhr.onerror = () => reject(new Error('Network error while uploading the file.'));\n xhr.onabort = () => reject(new Error('The upload was cancelled.'));\n xhr.send(file);\n });\n}\n\nconst useDocumentUpload = (entityType: string, entityId: string) => {\n const { apiGatewayUrl } = useBrainyRich();\n const qc = useQueryClient();\n const [progress, setProgress] = useState(0);\n\n const mutation = useMutation({\n mutationFn: async (file: File) => {\n setProgress(0);\n\n // 0. resolve or create the entity folder\n let folder = await wspaceFetch<{ getFolders: { folders: FilesFolder[] } }>(\n `query BraResolveFolder($pagination: PaginationInput) {\n getFolders(pagination: $pagination) { folders { id name } }\n }`,\n { pagination: { limit: 200, offset: 0 } },\n apiGatewayUrl\n ).then((d) => d.getFolders.folders.find((f) => f.name === folderName(entityType, entityId)));\n\n if (!folder) {\n const created = await wspaceMutate<{ createFolder: FilesFolder }>(\n `mutation BraCreateFolder($input: CreateFolderInput!) {\n createFolder(input: $input) { id name }\n }`,\n {\n input: {\n name: folderName(entityType, entityId),\n description: `Documents attached to ${entityType} ${entityId}.`,\n visibility: 'WORKSPACE',\n },\n },\n apiGatewayUrl\n );\n folder = created.createFolder;\n }\n const folderId = folder.id;\n\n const dotIndex = file.name.lastIndexOf('.');\n const extension = dotIndex > -1 ? file.name.slice(dotIndex + 1) : '';\n const mimeType = file.type || 'application/octet-stream';\n const fileSize = String(file.size);\n\n // 1. initiate\n const initiated = await wspaceMutate<{\n initiateUpload: { uploadUrl: string | null; session: { id: string } };\n }>(\n `mutation BraInitiateUpload($input: InitiateUploadInput!) {\n initiateUpload(input: $input) { uploadUrl session { id } }\n }`,\n {\n input: {\n fileName: file.name,\n extension,\n mimeType,\n fileSize,\n folderId,\n visibility: 'WORKSPACE',\n },\n },\n apiGatewayUrl\n );\n const { uploadUrl } = initiated.initiateUpload;\n const sessionId = initiated.initiateUpload.session.id;\n if (!uploadUrl) throw new Error('The file service did not return an upload URL.');\n\n // 2. PUT the bytes\n await putWithProgress(uploadUrl, file, mimeType, setProgress);\n\n // 3. complete\n await wspaceMutate<{ completeUpload: { fileId: string } }>(\n `mutation BraCompleteUpload($input: CompleteUploadInput!) {\n completeUpload(input: $input) { fileId }\n }`,\n { input: { sessionId, fileSize, folderId } },\n apiGatewayUrl\n );\n setProgress(100);\n return folderId;\n },\n onSuccess: (folderId) => {\n qc.invalidateQueries({ queryKey: folderKey(entityType, entityId) });\n qc.invalidateQueries({ queryKey: filesKey(folderId) });\n },\n });\n\n return { ...mutation, progress };\n};\n\nconst useDownloadFile = () => {\n const { apiGatewayUrl } = useBrainyRich();\n return useMutation({\n mutationFn: async (id: string) => {\n const data = await wspaceFetch<{ getFileDownloadUrl: string }>(\n `query BraGetFileDownloadUrl($id: ID!, $expiresIn: Int) {\n getFileDownloadUrl(id: $id, expiresIn: $expiresIn)\n }`,\n { id, expiresIn: DOWNLOAD_URL_TTL_SECONDS },\n apiGatewayUrl\n );\n return data.getFileDownloadUrl;\n },\n });\n};\n\n// ============================================================================\n// Component\n// ============================================================================\n\nconst formatSize = (bytes: string): string => {\n const n = Number(bytes);\n if (!Number.isFinite(n) || n <= 0) return '—';\n if (n < 1024) return `${n} B`;\n if (n < 1024 * 1024) return `${(n / 1024).toFixed(0)} KB`;\n return `${(n / (1024 * 1024)).toFixed(1)} MB`;\n};\n\nexport interface DocumentsPanelProps {\n /** Polymorphic entity type, e.g. \"brainyrich-account\" | \"brainyrich-household\". */\n entityType: string;\n /** The bra entity's id (an ID scalar). */\n entityId: string;\n /** Optional heading; hide with `hideHeading`. */\n heading?: string;\n hideHeading?: boolean;\n}\n\nexport function DocumentsPanel({\n entityType,\n entityId,\n heading = 'Documents',\n hideHeading = false,\n}: DocumentsPanelProps) {\n const inputRef = useRef<HTMLInputElement>(null);\n const folder = useEntityFolder(entityType, entityId);\n const files = useFolderFiles(folder.data?.id);\n const upload = useDocumentUpload(entityType, entityId);\n const download = useDownloadFile();\n\n const onPick = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const file = e.target.files?.[0];\n if (file) upload.mutate(file);\n e.target.value = '';\n },\n [upload]\n );\n\n const onDownload = async (id: string) => {\n const url = await download.mutateAsync(id);\n if (url) window.open(url, '_blank', 'noopener,noreferrer');\n };\n\n const loading = folder.isLoading || (Boolean(folder.data) && files.isLoading);\n const list = files.data ?? [];\n\n return (\n <div className=\"space-y-3\">\n <div className=\"flex items-center justify-between\">\n {!hideHeading && (\n <h3 className=\"flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <FileText className=\"size-4\" aria-hidden=\"true\" />\n {heading}\n </h3>\n )}\n <div className=\"ml-auto\">\n <input\n ref={inputRef}\n type=\"file\"\n className=\"sr-only\"\n aria-hidden=\"true\"\n tabIndex={-1}\n onChange={onPick}\n />\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"outline\"\n onClick={() => inputRef.current?.click()}\n disabled={upload.isPending}\n >\n <Upload className=\"size-4\" aria-hidden=\"true\" />\n {upload.isPending ? `Uploading ${upload.progress}%` : 'Upload'}\n </Button>\n </div>\n </div>\n\n {upload.isPending && (\n <div\n className=\"h-1.5 w-full overflow-hidden rounded-full bg-bg-sunken\"\n role=\"progressbar\"\n aria-label=\"Upload progress\"\n aria-valuenow={upload.progress}\n aria-valuemin={0}\n aria-valuemax={100}\n >\n <div\n className=\"h-full rounded-full bg-primary motion-safe:transition-[width] motion-safe:duration-200\"\n style={{ width: `${upload.progress}%` }}\n />\n </div>\n )}\n\n {loading ? (\n <div className=\"space-y-2\" aria-busy=\"true\">\n <Skeleton className=\"h-12 w-full rounded-md\" />\n <Skeleton className=\"h-12 w-full rounded-md\" />\n </div>\n ) : files.isError ? (\n <p className=\"text-sm text-status-error-text\">\n Could not load documents.{' '}\n <button\n type=\"button\"\n className=\"underline underline-offset-2\"\n onClick={() => files.refetch()}\n >\n Retry\n </button>\n </p>\n ) : list.length === 0 ? (\n <div className=\"rounded-lg border border-dashed border-border-subtle bg-bg-surface px-4 py-8 text-center\">\n <FileText className=\"mx-auto mb-2 size-6 text-text-secondary\" aria-hidden=\"true\" />\n <p className=\"text-sm text-text-primary\">No documents yet</p>\n <p className=\"mt-0.5 text-xs text-text-secondary\">\n Upload statements, KYC or tax documents for this record.\n </p>\n </div>\n ) : (\n <ul className=\"space-y-2\">\n {list.map((file) => (\n <li key={file.id}>\n <Card>\n <CardContent className=\"flex items-center gap-3 p-3\">\n <div className=\"flex size-9 shrink-0 items-center justify-center rounded-md bg-bg-sunken text-text-secondary\">\n <FileText className=\"size-4\" aria-hidden=\"true\" />\n </div>\n <div className=\"min-w-0 flex-1\">\n <p className=\"truncate text-sm font-medium text-text-primary\">{file.name}</p>\n <p className=\"text-xs text-text-secondary\">\n {formatSize(file.size)} · {formatDate(file.createdAt)}\n </p>\n </div>\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"ghost\"\n aria-label={`Download ${file.name}`}\n disabled={download.isPending}\n onClick={() => onDownload(file.id)}\n >\n <Download className=\"size-4\" aria-hidden=\"true\" />\n </Button>\n </CardContent>\n </Card>\n </li>\n ))}\n </ul>\n )}\n\n {(upload.isError || download.isError) && (\n <p className=\"text-sm text-status-error-text\">\n {upload.error instanceof Error\n ? upload.error.message\n : download.error instanceof Error\n ? 'Could not open the document. Please try again.'\n : 'Something went wrong. Please try again.'}\n </p>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAiCA,IAAM,IAA2B,OAgB3B,IAAc,6CAEd,KAAc,GAAoB,MACtC,gBAAgB,EAAW,KAAK,KAE5B,KAAa,GAAoB,MACrC;CAAC;CAAc;CAAiB;CAAY;AAAQ,GAEhD,KAAY,MAChB;CAAC;CAAc;CAAgB,KAAY;AAAM,GAM7C,KAAmB,GAAoB,MAAiC;CAC5E,IAAM,EAAE,qBAAkB,EAAc,GAClC,IAAS,IAAW,EAAW,GAAY,CAAQ,IAAI;CAC7D,OAAO,EAAS;EACd,UAAU,EAAU,GAAY,KAAY,EAAE;EAC9C,SAAS,EAAQ;EACjB,SAAS,aAQA,MAPY,EACjB,yIAGA,EAAE,YAAY;GAAE,OAAO;GAAK,QAAQ;EAAE,EAAE,GACxC,CACF,GACY,WAAW,QAAQ,MAAM,MAAM,EAAE,SAAS,CAAM,KAAK;CAErE,CAAC;AACH,GAEM,KAAkB,MAAwC;CAC9D,IAAM,EAAE,qBAAkB,EAAc;CACxC,OAAO,EAAS;EACd,UAAU,EAAS,CAAQ;EAC3B,SAAS,EAAQ;EACjB,SAAS,aAUA,MATY,EACjB;;sBAEc,EAAY;;YAG1B;GAAE;GAAU,YAAY;IAAE,OAAO;IAAK,QAAQ;GAAE;EAAE,GAClD,CACF,GACY,iBAAiB;CAEjC,CAAC;AACH;AAMA,SAAS,EACP,GACA,GACA,GACA,GACe;CACf,OAAO,IAAI,SAAe,GAAS,MAAW;EAC5C,IAAM,IAAM,IAAI,eAAe;EAc/B,AAbA,EAAI,KAAK,OAAO,CAAG,GACnB,EAAI,iBAAiB,gBAAgB,CAAW,GAChD,EAAI,OAAO,cAAc,MAAU;GACjC,AAAI,EAAM,oBACR,EAAW,KAAK,MAAO,EAAM,SAAS,EAAM,QAAS,GAAG,CAAC;EAE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Y;KAAQ,CAAA;KAClF,kBAAC,KAAD;MAAG,WAAU;gBAA4B;KAAmB,CAAA;KAC5D,kBAAC,KAAD;MAAG,WAAU;gBAAqC;KAE/C,CAAA;IACA;QAEL,kBAAC,MAAD;IAAI,WAAU;cACX,EAAK,KAAK,MACT,kBAAC,MAAD,EAAA,UACE,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD;KAAa,WAAU;eAAvB;MACE,kBAAC,OAAD;OAAK,WAAU;iBACb,kBAAC,GAAD;QAAU,WAAU;QAAS,eAAY;OAAQ,CAAA;MAC9C,CAAA;MACL,kBAAC,OAAD;OAAK,WAAU;iBAAf,CACE,kBAAC,KAAD;QAAG,WAAU;kBAAkD,EAAK;OAAQ,CAAA,GAC5E,kBAAC,KAAD;QAAG,WAAU;kBAAb;SACG,EAAW,EAAK,IAAI;SAAE;SAAI,EAAW,EAAK,SAAS;QACnD;SACA;;MACL,kBAAC,GAAD;OACE,MAAK;OACL,MAAK;OACL,SAAQ;OACR,cAAY,YAAY,EAAK;OAC7B,UAAU,EAAS;OACnB,eAAe,EAAW,EAAK,EAAE;iBAEjC,kBAAC,GAAD;QAAU,WAAU;QAAS,eAAY;OAAQ,CAAA;MAC3C,CAAA;KACG;OACT,CAAA,EACJ,GAxBK,EAAK,EAwBV,CACL;GACC,CAAA;IAGJ,EAAO,WAAW,EAAS,YAC3B,kBAAC,KAAD;IAAG,WAAU;cACV,EAAO,iBAAiB,QACrB,EAAO,MAAM,UACb,EAAS,iBAAiB,QACxB,mDACA;GACL,CAAA;EAEF;;AAET"}
|
|
1
|
+
{"version":3,"file":"DocumentsPanel.js","names":[],"sources":["../../../../src/brainyrich/components/reuse/DocumentsPanel.tsx"],"sourcesContent":["/**\n * DocumentsPanel — REUSE of `wspace-files-svc` for statement / KYC / tax-doc\n * attachments on Accounts + Households.\n * @module brainyrich/components/reuse/DocumentsPanel\n *\n * A wealth product needs to attach documents (statements, KYC, tax packs) to\n * accounts and households. `wspace-files-svc` has no native entity-owned link on\n * `File`, so we scope documents to an entity via a dedicated, stably-named\n * FOLDER per `(entityType, entityId)` and list its contents. All ops route\n * through the workspace supergraph the MFE already uses.\n *\n * Flow:\n * - resolve folder → `getFolders(filter)` matched by name (created lazily on\n * first upload via `createFolder`); no side-effects on read.\n * - list → `getFilesInFolder(folderId, pagination)`\n * - upload (3-step) → `initiateUpload` → S3 `PUT` (byte-progress) → `completeUpload`\n * reachable by click OR by dropping a file on the zone; both take one file,\n * which is exactly what the single-file upload mutation supports.\n * - download → `getFileDownloadUrl(id, expiresIn)` capped at 21600s to\n * avoid the >604800 fleet bug (S3 7-day cap → 500).\n * - delete → `deleteFile(id)` (RBAC `delete`/`file`, enforced at the\n * gateway) behind a confirm step.\n *\n * Presentational + self-contained: owns its hooks, reads the gateway base URL\n * from `useBrainyRich()`, uses fe-libs/ui primitives + semantic tokens.\n */\n\nimport { useCallback, useRef, useState } from 'react';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport { Download, FileText, Trash2, Upload, UploadCloud } from 'lucide-react';\nimport { Button, Card, CardContent, Skeleton } from '@burdenoff/fe-libs/ui';\n\nimport { useBrainyRich } from '../../providers/BrainyRichProvider';\nimport { formatDate } from '../../pages/_shared';\nimport { ConfirmDialog } from '../ConfirmDialog';\nimport { wspaceFetch, wspaceMutate } from './transport';\n\n// Presigned-URL TTL: cap at 21600s (6h). >604800 (S3 7-day) → INTERNAL_SERVER_ERROR.\nconst DOWNLOAD_URL_TTL_SECONDS = 21600;\n\ninterface FilesFolder {\n id: string;\n name: string;\n}\n\ninterface FilesFile {\n id: string;\n name: string;\n extension: string;\n mimeType: string;\n size: string;\n createdAt: string;\n}\n\nconst FILE_FIELDS = 'id name extension mimeType size createdAt';\n\nconst folderName = (entityType: string, entityId: string) =>\n `BrainyRich · ${entityType} · ${entityId}`;\n\nconst folderKey = (entityType: string, entityId: string) =>\n ['brainyrich', 'entity-folder', entityType, entityId] as const;\n\nconst filesKey = (folderId: string | null | undefined) =>\n ['brainyrich', 'folder-files', folderId ?? 'none'] as const;\n\n// ============================================================================\n// Folder resolution (read-only — no lazy creation here)\n// ============================================================================\n\nconst useEntityFolder = (entityType: string, entityId: string | undefined) => {\n const { apiGatewayUrl } = useBrainyRich();\n const wanted = entityId ? folderName(entityType, entityId) : '';\n return useQuery({\n queryKey: folderKey(entityType, entityId ?? ''),\n enabled: Boolean(entityId),\n queryFn: async () => {\n const data = await wspaceFetch<{ getFolders: { folders: FilesFolder[] } }>(\n `query BraGetFolders($pagination: PaginationInput) {\n getFolders(pagination: $pagination) { folders { id name } }\n }`,\n { pagination: { limit: 200, offset: 0 } },\n apiGatewayUrl\n );\n return data.getFolders.folders.find((f) => f.name === wanted) ?? null;\n },\n });\n};\n\nconst useFolderFiles = (folderId: string | null | undefined) => {\n const { apiGatewayUrl } = useBrainyRich();\n return useQuery({\n queryKey: filesKey(folderId),\n enabled: Boolean(folderId),\n queryFn: async () => {\n const data = await wspaceFetch<{ getFilesInFolder: { files: FilesFile[] } }>(\n `query BraGetFilesInFolder($folderId: ID, $pagination: PaginationInput) {\n getFilesInFolder(folderId: $folderId, pagination: $pagination) {\n files { ${FILE_FIELDS} }\n }\n }`,\n { folderId, pagination: { limit: 100, offset: 0 } },\n apiGatewayUrl\n );\n return data.getFilesInFolder.files;\n },\n });\n};\n\n// ============================================================================\n// Upload (3-step platform flow, with lazy folder creation)\n// ============================================================================\n\nfunction putWithProgress(\n url: string,\n file: File,\n contentType: string,\n onProgress: (percent: number) => void\n): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n const xhr = new XMLHttpRequest();\n xhr.open('PUT', url);\n xhr.setRequestHeader('Content-Type', contentType);\n xhr.upload.onprogress = (event) => {\n if (event.lengthComputable) {\n onProgress(Math.round((event.loaded / event.total) * 100));\n }\n };\n xhr.onload = () =>\n xhr.status >= 200 && xhr.status < 300\n ? resolve()\n : reject(new Error(`File storage rejected the upload (HTTP ${xhr.status}).`));\n xhr.onerror = () => reject(new Error('Network error while uploading the file.'));\n xhr.onabort = () => reject(new Error('The upload was cancelled.'));\n xhr.send(file);\n });\n}\n\nconst useDocumentUpload = (entityType: string, entityId: string) => {\n const { apiGatewayUrl } = useBrainyRich();\n const qc = useQueryClient();\n const [progress, setProgress] = useState(0);\n\n const mutation = useMutation({\n mutationFn: async (file: File) => {\n setProgress(0);\n\n // 0. resolve or create the entity folder\n let folder = await wspaceFetch<{ getFolders: { folders: FilesFolder[] } }>(\n `query BraResolveFolder($pagination: PaginationInput) {\n getFolders(pagination: $pagination) { folders { id name } }\n }`,\n { pagination: { limit: 200, offset: 0 } },\n apiGatewayUrl\n ).then((d) => d.getFolders.folders.find((f) => f.name === folderName(entityType, entityId)));\n\n if (!folder) {\n const created = await wspaceMutate<{ createFolder: FilesFolder }>(\n `mutation BraCreateFolder($input: CreateFolderInput!) {\n createFolder(input: $input) { id name }\n }`,\n {\n input: {\n name: folderName(entityType, entityId),\n description: `Documents attached to ${entityType} ${entityId}.`,\n visibility: 'WORKSPACE',\n },\n },\n apiGatewayUrl\n );\n folder = created.createFolder;\n }\n const folderId = folder.id;\n\n const dotIndex = file.name.lastIndexOf('.');\n const extension = dotIndex > -1 ? file.name.slice(dotIndex + 1) : '';\n const mimeType = file.type || 'application/octet-stream';\n const fileSize = String(file.size);\n\n // 1. initiate\n const initiated = await wspaceMutate<{\n initiateUpload: { uploadUrl: string | null; session: { id: string } };\n }>(\n `mutation BraInitiateUpload($input: InitiateUploadInput!) {\n initiateUpload(input: $input) { uploadUrl session { id } }\n }`,\n {\n input: {\n fileName: file.name,\n extension,\n mimeType,\n fileSize,\n folderId,\n visibility: 'WORKSPACE',\n },\n },\n apiGatewayUrl\n );\n const { uploadUrl } = initiated.initiateUpload;\n const sessionId = initiated.initiateUpload.session.id;\n if (!uploadUrl) throw new Error('The file service did not return an upload URL.');\n\n // 2. PUT the bytes\n await putWithProgress(uploadUrl, file, mimeType, setProgress);\n\n // 3. complete\n await wspaceMutate<{ completeUpload: { fileId: string } }>(\n `mutation BraCompleteUpload($input: CompleteUploadInput!) {\n completeUpload(input: $input) { fileId }\n }`,\n { input: { sessionId, fileSize, folderId } },\n apiGatewayUrl\n );\n setProgress(100);\n return folderId;\n },\n onSuccess: (folderId) => {\n qc.invalidateQueries({ queryKey: folderKey(entityType, entityId) });\n qc.invalidateQueries({ queryKey: filesKey(folderId) });\n },\n });\n\n return { ...mutation, progress };\n};\n\nconst useDownloadFile = () => {\n const { apiGatewayUrl } = useBrainyRich();\n return useMutation({\n mutationFn: async (id: string) => {\n const data = await wspaceFetch<{ getFileDownloadUrl: string }>(\n `query BraGetFileDownloadUrl($id: ID!, $expiresIn: Int) {\n getFileDownloadUrl(id: $id, expiresIn: $expiresIn)\n }`,\n { id, expiresIn: DOWNLOAD_URL_TTL_SECONDS },\n apiGatewayUrl\n );\n return data.getFileDownloadUrl;\n },\n });\n};\n\n/**\n * Remove one document. `deleteFile(id: ID!): Boolean!` is a real mutation on the\n * files subgraph of the same workspace supergraph; the gateway enforces its\n * `delete`/`file` @rbac directive, so a caller without the right gets a GraphQL\n * error surfaced below rather than a silently ignored click.\n */\nconst useDeleteFile = (folderId: string | null | undefined) => {\n const { apiGatewayUrl } = useBrainyRich();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: async (id: string) => {\n const data = await wspaceMutate<{ deleteFile: boolean }>(\n `mutation BraDeleteFile($id: ID!) { deleteFile(id: $id) }`,\n { id },\n apiGatewayUrl\n );\n return data.deleteFile;\n },\n onSuccess: () => qc.invalidateQueries({ queryKey: filesKey(folderId) }),\n });\n};\n\n// ============================================================================\n// Component\n// ============================================================================\n\nconst formatSize = (bytes: string): string => {\n const n = Number(bytes);\n if (!Number.isFinite(n) || n <= 0) return '—';\n if (n < 1024) return `${n} B`;\n if (n < 1024 * 1024) return `${(n / 1024).toFixed(0)} KB`;\n return `${(n / (1024 * 1024)).toFixed(1)} MB`;\n};\n\nexport interface DocumentsPanelProps {\n /** Polymorphic entity type, e.g. \"brainyrich-account\" | \"brainyrich-household\". */\n entityType: string;\n /** The bra entity's id (an ID scalar). */\n entityId: string;\n /** Optional heading; hide with `hideHeading`. */\n heading?: string;\n hideHeading?: boolean;\n}\n\nexport function DocumentsPanel({\n entityType,\n entityId,\n heading = 'Documents',\n hideHeading = false,\n}: DocumentsPanelProps) {\n const inputRef = useRef<HTMLInputElement>(null);\n const folder = useEntityFolder(entityType, entityId);\n const files = useFolderFiles(folder.data?.id);\n const upload = useDocumentUpload(entityType, entityId);\n const download = useDownloadFile();\n const remove = useDeleteFile(folder.data?.id);\n\n const [dragActive, setDragActive] = useState(false);\n const [fileToDelete, setFileToDelete] = useState<FilesFile | null>(null);\n\n const onPick = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const file = e.target.files?.[0];\n if (file) upload.mutate(file);\n e.target.value = '';\n },\n [upload]\n );\n\n // The upload mutation handles one file per call, so the drop zone accepts one\n // — matching the picker, which is deliberately not `multiple`.\n const onDrop = useCallback(\n (e: React.DragEvent<HTMLElement>) => {\n e.preventDefault();\n setDragActive(false);\n if (upload.isPending) return;\n const file = e.dataTransfer.files?.[0];\n if (file) upload.mutate(file);\n },\n [upload]\n );\n\n const onDownload = async (id: string) => {\n const url = await download.mutateAsync(id);\n if (url) window.open(url, '_blank', 'noopener,noreferrer');\n };\n\n const loading = folder.isLoading || (Boolean(folder.data) && files.isLoading);\n const list = files.data ?? [];\n\n return (\n <div className=\"space-y-3\">\n <div className=\"flex items-center justify-between\">\n {!hideHeading && (\n <h3 className=\"flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <FileText className=\"size-4\" aria-hidden=\"true\" />\n {heading}\n </h3>\n )}\n <div className=\"ml-auto\">\n <input\n ref={inputRef}\n type=\"file\"\n className=\"sr-only\"\n aria-hidden=\"true\"\n tabIndex={-1}\n onChange={onPick}\n />\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"outline\"\n onClick={() => inputRef.current?.click()}\n disabled={upload.isPending}\n >\n <Upload className=\"size-4\" aria-hidden=\"true\" />\n {upload.isPending ? `Uploading ${upload.progress}%` : 'Upload'}\n </Button>\n </div>\n </div>\n\n {upload.isPending && (\n <div\n className=\"h-1.5 w-full overflow-hidden rounded-full bg-bg-sunken\"\n role=\"progressbar\"\n aria-label=\"Upload progress\"\n aria-valuenow={upload.progress}\n aria-valuemin={0}\n aria-valuemax={100}\n >\n <div\n className=\"h-full rounded-full bg-primary motion-safe:transition-[width] motion-safe:duration-200\"\n style={{ width: `${upload.progress}%` }}\n />\n </div>\n )}\n\n {/* Drop target — same single-file upload path as the picker button */}\n <button\n type=\"button\"\n onClick={() => inputRef.current?.click()}\n disabled={upload.isPending}\n onDragOver={(e) => {\n e.preventDefault();\n if (!upload.isPending) setDragActive(true);\n }}\n onDragLeave={() => setDragActive(false)}\n onDrop={onDrop}\n className={`w-full rounded-lg border border-dashed px-4 py-8 text-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-action-primary-border)] disabled:cursor-not-allowed disabled:opacity-60 ${\n dragActive\n ? 'border-[var(--color-action-primary-border)] bg-bg-elevated'\n : 'border-border-subtle bg-bg-surface hover:border-[var(--color-action-primary-border)]'\n }`}\n >\n <UploadCloud className=\"mx-auto mb-2 size-6 text-text-secondary\" aria-hidden=\"true\" />\n <span className=\"block text-sm text-text-primary\">\n Drop a statement, KYC or tax document here\n </span>\n <span className=\"mt-0.5 block text-xs text-text-secondary\">\n or click to choose one file\n </span>\n </button>\n\n {loading ? (\n <div className=\"space-y-2\" aria-busy=\"true\">\n <Skeleton className=\"h-12 w-full rounded-md\" />\n <Skeleton className=\"h-12 w-full rounded-md\" />\n </div>\n ) : files.isError ? (\n <p className=\"text-sm text-status-error-text\">\n Could not load documents.{' '}\n <button\n type=\"button\"\n className=\"underline underline-offset-2\"\n onClick={() => files.refetch()}\n >\n Retry\n </button>\n </p>\n ) : list.length === 0 ? (\n <p className=\"text-center text-xs text-text-secondary\">\n No documents attached to this record yet.\n </p>\n ) : (\n <ul className=\"space-y-2\">\n {list.map((file) => (\n <li key={file.id}>\n <Card>\n <CardContent className=\"flex items-center gap-3 p-3\">\n <div className=\"flex size-9 shrink-0 items-center justify-center rounded-md bg-bg-sunken text-text-secondary\">\n <FileText className=\"size-4\" aria-hidden=\"true\" />\n </div>\n <div className=\"min-w-0 flex-1\">\n <p className=\"truncate text-sm font-medium text-text-primary\">{file.name}</p>\n <p className=\"text-xs text-text-secondary\">\n {formatSize(file.size)} · {formatDate(file.createdAt)}\n </p>\n </div>\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"ghost\"\n aria-label={`Download ${file.name}`}\n disabled={download.isPending}\n onClick={() => onDownload(file.id)}\n >\n <Download className=\"size-4\" aria-hidden=\"true\" />\n </Button>\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"ghost\"\n className=\"text-status-error-text hover:text-status-error-text\"\n aria-label={`Delete ${file.name}`}\n disabled={remove.isPending}\n onClick={() => setFileToDelete(file)}\n >\n <Trash2 className=\"size-4\" aria-hidden=\"true\" />\n </Button>\n </CardContent>\n </Card>\n </li>\n ))}\n </ul>\n )}\n\n {(upload.isError || download.isError || remove.isError) && (\n <p className=\"text-sm text-status-error-text\">\n {upload.error instanceof Error\n ? upload.error.message\n : remove.error instanceof Error\n ? `Could not delete the document. ${remove.error.message}`\n : download.error instanceof Error\n ? 'Could not open the document. Please try again.'\n : 'Something went wrong. Please try again.'}\n </p>\n )}\n\n <ConfirmDialog\n open={fileToDelete !== null}\n onOpenChange={(open) => {\n if (!open) setFileToDelete(null);\n }}\n title=\"Delete this document?\"\n description={\n fileToDelete\n ? `“${fileToDelete.name}” will be removed from this record. This cannot be undone.`\n : undefined\n }\n confirmLabel=\"Delete\"\n pendingLabel=\"Deleting…\"\n destructive\n pending={remove.isPending}\n onConfirm={() => {\n if (!fileToDelete) return;\n remove.mutate(fileToDelete.id, { onSuccess: () => setFileToDelete(null) });\n }}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAsCA,IAAM,IAA2B,OAgB3B,I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