Skip to content

Commit

Permalink
Fix : less strict controls, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDmz committed Jul 27, 2023
1 parent 48485fc commit 7bc6192
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pearl",
"version": "1.1.5",
"version": "1.1.6",
"private": true,
"dependencies": {
"@date-io/date-fns": "1.x",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import D from 'i18n';
import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography';
import { getTitle } from 'utils/functions';
import { getTitle, isValidString } from 'utils/functions';
import { makeStyles } from '@material-ui/core';
import clsx from 'clsx';

Expand All @@ -21,7 +21,6 @@ const useStyles = makeStyles(() => ({
},
address: {
paddingLeft: '2em',
// fontWeight: 'bold',
},
error: {
color: 'red',
Expand Down Expand Up @@ -59,7 +58,9 @@ export const CommunicationRequestValidation = ({
const reasonLabel = findCommunicationReasonValueByType(reason);

const buildAddressFirstLine = (title, firstname, lastName) =>
`${getTitle(title)} ${firstname} ${lastName}`;
`${getTitle(title)} ${isValidString(firstname) ? firstname : ''} ${
isValidString(lastName) ? lastName : '!!!'
}`;
const recipientAddress = buildAddressFirstLine(
recipientTitle,
recipientFirstName,
Expand Down
22 changes: 10 additions & 12 deletions src/utils/functions/communicationFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const VALID_MAIL_FORMAT = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
export const isEmailValid = email => email?.match(VALID_MAIL_FORMAT) ?? false;

export const isValidTitle = title => Object.keys(TITLES).includes(title.toUpperCase());
export const isValidString = string => !!string && string?.length !== 0;

export const checkCommunicationRequestFormAddressesValidity = (
recipientInformation,
Expand All @@ -30,10 +31,8 @@ export const checkCommunicationRequestFormAddressesValidity = (
) => {
let userError = {
title: true,
firstName: true,
lastName: true,
email: true,
phoneNumber: true,
name: true,
emailAndPhoneNumber: true,
},
recipientError = {
title: true,
Expand All @@ -51,10 +50,9 @@ export const checkCommunicationRequestFormAddressesValidity = (
if (userInformation !== undefined) {
const { title, firstName, lastName, email, phoneNumber } = userInformation;
userError.title = !isValidTitle(title);
userError.firstName = !firstName || firstName.length === 0;
userError.lastName = !lastName || lastName.length === 0;
userError.email = !isEmailValid(email);
userError.phoneNumber = !phoneNumber || phoneNumber.length < 10;
userError.name = !isValidString(lastName);
userError.emailAndPhoneNumber =
!isEmailValid(email) && (!phoneNumber || phoneNumber.length < 10);
}
if (recipientInformation !== undefined) {
const {
Expand All @@ -65,10 +63,10 @@ export const checkCommunicationRequestFormAddressesValidity = (
recipientCityName,
} = recipientInformation;
recipientError.title = !isValidTitle(title);
recipientError.firstName = !recipientFirstName || recipientFirstName.length === 0;
recipientError.lastName = !recipientLastName || recipientLastName.length === 0;
recipientError.postCode = !recipientPostcode || recipientPostcode.length === 0;
recipientError.cityName = !recipientCityName || recipientCityName.length === 0;
recipientError.firstName = !isValidString(recipientFirstName);
recipientError.lastName = !isValidString(recipientLastName);
recipientError.postCode = !isValidString(recipientPostcode);
recipientError.cityName = !isValidString(recipientCityName);
}

return { userError, recipientError, communicationRequestError };
Expand Down

0 comments on commit 7bc6192

Please sign in to comment.