lbry-desktop/src/ui/component/userEmail/view.jsx

79 lines
2.2 KiB
React
Raw Normal View History

2019-06-17 22:32:38 +02:00
// @flow
2019-07-17 20:04:50 +02:00
import type { Node } from 'react';
import React, { useEffect } from 'react';
2019-06-17 22:32:38 +02:00
import Button from 'component/button';
import { FormField } from 'component/common/form';
import UserEmailNew from 'component/userEmailNew';
import UserEmailVerify from 'component/userEmailVerify';
2019-07-19 16:52:42 +02:00
import UserEmailResetButton from 'component/userEmailResetButton';
2019-06-17 22:32:38 +02:00
type Props = {
2019-07-17 20:04:50 +02:00
cancelButton: Node,
2019-06-17 22:32:38 +02:00
email: string,
resendVerificationEmail: string => void,
checkEmailVerified: () => void,
user: {
has_verified_email: boolean,
},
fetchAccessToken: () => void,
accessToken: string,
2019-06-17 22:32:38 +02:00
};
function UserEmail(props: Props) {
const { email, user, accessToken, fetchAccessToken } = props;
2019-06-27 08:18:45 +02:00
2019-07-17 20:04:50 +02:00
let isVerified = false;
if (user) {
isVerified = user.has_verified_email;
}
useEffect(() => {
if (!accessToken) {
fetchAccessToken();
}
}, [accessToken, fetchAccessToken]);
2019-06-17 22:32:38 +02:00
return (
<section className="card card--section">
{!email && <UserEmailNew />}
{user && email && !isVerified && <UserEmailVerify />}
{email && isVerified && (
<React.Fragment>
2019-07-21 23:31:22 +02:00
<h2 className="card__title">{__('Email')}</h2>
<p className="card__subtitle">
{email && isVerified && __('Your email has been successfully verified')}
{!email && __('')}.
</p>
2019-06-17 22:32:38 +02:00
{isVerified && (
<FormField
type="text"
className="form-field--copyable"
readOnly
label={
<React.Fragment>
2019-07-17 20:04:50 +02:00
{__('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-07-19 16:52:42 +02:00
inputButton={<UserEmailResetButton button="inverse" />}
2019-06-17 22:32:38 +02:00
/>
)}
<p className="help">
{`${__(
'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;