admin panel changes

This commit is contained in:
Maciek Głowacki 2020-12-12 20:32:09 +01:00
parent e3a1b280e0
commit 54027d1980
6 changed files with 34 additions and 19 deletions

View File

@ -90,7 +90,7 @@ const Icon = styled.img`
`; `;
export const Admin = () => { export const Admin = () => {
const [currentTab, setCurrentTab] = useState<null | number>(null); const [currentTab, setCurrentTab] = useState<null | number>(1);
const handleClick = (e: MouseEvent<HTMLDivElement>) => { const handleClick = (e: MouseEvent<HTMLDivElement>) => {
setCurrentTab(Number(e.currentTarget.id)); setCurrentTab(Number(e.currentTarget.id));

View File

@ -50,7 +50,9 @@ interface DropdownProps {
} }
export const Dropdown = ({ open, input, handleCloseDropdown, selectedOption }: DropdownProps) => { export const Dropdown = ({ open, input, handleCloseDropdown, selectedOption }: DropdownProps) => {
const { courses, selectBasketNames, addCourseToBasket, getUserID } = useContext(coursesContext)!; const { courses, selectBasketNames, addCourseToBasket, changeStudent } = useContext(
coursesContext,
)!;
const { students } = useContext(studentsContext)!; const { students } = useContext(studentsContext)!;
const basketNames = useMemo(() => selectBasketNames(), [selectBasketNames]); const basketNames = useMemo(() => selectBasketNames(), [selectBasketNames]);
const [filteredCourses, setFilteredCourses] = useState<Array<Course>>([]); const [filteredCourses, setFilteredCourses] = useState<Array<Course>>([]);
@ -67,7 +69,7 @@ export const Dropdown = ({ open, input, handleCloseDropdown, selectedOption }: D
const onUserClick = (event: MouseEvent) => { const onUserClick = (event: MouseEvent) => {
const target = event.currentTarget; const target = event.currentTarget;
getUserID(target.id); changeStudent(target.id);
handleCloseDropdown(); handleCloseDropdown();
}; };
@ -119,7 +121,7 @@ export const Dropdown = ({ open, input, handleCloseDropdown, selectedOption }: D
{filteredStudents.map(({ name, surname, id }, index) => ( {filteredStudents.map(({ name, surname, id }, index) => (
<CourseContainer key={index} id={id.toString()} onClick={onUserClick}> <CourseContainer key={index} id={id.toString()} onClick={onUserClick}>
<p> <p>
{name} {surname}{' '} {name} {surname}
</p> </p>
</CourseContainer> </CourseContainer>
))} ))}

View File

@ -1,4 +1,4 @@
import React, { useEffect, useRef } from 'react'; import React, { useEffect, useLayoutEffect, useRef } from 'react';
import { useState } from 'react'; import { useState } from 'react';
import { SchedulerEvents } from './SchedulerEvents'; import { SchedulerEvents } from './SchedulerEvents';
import { days, hours } from '../constants/index'; import { days, hours } from '../constants/index';
@ -66,7 +66,7 @@ export const Scheduler = () => {
const [cellWidth, setCellWidth] = useState(0); const [cellWidth, setCellWidth] = useState(0);
const [cellHeight, setCellHeight] = useState(0); const [cellHeight, setCellHeight] = useState(0);
useEffect(() => { useLayoutEffect(() => {
const handleResize = () => { const handleResize = () => {
if (cellRef.current) { if (cellRef.current) {
setCellWidth(cellRef.current.getBoundingClientRect().width); setCellWidth(cellRef.current.getBoundingClientRect().width);

View File

@ -140,7 +140,6 @@ export const SchedulerRow = ({ groups, indexRow, rowTop, cellWidth, cellHeight }
const [popoverId, setPopoverId] = useState<string | null>(null); const [popoverId, setPopoverId] = useState<string | null>(null);
//looks weird //looks weird
const handlePopoverOpen = (event: MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => { const handlePopoverOpen = (event: MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => {
console.log('I was clicked!!!!');
setAnchorEl(event.currentTarget); setAnchorEl(event.currentTarget);
setPopoverId(event.currentTarget.id); setPopoverId(event.currentTarget.id);
}; };

View File

@ -26,12 +26,13 @@ interface CourseContext {
restoreGroupInBasket: (restoreGroup: Group, courseId: number) => void; restoreGroupInBasket: (restoreGroup: Group, courseId: number) => void;
deleteFromBasket: (id: number) => void; deleteFromBasket: (id: number) => void;
saveBasket: (userID: string) => Promise<void>; saveBasket: (userID: string) => Promise<void>;
getUserID: (userID: string) => Promise<void>; changeStudent: (studentId: string) => void;
selectSchedulerEvents: () => Array<SchedulerEvent>; selectSchedulerEvents: () => Array<SchedulerEvent>;
selectBasketNames: () => Array<string>; selectBasketNames: () => Array<string>;
selectBasketCourses: () => Array<Course>; selectBasketCourses: () => Array<Course>;
selectBasketCourseGroups: (courseId: number) => { lecture: Group | undefined; classes: Group | undefined }; selectBasketCourseGroups: (courseId: number) => { lecture: Group | undefined; classes: Group | undefined };
getUserTimetable: (userID: string) => Promise<void>; getNewestStudentTimetable: (studentId: string) => void;
changeDataLoading: (isLoading: boolean) => void;
} }
export const coursesContext = createContext<CourseContext | undefined>(undefined); export const coursesContext = createContext<CourseContext | undefined>(undefined);
@ -92,6 +93,8 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
const changeHoveredGroup = (group: Group | null) => setHoveredGroup(group); const changeHoveredGroup = (group: Group | null) => setHoveredGroup(group);
const changeDataLoading = (isLoading: boolean) => setIsDataLoading(isLoading);
const addCourseToBasket = (course: Course) => { const addCourseToBasket = (course: Course) => {
const courseToBasket: Basket = { const courseToBasket: Basket = {
name: course.name, name: course.name,
@ -104,8 +107,11 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
const deleteFromBasket = (id: number) => setBasket(basket.filter((course) => course.id !== id)); const deleteFromBasket = (id: number) => setBasket(basket.filter((course) => course.id !== id));
const getUserID = async (userID: string) => { const changeStudent = async (studentId: string) => {
setUserID(userID); setUserID(studentId);
setTimeout(() => {
getNewestStudentTimetable(studentId);
}, 100);
}; };
const saveBasket = async (userID: string) => { const saveBasket = async (userID: string) => {
@ -177,10 +183,13 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
} }
}; };
const getUserTimetable = async (userID: string) => { const getNewestStudentTimetable = async (studentId: string) => {
try { try {
const { data } = await axiosInstance.get(`${process.env.REACT_APP_API_URL}/api/v1/commisions/user/${userID}`); const { data } = await axiosInstance.get(
console.log(data); `${process.env.REACT_APP_API_URL}/api/v1/commisions/user/${studentId}/schedule`,
);
const basket = data === '' ? [] : data;
setBasket(basket);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} }
@ -225,8 +234,9 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
selectBasketNames, selectBasketNames,
selectBasketCourses, selectBasketCourses,
selectBasketCourseGroups, selectBasketCourseGroups,
getUserTimetable, getNewestStudentTimetable,
getUserID, changeStudent,
changeDataLoading,
}} }}
> >
{children} {children}

View File

@ -1,6 +1,7 @@
import React, { useState, createContext, useEffect, ReactNode, useRef } from 'react'; import React, { useState, createContext, useEffect, ReactNode, useRef, useContext } from 'react';
import { Student } from '../types'; import { Student } from '../types';
import { axiosInstance } from '../utils/axiosInstance'; import { axiosInstance } from '../utils/axiosInstance';
import { CASContext } from './CASProvider';
interface StudentContext { interface StudentContext {
students: Array<Student>; students: Array<Student>;
@ -15,7 +16,9 @@ interface StudentsProviderProps {
export const StudentsProvider = ({ children }: StudentsProviderProps) => { export const StudentsProvider = ({ children }: StudentsProviderProps) => {
const [students, setStudents] = useState<Array<Student>>([]); const [students, setStudents] = useState<Array<Student>>([]);
//not working currently
const userPrivilige = localStorage.getItem('userPrivilige'); const userPrivilige = localStorage.getItem('userPrivilige');
const { user } = useContext(CASContext)!;
const getStudents = async () => { const getStudents = async () => {
try { try {
@ -31,7 +34,8 @@ export const StudentsProvider = ({ children }: StudentsProviderProps) => {
useEffect(() => { useEffect(() => {
setTimeout(() => { setTimeout(() => {
userPrivilige === 'DEANERY' && getStudents(); // user?.authorityRole === 'DEANERY' &&
getStudents();
}, 500); }, 500);
}, []); }, []);