Skip to content

Commit

Permalink
Move SampleTableDashboard code to TableDashboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
cengelbart39 committed Mar 1, 2024
1 parent eb70b3d commit 042e74d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 86 deletions.
38 changes: 0 additions & 38 deletions src/components/SampleTableDashboard.tsx

This file was deleted.

74 changes: 28 additions & 46 deletions src/components/TableDashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,36 @@
import {
Table,
Thead,
Tr,
Th,
TableContainer,
Td,
Tbody
} from '@chakra-ui/react'
import { getAllUsers } from '../api/lib/users'
import { useEffect, useState } from 'react'
import { type User } from '../types'
import { Table, Thead, Tbody, Tr, Th, TableContainer } from '@chakra-ui/react'
import React from 'react'
import sampleUserData from '../sample_data.json'

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()
}, [])
const [sampleData] = React.useState(sampleUserData)

return (
<TableContainer>
<Table variant='simple'>
<Thead>
<Tr>
<Th>Name</Th>
<Th>Email</Th>
<Th>Title</Th>
<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>
<Table variant="simple" size='md'>
<Thead>
<Tr>
<Th>Name</Th>
<Th>Email</Th>
<Th>Title</Th>
<Th>Status</Th>
</Tr>
</Thead>
<Tbody>
{sampleData && Object.values(sampleData.Users)
.sort((a, b) => {
return a.Displayname.localeCompare(b.Displayname)
}).filter((user) => !user.Disabled)
.map(({ Displayname, Email, Disabled }) =>
<Tr key={Email}>
<Th>{Displayname}</Th>
<Th>{Email}</Th>
<Th></Th>
<Th>{Disabled ? 'Inactive' : 'Active'}</Th>
</Tr>
)}
</Tbody>
</Table>
</TableContainer>
)
}
Expand Down
2 changes: 0 additions & 2 deletions src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Container, HStack } from '@chakra-ui/react'
import TableDashboard from '../components/TableDashboard'
import Sidebar from '../components/Sidebar'
import SampleTableDashboard from '../components/SampleTableDashboard'

function HomePage (): JSX.Element {
return (
<HStack height="100vh" spacing="0">
<Sidebar />
<Container>
<SampleTableDashboard />
<TableDashboard />
</Container>
</HStack>
Expand Down

0 comments on commit 042e74d

Please sign in to comment.