-
Notifications
You must be signed in to change notification settings - Fork 21
Hw1 #6
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
gladk0ff
wants to merge
2
commits into
romabelka:master
Choose a base branch
from
gladk0ff:HW1
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
Hw1 #6
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import React, { Component } from 'react' | ||
| import {reduxForm, Field} from 'redux-form' | ||
| import emailValidator from 'email-validator' | ||
| import ErrorField from '../common/ErrorField' | ||
|
|
||
| class RegisteredUserForm extends Component { | ||
| render() { | ||
| const {handleSubmit} = this.props | ||
| return ( | ||
| <div> | ||
| <h2>Add user form</h2> | ||
| <form onSubmit={handleSubmit}> | ||
| <Field name="firstName" component={ErrorField}/> | ||
| <Field name="lastName" component={ErrorField} /> | ||
| <Field name="email" component={ErrorField} /> | ||
|
|
||
| <div> | ||
| <input type="submit" /> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| const validate = ({firstName,lastName, email}) => { | ||
| //debugger | ||
| let errors = {} | ||
| const validateName = (param,label)=>{ | ||
|
|
||
| if (!param) errors[label] = `${label} is required` | ||
| else if (/^[a-zA-Zа-яА-ЯёЁ]$/.test(param)) errors[label] = `invalid ${label}` | ||
| } | ||
| if (!email) errors.email = 'email is required' | ||
| else if (!emailValidator.validate(email)) errors.email = 'invalid email' | ||
|
|
||
| validateName(lastName,'lastName') | ||
| validateName(firstName,'firstName') | ||
| return errors | ||
| } | ||
|
|
||
|
|
||
| export default reduxForm({ | ||
| form: 'registeredUserForm', | ||
| validate | ||
| })(RegisteredUserForm) | ||
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 {connect} from 'react-redux' | ||
| import {moduleName} from '../../ducks/registeredUser' | ||
|
|
||
|
|
||
| const UserList = (props)=>{ | ||
| console.log(props) | ||
| const _list = props.users.map( | ||
| user=><li>{user.firstName} /{user.lastName}/ {user.email}</li>) | ||
| return ( | ||
| <div> | ||
| <h1>User list</h1> | ||
| {_list} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default connect(store=>({ | ||
| users:store[moduleName].users | ||
| }))(UserList) |
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 |
|---|---|---|
|
|
@@ -12,7 +12,4 @@ function ErrorField(props) { | |
| ) | ||
| } | ||
|
|
||
| ErrorField.propTypes = { | ||
| } | ||
|
|
||
| export default ErrorField | ||
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,17 +1,24 @@ | ||
| import React, { Component } from 'react' | ||
| import {Route, NavLink} from 'react-router-dom' | ||
| import {connect} from 'react-redux' | ||
| import {addUser} from '../../ducks/registeredUser' | ||
| import RegisteredUserForm from '../admin/RegisteredUserForm' | ||
| import UserList from '../admin/UserList' | ||
|
|
||
| class AdminPage extends Component { | ||
| static propTypes = { | ||
|
|
||
| }; | ||
|
|
||
| render() { | ||
| return ( | ||
| <div> | ||
| <h1>Admin Page</h1> | ||
| <NavLink to="/admin/people" activeStyle={{color: 'red'}}>Registered user</NavLink> | ||
| <NavLink to="/admin/users" activeStyle={{color: 'red'}}>User list</NavLink> | ||
| <Route path="/admin/people" render={() => <RegisteredUserForm onSubmit = {this.handleAddUser}/>}/> | ||
| <Route path="/admin/users" render={() => <UserList onSubmit = {this.handleAddUser}/>}/> | ||
| </div> | ||
| ) | ||
| } | ||
| handleAddUser=({email, lastName,firstName}) => this.props.addUser(email, lastName,firstName) | ||
| } | ||
|
|
||
| export default AdminPage | ||
| export default connect(null, {addUser})(AdminPage) |
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,15 @@ | ||
| import firebase from 'firebase' | ||
|
|
||
| export const appName = "advreact-21-08" | ||
| export const appName = 'advreact-277e8'//"advreact-21-08" | ||
| export const firebaseConfig = { | ||
| apiKey: "AIzaSyDjA6CeIHuni5lNm4ML1b-TSxJltsYUO8g", | ||
| //apiKey: "AIzaSyDjA6CeIHuni5lNm4ML1b-TSxJltsYUO8g", | ||
| apiKey: "AIzaSyCw2LF9saF-AiDhbN464gWERWR35m5qm0Q", | ||
| authDomain: `${appName}.firebaseapp.com`, | ||
| databaseURL: `https://${appName}.firebaseio.com`, | ||
| projectId: appName, | ||
| storageBucket: `${appName}.appspot.com`, | ||
| messagingSenderId: "789814589283" | ||
| //messagingSenderId: "789814589283" | ||
| messagingSenderId: "313050002315" | ||
| } | ||
|
|
||
| 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,35 @@ | ||
| import {appName} from '../config' | ||
| import {Record} from 'immutable' | ||
|
|
||
| const ReducerRecord = Record({ | ||
| users: [], | ||
| loading: false | ||
| }) | ||
|
|
||
| export const moduleName = 'registeredUser' | ||
| export const CHANGE_USERS_LIST = `${appName}/${moduleName}/CHANGE_USERS_LIST` | ||
|
|
||
| //console.log('---', ReducerRecord) | ||
| export default function reducer(state = new ReducerRecord(), action) { | ||
| const {type, payload} = action | ||
|
|
||
| switch (type) { | ||
| case CHANGE_USERS_LIST: | ||
| return state | ||
| .set('users', payload) | ||
| default: | ||
| return state | ||
| } | ||
| } | ||
|
|
||
| export function addUser(email, lastName,firstName) { | ||
|
|
||
| return (dispatch,getState) => { | ||
| let _users=[...getState()[moduleName].users] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачем ты делаешь это в AC? Это работа для редюсера |
||
| _users.push({email,lastName,firstName}) | ||
| dispatch({ | ||
| type: CHANGE_USERS_LIST, | ||
| payload:_users | ||
| }) | ||
| } | ||
| } | ||
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.
зачем тебе каждый раз создавать эту функцию? Вынеси в другой скоуп