import { type FormEvent, useEffect, useState } from 'react'; import { httpPost } from '../../lib/http'; import { deleteUrlParam, getUrlParams } from '../../lib/browser'; import { isLoggedIn, setAIReferralCode } from '../../lib/jwt'; type EmailSignupFormProps = { isDisabled?: boolean; setIsDisabled?: (isDisabled: boolean) => void; }; export function EmailSignupForm(props: EmailSignupFormProps) { const { isDisabled, setIsDisabled } = props; const { rc: referralCode } = getUrlParams() as { rc?: string; }; const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [name, setName] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const onSubmit = async (e: FormEvent) => { e.preventDefault(); setIsLoading(true); setIsDisabled?.(true); setError(''); const { response, error } = await httpPost<{ status: 'ok' }>( `${import.meta.env.PUBLIC_API_URL}/v1-register`, { email, password, name, }, ); if (error || response?.status !== 'ok') { setIsLoading(false); setIsDisabled?.(false); setError( error?.message || 'Something went wrong. Please try again later.', ); return; } window.location.href = `/verification-pending?email=${encodeURIComponent( email, )}`; }; useEffect(() => { if (!referralCode || isLoggedIn()) { deleteUrlParam('rc'); return; } setAIReferralCode(referralCode); deleteUrlParam('rc'); }, []); return (
setName(String((e.target as any).value))} /> setEmail(String((e.target as any).value))} /> setPassword(String((e.target as any).value))} /> {error && (

{error}.

)}
); }