-
Notifications
You must be signed in to change notification settings - Fork 21
hw-1 add people page: form and list #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ev-smirnov
wants to merge
1
commit into
romabelka:master
Choose a base branch
from
ev-smirnov:hw-1-ev-smirnov
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import React, { Component } from 'react'; | ||
| import { reduxForm, Field } from 'redux-form'; | ||
| import ErrorField from '../common/ErrorField'; | ||
| import { getEmailFieldError } from '../../helpers'; | ||
|
|
||
| class NewPersonForm extends Component { | ||
| render() { | ||
| return ( | ||
| <div> | ||
| <h2>New Person</h2> | ||
| <form onSubmit={this.props.handleSubmit}> | ||
| <Field name="firstName" label="First Name" component={ErrorField} /> | ||
| <Field name="lastName" label="Last Name" component={ErrorField} /> | ||
| <Field name="email" label="Email" component={ErrorField} /> | ||
| <input type="submit" /> | ||
| </form> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| NewPersonForm.propTypes = {}; | ||
| NewPersonForm.defaultProps = {}; | ||
|
|
||
| const validate = ({ firstName, lastName, email }) => { | ||
| const errors = {} | ||
|
|
||
| if (!firstName) errors.firstName = 'first name is required' | ||
| if (!lastName) errors.lastName = 'last name is required' | ||
|
|
||
| const emailError = getEmailFieldError(email) | ||
| if (emailError) errors.email = emailError | ||
|
|
||
| return errors; | ||
| } | ||
|
|
||
| export default reduxForm({ | ||
| form: 'newPerson', | ||
| validate | ||
| })(NewPersonForm); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import React, { Component } from 'react'; | ||
|
|
||
| class PeopleList extends Component { | ||
| render() { | ||
| const { people } = this.props | ||
| return ( | ||
| <div> | ||
| <h2>People List</h2> | ||
| {people.map(({id, ...rest}) => ( | ||
| <div key={id}>{Object.values(rest).join(' ')}</div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| PeopleList.propTypes = {}; | ||
| PeopleList.defaultProps = {}; | ||
|
|
||
| export default PeopleList; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import React, { Component } from 'react'; | ||
| import { connect } from 'react-redux'; | ||
| import { addPerson, moduleName } from '../../ducks/people'; | ||
| import NewPersonForm from '../people/NewPersonForm'; | ||
| import PeopleList from '../people/PeopleList'; | ||
|
|
||
| class PeoplePage extends Component { | ||
| handleNewPerson = (person) => { | ||
| console.log('---', person); | ||
| this.props.addPerson(person) | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <div> | ||
| <h1>People Page</h1> | ||
| <NewPersonForm onSubmit = {this.handleNewPerson}/> | ||
| <PeopleList people={this.props.people} /> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| PeoplePage.propTypes = {}; | ||
| PeoplePage.defaultProps = {}; | ||
|
|
||
| export default connect(state => ({ | ||
| people: state[moduleName] | ||
| }), {addPerson})(PeoplePage); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,14 @@ | ||
| import firebase from 'firebase' | ||
| import firebase from 'firebase'; | ||
|
|
||
| export const appName = "adv-react"; | ||
|
|
||
| export const appName = "advreact-21-08" | ||
| export const firebaseConfig = { | ||
| apiKey: "AIzaSyDjA6CeIHuni5lNm4ML1b-TSxJltsYUO8g", | ||
| authDomain: `${appName}.firebaseapp.com`, | ||
| databaseURL: `https://${appName}.firebaseio.com`, | ||
| projectId: appName, | ||
| storageBucket: `${appName}.appspot.com`, | ||
| messagingSenderId: "789814589283" | ||
| } | ||
| apiKey: "AIzaSyBX5UU94QPTl4P3WaKwTYU-RLMqSzuThAI", | ||
| authDomain: `${appName}.firebaseapp.com`, | ||
| databaseURL: `https://${appName}.firebaseio.com`, | ||
| projectId: appName, | ||
| storageBucket: `${appName}.appspot.com`, | ||
| messagingSenderId: "825625171274" | ||
| }; | ||
|
|
||
| firebase.initializeApp(firebaseConfig) | ||
| firebase.initializeApp(firebaseConfig); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { appName } from '../config'; | ||
|
|
||
| export const moduleName = 'people' | ||
| export const ADD_PERSON = `${appName}/${moduleName}/ADD_PERSON` | ||
|
|
||
| export default (state = [], action) => { | ||
| const { type, payload } = action | ||
|
|
||
| switch (type) { | ||
| case ADD_PERSON: | ||
| return state.concat({ | ||
| id: Date.now(), | ||
| ...payload.person | ||
| }) | ||
|
|
||
| default: | ||
| return state | ||
| } | ||
| }; | ||
|
|
||
| export const addPerson = (person) => ({ | ||
| type: ADD_PERSON, | ||
| payload: { person } | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import emailValidator from 'email-validator' | ||
|
|
||
| export const getEmailFieldError = (email) => { | ||
| if (!email) return 'email is required' | ||
| else if (!emailValidator.validate(email)) return 'invalid email' | ||
| return null; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это плохая практика, редюсер должен быть чистой функцией