Skip to content

Commit

Permalink
fix(osp): fix osp validation (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
oyo authored Nov 2, 2023
1 parent b611534 commit 7fa214a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
32 changes: 4 additions & 28 deletions src/components/overlays/OSPRegister/OSPRegisterContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import {
isCountryCode,
isFirstName,
isID,
isIDOrEmpty,
isLastName,
isMail,
isPartnerUniqueID,
isRegionNameOrEmpty,
isStreetName,
isStreetNumberOrEmpty,
Expand All @@ -51,35 +51,11 @@ import {
emptyPartnerRegistration,
} from 'features/admin/networkApiSlice'

const emptyData: PartnerRegistration = {
externalId: '',
name: '',
bpn: '',
streetName: '',
streetNumber: '',
city: '',
zipCode: '',
region: '',
countryAlpha2Code: '',
uniqueIds: [],
userDetails: [
{
identityProviderId: '',
providerId: '',
username: '',
firstName: '',
lastName: '',
email: '',
},
],
companyRoles: [],
}

const getEmptyPartnerRegistration = (identityProviderId: string) => ({
...emptyData,
...emptyPartnerRegistration,
userDetails: [
{
...emptyData.userDetails[0],
...emptyPartnerRegistration.userDetails[0],
identityProviderId,
},
],
Expand Down Expand Up @@ -385,7 +361,7 @@ const OSPRegisterForm = ({
name={'uniqeIdValue'}
label={t('field.uniqeIdValue.name')}
hint={t('field.uniqeIdValue.hint')}
validate={isIDOrEmpty}
validate={isPartnerUniqueID}
onInvalid={invalidate}
onValid={(_key, value: string) => {
updateData({
Expand Down
2 changes: 1 addition & 1 deletion src/features/admin/networkApiSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export type CompanyRoleAgreementData = {
export const emptyPartnerRegistration: PartnerRegistration = {
externalId: '',
name: '',
bpn: '',
bpn: null,
streetName: '',
streetNumber: '',
city: '',
Expand Down
19 changes: 19 additions & 0 deletions src/types/Patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export const Patterns = {
MAIL: /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@/,
},
SEARCH: /^[a-zA-ZÀ-ÿ0-9 !?@&_\-.]{3,80}$/,
partner: {
COMMERCIAL_REG_NUMBER: /^[a-zA-Z\d-\s]{9}$/,
VAT_ID: /^[a-zA-Z\d-\s]{8,15}$/,
LEI_CODE: /^[a-zA-Z\d]{20}$/,
VIES: /.{1,500}/,
EORI: /^[a-zA-Z\d\s]{18}$/,
},
appMarketCard: {
appTitle: /^([A-Za-z.:_@&0-9' -]){5,40}$/,
appProvider: /^([A-Za-z.:_@&0-9' -]){3,30}$/,
Expand Down Expand Up @@ -114,6 +121,18 @@ export const isValidCancelInput = (expr: string) =>
Patterns.CANCEL_INPUT.test(expr)
export const isClientID = (expr: string) =>
Patterns.techuser.clientId.test(expr)
export const isCommercialRegNumber = (expr: string) =>
Patterns.partner.COMMERCIAL_REG_NUMBER.test(expr)
export const isVatID = (expr: string) => Patterns.partner.VAT_ID.test(expr)
export const isLeiCode = (expr: string) => Patterns.partner.LEI_CODE.test(expr)
export const isVies = (expr: string) => Patterns.partner.VIES.test(expr)
export const isEori = (expr: string) => Patterns.partner.EORI.test(expr)
export const isPartnerUniqueID = (expr: string) =>
isVies(expr) ||
isCommercialRegNumber(expr) ||
isVatID(expr) ||
isLeiCode(expr) ||
isEori(expr)
export const isMailOrEmpty = (expr: string) => expr === '' || isMail(expr)
export const isBPNOrEmpty = (expr: string) => expr === '' || isBPN(expr)
export const isDomainOrEmpty = (expr: string) => expr === '' || isDomain(expr)
Expand Down

0 comments on commit 7fa214a

Please sign in to comment.