2019-06-17 16:32:38 -04:00
|
|
|
// @flow
|
2019-09-26 12:07:11 -04:00
|
|
|
import * as PAGES from 'constants/pages';
|
2019-07-17 14:04:50 -04:00
|
|
|
import type { Node } from 'react';
|
|
|
|
import React, { useEffect } from 'react';
|
2019-06-17 16:32:38 -04:00
|
|
|
import Button from 'component/button';
|
|
|
|
import { FormField } from 'component/common/form';
|
2019-09-26 12:07:11 -04:00
|
|
|
import UserSignOutButton from 'component/userSignOutButton';
|
|
|
|
import Card from 'component/common/card';
|
2019-06-17 16:32:38 -04:00
|
|
|
|
|
|
|
type Props = {
|
2019-07-17 14:04:50 -04:00
|
|
|
cancelButton: Node,
|
2019-06-17 16:32:38 -04:00
|
|
|
email: string,
|
|
|
|
resendVerificationEmail: string => void,
|
|
|
|
checkEmailVerified: () => void,
|
|
|
|
user: {
|
|
|
|
has_verified_email: boolean,
|
|
|
|
},
|
2019-07-16 23:23:45 -04:00
|
|
|
fetchAccessToken: () => void,
|
|
|
|
accessToken: string,
|
2019-06-17 16:32:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
function UserEmail(props: Props) {
|
2019-07-16 23:23:45 -04:00
|
|
|
const { email, user, accessToken, fetchAccessToken } = props;
|
2019-06-27 02:18:45 -04:00
|
|
|
|
2019-07-17 14:04:50 -04:00
|
|
|
let isVerified = false;
|
|
|
|
if (user) {
|
|
|
|
isVerified = user.has_verified_email;
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!accessToken) {
|
|
|
|
fetchAccessToken();
|
|
|
|
}
|
|
|
|
}, [accessToken, fetchAccessToken]);
|
|
|
|
|
2019-06-17 16:32:38 -04:00
|
|
|
return (
|
2019-09-26 12:07:11 -04:00
|
|
|
<Card
|
2019-11-13 13:14:19 -05:00
|
|
|
title={__('lbry.tv Account')}
|
|
|
|
subtitle={
|
|
|
|
isVerified
|
|
|
|
? undefined
|
|
|
|
: __(
|
|
|
|
'Creating a lbry.tv account will allow you to earn rewards, receive content and security updates, and optionally backup your data.'
|
|
|
|
)
|
|
|
|
}
|
2019-09-26 12:28:08 -04:00
|
|
|
actions={
|
2019-09-27 14:56:15 -04:00
|
|
|
isVerified ? (
|
2019-09-26 12:07:11 -04:00
|
|
|
<FormField
|
|
|
|
type="text"
|
|
|
|
className="form-field--copyable"
|
|
|
|
readOnly
|
|
|
|
label={
|
|
|
|
<React.Fragment>
|
|
|
|
{__('Your Email')}{' '}
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
label={__('Update mailing preferences')}
|
|
|
|
href={`http://lbry.io/list/edit/${accessToken}`}
|
|
|
|
/>
|
|
|
|
</React.Fragment>
|
|
|
|
}
|
2019-11-22 16:13:00 -05:00
|
|
|
inputButton={<UserSignOutButton button="secondary" />}
|
2019-09-26 12:07:11 -04:00
|
|
|
value={email || ''}
|
|
|
|
/>
|
2019-09-27 14:56:15 -04:00
|
|
|
) : (
|
2019-11-13 13:14:19 -05:00
|
|
|
<Button button="primary" label={__('Sign In')} navigate={`/$/${PAGES.AUTH}`} />
|
2019-09-26 12:28:08 -04:00
|
|
|
)
|
2019-09-26 12:07:11 -04:00
|
|
|
}
|
|
|
|
/>
|
2019-06-17 16:32:38 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default UserEmail;
|