diff --git a/Lab5/data.json b/Lab5/data.json index 6124570..5f3aadf 100644 --- a/Lab5/data.json +++ b/Lab5/data.json @@ -1,4 +1,11 @@ { + "entrysData": [ + { + "id": 0, + "login": "dyctator", + "password": "12345" + } + ], "directions": [ { "id": 0, diff --git a/Lab5/src/components/Directions/direct/Directions.jsx b/Lab5/src/components/Directions/direct/Directions.jsx index 6143454..74b0a0a 100644 --- a/Lab5/src/components/Directions/direct/Directions.jsx +++ b/Lab5/src/components/Directions/direct/Directions.jsx @@ -24,10 +24,10 @@ const Directions = () => { || item.things.toLowerCase().includes(searchValue.toLowerCase()) || item.code.toLowerCase().includes(searchValue.toLowerCase())) { return ; - } - return null; - }) - } + } + return null; + }) + } diff --git a/Lab5/src/components/logins/hooks/EntrysDataHook.js b/Lab5/src/components/logins/hooks/EntrysDataHook.js index 62b534e..5367865 100644 --- a/Lab5/src/components/logins/hooks/EntrysDataHook.js +++ b/Lab5/src/components/logins/hooks/EntrysDataHook.js @@ -1,34 +1,22 @@ import { useEffect, useState } from 'react'; import EntrysDataApiService from '../service/EntrysDataApiService'; -const useEntysDataItem = (id) => { - const emptyItem = { - id: '', - date: '', - name: '', - description: '', - image: '', - }; - const [item, setItem] = useState({ ...emptyItem }); +const useEntrysData = () => { + const [entrys, setEntrys] = useState([]); - const getItem = async (itemId = undefined) => { - if (itemId && itemId > 0) { - const data = await EntrysDataApiService.get(itemId); - setItem(data); - } else { - setItem({ ...emptyItem }); - } + const getEntrysData = async () => { + const data = await EntrysDataApiService.getAll(); + setEntrys(data ?? []); }; useEffect(() => { - getItem(id); + getEntrysData(); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [id]); + }, []); return { - item, - setItem, + entrys, }; }; -export default useEntysDataItem; +export default useEntrysData; diff --git a/Lab5/src/components/logins/login/Entry.jsx b/Lab5/src/components/logins/login/Entry.jsx index a1aadec..9a31cd4 100644 --- a/Lab5/src/components/logins/login/Entry.jsx +++ b/Lab5/src/components/logins/login/Entry.jsx @@ -1,36 +1,59 @@ import { useState } from 'react'; +import { Link } from 'react-router-dom'; import toast from 'react-hot-toast'; -import { Button, Form, Label } from 'react-bootstrap'; +import { Button, Form } from 'react-bootstrap'; import Input from '../../input/Input.jsx'; +import useEntrysData from '../hooks/EntrysDataHook'; const Entry = () => { + const { entrys } = useEntrysData(); const [validated, setValidated] = useState(false); const [login, setLogin] = useState(''); const [password, setPassword] = useState(''); + const isLoginValid = (value) => /^[a-zA-Z]+$/.test(value); const handleSubmit = (event) => { const form = event.currentTarget; event.preventDefault(); event.stopPropagation(); if (form.checkValidity() !== false) { - toast.success('Валидация прошла успешно'); + if (isLoginValid(login)) { + entrys.map((item) => { + if (login === item.login) { + if (password === item.password) { + toast.success('Вы вошли в аккаунт'); + return []; + } + } + toast.error('Данный пользователь не найден, либо был введён неверный пароль'); + return []; + }); + } else { + toast.error('Логин должен быть введён латинскими символами'); + return; + } } setValidated(true); }; + return (
Личный кабинет
+ + +
- + setLogin(e.target.value)} placeholder="dyctator" type="text" required /> - + setPassword(e.target.value)} type="password" required /> +
diff --git a/Lab5/src/index.css b/Lab5/src/index.css index 538beb0..9fc06a7 100644 --- a/Lab5/src/index.css +++ b/Lab5/src/index.css @@ -37,6 +37,11 @@ h3 { color: #060647; font-size: 50px; } +.EntrysSt{ + font-weight: bold; + color: #060647; + font-size: 30px; +} .rectPage2{ color: #FFFFFF; diff --git a/Lab5/src/main.jsx b/Lab5/src/main.jsx index 2c55b15..e5c0281 100644 --- a/Lab5/src/main.jsx +++ b/Lab5/src/main.jsx @@ -10,6 +10,7 @@ import Page2 from './pages/Page2.jsx'; import Page3 from './pages/Page3.jsx'; import Page4 from './pages/Page4.jsx'; import Page5 from './pages/Page5.jsx'; +import RegistrPage from './pages/RegistrPage.jsx'; const routes = [ { @@ -38,6 +39,10 @@ const routes = [ element: , title: 'Контакты', }, + { + path: '/registrPage', + element: , + }, ]; const router = createBrowserRouter([ diff --git a/Lab5/src/pages/RegistrPage.jsx b/Lab5/src/pages/RegistrPage.jsx new file mode 100644 index 0000000..f7a792d --- /dev/null +++ b/Lab5/src/pages/RegistrPage.jsx @@ -0,0 +1,9 @@ +const RegistrPage = () => { + return ( +
+ +
+ ); +}; + +export default RegistrPage;