Skip to content

Commit

Permalink
Merge pull request #12 from layshidani/history3
Browse files Browse the repository at this point in the history
Resolves History 3 and 4
  • Loading branch information
layshidani authored Jun 17, 2019
2 parents ab9bc95 + 70b95f8 commit 26fd1c9
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/pages/home.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {Component} from 'react';
import React, { Component } from 'react';
import './home.css'
import Button from '../components/Button'
import '../components/Form.css'
Expand All @@ -17,13 +17,14 @@ class Home extends Component {
email: '',
password: '',
displayName: '',
errorMsg: ''
};
}

handleChange = (event, element) => {
const newState = this.state;
newState[element] = event.target.value
this.setState(newState);
this.setState({ newState });
}

createUser = () => {
Expand All @@ -42,6 +43,8 @@ class Home extends Component {
.then((resp) => {
if (resp) {
this.props.history.push(`/${userType}`)
} else {
this.setState({ errorMsg: this.props.error });
}
})
}
Expand All @@ -50,23 +53,24 @@ class Home extends Component {
const { email, password } = this.state;
this.props.signInWithEmailAndPassword(email, password)
.then((resp) => {
if (!resp) return;
const id = resp.user.uid;
database.collection('users').doc(id).get()
.then((resp) => {
this.props.history.push(`/${resp.data().userType}`)
})
.catch((error) => {
alert(error)
if (resp) {
this.props.history.push(`/${resp.data().userType}`);
} else {
this.setState({ errorMsg: this.props.error });
}
})
})
}

render() {
const errorMsg = this.props.error;
return (
<div className='home'>
<p>
{errorMsg}
{this.state.errorMsg}
</p>
<h1>Entrar</h1>
<input value={this.state.email} type='email'
Expand All @@ -76,7 +80,7 @@ class Home extends Component {
placeholder='Senha'
onChange={(e) => this.handleChange(e, 'password')} />
<Button text='Entrar' className='btn' iconName={faSignInAlt} onClick={this.signIn} />
<hr/>
<hr />
<h1>Criar usuário</h1>
<input value={this.state.displayName}
placeholder='Nome de usuário'
Expand Down

0 comments on commit 26fd1c9

Please sign in to comment.