add minue and second in text useCountDown
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
AUTH_PAGE_ELEMENT as AUTH_PAGE_ELEMENTS
|
AUTH_PAGE_ELEMENT as AUTH_PAGE_ELEMENTS
|
||||||
} from '@/enums'
|
} from '@/enums'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
|
import { formatCountdown } from '@/hooks/useCountdown'
|
||||||
import Image from 'next/image'
|
import Image from 'next/image'
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@@ -22,15 +23,6 @@ type Props = {
|
|||||||
pending?: boolean | undefined
|
pending?: boolean | undefined
|
||||||
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'id'>
|
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'id'>
|
||||||
|
|
||||||
const formatCountdown = (seconds: number) => {
|
|
||||||
const mins = Math.floor(seconds / 60)
|
|
||||||
const secs = seconds % 60
|
|
||||||
if (mins > 0) {
|
|
||||||
return `${mins}:${String(secs).padStart(2, '0')}`
|
|
||||||
}
|
|
||||||
return String(seconds)
|
|
||||||
}
|
|
||||||
|
|
||||||
function StepEnterOtp ({
|
function StepEnterOtp ({
|
||||||
onChange,
|
onChange,
|
||||||
onClick,
|
onClick,
|
||||||
@@ -96,7 +88,7 @@ function StepEnterOtp ({
|
|||||||
<div>
|
<div>
|
||||||
{timerRunning ? (
|
{timerRunning ? (
|
||||||
<div>
|
<div>
|
||||||
{t('OTP.TimerRunning', { time: formatCountdown(secondsLeft) })}
|
{t('OTP.TimerRunning', { time: formatCountdown(secondsLeft, t) })}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { setRefreshToken, setToken } from '@/lib/api/func'
|
|||||||
import { useSearchParams } from 'next/navigation'
|
import { useSearchParams } from 'next/navigation'
|
||||||
import { AUTH_PAGE_ELEMENT } from '@/enums'
|
import { AUTH_PAGE_ELEMENT } from '@/enums'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
|
import { formatCountdown } from '@/hooks/useCountdown'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
phone: string
|
phone: string
|
||||||
@@ -24,15 +25,6 @@ type Props = {
|
|||||||
isResendPending?: boolean
|
isResendPending?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatCountdown = (seconds: number) => {
|
|
||||||
const mins = Math.floor(seconds / 60)
|
|
||||||
const secs = seconds % 60
|
|
||||||
if (mins > 0) {
|
|
||||||
return `${mins}:${String(secs).padStart(2, '0')}`
|
|
||||||
}
|
|
||||||
return String(seconds)
|
|
||||||
}
|
|
||||||
|
|
||||||
const StepOtp = ({ phone, slug, timerRunning, secondsLeft, onResend, isResendPending }: Props) => {
|
const StepOtp = ({ phone, slug, timerRunning, secondsLeft, onResend, isResendPending }: Props) => {
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const redirectUrl = searchParams.get('redirect')
|
const redirectUrl = searchParams.get('redirect')
|
||||||
@@ -126,7 +118,7 @@ const StepOtp = ({ phone, slug, timerRunning, secondsLeft, onResend, isResendPen
|
|||||||
<div className='text-center w-full pt-6 text-xs'>
|
<div className='text-center w-full pt-6 text-xs'>
|
||||||
{timerRunning ? (
|
{timerRunning ? (
|
||||||
<div>
|
<div>
|
||||||
{t('OTP.TimerRunning', { time: formatCountdown(secondsLeft) })}
|
{t('OTP.TimerRunning', { time: formatCountdown(secondsLeft, t) })}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -1,5 +1,20 @@
|
|||||||
|
import { ef } from '@/lib/helpers/utfNumbers';
|
||||||
|
import type { TFunction } from 'i18next';
|
||||||
import { useEffect, useRef, useState } from 'react';
|
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) => {
|
export const useCountdown = (shouldStart: boolean, duration: number = 30, delay: number = 1000) => {
|
||||||
const [timerRunning, setTimerRunning] = useState(false);
|
const [timerRunning, setTimerRunning] = useState(false);
|
||||||
const [secondsLeft, setSecondsLeft] = useState(duration);
|
const [secondsLeft, setSecondsLeft] = useState(duration);
|
||||||
|
|||||||
@@ -10,6 +10,11 @@
|
|||||||
"Description": "Please enter the 6-digit code sent to the number {{phoneNumber}}.",
|
"Description": "Please enter the 6-digit code sent to the number {{phoneNumber}}.",
|
||||||
"Label": "",
|
"Label": "",
|
||||||
"TimerRunning": "Resend available in {{time}}",
|
"TimerRunning": "Resend available in {{time}}",
|
||||||
|
"Countdown": {
|
||||||
|
"Minute": "{{count}} minute",
|
||||||
|
"Second": "{{count}} second",
|
||||||
|
"MinuteAndSecond": "{{mins}} minute and {{secs}} second"
|
||||||
|
},
|
||||||
"TimerOut": "Didn’t receive the code?",
|
"TimerOut": "Didn’t receive the code?",
|
||||||
"TimerReset": "Resend",
|
"TimerReset": "Resend",
|
||||||
"ButtonSubmit": "Next"
|
"ButtonSubmit": "Next"
|
||||||
|
|||||||
@@ -10,6 +10,11 @@
|
|||||||
"Description": "کد ۵ رقمی ارسال شده به شماره {{phoneNumber}} را وارد نمایید.",
|
"Description": "کد ۵ رقمی ارسال شده به شماره {{phoneNumber}} را وارد نمایید.",
|
||||||
"Label": "",
|
"Label": "",
|
||||||
"TimerRunning": "ارسال مجدد تا {{time}} دیگر",
|
"TimerRunning": "ارسال مجدد تا {{time}} دیگر",
|
||||||
|
"Countdown": {
|
||||||
|
"Minute": "{{count}} دقیقه",
|
||||||
|
"Second": "{{count}} ثانیه",
|
||||||
|
"MinuteAndSecond": "{{mins}} دقیقه و {{secs}} ثانیه"
|
||||||
|
},
|
||||||
"TimerOut": "کد را دریافت نکردید؟",
|
"TimerOut": "کد را دریافت نکردید؟",
|
||||||
"TimerReset": "ارسال مجدد",
|
"TimerReset": "ارسال مجدد",
|
||||||
"ButtonSubmit": "بعدی"
|
"ButtonSubmit": "بعدی"
|
||||||
|
|||||||
Reference in New Issue
Block a user