Ivan - STAFF LOGIN - Add session architecture for staff login [skip ci]
This commit is contained in:
parent
e3650f146f
commit
3936e772d7
|
@ -12,7 +12,7 @@ export default {
|
|||
path: '/user/login',
|
||||
data: loginData
|
||||
}).then((result) => {
|
||||
store.dispatch(this.getUserData(result.data.userId, result.data.token));
|
||||
store.dispatch(this.getUserData(result.data.userId, result.data.token, result.data.staff));
|
||||
|
||||
return result;
|
||||
})
|
||||
|
@ -49,7 +49,7 @@ export default {
|
|||
};
|
||||
},
|
||||
|
||||
getUserData(userId, token) {
|
||||
getUserData(userId, token, staff) {
|
||||
let data = {};
|
||||
|
||||
if (userId && token) {
|
||||
|
@ -62,7 +62,7 @@ export default {
|
|||
return {
|
||||
type: 'USER_DATA',
|
||||
payload: API.call({
|
||||
path: '/user/get',
|
||||
path: (staff) ? '/staff/get' : '/user/get',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
|
|
@ -44,7 +44,9 @@ class App extends React.Component {
|
|||
const validations = {
|
||||
languageChanged: props.config.language !== this.props.config.language,
|
||||
loggedIn: !_.includes(props.location.pathname, '/dashboard') && props.session.logged,
|
||||
loggedOut: _.includes(props.location.pathname, '/dashboard') && !props.session.logged
|
||||
loggedOut: _.includes(props.location.pathname, '/dashboard') && !props.session.logged,
|
||||
loggedInStaff: !_.includes(props.location.pathname, '/admin/panel') && props.session.staff,
|
||||
loggedOutStaff: _.includes(props.location.pathname, '/admin/panel') && !props.session.logged
|
||||
};
|
||||
|
||||
if (validations.languageChanged) {
|
||||
|
@ -55,8 +57,14 @@ class App extends React.Component {
|
|||
browserHistory.push('/');
|
||||
}
|
||||
|
||||
if (validations.loggedIn) {
|
||||
if (validations.loggedOutStaff) {
|
||||
browserHistory.push('/admin');
|
||||
}
|
||||
|
||||
if (validations.loggedIn && !props.session.staff) {
|
||||
browserHistory.push('/dashboard');
|
||||
} else if(validations.loggedInStaff) {
|
||||
browserHistory.push('/admin/panel');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,25 @@
|
|||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
import {connect} from 'react-redux';
|
||||
|
||||
import i18n from 'lib-app/i18n';
|
||||
import API from 'lib-app/api-call';
|
||||
import SessionActions from 'actions/session-actions';
|
||||
|
||||
import Form from 'core-components/form';
|
||||
import FormField from 'core-components/form-field';
|
||||
import SubmitButton from 'core-components/submit-button';
|
||||
|
||||
class AdminLoginPage extends React.Component {
|
||||
render(){
|
||||
render() {
|
||||
return (
|
||||
<div className="admin-login-page">
|
||||
<div className="admin-login-page__content">
|
||||
<div className="admin-login-page__image"><img width="100%" src="/images/logo.png" alt="OpenSupports Admin Panel"/></div>
|
||||
<div className="admin-login-page__login-form">
|
||||
<Form onSubmit={this.onSubmit.bind(this)}>
|
||||
<Form onSubmit={this.onSubmit.bind(this)} loading={this.props.session.pending}>
|
||||
<FormField name="email" label={i18n('EMAIL')} field="input" validation="EMAIL" fieldProps={{size:'large'}} required />
|
||||
<FormField name="password" label={i18n('PASSWORD')} field="input" validation="PASSWORD" fieldProps={{password:true, size:'large'}} required />
|
||||
<SubmitButton> {i18n('LOG_IN')} </SubmitButton>
|
||||
<FormField name="password" label={i18n('PASSWORD')} field="input" fieldProps={{password:true, size:'large'}} />
|
||||
<SubmitButton>{i18n('LOG_IN')}</SubmitButton>
|
||||
</Form>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -26,8 +28,14 @@ class AdminLoginPage extends React.Component {
|
|||
}
|
||||
|
||||
onSubmit(formState) {
|
||||
|
||||
this.props.dispatch(SessionActions.login(_.extend({}, formState, {
|
||||
staff: true
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
export default AdminLoginPage;
|
||||
export default connect((store) => {
|
||||
return {
|
||||
session: store.session
|
||||
};
|
||||
})(AdminLoginPage);
|
||||
|
|
|
@ -10,6 +10,7 @@ module.exports = [
|
|||
email: 'staff@opensupports.com',
|
||||
profilePic: 'http://i65.tinypic.com/9bep95.jpg',
|
||||
level: 1,
|
||||
staff: true,
|
||||
departments: [
|
||||
{id: 1, name: 'Sales Support'},
|
||||
{id: 2, name: 'Technical Issues'},
|
||||
|
|
|
@ -41,7 +41,8 @@ class SessionReducer extends Reducer {
|
|||
return _.extend({}, state, {
|
||||
logged: true,
|
||||
pending: false,
|
||||
failed: false
|
||||
failed: false,
|
||||
staff: payload.data.staff
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -101,8 +102,12 @@ class SessionReducer extends Reducer {
|
|||
sessionStore.storeUserData(payload.data);
|
||||
|
||||
return _.extend({}, state, {
|
||||
userName: userData.name,
|
||||
userEmail: userData.email,
|
||||
staff: userData.staff,
|
||||
userName: userData.name,
|
||||
userEmail: userData.email,
|
||||
userProfilePic: userData.profilePic,
|
||||
userLevel: userData.level,
|
||||
userDepartments: userData.departments,
|
||||
userTickets: userData.tickets
|
||||
});
|
||||
}
|
||||
|
@ -113,8 +118,12 @@ class SessionReducer extends Reducer {
|
|||
return _.extend({}, state, {
|
||||
initDone: true,
|
||||
logged: true,
|
||||
staff: userData.staff,
|
||||
userName: userData.name,
|
||||
userEmail: userData.email,
|
||||
userProfilePic: userData.profilePic,
|
||||
userLevel: userData.level,
|
||||
userDepartments: userData.departments,
|
||||
userTickets: userData.tickets
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue