import useGlobalStore from '@/config/use-global'; import { sendEmailCode } from '@/services/common/common'; import { Icon } from '@iconify/react'; import { Button } from '@shadcn/ui/button'; import { Form, FormControl, FormField, FormItem, FormMessage } from '@shadcn/ui/form'; import { Input } from '@shadcn/ui/input'; import { useForm } from '@shadcn/ui/lib/react-hook-form'; import { z, zodResolver } from '@shadcn/ui/lib/zod'; import { useCountDown } from 'ahooks'; import { useTranslations } from 'next-intl'; import { Dispatch, SetStateAction, useState } from 'react'; import CloudFlareTurnstile from './turnstile'; export default function UserResetForm({ loading, onSubmit, initialValues, setInitialValues, onSwitchForm, }: { loading?: boolean; onSubmit: (data: any) => void; initialValues: any; setInitialValues: Dispatch>; onSwitchForm: (type?: 'register' | 'reset') => void; }) { const t = useTranslations('auth.reset'); const { common } = useGlobalStore(); const { verify, register } = common; const [targetDate, setTargetDate] = useState(); const [, { seconds }] = useCountDown({ targetDate, onEnd: () => { setTargetDate(undefined); }, }); const handleSendCode = async () => { await sendEmailCode({ email: initialValues.email, type: 2, }); setTargetDate(Date.now() + 60000); // 60秒倒计时 }; const formSchema = z.object({ email: z.string(), password: z.string(), code: register.enable_email_verify ? z.string() : z.string().nullish(), cf_token: verify.enable_register_verify ? z.string() : z.string().nullish(), }); const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: initialValues, }); return ( <>
( )} /> ( )} /> {register.enable_email_verify && ( (
)} /> )} {verify.enable_reset_password_verify && ( ( )} /> )}
{t('existingAccount')}
); }