2019-06-17 22:32:38 +02:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import { FormField } from 'component/common/form';
|
|
|
|
import UserEmailNew from 'component/userEmailNew';
|
|
|
|
import UserEmailVerify from 'component/userEmailVerify';
|
2019-06-27 08:18:45 +02:00
|
|
|
import cookie from 'cookie';
|
2019-06-17 22:32:38 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
cancelButton: React.Node,
|
|
|
|
email: string,
|
|
|
|
resendVerificationEmail: string => void,
|
|
|
|
checkEmailVerified: () => void,
|
|
|
|
user: {
|
|
|
|
has_verified_email: boolean,
|
|
|
|
},
|
2019-07-17 05:23:45 +02:00
|
|
|
fetchAccessToken: () => void,
|
|
|
|
accessToken: string,
|
2019-06-17 22:32:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function UserEmail(props: Props) {
|
2019-07-17 05:23:45 +02:00
|
|
|
const { email, user, accessToken, fetchAccessToken } = props;
|
2019-06-17 22:32:38 +02:00
|
|
|
let isVerified = false;
|
|
|
|
if (user) {
|
|
|
|
isVerified = user.has_verified_email;
|
|
|
|
}
|
|
|
|
|
2019-07-17 05:23:45 +02:00
|
|
|
if (!accessToken) fetchAccessToken();
|
|
|
|
|
2019-06-27 08:18:45 +02:00
|
|
|
const buttonsProps = IS_WEB
|
|
|
|
? {
|
|
|
|
onClick: () => {
|
|
|
|
document.cookie = cookie.serialize('auth_token', '');
|
|
|
|
window.location.reload();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: { href: 'https://lbry.com/faq/how-to-change-email' };
|
|
|
|
|
2019-06-17 22:32:38 +02:00
|
|
|
return (
|
|
|
|
<section className="card card--section">
|
|
|
|
{!email && <UserEmailNew />}
|
|
|
|
{user && email && !isVerified && <UserEmailVerify />}
|
|
|
|
{email && isVerified && (
|
|
|
|
<React.Fragment>
|
|
|
|
<div className="card__header">
|
|
|
|
<h2 className="card__title">{__('Email')}</h2>
|
|
|
|
<p className="card__subtitle">
|
|
|
|
{email && isVerified && __('Your email has been successfully verified')}
|
|
|
|
{!email && __('')}.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{isVerified && (
|
|
|
|
<FormField
|
|
|
|
type="text"
|
|
|
|
className="form-field--copyable"
|
|
|
|
readOnly
|
2019-07-17 05:23:45 +02:00
|
|
|
label={
|
|
|
|
<React.Fragment>
|
|
|
|
{__('Your Email - ')}{' '}
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
label={__('Update mailing preferences')}
|
|
|
|
href={`http://lbry.io/list/edit/${accessToken}`}
|
|
|
|
/>
|
|
|
|
</React.Fragment>
|
|
|
|
}
|
2019-06-17 22:32:38 +02:00
|
|
|
value={email}
|
2019-06-27 08:18:45 +02:00
|
|
|
inputButton={<Button button="inverse" label={__('Change')} {...buttonsProps} />}
|
2019-06-17 22:32:38 +02:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<p className="help">
|
|
|
|
{`${__(
|
2019-07-17 05:23:45 +02:00
|
|
|
'This information is disclosed only to LBRY, Inc. and not to the LBRY network. It is only required to save account information and earn rewards.'
|
2019-06-17 22:32:38 +02:00
|
|
|
)} `}
|
|
|
|
</p>
|
|
|
|
</React.Fragment>
|
|
|
|
)}
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default UserEmail;
|