2024-03-08 14:58:36 +01:00
|
|
|
import {
|
|
|
|
Badge,
|
|
|
|
Box,
|
|
|
|
Container,
|
|
|
|
Flex,
|
|
|
|
Heading,
|
2024-04-16 16:56:59 +02:00
|
|
|
SkeletonText,
|
2024-03-08 14:58:36 +01:00
|
|
|
Table,
|
|
|
|
TableContainer,
|
|
|
|
Tbody,
|
|
|
|
Td,
|
|
|
|
Th,
|
|
|
|
Thead,
|
|
|
|
Tr,
|
2024-03-17 17:28:45 +01:00
|
|
|
} from "@chakra-ui/react"
|
2024-04-16 16:56:59 +02:00
|
|
|
import { useQueryClient, useSuspenseQuery } from "@tanstack/react-query"
|
2024-04-08 15:49:22 -05:00
|
|
|
import { createFileRoute } from "@tanstack/react-router"
|
2024-03-07 19:16:23 +01:00
|
|
|
|
2024-04-16 16:56:59 +02:00
|
|
|
import { Suspense } from "react"
|
2024-04-06 18:26:12 -05:00
|
|
|
import { type UserPublic, UsersService } from "../../client"
|
2024-03-17 17:28:45 +01:00
|
|
|
import ActionsMenu from "../../components/Common/ActionsMenu"
|
|
|
|
import Navbar from "../../components/Common/Navbar"
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-03-17 17:28:45 +01:00
|
|
|
export const Route = createFileRoute("/_layout/admin")({
|
2024-03-08 14:58:36 +01:00
|
|
|
component: Admin,
|
2024-03-07 19:16:23 +01:00
|
|
|
})
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-04-16 16:56:59 +02:00
|
|
|
const MembersTableBody = () => {
|
2024-03-08 14:58:36 +01:00
|
|
|
const queryClient = useQueryClient()
|
2024-04-06 18:26:12 -05:00
|
|
|
const currentUser = queryClient.getQueryData<UserPublic>(["currentUser"])
|
2024-04-16 16:56:59 +02:00
|
|
|
|
|
|
|
const { data: users } = useSuspenseQuery({
|
2024-04-04 16:30:42 +02:00
|
|
|
queryKey: ["users"],
|
|
|
|
queryFn: () => UsersService.readUsers({}),
|
|
|
|
})
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-04-16 16:56:59 +02:00
|
|
|
return (
|
|
|
|
<Tbody>
|
|
|
|
{users.data.map((user) => (
|
|
|
|
<Tr key={user.id}>
|
|
|
|
<Td color={!user.full_name ? "ui.dim" : "inherit"}>
|
|
|
|
{user.full_name || "N/A"}
|
|
|
|
{currentUser?.id === user.id && (
|
|
|
|
<Badge ml="1" colorScheme="teal">
|
|
|
|
You
|
|
|
|
</Badge>
|
|
|
|
)}
|
|
|
|
</Td>
|
|
|
|
<Td>{user.email}</Td>
|
|
|
|
<Td>{user.is_superuser ? "Superuser" : "User"}</Td>
|
|
|
|
<Td>
|
|
|
|
<Flex gap={2}>
|
|
|
|
<Box
|
|
|
|
w="2"
|
|
|
|
h="2"
|
|
|
|
borderRadius="50%"
|
|
|
|
bg={user.is_active ? "ui.success" : "ui.danger"}
|
|
|
|
alignSelf="center"
|
|
|
|
/>
|
|
|
|
{user.is_active ? "Active" : "Inactive"}
|
|
|
|
</Flex>
|
|
|
|
</Td>
|
|
|
|
<Td>
|
|
|
|
<ActionsMenu
|
|
|
|
type="User"
|
|
|
|
value={user}
|
|
|
|
disabled={currentUser?.id === user.id ? true : false}
|
|
|
|
/>
|
|
|
|
</Td>
|
|
|
|
</Tr>
|
|
|
|
))}
|
|
|
|
</Tbody>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const MembersBodySkeleton = () => {
|
|
|
|
return (
|
|
|
|
<Tbody>
|
|
|
|
<Tr>
|
|
|
|
{new Array(5).fill(null).map((_, index) => (
|
|
|
|
<Td key={index}>
|
|
|
|
<SkeletonText noOfLines={1} paddingBlock="16px" />
|
|
|
|
</Td>
|
|
|
|
))}
|
|
|
|
</Tr>
|
|
|
|
</Tbody>
|
|
|
|
)
|
|
|
|
}
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-04-16 16:56:59 +02:00
|
|
|
function Admin() {
|
2024-03-08 14:58:36 +01:00
|
|
|
return (
|
2024-04-16 16:56:59 +02:00
|
|
|
<Container maxW="full">
|
|
|
|
<Heading size="lg" textAlign={{ base: "center", md: "left" }} pt={12}>
|
|
|
|
User Management
|
|
|
|
</Heading>
|
|
|
|
<Navbar type={"User"} />
|
|
|
|
<TableContainer>
|
|
|
|
<Table fontSize="md" size={{ base: "sm", md: "md" }}>
|
|
|
|
<Thead>
|
|
|
|
<Tr>
|
|
|
|
<Th width="20%">Full name</Th>
|
|
|
|
<Th width="50%">Email</Th>
|
|
|
|
<Th width="10%">Role</Th>
|
|
|
|
<Th width="10%">Status</Th>
|
|
|
|
<Th width="10%">Actions</Th>
|
|
|
|
</Tr>
|
|
|
|
</Thead>
|
|
|
|
<Suspense fallback={<MembersBodySkeleton />}>
|
|
|
|
<MembersTableBody />
|
|
|
|
</Suspense>
|
|
|
|
</Table>
|
|
|
|
</TableContainer>
|
|
|
|
</Container>
|
2024-03-08 14:58:36 +01:00
|
|
|
)
|
2024-02-12 16:46:51 -05:00
|
|
|
}
|