Merge pull request #13 from leomurca/feature/professor_initial_setup
Setup inicial para o app da versao do professor
This commit is contained in:
commit
f20dd77067
7 changed files with 111 additions and 43 deletions
|
@ -1,22 +1,20 @@
|
||||||
import { Navigate, Route, Routes, useNavigate } from 'react-router-dom';
|
import { lazy } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { Container } from '@mui/system';
|
import { Container } from '@mui/system';
|
||||||
import { useUser } from '../context/user';
|
|
||||||
import { useAuthState } from '../context/auth';
|
import { useAuthState } from '../context/auth';
|
||||||
|
import { useUser } from '../context/user';
|
||||||
|
|
||||||
import MainMenu from '../components/MainMenu';
|
import MainMenu from '../components/MainMenu';
|
||||||
import Home from '../screens/Home';
|
|
||||||
import Information from '../screens/Information';
|
|
||||||
import Calendar from '../screens/Calendar';
|
|
||||||
import useLayoutType from '../hooks/useLayoutType';
|
import useLayoutType from '../hooks/useLayoutType';
|
||||||
import Toolbar from '../components/Toolbar';
|
import Toolbar from '../components/Toolbar';
|
||||||
import Classroom from '../screens/Classroom';
|
|
||||||
import Assignment from '../screens/Assignment';
|
|
||||||
import Profile from '../screens/Profile';
|
|
||||||
|
|
||||||
import { avatarMenuOptions, menuOptions } from './data';
|
import { avatarMenuOptions, menuOptions } from './data';
|
||||||
|
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
|
|
||||||
|
const StudentRoutes = lazy(() => import('./StudentRoutes'));
|
||||||
|
const ProfessorRoutes = lazy(() => import('./ProfessorRoutes'));
|
||||||
|
|
||||||
function AuthenticatedApp() {
|
function AuthenticatedApp() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { state } = useUser();
|
const { state } = useUser();
|
||||||
|
@ -24,6 +22,17 @@ function AuthenticatedApp() {
|
||||||
const layoutType = useLayoutType();
|
const layoutType = useLayoutType();
|
||||||
const { container, toolbar } = styles[layoutType];
|
const { container, toolbar } = styles[layoutType];
|
||||||
|
|
||||||
|
const routeResolver = role => {
|
||||||
|
switch (role) {
|
||||||
|
case 'STUDENT':
|
||||||
|
return <StudentRoutes />;
|
||||||
|
case 'PROFESSOR':
|
||||||
|
return <ProfessorRoutes />;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
state &&
|
state &&
|
||||||
state.user && (
|
state.user && (
|
||||||
|
@ -43,21 +52,7 @@ function AuthenticatedApp() {
|
||||||
options={menuOptions(state.pathname)}
|
options={menuOptions(state.pathname)}
|
||||||
layoutType={layoutType}
|
layoutType={layoutType}
|
||||||
/>
|
/>
|
||||||
<Routes>
|
{routeResolver(state.user.role)}
|
||||||
<Route path="/home" element={<Home />} />
|
|
||||||
<Route path="/info" element={<Information />} />
|
|
||||||
<Route path="/calendar" element={<Calendar />} />
|
|
||||||
<Route path="/profile" element={<Profile />} />
|
|
||||||
<Route path="/class">
|
|
||||||
<Route path=":id" element={<Classroom />} />
|
|
||||||
</Route>
|
|
||||||
<Route path="/assignment">
|
|
||||||
<Route path=":id" element={<Assignment />} />
|
|
||||||
</Route>
|
|
||||||
<Route path="/login" element={<Navigate to="/home" />} />
|
|
||||||
<Route path="/register" element={<Navigate to="/home" />} />
|
|
||||||
<Route path="/" element={<Navigate to="/home" />} />
|
|
||||||
</Routes>
|
|
||||||
</Container>
|
</Container>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
17
src/app/ProfessorRoutes.js
Normal file
17
src/app/ProfessorRoutes.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import { Navigate, Route, Routes } from 'react-router-dom';
|
||||||
|
|
||||||
|
function ProfessorRoutes() {
|
||||||
|
return (
|
||||||
|
<Routes>
|
||||||
|
<Route path="/calendar" element={<h1>Calendar</h1>} />
|
||||||
|
<Route path="/profile" element={<h1>Profile</h1>} />
|
||||||
|
<Route path="/info" element={<h1>Information</h1>} />
|
||||||
|
<Route path="/home" element={<h1>Home</h1>} />
|
||||||
|
<Route path="/login" element={<Navigate to="/home" />} />
|
||||||
|
<Route path="/register" element={<Navigate to="/home" />} />
|
||||||
|
<Route path="/" element={<Navigate to="/home" />} />
|
||||||
|
</Routes>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ProfessorRoutes;
|
30
src/app/StudentRoutes.js
Normal file
30
src/app/StudentRoutes.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import { Navigate, Route, Routes } from 'react-router-dom';
|
||||||
|
|
||||||
|
import Home from '../screens/Home';
|
||||||
|
import Information from '../screens/Information';
|
||||||
|
import Calendar from '../screens/Calendar';
|
||||||
|
import Classroom from '../screens/Classroom';
|
||||||
|
import Assignment from '../screens/Assignment';
|
||||||
|
import Profile from '../screens/Profile';
|
||||||
|
|
||||||
|
function StudentRoutes() {
|
||||||
|
return (
|
||||||
|
<Routes>
|
||||||
|
<Route path="/home" element={<Home />} />
|
||||||
|
<Route path="/info" element={<Information />} />
|
||||||
|
<Route path="/calendar" element={<Calendar />} />
|
||||||
|
<Route path="/profile" element={<Profile />} />
|
||||||
|
<Route path="/class">
|
||||||
|
<Route path=":id" element={<Classroom />} />
|
||||||
|
</Route>
|
||||||
|
<Route path="/assignment">
|
||||||
|
<Route path=":id" element={<Assignment />} />
|
||||||
|
</Route>
|
||||||
|
<Route path="/login" element={<Navigate to="/home" />} />
|
||||||
|
<Route path="/register" element={<Navigate to="/home" />} />
|
||||||
|
<Route path="/" element={<Navigate to="/home" />} />
|
||||||
|
</Routes>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default StudentRoutes;
|
|
@ -28,6 +28,7 @@ const menuOptions = activePath => [
|
||||||
isActive:
|
isActive:
|
||||||
activePath === '/home' ||
|
activePath === '/home' ||
|
||||||
activePath === '/login' ||
|
activePath === '/login' ||
|
||||||
|
activePath === '/register' ||
|
||||||
activePath === '/profile' ||
|
activePath === '/profile' ||
|
||||||
activePath === '/' ||
|
activePath === '/' ||
|
||||||
activePath.indexOf('class') !== -1 ||
|
activePath.indexOf('class') !== -1 ||
|
||||||
|
|
|
@ -22,10 +22,9 @@ function AuthProvider(props) {
|
||||||
|
|
||||||
const register = data => {
|
const register = data => {
|
||||||
setState({ ...state, status: 'pending' });
|
setState({ ...state, status: 'pending' });
|
||||||
let shouldFail = false;
|
|
||||||
|
|
||||||
return registerUser(data, shouldFail).then(data => {
|
return registerUser(data).then(data => {
|
||||||
if (shouldFail) {
|
if (data.message) {
|
||||||
return setState({ status: 'error', user: null, error: data });
|
return setState({ status: 'error', user: null, error: data });
|
||||||
} else {
|
} else {
|
||||||
return setState({ status: 'success', user: data, error: null });
|
return setState({ status: 'success', user: data, error: null });
|
||||||
|
@ -35,10 +34,9 @@ function AuthProvider(props) {
|
||||||
|
|
||||||
const login = (email, password) => {
|
const login = (email, password) => {
|
||||||
setState({ ...state, status: 'pending' });
|
setState({ ...state, status: 'pending' });
|
||||||
let shouldFail = email !== 'teste@teste.com' || password !== '#teste1234';
|
|
||||||
|
|
||||||
return getUser(shouldFail).then(data => {
|
return getUser(email, password).then(data => {
|
||||||
if (shouldFail) {
|
if (data.message) {
|
||||||
return setState({ status: 'error', user: null, error: data });
|
return setState({ status: 'error', user: null, error: data });
|
||||||
} else {
|
} else {
|
||||||
return setState({ status: 'success', user: data, error: null });
|
return setState({ status: 'success', user: data, error: null });
|
||||||
|
|
|
@ -534,7 +534,7 @@ const allPeople = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const user = {
|
const studentUser = {
|
||||||
id: '123',
|
id: '123',
|
||||||
ra: '0021123',
|
ra: '0021123',
|
||||||
username: 'ronaldosilva',
|
username: 'ronaldosilva',
|
||||||
|
@ -548,6 +548,24 @@ const user = {
|
||||||
course: 0,
|
course: 0,
|
||||||
termsAgreed: true,
|
termsAgreed: true,
|
||||||
year: 2018,
|
year: 2018,
|
||||||
|
role: 'STUDENT',
|
||||||
|
};
|
||||||
|
|
||||||
|
const professorUser = {
|
||||||
|
id: '321',
|
||||||
|
ra: '0021123',
|
||||||
|
username: 'cazalbe',
|
||||||
|
email: 'carlos.junior@ifmg.edu.br',
|
||||||
|
password: '#carlos1234', // TODO: Remove this!
|
||||||
|
firstName: 'Carlos',
|
||||||
|
lastName: 'Severiano',
|
||||||
|
token: 'xkhfb9458hnsdfsi9q8345bsdf9b834yr',
|
||||||
|
phone: '31111111111',
|
||||||
|
avatar: 'https://i.pravatar.cc/300?img=61',
|
||||||
|
course: 0,
|
||||||
|
termsAgreed: true,
|
||||||
|
year: 2018,
|
||||||
|
role: 'PROFESSOR',
|
||||||
};
|
};
|
||||||
|
|
||||||
const authFailure = {
|
const authFailure = {
|
||||||
|
@ -560,7 +578,8 @@ export {
|
||||||
allClassroomAnnouncements,
|
allClassroomAnnouncements,
|
||||||
allPeople,
|
allPeople,
|
||||||
faq,
|
faq,
|
||||||
user,
|
studentUser,
|
||||||
|
professorUser,
|
||||||
authFailure,
|
authFailure,
|
||||||
allUpcomingAssignments,
|
allUpcomingAssignments,
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,8 @@ import {
|
||||||
allClassrooms,
|
allClassrooms,
|
||||||
allAssignments,
|
allAssignments,
|
||||||
faq,
|
faq,
|
||||||
user,
|
studentUser,
|
||||||
|
professorUser,
|
||||||
authFailure,
|
authFailure,
|
||||||
allClassroomAnnouncements,
|
allClassroomAnnouncements,
|
||||||
allUpcomingAssignments,
|
allUpcomingAssignments,
|
||||||
|
@ -84,25 +85,32 @@ const getFaq = () =>
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const getUser = shouldFail =>
|
const getUser = (email, password) =>
|
||||||
sleep(300).then(() => {
|
sleep(300).then(() => {
|
||||||
if (shouldFail) {
|
let user;
|
||||||
return authFailure;
|
if (email === 'p@test.com' && password === 'p123') {
|
||||||
|
user = professorUser;
|
||||||
|
} else if (email === 's@test.com' && password === 's123') {
|
||||||
|
user = studentUser;
|
||||||
} else {
|
} else {
|
||||||
|
return authFailure;
|
||||||
|
}
|
||||||
window.localStorage.setItem('$USER', JSON.stringify(user));
|
window.localStorage.setItem('$USER', JSON.stringify(user));
|
||||||
return user;
|
return user;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const registerUser = (data, shouldFail) =>
|
const registerUser = data =>
|
||||||
sleep(300).then(() => {
|
sleep(300).then(() => {
|
||||||
if (shouldFail) {
|
let userData;
|
||||||
return authFailure;
|
if (data.email === 'p@test.com') {
|
||||||
|
userData = { ...data, role: 'PROFESSOR' };
|
||||||
|
} else if (data.email === 's@test.com') {
|
||||||
|
userData = { ...data, role: 'STUDENT' };
|
||||||
} else {
|
} else {
|
||||||
console.log(data);
|
return authFailure;
|
||||||
window.localStorage.setItem('$USER', JSON.stringify(data));
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
window.localStorage.setItem('$USER', JSON.stringify(data));
|
||||||
|
return userData;
|
||||||
});
|
});
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
Loading…
Reference in a new issue