// @flow import { SITE_NAME, SIMPLE_SITE } from 'config'; import * as PAGES from 'constants/pages'; import React, { useState } from 'react'; import { FormField, Form } from 'component/common/form'; import Button from 'component/button'; import { EMAIL_REGEX } from 'constants/email'; import { useHistory } from 'react-router-dom'; import UserEmailVerify from 'component/userEmailVerify'; import Card from 'component/common/card'; import Nag from 'component/common/nag'; import classnames from 'classnames'; import LoginGraphic from 'component/loginGraphic'; type Props = { user: ?User, errorMessage: ?string, emailToVerify: ?string, emailDoesNotExist: boolean, doClearEmailEntry: () => void, doUserSignIn: (string, ?string) => void, doUserCheckIfEmailExists: (string) => void, doSetWalletSyncPreference: (boolean) => void, doSetClientSetting: (string, boolean, ?boolean) => void, isPending: boolean, }; function UserEmailReturning(props: Props) { const { user, errorMessage, doUserCheckIfEmailExists, emailToVerify, doClearEmailEntry, emailDoesNotExist, doSetWalletSyncPreference, isPending, } = props; const { push, location } = useHistory(); const urlParams = new URLSearchParams(location.search); const emailFromUrl = urlParams.get('email'); const emailExistsFromUrl = urlParams.get('email_exists'); const defaultEmail = emailFromUrl ? decodeURIComponent(emailFromUrl) : ''; const hasPasswordSet = user && user.password_set; const [email, setEmail] = useState(defaultEmail); const [syncEnabled, setSyncEnabled] = useState(true); const valid = email.match(EMAIL_REGEX); const showEmailVerification = emailToVerify || hasPasswordSet; function handleSubmit() { // @if TARGET='app' doSetWalletSyncPreference(syncEnabled); // @endif doUserCheckIfEmailExists(email); } function handleChangeToSignIn() { doClearEmailEntry(); let url = `/$/${PAGES.AUTH}`; const urlParams = new URLSearchParams(location.search); urlParams.delete('email_exists'); urlParams.delete('email'); if (email) { urlParams.set('email', encodeURIComponent(email)); } push(`${url}?${urlParams.toString()}`); } return (
{showEmailVerification ? ( ) : (
setEmail(e.target.value)} /> {/* @if TARGET='app' */} {__('Backup your account and wallet data.')}{' '}
} nag={ <> {!emailDoesNotExist && emailExistsFromUrl && ( )} {emailDoesNotExist && ( )} {!emailExistsFromUrl && !emailDoesNotExist && errorMessage && ( )} } secondPane={SIMPLE_SITE && } /> )} ); } export default UserEmailReturning;