// @flow import * as PAGES from 'constants/pages'; import { DOMAIN } from 'config'; import React, { useState } from 'react'; import { FormField, Form } from 'component/common/form'; import Button from 'component/button'; import analytics from 'analytics'; import { EMAIL_REGEX } from 'constants/email'; import I18nMessage from 'component/i18nMessage'; import { useHistory } from 'react-router-dom'; import Card from 'component/common/card'; import ErrorText from 'component/common/error-text'; import Nag from 'component/common/nag'; import classnames from 'classnames'; type Props = { errorMessage: ?string, emailExists: boolean, isPending: boolean, syncEnabled: boolean, setSync: (boolean) => void, balance: number, daemonSettings: { share_usage_data: boolean }, setShareDiagnosticData: (boolean) => void, doSignUp: (string, ?string) => Promise, clearEmailEntry: () => void, interestedInYoutubSync: boolean, doToggleInterestedInYoutubeSync: () => void, }; function UserEmailNew(props: Props) { const { errorMessage, isPending, doSignUp, setSync, daemonSettings, setShareDiagnosticData, clearEmailEntry, emailExists, } = props; const { share_usage_data: shareUsageData } = daemonSettings; const { push, location } = useHistory(); const urlParams = new URLSearchParams(location.search); const emailFromUrl = urlParams.get('email'); const defaultEmail = emailFromUrl ? decodeURIComponent(emailFromUrl) : ''; const [email, setEmail] = useState(defaultEmail); const [password, setPassword] = useState(''); const [localShareUsageData, setLocalShareUsageData] = React.useState(false); const [formSyncEnabled, setFormSyncEnabled] = useState(true); const valid = email.match(EMAIL_REGEX); function handleUsageDataChange() { setLocalShareUsageData(!localShareUsageData); } function handleSubmit() { // @if TARGET='app' setSync(formSyncEnabled); setShareDiagnosticData(true); // @endif doSignUp(email, password === '' ? undefined : password).then(() => { analytics.emailProvidedEvent(); }); } function handleChangeToSignIn(additionalParams) { clearEmailEntry(); let url = `/$/${PAGES.AUTH_SIGNIN}`; const urlParams = new URLSearchParams(location.search); urlParams.delete('email'); if (email) { urlParams.set('email', encodeURIComponent(email)); } urlParams.delete('email_exists'); if (emailExists) { urlParams.set('email_exists', '1'); } push(`${url}?${urlParams.toString()}`); } React.useEffect(() => { if (emailExists) { handleChangeToSignIn(); } }, [emailExists]); return (
setEmail(e.target.value)} /> setPassword(e.target.value)} /> {__('Backup your account and wallet data.')}{' '}

, }} > By creating an account, you agree to our %terms% and confirm you're over the age of 13.

} nag={<>{errorMessage && {errorMessage}} />}} /> ); } export default UserEmailNew;