Skip to content

Commit

Permalink
feat(company data): improved white space handling for company data
Browse files Browse the repository at this point in the history
Move trimming to onBlur and save.

Refs: eclipse-tractusx#190
  • Loading branch information
typecastcloud committed Jul 9, 2024
1 parent 2e65e06 commit a34fb0b
Showing 1 changed file with 45 additions and 18 deletions.
63 changes: 45 additions & 18 deletions src/components/cax-companyData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -222,7 +222,7 @@ export const CompanyDataCax = () => {
const validateLegalEntity = (value: string) => {
setLegalEntity(value)

if (!Patterns.legalEntityPattern.test(value)) {
if (!Patterns.legalEntityPattern.test(value?.trim())) {
setErrors((prevState) => ({
...prevState,
legalEntity: 'legalEntityError',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -269,7 +269,7 @@ export const CompanyDataCax = () => {
return
}

if (!Patterns.postalCodePattern.test(value)) {
if (!Patterns.postalCodePattern.test(value?.trim())) {
setErrors((prevState) => ({
...prevState,
postalCode: 'postalCodeError',
Expand All @@ -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',
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -341,7 +341,7 @@ export const CompanyDataCax = () => {
: 'Worldwide'
if (
identifierType &&
!Patterns[countryCode][identifierType].test(value)
!Patterns[countryCode][identifierType].test(value?.trim())
) {
setErrors((prevState) => ({
...prevState,
Expand All @@ -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)
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -489,6 +495,9 @@ export const CompanyDataCax = () => {
onChange={(e) => {
validateRegisteredName(e.target.value)
}}
onBlur={(e) => {
setRegisteredName(e.target.value.trim())
}}
/>
{errors.registeredName && (
<label>
Expand Down Expand Up @@ -516,6 +525,9 @@ export const CompanyDataCax = () => {
onChange={(e) => {
validateStreetHouseNumber(e.target.value)
}}
onBlur={(e) => {
setStreetHouseNumber(e.target.value.trim())
}}
/>
{errors.streetHouseNumber && (
<label>
Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -685,6 +709,9 @@ export const CompanyDataCax = () => {
onChange={(e) => {
validateIdentifierNumber(e.target.value)
}}
onBlur={(e) => {
setIdentifierNumber(e.target.value.trim())
}}
/>
{errors.identifierNumber && (
<label>
Expand Down

0 comments on commit a34fb0b

Please sign in to comment.