diff --git a/src/pages/settings/Profile/DisplayNamePage.js b/src/pages/settings/Profile/DisplayNamePage.js index 2649db5a1805..5e676a570e33 100644 --- a/src/pages/settings/Profile/DisplayNamePage.js +++ b/src/pages/settings/Profile/DisplayNamePage.js @@ -1,5 +1,5 @@ import lodashGet from 'lodash/get'; -import React, {Component} from 'react'; +import React from 'react'; import {View} from 'react-native'; import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from '../../../components/withCurrentUserPersonalDetails'; import ScreenWrapper from '../../../components/ScreenWrapper'; @@ -27,23 +27,18 @@ const defaultProps = { ...withCurrentUserPersonalDetailsDefaultProps, }; -class DisplayNamePage extends Component { - constructor(props) { - super(props); - - this.validate = this.validate.bind(this); - this.updateDisplayName = this.updateDisplayName.bind(this); - } +/** + * Submit form to update user's first and last name (and display name) + * @param {Object} values + * @param {String} values.firstName + * @param {String} values.lastName + */ +const updateDisplayName = (values) => { + PersonalDetails.updateDisplayName(values.firstName.trim(), values.lastName.trim()); +}; - /** - * Submit form to update user's first and last name (and display name) - * @param {Object} values - * @param {String} values.firstName - * @param {String} values.lastName - */ - updateDisplayName(values) { - PersonalDetails.updateDisplayName(values.firstName.trim(), values.lastName.trim()); - } +function DisplayNamePage(props) { + const currentUserDetails = props.currentUserPersonalDetails || {}; /** * @param {Object} values @@ -51,70 +46,67 @@ class DisplayNamePage extends Component { * @param {String} values.lastName * @returns {Object} - An object containing the errors for each inputID */ - validate(values) { + const validate = (values) => { const errors = {}; // First we validate the first name field if (!ValidationUtils.isValidDisplayName(values.firstName)) { - ErrorUtils.addErrorMessage(errors, 'firstName', this.props.translate('personalDetails.error.hasInvalidCharacter')); + ErrorUtils.addErrorMessage(errors, 'firstName', props.translate('personalDetails.error.hasInvalidCharacter')); } if (ValidationUtils.doesContainReservedWord(values.firstName, CONST.DISPLAY_NAME.RESERVED_FIRST_NAMES)) { - ErrorUtils.addErrorMessage(errors, 'firstName', this.props.translate('personalDetails.error.containsReservedWord')); + ErrorUtils.addErrorMessage(errors, 'firstName', props.translate('personalDetails.error.containsReservedWord')); } // Then we validate the last name field if (!ValidationUtils.isValidDisplayName(values.lastName)) { - errors.lastName = this.props.translate('personalDetails.error.hasInvalidCharacter'); + errors.lastName = props.translate('personalDetails.error.hasInvalidCharacter'); } return errors; - } - - render() { - const currentUserDetails = this.props.currentUserPersonalDetails || {}; + }; - return ( - - Navigation.goBack(ROUTES.SETTINGS_PROFILE)} - /> -
- {this.props.translate('displayNamePage.isShownOnProfile')} - - - - - - -
-
- ); - } + return ( + + Navigation.goBack(ROUTES.SETTINGS_PROFILE)} + /> +
+ {props.translate('displayNamePage.isShownOnProfile')} + + + + + + +
+
+ ); } DisplayNamePage.propTypes = propTypes; DisplayNamePage.defaultProps = defaultProps; +DisplayNamePage.displayName = 'DisplayNamePage'; export default compose(withLocalize, withCurrentUserPersonalDetails)(DisplayNamePage);