journal.pl/src/pages/UserPage.tsx

55 lines
1.6 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 {
ErrorSpan,
LessonItem,
Lessonname,
MainWrapper,
StartWrapper,
} from './style'
import { api } from '../__data__/api/api'
import dayjs from 'dayjs'
2023-04-16 12:18:29 +03:00
export 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
2023-04-16 12:18:29 +03:00
return (
<MainWrapper>
<StartWrapper>
2024-03-01 11:43:31 +03:00
{acc.isLoading && <h1>Отправляем запрос</h1>}
{acc.isSuccess && <h1>Успешно</h1>}
2024-03-01 12:16:13 +03:00
{acc.error &&
(acc as any).error?.data?.body?.errorMessage ===
'Code is expired' && (
<div style={{ padding: 12, marginTop: 24, fontSize: 36 }}>
<ErrorSpan>
Не удалось активировать код доступа. Попробуйте отсканировать
код еще раз
</ErrorSpan>
</div>
)}
2024-03-01 11:43:31 +03:00
<h1>Тема занятия - {ls.data?.body?.name}</h1>
<span>{dayjs(ls.data?.body?.date).format('DD MMMM YYYYг.')}</span>
<ul style={{ paddingLeft: 0 }}>
{ls.data?.body?.students?.map((student, index) => (
<LessonItem key={index}>
2024-03-01 12:16:13 +03:00
<Lessonname>
{student.name || student.preferred_username}
</Lessonname>
2024-03-01 11:43:31 +03:00
</LessonItem>
))}
</ul>
2023-04-16 12:18:29 +03:00
</StartWrapper>
</MainWrapper>
)
}