Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // @flow
- import React from "react";
- import { bindActionCreators } from "redux";
- import { connect } from "react-redux";
- import { isEmpty, match } from "ramda";
- import { parse } from "query-string";
- import Component from "./component";
- import loginAction from "modules/user/actions/login";
- import registerAction from "modules/user/actions/register";
- import forgotPasswordAction from "modules/user/actions/forgot_password";
- import setPreviousPageAction from "modules/previous_page/actions/set";
- import resetErrorMessageAction from "modules/user/actions/reset_error_message";
- import type { Location } from "react-router";
- import type { User } from "modules/user";
- import type { RouterHistory } from "react-router";
- import typeof LoginAction from "modules/user/actions/login";
- import typeof RegisterAction from "modules/user/actions/register";
- import typeof ForgotPasswordAction from "modules/user/actions/forgot_password";
- import typeof PreviousPageAction from "modules/previous_page/actions/set";
- type Props = {
- location: Location,
- login: LoginAction,
- register: RegisterAction,
- setPreviousPage: PreviousPageAction,
- user: User,
- previous_page: string,
- history: RouterHistory,
- forgotPassword: ForgotPasswordAction,
- resetErrorMessage: () => void,
- };
- type State = {
- email: ?string,
- }
- class Login extends React.Component<Props, State> {
- state = {
- email: null,
- };
- constructor(props: Props) {
- super(props);
- console.log("constructor@@@")
- }
- onLogin: Function = (...args) => {
- const { setPreviousPage, previous_page, history: { push } } = this.props;
- console.log("args[0]", args[0])
- this.setState({ email: args[0] });
- console.log("email000", this.state)
- return (this.props.login(...args): any)
- .then(data => {
- console.log("email000", this.state.email)
- const { logged_in, email_verified } = data.value;
- if (
- logged_in &&
- email_verified &&
- !isEmpty(match("verifyemail", previous_page))
- ) {
- // push("/");
- } else {
- // previous_page && push(previous_page);
- }
- })
- .then(() => {
- console.log("email000", this.state.email)
- // setPreviousPage(`/login?email=${args[0]}`)
- });
- };
- onRegister: Function = () => {
- const { history: { push }, resetErrorMessage } = this.props;
- resetErrorMessage();
- push("/register");
- };
- render() {
- const { user, forgotPassword } = this.props;
- // const { email } = this.state;
- console.log("email111", this.state)
- return (
- <Component
- onLogin={this.onLogin}
- onRegister={this.onRegister}
- onForgotPassword={forgotPassword}
- user={user}
- history={this.props.history}
- // search={{ email: "aaa@sdf.sdf" }}
- search={ this.state.email ? { email: this.state.email } : parse(this.props.location.search) }
- />
- );
- }
- }
- const select = (state, props) => ({
- user: state.user,
- previous_page: state.previous_page,
- });
- const mapDispatchToProps = dispatch =>
- bindActionCreators(
- {
- login: loginAction,
- register: registerAction,
- setPreviousPage: setPreviousPageAction,
- forgotPassword: forgotPasswordAction,
- resetErrorMessage: resetErrorMessageAction,
- },
- dispatch,
- );
- export default connect(select, mapDispatchToProps)(Login);
Add Comment
Please, Sign In to add comment