Skip to content

Commit

Permalink
UI Update, Courses and Classrooms Pages Addition (#39)
Browse files Browse the repository at this point in the history
* Changed Ui, add courses and classrooms

* Add classroom page

---------

Co-authored-by: Dragodui <[email protected]>
  • Loading branch information
romandykyi and Dragodui authored Nov 13, 2023
1 parent 3f2c410 commit 8ccf38c
Show file tree
Hide file tree
Showing 22 changed files with 575 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import { Route, Routes } from 'react-router-dom';
import AppRoutes from './AppRoutes';
import AuthorizeRoute from './components/api-authorization/AuthorizeRoute';
import Layout from "./components/Layout";
import './custom.css';
import './styles/style.css';
import './styles/index.css';
import Login from "./components/Pages/Login";
//To do
// end a PasswordChangeBlock when password changes successfully
// add Redux to a project to realize some features with global states

const App = () => {
return (
<Layout>
Expand Down
23 changes: 19 additions & 4 deletions EUniversity/ClientApp/src/AppRoutes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import ApiAuthorzationRoutes from './components/api-authorization/ApiAuthorizationRoutes';
import Home from "./components/Home";
import Home from "./components/Pages/Home";
import Login from "./components/Pages/Login";
import ChangePassword from "./components/Pages/ChangePassword";
import RegisterNewUsers from "./components/Pages/RegisterNewUsers";
import AdminUsers from "./components/Pages/AdminUsers";
import AdminGroups from './components/Pages/AdminGroups';
import AdminGroup from "./components/Pages/AdminGroup";
import AdminCourses from "./components/Pages/AdminCourses";
import AdminClassrooms from './components/Pages/AdminClassrooms';
import AdminClassroom from './components/Pages/AdminClassroom';

const AppRoutes = [
{
Expand All @@ -31,19 +34,31 @@ const AppRoutes = [
path: '/users',
requireAuth: true,
element: <AdminUsers/>,
requireAdminRight: true,
},
{
path: '/groups',
requireAuth: true,
element: <AdminGroups/>,
requireAdminRight: true,
},
{
path: '/groups/:id',
requireAuth: true,
element: <AdminGroup/>,
requireAdminRight: true,
},
{
path: '/courses',
requireAuth: true,
element: <AdminCourses/>,
},
{
path: '/classrooms',
requireAuth: true,
element: <AdminClassrooms/>,
},
{
path: '/classrooms/:id',
requireAuth: true,
element: <AdminClassroom/>,
},
...ApiAuthorzationRoutes
];
Expand Down
14 changes: 0 additions & 14 deletions EUniversity/ClientApp/src/components/Home.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Container } from 'reactstrap';
import NavMenu from './NavMenu';
import PasswordChangedBlock from "./UI/PasswordChangedBlock/PasswordChangedBlock";


const Layout = (props) => {
return (
Expand Down
88 changes: 0 additions & 88 deletions EUniversity/ClientApp/src/components/NavMenu.js

This file was deleted.

122 changes: 122 additions & 0 deletions EUniversity/ClientApp/src/components/NavMenu.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import React, { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
import LoginMenu from "./api-authorization/LoginMenu.js";
import '../styles/NavMenu.css';
import authService from "./api-authorization/AuthorizeService";
import {ADMINISTRATOR_ROLE} from "./api-authorization/Roles";
import { useAppDispatch, useAppSelector } from '../store/store';
import { setIsAdmin } from '../store/features/isAdminSlice';


const NavMenu = () => {

const [collapsed, setCollapsed] = useState(false);
const [isAuthenticated, setIsAuthenticated] = useState(false);
const dispatch = useAppDispatch();
const isAdmin = useAppSelector(state => state.isAdmin.isAdmin);

const authNavList = [
{
to: "/change-password",
title: "Change password"
},
];

const adminNavList = [
{
to: "/users",
title: "Users"
},
{
to: "/register-users",
title: "Register users"
},
{
to: "/groups",
title: "Groups"
},
{
to: "/courses",
title: "Courses"
},
{
to: "/classrooms",
title: "Classrooms"
},
];

const AuthNav = () => {
return (
<ul>
<li onClick = {() => setCollapsed(false)}>
<Link className="text-sky-500 text-2xl font-medium" to="/">Home</Link>
</li>
{
authNavList.map(link => <li key={link.title} onClick = {() => setCollapsed(false)}><Link className="text-black text-2xl font-medium" to={link.to}>{link.title}</Link></li>)
}
</ul>
)
};
const AdminNav = () => {
return (
<ul className =" flex flex-col justify-end gap-3">
<li onClick = {() => setCollapsed(false)}>
<Link className="text-sky-500 text-2xl font-medium" to="/">Home</Link>
</li>
{
adminNavList.map(link => <li key={link.title} onClick = {() => setCollapsed(false)}><Link className="text-black text-2xl font-medium" to={link.to}>{link.title}</Link></li>)
}
</ul>
)
};

useEffect(() => {
const checkAuthentication = async () => {
const isAuthenticated = await authService.isAuthenticated();
setIsAuthenticated(isAuthenticated);
const isAdmin = await authService.isInRole(ADMINISTRATOR_ROLE);
dispatch(setIsAdmin(isAdmin));
};
checkAuthentication();
const subscriptionId = authService.subscribe(checkAuthentication);

return () => {
authService.unsubscribe(subscriptionId);
};
}, []);

const toggleNavbar = () => {
setCollapsed(!collapsed);
};

return (
<header className="py-3 shadow-md bg-white">
<div className="container max-w-[1100px] flex items-center gap-4 justify-between">
<Link className="text-2xl font-bold" to="/">EUniversity</Link>
<nav className={`shadow-lg flex flex-col justify-center px-4 bg-white w-[300px] h-full fixed transition-all top-0 duration-300 ${collapsed ? "right-0" : "right-[-100%]"}`}>
{
isAuthenticated
? isAdmin
? <AdminNav />
: <AuthNav />
: ""
}
</nav>
<div className="flex items-center gap-4">
<LoginMenu />
{
isAuthenticated
? <div className="flex items-center justify-between w-10 h-6 flex-col cursor-pointer z-20 " onClick={toggleNavbar}>
<div className="w-full h-1 bg-black rounded-full"></div>
<div className="w-full h-1 bg-sky-500 rounded-full"></div>
<div className="w-full h-1 bg-black rounded-full"></div>
</div>
: ""
}
</div>
</div>
</header>
);
}

export default NavMenu;
37 changes: 37 additions & 0 deletions EUniversity/ClientApp/src/components/PageOfItems.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import PaginatedList from './PaginatedList';

const PageOfItems = ({
title,
fetchFunction,
isLoading,
itemsPerPage,
setItemsPerPage,
totalItems,
tableHead,
tableBody,
additionalItems,
usersType
}) => {
return (
<div className="students container max-w-[1100px] pt-10">
<h1 className="students__title form__title">
{title}
</h1>
{additionalItems}
<PaginatedList
itemsPerPage={itemsPerPage}
setItemsPerPage={setItemsPerPage}
isLoading={isLoading}
totalItems={totalItems}
fetchItems={fetchFunction}
tableHead={tableHead}
tableBody={tableBody}
usersType = {usersType}
/>
</div>

);
};

export default PageOfItems;
Loading

0 comments on commit 8ccf38c

Please sign in to comment.