Skip to content

Commit

Permalink
feat: Added API call to Table component
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-merlin committed Feb 22, 2024
1 parent 4aebd18 commit 6312b3d
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/components/TableDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,30 @@ import {
Thead,
Tr,
Th,
TableContainer
TableContainer,
Td,
Tbody
} from '@chakra-ui/react'
import { getAllUsers } from '../api/lib/users'
import { useEffect, useState } from 'react'
import { type User } from '../types'

function TableDashboard (): JSX.Element {
const [users, setUsers] = useState<User[]>([])
useEffect(() => {
const fetchUsers = async (): Promise<void> => {
try {
const response = await getAllUsers()
if (response.data) {
setUsers(response.data as User[])
}
} catch (error) {
console.error('Error fetching users: ', error)
}
}
void fetchUsers()
}, [])

return (
<TableContainer>
<Table variant='simple'>
Expand All @@ -18,6 +38,16 @@ function TableDashboard (): JSX.Element {
<Th>Status</Th>
</Tr>
</Thead>
<Tbody>
{users.map((user, index) => (
<Tr key={index}>
<Td>{user.displayName}</Td>
<Td>{user.email}</Td>
<Td>{user.role}</Td>
<Td>{user.enabled}</Td>
</Tr>
))}
</Tbody>
</Table>
</TableContainer>
)
Expand Down

0 comments on commit 6312b3d

Please sign in to comment.