'use client' import Link from 'next/link' import { RiArrowLeftLine, RiLockPasswordLine } 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 { COUNT_DOWN_KEY, COUNT_DOWN_TIME_MS } from '../components/signin/countdown' import { emailRegex } from '@/config' import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' import Toast from '@/app/components/base/toast' import { sendResetPasswordCode } from '@/service/common' import I18NContext from '@/context/i18n' export default function CheckCode() { const { t } = useTranslation() const searchParams = useSearchParams() const router = useRouter() const [email, setEmail] = useState('') const [loading, setIsLoading] = useState(false) const { locale } = useContext(I18NContext) const handleGetEMailVerificationCode = async () => { try { if (!email) { Toast.notify({ type: 'error', message: t('login.error.emailEmpty') }) return } if (!emailRegex.test(email)) { Toast.notify({ type: 'error', message: t('login.error.emailInValid'), }) return } setIsLoading(true) const res = await sendResetPasswordCode(email, locale) if (res.result === 'success') { localStorage.setItem(COUNT_DOWN_KEY, `${COUNT_DOWN_TIME_MS}`) const params = new URLSearchParams(searchParams) params.set('token', encodeURIComponent(res.data)) params.set('email', encodeURIComponent(email)) router.push(`/reset-password/check-code?${params.toString()}`) } else if (res.code === 'account_not_found') { Toast.notify({ type: 'error', message: t('login.error.registrationNotAllowed'), }) } else { Toast.notify({ type: 'error', message: res.data, }) } } catch (error) { console.error(error) } finally { setIsLoading(false) } } return
{t('login.resetPasswordDesc')}