update
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import moment from 'moment';
|
||||
|
||||
export const validateDate = (date = null) => {
|
||||
if (!date) {
|
||||
return null;
|
||||
}
|
||||
if (moment(date).isValid()) {
|
||||
return date;
|
||||
}
|
||||
if (typeof date?.toDate === 'function') {
|
||||
return date?.toDate();
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export function getAge(birthDate) {
|
||||
return moment().diff(birthDate.toDate(), 'years', false);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
responsiveHeight as _responsiveHeight,
|
||||
responsiveWidth as _responsiveWidth,
|
||||
responsiveFontSize as _responsiveFontSize,
|
||||
} from "react-native-responsive-dimensions";
|
||||
|
||||
import {
|
||||
isWeb,
|
||||
isDesktop,
|
||||
isLargeDesktop,
|
||||
isSmallDesktop,
|
||||
isSuperSmallDesktop,
|
||||
} from "../hooks/useLayoutType";
|
||||
|
||||
export const reductionCoeff = (bypass) =>
|
||||
bypass ? 1 : isLargeDesktop ? 3 : isSmallDesktop ? 2.2 : isDesktop ? 2.8 : 1;
|
||||
|
||||
export const responsiveHeight = (height, bypass = false) => {
|
||||
return _responsiveHeight(height) / reductionCoeff(bypass);
|
||||
};
|
||||
|
||||
export const responsiveWidth = (width, bypass = false) => {
|
||||
return _responsiveWidth(width) / reductionCoeff(bypass);
|
||||
};
|
||||
|
||||
export const responsiveFontSize = (fontSize, bypass = false) => {
|
||||
if (isWeb) {
|
||||
if (isSuperSmallDesktop) {
|
||||
return fontSize * 6;
|
||||
} else if (isSmallDesktop) {
|
||||
return fontSize * 7;
|
||||
} else {
|
||||
return fontSize * 7.5;
|
||||
}
|
||||
} else {
|
||||
return _responsiveFontSize(fontSize) / reductionCoeff(bypass);
|
||||
}
|
||||
};
|
||||
|
||||
// test
|
||||
@@ -0,0 +1,74 @@
|
||||
export function checkIfEmailIsValid({ email }) {
|
||||
let regex = new RegExp(
|
||||
"([!#-'*+/-9=?A-Z^-~-]+(.[!#-'*+/-9=?A-Z^-~-]+)*|\"([]!#-[^-~ \t]|(\\[\t -~]))+\")@([!#-'*+/-9=?A-Z^-~-]+(.[!#-'*+/-9=?A-Z^-~-]+)*|[[\t -Z^-~]*])"
|
||||
);
|
||||
return regex.test(email);
|
||||
}
|
||||
|
||||
export function checkIfPasswordIsStrongEnough({ password }) {
|
||||
const reg =
|
||||
/^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})/;
|
||||
return reg.test(password);
|
||||
}
|
||||
|
||||
export const formatPhoneNumber = ({ phoneNumber = null }) => {
|
||||
if (!phoneNumber) {
|
||||
return null;
|
||||
}
|
||||
let newPhoneNumber = phoneNumber;
|
||||
|
||||
newPhoneNumber = newPhoneNumber
|
||||
.trim()
|
||||
.replace(/\s+/g, "") // remove spaces
|
||||
.replace(/\D/g, ""); // remove non digits
|
||||
|
||||
if (newPhoneNumber.startsWith("330")) {
|
||||
newPhoneNumber = newPhoneNumber.substring(2);
|
||||
}
|
||||
if (newPhoneNumber.startsWith("06") || newPhoneNumber.startsWith("07")) {
|
||||
newPhoneNumber = `+33${newPhoneNumber.slice(1)}`;
|
||||
} else if (
|
||||
newPhoneNumber.startsWith("336") ||
|
||||
newPhoneNumber.startsWith("337")
|
||||
) {
|
||||
newPhoneNumber = `+${newPhoneNumber}`;
|
||||
} else {
|
||||
newPhoneNumber = null;
|
||||
}
|
||||
return newPhoneNumber;
|
||||
};
|
||||
|
||||
export function handleFirebaseError(code) {
|
||||
switch (code) {
|
||||
case "auth/user-not-found":
|
||||
return "Ce compte n'existe pas.";
|
||||
case "auth/invalid-verification-code":
|
||||
return "Votre code de validation est incorrect.";
|
||||
case "auth/provider-already-linked":
|
||||
return "Ce compte est déjà lié à un utilisateur.";
|
||||
case "auth/invalid-credential":
|
||||
return "Identifiants incorrects.";
|
||||
case "auth/invalid-login-credentials":
|
||||
return "Identifiants incorrects.";
|
||||
case "auth/credential-already-in-use":
|
||||
return "Ce compte existe déjà ou est déjà lié.";
|
||||
case "auth/operation-not-allowed":
|
||||
return "Le provider n'est pas activé.";
|
||||
case "auth/invalid-email":
|
||||
return "Email invalide.";
|
||||
case "auth/wrong-password":
|
||||
return "Mot de passe incorrect.";
|
||||
case "auth/invalid-verification-id":
|
||||
return "Impossible de vous authentifié, réessayez dans quelques secondes.";
|
||||
case "auth/invalid-phone-number":
|
||||
return "Numéro de téléphone incorrect.";
|
||||
case "auth/too-many-requests":
|
||||
return "Nous avons détecté une activité inhabituelle et avons bloqué momentanément votre requête, réessayez dans quelques minutes.";
|
||||
case "auth/email-already-in-use":
|
||||
return "Il y a déjà un compte avec cette adresse mail.";
|
||||
case "auth/missing-password":
|
||||
return "Veuillez entrer un mot de passe.";
|
||||
default:
|
||||
return code;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user