Skip to content

Commit 73e8913

Browse files
feat: remove username from the registration from (openedx#1201) (openedx#1241)
Co-authored-by: Attiya Ishaque <atiya.ishaq@arbisoft.com>
1 parent 3ddaf79 commit 73e8913

File tree

4 files changed

+65
-12
lines changed

4 files changed

+65
-12
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ POST_REGISTRATION_REDIRECT_URL=''
2323
SEARCH_CATALOG_URL=''
2424
# ***** Features flags *****
2525
DISABLE_ENTERPRISE_LOGIN=''
26+
ENABLE_AUTO_GENERATED_USERNAME=''
2627
ENABLE_DYNAMIC_REGISTRATION_FIELDS=''
2728
ENABLE_PROGRESSIVE_PROFILING_ON_AUTHN=''
2829
ENABLE_POST_REGISTRATION_RECOMMENDATIONS=''

src/config/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const configuration = {
44
USER_RETENTION_COOKIE_NAME: process.env.USER_RETENTION_COOKIE_NAME || '',
55
// Features
66
DISABLE_ENTERPRISE_LOGIN: process.env.DISABLE_ENTERPRISE_LOGIN || '',
7+
ENABLE_AUTO_GENERATED_USERNAME: process.env.ENABLE_AUTO_GENERATED_USERNAME || false,
78
ENABLE_DYNAMIC_REGISTRATION_FIELDS: process.env.ENABLE_DYNAMIC_REGISTRATION_FIELDS || false,
89
ENABLE_PROGRESSIVE_PROFILING_ON_AUTHN: process.env.ENABLE_PROGRESSIVE_PROFILING_ON_AUTHN || false,
910
ENABLE_POST_REGISTRATION_RECOMMENDATIONS: process.env.ENABLE_POST_REGISTRATION_RECOMMENDATIONS || false,

src/register/RegistrationPage.jsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const RegistrationPage = (props) => {
6060
showConfigurableEdxFields: getConfig().SHOW_CONFIGURABLE_EDX_FIELDS,
6161
showConfigurableRegistrationFields: getConfig().ENABLE_DYNAMIC_REGISTRATION_FIELDS,
6262
showMarketingEmailOptInCheckbox: getConfig().MARKETING_EMAILS_OPT_IN,
63+
autoGeneratedUsernameEnabled: getConfig().ENABLE_AUTO_GENERATED_USERNAME,
6364
};
6465
const {
6566
handleInstitutionLogin,
@@ -215,6 +216,9 @@ const RegistrationPage = (props) => {
215216
delete payload.password;
216217
payload.social_auth_provider = currentProvider;
217218
}
219+
if (flags.autoGeneratedUsernameEnabled) {
220+
delete payload.username;
221+
}
218222

219223
// Validating form data before submitting
220224
const { isValid, fieldErrors, emailSuggestion } = isFormValid(
@@ -324,16 +328,18 @@ const RegistrationPage = (props) => {
324328
helpText={[formatMessage(messages['help.text.email'])]}
325329
floatingLabel={formatMessage(messages['registration.email.label'])}
326330
/>
327-
<UsernameField
328-
name="username"
329-
spellCheck="false"
330-
value={formFields.username}
331-
handleChange={handleOnChange}
332-
handleErrorChange={handleErrorChange}
333-
errorMessage={errors.username}
334-
helpText={[formatMessage(messages['help.text.username.1']), formatMessage(messages['help.text.username.2'])]}
335-
floatingLabel={formatMessage(messages['registration.username.label'])}
336-
/>
331+
{!flags.autoGeneratedUsernameEnabled && (
332+
<UsernameField
333+
name="username"
334+
spellCheck="false"
335+
value={formFields.username}
336+
handleChange={handleOnChange}
337+
handleErrorChange={handleErrorChange}
338+
errorMessage={errors.username}
339+
helpText={[formatMessage(messages['help.text.username.1']), formatMessage(messages['help.text.username.2'])]}
340+
floatingLabel={formatMessage(messages['registration.username.label'])}
341+
/>
342+
)}
337343
{!currentProvider && (
338344
<PasswordField
339345
name="password"

src/register/RegistrationPage.test.jsx

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,16 @@ describe('RegistrationPage', () => {
134134
jest.clearAllMocks();
135135
});
136136

137-
const populateRequiredFields = (getByLabelText, payload, isThirdPartyAuth = false) => {
137+
const populateRequiredFields = (
138+
getByLabelText,
139+
payload,
140+
isThirdPartyAuth = false,
141+
autoGeneratedUsernameEnabled = false,
142+
) => {
138143
fireEvent.change(getByLabelText('Full name'), { target: { value: payload.name, name: 'name' } });
139-
fireEvent.change(getByLabelText('Public username'), { target: { value: payload.username, name: 'username' } });
144+
if (!autoGeneratedUsernameEnabled) {
145+
fireEvent.change(getByLabelText('Public username'), { target: { value: payload.username, name: 'username' } });
146+
}
140147
fireEvent.change(getByLabelText('Email'), { target: { value: payload.email, name: 'email' } });
141148

142149
fireEvent.change(getByLabelText('Country/Region'), { target: { value: payload.country, name: 'country' } });
@@ -299,6 +306,44 @@ describe('RegistrationPage', () => {
299306
});
300307
});
301308

309+
it('should submit form without UsernameField when autoGeneratedUsernameEnabled is true', () => {
310+
mergeConfig({
311+
ENABLE_AUTO_GENERATED_USERNAME: true,
312+
});
313+
jest.spyOn(global.Date, 'now').mockImplementation(() => 0);
314+
const payload = {
315+
name: 'John Doe',
316+
email: 'john.doe@gmail.com',
317+
password: 'password1',
318+
country: 'Pakistan',
319+
honor_code: true,
320+
totalRegistrationTime: 0,
321+
};
322+
323+
store.dispatch = jest.fn(store.dispatch);
324+
const { getByLabelText, container } = render(routerWrapper(reduxWrapper(<IntlRegistrationPage {...props} />)));
325+
populateRequiredFields(getByLabelText, payload, false, true);
326+
const button = container.querySelector('button.btn-brand');
327+
fireEvent.click(button);
328+
expect(store.dispatch).toHaveBeenCalledWith(registerNewUser({ ...payload, country: 'PK' }));
329+
mergeConfig({
330+
ENABLE_AUTO_GENERATED_USERNAME: false,
331+
});
332+
});
333+
334+
it('should not display UsernameField when ENABLE_AUTO_GENERATED_USERNAME is true', () => {
335+
mergeConfig({
336+
ENABLE_AUTO_GENERATED_USERNAME: true,
337+
});
338+
339+
const { queryByLabelText } = render(routerWrapper(reduxWrapper(<IntlRegistrationPage {...props} />)));
340+
expect(queryByLabelText('Username')).toBeNull();
341+
342+
mergeConfig({
343+
ENABLE_AUTO_GENERATED_USERNAME: false,
344+
});
345+
});
346+
302347
it('should not dispatch registerNewUser on empty form Submission', () => {
303348
store.dispatch = jest.fn(store.dispatch);
304349

0 commit comments

Comments
 (0)