Skip to content

Commit b263458

Browse files
authored
Merge pull request #3645 from openstax/rm-previews
drop self from all courses, including previews
2 parents 0239399 + 25a7be2 commit b263458

File tree

1 file changed

+12
-15
lines changed
  • tutor/src/screens/my-courses/dashboard

1 file changed

+12
-15
lines changed

tutor/src/screens/my-courses/dashboard/index.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { React, useState, observer } from 'vendor'
22
import { Button } from 'react-bootstrap'
3-
import { map, filter, findIndex, every, sumBy } from 'lodash'
3+
import { map, filter, every, sumBy } from 'lodash'
44
import styled from 'styled-components'
55
import { colors } from '../../../theme'
66
import { Icon } from 'shared'
77
import { ID } from '../../../models/types'
8-
import { currentCourses } from '../../../models'
8+
import { currentCourses, currentOfferings } from '../../../models'
99
import OfferingBlock from './offering-block'
1010
import AddSubjectDropdown from './add-subject-dropdown'
1111
import { DeleteOfferingModal, DeleteOfferingWarningModal } from './delete-offering-modal'
@@ -130,22 +130,19 @@ export const MyCoursesDashboard = observer(() => {
130130

131131
// delete offering
132132
const deleteOffering = () => {
133-
const tempDisplayedOfferingIds = [...displayedOfferingIds]
134-
const index = findIndex(tempDisplayedOfferingIds, id => id === deleteOfferingIdModal)
135-
if (index >= 0 && deleteOfferingIdModal) {
136-
const offeringCourses = filter(courses.array, c => c.offering_id === deleteOfferingIdModal && !c.is_preview)
137-
Promise.all(map(offeringCourses, async c => {
138-
return c.teachers.current?.drop() || Promise.resolve()
139-
})).then(() => {
140-
tempDisplayedOfferingIds.splice(index, 1)
141-
setDisplayedOfferingIds(tempDisplayedOfferingIds)
142-
setDeleteOfferingIdModal(null)
143-
})
144-
}
133+
if (!deleteOfferingIdModal) return
134+
const offering = currentOfferings.get(deleteOfferingIdModal)
135+
if (!offering) return
136+
Promise.all(courses.forOffering(offering).array.map(c => {
137+
return c.teachers.current?.drop() || Promise.resolve()
138+
})).then(() => {
139+
setDisplayedOfferingIds(displayedOfferingIds.filter(id => id != offering.id))
140+
setDeleteOfferingIdModal(null)
141+
})
145142
}
146143

147144
const renderDeleteModal = () => {
148-
const offeringCourses = filter(courses.array, c => c.offering_id === deleteOfferingIdModal)
145+
const offeringCourses = courses.array.filter(c => c.offering_id == deleteOfferingIdModal)
149146
const areAllPreviewCourses = every(offeringCourses, oc => oc.is_preview)
150147
const areAllNonPreviewCoursesWithoutStudents = every(filter(offeringCourses, c => String(c.term) !== 'preview'), oc => sumBy(oc?.periods, (p:any) => {
151148
return p.num_enrolled_students

0 commit comments

Comments
 (0)