-
Notifications
You must be signed in to change notification settings - Fork 13
Павлов ДЗ 1 #8
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
VorgSpring
wants to merge
4
commits into
romabelka:master
Choose a base branch
from
VorgSpring:task-1
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
Павлов ДЗ 1 #8
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import React, {Component} from 'react' | ||
| import {reduxForm, Field} from 'redux-form' | ||
| import validator from 'email-validator' | ||
| import ErrorField from "../common/error-field"; | ||
|
|
||
| class AddPersonForm extends Component { | ||
| static propTypes = {} | ||
|
|
||
| render() { | ||
| return ( | ||
| <div> | ||
| <h3>Add Person</h3> | ||
| <form onSubmit={this.props.handleSubmit}> | ||
| <Field name="firstName" component={ErrorField} label="First Name"/> | ||
| <Field name="lastName" component={ErrorField} label="Last Name"/> | ||
| <Field name="email" component={ErrorField} label="Email"/> | ||
| <button type="submit">Add Person</button> | ||
| </form> | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| const validate = ({firstName, lastName, email}) => { | ||
| const errors = {} | ||
| if (!email) errors.email = 'email is a required field' | ||
| else if (!validator.validate(email)) errors.email = 'invalid email' | ||
|
|
||
| if (!firstName) errors.firstName = 'first name is a required field' | ||
| if (!lastName) errors.lastName = 'last name is a required field' | ||
|
|
||
| return errors | ||
| } | ||
|
|
||
| export default reduxForm({ | ||
| form: 'add-person', | ||
| validate | ||
| })(AddPersonForm) |
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 from 'react' | ||
| import Person from './person' | ||
|
|
||
| const PeopleList = ({ people }) => { | ||
| if(people.length === 0) return null | ||
| return ( | ||
| <div> | ||
| <h2>People</h2> | ||
| <ul> | ||
| {people.map(({firstName, lastName, email, id}) => ( | ||
| <li key={id}> | ||
| <Person firstName={firstName} lastName={lastName} email={email}/> | ||
| </li>))} | ||
| </ul> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
|
|
||
| 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,10 @@ | ||
| import React from 'react' | ||
|
|
||
| const Person = ({firstName, lastName, email}) => ( | ||
| <div> | ||
| <div>{`${firstName} ${lastName}`}</div> | ||
| <div>{email}</div> | ||
| </div> | ||
| ) | ||
|
|
||
| export default 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,25 @@ | ||
| import React, { Component } from 'react' | ||
| import { connect } from 'react-redux' | ||
| import AddForm from '../../people/add-person-form' | ||
| import People from '../../../components/people/people-list' | ||
| import { addPerson, peopleListSelector } from '../../../ducks/people' | ||
|
|
||
| class PeoplePage extends Component { | ||
| render() { | ||
| return ( | ||
| <div> | ||
| <h1>People Page</h1> | ||
| <AddForm onSubmit={this.handleAddPerson} /> | ||
| <People people={this.props.people} /> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| handleAddPerson = (person) => this.props.addPerson(person) | ||
| } | ||
|
|
||
| export default connect((state) => { | ||
| return { | ||
| people: peopleListSelector(state) | ||
| } | ||
| }, { 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
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,71 @@ | ||
| import { Record, OrderedMap } from 'immutable' | ||
| import { appName } from '../config' | ||
| import { createSelector } from 'reselect' | ||
| import {reset} from 'redux-form' | ||
|
|
||
| /** | ||
| * Constants | ||
| * */ | ||
| export const moduleName = 'auth' | ||
| const prefix = `${appName}/${moduleName}` | ||
|
|
||
| export const ADD_PERSON = `${prefix}/ADD_PERSON` | ||
|
|
||
| /** | ||
| * Reducer | ||
| * */ | ||
| export const PersonRecord = Record({ | ||
| id: null, | ||
| firstName: null, | ||
| lastName: null, | ||
| email: null | ||
| }) | ||
|
|
||
|
|
||
| const ReducerRecord = Record({ | ||
| entities: new OrderedMap({}), | ||
| }) | ||
|
|
||
| export default function reducer(state = new ReducerRecord(), action) { | ||
| const { type, payload } = action | ||
|
|
||
| switch (type) { | ||
| case ADD_PERSON: | ||
| return state.setIn( | ||
| ['entities', randomId], | ||
| new PersonRecord({ | ||
| ...payload.person, | ||
| id: randomId | ||
| }) | ||
| ) | ||
| default: | ||
| return state | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Selectors | ||
| * */ | ||
|
|
||
| const peopleMapSelector = (state) => state.people.entities | ||
|
|
||
| export const peopleListSelector = createSelector( | ||
| peopleMapSelector, | ||
| (peopleMap) => peopleMap.valueSeq().toArray() | ||
| ); | ||
|
|
||
| /** | ||
| * Action Creators | ||
| * */ | ||
|
|
||
| export const addPerson = (person) => (dispatch) => { | ||
| dispatch({ | ||
| type: ADD_PERSON, | ||
| payload: { person } | ||
| }) | ||
| dispatch(reset('add-person')) | ||
| } | ||
|
|
||
| function randomId() { | ||
| return (Date.now() + Math.random()).toString() | ||
| } |
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
Oops, something went wrong.
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.
Я б делал эту проверку в защищенном роуте, чтоб не разносить логику по разным частям