diff --git a/src/components/SchedulerHistory.tsx b/src/components/SchedulerHistory.tsx
new file mode 100644
index 0000000..1e7741d
--- /dev/null
+++ b/src/components/SchedulerHistory.tsx
@@ -0,0 +1,54 @@
+import React, { useContext, useEffect, useState } from 'react';
+import styled from 'styled-components';
+import { coursesContext } from '../contexts/CoursesProvider';
+import { SchedulerEvent } from '../types';
+import { Scheduler } from './Scheduler';
+import { SchedulerHistoryNavigation } from './SchedulerHistoryNavigation';
+
+const Wrapper = styled.div`
+ display: flex;
+ flex-direction: column;
+ width: 100%;
+`;
+
+interface SchedulerHistoryProps {
+ schedulerHistoryEvents: Array
;
+}
+
+export const SchedulerHistory = ({schedulerHistoryEvents}:SchedulerHistoryProps) => {
+ const { timetableHistory, setHistoryBasketFromHistoryGroups } = useContext(coursesContext)!;
+ const [currentTimetable, setCurrentTimetable] = useState(timetableHistory.length===0 ? 0 : timetableHistory.length - 1);
+ let commisionDate = timetableHistory[currentTimetable]?.commisionDate;
+
+ const SubstractCurrentTimetable = (value: number) => {
+ if (currentTimetable > 0) {
+ setCurrentTimetable((currentTimetable) => currentTimetable + value);
+ }
+ };
+
+ const AddCurrentTimetable = (value: number) => {
+ if (currentTimetable < timetableHistory.length - 1) {
+ setCurrentTimetable((currentTimetable) => currentTimetable + value);
+ }
+ };
+
+ useEffect(() => {
+ const timetable = timetableHistory[currentTimetable];
+ if (timetable) {
+ const { groups } = timetable;
+ setHistoryBasketFromHistoryGroups(groups);
+ }
+ else{
+ setHistoryBasketFromHistoryGroups([]);
+ }
+ }, [currentTimetable,timetableHistory]);
+
+ return (
+
+ {timetableHistory.length > 0 && (
+
+ )}
+
+
+ );
+};
diff --git a/src/components/SchedulerHistoryNavigation.tsx b/src/components/SchedulerHistoryNavigation.tsx
new file mode 100644
index 0000000..bd3c680
--- /dev/null
+++ b/src/components/SchedulerHistoryNavigation.tsx
@@ -0,0 +1,91 @@
+import React, { useContext } from 'react';
+import styled from 'styled-components';
+import { coursesContext } from '../contexts/CoursesProvider';
+import RightArrow from '../assets/right-arrow.svg';
+import LeftArrow from '../assets/left-arrow.svg';
+
+type ButtonProps = {
+ direction: 'left' | 'right';
+};
+
+const Wrapper = styled.div`
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ margin-top:-15px;
+`;
+
+const StyledButton = styled.div`
+cursor:pointer;
+user-select: none;
+margin:10px;
+border-radius:5px;
+ border-radius: 15px;
+ background-color: #9ed3ff;
+ border: 2px solid white;
+ min-width: 45px;
+ color: black;
+ display:flex;
+ align-items:center;
+ justify-content:center;
+ padding: 12px;
+ :hover{
+ background-color:#85c8ff;
+}
+ transition: color 0.3s, background-color 0.3s;
+`;
+
+const StyledArrow = styled.img`
+width:20px;
+`;
+
+
+const StyledDate = styled.div`
+user-select: none;
+margin:10px;
+border-radius:5px;
+ border-radius: 15px;
+ background-color: #FFDC61;
+ border: 2px solid white;
+ min-width: 45px;
+ text-align:center;
+ color: black;
+ padding: 10px;
+`;
+
+type SchedulerHistoryNavigationProps = {
+ commisionDate?: Date;
+ SubstractCurrentTimetable: (value: number) => void;
+ AddCurrentTimetable: (value: number) => void;
+};
+
+export const SchedulerHistoryNavigation = ({
+ commisionDate,
+ SubstractCurrentTimetable,
+ AddCurrentTimetable,
+}: SchedulerHistoryNavigationProps) => {
+
+ return (
+
+ {
+ console.log('left clicked');
+ SubstractCurrentTimetable(-1);
+ }}
+ >
+
+
+ {commisionDate}
+ {
+ console.log('right clicked');
+ AddCurrentTimetable(1);
+ }}
+ >
+
+
+
+ );
+};
diff --git a/src/components/SchedulerRow.tsx b/src/components/SchedulerRow.tsx
index a007620..e5aaf58 100644
--- a/src/components/SchedulerRow.tsx
+++ b/src/components/SchedulerRow.tsx
@@ -146,14 +146,10 @@ export const SchedulerRow = ({ groups, indexRow, rowTop, cellWidth, cellHeight }
};
const handlePopoverClose = (e: MouseEvent) => {
- console.log('current target:', e.currentTarget);
- console.log(' target:', e.target);
setPopoverId(null);
setAnchorEl(null);
- console.log('click awayyy');
};
useEffect(() => {
- console.log('anchorEl: ', anchorEl);
}, [anchorEl]);
const open = Boolean(anchorEl);
const id = open ? 'simple-popover' : undefined;
diff --git a/src/contexts/CASProvider.tsx b/src/contexts/CASProvider.tsx
index e85760c..6422d52 100644
--- a/src/contexts/CASProvider.tsx
+++ b/src/contexts/CASProvider.tsx
@@ -36,7 +36,6 @@ export const CASProvider = ({ children }: CASProviderProps) => {
const { data: user } = await axiosInstance.get(
`${process.env.REACT_APP_API_URL}/token?ticket=${ticket}`,
);
- console.log('token response: ', user);
setUser({ authorityRole: user.authorityRole, email: user.email, id: user.id });
localStorage.setItem('userToken', user.token);
localStorage.setItem('userPrivilige', user.authorityRole);
diff --git a/src/contexts/CoursesProvider.tsx b/src/contexts/CoursesProvider.tsx
index 79f9e6b..b678230 100644
--- a/src/contexts/CoursesProvider.tsx
+++ b/src/contexts/CoursesProvider.tsx
@@ -1,5 +1,5 @@
import React, { useState, createContext, useEffect, ReactNode } from 'react';
-import { Course, Group, Basket, GroupType, SchedulerEvent } from '../types';
+import { Course, Group, Basket, GroupType, SchedulerEvent, TimetableHistory } from '../types';
import { useSnackbar } from 'notistack';
import { axiosInstance } from '../utils/axiosInstance';
import CloseIcon from '@material-ui/icons/Close';
@@ -16,22 +16,27 @@ const StyledCloseIcon = styled(CloseIcon)`
interface CourseContext {
courses: Array;
basket: Array;
+ timetableHistory: Array;
hoveredGroup: Group | undefined | null;
userID: string;
isDataLoading: boolean;
+ historyBasket: Array;
addCourseToBasket: (courses: Course) => void;
changeHoveredGroup: (group: Group | null) => void;
- changeGroupInBasket: (group: Group, courseId: number) => void;
+ changeGroupInBasket: (group: any, courseId: number) => void;
restoreGroupInBasket: (restoreGroup: Group, courseId: number) => void;
deleteFromBasket: (id: number) => void;
saveBasket: (userID: string) => Promise;
changeStudent: (studentId: string) => void;
selectSchedulerEvents: () => Array;
+ selectHistorySchedulerEvents: () => Array;
selectBasketNames: () => Array;
selectBasketCourses: () => Array;
selectBasketCourseGroups: (courseId: number) => { lecture: Group | undefined; classes: Group | undefined };
getNewestStudentTimetable: (studentId: string) => void;
+ getStudentTimetablesHistory: (studentId: string) => void;
changeDataLoading: (isLoading: boolean) => void;
+ setHistoryBasketFromHistoryGroups: (groupsIds: Array) => void;
}
export const coursesContext = createContext(undefined);
@@ -46,6 +51,8 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
//fetch courses with groups
const [courses, setCourses] = useState>([]);
const [basket, setBasket] = useState>([]);
+ const [historyBasket, setHistoryBasket] = useState>([]);
+ const [timetableHistory, setTimetableHistory] = useState>([]);
const [userID, setUserID] = useState('');
const [hoveredGroup, setHoveredGroup] = useState(null);
const [isDataLoading, setIsDataLoading] = useState(false);
@@ -70,18 +77,29 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
return basket.reduce((res, el) => {
const { name } = el;
if (el.classes) {
- console.log('element kurwa is: ', el);
res.push({ ...el.classes, name });
}
if (el.lecture) {
- console.log('element kurwa is: ', el);
-
res.push({ ...el.lecture, name });
}
return res;
}, [] as Array);
};
+ const selectHistorySchedulerEvents = () => {
+ return historyBasket.reduce((res, el) => {
+ const { name } = el;
+ if (el.classes) {
+ res.push({ ...el.classes, name });
+ }
+ if (el.lecture) {
+ res.push({ ...el.lecture, name });
+ }
+ return res;
+ }, [] as Array);
+ };
+
+
const selectBasketCourseGroups = (courseId: number) => {
const course = basket.find(({ id }) => id === courseId);
if (course !== undefined) {
@@ -111,6 +129,7 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
setUserID(studentId);
setTimeout(() => {
getNewestStudentTimetable(studentId);
+ getStudentTimetablesHistory(studentId);
}, 100);
};
@@ -131,32 +150,30 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
`${process.env.REACT_APP_API_URL}/api/v1/commisions/user/${userID}`,
JSON.stringify(basketIds),
);
- enqueueSnackbar('Plan został zapisany', {
+ enqueueSnackbar('Ustawienia zostały zapisane', {
variant: 'success',
action,
});
} catch (e) {
console.log('error: ', e);
- enqueueSnackbar('Zapisywanie planu nie powiodło się', {
+ enqueueSnackbar('Ustawienia nie zostały zapisane', {
variant: 'error',
action,
});
}
+ getStudentTimetablesHistory(userID);
};
- const changeGroupInBasket = (choosenGroup: Group, courseId: number) => {
+ const changeGroupInBasket = (choosenGroup: any, courseId: number) => {
const basketCourse = basket.filter((course) => course.id === courseId)[0];
- const { type } = choosenGroup;
- if (type === GroupType.CLASS) {
+ if (choosenGroup.lecture && choosenGroup.classes)
+ {
+ const prev = choosenGroup.prev==="lecture"?choosenGroup.lecture : choosenGroup.classes
setBasket(
- basket.map((basket) => (basket.id === basketCourse.id ? { ...basket, classes: choosenGroup } : basket)),
+ basket.map((basket) => (basket.id === basketCourse.id ? { ...basket, lecture: choosenGroup.lecture, classes:choosenGroup.classes } : basket)),
);
- } else if (type === GroupType.LECTURE) {
- setBasket(
- basket.map((basket) => (basket.id === basketCourse.id ? { ...basket, lecture: choosenGroup } : basket)),
- );
- }
- changeHoveredGroup(choosenGroup);
+ changeHoveredGroup(prev);
+ }
};
const restoreGroupInBasket = (restoreGroup: Group, courseId: number) => {
@@ -179,8 +196,6 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
`${process.env.REACT_APP_API_URL}/api/v1/commisions/user/schedule`,
);
const basket = data === '' ? [] : data;
- console.log('basket is: ', basket);
- console.log('mordo weź');
setBasket(basket);
} catch (e) {
console.log(e);
@@ -200,17 +215,57 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
}
};
+ const getStudentTimetablesHistory = async (studentId: string) => {
+ try {
+ const { data } = await axiosInstance.get | []>(
+ `${process.env.REACT_APP_API_URL}/api/v1/commisions/user/${studentId}?groups=true`,
+ );
+ console.log('data is mordo: ', data);
+ setTimetableHistory(data);
+ } catch (e) {
+ console.log(e);
+ }
+ };
+
const fetchCourses = async () => {
try {
const { data: courses } = await axiosInstance.get>(
`${process.env.REACT_APP_API_URL}/api/v1/courses/all?groups=true&takenPlaces=true`,
);
const sortedCourses = courses.sort((a, b) => (a.name > b.name ? 1 : -1));
- console.log('sortedCourses: ', sortedCourses);
setCourses(sortedCourses);
} catch (e) {
console.log(e);
- }
+ }
+ };
+
+ const setHistoryBasketFromHistoryGroups = (groupsIds: Array) => {
+ const basket: Array = [];
+ for (const groupId of groupsIds) {
+ for (const course of courses) {
+ const { lectures, classes, name, id } = course;
+ let basketElement: Basket = { name: name, id: id };
+ if (lectures) {
+ for (const lecture of lectures) {
+ if (groupId === lecture.id) {
+ basketElement = { ...basketElement, lecture: lecture };
+ }
+ }
+ }
+ if (classes) {
+ for (const singleClass of classes) {
+ if (groupId === singleClass.id) {
+ basketElement = { ...basketElement, classes: singleClass };
+ }
+ }
+ }
+ if (basketElement.classes !== undefined || basketElement.lecture !== undefined) {
+ basket.push(basketElement);
+ }
+ }
+ }
+ console.log('baskeeeeeet: ', basket);
+ setHistoryBasket(basket);
};
useEffect(() => {
@@ -231,7 +286,9 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
courses,
basket,
hoveredGroup,
+ timetableHistory,
isDataLoading,
+ historyBasket,
addCourseToBasket,
changeHoveredGroup,
changeGroupInBasket,
@@ -239,11 +296,14 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
restoreGroupInBasket,
saveBasket,
selectSchedulerEvents,
+ selectHistorySchedulerEvents,
selectBasketNames,
selectBasketCourses,
selectBasketCourseGroups,
getNewestStudentTimetable,
changeStudent,
+ getStudentTimetablesHistory,
+ setHistoryBasketFromHistoryGroups,
changeDataLoading,
}}
>
diff --git a/src/contexts/StudentsProvider.tsx b/src/contexts/StudentsProvider.tsx
index 11faf16..7bf353b 100644
--- a/src/contexts/StudentsProvider.tsx
+++ b/src/contexts/StudentsProvider.tsx
@@ -1,7 +1,6 @@
import React, { useState, createContext, useEffect, ReactNode, useRef, useContext } from 'react';
import { Student } from '../types';
import { axiosInstance } from '../utils/axiosInstance';
-import { CASContext } from './CASProvider';
interface StudentContext {
students: Array;
@@ -19,15 +18,12 @@ export const StudentsProvider = ({ children }: StudentsProviderProps) => {
const [students, setStudents] = useState>([]);
const [selectedStudent, setSelectedStudent] = useState(null);
- //not working currently
-
const getStudents = async () => {
try {
const { data } = await axiosInstance.get>(
`${process.env.REACT_APP_API_URL}/api/v1/users/students`,
);
setStudents(data);
- console.log(data);
} catch (e) {
console.log(e);
}
@@ -40,7 +36,6 @@ export const StudentsProvider = ({ children }: StudentsProviderProps) => {
useEffect(() => {
setTimeout(() => {
const userPrivilige = localStorage.getItem('userPrivilige');
- console.log('mordo privilidż: ', userPrivilige);
userPrivilige === 'DEANERY' && getStudents();
}, 500);
}, []);
diff --git a/src/types/index.ts b/src/types/index.ts
index fcf3b7c..9fcf290 100644
--- a/src/types/index.ts
+++ b/src/types/index.ts
@@ -54,3 +54,20 @@ export interface SchedulerEvent {
takenPlaces: number;
name: string;
}
+
+export interface TimetableHistory {
+ commisionDate: Date;
+ commiter: {
+ id: number;
+ name: string;
+ surname: string;
+ email: string;
+ };
+ groups: Array;
+ owner: {
+ id: number;
+ name: string;
+ surname: string;
+ email: string;
+ };
+}
diff --git a/src/utils/axiosInstance.ts b/src/utils/axiosInstance.ts
index cb82f86..066c670 100644
--- a/src/utils/axiosInstance.ts
+++ b/src/utils/axiosInstance.ts
@@ -37,7 +37,6 @@ axiosInstance.interceptors.response.use(
},
async (error) => {
const originalRequest = error.config;
- console.log("original request is: ", originalRequest)
if (error.response.status === 403 && !originalRequest._retry) {
originalRequest._retry = true;
const access_token = await getNewTokens();