-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat(company data): improved white space handling and update identifier error messages #210
Merged
evegufy
merged 2 commits into
eclipse-tractusx:main
from
Cofinity-X:feat/improved-white-space-handling-for-company-data
Jul 12, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,7 +206,7 @@ export const CompanyDataCax = () => { | |
} | ||
|
||
const onSearchChange = (expr: string) => { | ||
if (isBPN(expr)) { | ||
if (isBPN(expr?.trim())) { | ||
fetchData(expr) | ||
// make sure to catch any error | ||
.catch((errorCode: number) => { | ||
|
@@ -222,7 +222,7 @@ export const CompanyDataCax = () => { | |
const validateLegalEntity = (value: string) => { | ||
setLegalEntity(value) | ||
|
||
if (!Patterns.legalEntityPattern.test(value)) { | ||
if (!Patterns.legalEntityPattern.test(value?.trim())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. personally I'd prefer to replace all the |
||
setErrors((prevState) => ({ | ||
...prevState, | ||
legalEntity: 'legalEntityError', | ||
|
@@ -236,7 +236,7 @@ export const CompanyDataCax = () => { | |
const validateRegisteredName = (value: string) => { | ||
setRegisteredName(value) | ||
|
||
if (!Patterns.registeredNamePattern.test(value)) { | ||
if (!Patterns.registeredNamePattern.test(value?.trim())) { | ||
setErrors((prevState) => ({ | ||
...prevState, | ||
registeredName: 'registerdNameError', | ||
|
@@ -250,7 +250,7 @@ export const CompanyDataCax = () => { | |
const validateStreetHouseNumber = (value: string) => { | ||
setStreetHouseNumber(value) | ||
|
||
if (!isStreet(value)) { | ||
if (!isStreet(value?.trim())) { | ||
setErrors((prevState) => ({ | ||
...prevState, | ||
streetHouseNumber: 'streetHouseNumberError', | ||
|
@@ -269,7 +269,7 @@ export const CompanyDataCax = () => { | |
return | ||
} | ||
|
||
if (!Patterns.postalCodePattern.test(value)) { | ||
if (!Patterns.postalCodePattern.test(value?.trim())) { | ||
setErrors((prevState) => ({ | ||
...prevState, | ||
postalCode: 'postalCodeError', | ||
|
@@ -283,7 +283,7 @@ export const CompanyDataCax = () => { | |
const validateCity = (value: string) => { | ||
setCity(value) | ||
|
||
if (!isCity(value)) { | ||
if (!isCity(value?.trim())) { | ||
setErrors((prevState) => ({ | ||
...prevState, | ||
city: 'cityError', | ||
|
@@ -297,7 +297,7 @@ export const CompanyDataCax = () => { | |
const validateCountry = (value: string) => { | ||
setChangedCountryValue(true) | ||
setCountry(value?.toUpperCase()) | ||
if (!Patterns.countryPattern.test(value)) { | ||
if (!Patterns.countryPattern.test(value?.trim())) { | ||
setShowIdentifiers(false) | ||
setErrors((prevState) => ({ | ||
...prevState, | ||
|
@@ -318,7 +318,7 @@ export const CompanyDataCax = () => { | |
setErrors((prevState) => ({ ...prevState, region: '' })) | ||
} | ||
|
||
if (value && !Patterns.regionPattern.test(value)) { | ||
if (value && !Patterns.regionPattern.test(value?.trim())) { | ||
setErrors((prevState) => ({ | ||
...prevState, | ||
region: 'regionError', | ||
|
@@ -341,7 +341,7 @@ export const CompanyDataCax = () => { | |
: 'Worldwide' | ||
if ( | ||
identifierType && | ||
!Patterns[countryCode][identifierType].test(value) | ||
!Patterns[countryCode][identifierType].test(value?.trim()) | ||
) { | ||
setErrors((prevState) => ({ | ||
...prevState, | ||
|
@@ -367,18 +367,18 @@ export const CompanyDataCax = () => { | |
|
||
const nextClick = () => { | ||
const companyData = { ...companyDetails } | ||
companyData.bpn = bpn | ||
companyData.name = legalEntity | ||
companyData.shortName = registeredName | ||
companyData.streetName = streetHouseNumber | ||
companyData.region = region | ||
companyData.city = city | ||
companyData.zipCode = postalCode | ||
companyData.countryAlpha2Code = country | ||
companyData.bpn = bpn?.trim() | ||
companyData.name = legalEntity?.trim() | ||
companyData.shortName = registeredName?.trim() | ||
companyData.streetName = streetHouseNumber?.trim() | ||
companyData.region = region?.trim() | ||
companyData.city = city?.trim() | ||
companyData.zipCode = postalCode?.trim() | ||
companyData.countryAlpha2Code = country?.trim() | ||
companyData.uniqueIds = [ | ||
{ | ||
type: identifierType, | ||
value: identifierNumber, | ||
value: identifierNumber?.trim(), | ||
}, | ||
] | ||
//addCompanyData(companyData) | ||
|
@@ -420,6 +420,9 @@ export const CompanyDataCax = () => { | |
onChange={(expr) => { | ||
onSearchChange(expr) | ||
}} | ||
onBlur={(e) => { | ||
setBpn(e.target.value.trim()) | ||
}} | ||
/> | ||
<label className="error-message">{bpnErrorMsg}</label> | ||
</div> | ||
|
@@ -469,6 +472,9 @@ export const CompanyDataCax = () => { | |
onChange={(e) => { | ||
validateLegalEntity(e.target.value) | ||
}} | ||
onBlur={(e) => { | ||
setLegalEntity(e.target.value.trim()) | ||
}} | ||
/> | ||
{errors.legalEntity && ( | ||
<label>{t(`registrationStepOne.${errors.legalEntity}`)}</label> | ||
|
@@ -489,6 +495,9 @@ export const CompanyDataCax = () => { | |
onChange={(e) => { | ||
validateRegisteredName(e.target.value) | ||
}} | ||
onBlur={(e) => { | ||
setRegisteredName(e.target.value.trim()) | ||
}} | ||
/> | ||
{errors.registeredName && ( | ||
<label> | ||
|
@@ -516,6 +525,9 @@ export const CompanyDataCax = () => { | |
onChange={(e) => { | ||
validateStreetHouseNumber(e.target.value) | ||
}} | ||
onBlur={(e) => { | ||
setStreetHouseNumber(e.target.value.trim()) | ||
}} | ||
/> | ||
{errors.streetHouseNumber && ( | ||
<label> | ||
|
@@ -534,6 +546,9 @@ export const CompanyDataCax = () => { | |
onChange={(e) => { | ||
validatePostalCode(e.target.value) | ||
}} | ||
onBlur={(e) => { | ||
setPostalCode(e.target.value.trim()) | ||
}} | ||
/> | ||
{errors.postalCode && ( | ||
<label>{t(`registrationStepOne.${errors.postalCode}`)}</label> | ||
|
@@ -551,6 +566,9 @@ export const CompanyDataCax = () => { | |
onChange={(e) => { | ||
validateCity(e.target.value) | ||
}} | ||
onBlur={(e) => { | ||
setCity(e.target.value.trim()) | ||
}} | ||
/> | ||
{errors.city && ( | ||
<label>{t(`registrationStepOne.${errors.city}`)}</label> | ||
|
@@ -595,6 +613,9 @@ export const CompanyDataCax = () => { | |
onChange={(e) => { | ||
validateRegion(e.target.value) | ||
}} | ||
onBlur={(e) => { | ||
setRegion(e.target.value.trim()) | ||
}} | ||
/> | ||
{errors.region && ( | ||
<label>{t(`registrationStepOne.${errors.region}`)}</label> | ||
|
@@ -624,6 +645,9 @@ export const CompanyDataCax = () => { | |
onChange={() => { | ||
handleIdentifierSelect(id.type, id.value) | ||
}} | ||
onBlur={(e) => { | ||
setIdentifierNumber(e.target.value.trim()) | ||
}} | ||
defaultChecked={uniqueIds[0].type === id.type} | ||
/> | ||
<label> | ||
|
@@ -685,6 +709,9 @@ export const CompanyDataCax = () => { | |
onChange={(e) => { | ||
validateIdentifierNumber(e.target.value) | ||
}} | ||
onBlur={(e) => { | ||
setIdentifierNumber(e.target.value.trim()) | ||
}} | ||
/> | ||
{errors.identifierNumber && ( | ||
<label> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we follow the discussed convention to always trim any input value I think it's better to do the trim inside the
isBPN
(and all other similar) functions so the code here would be better readable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be unexpected behavior for isXYZ functions imho. You check a value against REGEX. Trimming here is only valid because we take care of white spaces somewhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay - there are different ways to solve that. Anyway the trim has to go somewhere. Thinking about different input fields the question becomes more generic and tricky anyway: for example let's consider spaces inside some values like IBAN or phone numbers and how the system should deal with those. From a user perspective i guess it is less annoying if the system automatically parses and reformats values instead of showing an error like when pasting IBANs, phone numbers, etc. which are common to be written with spaces.