-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a22827
commit d930074
Showing
20 changed files
with
1,106 additions
and
635 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,71 @@ | ||
import React, { useState } from 'react'; | ||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; | ||
import React, {useState} from 'react'; | ||
import {BrowserRouter as Router, Routes, Route, Navigate} from 'react-router-dom'; | ||
import LoginRoute from './pages/LoginRoute'; | ||
import CalendarRoute from './pages/CalendarRoute'; | ||
import { loginModeus, searchModeus } from './services/api'; // Ваши API-запросы | ||
import {loginModeus, searchModeus} from './services/api'; | ||
import PrivateRoute from "./components/Calendar/PrivateRoute"; // Ваши API-запросы | ||
|
||
const App = () => { | ||
const [authData, setAuthData] = useState({ | ||
email: '', | ||
password: '', | ||
personId: '' | ||
}); | ||
const [authData, setAuthData] = useState({ | ||
email: '', | ||
password: '', | ||
personId: '' | ||
}); | ||
|
||
// Функция для обработки логина | ||
const handleLogin = async (email, password, personId) => { | ||
console.log('handleLogin personId', personId) | ||
try { | ||
let response = await loginModeus(email, password); | ||
// Функция для обработки логина | ||
const handleLogin = async (email, password, personId) => { | ||
try { | ||
let response = await loginModeus(email, password); | ||
|
||
console.log('response handleLogin', response) | ||
if (response.status === 200) { | ||
setAuthData({email, password, personId}); | ||
localStorage.setItem('token', response.data["_netology-on-rails_session"]); | ||
return {success: true}; | ||
} else { | ||
return {success: false, message: "Неверный логин или пароль."}; | ||
} | ||
} catch (error) { | ||
return {success: false, message: "Произошла ошибка. Попробуйте снова."}; | ||
} | ||
}; | ||
|
||
if (response.status === 200) { | ||
setAuthData({ email, password, personId }); | ||
localStorage.setItem('token', response.data["_netology-on-rails_session"]); | ||
return { success: true }; | ||
} else { | ||
return { success: false, message: "Неверный логин или пароль." }; | ||
} | ||
} catch (error) { | ||
return { success: false, message: "Произошла ошибка. Попробуйте снова." }; | ||
} | ||
}; | ||
// Функция для поиска пользователя по ФИО | ||
const handleSearch = async (fullName) => { | ||
try { | ||
let response = await searchModeus(fullName); | ||
|
||
// Функция для поиска пользователя по ФИО | ||
const handleSearch = async (fullName) => { | ||
try { | ||
let response = await searchModeus(fullName); | ||
if (response.status === 200) { | ||
return {success: true, data: response.data}; | ||
} else { | ||
return {success: false, message: "Неверное ФИО. Попробуйте снова."}; | ||
} | ||
} catch (error) { | ||
return {success: false, message: "Произошла ошибка. Попробуйте снова."}; | ||
} | ||
}; | ||
|
||
if (response.status === 200) { | ||
return { success: true, data: response.data }; | ||
} else { | ||
return { success: false, message: "Неверное ФИО. Попробуйте снова." }; | ||
} | ||
} catch (error) { | ||
return { success: false, message: "Произошла ошибка. Попробуйте снова." }; | ||
} | ||
}; | ||
|
||
return ( | ||
<Router> | ||
<Routes> | ||
<Route path="/" element={<LoginRoute onLogin={handleLogin} onSearch={handleSearch} />} /> | ||
<Route | ||
path="/calendar" | ||
element={ | ||
<CalendarRoute | ||
email={authData.email} | ||
password={authData.password} | ||
personId={authData.personId} | ||
token={localStorage.getItem('token')} | ||
/> | ||
} | ||
/> | ||
</Routes> | ||
</Router> | ||
); | ||
return ( | ||
<Router> | ||
<Routes> | ||
<Route path="/login" element={<LoginRoute onLogin={handleLogin} onSearch={handleSearch}/>}/> | ||
<Route | ||
path="/calendar" | ||
element={ | ||
<PrivateRoute> | ||
<CalendarRoute | ||
email={authData.email} | ||
password={authData.password} | ||
personId={authData.personId} | ||
token={localStorage.getItem('token')} | ||
/> | ||
</PrivateRoute> | ||
} | ||
/> | ||
{/* Дефолтный маршрут, который перенаправляет на /login */} | ||
<Route path="*" element={<Navigate to="/login" />} /> | ||
</Routes> | ||
</Router> | ||
); | ||
}; | ||
|
||
export default App; |
Oops, something went wrong.