Skip to content

Commit 8119ca3

Browse files
authored
Merge pull request #2489 from tekdi/release-1.13.0-prod-register
Release 1.13.0 prod register to learner qa
2 parents 79943e1 + 2aad1d1 commit 8119ca3

File tree

5 files changed

+219
-8
lines changed

5 files changed

+219
-8
lines changed

apps/learner-web-app/src/app/enroll-profile-completion/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ const EnrollProfileCompletionInner = () => {
171171
}
172172
}
173173
else{
174+
localStorage.removeItem('enrollTenantId')
174175
router.push(landingPage || '/home');
175176

176177
}

apps/learner-web-app/src/app/programs/page.tsx

Lines changed: 195 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
'use client';
22

3-
import { Box, Container, Grid, Typography, Tabs, Tab } from '@mui/material';
3+
import { Box, Container, Grid, Typography, Tabs, Tab, CircularProgress } from '@mui/material';
44
import Image from 'next/image';
55
import { useRouter, useSearchParams } from 'next/navigation';
66
import { Suspense, useState, useEffect } from 'react';
77
import { useTranslation } from '@shared-lib';
88
import Header from '@learner/components/Header/Header';
99
import EnrollProgramCarousel from '@learner/components/EnrollProgramCarousel/EnrollProgramCarousel';
1010
import { getUserDetails } from '@learner/utils/API/userService';
11+
import { getTenantInfo } from '@learner/utils/API/ProgramService';
12+
import { profileComplitionCheck } from '@learner/utils/API/userService';
13+
import { getAcademicYear } from '@learner/utils/API/AcademicYearService';
14+
import { TenantName } from '@learner/utils/app.constant';
15+
16+
declare global {
17+
interface Window {
18+
ReactNativeWebView?: {
19+
postMessage: (message: string) => void;
20+
};
21+
}
22+
}
1123

1224
function ProgramsContent() {
1325
const router = useRouter();
@@ -16,6 +28,7 @@ function ProgramsContent() {
1628
const [currentTab, setCurrentTab] = useState(0);
1729
const [userId, setUserId] = useState<string | null>(null);
1830
const [isAndroidApp, setIsAndroidApp] = useState(true);
31+
const [isCheckingEnrollTenantId, setIsCheckingEnrollTenantId] = useState(false);
1932

2033
useEffect(() => {
2134
const processData = async () => {
@@ -27,6 +40,167 @@ function ProgramsContent() {
2740
const isAndroid = localStorage.getItem('isAndroidApp') === 'yes';
2841
setIsAndroidApp(isAndroid);
2942

43+
// Check if enrollTenantId exists in localStorage
44+
const enrollTenantId = localStorage.getItem('enrollTenantId');
45+
if (enrollTenantId && storedUserId) {
46+
setIsCheckingEnrollTenantId(true);
47+
try {
48+
// Get user details to check if tenantId is already enrolled
49+
const userData = await getUserDetails(storedUserId, true);
50+
const tenantData = userData?.result?.userData?.tenantData || [];
51+
52+
// Check if tenantId exists in enrolled programs (My Programs)
53+
const enrolledTenant = tenantData.find(
54+
(item: any) =>
55+
item.tenantId === enrollTenantId &&
56+
item?.roles?.some((role: any) => role?.roleName === 'Learner')
57+
);
58+
59+
if (enrolledTenant) {
60+
// User is already enrolled - redirect to program page
61+
const token = localStorage.getItem('token');
62+
if (!token) {
63+
console.error('Token not found in localStorage');
64+
localStorage.removeItem('enrollTenantId');
65+
setIsCheckingEnrollTenantId(false);
66+
return;
67+
}
68+
69+
// Handle Android app case
70+
if (localStorage.getItem('isAndroidApp') === 'yes') {
71+
// Send message to React Native WebView
72+
if (window.ReactNativeWebView) {
73+
window.ReactNativeWebView.postMessage(JSON.stringify({
74+
type: 'ACCESS_PROGRAM_EVENT',
75+
data: {
76+
userId: storedUserId,
77+
tenantId: enrollTenantId,
78+
token: token,
79+
refreshToken: localStorage.getItem('refreshTokenForAndroid'),
80+
}
81+
}));
82+
}
83+
// Remove enrollTenantId from localStorage
84+
localStorage.removeItem('enrollTenantId');
85+
// Keep loading state true during redirect
86+
return;
87+
}
88+
89+
// Set localStorage values for the program
90+
localStorage.setItem('userId', storedUserId);
91+
localStorage.setItem('templtateId', enrolledTenant?.templateId);
92+
localStorage.setItem(
93+
'userIdName',
94+
userData?.result?.userData?.username
95+
);
96+
localStorage.setItem(
97+
'firstName',
98+
userData?.result?.userData?.firstName || ''
99+
);
100+
101+
const tenantId = enrolledTenant?.tenantId;
102+
const tenantName = enrolledTenant?.tenantName;
103+
const uiConfig = enrolledTenant?.params?.uiConfig;
104+
const landingPage = enrolledTenant?.params?.uiConfig?.landingPage;
105+
106+
localStorage.setItem('landingPage', landingPage);
107+
localStorage.setItem('uiConfig', JSON.stringify(uiConfig || {}));
108+
localStorage.setItem('tenantId', tenantId);
109+
localStorage.setItem('userProgram', tenantName);
110+
111+
// Set channel and collection framework
112+
const channelId = enrolledTenant?.channelId;
113+
if (channelId) {
114+
localStorage.setItem('channelId', channelId);
115+
}
116+
117+
const collectionFramework = enrolledTenant?.collectionFramework;
118+
if (collectionFramework) {
119+
localStorage.setItem('collectionFramework', collectionFramework);
120+
}
121+
122+
// Set cookie
123+
document.cookie = `token=${token}; path=/; secure; SameSite=Strict`;
124+
125+
// Check profile completion
126+
await profileComplitionCheck();
127+
128+
// Handle academic year for YOUTHNET
129+
if (tenantName === TenantName.YOUTHNET) {
130+
const academicYearResponse = await getAcademicYear();
131+
if (academicYearResponse?.[0]?.id) {
132+
localStorage.setItem('academicYearId', academicYearResponse[0].id);
133+
}
134+
}
135+
136+
// Remove enrollTenantId from localStorage
137+
localStorage.removeItem('enrollTenantId');
138+
139+
// Redirect to landing page (keep loading state true during redirect)
140+
router.push(landingPage || '/home');
141+
return;
142+
} else {
143+
// User is not enrolled - get program details and redirect to enroll-profile-completion
144+
const tenantInfoResponse = await getTenantInfo();
145+
const programsData = tenantInfoResponse?.result || [];
146+
const program = programsData.find(
147+
(p: any) => p.tenantId === enrollTenantId
148+
);
149+
150+
if (program) {
151+
// Store program information similar to handleEnroll function
152+
const currentTenantId = localStorage.getItem('tenantId');
153+
localStorage.setItem('previousTenantId', currentTenantId || '');
154+
localStorage.setItem('tenantId', program.tenantId);
155+
localStorage.setItem('userProgram', program?.name);
156+
157+
// Store uiConfig if available
158+
if (program?.params?.uiConfig) {
159+
localStorage.setItem(
160+
'uiConfig',
161+
JSON.stringify(program.params.uiConfig)
162+
);
163+
}
164+
165+
// Store landing page if available
166+
if (program?.params?.uiConfig?.landingPage) {
167+
localStorage.setItem(
168+
'landingPage',
169+
program.params.uiConfig.landingPage
170+
);
171+
}
172+
173+
// Store enrolled program data for the profile completion page
174+
localStorage.setItem(
175+
'enrolledProgramData',
176+
JSON.stringify({
177+
tenantId: program.tenantId,
178+
name: program.name,
179+
params: program.params,
180+
})
181+
);
182+
183+
// Remove enrollTenantId from localStorage
184+
// localStorage.removeItem('enrollTenantId');
185+
186+
// Navigate to enrollment profile completion page (keep loading state true during redirect)
187+
router.push('/enroll-profile-completion?directEnroll=true');
188+
return;
189+
} else {
190+
console.error('Program not found for enrollTenantId:', enrollTenantId);
191+
localStorage.removeItem('enrollTenantId');
192+
setIsCheckingEnrollTenantId(false);
193+
}
194+
}
195+
} catch (error) {
196+
console.error('Failed to process enrollTenantId:', error);
197+
localStorage.removeItem('enrollTenantId');
198+
setIsCheckingEnrollTenantId(false);
199+
}
200+
} else {
201+
setIsCheckingEnrollTenantId(false);
202+
}
203+
30204
// Read tab from query params on mount
31205
const tabParam = searchParams.get('tab');
32206
if (tabParam === 'my-programs') {
@@ -58,7 +232,7 @@ function ProgramsContent() {
58232
}
59233
};
60234
processData();
61-
}, [searchParams]);
235+
}, [searchParams, router]);
62236

63237
const handleTabChange = (event: React.SyntheticEvent, newValue: number) => {
64238
setCurrentTab(newValue);
@@ -70,6 +244,25 @@ function ProgramsContent() {
70244
router.push(`/programs?${params.toString()}`, { scroll: false });
71245
};
72246

247+
// Show loader while checking enrollTenantId
248+
if (isCheckingEnrollTenantId) {
249+
return (
250+
<>
251+
<Header isShowLogout={true} />
252+
<Box
253+
sx={{
254+
display: 'flex',
255+
justifyContent: 'center',
256+
alignItems: 'center',
257+
minHeight: '60vh',
258+
}}
259+
>
260+
<CircularProgress />
261+
</Box>
262+
</>
263+
);
264+
}
265+
73266
return (
74267
<>
75268
<Header isShowLogout={true} />

apps/learner-web-app/src/app/registration/RegisterationFlow.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ const RegisterationFlow = () => {
6161
const [creatingAccount, setCreatingAccount] = useState(false);
6262
const [invalidLinkModal, setInvalidLinkModal] = useState(false);
6363
const tenantId = searchParams.get('tenantId');
64+
const enroll = searchParams.get('enroll');
65+
6466

6567
const [accountExistModal, setAccountExistModal] = useState<boolean>(false);
6668
const [usernamePasswordForm, setUsernamePasswordForm] =
@@ -126,6 +128,12 @@ const RegisterationFlow = () => {
126128
};
127129
fetchData();
128130
}, [tenantId]);
131+
132+
useEffect(() => {
133+
if (typeof window !== 'undefined' && enroll) {
134+
localStorage.setItem('enrollTenantId', enroll as string);
135+
}
136+
}, [enroll]);
129137
useEffect(() => {
130138
// Fetch form schema from API and set it in state.
131139
const fetchData = async () => {
@@ -370,7 +378,7 @@ const RegisterationFlow = () => {
370378
const payload = isEmailCheck
371379
? { email: formData.email }
372380
: {
373-
firstName: formData.firstName,
381+
// firstName: formData.firstName,
374382
mobile: isUnderEighteen(formData.dob)
375383
? formData.parent_phone
376384
: formData.mobile,

apps/learner-web-app/src/components/EditProfile/EditProfile.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
profileComplitionCheck,
3838
updateUser,
3939
} from '@learner/utils/API/userService';
40+
import Header from '../Header/Header';
4041

4142
type UserAccount = {
4243
name: string;
@@ -51,7 +52,8 @@ interface EditProfileProps {
5152
const EditProfile = ({ completeProfile, enrolledProgram, uponEnrollCompletion }: EditProfileProps) => {
5253
const { t } = useTranslation();
5354
const searchParams = useSearchParams();
54-
55+
const directEnroll = searchParams.get('directEnroll');
56+
console.log('directEnroll', directEnroll);
5557
// let formData: any = {};
5658
const [loading, setLoading] = useState(true);
5759
const [invalidLinkModal, setInvalidLinkModal] = useState(false);
@@ -386,7 +388,9 @@ if (landingPage) {
386388
</Box>
387389
) : (
388390
<>
389-
<Box
391+
{directEnroll == 'true' && <Header isShowLogout={true} />}
392+
393+
{directEnroll != 'true' && (<Box
390394
sx={{
391395
// p: 2,
392396
mt: 2,
@@ -400,7 +404,7 @@ if (landingPage) {
400404
<ArrowBackIcon
401405
sx={{ color: '#4B5563', '&:hover': { color: '#000' } }}
402406
/>
403-
</Box>
407+
</Box>)}
404408
<Box
405409
sx={{
406410
textAlign: 'center',

apps/learner-web-app/src/utils/API/userService.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ export const userCheck = async ({
3131
// }
3232
if (email) {
3333
response = await post(apiUrl, { email });
34-
} else if (mobile && firstName) {
34+
}
35+
else if (mobile && firstName) {
3536
response = await post(apiUrl, { mobile, email, firstName });
36-
} else if (username) {
37+
}
38+
else if (mobile) {
39+
response = await post(apiUrl, { mobile });
40+
}
41+
else if (username) {
3742
response = await post(apiUrl, { username });
3843
}
3944

0 commit comments

Comments
 (0)