diff --git a/src/register/RegistrationFields/NameField/NameField.jsx b/src/register/RegistrationFields/NameField/NameField.jsx
index ec2eb8552e..9a03b6cf1e 100644
--- a/src/register/RegistrationFields/NameField/NameField.jsx
+++ b/src/register/RegistrationFields/NameField/NameField.jsx
@@ -27,21 +27,23 @@ const NameField = (props) => {
const {
handleErrorChange,
shouldFetchUsernameSuggestions,
+ name,
+ fullName,
} = props;
const handleOnBlur = (e) => {
const { value } = e.target;
- const fieldError = validateName(value, formatMessage);
+ const fieldError = validateName(value, name, formatMessage);
if (fieldError) {
- handleErrorChange('name', fieldError);
+ handleErrorChange(name, fieldError);
} else if (shouldFetchUsernameSuggestions && !validationApiRateLimited) {
- dispatch(fetchRealtimeValidations({ name: value }));
+ dispatch(fetchRealtimeValidations({ name: fullName.trim() }));
}
};
const handleOnFocus = () => {
- handleErrorChange('name', '');
- dispatch(clearRegistrationBackendError('name'));
+ handleErrorChange(name, '');
+ dispatch(clearRegistrationBackendError(name));
};
return (
@@ -56,6 +58,7 @@ const NameField = (props) => {
NameField.defaultProps = {
errorMessage: '',
shouldFetchUsernameSuggestions: false,
+ fullName: '',
};
NameField.propTypes = {
@@ -64,6 +67,8 @@ NameField.propTypes = {
value: PropTypes.string.isRequired,
handleChange: PropTypes.func.isRequired,
handleErrorChange: PropTypes.func.isRequired,
+ name: PropTypes.string.isRequired,
+ fullName: PropTypes.string,
};
export default NameField;
diff --git a/src/register/RegistrationFields/NameField/NameField.test.jsx b/src/register/RegistrationFields/NameField/NameField.test.jsx
index 3d33467229..eb52754413 100644
--- a/src/register/RegistrationFields/NameField/NameField.test.jsx
+++ b/src/register/RegistrationFields/NameField/NameField.test.jsx
@@ -51,7 +51,7 @@ describe('NameField', () => {
beforeEach(() => {
store = mockStore(initialState);
props = {
- name: 'name',
+ name: '',
value: '',
errorMessage: '',
handleChange: jest.fn(),
@@ -66,43 +66,44 @@ describe('NameField', () => {
});
describe('Test Name Field', () => {
- const fieldValidation = { name: 'Enter your full name' };
-
- it('should run name field validation when onBlur is fired', () => {
+ it('should run first name field validation when onBlur is fired', () => {
+ props.name = 'firstName';
const { container } = render(routerWrapper(reduxWrapper()));
- const nameInput = container.querySelector('input#name');
- fireEvent.blur(nameInput, { target: { value: '', name: 'name' } });
+ const firstNameInput = container.querySelector('input#firstName');
+ fireEvent.blur(firstNameInput, { target: { value: '', name: 'firstName' } });
expect(props.handleErrorChange).toHaveBeenCalledTimes(1);
expect(props.handleErrorChange).toHaveBeenCalledWith(
- 'name',
- fieldValidation.name,
+ 'firstName',
+ 'Enter your first name',
);
});
- it('should update errors for frontend validations', () => {
+ it('should update first name field error for frontend validations', () => {
+ props.name = 'firstName';
const { container } = render(routerWrapper(reduxWrapper()));
- const nameInput = container.querySelector('input#name');
- fireEvent.blur(nameInput, { target: { value: 'https://invalid-name.com', name: 'name' } });
+ const firstNameInput = container.querySelector('input#firstName');
+ fireEvent.blur(firstNameInput, { target: { value: 'https://invalid-name.com', name: 'firstName' } });
expect(props.handleErrorChange).toHaveBeenCalledTimes(1);
expect(props.handleErrorChange).toHaveBeenCalledWith(
- 'name',
- 'Enter a valid name',
+ 'firstName',
+ 'Enter a valid first name',
);
});
- it('should clear error on focus', () => {
+ it('should clear first name error on focus', () => {
+ props.name = 'firstName';
const { container } = render(routerWrapper(reduxWrapper()));
- const nameInput = container.querySelector('input#name');
- fireEvent.focus(nameInput, { target: { value: '', name: 'name' } });
+ const firstNameInput = container.querySelector('input#firstName');
+ fireEvent.focus(firstNameInput, { target: { value: '', name: 'firstName' } });
expect(props.handleErrorChange).toHaveBeenCalledTimes(1);
expect(props.handleErrorChange).toHaveBeenCalledWith(
- 'name',
+ 'firstName',
'',
);
});
@@ -112,14 +113,16 @@ describe('NameField', () => {
props = {
...props,
shouldFetchUsernameSuggestions: true,
+ fullName: 'test test',
};
+ props.name = 'lastName';
const { container } = render(routerWrapper(reduxWrapper()));
- const nameInput = container.querySelector('input#name');
+ const lastNameInput = container.querySelector('input#lastName');
// Enter a valid name so that frontend validations are passed
- fireEvent.blur(nameInput, { target: { value: 'test', name: 'name' } });
+ fireEvent.blur(lastNameInput, { target: { value: 'test', name: 'lastName' } });
- expect(store.dispatch).toHaveBeenCalledWith(fetchRealtimeValidations({ name: 'test' }));
+ expect(store.dispatch).toHaveBeenCalledWith(fetchRealtimeValidations({ name: props.fullName }));
});
it('should clear the registration validation error on focus on field', () => {
@@ -134,14 +137,43 @@ describe('NameField', () => {
},
});
+ props.name = 'lastName';
store.dispatch = jest.fn(store.dispatch);
const { container } = render(routerWrapper(reduxWrapper()));
- const nameInput = container.querySelector('input#name');
+ const lastNameInput = container.querySelector('input#lastName');
+
+ fireEvent.focus(lastNameInput, { target: { value: 'test', name: 'lastName' } });
- fireEvent.focus(nameInput, { target: { value: 'test', name: 'name' } });
+ expect(store.dispatch).toHaveBeenCalledWith(clearRegistrationBackendError('lastName'));
+ });
+
+ it('should run last name field validation when onBlur is fired', () => {
+ props.name = 'lastName';
+ const { container } = render(routerWrapper(reduxWrapper()));
- expect(store.dispatch).toHaveBeenCalledWith(clearRegistrationBackendError('name'));
+ const lastNameInput = container.querySelector('input#lastName');
+ fireEvent.blur(lastNameInput, { target: { value: '', name: 'lastName' } });
+
+ expect(props.handleErrorChange).toHaveBeenCalledTimes(1);
+ expect(props.handleErrorChange).toHaveBeenCalledWith(
+ 'lastName',
+ 'Enter your last name',
+ );
+ });
+
+ it('should update last name field error for frontend validation', () => {
+ props.name = 'lastName';
+ const { container } = render(routerWrapper(reduxWrapper()));
+
+ const lastNameInput = container.querySelector('input#lastName');
+ fireEvent.blur(lastNameInput, { target: { value: 'https://invalid-name.com', name: 'lastName' } });
+
+ expect(props.handleErrorChange).toHaveBeenCalledTimes(1);
+ expect(props.handleErrorChange).toHaveBeenCalledWith(
+ 'lastName',
+ 'Enter a valid last name',
+ );
});
});
});
diff --git a/src/register/RegistrationFields/NameField/validator.js b/src/register/RegistrationFields/NameField/validator.js
index e62c227d08..36036bf924 100644
--- a/src/register/RegistrationFields/NameField/validator.js
+++ b/src/register/RegistrationFields/NameField/validator.js
@@ -9,12 +9,16 @@ export const HTML_REGEX = /<|>/u;
// regex from backend
export const INVALID_NAME_REGEX = /https?:\/\/(?:[-\w.]|(?:%[\da-fA-F]{2}))*/g;
-const validateName = (value, formatMessage) => {
+const validateName = (value, fieldName, formatMessage) => {
let fieldError;
if (!value.trim()) {
- fieldError = formatMessage(messages['empty.name.field.error']);
+ fieldError = fieldName === 'lastName'
+ ? formatMessage(messages['empty.lastName.field.error'])
+ : formatMessage(messages['empty.firstName.field.error']);
} else if (URL_REGEX.test(value) || HTML_REGEX.test(value) || INVALID_NAME_REGEX.test(value)) {
- fieldError = formatMessage(messages['name.validation.message']);
+ fieldError = fieldName === 'lastName'
+ ? formatMessage(messages['lastName.validation.message'])
+ : formatMessage(messages['firstName.validation.message']);
}
return fieldError;
};
diff --git a/src/register/RegistrationPage.jsx b/src/register/RegistrationPage.jsx
index 43fc3df8b5..c5e616cdbf 100644
--- a/src/register/RegistrationPage.jsx
+++ b/src/register/RegistrationPage.jsx
@@ -119,9 +119,11 @@ const RegistrationPage = (props) => {
setErrorCode(prevState => ({ type: TPA_AUTHENTICATION_FAILURE, count: prevState.count + 1 }));
}
if (pipelineUserDetails && Object.keys(pipelineUserDetails).length !== 0) {
- const { name = '', username = '', email = '' } = pipelineUserDetails;
+ const {
+ firstName = '', lastName = '', username = '', email = '',
+ } = pipelineUserDetails;
setFormFields(prevState => ({
- ...prevState, name, username, email,
+ ...prevState, firstName, lastName, username, email,
}));
dispatch(setUserPipelineDataLoaded(true));
}
@@ -310,14 +312,22 @@ const RegistrationPage = (props) => {
/>