From ac62158de9f0201c36e4fb0f02cc249b2ad5e1c8 Mon Sep 17 00:00:00 2001 From: LandaMm Date: Sun, 15 Jun 2025 19:27:02 +0200 Subject: [PATCH] feat: pagination + session revoking UI --- web/src/pages/Admin/UserSessions/index.tsx | 62 +++++++++++++--------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/web/src/pages/Admin/UserSessions/index.tsx b/web/src/pages/Admin/UserSessions/index.tsx index e3e7950..6da72fa 100644 --- a/web/src/pages/Admin/UserSessions/index.tsx +++ b/web/src/pages/Admin/UserSessions/index.tsx @@ -1,13 +1,14 @@ -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 type { DeviceInfo } from "@/types"; import { Ban } from "lucide-react"; -import { useEffect, useMemo, useState, type FC } from "react"; +import { useCallback, useEffect, useMemo, type FC } from "react"; import { Link } from "react-router"; import moment from "moment"; import Pagination from "@/components/ui/pagination"; +import { useUserSessions } from "@/store/admin/userSessions"; +import { useAuth } from "@/store/auth"; const SessionSource: FC<{ deviceInfo: string }> = ({ deviceInfo }) => { const parsed = useMemo( @@ -23,20 +24,29 @@ const SessionSource: FC<{ deviceInfo: string }> = ({ deviceInfo }) => { }; const AdminSessionsPage: FC = () => { - const loading = false; - const [sessions, setSessions] = useState([]); + const loading = useUserSessions((s) => s.loading); + const sessions = useUserSessions((s) => s.items); + + const page = useUserSessions((s) => s.page); + const totalPages = useUserSessions((s) => s.totalPages); + + const fetchSessions = useUserSessions((s) => s.fetch); + const revokeSession = useUserSessions((s) => s.revoke); + + const revokingId = useUserSessions((s) => s.revokingId); + + const profile = useAuth((s) => s.profile); + + const handleRevokeSession = useCallback( + (id: string) => { + revokeSession(id); + }, + [revokeSession], + ); useEffect(() => { - adminGetUserSessionsApi({ - limit: 10, - offset: 0, - }).then((res) => { - console.log("get sessions response:", res); - if (Array.isArray(res)) { - return setSessions(res); - } - }); - }, []); + fetchSessions(1); + }, [fetchSessions]); return (
@@ -113,11 +123,6 @@ const AdminSessionsPage: FC = () => { key={session.id} className="hover:bg-gray-50 dark:hover:bg-gray-800" > - {/* - - {sessionsType} - - */}
{typeof session.user?.profile_picture === "string" && ( @@ -126,9 +131,11 @@ const AdminSessionsPage: FC = () => { className="w-7 h-7 min-w-7" /> )} - -

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

+ {session.user?.full_name ?? ""}{" "} + {session.user_id === profile?.id ? "(You)" : ""}

@@ -177,6 +184,8 @@ const AdminSessionsPage: FC = () => { @@ -187,9 +196,12 @@ const AdminSessionsPage: FC = () => { )} - -
+ fetchSessions(newPage)} + totalPages={totalPages} + /> ); };