Skip to content

Commit

Permalink
3400 remove enrolled state and modal default (#2065)
Browse files Browse the repository at this point in the history
* remove enrolled state and change the enrollable sort

* format

* remove test

* remove test

* remove test

* validate paid enrollment
  • Loading branch information
rachellougee authored Jan 22, 2024
1 parent e59c750 commit 5a1a5b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 122 deletions.
10 changes: 9 additions & 1 deletion courses/views/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
CourseRunEnrollment,
Department,
LearnerProgramRecordShare,
PaidCourseRun,
PartnerSchool,
Program,
ProgramEnrollment,
Expand All @@ -60,8 +61,9 @@
USER_MSG_TYPE_ENROLL_BLOCKED,
USER_MSG_TYPE_ENROLL_FAILED,
USER_MSG_TYPE_ENROLLED,
USER_MSG_TYPE_ENROLL_DUPLICATED,
)
from main.utils import encode_json_cookie_value
from main.utils import encode_json_cookie_value, redirect_with_user_message
from openedx.api import (
subscribe_to_edx_course_emails,
sync_enrollments_with_edx,
Expand Down Expand Up @@ -269,6 +271,12 @@ def _validate_enrollment_post_request(
max_age=USER_MSG_COOKIE_MAX_AGE,
)
return resp, None, None
if PaidCourseRun.fulfilled_paid_course_run_exists(user, run):
resp = redirect_with_user_message(
reverse("user-dashboard"),
{"type": USER_MSG_TYPE_ENROLL_DUPLICATED},
)
return resp, None, None
return None, user, run


Expand Down
49 changes: 2 additions & 47 deletions frontend/public/src/components/CourseProductDetailEnroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,9 @@ export class CourseProductDetailEnroll extends React.Component<
courseRuns
.sort(
(a: EnrollmentFlaggedCourseRun, b: EnrollmentFlaggedCourseRun) => {
if (
moment(a.enrollment_start).isBefore(moment(b.enrollment_start))
) {
if (moment(a.start_date).isBefore(moment(b.start_date))) {
return -1
} else if (
moment(a.enrollment_start).isAfter(moment(b.enrollment_start))
) {
} else if (moment(a.start_date).isAfter(moment(b.start_date))) {
return 1
} else {
return 0
Expand Down Expand Up @@ -481,45 +477,6 @@ export class CourseProductDetailEnroll extends React.Component<
)
}

renderEnrolledButton(run: EnrollmentFlaggedCourseRun) {
const startDate =
run && !emptyOrNil(run.start_date)
? moment(new Date(run.start_date))
: null
const waitingForCourseToBeginMessage = moment().isBefore(startDate) ? (
<p style={{ fontSize: "16px" }}>
Enrolled and waiting for the course to begin.
</p>
) : null
const disableEnrolledBtn = moment().isBefore(startDate) ? "disabled" : ""
return run && run.is_enrolled ? (
<>
<Fragment>
{run.courseware_url ? (
<a
href={run.courseware_url}
onClick={ev =>
run ? this.redirectToCourseHomepage(run.courseware_url, ev) : ev
}
className={`btn btn-primary btn-enrollment-button btn-gradient-red highlight outline ${disableEnrolledBtn}`}
target="_blank"
rel="noopener noreferrer"
>
Enrolled &#10003;
</a>
) : (
<div
className={`btn btn-primary btn-enrollment-button btn-gradient-red highlight outline ${disableEnrolledBtn}`}
>
Enrolled &#10003;
</div>
)}
{waitingForCourseToBeginMessage}
</Fragment>
</>
) : null
}

renderEnrollLoginButton() {
const { currentUser } = this.props
return !currentUser || !currentUser.id ? (
Expand All @@ -545,7 +502,6 @@ export class CourseProductDetailEnroll extends React.Component<
return currentUser &&
currentUser.id &&
run &&
!run.is_enrolled &&
isWithinEnrollmentPeriod(run) ? (
<h2>
{product && run.is_upgradable ? (
Expand Down Expand Up @@ -600,7 +556,6 @@ export class CourseProductDetailEnroll extends React.Component<
// $FlowFixMe: isLoading null or undefined
<Loader key="product_detail_enroll_loader" isLoading={isLoading}>
<>
{this.renderEnrolledButton(run)}
{this.renderEnrollLoginButton()}
{this.renderEnrollNowButton(run, product)}

Expand Down
74 changes: 0 additions & 74 deletions frontend/public/src/components/CourseProductDetailEnroll_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
// @flow
import { assert } from "chai"
import moment from "moment-timezone"
import React from "react"

import IntegrationTestHelper from "../util/integration_test_helper"
import CourseProductDetailEnroll, {
CourseProductDetailEnroll as InnerCourseProductDetailEnroll
} from "./CourseProductDetailEnroll"

import { courseRunsSelector } from "../lib/queries/courseRuns"
import {
makeCourseDetailWithRuns,
makeCourseRunDetail,
Expand Down Expand Up @@ -198,78 +196,6 @@ describe("CourseProductDetailEnrollShallowRender", () => {
"Enroll now"
)
})

it("checks for disabled enrolled button", async () => {
const userEnrollment = makeCourseRunEnrollment()

userEnrollment.run["start_date"] = moment().add(2, "M")
const expectedResponse = {
...userEnrollment.run,
is_enrolled: true
}

const { inner, store } = await renderPage(
{
entities: {
courseRuns: [expectedResponse]
},
queries: {
courseRuns: {
isPending: false,
status: 200
}
}
},
{}
)

const item = inner.find("a").first()
assert.isTrue(item.hasClass("disabled"))
assert.isTrue(
inner.containsMatchingElement(
<p>Enrolled and waiting for the course to begin.</p>
)
)

assert.equal(item.text(), "Enrolled ✓")
assert.equal(courseRunsSelector(store.getState())[0], expectedResponse)
})

it("checks for enrolled button", async () => {
const userEnrollment = makeCourseRunEnrollment()
userEnrollment.run["start_date"] = moment().add(-2, "M")
const expectedResponse = {
...userEnrollment.run,
is_enrolled: true
}

const { inner, store } = await renderPage(
{
entities: {
courseRuns: [expectedResponse]
},
queries: {
courseRuns: {
isPending: false,
status: 200
}
}
},
{}
)

const item = inner.find("a").first()

assert.isFalse(item.hasClass("disabled"))
assert.isFalse(
inner.containsMatchingElement(
<p>Enrolled and waiting for the course to begin.</p>
)
)

assert.equal(item.text(), "Enrolled ✓")
assert.equal(courseRunsSelector(store.getState())[0], expectedResponse)
})
;[
[true, false],
[false, false],
Expand Down

0 comments on commit 5a1a5b8

Please sign in to comment.