journal.pl/src/pages/user-page.tsx

93 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-03-01 12:16:13 +03:00
import React from 'react'
import { useParams } from 'react-router-dom'
import { api } from '../__data__/api/api'
import dayjs from 'dayjs'
2024-04-03 22:00:17 +03:00
import {
Alert,
AlertIcon,
Box,
Center,
Container,
Heading,
Spinner,
Text,
Stack,
} from '@chakra-ui/react'
import { UserCard } from '../components/user-card'
2023-04-16 12:18:29 +03:00
const UserPage = () => {
2024-03-01 12:16:13 +03:00
const { lessonId, accessId } = useParams()
2024-03-01 11:43:31 +03:00
const acc = api.useGetAccessQuery({ accessCode: accessId })
const ls = api.useLessonByIdQuery(lessonId, {
pollingInterval: 1000,
2024-03-01 12:16:13 +03:00
skipPollingIfUnfocused: true,
})
2023-04-16 12:30:42 +03:00
2024-04-03 22:00:17 +03:00
if (acc.isLoading) {
return (
<Container maxW="container.xl">
<Center h="300px">
<Spinner
thickness="4px"
speed="0.65s"
emptyColor="gray.200"
color="blue.500"
size="xl"
/>
</Center>
</Container>
)
}
2023-04-16 12:18:29 +03:00
return (
2024-04-03 22:00:17 +03:00
<Container>
{acc.isLoading && <h1>Отправляем запрос</h1>}
{acc.isSuccess && <h1>Успешно</h1>}
{acc.error && (
<Box mb="6" mt="2">
<Alert status="warning">
<AlertIcon />
{(acc as any).error?.data?.body?.errorMessage ===
'Code is expired' ? (
'Не удалось активировать код доступа. Попробуйте отсканировать код ещё раз'
) : (
<pre>{JSON.stringify(acc.error, null, 4)}</pre>
)}
</Alert>
</Box>
)}
<Box mb={6}>
<Text fontSize={18} fontWeight={600} as="h1" mt="4" mb="3">
Тема занятия: {ls.data?.body?.name}
</Text>
2024-03-01 11:43:31 +03:00
<span>{dayjs(ls.data?.body?.date).format('DD MMMM YYYYг.')}</span>
2024-04-03 22:00:17 +03:00
</Box>
2024-03-01 11:43:31 +03:00
2024-04-03 22:00:17 +03:00
<Box
as="ul"
display="flex"
flexWrap="wrap"
justifyContent="center"
gap={3}
>
{ls.data?.body?.students?.map((student) => (
<UserCard
width="40%"
wrapperAS="li"
key={student.sub}
student={student}
present
/>
))}
</Box>
</Container>
2023-04-16 12:18:29 +03:00
)
}
export default UserPage