Skip to content

Commit

Permalink
feat: Moved API call to Home Page
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-merlin committed Mar 28, 2024
1 parent 314cb67 commit 9c7d042
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
17 changes: 4 additions & 13 deletions src/components/TableDashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { Table, Thead, Tbody, Tr, Th, TableContainer } from '@chakra-ui/react'
import { getAllUsers } from '../api/lib/users'
import { type User } from '../types/index'
import React from 'react'

function TableDashboard (): JSX.Element {
const [members, setMembers] = React.useState<User[]>([])

React.useEffect(() => {
void getAllUsers().then((response) => {
setMembers(response.data as User[])
})
}, [])

function TableDashboard ({ members }: { members: User[] }): JSX.Element {
return (
<TableContainer>
<Table variant="simple" size='md'>
Expand All @@ -25,10 +16,10 @@ function TableDashboard (): JSX.Element {
</Thead>
<Tbody>
{members
.sort((a, b) => {
.sort((a: User, b: User) => {
return a.displayName.localeCompare(b.displayName)
}).filter((user) => !user.enabled)
.map(({ displayName, email, enabled }) =>
}).filter((user: User) => !user.enabled)
.map(({ displayName, email, enabled }: User) => // Add type annotation for User
<Tr key={email}>
<Th>{displayName}</Th>
<Th>{email}</Th>
Expand Down
13 changes: 12 additions & 1 deletion src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { Container, HStack } from '@chakra-ui/react'
import TableDashboard from '../components/TableDashboard'
import Sidebar from '../components/Sidebar'
import { getAllUsers } from '../api/lib/users'
import { type User } from '../types/index'
import React, { useEffect } from 'react'

function HomePage (): JSX.Element {
const [members, setMembers] = React.useState<User[]>([])

useEffect(() => {
void getAllUsers().then((response) => {
setMembers(response.data as User[])
})
}, [])

return (
<HStack height="100vh" spacing="0">
<Sidebar />
<Container>
<TableDashboard />
<TableDashboard members={members} />
</Container>
</HStack>
)
Expand Down

0 comments on commit 9c7d042

Please sign in to comment.