Skip to content

Commit

Permalink
Assorted fixes for More Dates selector in existing design (#1903)
Browse files Browse the repository at this point in the history
- Adds a filter to `get_user_relevant_course_run_qset` to only consider Live courses (this can be moved to the CoursePage model too)
- Fixes the onclick handler for More Dates to only work on buttons - you could technically activate it on the disabled <p> tags too and then enroll in something you shouldn't
- Updates date selector to find the first unenrolled courserun if there's not one explicitly selected, rather than just the first in the list
  • Loading branch information
jkachel authored Sep 28, 2023
1 parent 1e9a0f1 commit c5959e2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
6 changes: 5 additions & 1 deletion cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,11 +1129,15 @@ def get_admin_display_title(self):
return f"{self.course.readable_id} | {self.title}"

def get_context(self, request, *args, **kwargs):
now = now_in_utc()

relevant_run = get_user_relevant_course_run(
course=self.product, user=request.user
)
relevant_runs = list(
get_user_relevant_course_run_qset(course=self.product, user=request.user)
get_user_relevant_course_run_qset(
course=self.product, user=request.user
).filter(models.Q(enrollment_end=None) | models.Q(enrollment_end__gt=now))
)
is_enrolled = (
False
Expand Down
14 changes: 8 additions & 6 deletions cms/templates/product_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,15 @@ <h1>{{ page.title }}</h1>
<p>Click below to enroll in one of these dates</p>
</div>
{% for course_run in course_runs %}
<div>
{% if course_run.is_not_beyond_enrollment %}
<button class='date-link' id='{{ course_run.courseware_id }}' >Start Date {{ course_run.start_date|date:'F j, Y' }}</button>
{% else %}
<p class='date-link-disabled' id='{{ course_run.courseware_id }}' >{{ course_run.start_date|date:'F j, Y' }}(enrollment opens {{ course_run.enrollment_start|date:'F j, Y' }})</p>
<div>
{% if course_run.is_not_beyond_enrollment %}
<button class='date-link' id='{{ course_run.courseware_id }}' >Start Date {{ course_run.start_date|date:'F j, Y' }}</button>
{% else %}
{% if not course_run.is_past %}
<p class='date-link-disabled' id='{{ course_run.courseware_id }}' >{{ course_run.start_date|date:'F j, Y' }}(enrollment opens {{ course_run.enrollment_start|date:'F j, Y' }})</p>
{% endif %}
</div>
{% endif %}
</div>
{% endfor %}
">
More Dates
Expand Down
7 changes: 6 additions & 1 deletion courses/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ def _relevant_course_qset_filter(
Does the actual filtering for user_relevant_course_run_qset and
user_relevant_program_course_run_qset.
"""

now = now or now_in_utc()
run_qset = (
run_qset.exclude(start_date=None)
.exclude(enrollment_start=None)
.filter(live=True)
)
if user and user.is_authenticated:
user_enrollments = Count(
"enrollments",
Expand Down
20 changes: 18 additions & 2 deletions frontend/public/src/components/CourseProductDetailEnroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,23 @@ export class CourseProductDetailEnroll extends React.Component<
return this.state.currentCourseRun
}

getFirstUnenrolledCourseRun = (): EnrollmentFlaggedCourseRun => {
const { courseRuns } = this.props

return courseRuns
? courseRuns.find(
(run: EnrollmentFlaggedCourseRun) =>
run.is_enrolled === false &&
moment(run.enrollment_start) <= moment.now()
) || courseRuns[0]
: null
}

renderUpgradeEnrollmentDialog(showNewDesign: boolean) {
const { courseRuns, courses } = this.props
const run =
!this.getCurrentCourseRun() && courseRuns
? courseRuns[0]
? this.getFirstUnenrolledCourseRun()
: this.getCurrentCourseRun()

const course =
Expand Down Expand Up @@ -504,7 +516,11 @@ export class CourseProductDetailEnroll extends React.Component<
courseRuns.map(courseRun => {
// $FlowFixMe
document.addEventListener("click", function(e) {
if (e.target && e.target.id === courseRun.courseware_id) {
if (
e.target &&
e.target.tagName.toLowerCase() === "button" &&
e.target.id === courseRun.courseware_id
) {
thisScope.setCurrentCourseRun(courseRun)
run = thisScope.getCurrentCourseRun()
product = run && run.products ? run.products[0] : null
Expand Down

0 comments on commit c5959e2

Please sign in to comment.