import React from 'react'; import { connect } from 'react-redux'; import { Redirect, RouteProps } from 'react-router'; import { Button } from 'antd'; import { AppState } from 'store/reducers'; import { authActions } from 'modules/auth'; import { NativeButtonProps } from 'antd/lib/button/button'; import { withRouter } from 'react-router-dom'; import { compose } from 'recompose'; type OwnProps = NativeButtonProps; interface StateProps { user: AppState['auth']['user']; } interface DispatchProps { setAuthForwardLocation: typeof authActions['setAuthForwardLocation']; } type Props = OwnProps & RouteProps & StateProps & DispatchProps; const STATE = { sendToAuth: false, }; type State = typeof STATE; class AuthButton extends React.Component { state: State = { ...STATE }; public render() { const { location, children, loading } = this.props; if (this.state.sendToAuth) { return ; } return ( ); } private handleClick = (e: React.MouseEvent) => { if (!this.props.onClick) { return; } if (this.props.user) { this.props.onClick(e); } else { const { location, setAuthForwardLocation } = this.props; setAuthForwardLocation(location); setTimeout(() => { this.setState({ sendToAuth: true }); }, 200); } }; } const withConnect = connect( (state: AppState) => ({ user: state.auth.user, }), { setAuthForwardLocation: authActions.setAuthForwardLocation }, ); export default compose( withRouter, withConnect, )(AuthButton);