Skip to content

Commit

Permalink
Shortlogin failure now redirect back to normal login
Browse files Browse the repository at this point in the history
  • Loading branch information
agix committed Feb 14, 2022
1 parent 2afe302 commit 7642ddd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
22 changes: 10 additions & 12 deletions src/components/users/UserConnect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import secretin from 'utils/secretin';

import * as AppUIActions from 'slices/AppUISlice';

Expand All @@ -19,6 +18,7 @@ class UserConnect extends Component {
total: PropTypes.number,
}),
dispatch: PropTypes.func,
showShortpass: PropTypes.bool,
};

constructor(props) {
Expand All @@ -27,13 +27,11 @@ class UserConnect extends Component {
this.onSubmit = this.onSubmit.bind(this);
this.toggleSignup = this.toggleSignup.bind(this);
this.handleChange = this.handleChange.bind(this);
this.hideShortpass = this.hideShortpass.bind(this);

this.state = {
signup: false,
username: '',
password: '',
showShortpass: secretin.canITryShortLogin(),
};
}

Expand Down Expand Up @@ -72,23 +70,16 @@ class UserConnect extends Component {
});
}

hideShortpass() {
this.setState({
showShortpass: false,
});
}

render() {
const { savedUsername, loading, errors } = this.props;

return (
<div className="user-connect">
{this.state.showShortpass ? (
{this.props.showShortpass ? (
<UserConnectShortPass
savedUsername={savedUsername}
loading={loading}
error={errors.shortlogin}
onCancel={this.hideShortpass}
/>
) : (
<UserConnectForm loading={loading} errors={errors} />
Expand All @@ -98,4 +89,11 @@ class UserConnect extends Component {
}
}

export default connect()(UserConnect);
const mapStateToProps = state => {
const { showShortpass } = state.AppUI;
return {
showShortpass,
};
};

export default connect(mapStateToProps)(UserConnect);
1 change: 0 additions & 1 deletion src/components/users/UserConnectShortPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class UserConnectShortPass extends Component {
cancelLabel: 'Cancel',
onAccept: () => {
this.props.dispatch(AppUIActions.disableShortLogin());
return this.props.onCancel();
},
onCancel: () => ({}),
});
Expand Down
15 changes: 12 additions & 3 deletions src/slices/AppUISlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const AppUISlice = createSlice({
errors: {},
currentUser: null,
status: null,
showShortpass: secretin.canITryShortLogin(),
},
reducers: {
loading: _loading,
Expand Down Expand Up @@ -91,6 +92,9 @@ export const AppUISlice = createSlice({
const { error } = action.payload;
state.errors = error;
},
hideShortpass: state => {
state.showShortpass = false;
},
},
});

Expand All @@ -111,6 +115,7 @@ export const {
loginUserFailure,
addSecretToFolderFailure,
removeSecretFromCurrentFolderFailure,
hideShortpass,
} = AppUISlice.actions;

export const disconnectUser = () => dispatch => {
Expand Down Expand Up @@ -255,19 +260,23 @@ export const shortLogin = ({ shortpass }) => dispatch => {
})
);
})
.catch(() =>
.catch(() => {
dispatch(
loginUserFailure({
error: { shortlogin: 'Invalid shortpass' },
})
)
);
);
setTimeout(() => {
dispatch(hideShortpass());
}, 1000);
});
};

export const disableShortLogin = () => dispatch => {
dispatch(loading());
secretin.deactivateShortLogin();
dispatch(disableShortLoginSuccess());
dispatch(hideShortpass());
};

export default AppUISlice.reducer;

0 comments on commit 7642ddd

Please sign in to comment.