add minue and second in text useCountDown

This commit is contained in:
hamid zarghami
2026-06-11 11:30:56 +03:30
parent b738d0c292
commit 5976e8ea44
5 changed files with 29 additions and 20 deletions
+15
View File
@@ -1,5 +1,20 @@
import { ef } from '@/lib/helpers/utfNumbers';
import type { TFunction } from 'i18next';
import { useEffect, useRef, useState } from 'react';
export const formatCountdown = (seconds: number, t: TFunction) => {
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
if (mins > 0 && secs > 0) {
return t('OTP.Countdown.MinuteAndSecond', { mins: ef(mins), secs: ef(secs) });
}
if (mins > 0) {
return t('OTP.Countdown.Minute', { count: ef(mins) });
}
return t('OTP.Countdown.Second', { count: ef(secs) });
};
export const useCountdown = (shouldStart: boolean, duration: number = 30, delay: number = 1000) => {
const [timerRunning, setTimerRunning] = useState(false);
const [secondsLeft, setSecondsLeft] = useState(duration);