diff --git a/.idea/advreact_04_12.iml b/.idea/advreact_04_12.iml new file mode 100644 index 0000000..24643cc --- /dev/null +++ b/.idea/advreact_04_12.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..24eb271 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..be1bc21 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..dc106c3 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,1078 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + authReducer + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + + + + + + + + + + + + + + project + + + true + + + + DIRECTORY + + false + + + + + + + + + 1512909375815 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b9adbae --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# advreact_04_12 \ No newline at end of file diff --git a/admin-panel/README.md b/admin-panel/README.md index f445bfc..246a593 100644 --- a/admin-panel/README.md +++ b/admin-panel/README.md @@ -1,3 +1,3 @@ -##HT1.1 Завести собственный проект на firebase, работать с ним -##HT1.2 Сделать форму для добавлегния людей(firstName, lastName, email) -##HT1.3 Показывать лоадер и ошибки в форме аутентификации \ No newline at end of file +##HT1.1 Завести собственный проект на firebase, работать с ним +++ +##HT1.2 Сделать форму для добавлегния людей(firstName, lastName, email) +++ +##HT1.3 Показывать лоадер и ошибки в форме аутентификации +++ \ No newline at end of file diff --git a/admin-panel/src/components/auth/SignInForm.js b/admin-panel/src/components/auth/SignInForm.js index 3033ef6..b524a14 100644 --- a/admin-panel/src/components/auth/SignInForm.js +++ b/admin-panel/src/components/auth/SignInForm.js @@ -1,5 +1,7 @@ import React, { Component } from 'react' import {reduxForm, Field} from 'redux-form' +import ErrorField from '../common/ErrorField' +import {validate} from './utils' class SignInForm extends Component { static propTypes = { @@ -12,10 +14,10 @@ class SignInForm extends Component {

Sign In

- email: + email:
- password: + password:
@@ -26,5 +28,6 @@ class SignInForm extends Component { } export default reduxForm({ - form: 'auth' + form: 'auth', + validate })(SignInForm) \ No newline at end of file diff --git a/admin-panel/src/components/auth/SignUpForm.js b/admin-panel/src/components/auth/SignUpForm.js index d8e9a85..2c31413 100644 --- a/admin-panel/src/components/auth/SignUpForm.js +++ b/admin-panel/src/components/auth/SignUpForm.js @@ -1,7 +1,7 @@ import React, { Component } from 'react' import {reduxForm, Field} from 'redux-form' -import validator from 'email-validator' import ErrorField from '../common/ErrorField' +import {validate} from './utils' class SignUpForm extends Component { static propTypes = { @@ -27,18 +27,6 @@ class SignUpForm extends Component { } } -const validate = ({ email, password }) => { - const errors = {} - - if (!email) errors.email = 'email is a required field' - if (email && !validator.validate(email)) errors.email = 'incorrect email format' - - if (!password) errors.password = 'password is a required field' - if (password && password.length < 8) errors.password = 'password is to short' - - return errors -} - export default reduxForm({ form: 'auth', validate diff --git a/admin-panel/src/components/auth/utils.js b/admin-panel/src/components/auth/utils.js new file mode 100644 index 0000000..01a7f1a --- /dev/null +++ b/admin-panel/src/components/auth/utils.js @@ -0,0 +1,13 @@ +import validator from 'email-validator' + +export const validate = ({ email, password }) => { + const errors = {} + + if (!email) errors.email = 'email is a required field' + if (email && !validator.validate(email)) errors.email = 'incorrect email format' + + if (!password) errors.password = 'password is a required field' + if (password && password.length < 8) errors.password = 'password is to short' + + return errors +} diff --git a/admin-panel/src/components/people/PeopleForm.js b/admin-panel/src/components/people/PeopleForm.js new file mode 100644 index 0000000..9ce628c --- /dev/null +++ b/admin-panel/src/components/people/PeopleForm.js @@ -0,0 +1,44 @@ +import React, {Component} from 'react' +import {reduxForm, Field} from 'redux-form' +import validator from 'email-validator' +import ErrorField from '../common/ErrorField' + +class PeopleForm extends Component { + render() { + return ( +
+
+
+ First-name: +
+
+ Last-name: +
+
+ Email: +
+ +
+ +
+ ) + } +} + +const validate = ({firstName, lastName, email}) => { + const errors = {} + + if (!firstName) errors.firstName = 'First name is required' + + if (!lastName) errors.lastName = 'Last name is required' + + if (!email) errors.email = 'email is a required field' + if (email && !validator.validate(email)) errors.email = 'incorrect email format' + + return errors +} + +export default reduxForm({ + form: 'people', + validate +})(PeopleForm) diff --git a/admin-panel/src/components/routes/Admin.js b/admin-panel/src/components/routes/Admin.js index 952248e..65bb71f 100644 --- a/admin-panel/src/components/routes/Admin.js +++ b/admin-panel/src/components/routes/Admin.js @@ -1,4 +1,5 @@ import React, { Component } from 'react' +import People from './people' class Admin extends Component { static propTypes = { @@ -9,6 +10,7 @@ class Admin extends Component { return (

Admin Page

+
) } diff --git a/admin-panel/src/components/routes/auth/index.js b/admin-panel/src/components/routes/auth/index.js index 91c9bab..3454716 100644 --- a/admin-panel/src/components/routes/auth/index.js +++ b/admin-panel/src/components/routes/auth/index.js @@ -1,7 +1,7 @@ import React, { Component } from 'react' import {Route, NavLink} from 'react-router-dom' import {connect} from 'react-redux' -import {signIn, signUp} from '../../../ducks/auth' +import {signIn, signUp, loadingSelector} from '../../../ducks/auth' import SignInForm from '../../auth/SignInForm' import SignUpForm from '../../auth/SignUpForm' @@ -11,6 +11,8 @@ class Auth extends Component { }; render() { + const {loading} = this.props + return (

Auth page

@@ -18,6 +20,7 @@ class Auth extends Component {
  • Sign In
  • Sign Up
  • + {loading &&

    Loader...

    } } /> } />
    @@ -29,4 +32,4 @@ class Auth extends Component { } -export default connect(null, { signIn, signUp })(Auth) \ No newline at end of file +export default connect(loadingSelector, { signIn, signUp })(Auth) \ No newline at end of file diff --git a/admin-panel/src/components/routes/people/index.js b/admin-panel/src/components/routes/people/index.js new file mode 100644 index 0000000..d23ffa7 --- /dev/null +++ b/admin-panel/src/components/routes/people/index.js @@ -0,0 +1,24 @@ +import React, { Component } from 'react' +import {connect} from 'react-redux' +import {addPerson} from '../../../ducks/people' +import PeopleForm from '../../people/PeopleForm' + +class People extends Component { + static propTypes = { + + }; + + render() { + return ( +
    +

    Add person for the upcoming event here:

    + +
    + ) + } + + onAddPerson = ({ firstName, lastName, email }) => this.props.addPerson(firstName, lastName, email) + +} + +export default connect(null, { addPerson })(People) \ No newline at end of file diff --git a/admin-panel/src/config.js b/admin-panel/src/config.js index 65bba00..24253f6 100644 --- a/admin-panel/src/config.js +++ b/admin-panel/src/config.js @@ -1,14 +1,14 @@ import firebase from 'firebase' -export const appName = 'advreact-04-12' +export const appName = 'advreact-04-12-66c36' const config = { - apiKey: "AIzaSyCmDWlgYIhtEr1pWjgKYds3iXKWBl9wbjE", + apiKey: "AIzaSyDo7dedi23qFyb0vCT_KgYjhgzlf9itVxI", authDomain: `${appName}.firebaseapp.com`, databaseURL: `https://${appName}.firebaseio.com`, projectId: appName, storageBucket: "", - messagingSenderId: "95255462276" + messagingSenderId: "590592894041" } firebase.initializeApp(config) \ No newline at end of file diff --git a/admin-panel/src/ducks/auth.js b/admin-panel/src/ducks/auth.js index f031871..169c8a4 100644 --- a/admin-panel/src/ducks/auth.js +++ b/admin-panel/src/ducks/auth.js @@ -45,6 +45,7 @@ export default function reducer(state = new ReducerRecord(), action) { * */ export const userSelector = state => state[moduleName].user +export const loadingSelector = state => ({loading: state[moduleName].loading}) /** * Action Creators diff --git a/admin-panel/src/ducks/people.js b/admin-panel/src/ducks/people.js new file mode 100644 index 0000000..2d392db --- /dev/null +++ b/admin-panel/src/ducks/people.js @@ -0,0 +1,66 @@ +//import {all} from 'redux-saga/effects' +import {appName} from '../config' +import {Record, List} from 'immutable' +import {reset} from 'redux-form' + +/** + * Constants + * */ +export const moduleName = 'people' +const prefix = `${appName}/${moduleName}` + +export const ADD_PERSON = `${prefix}/ADD_PERSON` + + +/** + * Reducer + * */ +export const PersonRecord = Record({ + firstName: null, + lastName: null, + email: null, +}) + +export default function reducer(state = new List(), action) { + const { type, payload } = action + + switch (type) { + case ADD_PERSON: { + const { firstName, lastName, email } = payload + return state.push(new PersonRecord({firstName, lastName, email})) + } + + + default: + return state + } +} + +/** + * Selectors + * */ + +/** + * Action Creators + * */ + +export function addPerson(firstName, lastName, email) { + return (dispatch) => { + dispatch({ + type: ADD_PERSON, + payload: {firstName, lastName, email} + }) + + dispatch(reset('people')) + } +} + +/** + * Sagas + * */ + +//export function* saga() { +// yield all([ +// +// ]) +//} \ No newline at end of file diff --git a/admin-panel/src/redux/index.js b/admin-panel/src/redux/index.js index 1a37261..b8d5bcb 100644 --- a/admin-panel/src/redux/index.js +++ b/admin-panel/src/redux/index.js @@ -1,11 +1,14 @@ -import {createStore, applyMiddleware} from 'redux' +import {createStore, applyMiddleware, compose} from 'redux' import logger from 'redux-logger' import {routerMiddleware} from 'react-router-redux' import thunk from 'redux-thunk' import reducer from './reducer' import history from '../history' -const store = createStore(reducer, applyMiddleware(thunk, routerMiddleware(history), logger)) +const store = createStore(reducer, compose( + applyMiddleware(thunk, routerMiddleware(history), logger), + window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() +)) //dev only window.store = store diff --git a/admin-panel/src/redux/reducer.js b/admin-panel/src/redux/reducer.js index 34143fe..cc6e0aa 100644 --- a/admin-panel/src/redux/reducer.js +++ b/admin-panel/src/redux/reducer.js @@ -2,8 +2,10 @@ import {combineReducers} from 'redux' import {routerReducer as router} from 'react-router-redux' import {reducer as form} from 'redux-form' import authReducer, {moduleName as authModule} from '../ducks/auth' +import peopleReducer, {moduleName as peopleModule} from '../ducks/people' export default combineReducers({ router, form, - [authModule]: authReducer + [authModule]: authReducer, + [peopleModule]: peopleReducer }) \ No newline at end of file