✨ Modifying cell phone number validation
This commit is contained in:
parent
7a7d06579a
commit
10639ca35d
@ -76,6 +76,30 @@ export default class UserFolderHeader extends React.Component<IProps, IState> {
|
||||
private formatPhoneNumber(phoneNumber: string): string {
|
||||
if (!phoneNumber) return "";
|
||||
phoneNumber = phoneNumber.replace(/ /g, "");
|
||||
phoneNumber = phoneNumber.replace("+33", "0");
|
||||
|
||||
if (phoneNumber.length !== 10) {
|
||||
// split the last 9 digits
|
||||
const lastNineDigits = phoneNumber.slice(-9);
|
||||
|
||||
// get the country code
|
||||
const countryCode = phoneNumber.slice(0, -9);
|
||||
|
||||
// isolate the first digit
|
||||
const firstDigit = lastNineDigits.slice(0, 1);
|
||||
|
||||
// isolate the 8 other ones
|
||||
const lastEightDigits = lastNineDigits.slice(1);
|
||||
|
||||
// make a space every two digits on the last eights
|
||||
const output = lastEightDigits.split("").map((char, index) => {
|
||||
if (index % 2) return char + " ";
|
||||
return char;
|
||||
});
|
||||
// format the phone number
|
||||
phoneNumber = countryCode + " " + firstDigit + " " + output.join("");
|
||||
return phoneNumber;
|
||||
}
|
||||
const output = phoneNumber.split("").map((char, index) => {
|
||||
if (index % 2) return char + " ";
|
||||
return char;
|
||||
|
@ -163,7 +163,7 @@ export default function CollaboratorInformations(props: IProps) {
|
||||
<Typography typo={ITypo.NAV_INPUT_16} color={ITypoColor.GREY}>
|
||||
Numéro de téléphone
|
||||
</Typography>
|
||||
<Typography typo={ITypo.P_18}>{userSelected?.contact?.phone_number}</Typography>
|
||||
<Typography typo={ITypo.P_18}>{userSelected?.contact?.cell_phone_number}</Typography>
|
||||
</div>
|
||||
<div className={classes["user-infos-row"]}>
|
||||
<Typography typo={ITypo.NAV_INPUT_16} color={ITypoColor.GREY}>
|
||||
|
@ -229,6 +229,16 @@ class AddClientToFolderClass extends BasePage<IPropsClass, IState> {
|
||||
|
||||
if (this.state.selectedOption === "new_customer") {
|
||||
try {
|
||||
// remove every space from the phone number
|
||||
values["cell_phone_number"] = values["cell_phone_number"].replace(/\s/g, "");
|
||||
if (values["cell_phone_number"] && values["cell_phone_number"].length === 10) {
|
||||
// get the first digit of the phone number
|
||||
const firstDigit = values["cell_phone_number"].charAt(0);
|
||||
// if the first digit is a 0 replace it by +33
|
||||
if (firstDigit === "0") {
|
||||
values["cell_phone_number"] = "+33" + values["cell_phone_number"].substring(1);
|
||||
}
|
||||
}
|
||||
const contactToCreate = Contact.hydrate<Customer>(values);
|
||||
await contactToCreate.validateOrReject?.({ groups: ["createCustomer"], forbidUnknownValues: false });
|
||||
} catch (validationErrors) {
|
||||
|
@ -176,6 +176,17 @@ class UpdateClientClass extends BasePage<IPropsClass, IState> {
|
||||
[key: string]: string;
|
||||
},
|
||||
) {
|
||||
if (!values["cell_phone_number"]) return;
|
||||
// remove every space from the phone number
|
||||
values["cell_phone_number"] = values["cell_phone_number"].replace(/\s/g, "");
|
||||
if (values["cell_phone_number"] && values["cell_phone_number"].length === 10) {
|
||||
// get the first digit of the phone number
|
||||
const firstDigit = values["cell_phone_number"].charAt(0);
|
||||
// if the first digit is a 0 replace it by +33
|
||||
if (firstDigit === "0") {
|
||||
values["cell_phone_number"] = "+33" + values["cell_phone_number"].substring(1);
|
||||
}
|
||||
}
|
||||
const contact = Contact.hydrate<Contact>({
|
||||
first_name: values["first_name"],
|
||||
last_name: values["last_name"],
|
||||
|
@ -61,7 +61,7 @@ export default class MyAccount extends Base<IProps, IState> {
|
||||
<TextField
|
||||
name="phone"
|
||||
placeholder="Numéro de téléphone"
|
||||
defaultValue={this.state.user?.contact?.phone_number as string}
|
||||
defaultValue={this.state.user?.contact?.cell_phone_number as string}
|
||||
disabled
|
||||
canCopy
|
||||
/>
|
||||
|
@ -173,7 +173,7 @@ export default function UserInformations(props: IProps) {
|
||||
const liveVote = await LiveVotes.getInstance().post(vote);
|
||||
|
||||
if (liveVote.appointment.votes?.length === 3) {
|
||||
if(superAdminModalType === "add") {
|
||||
if (superAdminModalType === "add") {
|
||||
Toasts.getInstance().open({
|
||||
title: `Le titre de super-administrateur a été attribué à ${userSelected.contact?.first_name} ${userSelected.contact?.last_name} `,
|
||||
});
|
||||
@ -238,7 +238,7 @@ export default function UserInformations(props: IProps) {
|
||||
<Typography typo={ITypo.NAV_INPUT_16} color={ITypoColor.GREY}>
|
||||
Numéro de téléphone
|
||||
</Typography>
|
||||
<Typography typo={ITypo.P_18}>{userSelected?.contact?.phone_number}</Typography>
|
||||
<Typography typo={ITypo.P_18}>{userSelected?.contact?.cell_phone_number}</Typography>
|
||||
</div>
|
||||
<div className={classes["user-infos-row"]}>
|
||||
<Typography typo={ITypo.NAV_INPUT_16} color={ITypoColor.GREY}>
|
||||
|
Loading…
x
Reference in New Issue
Block a user