-
Notifications
You must be signed in to change notification settings - Fork 10
Task 1 #4
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
bmind12
wants to merge
2
commits into
romabelka:master
Choose a base branch
from
bmind12: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
Task 1 #4
Changes from all commits
Commits
Show all changes
2 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
| 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/error-field' | ||
| import { validate as validateEmail } from 'email-validator' | ||
|
|
||
| class NewUserForm extends Component { | ||
| render() { | ||
| return ( | ||
| <div> | ||
| <h3>Create User Form</h3> | ||
| <form onSubmit={this.props.handleSubmit}> | ||
| <Field label="First Name" name="firstName" component={ErrorField} /> | ||
| <Field label="Last Name" name="lastName" component={ErrorField} /> | ||
| <Field label="Email" name="email" component={ErrorField} /> | ||
|
|
||
| <button type="submit">Submit</button> | ||
| <button onClick={this.props.reset}>Reset</button> | ||
| </form> | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| const validate = ({ firstName, lastName, email }) => { | ||
| const errors = {} | ||
|
|
||
| if (!firstName) errors.firstName = 'first name is a required field' | ||
|
|
||
| if (!lastName) errors.lastName = 'last name is a required field' | ||
|
|
||
| if (!email) errors.email = 'email is a required field' | ||
| else if (!validateEmail(email)) errors.email = 'email is invalid' | ||
|
|
||
| return errors | ||
| } | ||
|
|
||
| export default reduxForm({ | ||
| form: 'user', | ||
| validate | ||
| })(NewUserForm) |
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,43 @@ | ||
| import { appName } from '../config' | ||
| import { Record, OrderedMap } from 'immutable' | ||
|
|
||
| /** | ||
| * Constants | ||
| * */ | ||
| export const moduleName = 'user' | ||
| const prefix = `${appName}/${moduleName}` | ||
|
|
||
| export const CREATE_USER = `${prefix}/CREATE_USER` | ||
|
|
||
| /** | ||
| * Reducer | ||
| * */ | ||
| export const ReducerList = Record({ | ||
| users: OrderedMap({}) | ||
| }) | ||
|
|
||
| export default function reducer(state = new ReducerList(), action) { | ||
| const { type, payload } = action | ||
|
|
||
| switch (type) { | ||
| case CREATE_USER: | ||
| return state.setIn(['users', payload.email], payload) | ||
|
|
||
| default: | ||
| return state | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Action Creators | ||
| * */ | ||
| export function createUser(firstName, lastName, email) { | ||
| return { | ||
| type: CREATE_USER, | ||
| payload: { | ||
| firstName, | ||
| lastName, | ||
| } | ||
| } | ||
| } |
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,8 +1,21 @@ | ||
| import { combineReducers } from 'redux' | ||
| import { reducer as form } from 'redux-form' | ||
| import { reducer as formReducer } from 'redux-form' | ||
| import authReducer, { moduleName as authModule } from '../ducks/auth' | ||
| import userReducer, { | ||
| moduleName as userModule, | ||
| CREATE_USER | ||
| } from '../ducks/user' | ||
|
|
||
| export default combineReducers({ | ||
| form, | ||
| form: formReducer.plugin({ | ||
| [userModule]: (state, action) => { | ||
| switch (action.type) { | ||
| case CREATE_USER: | ||
| return undefined | ||
| default: | ||
| return state | ||
| } | ||
| } | ||
| }), | ||
| [authModule]: authReducer | ||
| }) | ||
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,31 @@ | ||
| import React, { Component } from 'react' | ||
| import { Route, NavLink } from 'react-router-dom' | ||
| import { connect } from 'react-redux' | ||
| import NewUserForm from '../components/user/create-user' | ||
| import { createUser } from '../ducks/user' | ||
|
|
||
| class UserRoute extends Component { | ||
| render() { | ||
| return ( | ||
| <div> | ||
| <h1>User page</h1> | ||
| <NavLink to="/user/new-user" activeStyle={{ color: 'red' }}> | ||
| Create a new user | ||
| </NavLink> | ||
|
|
||
| <Route path="/user/new-user" render={this.newUserForm} onSubmit /> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| newUserForm = () => <NewUserForm onSubmit={this.handleSubmit} /> | ||
|
|
||
| handleSubmit = ({ firstName, lastName, email }) => { | ||
| this.props.createUser(firstName, lastName, email) | ||
| } | ||
| } | ||
|
|
||
| export default connect( | ||
| null, | ||
| { createUser } | ||
| )(UserRoute) |
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.
Я бы в user редюсере чистил форму