From f013ef54ee34404a608ec333ce015aa20537fe56 Mon Sep 17 00:00:00 2001 From: wrzesinski-hubert Date: Sat, 23 Jan 2021 18:54:20 +0100 Subject: [PATCH] push to master --- src/components/Scheduler.tsx | 43 ++++++++++++++++++++++++++++++-- src/components/SchedulerRow.tsx | 4 +-- src/components/Topbar.tsx | 6 +++-- src/components/Transfer.tsx | 13 +--------- src/contexts/CoursesProvider.tsx | 23 ++++++++++++++--- src/types/index.ts | 4 +++ 6 files changed, 71 insertions(+), 22 deletions(-) diff --git a/src/components/Scheduler.tsx b/src/components/Scheduler.tsx index 8e75fc5..4fc1b56 100644 --- a/src/components/Scheduler.tsx +++ b/src/components/Scheduler.tsx @@ -1,9 +1,12 @@ -import React, { useLayoutEffect, useRef } from 'react'; +import React, { useContext, useLayoutEffect, useRef } from 'react'; import { useState } from 'react'; import { SchedulerEvents } from './SchedulerEvents'; import { days, hours } from '../constants/index'; import styled from 'styled-components/macro'; import { SchedulerEvent } from '../types'; +import { coursesContext } from '../contexts/CoursesProvider'; +import Button from '@material-ui/core/Button'; +import Tooltip, { TooltipProps } from '@material-ui/core/Tooltip'; const SchedulerWrapper = styled.div` border-collapse: collapse; @@ -17,6 +20,7 @@ const SchedulerWrapper = styled.div` justify-content: center; align-items: center; box-shadow: 3px 3px 3px -2px rgba(0, 0, 0, 0.59); + position:relative; `; const TableBody = styled.div` @@ -62,6 +66,27 @@ const TableCell = styled.div` font-weight: bold; `; +const TourWrapper = styled.div` + display: flex; + justify-content:center; + align-items:center; + position:absolute; + top:8px; + right:8px; + min-width: 10px; + padding: 3px 7px; + font-size: 12px; + font-weight: 700; + color: black; + line-height: 1; + vertical-align: middle; + white-space: nowrap; + text-align: center; + background-color: #FFDC61; + border-radius: 10px; + font-size:18px; +`; + interface SchedulerProps { schedulerEvents: Array; } @@ -70,7 +95,8 @@ export const Scheduler = ({ schedulerEvents }: SchedulerProps) => { const cellRef = useRef(null); const [cellWidth, setCellWidth] = useState(0); const [cellHeight, setCellHeight] = useState(0); - + const { tour } = useContext(coursesContext)!; + useLayoutEffect(() => { const handleResize = () => { if (cellRef.current) { @@ -130,6 +156,19 @@ export const Scheduler = ({ schedulerEvents }: SchedulerProps) => { ))} + + +
{tour === 'FIRST_TOUR' && '1'}
+
+ +
{tour === 'SECOND_TOUR' && '2'}
+
+ +
{tour === 'NO_TOUR' && 'X'}
+
+ + +
); }; diff --git a/src/components/SchedulerRow.tsx b/src/components/SchedulerRow.tsx index 8de8b40..2adf71c 100644 --- a/src/components/SchedulerRow.tsx +++ b/src/components/SchedulerRow.tsx @@ -239,10 +239,10 @@ export const SchedulerRow = ({ groups, indexRow, rowTop, cellWidth, cellHeight } Sala zajęć: {groups[index].room}

- Kod przedmiotu: ACB129 + Kod przedmiotu: {groups[index].symbol}

- Kod grupy: FVJ753 + Numer grupy: {groups[index].grNr}

{groups[index].isAccepted===true && "Przedmiot został zaakceptowany"} diff --git a/src/components/Topbar.tsx b/src/components/Topbar.tsx index 1bf1a7b..6ae57f9 100644 --- a/src/components/Topbar.tsx +++ b/src/components/Topbar.tsx @@ -10,6 +10,7 @@ import { SelectMenu } from './SelectMenu'; import { studentsContext } from '../contexts/StudentsProvider'; import { CASContext } from '../contexts/CASProvider'; import { render } from 'react-dom'; +import { coursesContext } from '../contexts/CoursesProvider'; const Topbar = styled.div` background-color: #e3e5ed; @@ -112,6 +113,8 @@ const IconWrapper = styled.div` margin-right: 10px; `; + + const Icon = styled.img` width: 40px; margin-left: 40px; @@ -215,9 +218,8 @@ export default function ({ handleTransfer }: TopbarProps) { {selectedStudent?.email.replace(/@st.amu.edu.pl/, '')} - {/* Maciej Głowacki */} - {userPrivilige==="STUDENT" && } + {userPrivilige === 'STUDENT' && } {/* */} {/* */} diff --git a/src/components/Transfer.tsx b/src/components/Transfer.tsx index a1193ca..eeca9ad 100644 --- a/src/components/Transfer.tsx +++ b/src/components/Transfer.tsx @@ -180,7 +180,7 @@ const ExchangeParagraph = styled.p` `; export const Transfer = ({ handleClose, isTransferOpen }: TransferProps) => { - const { basket, selectBasketCourses } = useContext(coursesContext)!; + const { basket, tour, selectBasketCourses } = useContext(coursesContext)!; // const basketCourseGroups = useMemo(() => selectBasketCourseGroups(course.name), []); const basketCourses = selectBasketCourses(); @@ -195,7 +195,6 @@ export const Transfer = ({ handleClose, isTransferOpen }: TransferProps) => { const [groups, setGroups] = useState([]); const [exchanges, setExchanges] = useState(null); const [save, setSave] = useState(false); - const [tour, setTour] = useState(null); // const allGroups const handleSelectedAssignmentsGroupChange = (event: React.ChangeEvent<{ value: unknown }>) => { setSelectedAssignmentsClasses(event.target.value as any); @@ -243,7 +242,6 @@ export const Transfer = ({ handleClose, isTransferOpen }: TransferProps) => { } }; getExchanges(); - getCurrentTour(); getAssignmentsGroups(); }, [isTransferOpen, save]); @@ -261,15 +259,6 @@ export const Transfer = ({ handleClose, isTransferOpen }: TransferProps) => { setSave(!save); }; - const getCurrentTour = async () => { - try { - const { data } = await axiosInstance.get(`${process.env.REACT_APP_API_URL}/api/v1/configurator/config/tour`); - setTour(data.currentTour); - } catch (e) { - console.log(e); - } - }; - const deleteExchange = async (id: number) => { try { const response = await axiosInstance.delete(`${process.env.REACT_APP_API_URL}/api/v1/exchanges/exchange/${id}`); diff --git a/src/contexts/CoursesProvider.tsx b/src/contexts/CoursesProvider.tsx index 09b6e12..e3d6d9f 100644 --- a/src/contexts/CoursesProvider.tsx +++ b/src/contexts/CoursesProvider.tsx @@ -21,6 +21,8 @@ interface CourseContext { userID: string; isDataLoading: boolean; historyBasket: Array; + tour: string; + getCurrentTour: () => void; addCourseToBasket: (courses: Course) => void; changeHoveredGroup: (group: Group | null) => void; changeGroupInBasket: (group: any, courseId: number) => void; @@ -57,6 +59,7 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { const [userID, setUserID] = useState(''); const [hoveredGroup, setHoveredGroup] = useState(null); const [isDataLoading, setIsDataLoading] = useState(false); + const [tour, setTour] = useState(''); const selectBasketIds = () => { const classesIds = basket.map((course) => course?.classes?.id).filter((course) => course !== undefined); @@ -76,12 +79,12 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { const selectSchedulerEvents = () => { return basket.reduce((res, el) => { - const { name } = el; + const { name, symbol } = el; if (el.classes) { - res.push({ ...el.classes, name }); + res.push({ ...el.classes, name, symbol}); } if (el.lecture) { - res.push({ ...el.lecture, name }); + res.push({ ...el.lecture, name, symbol }); } return res; }, [] as Array); @@ -161,7 +164,7 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { }); } catch (e) { console.log('error: ', e); - enqueueSnackbar('Zapisywanie planu nie powiodło się', { + enqueueSnackbar('Zapisywanie niemożliwe w czasie bezturowym', { variant: 'error', action, }); @@ -275,9 +278,19 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { setHistoryBasket(basket); }; + const getCurrentTour = async () => { + try { + const { data } = await axiosInstance.get(`${process.env.REACT_APP_API_URL}/api/v1/configurator/config/tour`); + setTour(data.currentTour); + } catch (e) { + console.log(e); + } + }; + useEffect(() => { setIsDataLoading(true); setTimeout(() => { + getCurrentTour(); fetchCourses(); getNewestTimetable(); setIsDataLoading(false); @@ -294,6 +307,8 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { timetableHistory, isDataLoading, historyBasket, + tour, + getCurrentTour, addCourseToBasket, changeHoveredGroup, changeGroupInBasket, diff --git a/src/types/index.ts b/src/types/index.ts index 7b823f1..4f1e90f 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,6 +6,7 @@ export enum GroupType { export interface Basket { id: number; name: string; + symbol?:string; lecture?: Group; classes?: Group; } @@ -21,6 +22,7 @@ export interface Group { capacity?: number; takenPlaces: number; isAccepted:boolean; + grNr: number; } export interface Course { @@ -55,6 +57,8 @@ export interface SchedulerEvent { takenPlaces: number; name: string; isAccepted:boolean; + grNr?: number; + symbol?:string; } export interface TimetableHistory {