Guest User

Untitled

a guest
Aug 28th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. // @flow
  2.  
  3. import React from "react";
  4. import { bindActionCreators } from "redux";
  5. import { connect } from "react-redux";
  6. import { isEmpty, match } from "ramda";
  7. import { parse } from "query-string";
  8.  
  9. import Component from "./component";
  10.  
  11. import loginAction from "modules/user/actions/login";
  12. import registerAction from "modules/user/actions/register";
  13. import forgotPasswordAction from "modules/user/actions/forgot_password";
  14. import setPreviousPageAction from "modules/previous_page/actions/set";
  15. import resetErrorMessageAction from "modules/user/actions/reset_error_message";
  16.  
  17. import type { Location } from "react-router";
  18. import type { User } from "modules/user";
  19. import type { RouterHistory } from "react-router";
  20. import typeof LoginAction from "modules/user/actions/login";
  21. import typeof RegisterAction from "modules/user/actions/register";
  22. import typeof ForgotPasswordAction from "modules/user/actions/forgot_password";
  23. import typeof PreviousPageAction from "modules/previous_page/actions/set";
  24.  
  25. type Props = {
  26. location: Location,
  27. login: LoginAction,
  28. register: RegisterAction,
  29. setPreviousPage: PreviousPageAction,
  30. user: User,
  31. previous_page: string,
  32. history: RouterHistory,
  33. forgotPassword: ForgotPasswordAction,
  34. resetErrorMessage: () => void,
  35. };
  36.  
  37. type State = {
  38. email: ?string,
  39. }
  40.  
  41. class Login extends React.Component<Props, State> {
  42. state = {
  43. email: null,
  44. };
  45.  
  46. constructor(props: Props) {
  47. super(props);
  48. console.log("constructor@@@")
  49. }
  50.  
  51. onLogin: Function = (...args) => {
  52. const { setPreviousPage, previous_page, history: { push } } = this.props;
  53.  
  54. console.log("args[0]", args[0])
  55.  
  56. this.setState({ email: args[0] });
  57.  
  58. console.log("email000", this.state)
  59.  
  60.  
  61. return (this.props.login(...args): any)
  62. .then(data => {
  63.  
  64. console.log("email000", this.state.email)
  65.  
  66. const { logged_in, email_verified } = data.value;
  67. if (
  68. logged_in &&
  69. email_verified &&
  70. !isEmpty(match("verifyemail", previous_page))
  71. ) {
  72. // push("/");
  73. } else {
  74. // previous_page && push(previous_page);
  75. }
  76. })
  77. .then(() => {
  78. console.log("email000", this.state.email)
  79.  
  80. // setPreviousPage(`/login?email=${args[0]}`)
  81. });
  82.  
  83.  
  84. };
  85.  
  86. onRegister: Function = () => {
  87. const { history: { push }, resetErrorMessage } = this.props;
  88. resetErrorMessage();
  89. push("/register");
  90. };
  91.  
  92. render() {
  93. const { user, forgotPassword } = this.props;
  94. // const { email } = this.state;
  95.  
  96. console.log("email111", this.state)
  97.  
  98. return (
  99. <Component
  100. onLogin={this.onLogin}
  101. onRegister={this.onRegister}
  102. onForgotPassword={forgotPassword}
  103. user={user}
  104. history={this.props.history}
  105. // search={{ email: "aaa@sdf.sdf" }}
  106. search={ this.state.email ? { email: this.state.email } : parse(this.props.location.search) }
  107. />
  108. );
  109. }
  110. }
  111.  
  112. const select = (state, props) => ({
  113. user: state.user,
  114. previous_page: state.previous_page,
  115. });
  116.  
  117. const mapDispatchToProps = dispatch =>
  118. bindActionCreators(
  119. {
  120. login: loginAction,
  121. register: registerAction,
  122. setPreviousPage: setPreviousPageAction,
  123. forgotPassword: forgotPasswordAction,
  124. resetErrorMessage: resetErrorMessageAction,
  125. },
  126. dispatch,
  127. );
  128.  
  129. export default connect(select, mapDispatchToProps)(Login);
Add Comment
Please, Sign In to add comment