From c16173ea0fdbf6cc47b13756c0a77e8399669055 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sat, 12 Oct 2024 16:47:22 +0000 Subject: feature: Introduce a mechanism to cleanup dangling assets --- apps/web/components/dashboard/admin/UserList.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'apps/web/components/dashboard/admin/UserList.tsx') diff --git a/apps/web/components/dashboard/admin/UserList.tsx b/apps/web/components/dashboard/admin/UserList.tsx index 024325a3..65bf4068 100644 --- a/apps/web/components/dashboard/admin/UserList.tsx +++ b/apps/web/components/dashboard/admin/UserList.tsx @@ -15,10 +15,18 @@ import { api } from "@/lib/trpc"; import { Trash } from "lucide-react"; import { useSession } from "next-auth/react"; +function toHumanReadableSize(size: number) { + const sizes = ["Bytes", "KB", "MB", "GB", "TB"]; + if (size === 0) return "0 Bytes"; + const i = Math.floor(Math.log(size) / Math.log(1024)); + return (size / Math.pow(1024, i)).toFixed(2) + " " + sizes[i]; +} + export default function UsersSection() { const { data: session } = useSession(); const invalidateUserList = api.useUtils().users.list.invalidate; const { data: users } = api.users.list.useQuery(); + const { data: userStats } = api.admin.userStats.useQuery(); const { mutate: deleteUser, isPending: isDeletionPending } = api.users.delete.useMutation({ onSuccess: () => { @@ -35,7 +43,7 @@ export default function UsersSection() { }, }); - if (!users) { + if (!users || !userStats) { return ; } @@ -47,6 +55,8 @@ export default function UsersSection() { Name Email + Num Bookmarks + Asset Sizes Role Action @@ -55,6 +65,12 @@ export default function UsersSection() { {u.name} {u.email} + + {userStats[u.id].numBookmarks} + + + {toHumanReadableSize(userStats[u.id].assetSizes)} + {u.role}