Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
626 changes: 450 additions & 176 deletions .idea/workspace.xml

Large diffs are not rendered by default.

11,041 changes: 11,041 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Route} from 'react-router-dom'
import ProtectedRoute from './common/ProtectedRoute'
import AdminPage from './routes/Admin'
import AuthPage from './routes/Auth'
import PeoplePage from "./routes/People";

class App extends Component {
static propTypes = {
Expand All @@ -15,6 +16,7 @@ class App extends Component {
<h1>Hello world</h1>
<ProtectedRoute path = '/admin' component = {AdminPage}/>
<Route path = '/auth' component = {AuthPage}/>
<Route path = '/people' component = {PeoplePage} />
</div>
)
}
Expand Down
42 changes: 42 additions & 0 deletions src/components/people/PeopleAdd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { Component } from 'react'
import {reduxForm, Field} from 'redux-form'
import emailValidator from 'email-validator'
import ErrorField from '../common/ErrorField'

class PeopleAdd extends Component {

render() {
return (
<div>
<h3>People add</h3>
<form onSubmit={this.props.handleSubmit}>
<Field name='firstName' component={ErrorField} type='text' label='First name' />
<Field name='lastName' component={ErrorField} type='text' label='Last name' />
<Field name='email' component={ErrorField} type='text' label='Email' />

<div>
<input type = 'submit' disabled={this.props.invalid}/>
</div>
</form>
</div>
)
}
}

const validate = ({ firstName, lastName, email }) => {
const errors = {}

if (!firstName) errors.firstName = 'First name is required field'
if (!lastName) errors.lastName = 'Last name is required field'
if (!email) errors.email = 'Email is required field'

if (email && !emailValidator.validate(email)) errors.email = 'Email is not valid'

console.log('-----sadf')

return errors
}

const PeopleAddForm = reduxForm({ form: 'peopleAdd', validate })(PeopleAdd)

export default PeopleAddForm
22 changes: 22 additions & 0 deletions src/components/routes/People.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { Component } from 'react'
import {connect} from 'react-redux'
import {Route} from 'react-router-dom'
import PeopleAdd from '../people/PeopleAdd'
import {peopleAdd} from '../../ducks/people'

class PeoplePage extends Component {

render() {
return (
<div>
<Route path = '/people' exact render = { () => <PeopleAdd onSubmit = {this.handlePeopleAdd} /> } />
</div>
)
}

handlePeopleAdd = (values) => {
this.props.peopleAdd(values)
}
}

export default connect(null, { peopleAdd })(PeoplePage)
6 changes: 3 additions & 3 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import firebase from 'firebase'

export const appName = 'advreact-1610'
export const appName = 'advreact-1610-e107b'

firebase.initializeApp({
apiKey: "AIzaSyB31xpTtp4Jln_hb2kAbE4PGf6Mi8EgLyA",
apiKey: "AIzaSyBxoVzxv_5uMbGSHc_rpqppejalCO0qy3Y",
authDomain: `${appName}.firebaseapp.com`,
databaseURL: `https://${appName}.firebaseio.com`,
projectId: appName,
storageBucket: "",
messagingSenderId: "397157634637"
messagingSenderId: "250560019576"
})
62 changes: 62 additions & 0 deletions src/ducks/people.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {appName} from '../config'
import {Record, OrderedMap} from 'immutable'

/**
* Constants
* */

export const moduleName = 'people'
const prefix = `${appName}/${moduleName}`

const PEOPLE_ADD = `${prefix}/PEOPLE_ADD`

/**
* Reducer
* */

export const ReducerRecord = Record({
entities: new OrderedMap()
})

export const PeopleRecord = Record({
id: null,
firstName: null,
lastName: null,
email: null
})

export default function reducer(state = new ReducerRecord(), action) {
const {type, payload} = action

switch (type) {
case PEOPLE_ADD:
const {id} = payload
return state.setIn(['entities', id], new PeopleRecord(payload))

default:
return state
}
}

/**
* Selectors
* */



/**
* Action Creators
* */

export function peopleAdd(people) {
return (dispatch) => {
const id = (Date.now() + Math.random()).toString()

dispatch({
type: PEOPLE_ADD,
payload: {
...people, id
}
})
}
}
4 changes: 3 additions & 1 deletion src/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})