From 472e0f254bdd9df866fa69d2837d143a02ae2abd Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Tue, 16 Apr 2024 16:56:59 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20Use=20useSuspenseQuery=20to=20fe?= =?UTF-8?q?tch=20members=20and=20show=20skeleton=20(#1174)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/routes/_layout/admin.tsx | 165 +++++++++++++------------- 1 file changed, 81 insertions(+), 84 deletions(-) diff --git a/frontend/src/routes/_layout/admin.tsx b/frontend/src/routes/_layout/admin.tsx index e785ddf..800317b 100644 --- a/frontend/src/routes/_layout/admin.tsx +++ b/frontend/src/routes/_layout/admin.tsx @@ -4,7 +4,7 @@ import { Container, Flex, Heading, - Spinner, + SkeletonText, Table, TableContainer, Tbody, @@ -13,106 +13,103 @@ import { Thead, Tr, } from "@chakra-ui/react" -import { useQuery, useQueryClient } from "@tanstack/react-query" +import { useQueryClient, useSuspenseQuery } from "@tanstack/react-query" import { createFileRoute } from "@tanstack/react-router" +import { Suspense } from "react" import { type UserPublic, UsersService } from "../../client" import ActionsMenu from "../../components/Common/ActionsMenu" import Navbar from "../../components/Common/Navbar" -import useCustomToast from "../../hooks/useCustomToast" export const Route = createFileRoute("/_layout/admin")({ component: Admin, }) -function Admin() { +const MembersTableBody = () => { const queryClient = useQueryClient() - const showToast = useCustomToast() const currentUser = queryClient.getQueryData(["currentUser"]) - const { - data: users, - isLoading, - isError, - error, - } = useQuery({ + + const { data: users } = useSuspenseQuery({ queryKey: ["users"], queryFn: () => UsersService.readUsers({}), }) - if (isError) { - const errDetail = (error as any).body?.detail - showToast("Something went wrong.", `${errDetail}`, "error") - } + return ( + + {users.data.map((user) => ( + + + {user.full_name || "N/A"} + {currentUser?.id === user.id && ( + + You + + )} + + {user.email} + {user.is_superuser ? "Superuser" : "User"} + + + + {user.is_active ? "Active" : "Inactive"} + + + + + + + ))} + + ) +} + +const MembersBodySkeleton = () => { + return ( + + + {new Array(5).fill(null).map((_, index) => ( + + + + ))} + + + ) +} +function Admin() { return ( - <> - {isLoading ? ( - // TODO: Add skeleton - - - - ) : ( - users && ( - - - User Management - - - - - - - - - - - - - - - {users.data.map((user) => ( - - - - - - - - ))} - -
Full nameEmailRoleStatusActions
- {user.full_name || "N/A"} - {currentUser?.id === user.id && ( - - You - - )} - {user.email}{user.is_superuser ? "Superuser" : "User"} - - - {user.is_active ? "Active" : "Inactive"} - - - -
-
-
- ) - )} - + + + User Management + + + + + + + + + + + + + + }> + + +
Full nameEmailRoleStatusActions
+
+
) }