Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RegisterForm extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- email: '',
- username: '',
- password: '',
- SnackbarOpen: false,
- };
- }
- onSubmit = (event) => {
- event.preventDefault();
- this.props.register(this.state.email, this.state.username, this.state.password);
- }
- onError(error) {
- this.setState({SnackbarOpen: true})
- setTimeout(() => {
- this.setState({SnackbarOpen: false});
- }, 5000);
- }
- render(): with <form>
- }
- const mapStateToProps = (state) => ({
- error: state.auth.error,
- });
- const mapDispatchToProps = (dispatch) => ({
- register: (email, username, password) => {
- dispatch(Actions.register(email, username, password));
- }
- });
- export default connect(mapStateToProps, mapDispatchToProps)(RegisterForm);
- import { Types } from './Actions';
- import CognitoService from './CognitoService';
- function* register(action) {
- try {
- const result = yield call(CognitoService.register, action);
- yield put({ type: Types.registrationSuccess, user: result.user });
- } catch(error) {
- yield put({ type: Types.registrationFail, error: error.message });
- }
- }
- function* authSaga() {
- yield takeLatest(Types.register, register);
- }
- export default authSaga;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement