Guest User

Untitled

a guest
Feb 13th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. import axios from 'axios';
  2.  
  3. export const signupUser = (user, history) => dispatch => {
  4. axios.post('http://localhost:3000/signup', user)
  5. console.log(user)
  6. .then(res => history.push('/login'))
  7. .catch(err => {
  8. console.log(err);
  9.  
  10. });
  11. };
  12.  
  13. import React, { Component } from 'react';
  14. import { Link } from 'react-router-dom';
  15. import { signupUser } from '../actions/authentication';
  16. import axios from 'axios';
  17.  
  18. let today = new Date();
  19. let date = today.getFullYear()+ '-' + (today.getMonth()+1)+ '-' +today.getDate();
  20.  
  21.  
  22.  
  23.  
  24. class Signup extends Component {
  25.  
  26. constructor() {
  27. super()
  28. this.state = {
  29. first_name: '',
  30. last_name: '',
  31. user_name: '',
  32. email: '',
  33. password: '',
  34. created_on: date,
  35. isSignedup: false
  36. }
  37.  
  38. this.handleInputChange = this.handleInputChange.bind(this);
  39.  
  40. this.handleSubmit = this.handleSubmit.bind(this);
  41. }
  42.  
  43. handleInputChange = (e) => {
  44. this.setState({
  45. [e.target.name]: e.target.value
  46. })
  47. console.log(this.state);
  48. }
  49.  
  50. handleSubmit = (e) => {
  51. e.preventDefault();
  52.  
  53. const user = {
  54.  
  55. first_name: this.state.first_name,
  56. last_name: this.state.last_name,
  57. email: this.state.email,
  58. user_name: this.state.user_name,
  59. password: this.state.password,
  60. created_on: this.state.created_on,
  61. isSignedup: !this.state.isSignedup
  62. }
  63. .then(data => {
  64. console.log(data);
  65. this.props.history.replace('/login');
  66. })
  67. .catch(err => {
  68. console.log(err);
  69. })
  70. }
  71.  
  72. handleSubmit = (e) => {
  73. e.preventDefault();
  74.  
  75. axios.post('http://localhost:3000/signup', {
  76.  
  77. first_name: this.state.first_name,
  78. last_name: this.state.last_name,
  79. email: this.state.email,
  80. user_name: this.state.user_name,
  81. password: this.state.password,
  82. created_on: this.state.created_on,
  83. isSignedup: !this.state.isSignedup
  84. })
  85. .then(data => {
  86. console.log(data);
  87. this.props.history.replace('/login');
  88. })
  89. .catch(err => {
  90. console.log(err);
  91. })
  92. }
Add Comment
Please, Sign In to add comment