Skip to content

Commit

Permalink
bug: ENT-3715 enroll button cta bug fix for codes (#170)
Browse files Browse the repository at this point in the history
* feat: update hooks to prepare for upcoming changes, not used yet

* feat: disable enroll unless feature on and dialog on invalid userSubsidy

* feat: remove unused hook change, for next round
  • Loading branch information
binodpant authored Dec 18, 2020
1 parent 55c4e18 commit c8529a0
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions src/components/course/EnrollButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { CourseContext } from './CourseContextProvider';
import EnrollButtonLabel from './EnrollButtonLabel';
import EnrollModal from './EnrollModal';

import { features } from '../../config';

import { useCourseEnrollmentUrl } from './data/hooks';

import {
hasCourseStarted,
findUserEnrollmentForCourse,
Expand Down Expand Up @@ -108,20 +111,48 @@ export default function EnrollButton() {
</EnrollButtonWrapper>
);

const enrollBtnDisabled = (
<EnrollButtonCta
as="div"
className="btn btn-light btn-block disabled"
/>
);

const enrollLinkClass = 'btn-block';

if (!userEnrollment && isEnrollable) {
// enroll with a subscription license
if (enrollmentUrl && subscriptionLicense) {
if (userSubsidy) {
return (
<EnrollButtonCta
as="a"
className={classNames('btn btn-primary btn-brand-primary', enrollLinkClass)}
href={enrollmentUrl}
/>
);
}
// no user subsidy means we need to warn user with a dialog
return (
<EnrollButtonCta
as="a"
className={classNames('btn btn-primary btn-brand-primary', enrollLinkClass)}
href={enrollmentUrl}
/>
<>
<EnrollButtonCta
className={enrollLinkClass}
onClick={() => setIsModalOpen(true)}
/>
<EnrollModal
isModalOpen={isModalOpen}
setIsModalOpen={setIsModalOpen}
offersCount={offersCount}
courseHasOffer={!!findOfferForCourse(offers, catalogList)}
enrollmentUrl={enrollmentUrl}
/>
</>
);
}
// enroll with an offer (code)
if (!features.ENROLL_WITH_CODES) { // can't do offer based enrollment yet without switch
return enrollBtnDisabled;
}
if (enrollmentUrl) {
return (
<>
Expand All @@ -146,12 +177,7 @@ export default function EnrollButton() {
}

if (!userEnrollment && !isEnrollable) {
return (
<EnrollButtonCta
as="div"
className="btn btn-light btn-block disabled"
/>
);
return enrollBtnDisabled;
}

if (userEnrollment) {
Expand Down

0 comments on commit c8529a0

Please sign in to comment.