fix: do not change lesson order on deleting last lesson in course

This commit is contained in:
Sergey Yarkov 2022-06-06 22:50:25 +03:00
parent 7d9a9f7d19
commit e64d588833
2 changed files with 4 additions and 3 deletions

View File

@ -46,7 +46,7 @@ const CoursePage: React.FC<IPageProps> = () => {
const isEmptyLessons = course.lessons.length === 0; const isEmptyLessons = course.lessons.length === 0;
const isEmptyStudents = course.students.length === 0; const isEmptyStudents = course.students.length === 0;
const handleWatchCourse = () => history.push(`/lesson/${course.lessons[0].id}`); const handleWatchCourse = () => course.lessons[0] && history.push(`/lesson/${course.lessons[0].id}`);
const handleEditCourse = () => history.push(`/courses/edit/${course.id}`); const handleEditCourse = () => history.push(`/courses/edit/${course.id}`);
@ -74,7 +74,7 @@ const CoursePage: React.FC<IPageProps> = () => {
<Box> <Box>
{(me.isAdmin || me.isTeacher) && <EditButton onClick={handleEditCourse} mr='2' />} {(me.isAdmin || me.isTeacher) && <EditButton onClick={handleEditCourse} mr='2' />}
<Button <Button
isDisabled={!isCourseAvailable} isDisabled={!isCourseAvailable || course.lessons[0] === undefined}
onClick={handleWatchCourse} onClick={handleWatchCourse}
leftIcon={<MdPlayCircleOutline />} leftIcon={<MdPlayCircleOutline />}
size='sm' size='sm'
@ -133,7 +133,7 @@ const CoursePage: React.FC<IPageProps> = () => {
<Text fontSize={'2xl'} fontWeight={'medium'}> <Text fontSize={'2xl'} fontWeight={'medium'}>
What you&apos;ll learn. What you&apos;ll learn.
</Text> </Text>
<Text fontSize={'sm'} mt='2'> <Text fontSize={'sm'} mt='2' textAlign={'justify'}>
{course.education_description} {course.education_description}
</Text> </Text>
</Box> </Box>

View File

@ -69,6 +69,7 @@ const LessonList: React.FC<LessonListPropsType> = ({ course }) => {
const handleChangeOrder = async (ids: string[]) => { const handleChangeOrder = async (ids: string[]) => {
try { try {
if (ids.length <= 0) return;
const data = await LessonServiceInstance.saveOrder(ids); const data = await LessonServiceInstance.saveOrder(ids);
return data; return data;
} catch (error) { } catch (error) {