journal.pl/src/pages/user-page.tsx
Primakov Alexandr Alexandrovich 87c08e18bd
All checks were successful
platform/bro/pipeline/head This commit looks good
fix: поправил автоподстановку даты в форму редактирования лекции [#29]
2024-08-12 16:30:01 +03:00

91 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React from 'react'
import { useParams } from 'react-router-dom'
import { api } from '../__data__/api/api'
import dayjs from 'dayjs'
import {
Alert,
AlertIcon,
Box,
Center,
Container,
Spinner,
Text,
} from '@chakra-ui/react'
import { UserCard } from '../components/user-card'
const UserPage = () => {
const { lessonId, accessId } = useParams()
const acc = api.useGetAccessQuery({ accessCode: accessId })
const ls = api.useLessonByIdQuery(lessonId, {
pollingInterval: 1000,
skipPollingIfUnfocused: true,
})
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>
)
}
return (
<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>
<span>{dayjs(ls.data?.body?.date).format('DD MMMM YYYYг.')}</span>
</Box>
<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>
)
}
export default UserPage