Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix simplify registration experiment bugs #1175

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions src/register/RegistrationPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import {
FIRST_STEP,
getRegisterButtonLabelInExperiment,
NOT_INITIALIZED,
prepareSimplifiedRegistrationFirstStepPayload,
SECOND_STEP,
shouldDisplayFieldInExperiment,
Expand Down Expand Up @@ -219,10 +220,18 @@
useEffect(() => {
if (registrationResult.success) {
// This event is used by GTM
sendTrackEvent('edx.bi.user.account.registered.client', {
variation: simplifyRegistrationExpVariation,
picked_suggested_username: usernameSuggestionsBackup.includes(registrationResult?.authenticatedUser?.username),
});
let registeredEventProps = {};

if (simplifyRegistrationExpVariation !== NOT_INITIALIZED) {
registeredEventProps = {
variation: simplifyRegistrationExpVariation,
picked_suggested_username: usernameSuggestionsBackup.includes(
registrationResult?.authenticatedUser?.username,
),
};
}

sendTrackEvent('edx.bi.user.account.registered.client', registeredEventProps);

// This is used by the "User Retention Rate Event" on GTM
setCookie(getConfig().USER_RETENTION_COOKIE_NAME, true);
Expand Down Expand Up @@ -302,15 +311,9 @@
if (simplifyRegistrationExpVariation === SIMPLIFIED_REGISTRATION_VARIATION
&& simplifiedRegisterPageStep === FIRST_STEP) {
trackSimplifyRegistrationContinueBtnClicked();
const payload = prepareSimplifiedRegistrationFirstStepPayload(
formFields,
configurableFormFields,
const { isValid, fieldErrors } = validateSimplifiedRegistrationFirstStepPayload(

Check warning on line 314 in src/register/RegistrationPage.jsx

View check run for this annotation

Codecov / codecov/patch

src/register/RegistrationPage.jsx#L314

Added line #L314 was not covered by tests
formFields, errors, configurableFormFields, fieldDescriptions, formatMessage,
);
const {
isValid,
fieldErrors,
} = validateSimplifiedRegistrationFirstStepPayload(payload, errors, formatMessage);

setErrors(prevErrors => ({
...prevErrors,
...fieldErrors,
Expand All @@ -319,6 +322,10 @@
if (!isValid) {
setErrorCode(prevState => ({ type: FORM_SUBMISSION_ERROR, count: prevState.count + 1 }));
} else {
const payload = prepareSimplifiedRegistrationFirstStepPayload(

Check warning on line 325 in src/register/RegistrationPage.jsx

View check run for this annotation

Codecov / codecov/patch

src/register/RegistrationPage.jsx#L325

Added line #L325 was not covered by tests
formFields,
configurableFormFields,
);
dispatch(fetchRealtimeValidations(payload, true));
}
} else {
Expand Down
39 changes: 34 additions & 5 deletions src/register/data/optimizelyExperiment/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import messages from '../../messages';
import { validatePasswordField } from '../utils';

export const NOT_INITIALIZED = 'experiment-not-initialized';
export const DEFAULT_VARIATION = 'default-register-page';
export const SIMPLIFIED_REGISTRATION_VARIATION = 'simplified-register-page';

Expand Down Expand Up @@ -41,7 +42,8 @@
* registration page experiment
*/
export const shouldDisplayFieldInExperiment = (fieldName, expVariation, registerPageStep) => (
!expVariation || expVariation === DEFAULT_VARIATION || (expVariation === SIMPLIFIED_REGISTRATION_VARIATION
!expVariation || expVariation === NOT_INITIALIZED || expVariation === DEFAULT_VARIATION
|| (expVariation === SIMPLIFIED_REGISTRATION_VARIATION

Check warning on line 46 in src/register/data/optimizelyExperiment/helper.js

View check run for this annotation

Codecov / codecov/patch

src/register/data/optimizelyExperiment/helper.js#L46

Added line #L46 was not covered by tests
&& (
Comment on lines +45 to 47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my understanding can you explain this condition? What is this doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have four states of experiment
1- (!expVariation) at start, when experiment is being initialized or not initialized because it was either embedded register page, tpaHint or currentProvider was available -> We want to show spinner when exp is being initialized and we want to show normal register page if its embedded register page, tpaHint or currentProvider is available.

2- (expVariation === NOT_INITIALIZED) experiment could not be initialized due to any unknown reason -> we want to show normal register page

3- (expVariation === DEFAULT_VARIATION) experiment is initialized and user is bucketed into the DEFAULT_VARIATION. -> we want to show normal register page

4- expVariation === SIMPLIFIED_REGISTRATION_VARIATION ) experiment is initialized and user is bucketed into the SIMPLIFIED_REGISTRATION_VARIATION . -> we want to show all fields except username on first step and username + honor_code in second step of simplified register page

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above condition satisfies the above 4 scenarios

(registerPageStep === FIRST_STEP && fieldName !== 'username')
|| (registerPageStep === SECOND_STEP && SIMPLIFIED_REGISTER_PAGE_SECOND_STEP_FIELDS.includes(fieldName))
Expand Down Expand Up @@ -80,21 +82,48 @@
return payload;
};

export const validateSimplifiedRegistrationFirstStepPayload = (payload, errors, formatMessage) => {
export const validateSimplifiedRegistrationFirstStepPayload = (
payload, errors, configurableFormFields, fieldDescriptions, formatMessage,
) => {

Check warning on line 87 in src/register/data/optimizelyExperiment/helper.js

View check run for this annotation

Codecov / codecov/patch

src/register/data/optimizelyExperiment/helper.js#L87

Added line #L87 was not covered by tests
const fieldErrors = { ...errors };
let isValid = true;
Object.keys(payload).forEach(key => {

// We dont want to validate username since it is in second step of registration
const fieldsPayload = { ...payload };
delete fieldsPayload.username;

Check warning on line 93 in src/register/data/optimizelyExperiment/helper.js

View check run for this annotation

Codecov / codecov/patch

src/register/data/optimizelyExperiment/helper.js#L92-L93

Added lines #L92 - L93 were not covered by tests

Object.keys(fieldsPayload).forEach(key => {

Check warning on line 95 in src/register/data/optimizelyExperiment/helper.js

View check run for this annotation

Codecov / codecov/patch

src/register/data/optimizelyExperiment/helper.js#L95

Added line #L95 was not covered by tests
if (key === 'password') {
// We need to explicitly validated password field because the validations for password value
// are different at frontend and backend.
fieldErrors[key] = validatePasswordField(payload[key], formatMessage);
} else if (!payload[key]) {
fieldErrors[key] = validatePasswordField(fieldsPayload[key], formatMessage);

Check warning on line 99 in src/register/data/optimizelyExperiment/helper.js

View check run for this annotation

Codecov / codecov/patch

src/register/data/optimizelyExperiment/helper.js#L99

Added line #L99 was not covered by tests
} else if (!fieldsPayload[key]) {
fieldErrors[key] = formatMessage(messages[`empty.${key}.field.error`]);
}
if (fieldErrors[key]) {
isValid = false;
}
});

// Don't validate when country field is optional or hidden and not present on registration form
if (configurableFormFields?.country && !configurableFormFields.country?.displayValue) {
fieldErrors.country = formatMessage(messages['empty.country.field.error']);
isValid = false;

Check warning on line 111 in src/register/data/optimizelyExperiment/helper.js

View check run for this annotation

Codecov / codecov/patch

src/register/data/optimizelyExperiment/helper.js#L110-L111

Added lines #L110 - L111 were not covered by tests
} else if (configurableFormFields?.country && !configurableFormFields.country?.countryCode) {
fieldErrors.country = formatMessage(messages['invalid.country.field.error']);
isValid = false;

Check warning on line 114 in src/register/data/optimizelyExperiment/helper.js

View check run for this annotation

Codecov / codecov/patch

src/register/data/optimizelyExperiment/helper.js#L113-L114

Added lines #L113 - L114 were not covered by tests
}

Object.keys(fieldDescriptions).forEach(key => {

Check warning on line 117 in src/register/data/optimizelyExperiment/helper.js

View check run for this annotation

Codecov / codecov/patch

src/register/data/optimizelyExperiment/helper.js#L117

Added line #L117 was not covered by tests
if (key === 'country' && !configurableFormFields.country.displayValue) {
fieldErrors[key] = formatMessage(messages['empty.country.field.error']);

Check warning on line 119 in src/register/data/optimizelyExperiment/helper.js

View check run for this annotation

Codecov / codecov/patch

src/register/data/optimizelyExperiment/helper.js#L119

Added line #L119 was not covered by tests
} else if (!configurableFormFields[key]) {
fieldErrors[key] = fieldDescriptions[key].error_message;

Check warning on line 121 in src/register/data/optimizelyExperiment/helper.js

View check run for this annotation

Codecov / codecov/patch

src/register/data/optimizelyExperiment/helper.js#L121

Added line #L121 was not covered by tests
}
if (fieldErrors[key]) {
isValid = false;

Check warning on line 124 in src/register/data/optimizelyExperiment/helper.js

View check run for this annotation

Codecov / codecov/patch

src/register/data/optimizelyExperiment/helper.js#L124

Added line #L124 was not covered by tests
}
});

return { isValid, fieldErrors };
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import {
activateSimplifyRegistrationExperiment,
DEFAULT_VARIATION,
getSimplifyRegistrationExperimentVariation,
NOT_INITIALIZED,
} from './helper';
import { trackSimplifyRegistrationFirstStepViewed } from './track';
import { COMPLETE_STATE } from '../../../data/constants';
Expand Down Expand Up @@ -35,7 +35,7 @@
} else {
// This is to handle the case when user dont get variation for some reason, the register page
// shows unlimited spinner.
setVariation(DEFAULT_VARIATION);
setVariation(NOT_INITIALIZED);

Check warning on line 38 in src/register/data/optimizelyExperiment/useSimplifyRegistrationExperimentVariation.jsx

View check run for this annotation

Codecov / codecov/patch

src/register/data/optimizelyExperiment/useSimplifyRegistrationExperimentVariation.jsx#L38

Added line #L38 was not covered by tests
}
};

Expand Down
Loading