Skip to content

Commit

Permalink
STEP 1: fixing issue for sign up and login modal
Browse files Browse the repository at this point in the history
  • Loading branch information
realsoftdev committed Jul 19, 2017
1 parent d95c593 commit 57402c7
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Intl/localizationData/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default {
messages: {
siteTitle: 'MERN Starter Blog',
addPost: 'Add Post',
signUp: 'Sign up',
signup: 'Sign up',
login: 'Login',
switchLanguage: 'Switch Language',
twitterMessage: 'We are on Twitter',
Expand Down
2 changes: 1 addition & 1 deletion Intl/localizationData/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default {
messages: {
siteTitle: 'MERN blog de démarrage',
addPost: 'Ajouter Poster',
signUp: 'Sinscrire',
signup: 'Sinscrire',
login: 'Sidentifier',
switchLanguage: 'Changer de langue',
twitterMessage: 'Nous sommes sur Twitter',
Expand Down
24 changes: 22 additions & 2 deletions client/modules/App/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { showSignupModal, showLoginModal } from '../Auth/AuthActions';

// Import Style
import styles from './App.css';
Expand All @@ -10,6 +11,9 @@ import DevTools from './components/DevTools';
import Header from './components/Header/Header';
import Footer from './components/Footer/Footer';

import SignupModal from '../Auth/components/SignupModal';
import LoginModal from '../Auth/components/LoginModal';

// Import Actions
import { toggleAddPost } from './AppActions';
import { switchLanguage } from '../../modules/Intl/IntlActions';
Expand All @@ -28,6 +32,14 @@ export class App extends Component {
this.props.dispatch(toggleAddPost());
};

showLoginModal = () => {
this.props.dispatch(showLoginModal());
}

showSignupModal = () => {
this.props.dispatch(showSignupModal());
}

render() {
return (
<div>
Expand All @@ -52,9 +64,15 @@ export class App extends Component {
switchLanguage={lang => this.props.dispatch(switchLanguage(lang))}
intl={this.props.intl}
toggleAddPost={this.toggleAddPostSection}
isAuthenticated = {this.props.isAuthenticated}
showLoginModal = {this.showLoginModal}
showSignupModal = {this.showSignupModal}
/>
<SignupModal />
<LoginModal />
<div className={styles.container}>
{this.props.children}

</div>
<Footer />
</div>
Expand All @@ -67,13 +85,15 @@ App.propTypes = {
children: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
isAuthenticated: PropTypes.bool.isRequired
};

// Retrieve data from store as props
function mapStateToProps(store) {
function mapStoreToProps(store) {
return {
intl: store.intl,
isAuthenticated: store.auth.isAuthenticated
};
}

export default connect(mapStateToProps)(App);
export default connect(mapStoreToProps)(App);
9 changes: 8 additions & 1 deletion client/modules/App/components/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ export function Header(props, context) {
: null
}
{

!props.isAuthenticated &&
<a className={styles['add-post-button']} href="#" onClick={props.showLoginModal}><FormattedMessage id="login" /></a>
}
{
!props.isAuthenticated &&
<a className={styles['add-post-button']} href="#" onClick={props.showSignupModal}><FormattedMessage id="signup" /></a>
}
</div>
</div>
Expand All @@ -42,6 +47,8 @@ Header.contextTypes = {
Header.propTypes = {
toggleAddPost: PropTypes.func.isRequired,
switchLanguage: PropTypes.func.isRequired,
showLoginModal: PropTypes.func.isRequired,
showSignupModal: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
};

Expand Down
8 changes: 4 additions & 4 deletions client/modules/Auth/AuthActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function login(user) {
email: user.email,
passsword: user.password
},
}).then(res => dispatch(loggedIn({ email: res.email, token: res.token }));
}).then(res => dispatch(loggedIn({ email: res.email, token: res.token })));
};
}

Expand All @@ -27,17 +27,17 @@ export function signup(user) {
first_name: user.first_name,
last_name: user.last_name,
},
}).then(res => dispatch(hideSignUpModal()));
}).then(res => dispatch(hideSignupModal()));
};
}

export function hideSignUpModal() {
export function hideSignupModal() {
return {
type: HIDE_SIGNUP_MODAL
}
}

export function showSignUpModal() {
export function showSignupModal() {
return {
type: SHOW_SIGNUP_MODAL
}
Expand Down
12 changes: 8 additions & 4 deletions client/modules/Auth/AuthReducer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { LOGGED_IN } from './AuthReducer'
import { LOGGED_IN, SHOW_SIGNUP_MODAL, HIDE_SIGNUP_MODAL, SHOW_LOGIN_MODAL, HIDE_LOGIN_MODAL } from './AuthActions'

const initialState = {
isAuthenticated: false,
user: null,
isShowLoginModal: false,
isShowSignUpModal: false
isShowSignupModal: false
};

const AuthReducer = (state = initialState, action) => {
Expand Down Expand Up @@ -36,6 +36,10 @@ const AuthReducer = (state = initialState, action) => {
}
};

export isShowLoginModal = state => state.isShowLoginModal;
export const isShowLoginModal = state => state.auth.isShowLoginModal;

export isShowSignUpModal = state => state.isShowSignUpModal;
export const isShowSignupModal = state => state.auth.isShowSignupModal;

export const isAuthenticated = state => state.auth.isAuthenticated;

export default AuthReducer;
17 changes: 9 additions & 8 deletions client/modules/Auth/components/LoginModal.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { Component, PropTypes } from 'react';
import Modal from 'react-bootstrap/lib/Modal'
import { connect } from 'react-redux';

import { hideLoginModal } from '../AuthActions';
import { isShowLoginModal } from '../AuthReducer';

export class LoginModal extends Component {

hideModal = () => {
this.props.dispatch(hideLoginModal();
this.props.dispatch(hideLoginModal());
};

login = () => {
Expand All @@ -22,18 +23,18 @@ export class LoginModal extends Component {
render() {
return (
<Modal
show={ this.props.isShowLoginModal }
show={ this.props.isShowModal }
aria-labelledby='contained-modal-title'>
<Modal.Header>
<Modal.title>Sign Up</Modal.title>
</Modal.Header>
<Modal.body>
<div onBlur={this.props.hideModal}>
<input type='text' name='first_name' ref='first_name'>
<input type='text' name='last_name' ref='last_name'>
<input type='text' name='email' ref='email'>
<input type='password' name='password' ref='password'>
<a href='javascript:void(0);' onClick={this.props.signup} >Sign Up</a>
<div onBlur={this.hideModal}>
<input type='text' name='first_name' ref='first_name' />
<input type='text' name='last_name' ref='last_name' />
<input type='text' name='email' ref='email' />
<input type='password' name='password' ref='password' />
<a href='javascript:void(0);' onClick={this.login} >Sign Up</a>
</div>
</Modal.body>
</Modal>
Expand Down
33 changes: 16 additions & 17 deletions client/modules/Auth/components/SignupModal.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { Component, PropTypes } from 'react';
import Modal from 'react-bootstrap/lib/Modal'

import { hideSignUpModal, signup } from '../AuthActions';
import { isShowSignUpModal } from '../AuthReducer';
import { connect } from 'react-redux';
import { hideSignupModal, signup } from '../AuthActions';
import { isShowSignupModal } from '../AuthReducer';

export class SignUpModal extends Component {
export class SignupModal extends Component {

hideModal = () => {
this.props.dispatch(hideSignUpModal();
this.props.dispatch(hideSignupModal());
};

signup = () => {
Expand All @@ -23,38 +24,36 @@ export class SignUpModal extends Component {
}));
};

render() {
render = () => {
return (
<Modal
show={ this.props.isShowSignUpModal }
show={ this.props.isShowModal }
aria-labelledby='contained-modal-title'>
<Modal.Header>
<Modal.title>Sign Up</Modal.title>
</Modal.Header>
<Modal.body>
<div onBlur={this.props.hideModal}>
<input type='text' name='first_name' ref='first_name'>
<input type='text' name='last_name' ref='last_name'>
<input type='text' name='email' ref='email'>
<input type='password' name='password' ref='password'>
<a href='javascript:void(0);' onClick={this.props.signup} >Sign Up</a>
<div onBlur={this.hideModal}>
<input type='text' name='first_name' ref='first_name' />
<input type='text' name='last_name' ref='last_name' />
<input type='text' name='email' ref='email' />
<input type='password' name='password' ref='password' />
<a href='javascript:void(0);' onClick={this.signup} >Sign Up</a>
</div>
</Modal.body>
</Modal>
);
}
}

SignUpModal.propTypes = {
hideModal: PropTypes.func.isRequired,
signup: PropTypes.func.isRequired,
SignupModal.propTypes = {
isShowModal: PropTypes.bool.isRequired,
};

function mapStateToProps(state) {
return {
isShowModal: isShowSignUpModal(state)
isShowModal: isShowSignupModal(state)
};
}

export default connect(mapStateToProps)(SignUpModal);
export default connect(mapStateToProps)(SignupModal);
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions client/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { combineReducers } from 'redux';

// Import Reducers
import app from './modules/App/AppReducer';
import auth from './modules/Auth/AuthReducer';
import posts from './modules/Post/PostReducer';
import intl from './modules/Intl/IntlReducer';

// Combine all reducers into one root reducer
export default combineReducers({
app,
auth,
posts,
intl,
});

0 comments on commit 57402c7

Please sign in to comment.