import useGlobalStore from '@/config/use-global'; import { zodResolver } from '@hookform/resolvers/zod'; import { Button } from '@workspace/ui/components/button'; import { Form, FormControl, FormField, FormItem, FormMessage } from '@workspace/ui/components/form'; import { Input } from '@workspace/ui/components/input'; import { AreaCodeSelect } from '@workspace/ui/custom-components/area-code-select'; import { Icon } from '@workspace/ui/custom-components/icon'; import { Markdown } from '@workspace/ui/custom-components/markdown'; import { useTranslations } from 'next-intl'; import { Dispatch, SetStateAction } from 'react'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; import SendCode from '../send-code'; import CloudFlareTurnstile from '../turnstile'; export default function RegisterForm({ loading, onSubmit, initialValues, setInitialValues, onSwitchForm, }: { loading?: boolean; onSubmit: (data: any) => void; initialValues: any; setInitialValues: Dispatch>; onSwitchForm: Dispatch>; }) { const t = useTranslations('auth.register'); const { common } = useGlobalStore(); const { verify, auth, invite } = common; const formSchema = z .object({ telephone_area_code: z.string(), telephone: z.string(), password: z.string(), repeat_password: z.string(), code: z.string(), invite: invite.forced_invite ? z.string().min(1) : z.string().nullish(), cf_token: verify.enable_register_verify && verify.turnstile_site_key ? z.string() : z.string().nullish(), }) .superRefine(({ password, repeat_password }, ctx) => { if (password !== repeat_password) { ctx.addIssue({ code: z.ZodIssueCode.custom, message: t('passwordMismatch'), path: ['repeat_password'], }); } }); const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { ...initialValues, telephone_area_code: initialValues?.telephone_area_code || '1', invite: localStorage.getItem('invite') || '', }, }); return ( <> {auth.register.stop_register ? ( {t('message')} ) : (
(
( { if (value.phone) { form.setValue('telephone_area_code', value.phone); } }} /> )} />
)} /> ( )} /> ( )} /> (
)} /> ( )} /> {verify.enable_register_verify && ( ( )} /> )} )}
{t('existingAccount')} 
); }