2018-03-30 02:43:47 +02:00
|
|
|
// @flow
|
2020-04-13 21:16:07 +02:00
|
|
|
import * as PAGES from 'constants/pages';
|
2021-03-19 21:52:59 +01:00
|
|
|
import { SITE_NAME, DOMAIN } from 'config';
|
2019-08-27 16:43:42 +02:00
|
|
|
import React, { useState } from 'react';
|
2019-07-08 18:51:53 +02:00
|
|
|
import { FormField, Form } from 'component/common/form';
|
|
|
|
import Button from 'component/button';
|
2019-08-14 18:28:13 +02:00
|
|
|
import analytics from 'analytics';
|
2019-09-26 18:28:08 +02:00
|
|
|
import { EMAIL_REGEX } from 'constants/email';
|
2020-02-24 21:54:40 +01:00
|
|
|
import I18nMessage from 'component/i18nMessage';
|
2020-04-13 21:16:07 +02:00
|
|
|
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';
|
2021-03-19 21:52:59 +01:00
|
|
|
import classnames from 'classnames';
|
|
|
|
import OdyseeLogoWithWhiteText from 'component/header/odysee_white.png';
|
|
|
|
import OdyseeLogoWithText from 'component/header/odysee.png';
|
2017-06-02 02:51:52 +02:00
|
|
|
|
2018-03-30 02:43:47 +02:00
|
|
|
type Props = {
|
|
|
|
errorMessage: ?string,
|
2020-04-13 21:16:07 +02:00
|
|
|
emailExists: boolean,
|
2018-03-30 02:43:47 +02:00
|
|
|
isPending: boolean,
|
2019-09-26 18:28:08 +02:00
|
|
|
syncEnabled: boolean,
|
2021-03-19 21:52:59 +01:00
|
|
|
setSync: (boolean) => void,
|
2019-09-26 18:28:08 +02:00
|
|
|
balance: number,
|
2020-02-24 21:43:07 +01:00
|
|
|
daemonSettings: { share_usage_data: boolean },
|
2021-03-19 21:52:59 +01:00
|
|
|
setShareDiagnosticData: (boolean) => void,
|
2020-04-15 20:11:51 +02:00
|
|
|
doSignUp: (string, ?string) => Promise<any>,
|
2020-04-13 21:16:07 +02:00
|
|
|
clearEmailEntry: () => void,
|
2020-09-04 22:11:28 +02:00
|
|
|
interestedInYoutubSync: boolean,
|
|
|
|
doToggleInterestedInYoutubeSync: () => void,
|
2021-03-19 21:52:59 +01:00
|
|
|
currentTheme: string,
|
2018-03-30 02:43:47 +02:00
|
|
|
};
|
|
|
|
|
2019-08-27 16:43:42 +02:00
|
|
|
function UserEmailNew(props: Props) {
|
2020-04-13 21:16:07 +02:00
|
|
|
const {
|
|
|
|
errorMessage,
|
|
|
|
isPending,
|
|
|
|
doSignUp,
|
|
|
|
setSync,
|
|
|
|
daemonSettings,
|
|
|
|
setShareDiagnosticData,
|
|
|
|
clearEmailEntry,
|
|
|
|
emailExists,
|
2020-09-04 22:11:28 +02:00
|
|
|
interestedInYoutubSync,
|
|
|
|
doToggleInterestedInYoutubeSync,
|
2021-03-19 21:52:59 +01:00
|
|
|
currentTheme,
|
2020-04-13 21:16:07 +02:00
|
|
|
} = props;
|
2020-02-24 21:43:07 +01:00
|
|
|
const { share_usage_data: shareUsageData } = daemonSettings;
|
2020-04-13 21:16:07 +02:00
|
|
|
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('');
|
2020-02-24 21:43:07 +01:00
|
|
|
const [localShareUsageData, setLocalShareUsageData] = React.useState(false);
|
2019-10-15 23:23:51 +02:00
|
|
|
const [formSyncEnabled, setFormSyncEnabled] = useState(true);
|
2020-04-13 21:16:07 +02:00
|
|
|
const valid = email.match(EMAIL_REGEX);
|
2017-06-02 02:51:52 +02:00
|
|
|
|
2020-02-24 21:43:07 +01:00
|
|
|
function handleUsageDataChange() {
|
2020-02-25 16:16:33 +01:00
|
|
|
setLocalShareUsageData(!localShareUsageData);
|
2020-02-24 21:43:07 +01:00
|
|
|
}
|
|
|
|
|
2019-08-27 16:43:42 +02:00
|
|
|
function handleSubmit() {
|
2020-02-24 21:47:27 +01:00
|
|
|
// @if TARGET='app'
|
2020-11-09 20:13:44 +01:00
|
|
|
setSync(formSyncEnabled);
|
2020-02-24 21:43:07 +01:00
|
|
|
setShareDiagnosticData(true);
|
2020-02-24 21:47:27 +01:00
|
|
|
// @endif
|
2020-04-15 20:11:51 +02:00
|
|
|
doSignUp(email, password === '' ? undefined : password).then(() => {
|
|
|
|
analytics.emailProvidedEvent();
|
|
|
|
});
|
2017-06-02 02:51:52 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 21:16:07 +02:00
|
|
|
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]);
|
|
|
|
|
2019-08-27 16:43:42 +02:00
|
|
|
return (
|
2020-04-13 21:16:07 +02:00
|
|
|
<div className="main__sign-up">
|
|
|
|
<Card
|
2020-08-21 17:18:47 +02:00
|
|
|
title={__('Join %SITE_NAME%', { SITE_NAME })}
|
2020-04-13 21:16:07 +02:00
|
|
|
// @if TARGET='app'
|
|
|
|
subtitle={__('An account with lbry.tv allows you to earn rewards and backup your data.')}
|
|
|
|
// @endif
|
|
|
|
actions={
|
2021-03-19 21:52:59 +01:00
|
|
|
<div className={classnames({ 'card--disabled': DOMAIN === 'lbry.tv' })}>
|
2020-04-13 21:16:07 +02:00
|
|
|
<Form onSubmit={handleSubmit} className="section">
|
|
|
|
<FormField
|
|
|
|
autoFocus
|
2020-07-03 01:31:46 +02:00
|
|
|
placeholder={__('yourstruly@example.com')}
|
2020-04-13 21:16:07 +02:00
|
|
|
type="email"
|
|
|
|
name="sign_up_email"
|
|
|
|
label={__('Email')}
|
|
|
|
value={email}
|
2021-03-19 21:52:59 +01:00
|
|
|
onChange={(e) => setEmail(e.target.value)}
|
2020-04-13 21:16:07 +02:00
|
|
|
/>
|
|
|
|
<FormField
|
|
|
|
type="password"
|
|
|
|
name="sign_in_password"
|
|
|
|
label={__('Password')}
|
|
|
|
value={password}
|
2021-03-19 21:52:59 +01:00
|
|
|
onChange={(e) => setPassword(e.target.value)}
|
2020-04-13 21:16:07 +02:00
|
|
|
/>
|
2019-10-15 23:23:51 +02:00
|
|
|
|
2020-10-09 18:15:59 +02:00
|
|
|
{/* @if TARGET='web' */}
|
2020-09-04 22:11:28 +02:00
|
|
|
<FormField
|
|
|
|
type="checkbox"
|
|
|
|
name="youtube_sync_checkbox"
|
|
|
|
label={__('Sync my YouTube channel')}
|
|
|
|
checked={interestedInYoutubSync}
|
|
|
|
onChange={() => doToggleInterestedInYoutubeSync()}
|
|
|
|
/>
|
2020-10-09 18:15:59 +02:00
|
|
|
{/* @endif */}
|
2020-09-04 22:11:28 +02:00
|
|
|
|
2020-10-09 18:15:59 +02:00
|
|
|
{/* @if TARGET='app' */}
|
|
|
|
<FormField
|
|
|
|
type="checkbox"
|
|
|
|
name="sync_checkbox"
|
|
|
|
label={
|
|
|
|
<React.Fragment>
|
|
|
|
{__('Backup your account and wallet data.')}{' '}
|
|
|
|
<Button button="link" href="https://lbry.com/faq/account-sync" label={__('Learn More')} />
|
|
|
|
</React.Fragment>
|
|
|
|
}
|
|
|
|
checked={formSyncEnabled}
|
|
|
|
onChange={() => setFormSyncEnabled(!formSyncEnabled)}
|
|
|
|
/>
|
|
|
|
{/* @endif */}
|
2020-02-24 21:43:07 +01:00
|
|
|
|
2020-04-13 21:16:07 +02:00
|
|
|
{!shareUsageData && !IS_WEB && (
|
|
|
|
<FormField
|
|
|
|
type="checkbox"
|
|
|
|
name="share_data_checkbox"
|
|
|
|
checked={localShareUsageData}
|
|
|
|
onChange={handleUsageDataChange}
|
|
|
|
label={
|
|
|
|
<React.Fragment>
|
|
|
|
{__('Share usage data with LBRY inc.')}{' '}
|
|
|
|
<Button button="link" href="https://lbry.com/faq/privacy-and-data" label={__('Learn More')} />
|
|
|
|
{!localShareUsageData && <span className="error__text"> ({__('Required')})</span>}
|
|
|
|
</React.Fragment>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<div className="section__actions">
|
2020-02-24 21:54:40 +01:00
|
|
|
<Button
|
2020-04-13 21:16:07 +02:00
|
|
|
button="primary"
|
|
|
|
type="submit"
|
2020-08-21 06:24:02 +02:00
|
|
|
label={__('Sign Up')}
|
2020-04-13 21:16:07 +02:00
|
|
|
disabled={
|
|
|
|
!email || !password || !valid || (!IS_WEB && !localShareUsageData && !shareUsageData) || isPending
|
|
|
|
}
|
2020-02-24 21:54:40 +01:00
|
|
|
/>
|
2020-08-24 19:59:37 +02:00
|
|
|
<Button button="link" onClick={handleChangeToSignIn} label={__('Log In')} />
|
2020-04-13 21:16:07 +02:00
|
|
|
</div>
|
2020-08-21 17:18:47 +02:00
|
|
|
<p className="help--card-actions">
|
2020-04-13 21:16:07 +02:00
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
2020-08-21 17:18:47 +02:00
|
|
|
terms: <Button button="link" href="https://www.lbry.com/termsofservice" label={__('terms')} />,
|
2020-04-13 21:16:07 +02:00
|
|
|
}}
|
|
|
|
>
|
2020-08-21 17:18:47 +02:00
|
|
|
By creating an account, you agree to our %terms% and confirm you're over the age of 13.
|
2020-04-13 21:16:07 +02:00
|
|
|
</I18nMessage>
|
|
|
|
</p>
|
|
|
|
</Form>
|
|
|
|
</div>
|
|
|
|
}
|
2021-03-19 21:52:59 +01:00
|
|
|
nag={
|
|
|
|
<>
|
|
|
|
{IS_WEB && DOMAIN === 'lbry.tv' && (
|
|
|
|
<Nag
|
|
|
|
relative
|
|
|
|
message={
|
|
|
|
<I18nMessage
|
|
|
|
tokens={{
|
|
|
|
odysee: (
|
|
|
|
<Button button="link" label={__('odysee.com')} href="https://odysee.com?src=lbrytv-retired" />
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{__(
|
|
|
|
'lbry.tv is being retired in favor of %odysee% and new sign ups are disabled. Sign up on %odysee% instead'
|
|
|
|
)}
|
|
|
|
</I18nMessage>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{errorMessage && <Nag type="error" relative message={<ErrorText>{errorMessage}</ErrorText>} />}
|
|
|
|
</>
|
|
|
|
}
|
2020-04-13 21:16:07 +02:00
|
|
|
/>
|
2021-03-19 21:52:59 +01:00
|
|
|
|
|
|
|
{IS_WEB && DOMAIN === 'lbry.tv' && (
|
|
|
|
<div className="signup__odysee-logo">
|
|
|
|
<Button href="https://odysee.com?src=lbrytv-retired">
|
|
|
|
<img src={currentTheme === 'light' ? OdyseeLogoWithText : OdyseeLogoWithWhiteText} />
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-04-13 21:16:07 +02:00
|
|
|
</div>
|
2019-08-27 16:43:42 +02:00
|
|
|
);
|
2017-06-02 02:51:52 +02:00
|
|
|
}
|
|
|
|
|
2017-06-08 23:15:34 +02:00
|
|
|
export default UserEmailNew;
|