SHARE
TWEET

Untitled

a guest Dec 13th, 2016 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import SignUpForm from '../SignUpForm/SignUpForm';
  3. import Header from '../Header/Header';
  4. import './SignUpPage.css'
  5. import axios from 'axios';
  6.  
  7. export default class SignUpPage extends React.Component {
  8.  
  9.   constructor() {
  10.     super();
  11.     this.state = {
  12.       user: {
  13.         selectedRole: 'driver',
  14.         email: '',
  15.         phone: '',
  16.         password: ''
  17.       }
  18.     };
  19.     this.handleSignUpSubmit = this.handleSignUpSubmit.bind(this);
  20.   }
  21.  
  22.   handleSignUpSubmit(user) {
  23.  
  24.     (user.selectedRole === 'driver') ?
  25.       delete user.email :
  26.       delete user.phone;
  27.  
  28.     this.setState({
  29.       user: user
  30.     });
  31.  
  32.     const toSend = {
  33.       phone: user.selectedRole === 'driver' ?
  34.         this.state.user.phone :
  35.         this.state.user.email,
  36.       password: this.state.user.password,
  37.     };
  38.  
  39.     console.log(toSend);
  40.    
  41.  
  42.     fetch('http://localhost:7000/auth_user', {
  43.       method: 'POST',
  44.       mode: 'no-cors',
  45.       headers: {
  46.         'Content-Type': 'application/json'
  47.       },
  48.       body: JSON.stringify(toSend)
  49.  
  50.     }).then( (response) => {
  51.         console.log('Request succeeded with', response);
  52.       })
  53.       .catch((error) => {
  54.         console.log('Request failed', error);
  55.       });
  56.   }
  57.  
  58.  
  59.   render() {
  60.     return (
  61.       <div>
  62.         <Header
  63.           text={'Sign up page'}
  64.         />
  65.         <SignUpForm
  66.           user={this.state.user}
  67.           onSubmit={this.handleSignUpSubmit}
  68.         />
  69.       </div>
  70.     );
  71.   }
  72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top