'use client' import { RiArrowLeftLine, RiMailSendFill } from '@remixicon/react' import { useTranslation } from 'react-i18next' import { useState } from 'react' import { useRouter, useSearchParams } from 'next/navigation' import { useContext } from 'use-context-selector' import Countdown from '@/app/components/signin/countdown' import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' import Toast from '@/app/components/base/toast' import { sendResetPasswordCode, verifyResetPasswordCode } from '@/service/common' import I18NContext from '@/context/i18n' export default function CheckCode() { const { t } = useTranslation() const router = useRouter() const searchParams = useSearchParams() const email = decodeURIComponent(searchParams.get('email') as string) const token = decodeURIComponent(searchParams.get('token') as string) const [code, setVerifyCode] = useState('') const [loading, setIsLoading] = useState(false) const { locale } = useContext(I18NContext) const verify = async () => { try { if (!code.trim()) { Toast.notify({ type: 'error', message: t('login.checkCode.emptyCode'), }) return } if (!/\d{6}/.test(code)) { Toast.notify({ type: 'error', message: t('login.checkCode.invalidCode'), }) return } setIsLoading(true) const ret = await verifyResetPasswordCode({ email, code, token }) ret.is_valid && router.push(`/reset-password/set-password?${searchParams.toString()}`) } catch (error) { console.error(error) } finally { setIsLoading(false) } } const resendCode = async () => { try { const res = await sendResetPasswordCode(email, locale) if (res.result === 'success') { const params = new URLSearchParams(searchParams) params.set('token', encodeURIComponent(res.data)) router.replace(`/reset-password/check-code?${params.toString()}`) } } catch (error) { console.error(error) } } return
{t('login.checkCode.validTime')}