lbry-desktop/ui/component/userEmailVerify/view.jsx

99 lines
2.8 KiB
React
Raw Normal View History

2018-04-03 11:14:55 -04:00
// @flow
import * as React from 'react';
2018-03-26 14:32:43 -07:00
import Button from 'component/button';
2019-09-26 12:07:11 -04:00
import UserSignOutButton from 'component/userSignOutButton';
2020-01-09 14:03:47 -05:00
import I18nMessage from 'component/i18nMessage';
2017-06-02 19:09:52 -04:00
2018-04-03 11:14:55 -04:00
type Props = {
email: string,
2019-10-28 10:04:37 -04:00
isReturningUser: boolean,
resendVerificationEmail: string => void,
2019-10-28 10:04:37 -04:00
resendingEmail: boolean,
checkEmailVerified: () => void,
2019-10-28 10:04:37 -04:00
toast: string => void,
2019-01-07 21:46:33 -05:00
user: {
has_verified_email: boolean,
},
2018-04-03 11:14:55 -04:00
};
2019-01-07 21:46:33 -05:00
class UserEmailVerify extends React.PureComponent<Props> {
2018-04-03 11:14:55 -04:00
constructor(props: Props) {
2017-06-02 19:09:52 -04:00
super(props);
2019-01-07 21:46:33 -05:00
this.emailVerifyCheckInterval = null;
2018-06-06 21:40:32 -05:00
(this: any).handleResendVerificationEmail = this.handleResendVerificationEmail.bind(this);
2017-06-02 19:09:52 -04:00
}
2019-01-07 21:46:33 -05:00
componentDidMount() {
this.emailVerifyCheckInterval = setInterval(() => this.checkIfVerified(), 5000);
2017-06-02 19:09:52 -04:00
}
2019-01-07 21:46:33 -05:00
componentDidUpdate() {
2019-08-27 10:43:42 -04:00
const { user } = this.props;
if (this.emailVerifyCheckInterval && user && user.has_verified_email) {
2019-01-07 21:46:33 -05:00
clearInterval(this.emailVerifyCheckInterval);
}
}
componentWillUnmount() {
if (this.emailVerifyCheckInterval) {
clearInterval(this.emailVerifyCheckInterval);
2017-12-22 18:09:06 -08:00
}
2017-06-02 19:09:52 -04:00
}
2018-06-06 21:40:32 -05:00
handleResendVerificationEmail() {
2019-10-28 10:04:37 -04:00
const { email, resendVerificationEmail, toast } = this.props;
resendVerificationEmail(email);
toast(__('New email sent.'));
}
2019-01-07 21:46:33 -05:00
checkIfVerified() {
const { checkEmailVerified } = this.props;
checkEmailVerified();
2019-01-07 21:46:33 -05:00
}
emailVerifyCheckInterval: ?IntervalID;
2017-06-02 19:09:52 -04:00
render() {
2019-10-28 10:04:37 -04:00
const { email, isReturningUser, resendingEmail } = this.props;
2019-07-17 18:48:11 -04:00
2017-06-08 17:15:34 -04:00
return (
<React.Fragment>
2019-10-28 10:04:37 -04:00
<h1 className="section__title--large">{isReturningUser ? __('Check Your Email') : __('Confirm Your Email')}</h1>
2019-09-26 12:07:11 -04:00
<p className="section__subtitle">
2020-01-09 14:03:47 -05:00
{__(
'An email was sent to %email%. Follow the link to %verify_text%. After, this page will update automatically.',
{
email,
verify_text: isReturningUser ? __('sign in') : __('verify your email'),
}
)}
2019-07-21 17:31:22 -04:00
</p>
2019-09-26 12:07:11 -04:00
<div className="section__body section__actions">
2019-07-21 17:31:22 -04:00
<Button
button="primary"
2019-10-28 10:04:37 -04:00
label={__('Resend Email')}
2019-07-21 17:31:22 -04:00
onClick={this.handleResendVerificationEmail}
2019-10-28 10:04:37 -04:00
disabled={resendingEmail}
2019-07-21 17:31:22 -04:00
/>
2019-09-26 12:07:11 -04:00
<UserSignOutButton label={__('Start Over')} />
</div>
2019-07-21 17:31:22 -04:00
<p className="help">
2020-01-09 14:03:47 -05:00
<I18nMessage
tokens={{
help_link: <Button button="link" href="mailto:help@lbry.com" label="help@lbry.com" />,
chat_link: <Button button="link" href="https://chat.lbry.com" label="chat" />,
}}
>
Email %help_link% or join our %chat_link% if you encounter any trouble verifying.
</I18nMessage>
2019-07-21 17:31:22 -04:00
</p>
</React.Fragment>
2017-06-08 17:15:34 -04:00
);
2017-06-02 19:09:52 -04:00
}
}
2017-06-08 17:15:34 -04:00
export default UserEmailVerify;