Skip to content

Commit

Permalink
feat: Added alert message on failed API call
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-merlin committed Mar 28, 2024
1 parent 9c7d042 commit 3ba975e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import { Container, HStack } from '@chakra-ui/react'
import { Container, HStack, Text } 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'
import React, { useEffect, useState } from 'react'

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

useEffect(() => {
void getAllUsers().then((response) => {
setMembers(response.data as User[])
}).catch((error) => {
console.error(error)
setError('Failed to load Blueprint members. Please try again later.')
})
}, [])

return (
<HStack height="100vh" spacing="0">
<Sidebar />
<Container>
<TableDashboard members={members} />
{error ? (<Text color="red.500">{error}</Text>) : (<TableDashboard members={members} />)}
</Container>
</HStack>
)
Expand Down

0 comments on commit 3ba975e

Please sign in to comment.