Skip to content

Commit 186e5e9

Browse files
committed
feat: onboarding component recommendations on authn
1 parent 3272101 commit 186e5e9

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/data/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ export const VALID_EMAIL_REGEX = '(^[-!#$%&\'*+/=?^_`{}|~0-9A-Z]+(\\.[-!#$%&\'*+
3535

3636
// Query string parameters that can be passed to LMS to manage
3737
// things like auto-enrollment upon login and registration.
38-
export const AUTH_PARAMS = ['course_id', 'enrollment_action', 'course_mode', 'email_opt_in', 'purchase_workflow', 'next', 'register_for_free', 'track', 'is_account_recovery', 'variant', 'host', 'cta'];
38+
export const AUTH_PARAMS = ['course_id', 'enrollment_action', 'course_mode', 'country', 'email_opt_in', 'purchase_workflow', 'next', 'register_for_free', 'track', 'is_account_recovery', 'variant', 'host', 'cta', 'levelOfEducation', 'finishAuthUrl'];
3939
export const REDIRECT = 'redirect';
4040
export const APP_NAME = 'authn_mfe';

src/recommendations/RecommendationsPage.jsx

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import React, { useEffect } from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import { useSelector } from 'react-redux';
33

44
import { getConfig } from '@edx/frontend-platform';
5+
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
56
import { useIntl } from '@edx/frontend-platform/i18n';
67
import {
78
breakpoints,
@@ -21,18 +22,36 @@ import RecommendationsLargeLayout from './RecommendationsPageLayouts/LargeLayout
2122
import RecommendationsSmallLayout from './RecommendationsPageLayouts/SmallLayout';
2223
import { LINK_TIMEOUT, trackRecommendationsViewed, trackSkipButtonClicked } from './track';
2324
import { DEFAULT_REDIRECT_URL } from '../data/constants';
25+
import { getAllPossibleQueryParams } from '../data/utils';
2426

2527
const RecommendationsPage = () => {
2628
const { formatMessage } = useIntl();
29+
const DASHBOARD_URL = getConfig().LMS_BASE_URL.concat(DEFAULT_REDIRECT_URL);
2730
const isExtraSmall = useMediaQuery({ maxWidth: breakpoints.extraSmall.maxWidth - 1 });
2831
const location = useLocation();
32+
const queryParams = getAllPossibleQueryParams();
33+
// flag to show recommendations for onboarding component experience
34+
const showRecommendations = !!queryParams?.levelOfEducation
35+
|| (!!queryParams?.finalRedirectUrl && !!queryParams?.country);
36+
const backendCountryCode = useSelector((state) => state.register.backendCountryCode);
2937

30-
const registrationResponse = location.state?.registrationResult;
31-
const DASHBOARD_URL = getConfig().LMS_BASE_URL.concat(DEFAULT_REDIRECT_URL);
32-
const educationLevel = EDUCATION_LEVEL_MAPPING[location.state?.educationLevel];
33-
const userId = location.state?.userId;
38+
const [redirectUrl, setRedirectUrl] = useState(location.state?.registrationResult?.redirectUrl);
39+
const [educationLevel, setEducationLevel] = useState(EDUCATION_LEVEL_MAPPING[location.state?.educationLevel]);
40+
const [userId, setUserId] = useState(location.state?.userId || -1);
41+
const [userCountry, setUserCountry] = useState(backendCountryCode);
42+
43+
useEffect(() => {
44+
if (showRecommendations) {
45+
const authenticatedUser = getAuthenticatedUser();
46+
if (authenticatedUser) {
47+
setRedirectUrl(queryParams.finalRedirectUrl);
48+
setEducationLevel(EDUCATION_LEVEL_MAPPING[queryParams.levelOfEducation]);
49+
setUserCountry(queryParams.country);
50+
setUserId(authenticatedUser?.userId);
51+
}
52+
}
53+
}, [showRecommendations, queryParams]);
3454

35-
const userCountry = useSelector((state) => state.register.backendCountryCode);
3655
const {
3756
recommendations: algoliaRecommendations,
3857
isLoading,
@@ -46,8 +65,8 @@ const RecommendationsPage = () => {
4665

4766
const handleSkipRecommendationPage = () => {
4867
window.history.replaceState(location.state, null, '');
49-
if (registrationResponse) {
50-
window.location.href = registrationResponse.redirectUrl;
68+
if (redirectUrl) {
69+
window.location.href = redirectUrl;
5170
} else {
5271
window.location.href = DASHBOARD_URL;
5372
}
@@ -59,7 +78,7 @@ const RecommendationsPage = () => {
5978
setTimeout(() => { handleSkipRecommendationPage(); }, LINK_TIMEOUT);
6079
};
6180

62-
if (!registrationResponse) {
81+
if (!redirectUrl && !showRecommendations) {
6382
window.location.href = DASHBOARD_URL;
6483
return null;
6584
}

0 commit comments

Comments
 (0)