fix qr timer
This commit is contained in:
@@ -172,6 +172,8 @@ function LoginPageContent() {
|
||||
|
||||
const [qrExpiresAt, setQrExpiresAt] = useState<string | null>(null);
|
||||
|
||||
const [qrSecondsLeft, setQrSecondsLeft] = useState<number | null>(null);
|
||||
|
||||
const [qrLoading, setQrLoading] = useState(false);
|
||||
const [lastOtpChannel, setLastOtpChannel] = useState<string | undefined>();
|
||||
const [otpResendAvailableAt, setOtpResendAvailableAt] = useState<string | null>(null);
|
||||
@@ -448,6 +450,28 @@ function LoginPageContent() {
|
||||
|
||||
}, [applyLoginAuth, qrSessionId, showToast, step]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!qrExpiresAt || (step !== 'qr' && step !== 'qrLink')) {
|
||||
setQrSecondsLeft(null);
|
||||
return;
|
||||
}
|
||||
|
||||
const updateCountdown = () => {
|
||||
setQrSecondsLeft(Math.max(0, Math.ceil((new Date(qrExpiresAt).getTime() - Date.now()) / 1000)));
|
||||
};
|
||||
|
||||
updateCountdown();
|
||||
const timer = window.setInterval(updateCountdown, 1000);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [qrExpiresAt, step]);
|
||||
|
||||
function formatQrCountdown(seconds: number | null) {
|
||||
if (seconds === null) return null;
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const remainingSeconds = seconds % 60;
|
||||
return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function handleIdentify(event: FormEvent<HTMLFormElement>) {
|
||||
@@ -1427,7 +1451,7 @@ function LoginPageContent() {
|
||||
|
||||
{qrExpiresAt ? (
|
||||
|
||||
<p className="mt-2 text-xs text-[#8f92a0]">Код действует до {new Intl.DateTimeFormat('ru-RU', { hour: '2-digit', minute: '2-digit', second: '2-digit' }).format(new Date(qrExpiresAt))}</p>
|
||||
<p className="mt-2 text-xs text-[#8f92a0]">Код действителен: {formatQrCountdown(qrSecondsLeft)}</p>
|
||||
|
||||
) : null}
|
||||
|
||||
@@ -1459,7 +1483,7 @@ function LoginPageContent() {
|
||||
|
||||
<p className="mt-2 text-xs text-[#8f92a0]">
|
||||
|
||||
QR-код действует до {new Intl.DateTimeFormat('ru-RU', { hour: '2-digit', minute: '2-digit', second: '2-digit' }).format(new Date(qrExpiresAt))}
|
||||
Код действителен: {formatQrCountdown(qrSecondsLeft)}
|
||||
|
||||
</p>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user