diff --git a/src/pages/UserPage.tsx b/src/pages/UserPage.tsx index d017f50..0b04ebb 100644 --- a/src/pages/UserPage.tsx +++ b/src/pages/UserPage.tsx @@ -1,44 +1,24 @@ -import React, { useCallback, useEffect, useState } from 'react'; -import { useParams } from 'react-router-dom'; +import React from 'react' +import { useParams } from 'react-router-dom' -import { ArrowImg, IconButton, InputElement, InputLabel, InputWrapper, LessonItem, Lessonname, MainWrapper, StartWrapper } from './style'; -import arrow from '../assets/36-arrow-right.svg'; -import { api } from '../__data__/api/api'; -import dayjs from 'dayjs'; +import { + ErrorSpan, + LessonItem, + Lessonname, + MainWrapper, + StartWrapper, +} from './style' +import { api } from '../__data__/api/api' +import dayjs from 'dayjs' export const UserPage = () => { - const [socketId, setSocketId] = useState(null); - const [error, setError] = useState(null); - const { lessonId, accessId } = useParams(); + const { lessonId, accessId } = useParams() const acc = api.useGetAccessQuery({ accessCode: accessId }) const ls = api.useLessonByIdQuery(lessonId, { pollingInterval: 1000, - skipPollingIfUnfocused: true - }); - - useEffect(() => { - // socket.on('connect', () => { - // const id = localStorage.getItem('socketId'); - // if (!id) { - // localStorage.setItem('socketId', socket.id); - // setSocketId(socket.id); - // } else { - // setSocketId(id); - // } - - // const name = localStorage.getItem('name'); - // if (name) { - // const socket = getSocket(); - // socket.emit('add', { socketId: id || socket.id, name, lessonid: lessonId }); - // } - // }) - // socket.on('error', data => { - // setError(data) - // }) - }, []); - - const [value, setValue] = useState(localStorage.getItem('name') || ''); + skipPollingIfUnfocused: true, + }) return ( @@ -46,13 +26,25 @@ export const UserPage = () => { {acc.isLoading &&

Отправляем запрос

} {acc.isSuccess &&

Успешно

} + {acc.error && + (acc as any).error?.data?.body?.errorMessage === + 'Code is expired' && ( +
+ + Не удалось активировать код доступа. Попробуйте отсканировать + код еще раз + +
+ )}

Тема занятия - {ls.data?.body?.name}

{dayjs(ls.data?.body?.date).format('DD MMMM YYYYг.')} diff --git a/src/pages/style.ts b/src/pages/style.ts index b44e618..703e80f 100644 --- a/src/pages/style.ts +++ b/src/pages/style.ts @@ -4,7 +4,7 @@ import { css, keyframes } from '@emotion/react' export const MainWrapper = styled.main` display: flex; justify-content: center; - align-items: center; + /* align-items: center; */ height: 100%; ` diff --git a/stubs/api/index.js b/stubs/api/index.js index 9bcc5f3..1759530 100644 --- a/stubs/api/index.js +++ b/stubs/api/index.js @@ -21,10 +21,10 @@ router.post('/lesson/access-code', (req, res) => { }) router.get('/lesson/access-code/:accessCode', (req, res) => { - res.send(require('../mocks/lessons/access-code/get/success.json')) + res.status(400).send(require('../mocks/lessons/access-code/get/error.json')) }) -router.get('/api/lesson/:lessonId', (req, res) => { +router.get('/lesson/:lessonId', (req, res) => { res.send(require('../mocks/lessons/byid/success.json')) }) diff --git a/stubs/mocks/lessons/access-code/get/error.json b/stubs/mocks/lessons/access-code/get/error.json new file mode 100644 index 0000000..5dbe185 --- /dev/null +++ b/stubs/mocks/lessons/access-code/get/error.json @@ -0,0 +1 @@ +{ "success": false, "body": { "errorMessage": "Code is expired" } }