Skip to content

Commit

Permalink
Disable login button while login is in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
tech4him1 committed Oct 26, 2017
1 parent b501db7 commit 7225a12
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export function authenticateUser() {
dispatch(authenticating());
return backend.currentUser()
.then((user) => {
if (user) dispatch(authenticate(user));
if (user) {
dispatch(authenticate(user));
} else {
dispatch(logoutUser());
}
})
.catch((error) => {
dispatch(authError(error));
Expand Down
6 changes: 4 additions & 2 deletions src/backends/git-gateway/AuthenticationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default class AuthenticationPage extends React.Component {

static propTypes = {
onLogin: PropTypes.func.isRequired,
inProgress: PropTypes.bool.isRequired,
};

state = { email: "", password: "", errors: {} };
Expand Down Expand Up @@ -90,7 +91,7 @@ export default class AuthenticationPage extends React.Component {

render() {
const { errors } = this.state;
const { error } = this.props;
const { error, inProgress } = this.props;

if (window.netlifyIdentity) {
return <section className="nc-gitGatewayAuthenticationPage-root">
Expand Down Expand Up @@ -131,8 +132,9 @@ export default class AuthenticationPage extends React.Component {
<Button
className="nc-gitGatewayAuthenticationPage-button"
raised
disabled={inProgress}
>
<Icon type="login" /> Login
<Icon type="login" /> {inProgress ? "Logging in..." : "Login"}
</Button>
</form>
</Card>
Expand Down
5 changes: 4 additions & 1 deletion src/backends/github/AuthenticationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Toast } from '../../components/UI/index';
export default class AuthenticationPage extends React.Component {
static propTypes = {
onLogin: PropTypes.func.isRequired,
inProgress: PropTypes.bool.isRequired,
};

state = {};
Expand All @@ -32,6 +33,7 @@ export default class AuthenticationPage extends React.Component {

render() {
const { loginError } = this.state;
const { inProgress } = this.props;

return (
<section className="nc-githubAuthenticationPage-root">
Expand All @@ -40,9 +42,10 @@ export default class AuthenticationPage extends React.Component {
<Button
className="nc-githubAuthenticationPage-button"
raised
disabled={inProgress}
onClick={this.handleLogin}
>
<Icon type="github" /> Login with GitHub
<Icon type="github" /> {inProgress ? "Logging in..." : "Login with GitHub"}
</Button>
</section>
);
Expand Down
6 changes: 5 additions & 1 deletion src/backends/test-repo/AuthenticationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import logo from "../git-gateway/netlify_logo.svg";
export default class AuthenticationPage extends React.Component {
static propTypes = {
onLogin: PropTypes.func.isRequired,
inProgress: PropTypes.bool.isRequired,
};

state = { email: '' };
Expand All @@ -22,6 +23,8 @@ export default class AuthenticationPage extends React.Component {
};

render() {
const { inProgress } = this.props;

return (<section className="nc-gitGatewayAuthenticationPage-root">
<Card className="nc-gitGatewayAuthenticationPage-card">
<img src={logo} width={100} role="presentation" />
Expand All @@ -36,9 +39,10 @@ export default class AuthenticationPage extends React.Component {
<Button
className="nc-gitGatewayAuthenticationPage-button"
raised
disabled={inProgress}
onClick={this.handleLogin}
>
<Icon type="login" /> Login
<Icon type="login" /> {inProgress ? "Logging in..." : "Login"}
</Button>
</Card>
</section>);
Expand Down
2 changes: 1 addition & 1 deletion src/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class App extends React.Component {
React.createElement(backend.authComponent(), {
onLogin: this.handleLogin.bind(this),
error: auth && auth.get('error'),
isFetching: auth && auth.get('isFetching'),
inProgress: (auth && auth.get('isFetching')) || false,
siteId: this.props.config.getIn(["backend", "site_domain"]),
base_url: this.props.config.getIn(["backend", "base_url"], null)
})
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const auth = (state = null, action) => {
case AUTH_FAILURE:
return Immutable.Map({ error: action.payload.toString() });
case LOGOUT:
return state.remove('user');
return state.remove('user').remove('isFetching');
default:
return state;
}
Expand Down

0 comments on commit 7225a12

Please sign in to comment.