Skip to content

Commit

Permalink
handle expires outside of util function
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewJakubowicz committed Jul 24, 2018
1 parent 7a7031e commit 7432d42
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
11 changes: 4 additions & 7 deletions app/core/utils.coffee
Expand Up @@ -671,15 +671,12 @@ emailRegex = /[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,63}/
isValidEmail = (email) ->
emailRegex.test(email?.trim().toLowerCase())

formatStudentStatusDate = (status, expires, format) ->
formatStudentLicenseStatusDate = (status, date) ->
string = switch status
when 'not-enrolled' then $.i18n.t('teacher.status_not_enrolled')
when 'enrolled' then (if expires then $.i18n.t('teacher.status_enrolled') else '-')
when 'enrolled' then (if date then $.i18n.t('teacher.status_enrolled') else '-')
when 'expired' then $.i18n.t('teacher.status_expired')
if expires
string.replace('{{date}}', moment(expires).utc().format(format))
else
string.replace('{{date}}', "Never")
string.replace('{{date}}', date or 'Never')

module.exports = {
ageOfConsent
Expand All @@ -695,7 +692,7 @@ module.exports = {
findNextLevel
findNextAssessmentForLevel
formatDollarValue
formatStudentStatusDate
formatStudentLicenseStatusDate
functionCreators
getByPath
getCourseBundlePrice
Expand Down
3 changes: 2 additions & 1 deletion app/views/courses/TeacherClassView.coffee
Expand Up @@ -767,7 +767,8 @@ module.exports = class TeacherClassView extends RootView
studentStatusString: (student) ->
status = student.prepaidStatus()
expires = student.get('coursePrepaid')?.endDate
utils.formatStudentStatusDate(status, expires, 'll')
date = if expires? then moment(expires).utc().format('ll') else ''
utils.formatStudentLicenseStatusDate(status, date)

getTopScore: ({level, session}) ->
return unless level and session
Expand Down
3 changes: 2 additions & 1 deletion app/views/teachers/EditStudentModal.coffee
Expand Up @@ -59,7 +59,8 @@ module.exports = class EditStudentModal extends ModalView
studentStatusString: (student) ->
status = student.prepaidStatus()
expires = student.get('coursePrepaid')?.endDate
utils.formatStudentStatusDate(status, expires, 'll')
date = if expires? then moment(expires).utc().format('ll') else ''
utils.formatStudentLicenseStatusDate(status, date)

onClickEnrollStudentButton: ->
return unless me.id is @classroom.get('ownerID')
Expand Down
3 changes: 2 additions & 1 deletion app/views/teachers/TeacherStudentView.coffee
Expand Up @@ -403,7 +403,8 @@ module.exports = class TeacherStudentView extends RootView
status = @user.prepaidStatus()
return "" unless @user.get('coursePrepaid')
expires = @user.get('coursePrepaid')?.endDate
utils.formatStudentStatusDate(status, expires, 'l')
date = if expires? then moment(expires).utc().format('l') else ''
utils.formatStudentLicenseStatusDate(status, date)


# TODO: Hookup enroll/assign functionality
Expand Down

0 comments on commit 7432d42

Please sign in to comment.