Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frontend auth is setup, needs close buttons on the forms and styling
- Loading branch information
1 parent
fe0d461
commit dd1b839
Showing
20 changed files
with
4,616 additions
and
8 deletions.
There are no files selected for viewing
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,3 @@ | ||
{ | ||
"esversion": 6 | ||
} |
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,3 +1,20 @@ | ||
// Place all the styles related to the api/sessions controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ | ||
.modal-background { | ||
position: fixed; | ||
top: 0; | ||
bottom: 0; | ||
right: 0; | ||
left: 0; | ||
background: rgba(0, 0, 0, 0.7); | ||
z-index: 10; | ||
} | ||
|
||
.modal-child { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
background-color: white; | ||
} |
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 +1,10 @@ | ||
<% if logged_in? %> | ||
<script type="text/javascript"> | ||
window.currentUser = <%= render( | ||
'api/users/user.json.jbuilder', | ||
user: current_user | ||
).html_safe %> | ||
</script> | ||
<% end %> | ||
|
||
<main id="root"></main> |
File renamed without changes
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,15 @@ | ||
export const OPEN_MODAL = 'OPEN_MODAL'; | ||
export const CLOSE_MODAL = 'CLOSE_MODAL'; | ||
|
||
export const openModal = modal => { | ||
return { | ||
type: OPEN_MODAL, | ||
modal | ||
}; | ||
}; | ||
|
||
export const closeModal = () => { | ||
return { | ||
type: CLOSE_MODAL | ||
}; | ||
}; |
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
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,24 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
const Greeting = props => { | ||
const { currentUser, logout, openModal } = props; | ||
|
||
if (currentUser) { | ||
return ( | ||
<div> | ||
<span>{currentUser.username}</span> | ||
<button onClick={() => logout()}>Log out</button> | ||
</div> | ||
); | ||
} else { | ||
return ( | ||
<div> | ||
<button onClick={() => openModal('login')}>Log in</button> | ||
<button onClick={() => openModal('signup')}>Sign up</button> | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
export default Greeting; |
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 { connect } from 'react-redux'; | ||
import { logout } from '../../actions/session_actions'; | ||
import Greeting from './greeting'; | ||
import { openModal } from '../../actions/modal_actions'; | ||
|
||
const mapStateToProps = state => { | ||
return { | ||
currentUser: state.entities.users[state.session.id] | ||
}; | ||
}; | ||
|
||
const mapDispatchToProps = dispatch => { | ||
return { | ||
logout: () => dispatch(logout()), | ||
openModal: (modal) => dispatch(openModal(modal)) | ||
}; | ||
}; | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(Greeting); |
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,45 @@ | ||
import React from 'react'; | ||
import { closeModal } from '../../actions/modal_actions'; | ||
import { connect } from 'react-redux'; | ||
import LoginFormContainer from '../session/login_form_container'; | ||
import SignupFormContainer from '../session/signup_form_container'; | ||
|
||
const mapStateToProps = state => { | ||
return { | ||
modal: state.ui.modal | ||
}; | ||
}; | ||
|
||
const mapDispatchToProps = dispatch =>{ | ||
return { | ||
closeModal: () => dispatch(closeModal()) | ||
}; | ||
}; | ||
|
||
const Modal = ({ modal, closeModal}) => { | ||
if (!modal) { | ||
return null; | ||
} | ||
|
||
let component; | ||
switch (modal) { | ||
case 'login': | ||
component = <LoginFormContainer />; | ||
break; | ||
case 'signup': | ||
component = <SignupFormContainer />; | ||
break; | ||
default: | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className='modal-background' onClick={closeModal}> | ||
<div className='modal-child' onClick={ e => e.stopPropagation() }> | ||
{component} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(Modal); |
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,22 @@ | ||
import { connect } from 'react-redux'; | ||
import { login } from '../../actions/session_actions'; | ||
import SessionForm from './session_form'; | ||
import { openModal, closeModal } from '../../actions/modal_actions'; | ||
|
||
const mapStateToProps = state => { | ||
return { | ||
errors: state.errors.session, | ||
formType: 'Log in', | ||
otherType: 'Sign up' | ||
}; | ||
}; | ||
|
||
const mapDispatchToProps = dispatch => { | ||
return { | ||
processForm: user => dispatch(login(user)), | ||
closeModal: () => dispatch(closeModal()), | ||
openModal: () => dispatch(openModal('signup')) | ||
}; | ||
}; | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(SessionForm); |
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,58 @@ | ||
import React from 'react'; | ||
|
||
class SessionForm extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state={ | ||
username: '', | ||
password: '' | ||
}; | ||
|
||
this.handleSumbit = this.handleSumbit.bind(this); | ||
} | ||
|
||
update(field) { | ||
return (e) => { | ||
this.setState({[field]: e.currentTarget.value}); | ||
}; | ||
} | ||
|
||
handleSumbit(e) { | ||
e.preventDefault(); | ||
const user = Object.assign({}, this.state); | ||
this.props.processForm(user).then( | ||
() => this.props.history.push('/') | ||
); | ||
} | ||
|
||
render() { | ||
const { | ||
errors, | ||
formType, | ||
otherType, | ||
openModal, | ||
closeModal | ||
} = this.props; | ||
|
||
return ( | ||
<div> | ||
<h1>{formType}</h1> | ||
<form onSubmit={this.handleSumbit}> | ||
<input | ||
type='text' | ||
onChange={this.update('username')} /> | ||
<input | ||
type='password' | ||
onChange={this.update('password')} /> | ||
<input type='submit' value='Submit'/> | ||
</form> | ||
<ul> | ||
{errors} | ||
</ul> | ||
<button onClick={() => openModal()}>{otherType}</button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default SessionForm; |
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,22 @@ | ||
import { connect } from 'react-redux'; | ||
import { signup } from '../../actions/session_actions'; | ||
import SessionForm from './session_form'; | ||
import { openModal, closeModal } from '../../actions/modal_actions'; | ||
|
||
const mapStateToProps = state => { | ||
return { | ||
errors: state.errors.session, | ||
formType: 'Sign up', | ||
otherType: 'Log in' | ||
}; | ||
}; | ||
|
||
const mapDispatchToProps = dispatch => { | ||
return { | ||
processForm: user => dispatch(signup(user)), | ||
closeModal: () => dispatch(closeModal()), | ||
openModal: () => dispatch(openModal('login')) | ||
}; | ||
}; | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(SessionForm); |
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,14 @@ | ||
import { OPEN_MODAL, CLOSE_MODAL } from '../actions/modal_actions'; | ||
|
||
const modalReducer = (state = null, action) => { | ||
switch(action.type) { | ||
case OPEN_MODAL: | ||
return action.modal; | ||
case CLOSE_MODAL: | ||
return null; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default modalReducer; |
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
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,8 @@ | ||
import { combineReducers } from 'redux'; | ||
import modalReducer from './modal_reducer'; | ||
|
||
const uiReducer = combineReducers({ | ||
modal: modalReducer | ||
}); | ||
|
||
export default uiReducer; |
Oops, something went wrong.