diff --git a/src/components/coursemanage/lecture.tsx b/src/components/coursemanage/lecture.tsx index 5bb033f..e4aaf16 100644 --- a/src/components/coursemanage/lecture.tsx +++ b/src/components/coursemanage/lecture.tsx @@ -12,13 +12,14 @@ import { TableCell, TableRow, Typography, - Tooltip + Tooltip, + Alert } from '@mui/material'; import * as React from 'react'; import { Assignment } from '../../model/assignment'; import { Lecture } from '../../model/lecture'; import { deleteAssignment } from '../../services/assignments.service'; -import { CreateDialog, EditLectureDialog } from '../util/dialog'; +import { CreateDialog, EditLectureDialog, IEditLectureProps } from '../util/dialog'; import { updateLecture } from '../../services/lectures.service'; import { red, grey } from '@mui/material/colors'; import { enqueueSnackbar } from 'notistack'; @@ -157,6 +158,26 @@ export const LectureComponent = () => { const [lectureState, setLecture] = React.useState(lecture); const [assignmentsState, setAssignments] = React.useState(assignments); + const [isEditDialogOpen, setEditDialogOpen] = React.useState(false); + + const handleOpenEditDialog = () => { + setEditDialogOpen(true); + }; + + + const handleUpdateLecture = (updatedLecture) => { + updateLecture(updatedLecture).then( + (response) => { + setLecture(response); + }, + (error) => { + enqueueSnackbar(error.message, { + variant: 'error', + }); + } + ); + }; + if (navigation.state === 'loading') { return ( @@ -186,38 +207,42 @@ export const LectureComponent = () => { ) : null} - { - setAssignments((oldAssignments: Assignment[]) => [ - ...oldAssignments, - assigment - ]); - }} - /> - { - updateLecture(updatedLecture).then( - response => { - setLecture(response); - }, - error => { - enqueueSnackbar(error.message, { - variant: 'error' - }); - } - ); - }} - /> + + {lecture.code === lecture.name ? ( + + The name of the lecture is identical to the lecture code.{' '} + + Rename Lecture. + + + ) : null} + + + + { + setAssignments((oldAssignments: Assignment[]) => [ + ...oldAssignments, + assigment + ]); + }} + /> + setEditDialogOpen(false)} + /> + + Assignments diff --git a/src/components/util/dialog.tsx b/src/components/util/dialog.tsx index 1677ac3..65b159b 100644 --- a/src/components/util/dialog.tsx +++ b/src/components/util/dialog.tsx @@ -88,6 +88,8 @@ const validationSchemaLecture = yup.object({ export interface IEditLectureProps { lecture: Lecture; handleSubmit: (updatedLecture: Lecture) => void; + open: boolean; + handleClose: () => void; } const EditLectureNameTooltip = styled( @@ -114,7 +116,12 @@ export const EditLectureDialog = (props: IEditLectureProps) => { } }); + const { open, handleClose } = props; const [openDialog, setOpen] = React.useState(false); + const openDialogFunction = () => { + setOpen(true); + }; + return (
@@ -138,7 +145,7 @@ export const EditLectureDialog = (props: IEditLectureProps) => { { e.stopPropagation(); - setOpen(true); + openDialogFunction(); }} onMouseDown={event => event.stopPropagation()} aria-label="edit" @@ -146,7 +153,8 @@ export const EditLectureDialog = (props: IEditLectureProps) => { - setOpen(false)}> + { setOpen(false); handleClose(); }}> Edit Lecture
@@ -182,6 +190,7 @@ export const EditLectureDialog = (props: IEditLectureProps) => { variant="outlined" onClick={() => { setOpen(false); + handleClose(); }} > Cancel