Advertisement
Guest User

Untitled

a guest
Sep 9th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. class RegisterForm extends React.Component {
  2.  
  3. constructor(props) {
  4. super(props);
  5. this.state = {
  6. email: '',
  7. username: '',
  8. password: '',
  9. SnackbarOpen: false,
  10. };
  11. }
  12. onSubmit = (event) => {
  13. event.preventDefault();
  14. this.props.register(this.state.email, this.state.username, this.state.password);
  15. }
  16.  
  17. onError(error) {
  18. this.setState({SnackbarOpen: true})
  19. setTimeout(() => {
  20. this.setState({SnackbarOpen: false});
  21. }, 5000);
  22. }
  23.  
  24. render(): with <form>
  25. }
  26.  
  27. const mapStateToProps = (state) => ({
  28. error: state.auth.error,
  29. });
  30.  
  31. const mapDispatchToProps = (dispatch) => ({
  32. register: (email, username, password) => {
  33. dispatch(Actions.register(email, username, password));
  34. }
  35. });
  36.  
  37. export default connect(mapStateToProps, mapDispatchToProps)(RegisterForm);
  38.  
  39. import { Types } from './Actions';
  40. import CognitoService from './CognitoService';
  41.  
  42. function* register(action) {
  43. try {
  44. const result = yield call(CognitoService.register, action);
  45. yield put({ type: Types.registrationSuccess, user: result.user });
  46. } catch(error) {
  47. yield put({ type: Types.registrationFail, error: error.message });
  48. }
  49. }
  50.  
  51. function* authSaga() {
  52. yield takeLatest(Types.register, register);
  53. }
  54.  
  55. export default authSaga;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement