Skip to content

Commit bca6d04

Browse files
sign up into sagas pattern
1 parent 54130a0 commit bca6d04

File tree

13 files changed

+128
-14
lines changed

13 files changed

+128
-14
lines changed

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

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

88
class SignIn extends React.Component {
@@ -19,6 +19,7 @@ class SignIn extends React.Component {
1919
//extraigo el valor y el nombr
2020
const { value, name } = event.target;
2121
this.setState({ [name]: value });
22+
2223
};
2324

2425
handleSubmit = async event => {

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React 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";
5+
import {signUpStart,proob, checkUserSession} from '../../redux/user/user.actions';
6+
import {connect} from 'react-redux';
57

68
class SignUp extends React.Component {
79
constructor() {
@@ -15,9 +17,14 @@ class SignUp extends React.Component {
1517
}
1618

1719
handleSubmit = async event => {
18-
console.log("ESTOY AQUII ESPERANDOTE");
20+
1921
event.preventDefault();
2022
const { displayName, email, password, confirmPassword } = this.state;
23+
const user = {displayName,email,password,confirmPassword};
24+
const {signUpStart} = this.props;
25+
signUpStart(user);
26+
27+
/*
2128
if (password !== confirmPassword) {
2229
alert("passwords don't match");
2330
return;
@@ -39,6 +46,7 @@ class SignUp extends React.Component {
3946
} catch (error) {
4047
console.log(error);
4148
}
49+
*/
4250
};
4351

4452
handleChange = event => {
@@ -96,4 +104,10 @@ class SignUp extends React.Component {
96104
}
97105
}
98106

99-
export default SignUp;
107+
const mapDispatchToProps = dispatch =>({
108+
signUpStart : user => dispatch(signUpStart(user)),
109+
checkUserSession : () => dispatch(checkUserSession())
110+
111+
})
112+
113+
export default connect(null,mapDispatchToProps) (SignUp);

src/redux/cart/cart.actions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ export const deleteItem = item => ({
1818
type: CartActionTypes.DELETE_ITEM,
1919
payload: item
2020
});
21+
22+
export const clearCart = () => ({
23+
type : CartActionTypes.CLEAR_CART
24+
})

src/redux/cart/cart.reducer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ const cartReducer = (state = INITIAL_STATE, action) => {
3636
cartItems: removeItemToCart(state.cartItems, action.payload)
3737
};
3838

39+
case CartActionTypes.CLEAR_CART :
40+
return {
41+
...state,
42+
cartItems : [],
43+
cartHidden : true
44+
}
45+
3946
default:
4047
return state;
4148
}

src/redux/cart/cart.sagas.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {all, call,takeLatest, put} from 'redux-saga/effects';
2+
import UserActionTypes from '../user/user.types';
3+
import {clearCart} from './cart.actions';
4+
5+
6+
export function* clearCartOnSignOut(){
7+
yield put(clearCart());
8+
}
9+
10+
export function* onSignOutSuccess(){
11+
yield takeLatest(UserActionTypes.SIGN_OUT_SUCCESS,clearCartOnSignOut);
12+
}
13+
14+
15+
export function* cartSagas() {
16+
yield(all([call(onSignOutSuccess)]));
17+
}

src/redux/cart/cart.types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const CartActionTypes = {
22
TOGGLE_CART_HIDDEN: "TOGGLE_CART_HIDDEN",
33
ADD_ITEM: "ADD_ITEM",
44
DELETE_ITEM: "DELETE_ITEM",
5-
REMOVE_ITEM: "REMOVE_ITEM"
5+
REMOVE_ITEM: "REMOVE_ITEM",
6+
CLEAR_CART : 'CLEAR_CART'
67
};
78
export default CartActionTypes;

src/redux/root-saga.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {all, call} from 'redux-saga/effects';
2-
import {fetchCollectionsStart} from './shop/shop.sagas';
2+
import { shopSagas} from './shop/shop.sagas';
33
import {userSagas} from "./user/user.sagas";
4+
import {cartSagas} from "./cart/cart.sagas";
5+
46
//Aplica todas las sagas al middleware
57
export default function* rootSaga(){
6-
yield all([call(fetchCollectionsStart),call(userSagas)]);
8+
yield all([call(shopSagas),call(userSagas),call(cartSagas)]);
79
}

src/redux/shop/shop.actions.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ShopActionTypes } from './shop.types';
2-
import { firestore, convertCollectionsSnapshotToMap } from '../../firebase/firebase.utils';
32

43
export const fetchCollectionsStart = ()=> {
54
return {

src/redux/shop/shop.sagas.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {takeLatest,call,put} from 'redux-saga/effects';
1+
import {takeLatest,call,put,all} from 'redux-saga/effects';
22
import {firestore,convertCollectionsSnapshotToMap} from '../../firebase/firebase.utils';
33

44
import ShopActionTypes from "./shop.types";
@@ -33,3 +33,7 @@ export function* fetchCollectionsStart(){
3333
fetchCollecionsAsync);
3434

3535
}
36+
37+
export function* shopSagas() {
38+
yield all([call(fetchCollectionsStart)]);
39+
}

src/redux/user/user.actions.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ export const emailSignInStart = (emailAndPassword) => ({
1212
payload : emailAndPassword
1313
})
1414

15+
16+
1517
export const signInSuccess = (user) => {
16-
console.log("todo marcha bien");
18+
//console.log("todo marcha bien");
1719
const toR = {
1820
type : UserActionTypes.SIGN_IN_SUCCESS,
1921
payload : user,
2022
}
21-
console.log("despacho : ",toR);
23+
//console.log("despacho : ",toR);
2224
return toR;
2325
}
2426

@@ -45,5 +47,21 @@ export const signOutStart = () =>({
4547
type : UserActionTypes.SIGN_OUT_START
4648
})
4749

50+
export const signUpStart = (user) =>({
51+
type : UserActionTypes.SIGNUP_START,
52+
payload : user
53+
})
54+
55+
export const signUpFailure = (error) => ({
56+
type : UserActionTypes.SIGN_UP_FAILURE,
57+
payload : error
58+
})
59+
60+
export const signUpSuccess = (user)=>({
61+
type : UserActionTypes.SIGN_IN_SUCCESS,
62+
payload : user
63+
})
64+
65+
4866

4967

0 commit comments

Comments
 (0)