diff --git a/webapp/src/pages/index.tsx b/webapp/src/pages/index.tsx index 1a707c0a..aac515b4 100644 --- a/webapp/src/pages/index.tsx +++ b/webapp/src/pages/index.tsx @@ -22,7 +22,7 @@ import ChakraNextImage from "~/components/ChakraNextImage"; import FormInput from "~/components/forms/FormInput"; import { loginAnimation } from "~/utils/animations"; import { api } from "~/utils/api"; -import { frenchPhoneNumber } from "~/utils/tools"; +import { addSpaceToTwoCharacters, frenchPhoneNumber } from "~/utils/tools"; type LoginForm = { phone_number: string; @@ -174,7 +174,7 @@ export default function Home() { Vous avez reçu un code à 4 chiffres par SMS - Saisissez le code envoyé au 06 15 29 20 93 pour pouvoir créer votre + Saisissez le code envoyé au {addSpaceToTwoCharacters(formValues.phone_number)} pour pouvoir créer votre compte diff --git a/webapp/src/utils/tools.ts b/webapp/src/utils/tools.ts index ab84d04e..5cc54542 100644 --- a/webapp/src/utils/tools.ts +++ b/webapp/src/utils/tools.ts @@ -2,24 +2,24 @@ import crypto from 'crypto'; import { Where } from 'payload/types'; export const convertFrenchDateToEnglish = ( - frenchDate: string + frenchDate: string ): string | null => { - const match = frenchDate.match(/^(\d{2})\/(\d{2})\/(\d{2})$/); + const match = frenchDate.match(/^(\d{2})\/(\d{2})\/(\d{2})$/); - if (match) { - const [, day, month, year] = match.map(Number); + if (match) { + const [, day, month, year] = match.map(Number); - if (year !== undefined && month !== undefined && day !== undefined) { - // Creating a Date object with a four-digit year - const englishFormattedDate = new Date(2000 + year, month - 1, day); + if (year !== undefined && month !== undefined && day !== undefined) { + // Creating a Date object with a four-digit year + const englishFormattedDate = new Date(2000 + year, month - 1, day); - // Using toISOString to get the date in ISO format (YYYY-MM-DD) - return englishFormattedDate.toISOString().split("T")[0] || null; - } - } + // Using toISOString to get the date in ISO format (YYYY-MM-DD) + return englishFormattedDate.toISOString().split("T")[0] || null; + } + } - // Return null if the input format is incorrect - return null; + // Return null if the input format is incorrect + return null; }; export const frenchPhoneNumber = /^(?:\+33[1-9](\d{8})|(?!.*\+\d{2}).{10})$/; @@ -27,24 +27,24 @@ export const frenchPhoneNumber = /^(?:\+33[1-9](\d{8})|(?!.*\+\d{2}).{10})$/; export const payloadOrPhoneNumberCheck = (phone_number: string): Where => { const hasDialingCode = phone_number.startsWith('+') - return { - or: [ - { - phone_number: { - equals: hasDialingCode - ? phone_number - : `+33${phone_number.substring(1)}`, - }, - }, - { - phone_number: { - equals: hasDialingCode - ? `0${phone_number.substring(3)}` - : phone_number, - }, - }, - ], - }; + return { + or: [ + { + phone_number: { + equals: hasDialingCode + ? phone_number + : `+33${phone_number.substring(1)}`, + }, + }, + { + phone_number: { + equals: hasDialingCode + ? `0${phone_number.substring(3)}` + : phone_number, + }, + }, + ], + }; }; export const payloadWhereOfferIsValid = (prefix?: string): Where => { @@ -77,18 +77,26 @@ export const payloadWhereOfferIsValid = (prefix?: string): Where => { } export const generateRandomCode = (): string => { - const min = 1000; - const max = 9999; - const randomCode = Math.floor(Math.random() * (max - min + 1) + min); - return randomCode.toString(); + const min = 1000; + const max = 9999; + const randomCode = Math.floor(Math.random() * (max - min + 1) + min); + return randomCode.toString(); }; export const generateRandomPassword = (length: number): string => { - const buffer = crypto.randomBytes(length); - const password = buffer - .toString("base64") - .replace(/[/+=]/g, "") - .slice(0, length); + const buffer = crypto.randomBytes(length); + const password = buffer + .toString("base64") + .replace(/[/+=]/g, "") + .slice(0, length); - return password; + return password; }; + +export const addSpaceToTwoCharacters = (input: string) => { + var result = input.replace(/(\d{2})/g, '$1 '); + + result = result.trim(); + + return result; +}