import React from 'react'; import { connect } from 'react-redux'; import withPageTitle from 'HOCs/withPageTitle'; import { Icon, Loader, Button, Link, Input, Form, Popover, Tooltip } from 'UI'; import { login } from 'Duck/user'; import { forgotPassword, signup } from 'App/routes'; import ReCAPTCHA from 'react-google-recaptcha'; import { withRouter } from 'react-router-dom'; import stl from './login.module.css'; import cn from 'classnames'; import { setJwt } from 'Duck/user'; import LoginBg from '../../svg/login-illustration.svg'; const FORGOT_PASSWORD = forgotPassword(); const SIGNUP_ROUTE = signup(); const recaptchaRef = React.createRef(); export default @connect( (state, props) => ({ errors: state.getIn(['user', 'loginRequest', 'errors']), loading: state.getIn(['user', 'loginRequest', 'loading']), authDetails: state.getIn(['user', 'authDetails']), params: new URLSearchParams(props.location.search), }), { login, setJwt } ) @withPageTitle('Login - OpenReplay') @withRouter class Login extends React.Component { state = { email: '', password: '', CAPTCHA_ENABLED: window.env.CAPTCHA_ENABLED === 'true', }; componentDidMount() { const { params } = this.props; const jwt = params.get('jwt'); if (jwt) { this.props.setJwt(jwt); window.location.href = '/'; } } handleSubmit = (token) => { const { email, password } = this.state; this.props.login({ email: email.trim(), password, 'g-recaptcha-response': token }).then(() => { const { errors } = this.props; }); }; onSubmit = (e) => { e.preventDefault(); const { CAPTCHA_ENABLED } = this.state; if (CAPTCHA_ENABLED && recaptchaRef.current) { recaptchaRef.current.execute(); } else if (!CAPTCHA_ENABLED) { this.handleSubmit(); } }; write = ({ target: { value, name } }) => this.setState({ [name]: value }); render() { const { errors, loading, authDetails } = this.props; const { CAPTCHA_ENABLED } = this.state; return (
); } }