@sonatel-os/strapi-plugin-split 0.5.0 → 0.6.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.
package/README.md CHANGED
@@ -57,7 +57,8 @@ split: {
57
57
  cash: { instant: false },
58
58
  other: { instant: false },
59
59
  },
60
- limits: { maxGroupsPerPerson: 50, maxMembersPerGroup: 50, maxAmount: 50000000 },
60
+ // starting values: an administrator can change them in Settings → Split, and that wins
61
+ limits: { maxGroupsPerPerson: 150, maxMembersPerGroup: 150, maxAmount: 150000000 },
61
62
  },
62
63
  },
63
64
  ```
@@ -119,6 +120,7 @@ Clients branch on `code` (see `server/src/constants.js`), never on the French me
119
120
  | `people.write` | deactivate and reactivate people |
120
121
  | `settlements.read` | look settlements up |
121
122
  | `settings.read` | see the configuration page |
123
+ | `settings.write` | change the limits (logged) |
122
124
 
123
125
  ## Development
124
126
 
@@ -7,8 +7,8 @@ const admin = require("@strapi/strapi/admin");
7
7
  const reactRouterDom = require("react-router-dom");
8
8
  const reactIntl = require("react-intl");
9
9
  const styledComponents = require("styled-components");
10
- const index = require("./index-oyRhs5fN.js");
11
- const api = require("./api-cwZGoKZx.js");
10
+ const index = require("./index-Uv5-E0cg.js");
11
+ const format = require("./format-Dr6t_23v.js");
12
12
  const react = require("react");
13
13
  const getTranslation = (id) => `${index.PLUGIN_ID}.${id}`;
14
14
  const Head = styledComponents.styled.header`
@@ -34,7 +34,7 @@ const Title = styledComponents.styled(designSystem.Typography)`
34
34
  const Content = styledComponents.styled(designSystem.Box)`
35
35
  padding: 0 5.6rem 8rem;
36
36
  > * {
37
- transition: opacity 320ms ${api.SPRING};
37
+ transition: opacity 320ms ${format.SPRING};
38
38
  }
39
39
  `;
40
40
  const PageShell = ({
@@ -53,7 +53,7 @@ const PageShell = ({
53
53
  navigationAction ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingBottom: 4, children: navigationAction }) : null,
54
54
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "flex-end", gap: 6, wrap: "wrap", children: [
55
55
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { minWidth: 0 }, children: [
56
- /* @__PURE__ */ jsxRuntime.jsx(api.Eyebrow, { paddingBottom: 2, children: eyebrow }),
56
+ /* @__PURE__ */ jsxRuntime.jsx(format.Eyebrow, { paddingBottom: 2, children: eyebrow }),
57
57
  /* @__PURE__ */ jsxRuntime.jsx(Title, { tag: "h1", children: title }),
58
58
  subtitle ? /* @__PURE__ */ jsxRuntime.jsx(
59
59
  designSystem.Typography,
@@ -74,7 +74,7 @@ const PageShell = ({
74
74
  ] })
75
75
  ] }),
76
76
  /* @__PURE__ */ jsxRuntime.jsxs(Content, { children: [
77
- intro ? /* @__PURE__ */ jsxRuntime.jsx(api.Intro, { ...intro }) : null,
77
+ intro ? /* @__PURE__ */ jsxRuntime.jsx(format.Intro, { ...intro }) : null,
78
78
  children
79
79
  ] })
80
80
  ] });
@@ -98,34 +98,16 @@ const Cell = ({ main, sub, strong, tone }) => /* @__PURE__ */ jsxRuntime.jsxs(js
98
98
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: strong ? "semiBold" : void 0, textColor: tone, children: main ?? "—" }),
99
99
  sub ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: sub }) : null
100
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
101
  const ACCENT = "#FF7900";
120
102
  const GREEN = "#328048";
121
103
  const BLUE = "#4945FF";
122
104
  const AMBER = "#D9822F";
123
105
  const Dashboard = () => {
124
106
  const { locale } = reactIntl.useIntl();
125
- const { data, isLoading, isError } = api.useGetDashboardQuery();
107
+ const { data, isLoading, isError } = format.useGetDashboardQuery();
126
108
  if (isLoading) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Loading, {});
127
109
  if (isError || !data) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Error, {});
128
- const n = (value) => fmtNumber(value, locale);
110
+ const n = (value) => format.fmtNumber(value, locale);
129
111
  const { people, groups, expenses, settlements, days } = data;
130
112
  const settledMax = Math.max(1, ...settlements.byMethod.map((m) => m.total));
131
113
  const tiles = [
@@ -172,11 +154,11 @@ const Dashboard = () => {
172
154
  xs: 12,
173
155
  direction: "column",
174
156
  alignItems: "stretch",
175
- children: /* @__PURE__ */ jsxRuntime.jsx(api.StatTile, { ...tile, index: i })
157
+ children: /* @__PURE__ */ jsxRuntime.jsx(format.StatTile, { ...tile, index: i })
176
158
  },
177
159
  tile.label
178
160
  )) }),
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: [
161
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(format.Section, { title: "How debts get settled", help: "Confirmed settlements, by method.", index: 4, children: [
180
162
  /* @__PURE__ */ jsxRuntime.jsx(
181
163
  DataTable,
182
164
  {
@@ -189,7 +171,7 @@ const Dashboard = () => {
189
171
  {
190
172
  key: "share",
191
173
  label: "Share",
192
- render: (m) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { minWidth: 160 }, children: /* @__PURE__ */ jsxRuntime.jsx(api.Bar, { value: m.total, max: settledMax }) })
174
+ render: (m) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { minWidth: 160 }, children: /* @__PURE__ */ jsxRuntime.jsx(format.Bar, { value: m.total, max: settledMax }) })
193
175
  }
194
176
  ]
195
177
  }
@@ -288,7 +270,7 @@ const ListPage = ({
288
270
  ) }) : null,
289
271
  filters ? filters(extra, set) : null
290
272
  ] }),
291
- /* @__PURE__ */ jsxRuntime.jsxs(api.Section, { children: [
273
+ /* @__PURE__ */ jsxRuntime.jsxs(format.Section, { children: [
292
274
  isLoading ? /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Loading, {}) : /* @__PURE__ */ jsxRuntime.jsx(DataTable, { columns, rows: data?.data ?? [], onRow, empty }),
293
275
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsx(Pager, { meta: data?.meta?.pagination, onPage: setPage }) })
294
276
  ] })
@@ -303,7 +285,7 @@ const GroupsPage = () => {
303
285
  title: "Groups",
304
286
  subtitle: "Find a group by its name or its invite code, then open its books.",
305
287
  permissions: index.PERMISSIONS.groupsRead,
306
- useQuery: api.useGetGroupsQuery,
288
+ useQuery: format.useGetGroupsQuery,
307
289
  searchLabel: "Name or invite code",
308
290
  empty: "No group matches.",
309
291
  onRow: (g) => navigate(g.id),
@@ -312,17 +294,17 @@ const GroupsPage = () => {
312
294
  {
313
295
  key: "code",
314
296
  label: "Invite code",
315
- render: (g) => /* @__PURE__ */ jsxRuntime.jsx(api.Mono, { variant: "pi", children: g.inviteCode })
297
+ render: (g) => /* @__PURE__ */ jsxRuntime.jsx(format.Mono, { variant: "pi", children: g.inviteCode })
316
298
  },
317
299
  {
318
300
  key: "status",
319
301
  label: "Status",
320
- render: (g) => /* @__PURE__ */ jsxRuntime.jsx(api.StatusBadge, { status: g.isArchived ? "archived" : "active" })
302
+ render: (g) => /* @__PURE__ */ jsxRuntime.jsx(format.StatusBadge, { status: g.isArchived ? "archived" : "active" })
321
303
  },
322
304
  {
323
305
  key: "last",
324
306
  label: "Last activity",
325
- render: (g) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: fmtDateTime(g.lastActivityAt, locale), tone: "neutral600" })
307
+ render: (g) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: format.fmtDateTime(g.lastActivityAt, locale), tone: "neutral600" })
326
308
  }
327
309
  ]
328
310
  }
@@ -335,12 +317,12 @@ const GroupDetailPage = () => {
335
317
  const navigate = reactRouterDom.useNavigate();
336
318
  const { toggleNotification } = admin.useNotification();
337
319
  const { allowedActions } = admin.useRBAC({ archive: index.PERMISSIONS.groupsWrite });
338
- const { data: group, isLoading, isError } = api.useGetGroupQuery(id);
339
- const [archive, { isLoading: archiving }] = api.useArchiveGroupMutation();
320
+ const { data: group, isLoading, isError } = format.useGetGroupQuery(id);
321
+ const [archive, { isLoading: archiving }] = format.useArchiveGroupMutation();
340
322
  if (isLoading) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Loading, {});
341
323
  if (isError || !group) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Error, {});
342
- const n = (value) => fmtNumber(value, locale);
343
- const when = (value) => fmtDateTime(value, locale);
324
+ const n = (value) => format.fmtNumber(value, locale);
325
+ const when = (value) => format.fmtDateTime(value, locale);
344
326
  const onArchive = async () => {
345
327
  try {
346
328
  await archive(id).unwrap();
@@ -349,7 +331,7 @@ const GroupDetailPage = () => {
349
331
  message: "Group archived. Nothing can be written in it any more."
350
332
  });
351
333
  } catch (err) {
352
- toggleNotification({ type: "danger", message: errorMessage(err) });
334
+ toggleNotification({ type: "danger", message: format.errorMessage(err) });
353
335
  }
354
336
  };
355
337
  return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index.PERMISSIONS.groupsRead, children: /* @__PURE__ */ jsxRuntime.jsxs(
@@ -368,7 +350,7 @@ const GroupDetailPage = () => {
368
350
  children: "Groups"
369
351
  }
370
352
  ),
371
- primaryAction: group.isArchived ? /* @__PURE__ */ jsxRuntime.jsx(api.StatusBadge, { status: "archived" }) : allowedActions.canArchive ? /* @__PURE__ */ jsxRuntime.jsx(
353
+ primaryAction: group.isArchived ? /* @__PURE__ */ jsxRuntime.jsx(format.StatusBadge, { status: "archived" }) : allowedActions.canArchive ? /* @__PURE__ */ jsxRuntime.jsx(
372
354
  designSystem.Button,
373
355
  {
374
356
  variant: "danger-light",
@@ -383,10 +365,10 @@ const GroupDetailPage = () => {
383
365
  { label: "Members", value: n(group.memberCount) },
384
366
  { label: "Expenses", value: n(group.expenseCount) },
385
367
  { 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)) }),
368
+ ].map((tile, i) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 4, s: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxRuntime.jsx(format.StatTile, { ...tile, index: i }) }, tile.label)) }),
387
369
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 6, paddingTop: 6, children: [
388
370
  /* @__PURE__ */ jsxRuntime.jsx(
389
- api.Section,
371
+ format.Section,
390
372
  {
391
373
  title: "Members and balances",
392
374
  help: "Above zero is owed money, below zero owes money. Phone numbers are masked.",
@@ -412,7 +394,7 @@ const GroupDetailPage = () => {
412
394
  {
413
395
  key: "phone",
414
396
  label: "Phone",
415
- render: (m) => /* @__PURE__ */ jsxRuntime.jsx(api.Mono, { variant: "pi", children: m.phone ?? "—" })
397
+ render: (m) => /* @__PURE__ */ jsxRuntime.jsx(format.Mono, { variant: "pi", children: m.phone ?? "—" })
416
398
  },
417
399
  {
418
400
  key: "state",
@@ -428,7 +410,7 @@ const GroupDetailPage = () => {
428
410
  {
429
411
  key: "balance",
430
412
  label: "Balance",
431
- render: (m) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: fmtSigned(m.balance, locale), tone: toneOf(m.balance), strong: true })
413
+ render: (m) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: format.fmtSigned(m.balance, locale), tone: toneOf(m.balance), strong: true })
432
414
  }
433
415
  ]
434
416
  }
@@ -436,7 +418,7 @@ const GroupDetailPage = () => {
436
418
  }
437
419
  ),
438
420
  /* @__PURE__ */ jsxRuntime.jsx(
439
- api.Section,
421
+ format.Section,
440
422
  {
441
423
  title: "What would settle it",
442
424
  help: "The fewest payments that bring everyone to zero.",
@@ -459,7 +441,7 @@ const GroupDetailPage = () => {
459
441
  )
460
442
  }
461
443
  ),
462
- /* @__PURE__ */ jsxRuntime.jsx(api.Section, { title: "Settlements", help: "The most recent fifty.", index: 5, children: /* @__PURE__ */ jsxRuntime.jsx(
444
+ /* @__PURE__ */ jsxRuntime.jsx(format.Section, { title: "Settlements", help: "The most recent fifty.", index: 5, children: /* @__PURE__ */ jsxRuntime.jsx(
463
445
  DataTable,
464
446
  {
465
447
  empty: "No settlement yet.",
@@ -483,17 +465,17 @@ const GroupDetailPage = () => {
483
465
  {
484
466
  key: "status",
485
467
  label: "Status",
486
- render: (s) => /* @__PURE__ */ jsxRuntime.jsx(api.StatusBadge, { status: s.status })
468
+ render: (s) => /* @__PURE__ */ jsxRuntime.jsx(format.StatusBadge, { status: s.status })
487
469
  },
488
470
  {
489
471
  key: "ref",
490
472
  label: "Reference",
491
- render: (s) => /* @__PURE__ */ jsxRuntime.jsx(api.Mono, { variant: "pi", children: s.reference ?? "—" })
473
+ render: (s) => /* @__PURE__ */ jsxRuntime.jsx(format.Mono, { variant: "pi", children: s.reference ?? "—" })
492
474
  }
493
475
  ]
494
476
  }
495
477
  ) }),
496
- /* @__PURE__ */ jsxRuntime.jsx(api.Section, { title: "Expenses", help: "The most recent fifty.", index: 6, children: /* @__PURE__ */ jsxRuntime.jsx(
478
+ /* @__PURE__ */ jsxRuntime.jsx(format.Section, { title: "Expenses", help: "The most recent fifty.", index: 6, children: /* @__PURE__ */ jsxRuntime.jsx(
497
479
  DataTable,
498
480
  {
499
481
  empty: "No expense yet.",
@@ -544,7 +526,7 @@ const PeoplePage = () => {
544
526
  title: "People",
545
527
  subtitle: "Find someone by name or by phone number. Numbers stay masked in lists.",
546
528
  permissions: index.PERMISSIONS.peopleRead,
547
- useQuery: api.useGetPeopleQuery,
529
+ useQuery: format.useGetPeopleQuery,
548
530
  searchLabel: "Name or phone",
549
531
  empty: "Nobody matches.",
550
532
  onRow: (p) => navigate(p.id),
@@ -554,16 +536,16 @@ const PeoplePage = () => {
554
536
  label: "Person",
555
537
  render: (p) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: p.displayName ?? "No name yet", strong: true })
556
538
  },
557
- { key: "phone", label: "Phone", render: (p) => /* @__PURE__ */ jsxRuntime.jsx(api.Mono, { variant: "pi", children: p.phone ?? "—" }) },
539
+ { key: "phone", label: "Phone", render: (p) => /* @__PURE__ */ jsxRuntime.jsx(format.Mono, { variant: "pi", children: p.phone ?? "—" }) },
558
540
  {
559
541
  key: "status",
560
542
  label: "Status",
561
- render: (p) => /* @__PURE__ */ jsxRuntime.jsx(api.StatusBadge, { status: p.isActive ? "active" : "inactive" })
543
+ render: (p) => /* @__PURE__ */ jsxRuntime.jsx(format.StatusBadge, { status: p.isActive ? "active" : "inactive" })
562
544
  },
563
545
  {
564
546
  key: "seen",
565
547
  label: "Last seen",
566
- render: (p) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: fmtDateTime(p.lastActiveAt, locale), tone: "neutral600" })
548
+ render: (p) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: format.fmtDateTime(p.lastActiveAt, locale), tone: "neutral600" })
567
549
  }
568
550
  ]
569
551
  }
@@ -578,9 +560,9 @@ const PersonDetailPage = () => {
578
560
  reveal: index.PERMISSIONS.peoplePhone,
579
561
  write: index.PERMISSIONS.peopleWrite
580
562
  });
581
- const { data: person, isLoading, isError } = api.useGetPersonQuery(id);
582
- const [reveal, { isLoading: revealing }] = api.useRevealPhoneMutation();
583
- const [setActive, { isLoading: saving }] = api.useSetPersonActiveMutation();
563
+ const { data: person, isLoading, isError } = format.useGetPersonQuery(id);
564
+ const [reveal, { isLoading: revealing }] = format.useRevealPhoneMutation();
565
+ const [setActive, { isLoading: saving }] = format.useSetPersonActiveMutation();
584
566
  const [fullPhone, setFullPhone] = react.useState(null);
585
567
  if (isLoading) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Loading, {});
586
568
  if (isError || !person) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Error, {});
@@ -590,7 +572,7 @@ const PersonDetailPage = () => {
590
572
  if (done) toggleNotification({ type: "success", message: done });
591
573
  return result;
592
574
  } catch (err) {
593
- toggleNotification({ type: "danger", message: errorMessage(err) });
575
+ toggleNotification({ type: "danger", message: format.errorMessage(err) });
594
576
  return null;
595
577
  }
596
578
  };
@@ -604,7 +586,7 @@ const PersonDetailPage = () => {
604
586
  {
605
587
  title: person.displayName ?? "No name yet",
606
588
  eyebrow: "Person",
607
- subtitle: `First seen ${fmtDateTime(person.createdAt, locale)} · last seen ${fmtDateTime(person.lastActiveAt, locale)}`,
589
+ subtitle: `First seen ${format.fmtDateTime(person.createdAt, locale)} · last seen ${format.fmtDateTime(person.lastActiveAt, locale)}`,
608
590
  navigationAction: /* @__PURE__ */ jsxRuntime.jsx(
609
591
  designSystem.Button,
610
592
  {
@@ -624,15 +606,15 @@ const PersonDetailPage = () => {
624
606
  children: person.isActive ? "Deactivate" : "Reactivate"
625
607
  }
626
608
  ) : null,
627
- secondaryAction: /* @__PURE__ */ jsxRuntime.jsx(api.StatusBadge, { status: person.isActive ? "active" : "inactive" }),
609
+ secondaryAction: /* @__PURE__ */ jsxRuntime.jsx(format.StatusBadge, { status: person.isActive ? "active" : "inactive" }),
628
610
  children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
629
611
  /* @__PURE__ */ jsxRuntime.jsx(
630
- api.Section,
612
+ format.Section,
631
613
  {
632
614
  title: "Phone number",
633
615
  help: "Masked by default. Revealing it is written in the server log with your account.",
634
616
  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 ?? "—" }),
617
+ /* @__PURE__ */ jsxRuntime.jsx(format.Mono, { variant: "delta", fontWeight: "bold", children: fullPhone ?? person.phone ?? "—" }),
636
618
  allowedActions.canReveal && person.phone && !fullPhone ? /* @__PURE__ */ jsxRuntime.jsx(
637
619
  designSystem.Button,
638
620
  {
@@ -647,7 +629,7 @@ const PersonDetailPage = () => {
647
629
  ] })
648
630
  }
649
631
  ),
650
- /* @__PURE__ */ jsxRuntime.jsx(api.Section, { title: "Groups", index: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
632
+ /* @__PURE__ */ jsxRuntime.jsx(format.Section, { title: "Groups", index: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
651
633
  DataTable,
652
634
  {
653
635
  empty: "Not in any group.",
@@ -663,7 +645,7 @@ const PersonDetailPage = () => {
663
645
  {
664
646
  key: "status",
665
647
  label: "Status",
666
- render: (g) => /* @__PURE__ */ jsxRuntime.jsx(api.StatusBadge, { status: g.isArchived ? "archived" : "active" })
648
+ render: (g) => /* @__PURE__ */ jsxRuntime.jsx(format.StatusBadge, { status: g.isArchived ? "archived" : "active" })
667
649
  }
668
650
  ]
669
651
  }
@@ -682,7 +664,7 @@ const SettlementsPage = () => {
682
664
  title: "Settlements",
683
665
  subtitle: "Look a payment up by the reference the customer has: a mobile-money transaction id, for instance.",
684
666
  permissions: index.PERMISSIONS.settlementsRead,
685
- useQuery: api.useGetSettlementsQuery,
667
+ useQuery: format.useGetSettlementsQuery,
686
668
  searchLabel: "Payment reference",
687
669
  searchParam: "reference",
688
670
  empty: "No settlement matches.",
@@ -704,7 +686,7 @@ const SettlementsPage = () => {
704
686
  {
705
687
  key: "when",
706
688
  label: "Declared",
707
- render: (s) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: fmtDateTime(s.declaredAt, locale), tone: "neutral600" })
689
+ render: (s) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: format.fmtDateTime(s.declaredAt, locale), tone: "neutral600" })
708
690
  },
709
691
  { key: "group", label: "Group", render: (s) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: s.group?.name }) },
710
692
  {
@@ -715,13 +697,13 @@ const SettlementsPage = () => {
715
697
  {
716
698
  key: "amount",
717
699
  label: "Amount",
718
- render: (s) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: fmtNumber(s.amount, locale), sub: s.method, strong: true })
700
+ render: (s) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: format.fmtNumber(s.amount, locale), sub: s.method, strong: true })
719
701
  },
720
- { key: "status", label: "Status", render: (s) => /* @__PURE__ */ jsxRuntime.jsx(api.StatusBadge, { status: s.status }) },
702
+ { key: "status", label: "Status", render: (s) => /* @__PURE__ */ jsxRuntime.jsx(format.StatusBadge, { status: s.status }) },
721
703
  {
722
704
  key: "ref",
723
705
  label: "Reference",
724
- render: (s) => /* @__PURE__ */ jsxRuntime.jsx(api.Mono, { variant: "pi", children: s.reference ?? "—" })
706
+ render: (s) => /* @__PURE__ */ jsxRuntime.jsx(format.Mono, { variant: "pi", children: s.reference ?? "—" })
725
707
  }
726
708
  ]
727
709
  }
@@ -736,7 +718,7 @@ const AuditPage = () => {
736
718
  title: "Audit trail",
737
719
  subtitle: "Who did what, in which group, newest first. Written by the server, never edited.",
738
720
  permissions: index.PERMISSIONS.auditRead,
739
- useQuery: api.useGetEventsQuery,
721
+ useQuery: format.useGetEventsQuery,
740
722
  searchLabel: "Action, e.g. settlement.created",
741
723
  searchParam: "action",
742
724
  empty: "Nothing recorded.",
@@ -744,12 +726,12 @@ const AuditPage = () => {
744
726
  {
745
727
  key: "when",
746
728
  label: "When",
747
- render: (e) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: fmtDateTime(e.at, locale), tone: "neutral600" })
729
+ render: (e) => /* @__PURE__ */ jsxRuntime.jsx(Cell, { main: format.fmtDateTime(e.at, locale), tone: "neutral600" })
748
730
  },
749
731
  {
750
732
  key: "action",
751
733
  label: "Action",
752
- render: (e) => /* @__PURE__ */ jsxRuntime.jsx(api.Mono, { variant: "pi", fontWeight: "semiBold", children: e.action })
734
+ render: (e) => /* @__PURE__ */ jsxRuntime.jsx(format.Mono, { variant: "pi", fontWeight: "semiBold", children: e.action })
753
735
  },
754
736
  {
755
737
  key: "actor",
@@ -5,8 +5,8 @@ import { Page, useNotification, useRBAC } from "@strapi/strapi/admin";
5
5
  import { useNavigate, useParams, Routes, Route, NavLink } from "react-router-dom";
6
6
  import { useIntl } from "react-intl";
7
7
  import { styled } from "styled-components";
8
- import { P as PLUGIN_ID, a as PERMISSIONS } from "./index-PFbwTznf.mjs";
9
- import { E as Eyebrow, I as Intro, S as SPRING$1, u as useGetDashboardQuery, a as StatTile, b as Section, B as Bar, c as useGetGroupsQuery, M as Mono, d as StatusBadge, e as useGetGroupQuery, f as useArchiveGroupMutation, g as useGetPeopleQuery, h as useGetPersonQuery, i as useRevealPhoneMutation, j as useSetPersonActiveMutation, k as useGetSettlementsQuery, l as useGetEventsQuery } from "./api-BCYZ56eI.mjs";
8
+ import { P as PLUGIN_ID, a as PERMISSIONS } from "./index-oF7vL92A.mjs";
9
+ import { E as Eyebrow, I as Intro, S as SPRING$1, u as useGetDashboardQuery, a as StatTile, b as Section, B as Bar, f as fmtNumber, c as useGetGroupsQuery, M as Mono, d as StatusBadge, e as fmtDateTime, g as useGetGroupQuery, h as useArchiveGroupMutation, i as fmtSigned, j as errorMessage, k as useGetPeopleQuery, l as useGetPersonQuery, m as useRevealPhoneMutation, n as useSetPersonActiveMutation, o as useGetSettlementsQuery, p as useGetEventsQuery } from "./format-CNjIwTKo.mjs";
10
10
  import { useState } from "react";
11
11
  const getTranslation = (id) => `${PLUGIN_ID}.${id}`;
12
12
  const Head = styled.header`
@@ -96,24 +96,6 @@ const Cell = ({ main, sub, strong, tone }) => /* @__PURE__ */ jsxs(Fragment, { c
96
96
  /* @__PURE__ */ jsx(Typography, { fontWeight: strong ? "semiBold" : void 0, textColor: tone, children: main ?? "—" }),
97
97
  sub ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: sub }) : null
98
98
  ] });
99
- const fmtDateTime = (value, locale) => {
100
- if (!value) return "—";
101
- try {
102
- return new Intl.DateTimeFormat(locale ?? void 0, {
103
- dateStyle: "medium",
104
- timeStyle: "short"
105
- }).format(new Date(value));
106
- } catch {
107
- return String(value);
108
- }
109
- };
110
- const fmtNumber = (value, locale) => new Intl.NumberFormat(locale ?? void 0).format(Number(value ?? 0));
111
- const fmtSigned = (value, locale) => {
112
- const n = Number(value ?? 0);
113
- const digits = fmtNumber(Math.abs(n), locale);
114
- return n > 0 ? `+${digits}` : n < 0 ? `−${digits}` : digits;
115
- };
116
- const errorMessage = (err) => err?.data?.error?.message ?? err?.response?.data?.error?.message ?? err?.error?.message ?? err?.message ?? "Une erreur est survenue.";
117
99
  const ACCENT = "#FF7900";
118
100
  const GREEN = "#328048";
119
101
  const BLUE = "#4945FF";
@@ -0,0 +1,165 @@
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 admin = require("@strapi/strapi/admin");
6
+ const format = require("./format-Dr6t_23v.js");
7
+ const react = require("react");
8
+ const icons = require("@strapi/icons");
9
+ const index = require("./index-Uv5-E0cg.js");
10
+ const FIELDS = [
11
+ {
12
+ key: "maxGroupsPerPerson",
13
+ label: "Groups per person",
14
+ hint: "Groups a person sits in, archived ones included."
15
+ },
16
+ { key: "maxMembersPerGroup", label: "Members per group", hint: "Seats of one group." },
17
+ {
18
+ key: "maxAmount",
19
+ label: "Largest amount",
20
+ hint: "One expense or one settlement, in the currency's smallest unit."
21
+ }
22
+ ];
23
+ const errorOf = (value, ceiling) => Number.isInteger(value) && value > 0 && value <= ceiling ? void 0 : `A whole number from 1 to ${ceiling.toLocaleString()}.`;
24
+ const LimitsForm = ({ limits = {}, ceilings = {}, canEdit }) => {
25
+ const { toggleNotification } = admin.useNotification();
26
+ const [save, { isLoading }] = format.useSetLimitsMutation();
27
+ const [draft, setDraft] = react.useState(limits);
28
+ const errors = Object.fromEntries(
29
+ FIELDS.map((f) => [f.key, errorOf(draft[f.key], ceilings[f.key])])
30
+ );
31
+ const changed = FIELDS.some((f) => draft[f.key] !== limits[f.key]);
32
+ const valid = FIELDS.every((f) => !errors[f.key]);
33
+ const onSave = async () => {
34
+ try {
35
+ setDraft(await save(draft).unwrap());
36
+ toggleNotification({ type: "success", message: "Limits saved. They apply from now on." });
37
+ } catch (err) {
38
+ toggleNotification({ type: "danger", message: format.errorMessage(err) });
39
+ }
40
+ };
41
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 5, children: [
42
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Root, { gap: 5, children: FIELDS.map((f) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 4, s: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: f.key, hint: f.hint, error: canEdit ? errors[f.key] : void 0, children: [
43
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: f.label }),
44
+ /* @__PURE__ */ jsxRuntime.jsx(
45
+ designSystem.NumberInput,
46
+ {
47
+ value: draft[f.key],
48
+ disabled: !canEdit,
49
+ onValueChange: (value) => setDraft({ ...draft, [f.key]: value })
50
+ }
51
+ ),
52
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {}),
53
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, {})
54
+ ] }) }, f.key)) }),
55
+ canEdit ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "flex-end", children: /* @__PURE__ */ jsxRuntime.jsx(
56
+ designSystem.Button,
57
+ {
58
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}),
59
+ loading: isLoading,
60
+ disabled: !changed || !valid,
61
+ onClick: onSave,
62
+ children: "Save the limits"
63
+ }
64
+ ) }) : null
65
+ ] });
66
+ };
67
+ const Row = ({ k, v, hint }) => /* @__PURE__ */ jsxRuntime.jsxs(
68
+ designSystem.Flex,
69
+ {
70
+ justifyContent: "space-between",
71
+ alignItems: "flex-start",
72
+ gap: 4,
73
+ paddingTop: 3,
74
+ paddingBottom: 3,
75
+ style: { borderBottom: "1px solid #eaeaef" },
76
+ children: [
77
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: 1, minWidth: 0 }, children: [
78
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", tag: "p", children: k }),
79
+ hint ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: hint }) : null
80
+ ] }),
81
+ /* @__PURE__ */ jsxRuntime.jsx(format.Mono, { variant: "pi", fontWeight: "semiBold", children: String(v ?? "—") || "—" })
82
+ ]
83
+ }
84
+ );
85
+ const SettingsPage = () => {
86
+ const { data, isLoading, isError } = format.useGetSettingsQuery();
87
+ const { allowedActions, isLoading: checking } = admin.useRBAC({ write: index.PERMISSIONS.settingsWrite });
88
+ if (isLoading || checking) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Loading, {});
89
+ if (isError) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Error, {});
90
+ const s = data ?? {};
91
+ const methods = Object.entries(s.methods ?? {});
92
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index.PERMISSIONS.settingsRead, children: /* @__PURE__ */ jsxRuntime.jsxs(admin.Page.Main, { children: [
93
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Title, { children: "Split · Configuration" }),
94
+ /* @__PURE__ */ jsxRuntime.jsx(
95
+ admin.Layouts.Header,
96
+ {
97
+ title: "Split configuration",
98
+ subtitle: "Read from config/plugins.js and the server environment. Only the limits are changed here."
99
+ }
100
+ ),
101
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
102
+ /* @__PURE__ */ jsxRuntime.jsxs(
103
+ format.Section,
104
+ {
105
+ title: "Who is calling",
106
+ help: "The app routes under /api/split are protected by Strapi API tokens. The caller names the person with a header.",
107
+ children: [
108
+ /* @__PURE__ */ jsxRuntime.jsx(
109
+ Row,
110
+ {
111
+ k: "Person id header",
112
+ v: s.people?.idHeader,
113
+ hint: "Any stable id the host owns; a phone number is stored under one spelling."
114
+ }
115
+ ),
116
+ /* @__PURE__ */ jsxRuntime.jsx(
117
+ Row,
118
+ {
119
+ k: "Display name header",
120
+ v: s.people?.nameHeader,
121
+ hint: "Optional; refreshes the person's name."
122
+ }
123
+ ),
124
+ /* @__PURE__ */ jsxRuntime.jsx(Row, { k: "Create unknown people", v: s.people?.autoProvision ? "yes" : "no" }),
125
+ /* @__PURE__ */ jsxRuntime.jsx(
126
+ Row,
127
+ {
128
+ k: "Home country code",
129
+ v: s.countryCode,
130
+ hint: "Dropped from stored phone numbers."
131
+ }
132
+ )
133
+ ]
134
+ }
135
+ ),
136
+ /* @__PURE__ */ jsxRuntime.jsx(
137
+ format.Section,
138
+ {
139
+ title: "Limits",
140
+ help: "What is refused past these numbers. A change applies to what comes next: nothing that already exists is touched.",
141
+ index: 1,
142
+ children: /* @__PURE__ */ jsxRuntime.jsx(
143
+ LimitsForm,
144
+ {
145
+ limits: s.limits,
146
+ ceilings: s.limitCeilings,
147
+ canEdit: allowedActions.canWrite
148
+ }
149
+ )
150
+ }
151
+ ),
152
+ /* @__PURE__ */ jsxRuntime.jsx(format.Section, { title: "Groups", index: 2, children: /* @__PURE__ */ jsxRuntime.jsx(Row, { k: "Invite code prefix", v: s.inviteCodePrefix }) }),
153
+ /* @__PURE__ */ jsxRuntime.jsx(
154
+ format.Section,
155
+ {
156
+ title: "Settlement methods",
157
+ help: "An instant method is one the host pays itself: it is confirmed at once. The others wait for the receiver.",
158
+ index: 3,
159
+ children: methods.map(([name, m]) => /* @__PURE__ */ jsxRuntime.jsx(Row, { k: name, v: m.instant ? "instant" : "receiver confirms" }, name))
160
+ }
161
+ )
162
+ ] }) })
163
+ ] }) });
164
+ };
165
+ exports.SettingsPage = SettingsPage;