import React, { useEffect } from "react"; import classes from "./classes.module.scss"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; import Form from "@Front/Components/DesignSystem/Form"; import TextField from "@Front/Components/DesignSystem/Form/TextField"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import { ValidationError } from "class-validator"; type IProps = { onSubmit: (e: React.FormEvent | null, values: { [key: string]: string }) => void; validationErrors: ValidationError[]; partialPhoneNumber: string; onSendAnotherCode: () => void; }; export default function StepTotp(props: IProps) { const { onSubmit, validationErrors, partialPhoneNumber, onSendAnotherCode } = props; const [disableNewCodeButton, setDisableNewCodeButton] = React.useState(false); const [secondsBeforeNewCode, setSecondsBeforeNewCode] = React.useState(0); useEffect(() => { const interval = setInterval(() => { if (secondsBeforeNewCode > 0) { setSecondsBeforeNewCode(secondsBeforeNewCode - 1); if (secondsBeforeNewCode === 1) { setDisableNewCodeButton(false); } } }, 1000); return () => clearInterval(interval); }, [secondsBeforeNewCode]); const sendAnotherCode = () => { onSendAnotherCode(); setDisableNewCodeButton(true); setSecondsBeforeNewCode(30); }; return (
Votre code a été envoyé par SMS au ** ** ** {partialPhoneNumber.replace(/(.{2})/g, "$1 ")}
error.property === "totpCode")} />
Vous n'avez rien reçu ? {secondsBeforeNewCode !== 0 && ( Redemandez un code dans 00:{secondsBeforeNewCode < 10 ? `0${secondsBeforeNewCode}` : secondsBeforeNewCode} )}
); }