-
Notifications
You must be signed in to change notification settings - Fork 13
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
HomeTask1 #4
Open
vlapchenko
wants to merge
3
commits into
romabelka:master
Choose a base branch
from
vlapchenko:master
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
HomeTask1 #4
Changes from all commits
Commits
Show all changes
3 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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,33 +1,20 @@ | ||
import React, { Component } from 'react' | ||
import { Route, NavLink } from 'react-router-dom' | ||
import AuthPage from './components/routes/auth' | ||
import AdminPage from './components/routes/admin' | ||
import React, { Component } from "react"; | ||
import { Route, Switch } from "react-router-dom"; | ||
import AuthPage from "./components/routes/auth"; | ||
import AdminPage from "./components/routes/admin"; | ||
|
||
class App extends Component { | ||
static propTypes = { | ||
static propTypes = {}; | ||
|
||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<nav> | ||
<ul> | ||
<li> | ||
<NavLink to="/auth" activeStyle={{ color: 'red'}}>auth</NavLink> | ||
</li> | ||
<li> | ||
<NavLink to="/admin" activeStyle={{ color: 'red'}}>admin</NavLink> | ||
</li> | ||
</ul> | ||
</nav> | ||
<section> | ||
<Route path="/auth" component={AuthPage}/> | ||
<Route path="/admin" component={AdminPage}/> | ||
</section> | ||
</div> | ||
) | ||
} | ||
render() { | ||
return ( | ||
<Switch> | ||
<Route exact path="/" component={AuthPage} /> | ||
<Route path="/auth" component={AuthPage} /> | ||
<Route path="/admin" component={AdminPage} /> | ||
</Switch> | ||
); | ||
} | ||
} | ||
|
||
export default App | ||
export default (App); |
This file contains 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 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,34 @@ | ||
import React, { Component } from 'react' | ||
import { reduxForm, Field } from 'redux-form' | ||
import validator from 'email-validator' | ||
import ErrorField from '../common/error-field' | ||
|
||
class AddParticipantForm extends Component { | ||
render() { | ||
return ( | ||
<div> | ||
<h3>Add Participant</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</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 (!validator.validate(email)) errors.email = 'invalid email' | ||
|
||
return errors | ||
} | ||
|
||
export default reduxForm({ form: 'add-participant', validate })(AddParticipantForm) |
This file contains 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,41 @@ | ||
import React, { Component } from "react"; | ||
import { connect } from "react-redux"; | ||
import { getParticipantList } from '../../ducks/participants'; | ||
|
||
class ParticipantList extends Component { | ||
render() { | ||
const { participantList } = this.props; | ||
return ( | ||
<div> | ||
<h3>Participant List</h3> | ||
<div> | ||
{participantList.map(participant => ( | ||
<div | ||
key={participant.id} | ||
style={{ borderTop: "1px solid rgb(128, 128, 128)" }} | ||
> | ||
<div> | ||
<span>First Name:</span> | ||
<span>{participant.firstName}</span> | ||
</div> | ||
<div> | ||
<span>Last Name:</span> | ||
<span>{participant.lastName}</span> | ||
</div> | ||
<div> | ||
<span>Email:</span> | ||
<span>{participant.email}</span> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = state => ({ | ||
participantList: getParticipantList(state) | ||
}); | ||
|
||
export default connect(mapStateToProps)(ParticipantList); |
This file contains 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,34 @@ | ||
import React, { Component } from 'react' | ||
import {Route, NavLink, Redirect} from 'react-router-dom' | ||
import ParticipantsPage from '../participants' | ||
import {connect} from 'react-redux' | ||
import {getUser, signOut} from '../../../ducks/auth' | ||
|
||
class AdminPage extends Component { | ||
static propTypes = { | ||
|
||
} | ||
|
||
render() { | ||
if (!this.props.user) | ||
return <Redirect to="/auth"/> | ||
return ( | ||
<div> | ||
<h1>Admin</h1> | ||
<div> | ||
<NavLink to="/admin/participants">Participants</NavLink> | ||
<div> | ||
<span onClick={this.handleSignOut} style={{cursor: 'pointer'}}>Sign Out</span> | ||
</div> | ||
</div> | ||
<Route path="/admin/participants" component={ParticipantsPage}/> | ||
</div> | ||
) | ||
} | ||
|
||
handleSignOut = e => { | ||
this.props.dispatch(signOut()) | ||
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. Лучше передай |
||
} | ||
} | ||
|
||
export default AdminPage | ||
const mapStateToProps = state => ({ | ||
user: getUser(state) | ||
}) | ||
|
||
export default connect(mapStateToProps)(AdminPage) |
This file contains 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 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,19 @@ | ||
import React, { Component } from 'react' | ||
import ParticipantList from '../../../components/participants/participant-list' | ||
import AddParticipantForm from '../../../components/participants/add-participant-form' | ||
import { addParticipant } from '../../../ducks/participants' | ||
import { connect } from 'react-redux' | ||
|
||
class ParticipantsPage extends Component { | ||
render() { | ||
return ( | ||
<div> | ||
<h1>Participants</h1> | ||
<AddParticipantForm onSubmit={this.props.addParticipant}/> | ||
<ParticipantList/> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default connect(null, { addParticipant })(ParticipantsPage) |
This file contains 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,15 +1,15 @@ | ||
import firebase from 'firebase/app' | ||
import 'firebase/auth' | ||
|
||
export const appName = 'adv-react-29-01' | ||
export const appName = 'adv-react-29-01-9211b' | ||
|
||
const config = { | ||
apiKey: "AIzaSyD3RIBQ59em4ZGOdRLQpS1velxhcgImTeI", | ||
apiKey: "AIzaSyBM1x37CJgFd5i1z9RZWtHNwZdlhN_YXjo", | ||
authDomain: `${appName}.firebaseapp.com`, | ||
databaseURL: `https://${appName}.firebaseio.com`, | ||
projectId: appName, | ||
storageBucket: `${appName}.appspot.com`, | ||
messagingSenderId: "832921987414" | ||
messagingSenderId: "476036167607" | ||
} | ||
|
||
firebase.initializeApp(config) |
This file contains 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 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,63 @@ | ||
import { Record, List } from "immutable"; | ||
import { appName } from "../config"; | ||
import uuid from "uuid/v4"; | ||
import {reset} from 'redux-form'; | ||
|
||
/** | ||
* Constants | ||
* */ | ||
export const moduleName = "participants"; | ||
const prefix = `${appName}/${moduleName}`; | ||
|
||
export const ADD_PARTICIPANT_START = `${prefix}/ADD_PARTICIPANT_START`; | ||
export const ADD_PARTICIPANT_SUCCESS = `${prefix}/ADD_PARTICIPANT_SUCCESS`; | ||
|
||
/** | ||
* Reducer | ||
* */ | ||
export const ReducerRecord = Record({ | ||
list: List() | ||
}); | ||
|
||
export default function reducer(state = new ReducerRecord(), action) { | ||
const { type, payload } = action; | ||
|
||
switch (type) { | ||
case ADD_PARTICIPANT_SUCCESS: | ||
return state.set("list", state.list.push(payload)); | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
/** | ||
* Selectors | ||
* */ | ||
|
||
export const getParticipantList = state => state.participants.list; | ||
|
||
/** | ||
* Action Creators | ||
* */ | ||
|
||
export function addParticipant({ firstName, lastName, email }) { | ||
return dispatch => { | ||
dispatch({ | ||
type: ADD_PARTICIPANT_START | ||
}); | ||
|
||
// async in future with id from db | ||
var user = { | ||
id: uuid(), | ||
firstName, | ||
lastName, | ||
}; | ||
|
||
dispatch({ | ||
type: ADD_PARTICIPANT_SUCCESS, | ||
payload: user | ||
}); | ||
dispatch(reset('add-participant')); | ||
}; | ||
} |
This file contains 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.
так ты всегда сначала на
auth
редиректить будешь