import { Alert, Button } from 'antd'; import { observer } from 'mobx-react-lite'; import React, { ChangeEvent, FormEvent, useEffect, useRef, useState, } from 'react'; import ReCAPTCHA from 'react-google-recaptcha'; import { toast } from 'react-toastify'; import { PASSWORD_POLICY } from 'App/constants'; import { SITE_ID_STORAGE_KEY } from 'App/constants/storageKeys'; import { useStore } from 'App/mstore'; import { login } from 'App/routes'; import { validatePassword } from 'App/validate'; import { Form, Input, Link } from 'UI'; import Select from 'Shared/Select'; import { useTranslation } from 'react-i18next'; const LOGIN_ROUTE = login(); function SignupForm() { const { t } = useTranslation(); const { userStore } = useStore(); const { tenants } = userStore; const { signup } = userStore; const { errors } = userStore.signUpRequest; const { loading } = userStore.signUpRequest; const [state, setState] = useState({ tenantId: '', fullname: '', password: '', email: '', projectName: '', organizationName: '', reload: false, CAPTCHA_ENABLED: window.env.CAPTCHA_ENABLED === 'true', }); const recaptchaRef = useRef(null); const [passwordError, setPasswordError] = useState(null); const handleSubmit = (token: string) => { const { tenantId, fullname, password, email, projectName, organizationName, auth, } = state; if (!validatePassword(password)) return; localStorage.removeItem(SITE_ID_STORAGE_KEY); signup({ tenantId, fullname, password, email, projectName, organizationName, auth, 'g-recaptcha-response': token, }).then((resp: any) => { if ( resp && resp.errors && Array.isArray(resp.errors) && resp.errors.length > 0 ) { if ((resp.errors[0] as string).includes('in use')) { toast.error( t( "This email is already linked to an account or team on OpenReplay and can't be used again.", ), ); } else { resp.errors[0] ? toast.error(resp.errors[0]) : toast.error('Something went wrong'); } } }); setState({ ...state, reload: true }); }; const write = ({ target: { value, name } }: ChangeEvent) => setState({ ...state, [name]: value }); const writeOption = ({ name, value, }: { name: string; value: { value: string }; }) => setState({ ...state, [name]: value.value }); const onSubmit = (e: FormEvent) => { e.preventDefault(); const { CAPTCHA_ENABLED } = state; if (CAPTCHA_ENABLED && recaptchaRef.current) { recaptchaRef.current.execute(); } else if (!CAPTCHA_ENABLED) { handleSubmit(''); } }; useEffect(() => { if (state.password && !validatePassword(state.password)) { setPasswordError(t('Password must be at least 8 characters long')); } else { setPasswordError(null); } }, [state.password]); return (
Logo

{t('Create Account')}

<> {state.CAPTCHA_ENABLED && ( handleSubmit(token || '')} /> )}
{tenants.length > 0 && ( {passwordError && ( // )} {errors && errors.length > 0 ? ( ) : null}
{t('By signing up, you agree to our')}{' '} {t('terms of service')} {' '} {t('and')}{' '} {t('privacy policy')} .
{t('Already having an account?')}{' '} {t('Login')}
); } export default observer(SignupForm);