diff --git a/web/src/pages/Admin/UserSessions/index.tsx b/web/src/pages/Admin/UserSessions/index.tsx new file mode 100644 index 0000000..e3e7950 --- /dev/null +++ b/web/src/pages/Admin/UserSessions/index.tsx @@ -0,0 +1,197 @@ +import { adminGetUserSessionsApi } from "@/api/admin/sessions"; +import Breadcrumbs from "@/components/ui/breadcrumbs"; +import { Button } from "@/components/ui/button"; +import Avatar from "@/feature/Avatar"; +import type { DeviceInfo, UserSession } from "@/types"; +import { Ban } from "lucide-react"; +import { useEffect, useMemo, useState, type FC } from "react"; +import { Link } from "react-router"; +import moment from "moment"; +import Pagination from "@/components/ui/pagination"; + +const SessionSource: FC<{ deviceInfo: string }> = ({ deviceInfo }) => { + const parsed = useMemo( + () => JSON.parse(atob(deviceInfo)), + [deviceInfo], + ); + + return ( +

+ {parsed.os} {parsed.os_version} {parsed.browser} {parsed.browser_version} +

+ ); +}; + +const AdminSessionsPage: FC = () => { + const loading = false; + const [sessions, setSessions] = useState([]); + + useEffect(() => { + adminGetUserSessionsApi({ + limit: 10, + offset: 0, + }).then((res) => { + console.log("get sessions response:", res); + if (Array.isArray(res)) { + return setSessions(res); + } + }); + }, []); + + return ( +
+
+ +
+
+

Search...

+ {/* TODO: Filters */} +
+ +
+ + {loading && ( +
+
+ Loading... +
+
+ )} + + + + + + + + + + + + + + + {!loading && sessions.length === 0 ? ( + + + + ) : ( + sessions.map((session) => ( + + {/* */} + + + + + + + + + + )) + )} + +
+ User + + Source + + Status + + Issued At + + Expires At + + Last Active + + Revoked At + + Actions +
+ No sessions found. +
+ + {sessionsType} + + +
+ {typeof session.user?.profile_picture === "string" && ( + + )} + +

+ {session.user?.full_name ?? ""} +

+ +
+
+ + + + {session.is_active ? "Active" : "Inactive"} + {moment(session.expires_at).isSameOrBefore( + moment(new Date()), + ) && " (Expired)"} + + + {moment(session.issued_at).format("LLLL")} + + {session.expires_at + ? moment(session.expires_at).format("LLLL") + : "never"} + + {session.last_active + ? moment(session.last_active).format("LLLL") + : "never"} + + {session.revoked_at + ? new Date(session.revoked_at).toLocaleString() + : "never"} + +
+ +
+
+ + +
+
+ ); +}; + +export default AdminSessionsPage;