Skip to content

Commit

Permalink
Merge pull request #929 from mitodl/910-dashboard-doesnt-refresh-when…
Browse files Browse the repository at this point in the history
…-user-unenrolls-from-course-in-a-program

910 dashboard doesnt refresh when user unenrolls from course in a program
  • Loading branch information
rachellougee authored Sep 6, 2022
2 parents 3412289 + 77c0197 commit 6c364bf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
13 changes: 10 additions & 3 deletions frontend/public/src/components/EnrolledItemCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ type EnrolledItemCardProps = {
enrollmentId: number,
emailsSubscription: string
) => Promise<any>,
addUserNotification: Function
addUserNotification: Function,
closeDrawer:Function,
}

type EnrolledItemCardState = {
Expand Down Expand Up @@ -73,7 +74,7 @@ export class EnrolledItemCard extends React.Component<
}

async onDeactivate(enrollment: RunEnrollment) {
const { deactivateEnrollment, addUserNotification } = this.props
const { deactivateEnrollment, addUserNotification, closeDrawer } = this.props

if (enrollment.enrollment_mode === "verified") {
this.toggleVerifiedUnenrollmentModalVisibility()
Expand All @@ -91,6 +92,9 @@ export class EnrolledItemCard extends React.Component<
messageType = ALERT_TYPE_DANGER
userMessage = `Something went wrong with your request to unenroll. Please contact support at ${SETTINGS.support_email}.`
}
if (typeof closeDrawer === "function") {
closeDrawer()
}
addUserNotification({
"unenroll-status": {
type: messageType,
Expand All @@ -107,7 +111,7 @@ export class EnrolledItemCard extends React.Component<
}

async onSubmit(payload: Object) {
const { courseEmailsSubscription, addUserNotification } = this.props
const { courseEmailsSubscription, addUserNotification, closeDrawer } = this.props
this.setState({ submittingEnrollmentId: payload.enrollmentId })
this.toggleEmailSettingsModalVisibility()
try {
Expand All @@ -127,6 +131,9 @@ export class EnrolledItemCard extends React.Component<
messageType = ALERT_TYPE_DANGER
userMessage = `Something went wrong with your request to course ${payload.courseNumber} emails subscription. Please contact support at ${SETTINGS.support_email}.`
}
if (typeof closeDrawer === "function") {
closeDrawer()
}
addUserNotification({
"subscription-status": {
type: messageType,
Expand Down
4 changes: 3 additions & 1 deletion frontend/public/src/components/EnrolledItemCard_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe("EnrolledItemCard", () => {
currentUser,
isLinkableStub,
enrollmentCardProps,
isFinancialAssistanceAvailableStub
isFinancialAssistanceAvailableStub,
closeDrawer


beforeEach(() => {
Expand Down Expand Up @@ -56,6 +57,7 @@ describe("EnrolledItemCard", () => {
enrollmentCardProps.courseEmailsSubscription
}
addUserNotification={enrollmentCardProps.addUserNotification}
closeDrawer={closeDrawer}
/>
)
})
Expand Down
1 change: 1 addition & 0 deletions frontend/public/src/components/ProgramEnrollmentDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class ProgramEnrollmentDrawer extends React.Component<ProgramEnrollmentDr
currentUser={currentUser}
deactivateEnrollment={deactivateEnrollment}
courseEmailsSubscription={courseEmailsSubscription}
closeDrawer = {closeDrawer}
addUserNotification={addUserNotification}>
</EnrolledItemCard>
))) : (
Expand Down
5 changes: 4 additions & 1 deletion frontend/public/src/containers/pages/DashboardPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ type DashboardPageProps = {
enrollmentId: number,
emailsSubscription: string
) => Promise<any>,
addUserNotification: Function
addUserNotification: Function,
closeDrawer: Function,
}

type DashboardPageState = {
Expand Down Expand Up @@ -259,6 +260,7 @@ export class DashboardPage extends React.Component<
deactivateEnrollment,
courseEmailsSubscription,
addUserNotification,
closeDrawer,
} = this.props

if (isProgramUIEnabled() && programEnrollments) {
Expand All @@ -277,6 +279,7 @@ export class DashboardPage extends React.Component<
deactivateEnrollment={deactivateEnrollment}
courseEmailsSubscription={courseEmailsSubscription}
addUserNotification={addUserNotification}
closeDrawer={closeDrawer}
></EnrolledItemCard>
)
}
Expand Down
9 changes: 8 additions & 1 deletion frontend/public/src/lib/queries/enrollment.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ export const deactivateEnrollmentMutation = (enrollmentId: number) => ({
return emptyOrNil(prevEnrollments)
? []
: prevEnrollments.filter(enrollment => enrollment.id !== enrollmentId)
}
},
program_enrollments: prevProgramEnrollments => {
return emptyOrNil(prevProgramEnrollments)
? []
: prevProgramEnrollments.map(programEnrollment => {
return {...programEnrollment, enrollments: programEnrollment.enrollments.filter(enrollment => enrollment.id !== enrollmentId)}
})
},
}
})

Expand Down

0 comments on commit 6c364bf

Please sign in to comment.