From 3651eb0b0353641b5a5f9022b2a76dfcbd50b2d7 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 26 Jan 2024 15:10:15 +0700 Subject: [PATCH 1/3] fix: add validate to last name and legal name --- contributingGuides/FORMS.md | 2 +- src/CONST.ts | 2 +- src/languages/en.ts | 3 ++- src/pages/settings/Profile/DisplayNamePage.js | 5 ++++- src/pages/settings/Profile/PersonalDetails/LegalNamePage.js | 6 ++++++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/contributingGuides/FORMS.md b/contributingGuides/FORMS.md index ffec5f20254c..d87f9f889090 100644 --- a/contributingGuides/FORMS.md +++ b/contributingGuides/FORMS.md @@ -161,7 +161,7 @@ function validate(values) { errors = ErrorUtils.addErrorMessage(errors, 'firstName', 'personalDetails.error.hasInvalidCharacter'); } - if (ValidationUtils.doesContainReservedWord(values.firstName, CONST.DISPLAY_NAME.RESERVED_FIRST_NAMES)) { + if (ValidationUtils.doesContainReservedWord(values.firstName, CONST.DISPLAY_NAME.RESERVED_NAMES)) { errors = ErrorUtils.addErrorMessage(errors, 'firstName', 'personalDetails.error.containsReservedWord'); } diff --git a/src/CONST.ts b/src/CONST.ts index ff3934c31943..86a2f66fc4a2 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -92,7 +92,7 @@ const CONST = { DISPLAY_NAME: { MAX_LENGTH: 50, - RESERVED_FIRST_NAMES: ['Expensify', 'Concierge'], + RESERVED_NAMES: ['Expensify', 'Concierge'], }, LEGAL_NAME: { diff --git a/src/languages/en.ts b/src/languages/en.ts index fc426002809a..41347b67cbc9 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1135,7 +1135,7 @@ export default { }, personalDetails: { error: { - containsReservedWord: 'First name cannot contain the words Expensify or Concierge', + containsReservedWord: 'Name cannot contain the words Expensify or Concierge', hasInvalidCharacter: 'Name cannot contain a comma or semicolon', }, }, @@ -1151,6 +1151,7 @@ export default { dateShouldBeAfter: ({dateString}: DateShouldBeAfterParams) => `Date should be after ${dateString}.`, hasInvalidCharacter: 'Name can only include Latin characters.', incorrectZipFormat: ({zipFormat}: IncorrectZipFormatParams) => `Incorrect zip code format.${zipFormat ? ` Acceptable format: ${zipFormat}` : ''}`, + containsReservedWord: 'Name cannot contain the words Expensify or Concierge', }, }, resendValidationForm: { diff --git a/src/pages/settings/Profile/DisplayNamePage.js b/src/pages/settings/Profile/DisplayNamePage.js index 8ea471283004..fe02906a04e3 100644 --- a/src/pages/settings/Profile/DisplayNamePage.js +++ b/src/pages/settings/Profile/DisplayNamePage.js @@ -60,7 +60,7 @@ function DisplayNamePage(props) { if (!ValidationUtils.isValidDisplayName(values.firstName)) { ErrorUtils.addErrorMessage(errors, 'firstName', 'personalDetails.error.hasInvalidCharacter'); } - if (ValidationUtils.doesContainReservedWord(values.firstName, CONST.DISPLAY_NAME.RESERVED_FIRST_NAMES)) { + if (ValidationUtils.doesContainReservedWord(values.firstName, CONST.DISPLAY_NAME.RESERVED_NAMES)) { ErrorUtils.addErrorMessage(errors, 'firstName', 'personalDetails.error.containsReservedWord'); } @@ -68,6 +68,9 @@ function DisplayNamePage(props) { if (!ValidationUtils.isValidDisplayName(values.lastName)) { errors.lastName = 'personalDetails.error.hasInvalidCharacter'; } + if (ValidationUtils.doesContainReservedWord(values.lastName, CONST.DISPLAY_NAME.RESERVED_NAMES)) { + ErrorUtils.addErrorMessage(errors, 'lastName', 'personalDetails.error.containsReservedWord'); + } return errors; }; diff --git a/src/pages/settings/Profile/PersonalDetails/LegalNamePage.js b/src/pages/settings/Profile/PersonalDetails/LegalNamePage.js index 365ea62184ab..e73aa5c67945 100644 --- a/src/pages/settings/Profile/PersonalDetails/LegalNamePage.js +++ b/src/pages/settings/Profile/PersonalDetails/LegalNamePage.js @@ -60,6 +60,9 @@ function LegalNamePage(props) { } else if (_.isEmpty(values.legalFirstName)) { errors.legalFirstName = 'common.error.fieldRequired'; } + if (ValidationUtils.doesContainReservedWord(values.legalFirstName, CONST.DISPLAY_NAME.RESERVED_NAMES)) { + ErrorUtils.addErrorMessage(errors, 'legalFirstName', 'privatePersonalDetails.error.containsReservedWord'); + } if (values.legalFirstName.length > CONST.LEGAL_NAME.MAX_LENGTH) { ErrorUtils.addErrorMessage(errors, 'legalFirstName', ['common.error.characterLimitExceedCounter', {length: values.legalFirstName.length, limit: CONST.LEGAL_NAME.MAX_LENGTH}]); } @@ -69,6 +72,9 @@ function LegalNamePage(props) { } else if (_.isEmpty(values.legalLastName)) { errors.legalLastName = 'common.error.fieldRequired'; } + if (ValidationUtils.doesContainReservedWord(values.legalLastName, CONST.DISPLAY_NAME.RESERVED_NAMES)) { + ErrorUtils.addErrorMessage(errors, 'legalLastName', 'privatePersonalDetails.error.containsReservedWord'); + } if (values.legalLastName.length > CONST.LEGAL_NAME.MAX_LENGTH) { ErrorUtils.addErrorMessage(errors, 'legalLastName', ['common.error.characterLimitExceedCounter', {length: values.legalLastName.length, limit: CONST.LEGAL_NAME.MAX_LENGTH}]); } From 49f01fae9b579b079eb0b6ca42f6b93e9d21160e Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 26 Jan 2024 18:20:31 +0700 Subject: [PATCH 2/3] fix logic error legal name --- src/languages/en.ts | 1 - src/pages/settings/Profile/PersonalDetails/LegalNamePage.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 41347b67cbc9..e01aa9fc59e3 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1151,7 +1151,6 @@ export default { dateShouldBeAfter: ({dateString}: DateShouldBeAfterParams) => `Date should be after ${dateString}.`, hasInvalidCharacter: 'Name can only include Latin characters.', incorrectZipFormat: ({zipFormat}: IncorrectZipFormatParams) => `Incorrect zip code format.${zipFormat ? ` Acceptable format: ${zipFormat}` : ''}`, - containsReservedWord: 'Name cannot contain the words Expensify or Concierge', }, }, resendValidationForm: { diff --git a/src/pages/settings/Profile/PersonalDetails/LegalNamePage.js b/src/pages/settings/Profile/PersonalDetails/LegalNamePage.js index e73aa5c67945..2943bcf19992 100644 --- a/src/pages/settings/Profile/PersonalDetails/LegalNamePage.js +++ b/src/pages/settings/Profile/PersonalDetails/LegalNamePage.js @@ -61,7 +61,7 @@ function LegalNamePage(props) { errors.legalFirstName = 'common.error.fieldRequired'; } if (ValidationUtils.doesContainReservedWord(values.legalFirstName, CONST.DISPLAY_NAME.RESERVED_NAMES)) { - ErrorUtils.addErrorMessage(errors, 'legalFirstName', 'privatePersonalDetails.error.containsReservedWord'); + ErrorUtils.addErrorMessage(errors, 'legalFirstName', 'personalDetails.error.containsReservedWord'); } if (values.legalFirstName.length > CONST.LEGAL_NAME.MAX_LENGTH) { ErrorUtils.addErrorMessage(errors, 'legalFirstName', ['common.error.characterLimitExceedCounter', {length: values.legalFirstName.length, limit: CONST.LEGAL_NAME.MAX_LENGTH}]); @@ -73,7 +73,7 @@ function LegalNamePage(props) { errors.legalLastName = 'common.error.fieldRequired'; } if (ValidationUtils.doesContainReservedWord(values.legalLastName, CONST.DISPLAY_NAME.RESERVED_NAMES)) { - ErrorUtils.addErrorMessage(errors, 'legalLastName', 'privatePersonalDetails.error.containsReservedWord'); + ErrorUtils.addErrorMessage(errors, 'legalLastName', 'personalDetails.error.containsReservedWord'); } if (values.legalLastName.length > CONST.LEGAL_NAME.MAX_LENGTH) { ErrorUtils.addErrorMessage(errors, 'legalLastName', ['common.error.characterLimitExceedCounter', {length: values.legalLastName.length, limit: CONST.LEGAL_NAME.MAX_LENGTH}]); From 09503c482c36c3993e50d1e5d0ead48ac501dc9e Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 29 Jan 2024 10:28:50 +0700 Subject: [PATCH 3/3] change logic validate last name field --- src/pages/settings/Profile/DisplayNamePage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/settings/Profile/DisplayNamePage.js b/src/pages/settings/Profile/DisplayNamePage.js index fe02906a04e3..3269fc401c01 100644 --- a/src/pages/settings/Profile/DisplayNamePage.js +++ b/src/pages/settings/Profile/DisplayNamePage.js @@ -66,7 +66,7 @@ function DisplayNamePage(props) { // Then we validate the last name field if (!ValidationUtils.isValidDisplayName(values.lastName)) { - errors.lastName = 'personalDetails.error.hasInvalidCharacter'; + ErrorUtils.addErrorMessage(errors, 'lastName', 'personalDetails.error.hasInvalidCharacter'); } if (ValidationUtils.doesContainReservedWord(values.lastName, CONST.DISPLAY_NAME.RESERVED_NAMES)) { ErrorUtils.addErrorMessage(errors, 'lastName', 'personalDetails.error.containsReservedWord');