@@ -50,13 +50,13 @@ const EnrollProfileCompletionInner = () => {
5050 } ) ;
5151 }
5252 else {
53- // Enroll user to tenant
54- await enrollUserTenant ( {
55- userId : storedUserId ,
56- tenantId : program . tenantId ,
57- roleId : storedRoleId ,
58- } ) ;
59- }
53+ // Enroll user to tenant
54+ await enrollUserTenant ( {
55+ userId : storedUserId ,
56+ tenantId : program . tenantId ,
57+ roleId : storedRoleId ,
58+ } ) ;
59+ }
6060 // Get user details to find tenant data
6161 const userResponse = await getUserDetails ( storedUserId , true ) ;
6262 const tenantData = userResponse ?. result ?. userData ?. tenantData ?. find (
@@ -72,68 +72,78 @@ const EnrollProfileCompletionInner = () => {
7272 // Check if user has Learner role
7373 const roles = tenantData ?. roles || [ ] ;
7474 const hasLearnerRole = roles . some ( ( role : any ) => role ?. roleName === 'Learner' ) ;
75-
75+
7676 if ( ! hasLearnerRole && roles . length > 0 ) {
7777 console . error ( 'User does not have Learner role for this program' ) ;
7878 router . push ( '/programs' ) ;
7979 return ;
80- }
81-
82- else {
83- // Set localStorage values similar to callBackSwitchDialog
84- localStorage . setItem ( 'userId' , storedUserId ) ;
85- localStorage . setItem ( 'templtateId' , tenantData ?. templateId ) ;
80+ } else {
81+ // Set localStorage values similar to callBackSwitchDialog
82+ localStorage . setItem ( 'userId' , storedUserId ) ;
83+ localStorage . setItem ( 'templtateId' , tenantData ?. templateId ) ;
8684 localStorage . setItem ( 'userIdName' , userResponse ?. result ?. userData ?. username ) ;
8785 localStorage . setItem ( 'firstName' , userResponse ?. result ?. userData ?. firstName || '' ) ;
8886
89- const tenantId = tenantData ?. tenantId ;
90- const tenantName = tenantData ?. tenantName ;
91- const uiConfig = tenantData ?. params ?. uiConfig ;
92- const landingPage = tenantData ?. params ?. uiConfig ?. landingPage ;
93-
94- localStorage . setItem ( 'landingPage' , landingPage ) ;
95- localStorage . setItem ( 'uiConfig' , JSON . stringify ( uiConfig || { } ) ) ;
96- localStorage . setItem ( 'tenantId' , tenantId ) ;
97- localStorage . setItem ( 'userProgram' , tenantName ) ;
98-
99- // Check profile completion
100- await profileComplitionCheck ( ) ;
101-
102- // Handle academic year for YOUTHNET
103- if ( tenantName === TenantName . YOUTHNET ) {
104- const academicYearResponse = await getAcademicYear ( ) ;
105- if ( academicYearResponse ?. [ 0 ] ?. id ) {
106- localStorage . setItem ( 'academicYearId' , academicYearResponse [ 0 ] . id ) ;
87+ const tenantId = tenantData ?. tenantId ;
88+ const tenantName = tenantData ?. tenantName ;
89+ const uiConfig = tenantData ?. params ?. uiConfig ;
90+ const landingPage = tenantData ?. params ?. uiConfig ?. landingPage ;
91+
92+ localStorage . setItem ( 'landingPage' , landingPage ) ;
93+ localStorage . setItem ( 'uiConfig' , JSON . stringify ( uiConfig || { } ) ) ;
94+ localStorage . setItem ( 'tenantId' , tenantId ) ;
95+ localStorage . setItem ( 'userProgram' , tenantName ) ;
96+
97+ // Check profile completion
98+ await profileComplitionCheck ( ) ;
99+
100+ // Handle academic year for YOUTHNET
101+ if ( tenantName === TenantName . YOUTHNET ) {
102+ const academicYearResponse = await getAcademicYear ( ) ;
103+ if ( academicYearResponse ?. [ 0 ] ?. id ) {
104+ localStorage . setItem ( 'academicYearId' , academicYearResponse [ 0 ] . id ) ;
105+ }
107106 }
108- }
109-
110- // Set channel and collection framework
111- const channelId = tenantData ?. channelId ;
112- localStorage . setItem ( 'channelId' , channelId ) ;
113107
114- const collectionFramework = tenantData ?. collectionFramework ;
115- localStorage . setItem ( 'collectionFramework' , collectionFramework ) ;
108+ // Set channel and collection framework
109+ const channelId = tenantData ?. channelId ;
110+ localStorage . setItem ( 'channelId' , channelId ) ;
116111
117- // Set cookie
118- document . cookie = `token= ${ token } ; path=/; secure; SameSite=Strict` ;
112+ const collectionFramework = tenantData ?. collectionFramework ;
113+ localStorage . setItem ( 'collectionFramework' , collectionFramework ) ;
119114
120- // Log analytics event
121- logEvent ( {
122- action : 'access-program-after-enrollment' ,
123- category : 'Enrollment Profile Completion' ,
124- label : 'Profile Completed and Program Accessed' ,
125- } ) ;
115+ // Set cookie
116+ document . cookie = `token=${ token } ; path=/; secure; SameSite=Strict` ;
126117
127- // Clean up enrolled program data
128- localStorage . removeItem ( 'enrolledProgramData' ) ;
129- localStorage . removeItem ( 'previousTenantId' ) ;
130-
131- // Store landing page for later navigation
132- setLandingPage ( landingPage || '/home' ) ;
118+ // Log analytics event
119+ logEvent ( {
120+ action : 'access-program-after-enrollment' ,
121+ category : 'Enrollment Profile Completion' ,
122+ label : 'Profile Completed and Program Accessed' ,
123+ } ) ;
133124
134- // Show success modal instead of redirecting immediately
135- setSignupSuccessModal ( true ) ;
136- }
125+ // Clean up enrolled program data
126+ localStorage . removeItem ( 'enrolledProgramData' ) ;
127+ localStorage . removeItem ( 'previousTenantId' ) ;
128+
129+ // Store landing page for later navigation
130+ const finalLandingPage = landingPage || '/home' ;
131+ setLandingPage ( finalLandingPage ) ;
132+
133+ // Check if isForNavaPatham is true, skip popup and directly trigger start learning action
134+ const isForNavaPatham =
135+ typeof window !== 'undefined'
136+ ? localStorage . getItem ( 'isForNavaPatham' ) === 'true'
137+ : false ;
138+
139+ if ( isForNavaPatham ) {
140+ // Skip popup and directly trigger start learning action
141+ onSigin ( finalLandingPage ) ;
142+ } else {
143+ // Show success modal instead of redirecting immediately
144+ setSignupSuccessModal ( true ) ;
145+ }
146+ }
137147 } catch ( error ) {
138148 console . error ( 'Failed to access program:' , error ) ;
139149 router . push ( '/programs' ) ;
@@ -144,36 +154,36 @@ const EnrollProfileCompletionInner = () => {
144154 setSignupSuccessModal ( false ) ;
145155 } ;
146156
147- const onSigin = ( ) => {
157+ const onSigin = ( customLandingPage ?: string ) => {
148158 setSignupSuccessModal ( false ) ;
149159 console . log ( 'enroll user to tenant' , localStorage . getItem ( 'tenantId' ) ) ;
150- if ( localStorage . getItem ( 'isAndroidApp' ) == 'yes' )
151- {
152- // Send message to React Native WebView
153-
154- // const enrolledProgramData = localStorage.getItem('enrolledProgramData');
155-
156- // const program = JSON.parse(enrolledProgramData || '{}');
157-
158-
159- if ( window . ReactNativeWebView ) {
160- window . ReactNativeWebView . postMessage ( JSON . stringify ( {
161- type : 'ENROLL_PROGRAM_EVENT' , // Event type identifier
162- data : {
163- userId : localStorage . getItem ( 'userId' ) ,
164- tenantId : localStorage . getItem ( 'tenantId' ) ,
165- token : localStorage . getItem ( 'token' ) ,
166- refreshToken : localStorage . getItem ( 'refreshTokenForAndroid' ) ,
167-
168- // Add any data you want to send
169- }
170- } ) ) ;
171- }
172- }
173- else {
174- localStorage . removeItem ( 'enrollTenantId' )
175- router . push ( landingPage || '/home' ) ;
160+ const targetLandingPage = customLandingPage || landingPage || '/home' ;
161+
162+ if ( localStorage . getItem ( 'isAndroidApp' ) == 'yes' ) {
163+ // Send message to React Native WebView
176164
165+ // const enrolledProgramData = localStorage.getItem('enrolledProgramData');
166+
167+ // const program = JSON.parse(enrolledProgramData || '{}');
168+
169+ if ( window . ReactNativeWebView ) {
170+ window . ReactNativeWebView . postMessage (
171+ JSON . stringify ( {
172+ type : 'ENROLL_PROGRAM_EVENT' , // Event type identifier
173+ data : {
174+ userId : localStorage . getItem ( 'userId' ) ,
175+ tenantId : localStorage . getItem ( 'tenantId' ) ,
176+ token : localStorage . getItem ( 'token' ) ,
177+ refreshToken : localStorage . getItem ( 'refreshTokenForAndroid' ) ,
178+
179+ // Add any data you want to send
180+ } ,
181+ } )
182+ ) ;
183+ }
184+ } else {
185+ localStorage . removeItem ( 'enrollTenantId' ) ;
186+ router . push ( targetLandingPage ) ;
177187 }
178188 // Navigate to landing page
179189 } ;
@@ -185,7 +195,7 @@ const EnrollProfileCompletionInner = () => {
185195 enrolledProgram = { true }
186196 uponEnrollCompletion = { handleAccessProgram }
187197 />
188-
198+
189199 < SimpleModal
190200 open = { signupSuccessModal }
191201 onClose = { onCloseSignupSuccessModal }
@@ -210,4 +220,3 @@ const EnrollProfileCompletionPage = () => {
210220} ;
211221
212222export default EnrollProfileCompletionPage ;
213-
0 commit comments