@fonderie/react-admin-screens 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/dist/index.js CHANGED
@@ -443,20 +443,30 @@ function TokensScreen({ client }) {
443
443
  }
444
444
 
445
445
  // src/screens/UsersScreen.tsx
446
- import { useAdminLoginHistory, useAdminUser, useAdminUserSessions } from "@fonderie/react-admin";
446
+ import {
447
+ useAdminLoginHistory,
448
+ useAdminUser,
449
+ useAdminUserSessions,
450
+ useAdminUsers
451
+ } from "@fonderie/react-admin";
447
452
  import { useState as useState2 } from "react";
448
453
  import { Fragment as Fragment5, jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
449
- function UsersScreen({ client }) {
454
+ function UsersScreen({ client, pageSize = 50 }) {
450
455
  const [input, setInput] = useState2("");
451
- const [email, setEmail] = useState2(void 0);
456
+ const [selected, setSelected] = useState2(null);
457
+ const list = useAdminUsers(client, { limit: pageSize });
452
458
  const { user, isLoading, error, suspend, unsuspend, revokeSessions } = useAdminUser(
453
459
  client,
454
- email ? { email } : {}
460
+ selected ?? {}
455
461
  );
456
462
  const userId = user?.id ?? null;
457
463
  const sessions = useAdminUserSessions(client, userId);
458
464
  const history = useAdminLoginHistory(client, userId, { limit: 20 });
459
465
  const yesNo = (v) => v ? /* @__PURE__ */ jsx8("span", { style: styles.ok, children: "yes" }) : /* @__PURE__ */ jsx8("span", { style: styles.muted, children: "no" });
466
+ const clear = () => {
467
+ setSelected(null);
468
+ setInput("");
469
+ };
460
470
  return /* @__PURE__ */ jsxs8("div", { style: styles.container, children: [
461
471
  /* @__PURE__ */ jsx8("h1", { style: styles.title, children: "Users" }),
462
472
  /* @__PURE__ */ jsxs8(
@@ -465,7 +475,8 @@ function UsersScreen({ client }) {
465
475
  style: styles.toolbar,
466
476
  onSubmit: (e) => {
467
477
  e.preventDefault();
468
- setEmail(input.trim() || void 0);
478
+ const email = input.trim();
479
+ setSelected(email ? { email } : null);
469
480
  },
470
481
  children: [
471
482
  /* @__PURE__ */ jsx8(
@@ -479,11 +490,60 @@ function UsersScreen({ client }) {
479
490
  "aria-label": "Email"
480
491
  }
481
492
  ),
482
- /* @__PURE__ */ jsx8("button", { type: "submit", style: styles.button, disabled: isLoading, children: "Look up" })
493
+ /* @__PURE__ */ jsx8("button", { type: "submit", style: styles.button, disabled: isLoading, children: "Look up" }),
494
+ selected ? /* @__PURE__ */ jsx8("button", { type: "button", style: styles.button, onClick: clear, children: "\u2190 All users" }) : /* @__PURE__ */ jsx8(
495
+ "button",
496
+ {
497
+ type: "button",
498
+ style: styles.button,
499
+ onClick: () => void list.refresh(),
500
+ disabled: list.isLoading,
501
+ children: "Refresh"
502
+ }
503
+ )
483
504
  ]
484
505
  }
485
506
  ),
486
507
  error ? /* @__PURE__ */ jsx8("p", { style: styles.error, role: "alert", children: error.status === 404 ? "No user with that email." : error.explanation }) : null,
508
+ !selected ? /* @__PURE__ */ jsxs8(Fragment5, { children: [
509
+ list.error ? /* @__PURE__ */ jsx8("p", { style: styles.error, role: "alert", children: list.error.explanation }) : null,
510
+ list.users.length === 0 && !list.isLoading ? /* @__PURE__ */ jsx8("p", { style: styles.muted, children: "No users yet." }) : /* @__PURE__ */ jsxs8("table", { style: styles.table, children: [
511
+ /* @__PURE__ */ jsx8("thead", { children: /* @__PURE__ */ jsxs8("tr", { children: [
512
+ /* @__PURE__ */ jsx8("th", { style: styles.th, children: "Email" }),
513
+ /* @__PURE__ */ jsx8("th", { style: styles.th, children: "Name" }),
514
+ /* @__PURE__ */ jsx8("th", { style: styles.th, children: "Created" }),
515
+ /* @__PURE__ */ jsx8("th", { style: styles.th, children: "Status" })
516
+ ] }) }),
517
+ /* @__PURE__ */ jsx8("tbody", { children: list.users.map((u) => /* @__PURE__ */ jsxs8("tr", { children: [
518
+ /* @__PURE__ */ jsx8("td", { style: styles.td, children: /* @__PURE__ */ jsx8(
519
+ "button",
520
+ {
521
+ type: "button",
522
+ style: { ...styles.navItem, padding: 0 },
523
+ onClick: () => setSelected({ id: u.id }),
524
+ children: u.email
525
+ }
526
+ ) }),
527
+ /* @__PURE__ */ jsx8("td", { style: styles.td, children: `${u.firstName ?? ""} ${u.lastName ?? ""}`.trim() || /* @__PURE__ */ jsx8("span", { style: styles.muted, children: "\u2014" }) }),
528
+ /* @__PURE__ */ jsx8("td", { style: styles.td, children: new Date(u.createdAt).toLocaleDateString() }),
529
+ /* @__PURE__ */ jsxs8("td", { style: styles.td, children: [
530
+ u.suspended ? /* @__PURE__ */ jsx8("span", { style: styles.badge, children: "suspended" }) : null,
531
+ u.deletedAt ? /* @__PURE__ */ jsx8("span", { style: styles.badge, children: "deleted" }) : null,
532
+ !u.suspended && !u.deletedAt ? /* @__PURE__ */ jsx8("span", { style: styles.muted, children: "active" }) : null
533
+ ] })
534
+ ] }, u.id)) })
535
+ ] }),
536
+ list.isLoading ? /* @__PURE__ */ jsx8("p", { style: styles.status, children: "Loading\u2026" }) : null,
537
+ list.hasMore && !list.isLoading ? /* @__PURE__ */ jsx8(
538
+ "button",
539
+ {
540
+ type: "button",
541
+ style: { ...styles.button, marginTop: 8 },
542
+ onClick: () => void list.loadMore(),
543
+ children: "Load more"
544
+ }
545
+ ) : null
546
+ ] }) : null,
487
547
  user ? /* @__PURE__ */ jsxs8(Fragment5, { children: [
488
548
  /* @__PURE__ */ jsxs8("h2", { style: styles.subtitle, children: [
489
549
  user.firstName || user.lastName ? `${user.firstName} ${user.lastName}`.trim() : user.email,
@@ -657,17 +717,24 @@ function CatalogScreen({ client }) {
657
717
  }
658
718
 
659
719
  // src/screens/SubscriberScreen.tsx
660
- import { useAdminSubscriber } from "@fonderie/react-admin";
720
+ import { useAdminSubscriber, useAdminSubscribers } from "@fonderie/react-admin";
661
721
  import { useState as useState3 } from "react";
662
722
  import { Fragment as Fragment7, jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
663
- function SubscriberScreen({ client }) {
723
+ function SubscriberScreen({ client, pageSize = 50 }) {
664
724
  const [type, setType] = useState3("user");
665
725
  const [idInput, setIdInput] = useState3("");
666
726
  const [subscriber, setSubscriber] = useState3(null);
727
+ const list = useAdminSubscribers(client, { limit: pageSize });
667
728
  const { subscription, wallet, ledger, hasMoreLedger, isLoading, error, loadMoreLedger, grant } = useAdminSubscriber(client, subscriber, { limit: 20 });
668
729
  const [amount, setAmount] = useState3("");
669
730
  const [note, setNote] = useState3("");
670
731
  const [granted, setGranted] = useState3(null);
732
+ const open = (t, id) => {
733
+ setGranted(null);
734
+ setType(t);
735
+ setIdInput(id);
736
+ setSubscriber({ type: t, id });
737
+ };
671
738
  return /* @__PURE__ */ jsxs10("div", { style: styles.container, children: [
672
739
  /* @__PURE__ */ jsx10("h1", { style: styles.title, children: "Subscriber" }),
673
740
  /* @__PURE__ */ jsxs10(
@@ -703,11 +770,79 @@ function SubscriberScreen({ client }) {
703
770
  "aria-label": "Subscriber id"
704
771
  }
705
772
  ),
706
- /* @__PURE__ */ jsx10("button", { type: "submit", style: styles.button, disabled: isLoading, children: "Look up" })
773
+ /* @__PURE__ */ jsx10("button", { type: "submit", style: styles.button, disabled: isLoading, children: "Look up" }),
774
+ subscriber ? /* @__PURE__ */ jsx10(
775
+ "button",
776
+ {
777
+ type: "button",
778
+ style: styles.button,
779
+ onClick: () => {
780
+ setSubscriber(null);
781
+ setIdInput("");
782
+ setGranted(null);
783
+ },
784
+ children: "\u2190 All subscribers"
785
+ }
786
+ ) : /* @__PURE__ */ jsx10(
787
+ "button",
788
+ {
789
+ type: "button",
790
+ style: styles.button,
791
+ onClick: () => void list.refresh(),
792
+ disabled: list.isLoading,
793
+ children: "Refresh"
794
+ }
795
+ )
707
796
  ]
708
797
  }
709
798
  ),
710
799
  error ? /* @__PURE__ */ jsx10("p", { style: styles.error, role: "alert", children: error.explanation }) : null,
800
+ !subscriber ? /* @__PURE__ */ jsxs10(Fragment7, { children: [
801
+ list.error ? /* @__PURE__ */ jsx10("p", { style: styles.error, role: "alert", children: list.error.explanation }) : null,
802
+ list.subscriptions.length === 0 && !list.isLoading ? /* @__PURE__ */ jsx10("p", { style: styles.muted, children: "No subscribers yet." }) : /* @__PURE__ */ jsxs10("table", { style: styles.table, children: [
803
+ /* @__PURE__ */ jsx10("thead", { children: /* @__PURE__ */ jsxs10("tr", { children: [
804
+ /* @__PURE__ */ jsx10("th", { style: styles.th, children: "Subscriber" }),
805
+ /* @__PURE__ */ jsx10("th", { style: styles.th, children: "Plan" }),
806
+ /* @__PURE__ */ jsx10("th", { style: styles.th, children: "Status" }),
807
+ /* @__PURE__ */ jsx10("th", { style: styles.th, children: "Renews" })
808
+ ] }) }),
809
+ /* @__PURE__ */ jsx10("tbody", { children: list.subscriptions.map((s) => /* @__PURE__ */ jsxs10("tr", { children: [
810
+ /* @__PURE__ */ jsx10("td", { style: styles.td, children: /* @__PURE__ */ jsxs10(
811
+ "button",
812
+ {
813
+ type: "button",
814
+ style: { ...styles.navItem, padding: 0, ...styles.mono },
815
+ onClick: () => open(s.subscriberType, s.subscriberId),
816
+ children: [
817
+ s.subscriberType,
818
+ "/",
819
+ s.subscriberId
820
+ ]
821
+ }
822
+ ) }),
823
+ /* @__PURE__ */ jsxs10("td", { style: styles.td, children: [
824
+ /* @__PURE__ */ jsx10("strong", { children: s.plan }),
825
+ " \xB7 ",
826
+ s.interval
827
+ ] }),
828
+ /* @__PURE__ */ jsxs10("td", { style: styles.td, children: [
829
+ s.status,
830
+ s.cancelAtPeriodEnd ? /* @__PURE__ */ jsx10("span", { style: styles.badge, children: "cancels" }) : null
831
+ ] }),
832
+ /* @__PURE__ */ jsx10("td", { style: styles.td, children: s.currentPeriodEnd ? new Date(s.currentPeriodEnd).toLocaleDateString() : /* @__PURE__ */ jsx10("span", { style: styles.muted, children: "\u2014" }) })
833
+ ] }, s.id)) })
834
+ ] }),
835
+ list.isLoading ? /* @__PURE__ */ jsx10("p", { style: styles.status, children: "Loading\u2026" }) : null,
836
+ list.hasMore && !list.isLoading ? /* @__PURE__ */ jsx10(
837
+ "button",
838
+ {
839
+ type: "button",
840
+ style: { ...styles.button, marginTop: 8 },
841
+ onClick: () => void list.loadMore(),
842
+ children: "Load more"
843
+ }
844
+ ) : null
845
+ ] }) : null,
711
846
  subscriber && !isLoading ? /* @__PURE__ */ jsxs10(Fragment7, { children: [
712
847
  /* @__PURE__ */ jsx10("h2", { style: styles.subtitle, children: "Subscription" }),
713
848
  subscription ? /* @__PURE__ */ jsx10("table", { style: styles.table, children: /* @__PURE__ */ jsxs10("tbody", { children: [