@sonatel-os/strapi-plugin-split 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,937 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const designSystem = require("@strapi/design-system");
5
+ const icons = require("@strapi/icons");
6
+ const admin = require("@strapi/strapi/admin");
7
+ const reactRouterDom = require("react-router-dom");
8
+ const reactIntl = require("react-intl");
9
+ const styledComponents = require("styled-components");
10
+ const index = require("./index-oyRhs5fN.js");
11
+ const api = require("./api-cwZGoKZx.js");
12
+ const react = require("react");
13
+ const getTranslation = (id) => `${index.PLUGIN_ID}.${id}`;
14
+ const Head = styledComponents.styled.header`
15
+ position: relative;
16
+ padding: 4.8rem 5.6rem 3.2rem;
17
+ &::before {
18
+ content: '';
19
+ position: absolute;
20
+ inset: -20% -10% auto auto;
21
+ width: 46rem;
22
+ height: 46rem;
23
+ border-radius: 50%;
24
+ background: radial-gradient(circle, rgba(255, 121, 0, 0.1) 0%, rgba(255, 121, 0, 0) 65%);
25
+ pointer-events: none;
26
+ }
27
+ `;
28
+ const Title = styledComponents.styled(designSystem.Typography)`
29
+ font-size: 3.2rem;
30
+ line-height: 1.1;
31
+ font-weight: 700;
32
+ letter-spacing: -0.03em;
33
+ `;
34
+ const Content = styledComponents.styled(designSystem.Box)`
35
+ padding: 0 5.6rem 8rem;
36
+ > * {
37
+ transition: opacity 320ms ${api.SPRING};
38
+ }
39
+ `;
40
+ const PageShell = ({
41
+ title,
42
+ subtitle,
43
+ primaryAction,
44
+ secondaryAction,
45
+ navigationAction,
46
+ eyebrow = "Split",
47
+ intro,
48
+ children
49
+ }) => {
50
+ return /* @__PURE__ */ jsxRuntime.jsxs(admin.Page.Main, { children: [
51
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Title, { children: `Split · ${title}` }),
52
+ /* @__PURE__ */ jsxRuntime.jsxs(Head, { children: [
53
+ navigationAction ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingBottom: 4, children: navigationAction }) : null,
54
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "flex-end", gap: 6, wrap: "wrap", children: [
55
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { minWidth: 0 }, children: [
56
+ /* @__PURE__ */ jsxRuntime.jsx(api.Eyebrow, { paddingBottom: 2, children: eyebrow }),
57
+ /* @__PURE__ */ jsxRuntime.jsx(Title, { tag: "h1", children: title }),
58
+ subtitle ? /* @__PURE__ */ jsxRuntime.jsx(
59
+ designSystem.Typography,
60
+ {
61
+ variant: "omega",
62
+ textColor: "neutral600",
63
+ tag: "p",
64
+ paddingTop: 2,
65
+ style: { maxWidth: "70ch" },
66
+ children: subtitle
67
+ }
68
+ ) : null
69
+ ] }),
70
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", wrap: "wrap", children: [
71
+ secondaryAction,
72
+ primaryAction
73
+ ] })
74
+ ] })
75
+ ] }),
76
+ /* @__PURE__ */ jsxRuntime.jsxs(Content, { children: [
77
+ intro ? /* @__PURE__ */ jsxRuntime.jsx(api.Intro, { ...intro }) : null,
78
+ children
79
+ ] })
80
+ ] });
81
+ };
82
+ const DataTable = ({ columns, rows, onRow, empty }) => {
83
+ if (rows.length === 0) return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral600", children: empty });
84
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Table, { colCount: columns.length, rowCount: rows.length, children: [
85
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Thead, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tr, { children: columns.map((c) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: c.label }) }, c.key)) }) }),
86
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: rows.map((row, i) => /* @__PURE__ */ jsxRuntime.jsx(
87
+ designSystem.Tr,
88
+ {
89
+ onClick: onRow ? () => onRow(row) : void 0,
90
+ style: onRow ? { cursor: "pointer" } : void 0,
91
+ children: columns.map((c) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: c.render(row) }, c.key))
92
+ },
93
+ row.id ?? i
94
+ )) })
95
+ ] });
96
+ };
97
+ const Cell = ({ main, sub, strong, tone }) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
98
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: strong ? "semiBold" : void 0, textColor: tone, children: main ?? "—" }),
99
+ sub ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: sub }) : null
100
+ ] });
101
+ const fmtDateTime = (value, locale) => {
102
+ if (!value) return "—";
103
+ try {
104
+ return new Intl.DateTimeFormat(locale ?? void 0, {
105
+ dateStyle: "medium",
106
+ timeStyle: "short"
107
+ }).format(new Date(value));
108
+ } catch {
109
+ return String(value);
110
+ }
111
+ };
112
+ const fmtNumber = (value, locale) => new Intl.NumberFormat(locale ?? void 0).format(Number(value ?? 0));
113
+ const fmtSigned = (value, locale) => {
114
+ const n = Number(value ?? 0);
115
+ const digits = fmtNumber(Math.abs(n), locale);
116
+ return n > 0 ? `+${digits}` : n < 0 ? `−${digits}` : digits;
117
+ };
118
+ const errorMessage = (err) => err?.data?.error?.message ?? err?.response?.data?.error?.message ?? err?.error?.message ?? err?.message ?? "Une erreur est survenue.";
119
+ const ACCENT = "#FF7900";
120
+ const GREEN = "#328048";
121
+ const BLUE = "#4945FF";
122
+ const AMBER = "#D9822F";
123
+ const Dashboard = () => {
124
+ const { locale } = reactIntl.useIntl();
125
+ const { data, isLoading, isError } = api.useGetDashboardQuery();
126
+ if (isLoading) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Loading, {});
127
+ if (isError || !data) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Error, {});
128
+ const n = (value) => fmtNumber(value, locale);
129
+ const { people, groups, expenses, settlements, days } = data;
130
+ const settledMax = Math.max(1, ...settlements.byMethod.map((m) => m.total));
131
+ const tiles = [
132
+ {
133
+ label: "People",
134
+ value: n(people.total),
135
+ hint: `${n(people.active)} active, ${n(people.new)} new in ${days} days`,
136
+ accent: BLUE,
137
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.User, {})
138
+ },
139
+ {
140
+ label: "Groups",
141
+ value: n(groups.total),
142
+ hint: `${n(groups.new)} new in ${days} days, ${n(groups.archived)} archived`,
143
+ accent: ACCENT,
144
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Stack, {})
145
+ },
146
+ {
147
+ label: "Spent together",
148
+ value: n(expenses.total),
149
+ hint: `${n(expenses.count)} expenses, ${n(expenses.recent.total)} in ${days} days`,
150
+ accent: AMBER,
151
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PriceTag, {})
152
+ },
153
+ {
154
+ label: "Settled",
155
+ value: n(settlements.confirmed.total),
156
+ hint: `${n(settlements.confirmed.count)} confirmed, ${n(settlements.pending.count)} awaiting confirmation`,
157
+ accent: GREEN,
158
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowsCounterClockwise, {})
159
+ }
160
+ ];
161
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index.PERMISSIONS.dashboardRead, children: /* @__PURE__ */ jsxRuntime.jsxs(
162
+ PageShell,
163
+ {
164
+ title: "Dashboard",
165
+ subtitle: "Amounts are in the currency's smallest unit, as the ledger stores them.",
166
+ children: [
167
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Root, { gap: 5, children: tiles.map((tile, i) => /* @__PURE__ */ jsxRuntime.jsx(
168
+ designSystem.Grid.Item,
169
+ {
170
+ col: 3,
171
+ s: 6,
172
+ xs: 12,
173
+ direction: "column",
174
+ alignItems: "stretch",
175
+ children: /* @__PURE__ */ jsxRuntime.jsx(api.StatTile, { ...tile, index: i })
176
+ },
177
+ tile.label
178
+ )) }),
179
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(api.Section, { title: "How debts get settled", help: "Confirmed settlements, by method.", index: 4, children: [
180
+ /* @__PURE__ */ jsxRuntime.jsx(
181
+ DataTable,
182
+ {
183
+ empty: "Nothing has been settled yet.",
184
+ rows: settlements.byMethod.map((m) => ({ ...m, id: m.method })),
185
+ columns: [
186
+ { key: "method", label: "Method", render: (m) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: m.method, strong: true }) },
187
+ { key: "count", label: "Settlements", render: (m) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: n(m.count) }) },
188
+ { key: "total", label: "Amount", render: (m) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: n(m.total), strong: true }) },
189
+ {
190
+ key: "share",
191
+ label: "Share",
192
+ render: (m) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { minWidth: 160 }, children: /* @__PURE__ */ jsxRuntime.jsx(api.Bar, { value: m.total, max: settledMax }) })
193
+ }
194
+ ]
195
+ }
196
+ ),
197
+ settlements.pending.count > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "neutral600", tag: "p", paddingTop: 4, children: [
198
+ n(settlements.pending.total),
199
+ " declared in ",
200
+ n(settlements.pending.count),
201
+ " ",
202
+ "settlements still wait for the receiver to confirm."
203
+ ] }) : null
204
+ ] }) })
205
+ ]
206
+ }
207
+ ) });
208
+ };
209
+ const Pager = ({ meta, onPage }) => {
210
+ if (!meta || meta.pageCount <= 1) return null;
211
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", children: [
212
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: [
213
+ "Page ",
214
+ meta.page,
215
+ " / ",
216
+ meta.pageCount,
217
+ " · ",
218
+ meta.total,
219
+ " items"
220
+ ] }),
221
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
222
+ /* @__PURE__ */ jsxRuntime.jsx(
223
+ designSystem.Button,
224
+ {
225
+ size: "S",
226
+ variant: "tertiary",
227
+ disabled: meta.page <= 1,
228
+ onClick: () => onPage(meta.page - 1),
229
+ children: "Previous"
230
+ }
231
+ ),
232
+ /* @__PURE__ */ jsxRuntime.jsx(
233
+ designSystem.Button,
234
+ {
235
+ size: "S",
236
+ variant: "tertiary",
237
+ disabled: meta.page >= meta.pageCount,
238
+ onClick: () => onPage(meta.page + 1),
239
+ children: "Next"
240
+ }
241
+ )
242
+ ] })
243
+ ] });
244
+ };
245
+ const PAGE_SIZE = 25;
246
+ const ListPage = ({
247
+ title,
248
+ subtitle,
249
+ permissions,
250
+ useQuery,
251
+ searchLabel,
252
+ searchParam = "q",
253
+ filters,
254
+ columns,
255
+ onRow,
256
+ empty
257
+ }) => {
258
+ const [q, setQ] = react.useState("");
259
+ const [extra, setExtra] = react.useState({});
260
+ const [page, setPage] = react.useState(1);
261
+ const { data, isLoading, isError } = useQuery({
262
+ [searchParam]: q || void 0,
263
+ ...extra,
264
+ page,
265
+ pageSize: PAGE_SIZE
266
+ });
267
+ const set = (patch) => {
268
+ setExtra((current) => ({ ...current, ...patch }));
269
+ setPage(1);
270
+ };
271
+ if (isError) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Error, {});
272
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions, children: /* @__PURE__ */ jsxRuntime.jsxs(PageShell, { title, subtitle, children: [
273
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, paddingBottom: 4, wrap: "wrap", children: [
274
+ searchLabel ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.SearchForm, { onSubmit: (e) => e.preventDefault(), children: /* @__PURE__ */ jsxRuntime.jsx(
275
+ designSystem.Searchbar,
276
+ {
277
+ name: "q",
278
+ value: q,
279
+ onChange: (e) => {
280
+ setQ(e.target.value);
281
+ setPage(1);
282
+ },
283
+ onClear: () => setQ(""),
284
+ clearLabel: "Clear",
285
+ placeholder: searchLabel,
286
+ children: searchLabel
287
+ }
288
+ ) }) : null,
289
+ filters ? filters(extra, set) : null
290
+ ] }),
291
+ /* @__PURE__ */ jsxRuntime.jsxs(api.Section, { children: [
292
+ isLoading ? /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Loading, {}) : /* @__PURE__ */ jsxRuntime.jsx(DataTable, { columns, rows: data?.data ?? [], onRow, empty }),
293
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsx(Pager, { meta: data?.meta?.pagination, onPage: setPage }) })
294
+ ] })
295
+ ] }) });
296
+ };
297
+ const GroupsPage = () => {
298
+ const { locale } = reactIntl.useIntl();
299
+ const navigate = reactRouterDom.useNavigate();
300
+ return /* @__PURE__ */ jsxRuntime.jsx(
301
+ ListPage,
302
+ {
303
+ title: "Groups",
304
+ subtitle: "Find a group by its name or its invite code, then open its books.",
305
+ permissions: index.PERMISSIONS.groupsRead,
306
+ useQuery: api.useGetGroupsQuery,
307
+ searchLabel: "Name or invite code",
308
+ empty: "No group matches.",
309
+ onRow: (g) => navigate(g.id),
310
+ columns: [
311
+ { key: "name", label: "Group", render: (g) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: g.name, strong: true }) },
312
+ {
313
+ key: "code",
314
+ label: "Invite code",
315
+ render: (g) => /* @__PURE__ */ jsxRuntime.jsx(api.Mono, { variant: "pi", children: g.inviteCode })
316
+ },
317
+ {
318
+ key: "status",
319
+ label: "Status",
320
+ render: (g) => /* @__PURE__ */ jsxRuntime.jsx(api.StatusBadge, { status: g.isArchived ? "archived" : "active" })
321
+ },
322
+ {
323
+ key: "last",
324
+ label: "Last activity",
325
+ render: (g) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: fmtDateTime(g.lastActivityAt, locale), tone: "neutral600" })
326
+ }
327
+ ]
328
+ }
329
+ );
330
+ };
331
+ const toneOf = (balance) => balance > 0 ? "success600" : balance < 0 ? "warning600" : "neutral600";
332
+ const GroupDetailPage = () => {
333
+ const { id } = reactRouterDom.useParams();
334
+ const { locale } = reactIntl.useIntl();
335
+ const navigate = reactRouterDom.useNavigate();
336
+ const { toggleNotification } = admin.useNotification();
337
+ const { allowedActions } = admin.useRBAC({ archive: index.PERMISSIONS.groupsWrite });
338
+ const { data: group, isLoading, isError } = api.useGetGroupQuery(id);
339
+ const [archive, { isLoading: archiving }] = api.useArchiveGroupMutation();
340
+ if (isLoading) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Loading, {});
341
+ if (isError || !group) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Error, {});
342
+ const n = (value) => fmtNumber(value, locale);
343
+ const when = (value) => fmtDateTime(value, locale);
344
+ const onArchive = async () => {
345
+ try {
346
+ await archive(id).unwrap();
347
+ toggleNotification({
348
+ type: "success",
349
+ message: "Group archived. Nothing can be written in it any more."
350
+ });
351
+ } catch (err) {
352
+ toggleNotification({ type: "danger", message: errorMessage(err) });
353
+ }
354
+ };
355
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index.PERMISSIONS.groupsRead, children: /* @__PURE__ */ jsxRuntime.jsxs(
356
+ PageShell,
357
+ {
358
+ title: group.name,
359
+ eyebrow: `Group · ${group.inviteCode}`,
360
+ subtitle: `Created ${when(group.createdAt)} · last activity ${when(group.lastActivityAt)}`,
361
+ navigationAction: /* @__PURE__ */ jsxRuntime.jsx(
362
+ designSystem.Button,
363
+ {
364
+ variant: "ghost",
365
+ size: "S",
366
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, {}),
367
+ onClick: () => navigate("..", { relative: "path" }),
368
+ children: "Groups"
369
+ }
370
+ ),
371
+ primaryAction: group.isArchived ? /* @__PURE__ */ jsxRuntime.jsx(api.StatusBadge, { status: "archived" }) : allowedActions.canArchive ? /* @__PURE__ */ jsxRuntime.jsx(
372
+ designSystem.Button,
373
+ {
374
+ variant: "danger-light",
375
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Archive, {}),
376
+ loading: archiving,
377
+ onClick: onArchive,
378
+ children: "Archive"
379
+ }
380
+ ) : null,
381
+ children: [
382
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Root, { gap: 5, children: [
383
+ { label: "Members", value: n(group.memberCount) },
384
+ { label: "Expenses", value: n(group.expenseCount) },
385
+ { label: "Spent together", value: n(group.total) }
386
+ ].map((tile, i) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 4, s: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxRuntime.jsx(api.StatTile, { ...tile, index: i }) }, tile.label)) }),
387
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 6, paddingTop: 6, children: [
388
+ /* @__PURE__ */ jsxRuntime.jsx(
389
+ api.Section,
390
+ {
391
+ title: "Members and balances",
392
+ help: "Above zero is owed money, below zero owes money. Phone numbers are masked.",
393
+ index: 3,
394
+ children: /* @__PURE__ */ jsxRuntime.jsx(
395
+ DataTable,
396
+ {
397
+ empty: "Nobody.",
398
+ rows: group.members,
399
+ columns: [
400
+ {
401
+ key: "name",
402
+ label: "Member",
403
+ render: (m) => /* @__PURE__ */ jsxRuntime.jsx(
404
+ Cell,
405
+ {
406
+ main: m.displayName,
407
+ sub: m.role === "owner" ? "Created the group" : null,
408
+ strong: true
409
+ }
410
+ )
411
+ },
412
+ {
413
+ key: "phone",
414
+ label: "Phone",
415
+ render: (m) => /* @__PURE__ */ jsxRuntime.jsx(api.Mono, { variant: "pi", children: m.phone ?? "—" })
416
+ },
417
+ {
418
+ key: "state",
419
+ label: "State",
420
+ render: (m) => /* @__PURE__ */ jsxRuntime.jsx(
421
+ Cell,
422
+ {
423
+ main: m.hasLeft ? "Left" : m.isRegistered ? "Uses the app" : "Added by name",
424
+ tone: "neutral600"
425
+ }
426
+ )
427
+ },
428
+ {
429
+ key: "balance",
430
+ label: "Balance",
431
+ render: (m) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: fmtSigned(m.balance, locale), tone: toneOf(m.balance), strong: true })
432
+ }
433
+ ]
434
+ }
435
+ )
436
+ }
437
+ ),
438
+ /* @__PURE__ */ jsxRuntime.jsx(
439
+ api.Section,
440
+ {
441
+ title: "What would settle it",
442
+ help: "The fewest payments that bring everyone to zero.",
443
+ index: 4,
444
+ children: /* @__PURE__ */ jsxRuntime.jsx(
445
+ DataTable,
446
+ {
447
+ empty: "Everyone is even.",
448
+ rows: group.payments.map((p, i) => ({ ...p, id: i })),
449
+ columns: [
450
+ { key: "from", label: "Pays", render: (p) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: p.from.displayName }) },
451
+ { key: "to", label: "To", render: (p) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: p.to.displayName }) },
452
+ {
453
+ key: "amount",
454
+ label: "Amount",
455
+ render: (p) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: n(p.amount), strong: true })
456
+ }
457
+ ]
458
+ }
459
+ )
460
+ }
461
+ ),
462
+ /* @__PURE__ */ jsxRuntime.jsx(api.Section, { title: "Settlements", help: "The most recent fifty.", index: 5, children: /* @__PURE__ */ jsxRuntime.jsx(
463
+ DataTable,
464
+ {
465
+ empty: "No settlement yet.",
466
+ rows: group.settlements,
467
+ columns: [
468
+ {
469
+ key: "when",
470
+ label: "Declared",
471
+ render: (s) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: when(s.declaredAt), tone: "neutral600" })
472
+ },
473
+ {
474
+ key: "who",
475
+ label: "From → to",
476
+ render: (s) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: `${s.from.displayName} → ${s.to.displayName}` })
477
+ },
478
+ {
479
+ key: "amount",
480
+ label: "Amount",
481
+ render: (s) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: n(s.amount), sub: s.method, strong: true })
482
+ },
483
+ {
484
+ key: "status",
485
+ label: "Status",
486
+ render: (s) => /* @__PURE__ */ jsxRuntime.jsx(api.StatusBadge, { status: s.status })
487
+ },
488
+ {
489
+ key: "ref",
490
+ label: "Reference",
491
+ render: (s) => /* @__PURE__ */ jsxRuntime.jsx(api.Mono, { variant: "pi", children: s.reference ?? "—" })
492
+ }
493
+ ]
494
+ }
495
+ ) }),
496
+ /* @__PURE__ */ jsxRuntime.jsx(api.Section, { title: "Expenses", help: "The most recent fifty.", index: 6, children: /* @__PURE__ */ jsxRuntime.jsx(
497
+ DataTable,
498
+ {
499
+ empty: "No expense yet.",
500
+ rows: group.expenses,
501
+ columns: [
502
+ {
503
+ key: "when",
504
+ label: "Spent",
505
+ render: (e) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: when(e.spentAt), tone: "neutral600" })
506
+ },
507
+ {
508
+ key: "label",
509
+ label: "What",
510
+ render: (e) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: e.label, sub: e.category, strong: true })
511
+ },
512
+ {
513
+ key: "payer",
514
+ label: "Paid by",
515
+ render: (e) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: e.paidBy.displayName })
516
+ },
517
+ {
518
+ key: "amount",
519
+ label: "Amount",
520
+ render: (e) => /* @__PURE__ */ jsxRuntime.jsx(
521
+ Cell,
522
+ {
523
+ main: n(e.amount),
524
+ sub: `${e.mode}, ${e.shares.length} taking part`,
525
+ strong: true
526
+ }
527
+ )
528
+ }
529
+ ]
530
+ }
531
+ ) }),
532
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, {})
533
+ ] })
534
+ ]
535
+ }
536
+ ) });
537
+ };
538
+ const PeoplePage = () => {
539
+ const { locale } = reactIntl.useIntl();
540
+ const navigate = reactRouterDom.useNavigate();
541
+ return /* @__PURE__ */ jsxRuntime.jsx(
542
+ ListPage,
543
+ {
544
+ title: "People",
545
+ subtitle: "Find someone by name or by phone number. Numbers stay masked in lists.",
546
+ permissions: index.PERMISSIONS.peopleRead,
547
+ useQuery: api.useGetPeopleQuery,
548
+ searchLabel: "Name or phone",
549
+ empty: "Nobody matches.",
550
+ onRow: (p) => navigate(p.id),
551
+ columns: [
552
+ {
553
+ key: "name",
554
+ label: "Person",
555
+ render: (p) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: p.displayName ?? "No name yet", strong: true })
556
+ },
557
+ { key: "phone", label: "Phone", render: (p) => /* @__PURE__ */ jsxRuntime.jsx(api.Mono, { variant: "pi", children: p.phone ?? "—" }) },
558
+ {
559
+ key: "status",
560
+ label: "Status",
561
+ render: (p) => /* @__PURE__ */ jsxRuntime.jsx(api.StatusBadge, { status: p.isActive ? "active" : "inactive" })
562
+ },
563
+ {
564
+ key: "seen",
565
+ label: "Last seen",
566
+ render: (p) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: fmtDateTime(p.lastActiveAt, locale), tone: "neutral600" })
567
+ }
568
+ ]
569
+ }
570
+ );
571
+ };
572
+ const PersonDetailPage = () => {
573
+ const { id } = reactRouterDom.useParams();
574
+ const { locale } = reactIntl.useIntl();
575
+ const navigate = reactRouterDom.useNavigate();
576
+ const { toggleNotification } = admin.useNotification();
577
+ const { allowedActions } = admin.useRBAC({
578
+ reveal: index.PERMISSIONS.peoplePhone,
579
+ write: index.PERMISSIONS.peopleWrite
580
+ });
581
+ const { data: person, isLoading, isError } = api.useGetPersonQuery(id);
582
+ const [reveal, { isLoading: revealing }] = api.useRevealPhoneMutation();
583
+ const [setActive, { isLoading: saving }] = api.useSetPersonActiveMutation();
584
+ const [fullPhone, setFullPhone] = react.useState(null);
585
+ if (isLoading) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Loading, {});
586
+ if (isError || !person) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Error, {});
587
+ const attempt = async (work, done) => {
588
+ try {
589
+ const result = await work().unwrap();
590
+ if (done) toggleNotification({ type: "success", message: done });
591
+ return result;
592
+ } catch (err) {
593
+ toggleNotification({ type: "danger", message: errorMessage(err) });
594
+ return null;
595
+ }
596
+ };
597
+ const onReveal = async () => setFullPhone((await attempt(() => reveal(id)))?.phone ?? null);
598
+ const onToggle = () => attempt(
599
+ () => setActive({ id, isActive: !person.isActive }),
600
+ person.isActive ? "Deactivated: this person can no longer use the ledger." : "Reactivated."
601
+ );
602
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index.PERMISSIONS.peopleRead, children: /* @__PURE__ */ jsxRuntime.jsx(
603
+ PageShell,
604
+ {
605
+ title: person.displayName ?? "No name yet",
606
+ eyebrow: "Person",
607
+ subtitle: `First seen ${fmtDateTime(person.createdAt, locale)} · last seen ${fmtDateTime(person.lastActiveAt, locale)}`,
608
+ navigationAction: /* @__PURE__ */ jsxRuntime.jsx(
609
+ designSystem.Button,
610
+ {
611
+ variant: "ghost",
612
+ size: "S",
613
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, {}),
614
+ onClick: () => navigate("..", { relative: "path" }),
615
+ children: "People"
616
+ }
617
+ ),
618
+ primaryAction: allowedActions.canWrite ? /* @__PURE__ */ jsxRuntime.jsx(
619
+ designSystem.Button,
620
+ {
621
+ variant: person.isActive ? "danger-light" : "secondary",
622
+ loading: saving,
623
+ onClick: onToggle,
624
+ children: person.isActive ? "Deactivate" : "Reactivate"
625
+ }
626
+ ) : null,
627
+ secondaryAction: /* @__PURE__ */ jsxRuntime.jsx(api.StatusBadge, { status: person.isActive ? "active" : "inactive" }),
628
+ children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
629
+ /* @__PURE__ */ jsxRuntime.jsx(
630
+ api.Section,
631
+ {
632
+ title: "Phone number",
633
+ help: "Masked by default. Revealing it is written in the server log with your account.",
634
+ children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 4, alignItems: "center", children: [
635
+ /* @__PURE__ */ jsxRuntime.jsx(api.Mono, { variant: "delta", fontWeight: "bold", children: fullPhone ?? person.phone ?? "—" }),
636
+ allowedActions.canReveal && person.phone && !fullPhone ? /* @__PURE__ */ jsxRuntime.jsx(
637
+ designSystem.Button,
638
+ {
639
+ variant: "tertiary",
640
+ size: "S",
641
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Eye, {}),
642
+ loading: revealing,
643
+ onClick: onReveal,
644
+ children: "Reveal"
645
+ }
646
+ ) : null
647
+ ] })
648
+ }
649
+ ),
650
+ /* @__PURE__ */ jsxRuntime.jsx(api.Section, { title: "Groups", index: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
651
+ DataTable,
652
+ {
653
+ empty: "Not in any group.",
654
+ rows: person.groups,
655
+ onRow: (g) => navigate(`../../groups/${g.id}`, { relative: "path" }),
656
+ columns: [
657
+ { key: "name", label: "Group", render: (g) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: g.name, strong: true }) },
658
+ {
659
+ key: "role",
660
+ label: "Seat",
661
+ render: (g) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: g.hasLeft ? "Left" : g.role === "owner" ? "Created it" : "Member" })
662
+ },
663
+ {
664
+ key: "status",
665
+ label: "Status",
666
+ render: (g) => /* @__PURE__ */ jsxRuntime.jsx(api.StatusBadge, { status: g.isArchived ? "archived" : "active" })
667
+ }
668
+ ]
669
+ }
670
+ ) })
671
+ ] })
672
+ }
673
+ ) });
674
+ };
675
+ const STATUSES = ["pending", "confirmed", "rejected", "cancelled"];
676
+ const SettlementsPage = () => {
677
+ const { locale } = reactIntl.useIntl();
678
+ const navigate = reactRouterDom.useNavigate();
679
+ return /* @__PURE__ */ jsxRuntime.jsx(
680
+ ListPage,
681
+ {
682
+ title: "Settlements",
683
+ subtitle: "Look a payment up by the reference the customer has: a mobile-money transaction id, for instance.",
684
+ permissions: index.PERMISSIONS.settlementsRead,
685
+ useQuery: api.useGetSettlementsQuery,
686
+ searchLabel: "Payment reference",
687
+ searchParam: "reference",
688
+ empty: "No settlement matches.",
689
+ onRow: (s) => s.group ? navigate(`../groups/${s.group.id}`, { relative: "path" }) : null,
690
+ filters: (state, set) => /* @__PURE__ */ jsxRuntime.jsxs(
691
+ designSystem.SingleSelect,
692
+ {
693
+ size: "S",
694
+ "aria-label": "Status",
695
+ value: state.status ?? "",
696
+ onChange: (status) => set({ status }),
697
+ children: [
698
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "", children: "All statuses" }),
699
+ STATUSES.map((status) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: status, children: status }, status))
700
+ ]
701
+ }
702
+ ),
703
+ columns: [
704
+ {
705
+ key: "when",
706
+ label: "Declared",
707
+ render: (s) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: fmtDateTime(s.declaredAt, locale), tone: "neutral600" })
708
+ },
709
+ { key: "group", label: "Group", render: (s) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: s.group?.name }) },
710
+ {
711
+ key: "who",
712
+ label: "From → to",
713
+ render: (s) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: `${s.from.displayName} → ${s.to.displayName}` })
714
+ },
715
+ {
716
+ key: "amount",
717
+ label: "Amount",
718
+ render: (s) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: fmtNumber(s.amount, locale), sub: s.method, strong: true })
719
+ },
720
+ { key: "status", label: "Status", render: (s) => /* @__PURE__ */ jsxRuntime.jsx(api.StatusBadge, { status: s.status }) },
721
+ {
722
+ key: "ref",
723
+ label: "Reference",
724
+ render: (s) => /* @__PURE__ */ jsxRuntime.jsx(api.Mono, { variant: "pi", children: s.reference ?? "—" })
725
+ }
726
+ ]
727
+ }
728
+ );
729
+ };
730
+ const summary = (data) => data ? Object.entries(data).filter(([, value]) => value !== null && value !== void 0).map(([key, value]) => `${key}: ${value}`).join(" · ") : "—";
731
+ const AuditPage = () => {
732
+ const { locale } = reactIntl.useIntl();
733
+ return /* @__PURE__ */ jsxRuntime.jsx(
734
+ ListPage,
735
+ {
736
+ title: "Audit trail",
737
+ subtitle: "Who did what, in which group, newest first. Written by the server, never edited.",
738
+ permissions: index.PERMISSIONS.auditRead,
739
+ useQuery: api.useGetEventsQuery,
740
+ searchLabel: "Action, e.g. settlement.created",
741
+ searchParam: "action",
742
+ empty: "Nothing recorded.",
743
+ columns: [
744
+ {
745
+ key: "when",
746
+ label: "When",
747
+ render: (e) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: fmtDateTime(e.at, locale), tone: "neutral600" })
748
+ },
749
+ {
750
+ key: "action",
751
+ label: "Action",
752
+ render: (e) => /* @__PURE__ */ jsxRuntime.jsx(api.Mono, { variant: "pi", fontWeight: "semiBold", children: e.action })
753
+ },
754
+ {
755
+ key: "actor",
756
+ label: "By",
757
+ render: (e) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: e.actor?.displayName ?? "An administrator" })
758
+ },
759
+ { key: "group", label: "Group", render: (e) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: e.group?.name }) },
760
+ {
761
+ key: "data",
762
+ label: "Details",
763
+ render: (e) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: summary(e.data), tone: "neutral600" })
764
+ }
765
+ ]
766
+ }
767
+ );
768
+ };
769
+ const SPRING = "cubic-bezier(0.32, 0.72, 0, 1)";
770
+ const Canvas = styledComponents.styled(designSystem.Flex)`
771
+ min-height: 100vh;
772
+ background: ${({ theme }) => theme.colors.neutral100};
773
+ `;
774
+ const Rail = styledComponents.styled.aside`
775
+ width: 272px;
776
+ flex-shrink: 0;
777
+ padding: 1.6rem 0 1.6rem 1.6rem;
778
+ `;
779
+ const Side = styledComponents.styled.nav`
780
+ position: sticky;
781
+ top: 1.6rem;
782
+ display: flex;
783
+ flex-direction: column;
784
+ height: calc(100vh - 3.2rem);
785
+ overflow: auto;
786
+ border-radius: 2rem;
787
+ padding: 0.5rem;
788
+ background: ${({ theme }) => theme.colors.neutral150};
789
+ box-shadow:
790
+ 0 1px 2px rgba(33, 33, 52, 0.04),
791
+ 0 24px 48px -28px rgba(33, 33, 52, 0.3);
792
+ `;
793
+ const SideCore = styledComponents.styled.div`
794
+ flex: 1;
795
+ border-radius: calc(2rem - 0.5rem);
796
+ background: ${({ theme }) => theme.colors.neutral0};
797
+ box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
798
+ padding: 2rem 1.2rem;
799
+ display: flex;
800
+ flex-direction: column;
801
+ `;
802
+ const Brand = styledComponents.styled(designSystem.Flex)`
803
+ padding: 0 ${({ theme }) => theme.spaces[3]} ${({ theme }) => theme.spaces[5]};
804
+ `;
805
+ const Logo = styledComponents.styled.span`
806
+ display: inline-flex;
807
+ align-items: center;
808
+ justify-content: center;
809
+ width: 3.6rem;
810
+ height: 3.6rem;
811
+ border-radius: 1rem;
812
+ background: linear-gradient(135deg, #ff7900, #facc15);
813
+ color: #fff;
814
+ font-weight: 800;
815
+ font-size: 1.6rem;
816
+ letter-spacing: -0.04em;
817
+ box-shadow: 0 6px 14px -6px rgba(255, 121, 0, 0.6);
818
+ `;
819
+ const GroupTitle = styledComponents.styled(designSystem.Typography)`
820
+ display: block;
821
+ padding: ${({ theme }) => theme.spaces[5]} ${({ theme }) => theme.spaces[3]}
822
+ ${({ theme }) => theme.spaces[2]};
823
+ letter-spacing: 0.18em;
824
+ text-transform: uppercase;
825
+ font-size: 1rem;
826
+ `;
827
+ const Item = styledComponents.styled(reactRouterDom.NavLink)`
828
+ position: relative;
829
+ display: flex;
830
+ align-items: center;
831
+ gap: ${({ theme }) => theme.spaces[3]};
832
+ padding: 0.8rem 1.2rem 0.8rem 1.4rem;
833
+ border-radius: 1.2rem;
834
+ color: ${({ theme }) => theme.colors.neutral700};
835
+ text-decoration: none;
836
+ font-size: 1.4rem;
837
+ line-height: 2.2rem;
838
+ transition:
839
+ background 360ms ${SPRING},
840
+ color 360ms ${SPRING},
841
+ transform 360ms ${SPRING};
842
+ svg {
843
+ width: 1.6rem;
844
+ height: 1.6rem;
845
+ flex-shrink: 0;
846
+ color: ${({ theme }) => theme.colors.neutral500};
847
+ transition: color 360ms ${SPRING};
848
+ }
849
+ &::before {
850
+ content: '';
851
+ position: absolute;
852
+ left: 0.2rem;
853
+ top: 50%;
854
+ width: 0.4rem;
855
+ height: 0;
856
+ border-radius: 999px;
857
+ background: #ff7900;
858
+ transform: translateY(-50%);
859
+ transition: height 360ms ${SPRING};
860
+ }
861
+ &:hover {
862
+ background: ${({ theme }) => theme.colors.neutral100};
863
+ color: ${({ theme }) => theme.colors.neutral800};
864
+ transform: translateX(2px);
865
+ }
866
+ &:active {
867
+ transform: scale(0.98);
868
+ }
869
+ &.active {
870
+ background: ${({ theme }) => theme.colors.neutral100};
871
+ color: ${({ theme }) => theme.colors.neutral800};
872
+ font-weight: 600;
873
+ }
874
+ &.active::before {
875
+ height: 1.6rem;
876
+ }
877
+ &.active svg {
878
+ color: #ff7900;
879
+ }
880
+ `;
881
+ const GROUPS = [
882
+ {
883
+ title: "Overview",
884
+ items: [
885
+ { to: "", end: true, key: "nav.dashboard", label: "Dashboard", Icon: icons.PresentationChart }
886
+ ]
887
+ },
888
+ {
889
+ title: "Look up",
890
+ items: [
891
+ { to: "groups", key: "nav.groups", label: "Groups", Icon: icons.Stack },
892
+ { to: "people", key: "nav.people", label: "People", Icon: icons.User },
893
+ {
894
+ to: "settlements",
895
+ key: "nav.settlements",
896
+ label: "Settlements",
897
+ Icon: icons.ArrowsCounterClockwise
898
+ }
899
+ ]
900
+ },
901
+ {
902
+ title: "Verify",
903
+ items: [{ to: "audit", key: "nav.audit", label: "Audit trail", Icon: icons.ListSearch }]
904
+ }
905
+ ];
906
+ const App = () => {
907
+ const { formatMessage } = reactIntl.useIntl();
908
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index.PERMISSIONS.access, children: /* @__PURE__ */ jsxRuntime.jsxs(Canvas, { alignItems: "stretch", children: [
909
+ /* @__PURE__ */ jsxRuntime.jsx(Rail, { children: /* @__PURE__ */ jsxRuntime.jsx(Side, { "aria-label": "Split", children: /* @__PURE__ */ jsxRuntime.jsxs(SideCore, { children: [
910
+ /* @__PURE__ */ jsxRuntime.jsxs(Brand, { gap: 3, alignItems: "center", children: [
911
+ /* @__PURE__ */ jsxRuntime.jsx(Logo, { "aria-hidden": true, children: "÷" }),
912
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
913
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "beta", tag: "p", children: "Split" }),
914
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: "Shared expenses" })
915
+ ] })
916
+ ] }),
917
+ GROUPS.map((g) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
918
+ /* @__PURE__ */ jsxRuntime.jsx(GroupTitle, { variant: "sigma", textColor: "neutral500", children: g.title }),
919
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 1, children: g.items.map((n) => /* @__PURE__ */ jsxRuntime.jsxs(Item, { to: n.to, end: n.end, children: [
920
+ /* @__PURE__ */ jsxRuntime.jsx(n.Icon, { "aria-hidden": true }),
921
+ formatMessage({ id: getTranslation(n.key), defaultMessage: n.label })
922
+ ] }, n.key)) })
923
+ ] }, g.title))
924
+ ] }) }) }),
925
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { flex: 1, minWidth: 0 }, children: /* @__PURE__ */ jsxRuntime.jsxs(reactRouterDom.Routes, { children: [
926
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { index: true, element: /* @__PURE__ */ jsxRuntime.jsx(Dashboard, {}) }),
927
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "groups", element: /* @__PURE__ */ jsxRuntime.jsx(GroupsPage, {}) }),
928
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "groups/:id", element: /* @__PURE__ */ jsxRuntime.jsx(GroupDetailPage, {}) }),
929
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "people", element: /* @__PURE__ */ jsxRuntime.jsx(PeoplePage, {}) }),
930
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "people/:id", element: /* @__PURE__ */ jsxRuntime.jsx(PersonDetailPage, {}) }),
931
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "settlements", element: /* @__PURE__ */ jsxRuntime.jsx(SettlementsPage, {}) }),
932
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "audit", element: /* @__PURE__ */ jsxRuntime.jsx(AuditPage, {}) }),
933
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "*", element: /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Error, {}) })
934
+ ] }) })
935
+ ] }) });
936
+ };
937
+ exports.App = App;