diff --git a/src/components/people/PeopleForm.js b/src/components/people/PeopleForm.js new file mode 100644 index 0000000..d868198 --- /dev/null +++ b/src/components/people/PeopleForm.js @@ -0,0 +1,59 @@ +import React, { Component } from 'react' +import { reduxForm, Field } from 'redux-form' +import ErrorField from '../common/ErrorField' +import emailValidator from 'email-validator' +import { moduleName, addUser} from '../../ducks/people' +import { connect } from 'react-redux' + +class PeopleForm extends Component { + render() { + const { handleSubmit, submitting, reset } = this.props; + return ( +
+

+ Add person +

+
+ + + +
+ +
+ +
+ ); + } +} + +const validate = ({first_name, last_name, email}) => { + const errors = {} + + if (!email) errors.email = 'email is required' + else if (!emailValidator.validate(email)) errors.email = 'invalid email' + + if (!first_name) errors.first_name = 'first_name is required' + + if(!last_name) errors.last_name = 'last_name is required' + + return errors +} + +const mapStateToProps = (state) => ({ + loading: state[moduleName.loading] +}); + +const mapDispatchToProps = (dispatch) => ({ + + addUser: ({first_name, last_name, email}) => dispatch(addUser({first_name, last_name, email})) +}); + +PeopleForm = connect( + mapStateToProps, + mapDispatchToProps +)(PeopleForm); + +export default reduxForm({ + form: 'people', + validate, +})(PeopleForm); \ No newline at end of file diff --git a/src/config.js b/src/config.js index e8d8d78..3d96faa 100644 --- a/src/config.js +++ b/src/config.js @@ -1,13 +1,13 @@ import firebase from 'firebase' -export const appName = "advreact-21-08" +export const appName = "adv-21-08" export const firebaseConfig = { - apiKey: "AIzaSyDjA6CeIHuni5lNm4ML1b-TSxJltsYUO8g", + apiKey: "AIzaSyAFf2xnTf-RQAxK0W_QWKbsf8nEW0vJ66Y", authDomain: `${appName}.firebaseapp.com`, databaseURL: `https://${appName}.firebaseio.com`, projectId: appName, storageBucket: `${appName}.appspot.com`, - messagingSenderId: "789814589283" + messagingSenderId: "497019564518" } firebase.initializeApp(firebaseConfig) \ No newline at end of file diff --git a/src/ducks/auth.js b/src/ducks/auth.js index 2aa11a1..fb3fadc 100644 --- a/src/ducks/auth.js +++ b/src/ducks/auth.js @@ -5,7 +5,7 @@ import {Record} from 'immutable' import {all, cps, call, put, take, takeEvery} from 'redux-saga/effects' import {push} from 'react-router-redux' -export const ReducerRecord = Record({ +const ReducerRecord = Record({ user: null, error: null, loading: false @@ -16,8 +16,8 @@ export const SIGN_UP_REQUEST = `${appName}/${moduleName}/SIGN_UP_REQUEST` export const SIGN_UP_SUCCESS = `${appName}/${moduleName}/SIGN_UP_SUCCESS` export const SIGN_UP_ERROR = `${appName}/${moduleName}/SIGN_UP_ERROR` export const SIGN_IN_REQUEST = `${appName}/${moduleName}/SIGN_IN_REQUEST` -export const SIGN_IN_ERROR = `${appName}/${moduleName}/SIGN_IN_ERROR` export const SIGN_IN_SUCCESS = `${appName}/${moduleName}/SIGN_IN_SUCCESS` +export const SIGN_IN_ERROR = `${appName}/${moduleName}/SIGN_IN_ERROR` export const SIGN_OUT_REQUEST = `${appName}/${moduleName}/SIGN_OUT_REQUEST` export const SIGN_OUT_SUCCESS = `${appName}/${moduleName}/SIGN_OUT_SUCCESS` @@ -27,9 +27,14 @@ export default function reducer(state = new ReducerRecord(), action) { switch (type) { case SIGN_UP_REQUEST: - case SIGN_IN_REQUEST: return state.set('loading', true) + case SIGN_UP_SUCCESS: + return state + .set('loading', false) + .set('user', payload.user) + .set('error', null) + case SIGN_IN_SUCCESS: return state .set('loading', false) @@ -37,6 +42,10 @@ export default function reducer(state = new ReducerRecord(), action) { .set('error', null) case SIGN_UP_ERROR: + return state + .set('loading', false) + .set('error', error) + case SIGN_IN_ERROR: return state .set('loading', false) @@ -75,7 +84,7 @@ export const signUpSaga = function * () { while (true) { const action = yield take(SIGN_UP_REQUEST) - + try { const user = yield call( [auth, auth.createUserWithEmailAndPassword], @@ -96,11 +105,12 @@ export const signUpSaga = function * () { export const signInSaga = function * () { const auth = firebase.auth() - + while (true) { - const action = yield take(SIGN_IN_REQUEST) - + const action = yield take(SIGN_IN_REQUEST); + // debugger try { + //UserCredential const user = yield call( [auth, auth.signInWithEmailAndPassword], action.payload.email, action.payload.password diff --git a/src/redux/index.js b/src/redux/index.js index d0ca1dc..b54db05 100644 --- a/src/redux/index.js +++ b/src/redux/index.js @@ -9,7 +9,7 @@ import rootSaga from './saga' const sagaMiddleware = createSagaMiddleware() const enhancer = applyMiddleware(sagaMiddleware, routerMiddleware(history), logger) -const store = createStore(reducer, enhancer) +const store = createStore(reducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),enhancer) window.store = store sagaMiddleware.run(rootSaga)