import React, { useEffect, useState } from 'react'; import { Badge, Box, Container, Flex, Heading, Spinner, Table, TableContainer, Tbody, Td, Th, Thead, Tr } from '@chakra-ui/react'; import { ApiError } from '../client'; import ActionsMenu from '../components/Common/ActionsMenu'; import Navbar from '../components/Common/Navbar'; import useCustomToast from '../hooks/useCustomToast'; import { useUserStore } from '../store/user-store'; import { useUsersStore } from '../store/users-store'; const Admin: React.FC = () => { const showToast = useCustomToast(); const [isLoading, setIsLoading] = useState(false); const { users, getUsers } = useUsersStore(); const { user: currentUser } = useUserStore(); useEffect(() => { const fetchUsers = async () => { setIsLoading(true); try { await getUsers(); } catch (err) { const errDetail = (err as ApiError).body.detail; showToast('Something went wrong.', `${errDetail}`, 'error'); } finally { setIsLoading(false); } } if (users.length === 0) { fetchUsers(); } }, []) return ( <> {isLoading ? ( // TODO: Add skeleton ) : ( users && User Management Full name Email Role Status Actions {users.map((user) => ( {user.full_name || 'N/A'}{currentUser?.id === user.id && You} {user.email} {user.is_superuser ? 'Superuser' : 'User'} {user.is_active ? 'Active' : 'Inactive'} ))} )} > ) } export default Admin;