From 57519effaf4e31a367efa63f19348b0cd8178b85 Mon Sep 17 00:00:00 2001 From: Anna Gavrilman Date: Wed, 27 Mar 2024 15:22:59 -0400 Subject: [PATCH] Upgrade enrollment dialog fixes (#2141) --- .../components/CourseProductDetailEnroll.js | 43 ++--------- .../CourseProductDetailEnroll_test.js | 75 +++++++++++++++++++ 2 files changed, 80 insertions(+), 38 deletions(-) diff --git a/frontend/public/src/components/CourseProductDetailEnroll.js b/frontend/public/src/components/CourseProductDetailEnroll.js index 06b0b6948..bf0132012 100644 --- a/frontend/public/src/components/CourseProductDetailEnroll.js +++ b/frontend/public/src/components/CourseProductDetailEnroll.js @@ -132,44 +132,9 @@ export class CourseProductDetailEnroll extends React.Component< this.toggleAddlProfileFieldsModal() } } - - async checkForExistingEnrollment(run: EnrollmentFlaggedCourseRun) { - // Find an existing enrollment - the default should be the audit enrollment - // already have, so you can just upgrade in place. If you don't, you get the - // current run (which should be the first available one). - // This was changed to also make sure the run you're enrolled in is upgradeable. - const { enrollments } = this.props - - if (enrollments) { - const firstAuditEnrollment = enrollments.find( - (enrollment: RunEnrollment) => - enrollment.run.course.id === run.course.id && - enrollment.enrollment_mode === "audit" && - enrollment.run.enrollment_end !== null && - enrollment.run.enrollment_end > moment.now() && - (enrollment.run.upgrade_deadline === null || - enrollment.run.upgrade_deadline > moment.now()) - ) - - if (firstAuditEnrollment) { - this.setCurrentCourseRun(firstAuditEnrollment.run) - return - } - } - - this.setCurrentCourseRun(run) - } - toggleUpgradeDialogVisibility = () => { const { upgradeEnrollmentDialogVisibility } = this.state - const run = this.getCurrentCourseRun() - - if (!upgradeEnrollmentDialogVisibility) { - this.checkForExistingEnrollment(run) - } else { - window.location = "/dashboard/" - } - + this.setCurrentCourseRun(null) this.setState({ upgradeEnrollmentDialogVisibility: !upgradeEnrollmentDialogVisibility }) @@ -308,6 +273,7 @@ export class CourseProductDetailEnroll extends React.Component< ) : null const { upgradeEnrollmentDialogVisibility } = this.state const product = run && run.products ? run.products[0] : null + const canUpgrade = run && run.is_upgradable && product const upgradableCourseRuns = courseRuns ? courseRuns.filter( (run: EnrollmentFlaggedCourseRun) => run.is_upgradable @@ -376,11 +342,12 @@ export class CourseProductDetailEnroll extends React.Component< Certificate track:{" "} {product && + run.is_upgradable && formatLocalePrice(getFlexiblePriceForProduct(product))} <>
- {product && run.upgrade_deadline ? ( + {canUpgrade ? ( Payment date:{" "} {formatPrettyDate(moment(run.upgrade_deadline))} @@ -407,7 +374,7 @@ export class CourseProductDetailEnroll extends React.Component<