2019-06-17 22:32:38 +02:00
|
|
|
// @flow
|
2019-09-26 18:07:11 +02:00
|
|
|
import * as PAGES from 'constants/pages';
|
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';
|
2019-09-26 18:07:11 +02:00
|
|
|
import UserSignOutButton from 'component/userSignOutButton';
|
|
|
|
import Card from 'component/common/card';
|
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,
|
|
|
|
},
|
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-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 (
|
2019-09-26 18:07:11 +02:00
|
|
|
<Card
|
|
|
|
title={__('Email')}
|
|
|
|
subtitle={__(
|
|
|
|
'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
|
|
|
)}
|
2019-09-26 18:28:08 +02:00
|
|
|
actions={
|
2019-09-27 20:56:15 +02:00
|
|
|
isVerified ? (
|
2019-09-26 18:07:11 +02: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>
|
|
|
|
}
|
|
|
|
inputButton={<UserSignOutButton button="inverse" />}
|
|
|
|
value={email || ''}
|
|
|
|
/>
|
2019-09-27 20:56:15 +02:00
|
|
|
) : (
|
|
|
|
<Button button="primary" label={__('Add Email')} navigate={`/$/${PAGES.AUTH}`} />
|
2019-09-26 18:28:08 +02:00
|
|
|
)
|
2019-09-26 18:07:11 +02:00
|
|
|
}
|
|
|
|
/>
|
2019-06-17 22:32:38 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default UserEmail;
|