Skip to content

Commit

Permalink
feat: calendar ui
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrKarpovich committed Oct 13, 2024
1 parent 5a22827 commit d930074
Show file tree
Hide file tree
Showing 20 changed files with 1,106 additions and 635 deletions.
357 changes: 344 additions & 13 deletions frontend/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"react-router": "^6.26.2",
"react-router-dom": "^6.26.2",
"react-scripts": "5.0.1",
"sass-loader": "^16.0.2",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down Expand Up @@ -42,7 +43,7 @@
]
},
"devDependencies": {
"sass": "^1.79.4",
"sass": "^1.79.5",
"scss-reset": "^1.4.2"
}
}
116 changes: 59 additions & 57 deletions frontend/src/App.jsx
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;
Loading

0 comments on commit d930074

Please sign in to comment.