Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import axios from 'axios';
- export const signupUser = (user, history) => dispatch => {
- axios.post('http://localhost:3000/signup', user)
- console.log(user)
- .then(res => history.push('/login'))
- .catch(err => {
- console.log(err);
- });
- };
- import React, { Component } from 'react';
- import { Link } from 'react-router-dom';
- import { signupUser } from '../actions/authentication';
- import axios from 'axios';
- let today = new Date();
- let date = today.getFullYear()+ '-' + (today.getMonth()+1)+ '-' +today.getDate();
- class Signup extends Component {
- constructor() {
- super()
- this.state = {
- first_name: '',
- last_name: '',
- user_name: '',
- email: '',
- password: '',
- created_on: date,
- isSignedup: false
- }
- this.handleInputChange = this.handleInputChange.bind(this);
- this.handleSubmit = this.handleSubmit.bind(this);
- }
- handleInputChange = (e) => {
- this.setState({
- [e.target.name]: e.target.value
- })
- console.log(this.state);
- }
- handleSubmit = (e) => {
- e.preventDefault();
- const user = {
- first_name: this.state.first_name,
- last_name: this.state.last_name,
- email: this.state.email,
- user_name: this.state.user_name,
- password: this.state.password,
- created_on: this.state.created_on,
- isSignedup: !this.state.isSignedup
- }
- .then(data => {
- console.log(data);
- this.props.history.replace('/login');
- })
- .catch(err => {
- console.log(err);
- })
- }
- handleSubmit = (e) => {
- e.preventDefault();
- axios.post('http://localhost:3000/signup', {
- first_name: this.state.first_name,
- last_name: this.state.last_name,
- email: this.state.email,
- user_name: this.state.user_name,
- password: this.state.password,
- created_on: this.state.created_on,
- isSignedup: !this.state.isSignedup
- })
- .then(data => {
- console.log(data);
- this.props.history.replace('/login');
- })
- .catch(err => {
- console.log(err);
- })
- }
Add Comment
Please, Sign In to add comment