Skip to content

Commit

Permalink
Merge pull request #65 from AplinkosMinisterija/60-telefono-numeriu-t…
Browse files Browse the repository at this point in the history
…varkymai

trim phone number value on change, update validation
  • Loading branch information
dovilemely authored May 8, 2024
2 parents b06d0a9 + d272cf3 commit 9a6efb4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/components/forms/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ const RegistrationForm = ({
error={errors.assignedTo}
onChange={(value: any) => {
setFieldValue('assignedTo', value);
setFieldValue('phone', value?.phone || '');
setFieldValue('phone', value?.phone?.trim() || '');
}}
options={users}
disabled={isCustomer}
Expand All @@ -334,7 +334,7 @@ const RegistrationForm = ({
error={errors.phone}
onChange={(e: any) => {
if (/^\+?[0-9\s]{0,11}$/.test(e)) {
setFieldValue('phone', e);
setFieldValue('phone', e.trim());
}
}}
disabled={isCustomer}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/MyProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const MyProfile = () => {
label={inputLabels.phone}
name="phone"
placeholder="864222222"
onChange={(value) => setFieldValue('phone', value)}
onChange={(value) => setFieldValue('phone', value?.trim())}
disabled={disabled}
error={errors.phone}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/TenantUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const NariaiPage = () => {
label={inputLabels.phone}
name="phone"
placeholder="864222222"
onChange={(value) => setFieldValue('phone', value)}
onChange={(value) => setFieldValue('phone', value?.trim())}
disabled={disabled}
error={errors.phone}
/>
Expand Down
11 changes: 5 additions & 6 deletions src/utils/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { validationTexts } from './texts';
import { FishBatch, FishType } from './types';
import { checkIfDateIsAfter } from './functions';

const lithuanianPhoneNumberFormat = /^(06|86|\+3706)\d{7}$/;

export const loginSchema = Yup.object().shape({
email: Yup.string().required(validationTexts.requireText).email(validationTexts.badEmailFormat),
password: Yup.string().required(validationTexts.requireText),
Expand All @@ -28,8 +30,7 @@ export const validateNewTenantUser = Yup.object().shape({
}),
phone: Yup.string()
.required(validationTexts.requireText)
.trim()
.matches(/^(86|\+3706)\d{7}$/, validationTexts.badPhoneFormat),
.matches(lithuanianPhoneNumberFormat, validationTexts.badPhoneFormat),
personalCode: Yup.string()
.required(validationTexts.requireText)
.trim()
Expand All @@ -44,8 +45,7 @@ export const validateMyProfile = Yup.object().shape({
email: Yup.string().required(validationTexts.requireText).email(validationTexts.badEmailFormat),
phone: Yup.string()
.required(validationTexts.requireText)
.trim()
.matches(/^(86|\+3706)\d{7}$/, validationTexts.badPhoneFormat),
.matches(lithuanianPhoneNumberFormat, validationTexts.badPhoneFormat),
});

export const validateFishStocking = (minTime: number) =>
Expand All @@ -59,8 +59,7 @@ export const validateFishStocking = (minTime: number) =>
assignedTo: Yup.object().required(validationTexts.requireText).nullable(),
phone: Yup.string()
.required(validationTexts.requireText)
.trim()
.matches(/^(86|\+3706)\d{7}$/, validationTexts.badPhoneFormat),
.matches(lithuanianPhoneNumberFormat, validationTexts.badPhoneFormat),
batches: Yup.array().of(
Yup.object().shape({
fishType: Yup.object()
Expand Down

0 comments on commit 9a6efb4

Please sign in to comment.