strapi-plugin-magic-sessionmanager 4.13.1 → 4.14.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.
Files changed (27) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +99 -53
  3. package/dist/admin/{Analytics-BikQQx_J.js → Analytics-DSG3shUY.js} +1 -1
  4. package/dist/admin/{Analytics-DIY51RI_.mjs → Analytics-oW2QbDj4.mjs} +1 -1
  5. package/dist/admin/{App-B3vaybSO.mjs → App-BRj2qIUs.mjs} +1036 -11
  6. package/dist/admin/{App-BV1LM9Bp.js → App-DcxqQfMT.js} +1034 -9
  7. package/dist/admin/{OnlineUsersWidget-fJogM1xl.js → OnlineUsersWidget-CCTnV-aE.js} +1 -1
  8. package/dist/admin/{OnlineUsersWidget-T-2upsDd.mjs → OnlineUsersWidget-wxDYyK5v.mjs} +1 -1
  9. package/dist/admin/{Settings-BpBlXyMY.mjs → Settings-BNPO9cXS.mjs} +1 -1
  10. package/dist/admin/{Settings-AyYka8wn.js → Settings-XdBlPves.js} +1 -1
  11. package/dist/admin/{de-z0aHRwdw.js → de-B0CBR1Dw.js} +89 -1
  12. package/dist/admin/{de-BSCDuq1i.mjs → de-BlKn1pSD.mjs} +89 -1
  13. package/dist/admin/{en-BWPOiiMt.js → en-D0ZGIIjz.js} +89 -1
  14. package/dist/admin/{en-B4Cuq9JN.mjs → en-IT0YTY8f.mjs} +89 -1
  15. package/dist/admin/{es-DBAmysKi.mjs → es-BCGzaaCh.mjs} +89 -1
  16. package/dist/admin/{es-CMskkUh-.js → es-CWee-XCR.js} +89 -1
  17. package/dist/admin/{fr-ClJ2BkrE.js → fr-rQS1M7jE.js} +89 -1
  18. package/dist/admin/{fr-BNGdtjEl.mjs → fr-xBIH4Byq.mjs} +89 -1
  19. package/dist/admin/{index-DyE1rLW0.js → index-BBZNey0n.js} +15 -10
  20. package/dist/admin/{index-mCVi1j7e.mjs → index-BcQdNWzu.mjs} +33 -28
  21. package/dist/admin/index.js +1 -1
  22. package/dist/admin/index.mjs +2 -2
  23. package/dist/admin/{pt-CRh_J7JS.js → pt-C-yTLhnS.js} +89 -1
  24. package/dist/admin/{pt-Cl7TWsOV.mjs → pt-DWDeIDVa.mjs} +89 -1
  25. package/dist/server/index.js +666 -1
  26. package/dist/server/index.mjs +666 -1
  27. package/package.json +2 -1
@@ -1,13 +1,13 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { useFetchClient, useNotification, useClipboard, useRBAC, useQueryParams, Pagination, Page } from "@strapi/strapi/admin";
3
+ import { NavLink, Link as Link$1, Routes, Route } from "react-router-dom";
2
4
  import { useMemo, useState, useEffect, useRef, useCallback, useId, useLayoutEffect } from "react";
3
5
  import { useIntl } from "react-intl";
4
- import { NavLink, Link as Link$1 } from "react-router-dom";
5
- import { useFetchClient, useNotification, useClipboard, useQueryParams, Pagination, Page } from "@strapi/strapi/admin";
6
- import { Typography, Flex, Loader, Button, Modal, Accordion, Box, IconButton, Link, IconButtonGroup, SimpleMenu, MenuItem, Grid, Table, Thead, Tr, Th, VisuallyHidden, Tbody, Td, Tooltip, SearchForm, Searchbar, TextButton, SingleSelect, SingleSelectOption, EmptyStateLayout, LinkButton } from "@strapi/design-system";
7
- import { Earth, Duplicate, Cross, Eye, Trash, More, CaretDown, Download, ArrowClockwise, Check, Clock, User, ChartBubble, Cog } from "@strapi/icons";
6
+ import { Typography, Flex, Loader, Button, Modal, Accordion, Box, IconButton, Link, IconButtonGroup, SimpleMenu, MenuItem, Grid, Table, Thead, Tr, Th, VisuallyHidden, Tbody, Td, Tooltip, SearchForm, Searchbar, TextButton, SingleSelect, SingleSelectOption, EmptyStateLayout, LinkButton, Badge, Dialog } from "@strapi/design-system";
7
+ import { Earth, Duplicate, Cross, Eye, Trash, More, CaretDown, Download, ArrowClockwise, Check, Clock, User, ChartBubble, Cog, SignOut } from "@strapi/icons";
8
8
  import { EmptyDocuments } from "@strapi/icons/symbols";
9
9
  import styled, { useTheme } from "styled-components";
10
- import { g as getSessionEndReason, a as getEndReasonPresentation, b as getTranslation, p as presentText, i as isSessionFilter, D as DEFAULT_SESSION_FILTER, c as isEndReasonFilter, d as DEFAULT_END_REASON_FILTER, e as getDevicePresentation, u as useSessionFormatters, f as getSessionStatus, h as isNativeOnlySession, j as getSessionEndReasonPresentation, k as DeviceIcon, S as StatusBadge, P as PropertyList, C as ConfirmAction, t as toValidDate, l as pluginId, m as logSafeAdminError, n as PersistentAlert, R as ReadableText, M as MissingValue, V as ValueOrMissing, o as SESSION_STATES, q as SESSION_STATUS_PRESENTATION, r as isCancelledRequest, s as SESSION_FILTER_OPTIONS, E as END_REASON_FILTER_OPTIONS, v as PageShell, w as StatGrid, x as StatCard, y as restoreDialogFocus, z as requireSessionList, A as pluginPermissions } from "./index-mCVi1j7e.mjs";
10
+ import { g as getSessionEndReason, a as getEndReasonPresentation, b as getTranslation, p as presentText, i as isSessionFilter, D as DEFAULT_SESSION_FILTER, c as isEndReasonFilter, d as DEFAULT_END_REASON_FILTER, e as getDevicePresentation, u as useSessionFormatters, f as getSessionStatus, h as isNativeOnlySession, j as getSessionEndReasonPresentation, k as DeviceIcon, S as StatusBadge, P as PropertyList, C as ConfirmAction, t as toValidDate, l as pluginId, m as logSafeAdminError, n as PersistentAlert, R as ReadableText, o as pluginPermissions, M as MissingValue, V as ValueOrMissing, q as SESSION_STATES, r as SESSION_STATUS_PRESENTATION, s as isCancelledRequest, v as SESSION_FILTER_OPTIONS, E as END_REASON_FILTER_OPTIONS, w as PageShell, x as StatGrid, y as StatCard, z as restoreDialogFocus, A as requireSessionList, B as getBadgeColors } from "./index-BcQdNWzu.mjs";
11
11
  const EndReason = ({ session, reason, variant = "omega", textColor = "neutral800" }) => {
12
12
  const { formatMessage } = useIntl();
13
13
  const key = reason || getSessionEndReason(session);
@@ -803,6 +803,52 @@ const SessionDetailModal = ({ session, now, onClose, onCloseAutoFocus, onEndSess
803
803
  ) })
804
804
  ] }) });
805
805
  };
806
+ const SESSION_VIEW_PATHS = Object.freeze({
807
+ users: `/plugins/${pluginId}`,
808
+ admins: `/plugins/${pluginId}/admin-panel`
809
+ });
810
+ const ViewLink = styled(NavLink)`
811
+ display: inline-flex;
812
+ align-items: center;
813
+ min-height: 4rem;
814
+ padding: 0 ${({ theme }) => theme.spaces[4]};
815
+ border-bottom: 2px solid transparent;
816
+ color: ${({ theme }) => theme.colors.neutral600};
817
+ text-decoration: none;
818
+ white-space: nowrap;
819
+
820
+ &:hover {
821
+ color: ${({ theme }) => theme.colors.neutral800};
822
+ }
823
+
824
+ &[aria-current='page'] {
825
+ color: ${({ theme }) => theme.colors.primary700};
826
+ border-bottom-color: ${({ theme }) => theme.colors.primary600};
827
+ }
828
+
829
+ &:focus-visible {
830
+ outline: 2px solid ${({ theme }) => theme.colors.primary600};
831
+ outline-offset: -2px;
832
+ }
833
+ `;
834
+ const ViewNav = styled.nav`
835
+ border-bottom: 1px solid ${({ theme }) => theme.colors.neutral150};
836
+ min-width: 0;
837
+ `;
838
+ const SessionViewNav = ({ current }) => {
839
+ const { formatMessage } = useIntl();
840
+ const t = (id, defaultMessage) => formatMessage({ id: getTranslation(id), defaultMessage });
841
+ const {
842
+ allowedActions: { canRead },
843
+ isLoading
844
+ } = useRBAC(pluginPermissions.adminSessionsRead);
845
+ if (isLoading || !canRead && current !== "admins") return null;
846
+ const link = (view, label) => /* @__PURE__ */ jsx(ViewLink, { to: SESSION_VIEW_PATHS[view], end: true, "data-session-view": view, children: /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: label }) });
847
+ return /* @__PURE__ */ jsx(ViewNav, { "aria-label": t("views.label", "Session views"), "data-session-views": "", children: /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
848
+ link("users", t("views.users", "App users")),
849
+ link("admins", t("views.admins", "Admin panel"))
850
+ ] }) });
851
+ };
806
852
  const isolateActionKeys = (event) => {
807
853
  const fromInsideGroup = event.currentTarget.contains(
808
854
  /** @type {Node} */
@@ -1179,7 +1225,7 @@ const SearchWrapper = styled(Box)`
1179
1225
  }
1180
1226
  `;
1181
1227
  const SEARCH_DEBOUNCE_MS = 300;
1182
- const SessionSearch = ({ value, onSearch }) => {
1228
+ const SessionSearch = ({ value, onSearch, label, placeholder }) => {
1183
1229
  const { formatMessage } = useIntl();
1184
1230
  const t = (id, defaultMessage) => formatMessage({ id: getTranslation(id), defaultMessage });
1185
1231
  const [draft, setDraft] = useState(value);
@@ -1221,8 +1267,8 @@ const SessionSearch = ({ value, onSearch }) => {
1221
1267
  apply("");
1222
1268
  },
1223
1269
  clearLabel: t("homepage.search.clear", "Clear search"),
1224
- placeholder: t("homepage.search.placeholder", "Search user, email, IP or device"),
1225
- children: t("homepage.search.label", "Search sessions")
1270
+ placeholder: placeholder ?? t("homepage.search.placeholder", "Search user, email, IP or device"),
1271
+ children: label ?? t("homepage.search.label", "Search sessions")
1226
1272
  }
1227
1273
  )
1228
1274
  }
@@ -1730,7 +1776,7 @@ const UntrackedSessionsNotice = ({ stats, onChanged, fallbackFocusRef }) => {
1730
1776
  const CLOCK_TICK_MS = 30 * 1e3;
1731
1777
  const ANALYTICS_PATH = `/settings/${pluginId}/analytics`;
1732
1778
  const CONFIGURATION_PATH = `/settings/${pluginId}/general`;
1733
- const PaginationTargets = styled.div`
1779
+ const PaginationTargets$1 = styled.div`
1734
1780
  nav a {
1735
1781
  min-width: 3.2rem;
1736
1782
  }
@@ -2184,6 +2230,7 @@ const HomePage = () => {
2184
2230
  gap: 6,
2185
2231
  minWidth: 0,
2186
2232
  children: [
2233
+ /* @__PURE__ */ jsx(SessionViewNav, { current: "users" }),
2187
2234
  !loading && loadError ? /* @__PURE__ */ jsx(
2188
2235
  PersistentAlert,
2189
2236
  {
@@ -2299,7 +2346,7 @@ const HomePage = () => {
2299
2346
  compact: shouldUseCompactTable(listWidth, isBelowLarge)
2300
2347
  }
2301
2348
  ),
2302
- /* @__PURE__ */ jsx(PaginationTargets, { children: /* @__PURE__ */ jsxs(
2349
+ /* @__PURE__ */ jsx(PaginationTargets$1, { children: /* @__PURE__ */ jsxs(
2303
2350
  Pagination.Root,
2304
2351
  {
2305
2352
  pageCount: pageResult.pageCount,
@@ -2349,8 +2396,986 @@ const HomePage = () => {
2349
2396
  }
2350
2397
  );
2351
2398
  };
2399
+ const ADMIN_FILTER_OPTIONS = Object.freeze(["all", "signed-in", "not-signed-in"]);
2400
+ const ADMIN_PAGE_SIZE_OPTIONS = Object.freeze(["10", "25", "50", "100"]);
2401
+ const ADMIN_DEFAULT_PAGE_SIZE = "25";
2402
+ const ADMIN_MAX_SEARCH_LENGTH = 100;
2403
+ function parseAdminPanelQuery(query = {}) {
2404
+ const page = Number.parseInt(String(query?.page ?? ""), 10);
2405
+ const pageSize = String(query?.pageSize ?? "");
2406
+ const filter = String(query?.filter ?? "");
2407
+ let search = "";
2408
+ if (typeof query?.search === "string") {
2409
+ try {
2410
+ search = decodeURIComponent(query.search).trim();
2411
+ } catch {
2412
+ search = query.search.trim();
2413
+ }
2414
+ }
2415
+ return {
2416
+ page: Number.isInteger(page) && page >= 1 && page <= 1e6 ? page : 1,
2417
+ pageSize: Number(
2418
+ ADMIN_PAGE_SIZE_OPTIONS.includes(pageSize) ? pageSize : ADMIN_DEFAULT_PAGE_SIZE
2419
+ ),
2420
+ filter: ADMIN_FILTER_OPTIONS.includes(filter) ? filter : "all",
2421
+ search: search.slice(0, ADMIN_MAX_SEARCH_LENGTH)
2422
+ };
2423
+ }
2424
+ function buildAdminListParams(state) {
2425
+ return {
2426
+ page: state.page,
2427
+ pageSize: state.pageSize,
2428
+ filter: state.filter,
2429
+ ...state.search ? { search: state.search } : {}
2430
+ };
2431
+ }
2432
+ function hasAdminFilters(state) {
2433
+ return state.filter !== "all" || Boolean(state.search);
2434
+ }
2435
+ function getAdminStatusPresentation(row) {
2436
+ if (row?.account === "invited") {
2437
+ return {
2438
+ key: "invited",
2439
+ tone: "secondary",
2440
+ label: { messageId: "adminPanel.status.invited", defaultMessage: "Invited" },
2441
+ detail: {
2442
+ messageId: "adminPanel.status.invited.detail",
2443
+ defaultMessage: "Invitation not accepted yet"
2444
+ }
2445
+ };
2446
+ }
2447
+ if (row?.account === "deactivated") {
2448
+ return {
2449
+ key: "deactivated",
2450
+ tone: "neutral",
2451
+ label: { messageId: "adminPanel.status.deactivated", defaultMessage: "Deactivated" },
2452
+ detail: {
2453
+ messageId: "adminPanel.status.deactivated.detail",
2454
+ defaultMessage: "Cannot sign in"
2455
+ }
2456
+ };
2457
+ }
2458
+ const count = Number(row?.sessionCount) || 0;
2459
+ if (count > 0) {
2460
+ return {
2461
+ key: "signed-in",
2462
+ tone: "success",
2463
+ label: { messageId: "adminPanel.status.signedIn", defaultMessage: "Signed in" },
2464
+ detail: {
2465
+ messageId: "adminPanel.status.signedIn.detail",
2466
+ defaultMessage: "{count, plural, one {# session} other {# sessions}}",
2467
+ values: { count }
2468
+ }
2469
+ };
2470
+ }
2471
+ return {
2472
+ key: "not-signed-in",
2473
+ tone: "neutral",
2474
+ label: { messageId: "adminPanel.status.notSignedIn", defaultMessage: "Not signed in" },
2475
+ detail: {
2476
+ messageId: "adminPanel.status.notSignedIn.detail",
2477
+ defaultMessage: "No open session"
2478
+ }
2479
+ };
2480
+ }
2481
+ function splitDuration(seconds) {
2482
+ const value = Number(seconds);
2483
+ if (!Number.isFinite(value) || value <= 0) return null;
2484
+ if (value % 86400 === 0) return { unit: "days", count: value / 86400 };
2485
+ if (value % 3600 === 0) return { unit: "hours", count: value / 3600 };
2486
+ return { unit: "minutes", count: Math.max(1, Math.round(value / 60)) };
2487
+ }
2488
+ function getSignOutErrorMessage(error) {
2489
+ const response = (
2490
+ /** @type {any} */
2491
+ error?.response
2492
+ );
2493
+ const status = Number(response?.status ?? /** @type {any} */
2494
+ error?.status);
2495
+ const reason = response?.data?.error?.details?.reason;
2496
+ if (status === 403 && reason === "super-admin-protected") {
2497
+ return {
2498
+ messageId: "adminPanel.signOut.error.protected",
2499
+ defaultMessage: "Only a Super Admin can sign out a Super Admin."
2500
+ };
2501
+ }
2502
+ if (status === 403) {
2503
+ return {
2504
+ messageId: "adminPanel.signOut.error.forbidden",
2505
+ defaultMessage: "You do not have permission to sign admins out."
2506
+ };
2507
+ }
2508
+ if (status === 404) {
2509
+ return {
2510
+ messageId: "adminPanel.signOut.error.gone",
2511
+ defaultMessage: "This session has already ended. The list is up to date now."
2512
+ };
2513
+ }
2514
+ if (status === 429) {
2515
+ return {
2516
+ messageId: "adminPanel.signOut.error.rateLimited",
2517
+ defaultMessage: "Too many sign-outs in a short time. Wait a minute and try again."
2518
+ };
2519
+ }
2520
+ return {
2521
+ messageId: "adminPanel.signOut.error.generic",
2522
+ defaultMessage: "The admin could not be signed out. Try again."
2523
+ };
2524
+ }
2525
+ const HIGHLIGHT_BADGE = { backgroundColor: "primary100", textColor: "neutral800" };
2526
+ const SHRINKING_ADMIN_CELL = { maxWidth: 0, width: "34%" };
2527
+ const SHRINKING_ROLES_CELL = { maxWidth: 0, width: "22%" };
2528
+ const useT$1 = () => {
2529
+ const { formatMessage } = useIntl();
2530
+ return (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
2531
+ };
2532
+ const AdminIdentity = ({ admin }) => {
2533
+ const t = useT$1();
2534
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, minWidth: 0, children: [
2535
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", minWidth: 0, children: [
2536
+ /* @__PURE__ */ jsx(
2537
+ Typography,
2538
+ {
2539
+ variant: "omega",
2540
+ fontWeight: "semiBold",
2541
+ textColor: "neutral800",
2542
+ ellipsis: true,
2543
+ title: admin.name,
2544
+ children: admin.name
2545
+ }
2546
+ ),
2547
+ admin.self ? /* @__PURE__ */ jsx(Badge, { ...HIGHLIGHT_BADGE, shrink: 0, children: t("adminPanel.you", "You") }) : null
2548
+ ] }),
2549
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", ellipsis: true, title: admin.email, children: admin.email })
2550
+ ] });
2551
+ };
2552
+ const AdminRoles = ({ admin }) => {
2553
+ const t = useT$1();
2554
+ const names = (admin.roles || []).map((role) => role.name).filter(Boolean);
2555
+ const text = names.length ? names.join(", ") : t("adminPanel.roles.none", "No role");
2556
+ return /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", ellipsis: true, title: text, children: text });
2557
+ };
2558
+ const AdminStatus = ({ admin }) => {
2559
+ const t = useT$1();
2560
+ const status = getAdminStatusPresentation(admin);
2561
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 1, "data-admin-status": status.key, children: [
2562
+ /* @__PURE__ */ jsx(Badge, { ...getBadgeColors(status.tone), children: t(status.label.messageId, status.label.defaultMessage) }),
2563
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t(status.detail.messageId, status.detail.defaultMessage, status.detail.values) })
2564
+ ] });
2565
+ };
2566
+ const AdminTable = ({
2567
+ admins,
2568
+ labelledBy,
2569
+ canRevoke,
2570
+ onView,
2571
+ onSignOutEverywhere,
2572
+ busy
2573
+ }) => {
2574
+ const t = useT$1();
2575
+ return /* @__PURE__ */ jsx(Box, { background: "neutral0", hasRadius: true, shadow: "tableShadow", "data-admin-table": "", children: /* @__PURE__ */ jsxs(
2576
+ Table,
2577
+ {
2578
+ colCount: 5,
2579
+ rowCount: admins.length + 1,
2580
+ "aria-labelledby": labelledBy,
2581
+ "aria-busy": busy,
2582
+ children: [
2583
+ /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
2584
+ /* @__PURE__ */ jsx(Th, { style: SHRINKING_ADMIN_CELL, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: t("adminPanel.table.admin", "Admin") }) }),
2585
+ /* @__PURE__ */ jsx(Th, { style: SHRINKING_ROLES_CELL, children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: t("adminPanel.table.roles", "Roles") }) }),
2586
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: t("adminPanel.table.status", "Status") }) }),
2587
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: t("adminPanel.table.lastActive", "Last active") }) }),
2588
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(VisuallyHidden, { children: t("adminPanel.table.actions", "Actions") }) })
2589
+ ] }) }),
2590
+ /* @__PURE__ */ jsx(Tbody, { children: admins.map((admin) => /* @__PURE__ */ jsxs(Tr, { "data-admin-row": admin.id, children: [
2591
+ /* @__PURE__ */ jsx(Td, { style: SHRINKING_ADMIN_CELL, children: /* @__PURE__ */ jsx(AdminIdentity, { admin }) }),
2592
+ /* @__PURE__ */ jsx(Td, { style: SHRINKING_ROLES_CELL, children: /* @__PURE__ */ jsx(AdminRoles, { admin }) }),
2593
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(AdminStatus, { admin }) }),
2594
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(LastActive, { value: admin.lastActiveAt }) }),
2595
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Flex, { justifyContent: "flex-end", children: /* @__PURE__ */ jsxs(IconButtonGroup, { children: [
2596
+ /* @__PURE__ */ jsx(
2597
+ IconButton,
2598
+ {
2599
+ label: t("adminPanel.actions.view", "View sessions of {name}", {
2600
+ name: admin.name
2601
+ }),
2602
+ onClick: (event) => onView(admin, event.currentTarget),
2603
+ children: /* @__PURE__ */ jsx(Eye, {})
2604
+ }
2605
+ ),
2606
+ canRevoke && admin.canSignOut ? /* @__PURE__ */ jsx(
2607
+ IconButton,
2608
+ {
2609
+ variant: "danger-light",
2610
+ label: t(
2611
+ "adminPanel.actions.signOutEverywhere",
2612
+ "Sign out {name} everywhere",
2613
+ {
2614
+ name: admin.name
2615
+ }
2616
+ ),
2617
+ onClick: (event) => onSignOutEverywhere(admin, event.currentTarget),
2618
+ children: /* @__PURE__ */ jsx(SignOut, {})
2619
+ }
2620
+ ) : null
2621
+ ] }) }) })
2622
+ ] }, admin.id)) })
2623
+ ]
2624
+ }
2625
+ ) });
2626
+ };
2627
+ const AdminCardList = ({ admins, labelledBy, canRevoke, onView, onSignOutEverywhere }) => {
2628
+ const t = useT$1();
2629
+ return /* @__PURE__ */ jsx(
2630
+ Flex,
2631
+ {
2632
+ tag: "ul",
2633
+ direction: "column",
2634
+ alignItems: "stretch",
2635
+ gap: 3,
2636
+ "aria-labelledby": labelledBy,
2637
+ "data-admin-cards": "",
2638
+ children: admins.map((admin) => /* @__PURE__ */ jsx(
2639
+ Box,
2640
+ {
2641
+ tag: "li",
2642
+ background: "neutral0",
2643
+ hasRadius: true,
2644
+ shadow: "tableShadow",
2645
+ padding: 4,
2646
+ "data-admin-row": admin.id,
2647
+ children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 3, minWidth: 0, children: [
2648
+ /* @__PURE__ */ jsx(AdminIdentity, { admin }),
2649
+ /* @__PURE__ */ jsxs(Flex, { gap: 4, wrap: "wrap", alignItems: "flex-start", justifyContent: "space-between", children: [
2650
+ /* @__PURE__ */ jsx(AdminStatus, { admin }),
2651
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 1, children: [
2652
+ /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: t("adminPanel.table.lastActive", "Last active") }),
2653
+ /* @__PURE__ */ jsx(LastActive, { value: admin.lastActiveAt })
2654
+ ] })
2655
+ ] }),
2656
+ /* @__PURE__ */ jsx(AdminRoles, { admin }),
2657
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
2658
+ /* @__PURE__ */ jsx(
2659
+ Button,
2660
+ {
2661
+ variant: "secondary",
2662
+ startIcon: /* @__PURE__ */ jsx(Eye, {}),
2663
+ onClick: (event) => onView(admin, event.currentTarget),
2664
+ "aria-label": t("adminPanel.actions.view", "View sessions of {name}", {
2665
+ name: admin.name
2666
+ }),
2667
+ flex: "1 1 auto",
2668
+ children: t("adminPanel.actions.viewShort", "View sessions")
2669
+ }
2670
+ ),
2671
+ canRevoke && admin.canSignOut ? /* @__PURE__ */ jsx(
2672
+ Button,
2673
+ {
2674
+ variant: "danger-light",
2675
+ startIcon: /* @__PURE__ */ jsx(SignOut, {}),
2676
+ onClick: (event) => onSignOutEverywhere(admin, event.currentTarget),
2677
+ "aria-label": t(
2678
+ "adminPanel.actions.signOutEverywhere",
2679
+ "Sign out {name} everywhere",
2680
+ {
2681
+ name: admin.name
2682
+ }
2683
+ ),
2684
+ flex: "1 1 auto",
2685
+ children: t("adminPanel.actions.signOutEverywhereShort", "Sign out everywhere")
2686
+ }
2687
+ ) : null
2688
+ ] })
2689
+ ] })
2690
+ },
2691
+ admin.id
2692
+ ))
2693
+ }
2694
+ );
2695
+ };
2696
+ const useT = () => {
2697
+ const { formatMessage } = useIntl();
2698
+ return (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
2699
+ };
2700
+ const DateValue = ({ value }) => {
2701
+ const { formatDate } = useSessionFormatters();
2702
+ if (!value) return null;
2703
+ return /* @__PURE__ */ jsx(Typography, { tag: "time", dateTime: value, variant: "omega", textColor: "neutral800", children: formatDate(value) });
2704
+ };
2705
+ const SessionCard = ({ session, admin, canSignOut, onSignOut }) => {
2706
+ const t = useT();
2707
+ const device = session.device || t("adminPanel.session.unknownDevice", "Unknown browser");
2708
+ return /* @__PURE__ */ jsx(
2709
+ Box,
2710
+ {
2711
+ tag: "li",
2712
+ background: "neutral0",
2713
+ borderColor: "neutral200",
2714
+ hasRadius: true,
2715
+ padding: 4,
2716
+ "data-admin-session": "",
2717
+ children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 3, minWidth: 0, children: [
2718
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", alignItems: "center", justifyContent: "space-between", children: [
2719
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", alignItems: "center", minWidth: 0, children: [
2720
+ /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", textColor: "neutral800", children: device }),
2721
+ session.current ? /* @__PURE__ */ jsx(Badge, { ...HIGHLIGHT_BADGE, children: t("adminPanel.session.current", "This browser") }) : null,
2722
+ session.rememberMe ? /* @__PURE__ */ jsx(Badge, { children: t("adminPanel.session.rememberMe", "Remember me") }) : null
2723
+ ] }),
2724
+ canSignOut ? /* @__PURE__ */ jsx(
2725
+ Button,
2726
+ {
2727
+ size: "S",
2728
+ variant: "danger-light",
2729
+ startIcon: /* @__PURE__ */ jsx(SignOut, {}),
2730
+ onClick: (event) => onSignOut(session, event.currentTarget),
2731
+ "aria-label": t("adminPanel.session.signOutLabel", "Sign {name} out of {device}", {
2732
+ name: admin.name,
2733
+ device
2734
+ }),
2735
+ children: t("adminPanel.session.signOut", "Sign out")
2736
+ }
2737
+ ) : null
2738
+ ] }),
2739
+ /* @__PURE__ */ jsx(
2740
+ PropertyList,
2741
+ {
2742
+ columns: 2,
2743
+ items: [
2744
+ {
2745
+ id: "signedIn",
2746
+ label: t("adminPanel.session.signedInAt", "Signed in"),
2747
+ value: session.signedInAt,
2748
+ render: session.signedInAt ? /* @__PURE__ */ jsx(DateValue, { value: session.signedInAt }) : void 0
2749
+ },
2750
+ {
2751
+ id: "lastActive",
2752
+ label: t("adminPanel.session.lastActiveAt", "Last active"),
2753
+ value: session.lastActiveAt,
2754
+ render: session.lastActiveAt ? /* @__PURE__ */ jsx(LastActive, { value: session.lastActiveAt }) : void 0
2755
+ },
2756
+ {
2757
+ id: "endsAt",
2758
+ label: t("adminPanel.session.endsAt", "Ends at the latest"),
2759
+ value: session.endsAt,
2760
+ render: session.endsAt ? /* @__PURE__ */ jsx(DateValue, { value: session.endsAt }) : void 0,
2761
+ fullWidth: true
2762
+ }
2763
+ ]
2764
+ }
2765
+ )
2766
+ ] })
2767
+ }
2768
+ );
2769
+ };
2770
+ const AdminSessionsModal = ({
2771
+ admin,
2772
+ sessions,
2773
+ loading,
2774
+ error,
2775
+ onRetry,
2776
+ canRevoke,
2777
+ onSignOut,
2778
+ onSignOutEverywhere,
2779
+ onClose,
2780
+ onCloseAutoFocus
2781
+ }) => {
2782
+ const t = useT();
2783
+ const canSignOut = canRevoke && admin.account === "active" && !admin.protectedReason;
2784
+ const settingsPath = `/settings/users/${admin.id}`;
2785
+ let notice = null;
2786
+ if (admin.account !== "active") {
2787
+ notice = /* @__PURE__ */ jsx(PersistentAlert, { variant: "neutral", title: t("adminPanel.dialog.inactive.title", "No usable session"), children: t(
2788
+ "adminPanel.dialog.inactive.body",
2789
+ "Strapi rejects every request of a deactivated or invited account, so there is nothing to sign out."
2790
+ ) });
2791
+ } else if (admin.protectedReason === "super-admin-protected" && canRevoke) {
2792
+ notice = /* @__PURE__ */ jsx(PersistentAlert, { variant: "neutral", title: t("adminPanel.dialog.protected.title", "Super Admin"), children: t(
2793
+ "adminPanel.dialog.protected.body",
2794
+ "Only a Super Admin can sign out a Super Admin. This keeps at least one Super Admin able to work at all times."
2795
+ ) });
2796
+ }
2797
+ return /* @__PURE__ */ jsx(Modal.Root, { open: true, onOpenChange: (open) => open ? null : onClose(), children: /* @__PURE__ */ jsxs(Modal.Content, { onCloseAutoFocus, "aria-describedby": void 0, children: [
2798
+ /* @__PURE__ */ jsx(Modal.Header, { closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsx(Modal.Title, { children: t("adminPanel.dialog.title", "Sessions of {name}", { name: admin.name }) }) }),
2799
+ /* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 4, minWidth: 0, children: [
2800
+ /* @__PURE__ */ jsx(
2801
+ PropertyList,
2802
+ {
2803
+ columns: 2,
2804
+ items: [
2805
+ {
2806
+ id: "email",
2807
+ label: t("adminPanel.dialog.email", "Email"),
2808
+ value: admin.email,
2809
+ kind: "email"
2810
+ },
2811
+ {
2812
+ id: "roles",
2813
+ label: t("adminPanel.table.roles", "Roles"),
2814
+ render: /* @__PURE__ */ jsx(AdminRoles, { admin })
2815
+ },
2816
+ {
2817
+ id: "status",
2818
+ label: t("adminPanel.table.status", "Status"),
2819
+ render: /* @__PURE__ */ jsx(AdminStatus, { admin: { ...admin, sessionCount: sessions.length } }),
2820
+ fullWidth: true
2821
+ }
2822
+ ]
2823
+ }
2824
+ ),
2825
+ notice,
2826
+ loading ? /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsx(Loader, { small: true, children: t("adminPanel.dialog.loading", "Loading sessions") }) }) : null,
2827
+ !loading && error ? /* @__PURE__ */ jsx(
2828
+ PersistentAlert,
2829
+ {
2830
+ variant: "danger",
2831
+ action: /* @__PURE__ */ jsx(Button, { size: "S", variant: "secondary", onClick: onRetry, children: t("common.tryAgain", "Try again") }),
2832
+ children: t("adminPanel.dialog.error", "The sessions could not be loaded.")
2833
+ }
2834
+ ) : null,
2835
+ !loading && !error && admin.account === "active" && sessions.length === 0 ? /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", "data-admin-sessions-empty": "", children: t(
2836
+ "adminPanel.dialog.empty",
2837
+ "{name} is not signed in. Sessions appear here after the next sign-in.",
2838
+ { name: admin.name }
2839
+ ) }) : null,
2840
+ !loading && sessions.length > 0 ? /* @__PURE__ */ jsx(
2841
+ Flex,
2842
+ {
2843
+ tag: "ul",
2844
+ direction: "column",
2845
+ alignItems: "stretch",
2846
+ gap: 3,
2847
+ "aria-label": t("adminPanel.dialog.listLabel", "Signed-in browsers"),
2848
+ children: sessions.map((session) => /* @__PURE__ */ jsx(
2849
+ SessionCard,
2850
+ {
2851
+ session,
2852
+ admin,
2853
+ canSignOut,
2854
+ onSignOut
2855
+ },
2856
+ session.id
2857
+ ))
2858
+ }
2859
+ ) : null
2860
+ ] }) }),
2861
+ /* @__PURE__ */ jsx(Modal.Footer, { children: /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", justifyContent: "space-between", width: "100%", children: [
2862
+ /* @__PURE__ */ jsx(Modal.Close, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: t("common.close", "Close") }) }),
2863
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", justifyContent: "flex-end", children: [
2864
+ /* @__PURE__ */ jsx(LinkButton, { tag: Link$1, to: settingsPath, variant: "secondary", children: t("adminPanel.dialog.manage", "Manage in Settings") }),
2865
+ canSignOut && sessions.length > 0 ? /* @__PURE__ */ jsx(
2866
+ Button,
2867
+ {
2868
+ variant: "danger",
2869
+ startIcon: /* @__PURE__ */ jsx(SignOut, {}),
2870
+ onClick: (event) => onSignOutEverywhere(event.currentTarget),
2871
+ children: t("adminPanel.actions.signOutEverywhereShort", "Sign out everywhere")
2872
+ }
2873
+ ) : null
2874
+ ] })
2875
+ ] }) })
2876
+ ] }) });
2877
+ };
2878
+ const SETTINGS_USERS_PATH = "/settings/users";
2879
+ const PaginationTargets = styled.div`
2880
+ nav a {
2881
+ min-width: 3.2rem;
2882
+ }
2883
+
2884
+ & > div {
2885
+ flex-wrap: wrap;
2886
+ gap: ${({ theme }) => theme.spaces[2]} ${({ theme }) => theme.spaces[4]};
2887
+ }
2888
+
2889
+ & > div > div > span {
2890
+ white-space: nowrap;
2891
+ }
2892
+ `;
2893
+ const EMPTY_STATS = { signedInAdmins: 0, activeSessions: 0, activeAccounts: 0, totalAdmins: 0 };
2894
+ const AdminPanelPage = () => {
2895
+ const { formatMessage } = useIntl();
2896
+ const { get, post } = useFetchClient();
2897
+ const { toggleNotification } = useNotification();
2898
+ const { isBelowMedium } = useBreakpoint();
2899
+ const [{ query }, setQuery] = useQueryParams();
2900
+ const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
2901
+ const view = parseAdminPanelQuery(query);
2902
+ const {
2903
+ allowedActions: { canRevoke }
2904
+ } = useRBAC(pluginPermissions.adminSessionsRevoke);
2905
+ const [admins, setAdmins] = useState([]);
2906
+ const [meta, setMeta] = useState(null);
2907
+ const [loading, setLoading] = useState(true);
2908
+ const [refreshing, setRefreshing] = useState(false);
2909
+ const [loadError, setLoadError] = useState(false);
2910
+ const [selected, setSelected] = useState(null);
2911
+ const [dialogSessions, setDialogSessions] = useState([]);
2912
+ const [dialogLoading, setDialogLoading] = useState(false);
2913
+ const [dialogError, setDialogError] = useState(false);
2914
+ const [pending, setPending] = useState(null);
2915
+ const requestIdRef = useRef(0);
2916
+ const dialogRequestRef = useRef(0);
2917
+ const hasLoadedRef = useRef(false);
2918
+ const openerRef = useRef(null);
2919
+ const confirmReturnRef = useRef(null);
2920
+ const captionRef = useRef(null);
2921
+ const pageRef = useRef(null);
2922
+ const captionId = `admin-list-caption-${useId().replace(/:/g, "")}`;
2923
+ const listParams = useMemo(
2924
+ () => buildAdminListParams({
2925
+ page: view.page,
2926
+ pageSize: view.pageSize,
2927
+ filter: view.filter,
2928
+ search: view.search
2929
+ }),
2930
+ [view.page, view.pageSize, view.filter, view.search]
2931
+ );
2932
+ const fetchAdmins = useCallback(async () => {
2933
+ const requestId = requestIdRef.current + 1;
2934
+ requestIdRef.current = requestId;
2935
+ if (hasLoadedRef.current) setRefreshing(true);
2936
+ else setLoading(true);
2937
+ try {
2938
+ const response = await get(`/${pluginId}/admin-sessions/admins`, { params: listParams });
2939
+ if (requestId !== requestIdRef.current) return;
2940
+ const body = response?.data || {};
2941
+ setAdmins(Array.isArray(body.data) ? body.data : []);
2942
+ setMeta(body.meta || null);
2943
+ setLoadError(false);
2944
+ hasLoadedRef.current = true;
2945
+ } catch (err) {
2946
+ if (requestId !== requestIdRef.current || isCancelledRequest(err)) return;
2947
+ setLoadError(true);
2948
+ logSafeAdminError("adminPanel.load", err);
2949
+ } finally {
2950
+ if (requestId === requestIdRef.current) {
2951
+ setLoading(false);
2952
+ setRefreshing(false);
2953
+ }
2954
+ }
2955
+ }, [get, listParams]);
2956
+ useEffect(() => {
2957
+ fetchAdmins();
2958
+ }, [fetchAdmins]);
2959
+ const fetchDialogSessions = useCallback(
2960
+ async (admin) => {
2961
+ const requestId = dialogRequestRef.current + 1;
2962
+ dialogRequestRef.current = requestId;
2963
+ setDialogLoading(true);
2964
+ try {
2965
+ const response = await get(`/${pluginId}/admin-sessions/admins/${admin.id}/sessions`);
2966
+ if (requestId !== dialogRequestRef.current) return;
2967
+ const body = response?.data || {};
2968
+ setDialogSessions(Array.isArray(body.data) ? body.data : []);
2969
+ if (body.meta?.admin) setSelected((current) => current ? body.meta.admin : current);
2970
+ setDialogError(false);
2971
+ } catch (err) {
2972
+ if (requestId !== dialogRequestRef.current || isCancelledRequest(err)) return;
2973
+ setDialogError(true);
2974
+ logSafeAdminError("adminPanel.sessions", err);
2975
+ } finally {
2976
+ if (requestId === dialogRequestRef.current) setDialogLoading(false);
2977
+ }
2978
+ },
2979
+ [get]
2980
+ );
2981
+ const openDialog = (admin, trigger) => {
2982
+ openerRef.current = trigger;
2983
+ setSelected(admin);
2984
+ setDialogSessions([]);
2985
+ setDialogError(false);
2986
+ fetchDialogSessions(admin);
2987
+ };
2988
+ const closeDialog = () => {
2989
+ dialogRequestRef.current += 1;
2990
+ setSelected(null);
2991
+ setDialogSessions([]);
2992
+ };
2993
+ const pagination = meta?.pagination || { page: 1, pageCount: 1, total: 0 };
2994
+ useEffect(() => {
2995
+ if (!loading && !refreshing && view.page > pagination.pageCount) {
2996
+ setQuery({ page: String(pagination.pageCount) }, "push", true);
2997
+ }
2998
+ }, [loading, refreshing, view.page, pagination.pageCount, setQuery]);
2999
+ const handleFilterChange = (value) => {
3000
+ const filter = String(value);
3001
+ setQuery({ filter: filter === "all" ? void 0 : filter, page: "1" });
3002
+ };
3003
+ const handleSearch = useCallback(
3004
+ (value) => setQuery({ search: encodeSearchQuery(value), page: "1" }, "push", true),
3005
+ [setQuery]
3006
+ );
3007
+ const handleClearFilters = () => {
3008
+ setQuery({ search: void 0, filter: void 0, page: "1" });
3009
+ captionRef.current?.focus();
3010
+ };
3011
+ const askSignOut = (admin, session, trigger) => {
3012
+ confirmReturnRef.current = trigger;
3013
+ setPending({ admin, session });
3014
+ };
3015
+ const confirmSignOut = async () => {
3016
+ if (!pending) return;
3017
+ const { admin, session } = pending;
3018
+ const device = session?.device || t("adminPanel.session.unknownDevice", "Unknown browser");
3019
+ const url = session ? `/${pluginId}/admin-sessions/admins/${admin.id}/sessions/${session.id}/sign-out` : `/${pluginId}/admin-sessions/admins/${admin.id}/sign-out-everywhere`;
3020
+ try {
3021
+ const response = await post(url);
3022
+ const result = response?.data?.data || {};
3023
+ if (result.signedOutSelf) {
3024
+ toggleNotification({
3025
+ type: "warning",
3026
+ message: t(
3027
+ "adminPanel.signOut.success.self",
3028
+ "You signed yourself out of this browser. The login page opens next."
3029
+ )
3030
+ });
3031
+ } else {
3032
+ toggleNotification({
3033
+ type: "success",
3034
+ message: session ? t("adminPanel.signOut.success.one", "{name} was signed out of {device}.", {
3035
+ name: admin.name,
3036
+ device
3037
+ }) : t("adminPanel.signOut.success.all", "{name} was signed out everywhere.", {
3038
+ name: admin.name
3039
+ })
3040
+ });
3041
+ }
3042
+ await Promise.all([fetchAdmins(), selected ? fetchDialogSessions(selected) : null]);
3043
+ } catch (err) {
3044
+ logSafeAdminError("adminPanel.signOut", err);
3045
+ const message = getSignOutErrorMessage(err);
3046
+ toggleNotification({
3047
+ type: getErrorStatus(err) === 404 ? "warning" : "danger",
3048
+ message: t(message.messageId, message.defaultMessage)
3049
+ });
3050
+ if (getErrorStatus(err) === 404) {
3051
+ await Promise.all([fetchAdmins(), selected ? fetchDialogSessions(selected) : null]);
3052
+ return;
3053
+ }
3054
+ throw err;
3055
+ }
3056
+ };
3057
+ const stats = meta?.stats || EMPTY_STATS;
3058
+ const supported = meta?.supported !== false;
3059
+ const showData = !loading && Boolean(meta) && supported;
3060
+ const filtersActive = hasAdminFilters(view);
3061
+ const durationText = (seconds) => {
3062
+ const parts = splitDuration(seconds);
3063
+ if (!parts) return "";
3064
+ if (parts.unit === "days")
3065
+ return t("adminPanel.duration.days", "{count, plural, one {# day} other {# days}}", parts);
3066
+ if (parts.unit === "hours")
3067
+ return t("adminPanel.duration.hours", "{count, plural, one {# hour} other {# hours}}", parts);
3068
+ return t(
3069
+ "adminPanel.duration.minutes",
3070
+ "{count, plural, one {# minute} other {# minutes}}",
3071
+ parts
3072
+ );
3073
+ };
3074
+ const statusCard = (filter) => ({
3075
+ onClick: () => handleFilterChange(filter),
3076
+ pressed: view.filter === filter
3077
+ });
3078
+ let confirm = null;
3079
+ if (pending) {
3080
+ const { admin, session } = pending;
3081
+ const device = session?.device || t("adminPanel.session.unknownDevice", "Unknown browser");
3082
+ const includesThisBrowser = admin.self && (session ? session.current : true);
3083
+ const body = session ? t(
3084
+ "adminPanel.confirm.one.body",
3085
+ "{name} is signed out of {device} on their next click in the admin panel. They can sign in again with their password.",
3086
+ { name: admin.name, device }
3087
+ ) : t(
3088
+ "adminPanel.confirm.all.body",
3089
+ "Every session of {name} ends on their next click in the admin panel. They can sign in again with their password. To stop them from signing in, deactivate the account in Settings > Users.",
3090
+ { name: admin.name }
3091
+ );
3092
+ confirm = {
3093
+ title: includesThisBrowser ? t("adminPanel.confirm.self.title", "Sign yourself out?") : session ? t("adminPanel.confirm.one.title", "Sign {name} out of this browser?", {
3094
+ name: admin.name
3095
+ }) : t("adminPanel.confirm.all.title", "Sign {name} out everywhere?", { name: admin.name }),
3096
+ body: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 3, children: [
3097
+ /* @__PURE__ */ jsx(Dialog.Description, { children: body }),
3098
+ includesThisBrowser ? /* @__PURE__ */ jsx(PersistentAlert, { variant: "warning", children: t(
3099
+ "adminPanel.confirm.self.warning",
3100
+ "This includes the browser you are using now. You will be taken to the login page."
3101
+ ) }) : null
3102
+ ] }),
3103
+ label: session ? t("adminPanel.session.signOut", "Sign out") : t("adminPanel.actions.signOutEverywhereShort", "Sign out everywhere")
3104
+ };
3105
+ }
3106
+ const listProps = {
3107
+ admins,
3108
+ labelledBy: captionId,
3109
+ canRevoke: Boolean(canRevoke),
3110
+ onView: openDialog,
3111
+ onSignOutEverywhere: (admin, trigger) => askSignOut(admin, null, trigger),
3112
+ busy: refreshing
3113
+ };
3114
+ const policy = meta?.policy;
3115
+ const range = pagination.total > 0 ? {
3116
+ from: (pagination.page - 1) * pagination.pageSize + 1,
3117
+ to: Math.min(pagination.page * pagination.pageSize, pagination.total)
3118
+ } : null;
3119
+ return /* @__PURE__ */ jsx(
3120
+ PageShell,
3121
+ {
3122
+ headingId: "magic-sessionmanager-admin-panel-title",
3123
+ title: t("adminPanel.title", "Admin panel sessions"),
3124
+ subtitle: t(
3125
+ "adminPanel.subtitle",
3126
+ "Who is signed in to this Strapi admin panel. Your app’s users are under App users."
3127
+ ),
3128
+ primaryAction: /* @__PURE__ */ jsx(LinkButton, { tag: Link$1, to: SETTINGS_USERS_PATH, variant: "secondary", startIcon: /* @__PURE__ */ jsx(User, {}), children: t("adminPanel.manageUsers", "Manage admins") }),
3129
+ children: /* @__PURE__ */ jsxs(
3130
+ Flex,
3131
+ {
3132
+ ref: pageRef,
3133
+ tabIndex: -1,
3134
+ direction: "column",
3135
+ alignItems: "stretch",
3136
+ gap: 6,
3137
+ minWidth: 0,
3138
+ children: [
3139
+ /* @__PURE__ */ jsx(SessionViewNav, { current: "admins" }),
3140
+ !loading && loadError ? /* @__PURE__ */ jsx(
3141
+ PersistentAlert,
3142
+ {
3143
+ variant: "danger",
3144
+ action: /* @__PURE__ */ jsx(Button, { size: "S", variant: "secondary", onClick: fetchAdmins, children: t("common.tryAgain", "Try again") }),
3145
+ children: /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "span", children: t("adminPanel.error.load", "Admin sessions could not be loaded.") })
3146
+ }
3147
+ ) : null,
3148
+ loading ? /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsx(Loader, { children: t("adminPanel.loading", "Loading admins") }) }) : null,
3149
+ !loading && meta && !supported ? /* @__PURE__ */ jsx(
3150
+ EmptyStateLayout,
3151
+ {
3152
+ icon: /* @__PURE__ */ jsx(EmptyDocuments, { width: "16rem", height: "8.8rem", "aria-hidden": "true" }),
3153
+ content: t(
3154
+ "adminPanel.unsupported",
3155
+ "Admin panel sessions are not available on this Strapi version. They need Strapi 5 with session management (tested with 5.62)."
3156
+ )
3157
+ }
3158
+ ) : null,
3159
+ showData ? /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
3160
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx(Typography, { tag: "h2", children: t("adminPanel.stats.label", "Admin statistics") }) }),
3161
+ /* @__PURE__ */ jsxs(StatGrid, { columns: 3, label: t("adminPanel.stats.label", "Admin statistics"), children: [
3162
+ /* @__PURE__ */ jsx(
3163
+ StatCard,
3164
+ {
3165
+ icon: Check,
3166
+ tone: "success",
3167
+ label: t("adminPanel.stats.signedIn", "Signed-in admins"),
3168
+ value: stats.signedInAdmins,
3169
+ description: t(
3170
+ "adminPanel.stats.sessions",
3171
+ "{count, plural, one {# session} other {# sessions}} in total",
3172
+ { count: stats.activeSessions }
3173
+ ),
3174
+ ...statusCard("signed-in")
3175
+ }
3176
+ ),
3177
+ /* @__PURE__ */ jsx(
3178
+ StatCard,
3179
+ {
3180
+ icon: Cross,
3181
+ tone: "neutral",
3182
+ label: t("adminPanel.stats.notSignedIn", "Not signed in"),
3183
+ value: Math.max(0, stats.totalAdmins - stats.signedInAdmins),
3184
+ description: t(
3185
+ "adminPanel.stats.notSignedIn.detail",
3186
+ "Includes deactivated and invited accounts"
3187
+ ),
3188
+ ...statusCard("not-signed-in")
3189
+ }
3190
+ ),
3191
+ /* @__PURE__ */ jsx(
3192
+ StatCard,
3193
+ {
3194
+ icon: User,
3195
+ tone: "primary",
3196
+ label: t("adminPanel.stats.all", "All admins"),
3197
+ value: stats.totalAdmins,
3198
+ description: t(
3199
+ "adminPanel.stats.active",
3200
+ "{count, plural, one {# active account} other {# active accounts}}",
3201
+ { count: stats.activeAccounts }
3202
+ ),
3203
+ ...statusCard("all")
3204
+ }
3205
+ )
3206
+ ] })
3207
+ ] }) : null,
3208
+ showData ? /* @__PURE__ */ jsxs(
3209
+ PersistentAlert,
3210
+ {
3211
+ variant: "neutral",
3212
+ stacked: true,
3213
+ title: t("adminPanel.howItWorks.title", "How signing out works"),
3214
+ children: [
3215
+ /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "span", children: t(
3216
+ "adminPanel.howItWorks.body",
3217
+ "Signing out takes effect on the admin’s next click: Strapi checks the session on every admin request. They can sign in again with their password; to stop that, deactivate the account in Settings > Users. Admin API tokens are not affected. Strapi records no IP address for admin sessions."
3218
+ ) }),
3219
+ policy ? /* @__PURE__ */ jsxs(ReadableText, { variant: "omega", textColor: "neutral800", tag: "span", children: [
3220
+ " ",
3221
+ t(
3222
+ "adminPanel.howItWorks.policy",
3223
+ "Without activity a session ends after {idle}, or after {rememberIdle} when “Remember me” was ticked.",
3224
+ {
3225
+ idle: durationText(policy.idleSessionLifespan),
3226
+ rememberIdle: durationText(policy.idleRefreshTokenLifespan)
3227
+ }
3228
+ )
3229
+ ] }) : null
3230
+ ]
3231
+ }
3232
+ ) : null,
3233
+ showData ? /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 4, minWidth: 0, children: [
3234
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx(Typography, { variant: "delta", tag: "h2", children: t("adminPanel.list.heading", "Admin list") }) }),
3235
+ /* @__PURE__ */ jsxs(
3236
+ Flex,
3237
+ {
3238
+ direction: { initial: "column", medium: "row" },
3239
+ alignItems: { initial: "stretch", medium: "center" },
3240
+ gap: 2,
3241
+ "data-admin-toolbar": "",
3242
+ children: [
3243
+ /* @__PURE__ */ jsx(Flex, { flex: "1 1 auto", minWidth: 0, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsx(
3244
+ SessionSearch,
3245
+ {
3246
+ value: view.search,
3247
+ onSearch: handleSearch,
3248
+ label: t("adminPanel.search.label", "Search admins"),
3249
+ placeholder: t("adminPanel.search.placeholder", "Search name or email")
3250
+ }
3251
+ ) }),
3252
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", shrink: 0, children: [
3253
+ /* @__PURE__ */ jsx(
3254
+ Flex,
3255
+ {
3256
+ flex: isBelowMedium ? "1 1 auto" : void 0,
3257
+ minWidth: 0,
3258
+ direction: "column",
3259
+ alignItems: "stretch",
3260
+ children: /* @__PURE__ */ jsx(
3261
+ SingleSelect,
3262
+ {
3263
+ size: "S",
3264
+ "aria-label": t("adminPanel.filter.label", "Sign-in status"),
3265
+ value: view.filter,
3266
+ onChange: handleFilterChange,
3267
+ children: ADMIN_FILTER_OPTIONS.map((option) => /* @__PURE__ */ jsxs(SingleSelectOption, { value: option, children: [
3268
+ option === "all" && t("adminPanel.filter.all", "All admins"),
3269
+ option === "signed-in" && t("adminPanel.filter.signedIn", "Signed in"),
3270
+ option === "not-signed-in" && t("adminPanel.filter.notSignedIn", "Not signed in")
3271
+ ] }, option))
3272
+ }
3273
+ )
3274
+ }
3275
+ ),
3276
+ /* @__PURE__ */ jsx(
3277
+ IconButton,
3278
+ {
3279
+ label: t("adminPanel.actions.refresh", "Refresh admins"),
3280
+ onClick: () => fetchAdmins(),
3281
+ children: /* @__PURE__ */ jsx(ArrowClockwise, {})
3282
+ }
3283
+ )
3284
+ ] })
3285
+ ]
3286
+ }
3287
+ ),
3288
+ /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", gap: 4, wrap: "wrap", children: [
3289
+ /* @__PURE__ */ jsx(
3290
+ Typography,
3291
+ {
3292
+ id: captionId,
3293
+ ref: captionRef,
3294
+ tabIndex: -1,
3295
+ variant: "pi",
3296
+ textColor: "neutral600",
3297
+ "aria-live": "polite",
3298
+ "data-admin-caption": "",
3299
+ children: range ? t(
3300
+ "adminPanel.caption",
3301
+ "{from, number}–{to, number} of {total, plural, one {# admin} other {# admins}}",
3302
+ { ...range, total: pagination.total }
3303
+ ) : t("adminPanel.captionNone", "0 admins")
3304
+ }
3305
+ ),
3306
+ refreshing ? /* @__PURE__ */ jsx(Loader, { small: true, role: "status", "aria-live": "polite", children: t("adminPanel.refreshing", "Updating admins") }) : null
3307
+ ] }),
3308
+ admins.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
3309
+ isBelowMedium ? /* @__PURE__ */ jsx(AdminCardList, { ...listProps }) : /* @__PURE__ */ jsx(AdminTable, { ...listProps }),
3310
+ /* @__PURE__ */ jsx(PaginationTargets, { children: /* @__PURE__ */ jsxs(
3311
+ Pagination.Root,
3312
+ {
3313
+ pageCount: pagination.pageCount,
3314
+ total: pagination.total,
3315
+ defaultPageSize: Number(ADMIN_DEFAULT_PAGE_SIZE),
3316
+ children: [
3317
+ /* @__PURE__ */ jsx(Pagination.PageSize, { options: [...ADMIN_PAGE_SIZE_OPTIONS] }),
3318
+ /* @__PURE__ */ jsx(Pagination.Links, {})
3319
+ ]
3320
+ }
3321
+ ) })
3322
+ ] }) : /* @__PURE__ */ jsx(
3323
+ EmptyStateLayout,
3324
+ {
3325
+ icon: /* @__PURE__ */ jsx(EmptyDocuments, { width: "16rem", height: "8.8rem", "aria-hidden": "true" }),
3326
+ content: filtersActive ? t("adminPanel.noResults", "No admins match your search or filter.") : t("adminPanel.empty", "No admin accounts yet."),
3327
+ action: filtersActive ? /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: handleClearFilters, children: t("adminPanel.noResults.reset", "Clear filters") }) : null
3328
+ }
3329
+ )
3330
+ ] }) : null,
3331
+ selected ? /* @__PURE__ */ jsx(
3332
+ AdminSessionsModal,
3333
+ {
3334
+ admin: selected,
3335
+ sessions: dialogSessions,
3336
+ loading: dialogLoading && dialogSessions.length === 0,
3337
+ error: dialogError,
3338
+ onRetry: () => fetchDialogSessions(selected),
3339
+ canRevoke: Boolean(canRevoke),
3340
+ onSignOut: (session, trigger) => askSignOut(selected, session, trigger),
3341
+ onSignOutEverywhere: (trigger) => askSignOut(selected, null, trigger),
3342
+ onClose: closeDialog,
3343
+ onCloseAutoFocus: (event) => restoreDialogFocus(event, openerRef.current, captionRef.current || pageRef.current)
3344
+ }
3345
+ ) : null,
3346
+ confirm ? /* @__PURE__ */ jsx(
3347
+ ConfirmAction,
3348
+ {
3349
+ isOpen: true,
3350
+ onOpenChange: (open) => {
3351
+ if (!open) setPending(null);
3352
+ },
3353
+ title: confirm.title,
3354
+ body: confirm.body,
3355
+ confirmLabel: confirm.label,
3356
+ onConfirm: confirmSignOut,
3357
+ returnFocusRef: confirmReturnRef,
3358
+ fallbackFocusRef: captionRef
3359
+ }
3360
+ ) : null
3361
+ ]
3362
+ }
3363
+ )
3364
+ }
3365
+ );
3366
+ };
2352
3367
  const App = () => {
2353
- return /* @__PURE__ */ jsx(Page.Protect, { permissions: pluginPermissions.access, children: /* @__PURE__ */ jsx(HomePage, {}) });
3368
+ return /* @__PURE__ */ jsx(Page.Protect, { permissions: pluginPermissions.access, children: /* @__PURE__ */ jsxs(Routes, { children: [
3369
+ /* @__PURE__ */ jsx(Route, { index: true, element: /* @__PURE__ */ jsx(HomePage, {}) }),
3370
+ /* @__PURE__ */ jsx(
3371
+ Route,
3372
+ {
3373
+ path: "admin-panel",
3374
+ element: /* @__PURE__ */ jsx(Page.Protect, { permissions: pluginPermissions.adminSessionsRead, children: /* @__PURE__ */ jsx(AdminPanelPage, {}) })
3375
+ }
3376
+ ),
3377
+ /* @__PURE__ */ jsx(Route, { path: "*", element: /* @__PURE__ */ jsx(HomePage, {}) })
3378
+ ] }) });
2354
3379
  };
2355
3380
  export {
2356
3381
  App as default