Skip to content
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

fix(company data): update company data input patterns #946

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions src/assets/locales/de/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -2094,16 +2094,6 @@
"name": "Country Code",
"hint": "Country Code",
"error": "Please enter valid Country Code"
},
"countryIdentifier": {
"name": "Country Identifier",
"hint": "Country Identifier",
"error": "Please enter valid Country Identifier"
},
"identifierNumber": {
"name": "Identifier Number",
"hint": "Identifier Number",
"error": "Please enter valid Identifier Number"
}
}
},
Expand All @@ -2112,16 +2102,11 @@
"editTitle": "Edit Address",
"description": "[Description] ... Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est",
"form": {
"companySite": {
"site": {
"name": "Select company / site",
"hint": "Select company / site",
"error": "Please enter valid company / site"
},
"addressTitle": {
"name": "Address Title",
"hint": "Address Title",
"error": "Please enter valid Address Title"
},
"street": {
"name": "Street with House Number",
"hint": "Street with House Number",
Expand All @@ -2136,6 +2121,16 @@
"name": "City",
"hint": "City",
"error": "Please enter valid City"
},
"countryIdentifier": {
"name": "Country Identifier",
"hint": "Country Identifier",
"error": "Please enter valid Country Identifier"
},
"identifierNumber": {
"name": "Identifier Number",
"hint": "Identifier Number",
"error": "Please enter valid Identifier Number"
}
}
},
Expand Down
32 changes: 16 additions & 16 deletions src/assets/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -2061,16 +2061,6 @@
"name": "Country Code",
"hint": "Country Code",
"error": "Please enter valid Country Code"
},
"countryIdentifier": {
"name": "Country Identifier",
"hint": "Country Identifier",
"error": "Please enter valid Country Identifier"
},
"identifierNumber": {
"name": "Identifier Number",
"hint": "Identifier Number",
"error": "Please enter valid Identifier Number"
}
}
},
Expand All @@ -2079,16 +2069,11 @@
"editTitle": "Edit Address",
"description": "[Description] ... Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est",
"form": {
"companySite": {
"site": {
"name": "Select company / site",
"hint": "Select company / site",
"error": "Please enter valid company / site"
},
"addressTitle": {
"name": "Address Title",
"hint": "Address Title",
"error": "Please enter valid Address Title"
},
"street": {
"name": "Street with House Number",
"hint": "Street with House Number",
Expand All @@ -2103,6 +2088,21 @@
"name": "City",
"hint": "City",
"error": "Please enter valid City"
},
"countryCode": {
"name": "Country Code",
"hint": "Country Code",
"error": "Please enter valid Country Code"
},
"countryIdentifier": {
"name": "Country Identifier",
"hint": "Country Identifier",
"error": "Please enter valid Country Identifier"
},
"identifierNumber": {
"name": "Identifier Number",
"hint": "Identifier Number",
"error": "Please enter valid Identifier Number"
}
}
},
Expand Down
96 changes: 65 additions & 31 deletions src/components/pages/CompanyData/components/FormFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import { useEffect, useState } from 'react'
import {
isCity,
isCommercialRegNumber,
isCompanyCommercialRegNumber,
isCountry,
isEori,
isCompanyEori,
isName,
isStreet,
isVatID,
isVies,
isZipCode,
isCompanyVatID,
isCompanyVies,
isPostalCode,
} from 'types/Patterns'
import type { IHashMap } from 'types/MainTypes'
import { useTranslation } from 'react-i18next'
Expand Down Expand Up @@ -92,11 +92,17 @@ const UpdateForm = ({
<div style={{ marginTop: '34px' }}>
<ValidatingInput
name="siteName"
label={t('content.companyData.site.form.site.name')}
label={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.site.name`
)}
value={data.siteName ?? ''}
validate={isName}
hint={t('content.companyData.site.form.site.hint')}
errorMessage={t('content.companyData.site.form.site.error')}
hint={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.site.hint`
)}
errorMessage={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.site.error`
)}
onValid={onChange}
onInvalid={onChange}
skipInitialValidation={newForm}
Expand All @@ -105,52 +111,76 @@ const UpdateForm = ({
<div style={{ margin: '12px 0' }}>
<ValidatingInput
name="street"
label={t('content.companyData.site.form.street.name')}
label={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.street.name`
)}
value={data.street ?? ''}
hint={t('content.companyData.site.form.street.hint')}
hint={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.street.hint`
)}
validate={isStreet}
onValid={onChange}
onInvalid={onChange}
errorMessage={t('content.companyData.site.form.street.error')}
errorMessage={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.street.error`
)}
skipInitialValidation={newForm}
/>
</div>
<div style={{ margin: '12px 0' }}>
<ValidatingInput
name="city"
label={t('content.companyData.site.form.city.name')}
label={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.city.name`
)}
value={data.city ?? ''}
hint={t('content.companyData.site.form.city.hint')}
hint={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.city.hint`
)}
validate={isCity}
onValid={onChange}
onInvalid={onChange}
errorMessage={t('content.companyData.site.form.city.error')}
errorMessage={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.city.error`
)}
skipInitialValidation={newForm}
/>
</div>
<div style={{ margin: '12px 0' }}>
<ValidatingInput
name="countryCode"
label={t('content.companyData.site.form.countryCode.name')}
label={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.countryCode.name`
)}
value={data.countryCode ?? ''}
hint={t('content.companyData.site.form.countryCode.hint')}
hint={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.countryCode.hint`
)}
validate={isCountry}
onValid={onChange}
onInvalid={onChange}
errorMessage={t('content.companyData.site.form.countryCode.error')}
errorMessage={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.countryCode.error`
)}
skipInitialValidation={newForm}
/>
</div>
<div style={{ margin: '12px 0' }}>
<ValidatingInput
name="postalCode"
label={t('content.companyData.site.form.postal.name')}
label={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.postal.name`
)}
value={data.postalCode ?? ''}
hint={t('content.companyData.site.form.postal.hint')}
validate={isZipCode}
hint={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.postal.hint`
)}
validate={isPostalCode}
onValid={onChange}
onInvalid={onChange}
errorMessage={t('content.companyData.site.form.postal.error')}
errorMessage={t(
`content.companyData.${isAddress ? 'address' : 'site'}.form.postal.error`
)}
skipInitialValidation={newForm}
/>
</div>
Expand All @@ -165,13 +195,15 @@ const UpdateForm = ({
<SelectList
error={false}
helperText={t(
'content.companyData.site.form.countryIdentifier.hint'
'content.companyData.address.form.countryIdentifier.hint'
)}
defaultValue={defaultIdentifier?.[0]}
items={identifiers}
label={t('content.companyData.site.form.countryIdentifier.name')}
label={t(
'content.companyData.address.form.countryIdentifier.name'
)}
placeholder={t(
'content.companyData.site.form.countryIdentifier.name'
'content.companyData.address.form.countryIdentifier.name'
)}
onChangeItem={(val) => {
onChange('countryIdentifier', val.label)
Expand All @@ -182,19 +214,21 @@ const UpdateForm = ({
<div style={{ margin: '12px 0' }}>
<ValidatingInput
name="identifierNumber"
label={t('content.companyData.site.form.identifierNumber.name')}
label={t(
'content.companyData.address.form.identifierNumber.name'
)}
value={data.identifierNumber ?? ''}
hint={t('content.companyData.site.form.identifierNumber.hint')}
hint={t('content.companyData.address.form.identifierNumber.hint')}
validate={(expr) =>
isCommercialRegNumber(expr) ||
isVatID(expr) ||
isVies(expr) ||
isEori(expr)
isCompanyCommercialRegNumber(expr) ||
isCompanyVatID(expr) ||
isCompanyVies(expr) ||
isCompanyEori(expr)
}
onValid={onChange}
onInvalid={onChange}
errorMessage={t(
'content.companyData.site.form.identifierNumber.error'
'content.companyData.address.form.identifierNumber.error'
)}
skipInitialValidation={newForm}
/>
Expand Down
22 changes: 21 additions & 1 deletion src/types/Patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,16 @@ export const Patterns = {
},
companyData: {
CITY: /^[A-ZÀ-ÿ0-9Śął](([ .'-]|\. )?[A-Za-zÀ-ÿ0-9Śął]{1,40}){1,10}$/,
STREET: /^[A-ZÀ-ÿ0-9Śął](([ .'-]|\. )?[A-Za-zÀ-ÿ0-9Śął]{1,40}){1,10}$/,
STREET:
/^(?!.*\s$)([a-zA-Z0-9À-ÿšŚął]{1,40}( ?[.,'/-] ?| )?){1,10}[a-zA-Z0-9À-ÿšŚął.]$/,
COUNTRYCODE: /^[A-Za-zÀ-ÿ]{2,3}$/,
COMMERCIAL_REG_NUMBER: /^(?!.*\s$)([A-Za-z0-9](\.|\s|-)?){4,21}$/,
VAT_ID: /^(?!.*\s$)([A-Za-z0-9](\.|\s|-|\/)?){5,18}$/,
LEI_CODE: /^[A-Za-z0-9]{20}$/,
VIES: /^[A-Z]{2}[0-9A-Za-z+*.]{2,12}$/,
EORI: /^[A-Z]{2}[A-Za-z0-9]{1,15}$/,
POSTAL_CODE:
/^(?!.*\s$)(?=[a-zA-Z\d-]{0,10}[-\s]?[a-zA-Z\d-]{0,10}$)[a-zA-Z\d\s-]{2,10}$/,
},
}

Expand Down Expand Up @@ -185,5 +193,17 @@ export const isCity = (expr: string) => Patterns.companyData.CITY.test(expr)
export const isStreet = (expr: string) => Patterns.companyData.STREET.test(expr)
export const isCountry = (expr: string) =>
Patterns.companyData.COUNTRYCODE.test(expr)
export const isCompanyCommercialRegNumber = (expr: string) =>
Patterns.companyData.COMMERCIAL_REG_NUMBER.test(expr)
export const isCompanyVatID = (expr: string) =>
Patterns.companyData.VAT_ID.test(expr)
export const isCompantVies = (expr: string) =>
Patterns.companyData.VIES.test(expr)
export const isCompanyEori = (expr: string) =>
Patterns.companyData.EORI.test(expr)
export const isCompanyVies = (expr: string) =>
Patterns.companyData.VIES.test(expr)
export const isPostalCode = (expr: string) =>
Patterns.companyData.POSTAL_CODE.test(expr)

export default Patterns
Loading