-
Notifications
You must be signed in to change notification settings - Fork 262
/
OAuthSignInButton.js
60 lines (52 loc) · 1.67 KB
/
OAuthSignInButton.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React, { PropTypes } from "react";
import { connect } from "react-redux";
import ButtonLoader from "./ButtonLoader";
import { oAuthSignIn as _oAuthSignIn } from "../../actions/oauth-sign-in";
// hook for rewire
var oAuthSignIn = _oAuthSignIn;
class OAuthSignInButton extends React.Component {
static propTypes = {
provider: PropTypes.string.isRequired,
label: PropTypes.string,
signInParams: PropTypes.object,
children: PropTypes.node,
icon: PropTypes.string
};
static defaultProps = {
signInParams: {},
children: <span>OAuth Sign In</span>
};
getEndpoint () {
return (
this.props.endpoint ||
this.props.auth.getIn(["configure", "currentEndpointKey"]) ||
this.props.auth.getIn(["configure", "defaultEndpointKey"])
);
}
handleClick () {
this.props.dispatch(oAuthSignIn({
provider: this.props.provider,
params: this.props.signInParams,
endpointKey: this.getEndpoint()
}))
.then(this.props.next)
.catch(() => {});
}
render () {
let disabled = this.props.auth.getIn(["user", "isSignedIn"]);
let loading = (
(this.props.auth.getIn(["ui", "oAuthSignInLoadingProvider"]) === this.props.provider) &&
this.props.auth.getIn(["oAuthSignIn", this.getEndpoint(), "loading"])
);
return (
<ButtonLoader
loading={loading}
icon={this.props.icon}
className={this.props.className + ' oauth-sign-in-submit'}
disabled={disabled}
onClick={this.handleClick.bind(this)}
{...this.props} />
);
}
}
export default connect(({auth}) => ({auth}))(OAuthSignInButton);