1- import { FC , useCallback , useContext } from 'react'
1+ import { Dispatch , FC , SetStateAction , useCallback , useContext , useState } from 'react'
22import { NavigateFunction , useNavigate } from 'react-router-dom'
33
44import { Button , profileContext , ProfileContextData } from '../../../../lib'
55import { getAuthenticateAndEnrollRoute , getTCACertificationEnrollPath } from '../../learn.routes'
6+ import { LearnConfig } from '../../learn-config'
7+ import { DiceModal } from '../../course-details/course-curriculum/dice-modal'
68
79interface EnrollCtaBtnProps {
810 certification : string
@@ -11,9 +13,15 @@ interface EnrollCtaBtnProps {
1113const EnrollCtaBtn : FC < EnrollCtaBtnProps > = ( props : EnrollCtaBtnProps ) => {
1214 const navigate : NavigateFunction = useNavigate ( )
1315 const { initialized : profileReady , profile } : ProfileContextData = useContext ( profileContext )
16+ const [ isDiceModalOpen , setIsDiceModalOpen ] : [ boolean , Dispatch < SetStateAction < boolean > > ]
17+ = useState < boolean > ( false )
1418
1519 const isLoggedIn : boolean = profileReady && ! ! profile
1620
21+ function onDiceModalClose ( ) : void {
22+ setIsDiceModalOpen ( false )
23+ }
24+
1725 /**
1826 * Handle user click on start course/resume/login button
1927 */
@@ -29,8 +37,8 @@ const EnrollCtaBtn: FC<EnrollCtaBtnProps> = (props: EnrollCtaBtnProps) => {
2937
3038 // if the user is wipro and s/he hasn't set up DICE,
3139 // let the user know
32- if ( profile ?. isWipro && ! profile . diceEnabled ) {
33- // setIsDiceModalOpen(true)
40+ if ( LearnConfig . REQUIRE_DICE_ID && profile ?. isWipro && ! profile . diceEnabled ) {
41+ setIsDiceModalOpen ( true )
3442 return
3543 }
3644
@@ -45,6 +53,11 @@ const EnrollCtaBtn: FC<EnrollCtaBtnProps> = (props: EnrollCtaBtnProps) => {
4553 label = { isLoggedIn ? 'Enroll Now' : 'Log in to enroll' }
4654 onClick = { handleEnrollClick }
4755 />
56+
57+ < DiceModal
58+ isOpen = { isDiceModalOpen }
59+ onClose = { onDiceModalClose }
60+ />
4861 </ >
4962 )
5063}
0 commit comments