Skip to content

Commit 2cd1997

Browse files
sign components refactored, now using hooks...
1 parent 891ad1b commit 2cd1997

File tree

4 files changed

+50
-86
lines changed

4 files changed

+50
-86
lines changed

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class App extends React.Component {
3232
}
3333

3434
componentWillUnmount() {
35-
this.unsubscribeFromAuth();
35+
//this.unsubscribeFromAuth();
3636
}
3737

3838
handleRedirect = () => {

src/components/sign-in/sign-in.component.jsx

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,53 @@
1-
import React from "react";
1+
import React,{useState} from "react";
22
import FormInput from "../form-input/form-input.component";
33
import CustomButton from "../custom-button/custom-button.component";
4-
import {googleSignInStart,emailSignInStart,proob} from "../../redux/user/user.actions";
4+
import {googleSignInStart,emailSignInStart} from "../../redux/user/user.actions";
55
import { connect } from "react-redux";
66
import "./sign-in.styles.scss";
77

8-
class SignIn extends React.Component {
8+
const SignIn = ({googleSignInStart,emailSignInStart}) => {
99

10-
constructor(props) {
11-
super(props);
12-
this.state = {
13-
email: "",
14-
password: ""
15-
};
16-
}
10+
const [userCredentials, setUserCredentials] = useState({email:'',password:''});
11+
const {email,password} = userCredentials;
1712

18-
handleChange = event => {
13+
const handleChange = event => {
1914
//extraigo el valor y el nombr
2015
const { value, name } = event.target;
21-
this.setState({ [name]: value });
16+
setUserCredentials({...userCredentials, [name]: value });
2217

2318
};
2419

25-
handleSubmit = async event => {
20+
const handleSubmit = async event => {
2621
event.preventDefault();
27-
const { email, password } = this.state;
28-
const {emailSignInStart} = this.props;
22+
const { email, password } = userCredentials;
2923
emailSignInStart(email,password);
30-
/*try {
31-
await auth.signInWithEmailAndPassword(email, password);
32-
//Limpio la cache del estado actual
33-
this.setState({
34-
email: "",
35-
password: ""
36-
});
37-
} catch (error) {
38-
console.log(error);
39-
}*/
24+
4025
};
4126

27+
4228

4329

44-
render() {
45-
const {googleSignInStart} = this.props;
46-
4730
return (
4831
<div className="sign-in">
4932
<h2>I already have an account</h2>
5033
<span>Sign in with your email and password</span>
5134

52-
<form onSubmit={this.handleSubmit}>
35+
<form onSubmit={handleSubmit}>
5336
<FormInput
54-
handleChange={this.handleChange}
37+
handleChange={handleChange}
5538
name="email"
5639
label="email"
5740
type="email"
58-
value={this.state.email}
41+
value={email}
5942
required
6043
/>
6144

6245
<FormInput
63-
handleChange={this.handleChange}
46+
handleChange={handleChange}
6447
label="password"
6548
name="password"
6649
type="password"
67-
value={this.state.password}
50+
value={password}
6851
required
6952
/>
7053
<div className="buttons">
@@ -77,7 +60,7 @@ class SignIn extends React.Component {
7760
</div>
7861
);
7962
}
80-
}
63+
8164

8265
const mapDispatchToProps = dispatch => ({
8366
googleSignInStart: () => dispatch(googleSignInStart()),

src/components/sing-up/sign-up.component.jsx

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,46 @@
1-
import React from "react";
1+
import React,{useState} from "react";
22
import FormInput from "../form-input/form-input.component";
33
import CustomButton from "../custom-button/custom-button.component";
44
import { auth, createUserProfileDocument } from "../../firebase/firebase.utils";
55
import {signUpStart,proob, checkUserSession} from '../../redux/user/user.actions';
66
import {connect} from 'react-redux';
77

8-
class SignUp extends React.Component {
9-
constructor() {
10-
super();
11-
this.state = {
12-
displayName: "",
13-
email: "",
14-
password: "",
15-
confirmPassword: ""
16-
};
17-
}
8+
const SignUp = ({signUpStart}) => {
9+
const [userCredentials, setUserCredentials] = useState({
10+
displayName: "",
11+
email: "",
12+
password: "",
13+
confirmPassword: ""
14+
});
15+
const { displayName,email,password, confirmPassword } = userCredentials;
16+
1817

19-
handleSubmit = async event => {
18+
const handleSubmit = async event => {
2019

2120
event.preventDefault();
22-
const { displayName, email, password, confirmPassword } = this.state;
23-
const user = {displayName,email,password,confirmPassword};
24-
const {signUpStart} = this.props;
2521
if (password !== confirmPassword) {
2622
alert("passwords don't match");
2723
return;
2824
}
29-
signUpStart(user);
25+
signUpStart(userCredentials);
3026

31-
/*
32-
33-
try {
34-
const { user } = await auth.createUserWithEmailAndPassword(
35-
email,
36-
password
37-
);
38-
//vuelvo a los valores por defecto, no estoy muy seguro para que es esto...
39-
this.setState({
40-
displayName: "",
41-
email: "",
42-
password: "",
43-
confirmPassword: ""
44-
});
45-
} catch (error) {
46-
console.log(error);
47-
}
48-
*/
4927
};
5028

51-
handleChange = event => {
29+
const handleChange = event => {
5230
const { name, value } = event.target;
53-
this.setState({ [name]: value });
31+
setUserCredentials({...userCredentials, [name]: value });
5432
};
5533

56-
render() {
57-
const { displayName, email, password, confirmPassword } = this.state;
58-
return (
34+
return(
5935
<div className="sign-up">
6036
<h2 className="title">I do not have an account</h2>
6137
<span>Sign up with your email and password</span>
62-
<form onSubmit={this.handleSubmit}>
38+
<form onSubmit={handleSubmit}>
6339
<FormInput
6440
type="text"
6541
name="displayName"
6642
value={displayName}
67-
onChange={this.handleChange}
43+
onChange={handleChange}
6844
label="Display Name"
6945
required
7046
/>
@@ -73,7 +49,7 @@ class SignUp extends React.Component {
7349
type="email"
7450
name="email"
7551
value={email}
76-
onChange={this.handleChange}
52+
onChange={handleChange}
7753
label="Email"
7854
required
7955
/>
@@ -82,7 +58,7 @@ class SignUp extends React.Component {
8258
type="password"
8359
name="password"
8460
value={password}
85-
onChange={this.handleChange}
61+
onChange={handleChange}
8662
label="Password"
8763
required
8864
/>
@@ -91,7 +67,7 @@ class SignUp extends React.Component {
9167
type="password"
9268
name="confirmPassword"
9369
value={confirmPassword}
94-
onChange={this.handleChange}
70+
onChange={handleChange}
9571
label="Confirm Password"
9672
required
9773
/>
@@ -101,7 +77,7 @@ class SignUp extends React.Component {
10177
</div>
10278
);
10379
}
104-
}
80+
10581

10682
const mapDispatchToProps = dispatch =>({
10783
signUpStart : user => dispatch(signUpStart(user)),

src/redux/user/user.sagas.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import {signInSuccess,signInFailure, signOutFailure, signOutSuccess, signUpSucce
44
import {auth, googleProvider, createUserProfileDocument,getCurrentUser} from "../../firebase/firebase.utils";
55

66
export function* getSnapshotFromUserAuth(userAuth){
7-
console.log("Me esta llegando : ",userAuth);
8-
7+
98
try{
9+
yield console.log("voy a llamar al metodo con :",userAuth);
1010
const userRef = yield call(createUserProfileDocument,userAuth);
11+
yield console.log("Aparentemente todo salio como esperamos...");
1112
const userSnapshot = yield userRef.get();
13+
console.log("Ahora todo se desmadra");
1214
yield put(signInSuccess({id : userSnapshot.id,...userSnapshot.data}));
13-
14-
1515
}
1616
catch(error){
1717
yield put(signInFailure(error))
@@ -51,12 +51,14 @@ export function* signInWithGoogle(){
5151

5252
export function* signInWithEmail({payload : {email,password}}){
5353
try{
54-
const {user} = auth.signInWithEmailAndPassword(email,password);
54+
const {user} = yield auth.signInWithEmailAndPassword(email,password);
55+
console.log("I am an error");
5556
yield getSnapshotFromUserAuth(user);
5657

5758

5859
}
5960
catch(error){
61+
console.log("NO VEN QUE ESTOY ATAJANDO EL ERROR !!!");
6062
yield put(signInFailure(error))
6163

6264

@@ -104,7 +106,10 @@ export function* onGoogleSignInStart(){
104106
}
105107

106108
export function* onEmailSignInStart(){
107-
yield takeLatest(UserActionTypes.EMAIL_SIGN_IN_START,signInWithEmail)
109+
try{
110+
yield takeLatest(UserActionTypes.EMAIL_SIGN_IN_START,signInWithEmail)
111+
}
112+
catch(error){console.log(error)}
108113
}
109114

110115
export function* onSingUpStart(){

0 commit comments

Comments
 (0)