Merge branch 'master' into use-js-while-rendering

This commit is contained in:
David Jay
2016-12-12 20:36:10 -05:00
committed by GitHub
5 changed files with 25 additions and 21 deletions
@@ -91,7 +91,7 @@ class CommentStream extends Component {
const rootItem = this.props.items.assets && this.props.items.assets[rootItemId];
const {actions, users, comments} = this.props.items;
const {status, moderation, closedMessage} = this.props.config;
const {loggedIn, user, showSignInDialog, signInOffset} = this.props.auth;
const {loggedIn, isAdmin, user, showSignInDialog, signInOffset} = this.props.auth;
const {activeTab} = this.state;
const banned = (this.props.userData.status === 'banned');
@@ -105,7 +105,7 @@ class CommentStream extends Component {
<TabBar onChange={this.changeTab} activeTab={activeTab}>
<Tab><Count id={rootItemId} items={this.props.items}/></Tab>
<Tab>Settings</Tab>
<Tab>Configure Stream</Tab>
<Tab restricted={!isAdmin}>Configure Stream</Tab>
</TabBar>
{loggedIn && <UserBox user={user} logout={this.props.logout} />}
<TabContent show={activeTab === 0}>
+8 -6
View File
@@ -20,15 +20,16 @@ export const cleanState = () => ({type: actions.CLEAN_STATE});
// Sign In Actions
const signInRequest = () => ({type: actions.FETCH_SIGNIN_REQUEST});
const signInSuccess = user => ({type: actions.FETCH_SIGNIN_SUCCESS, user});
const signInSuccess = (user, isAdmin) => ({type: actions.FETCH_SIGNIN_SUCCESS, user, isAdmin});
const signInFailure = error => ({type: actions.FETCH_SIGNIN_FAILURE, error});
export const fetchSignIn = (formData) => dispatch => {
dispatch(signInRequest());
coralApi('/auth/local', {method: 'POST', body: formData})
.then(({user}) => {
const isAdmin = !!user.roles.filter(i => i === 'admin').length;
dispatch(signInSuccess(user, isAdmin));
dispatch(hideSignInDialog());
dispatch(signInSuccess(user));
dispatch(addItem(user, 'users'));
})
.catch(() => dispatch(signInFailure(lang.t('error.emailPasswordError'))));
@@ -73,7 +74,7 @@ const signUpFailure = error => ({type: actions.FETCH_SIGNUP_FAILURE, error});
export const fetchSignUp = formData => dispatch => {
dispatch(signUpRequest());
coralApi('/user', {method: 'POST', body: formData})
coralApi('/users', {method: 'POST', body: formData})
.then(({user}) => {
dispatch(signUpSuccess(user));
setTimeout(() =>{
@@ -117,7 +118,7 @@ export const invalidForm = error => ({type: actions.INVALID_FORM, error});
// Check Login
const checkLoginRequest = () => ({type: actions.CHECK_LOGIN_REQUEST});
const checkLoginSuccess = user => ({type: actions.CHECK_LOGIN_SUCCESS, user});
const checkLoginSuccess = (user, isAdmin) => ({type: actions.CHECK_LOGIN_SUCCESS, user, isAdmin});
const checkLoginFailure = error => ({type: actions.CHECK_LOGIN_FAILURE, error});
export const checkLogin = () => dispatch => {
@@ -125,10 +126,11 @@ export const checkLogin = () => dispatch => {
coralApi('/auth')
.then(user => {
if (!user) {
throw new Error('not logged in');
throw new Error('Not logged in');
}
dispatch(checkLoginSuccess(user));
const isAdmin = !!user.roles.filter(i => i === 'admin').length;
dispatch(checkLoginSuccess(user, isAdmin));
})
.catch(error => dispatch(checkLoginFailure(error)));
};
+4 -3
View File
@@ -4,6 +4,7 @@ import * as actions from '../constants/auth';
const initialState = Map({
isLoading: false,
loggedIn: false,
isAdmin: false,
user: null,
showSignInDialog: false,
view: 'SIGNIN',
@@ -50,10 +51,12 @@ export default function auth (state = initialState, action) {
case actions.CHECK_LOGIN_SUCCESS:
return state
.set('loggedIn', true)
.set('isAdmin', action.isAdmin)
.set('user', purge(action.user));
case actions.FETCH_SIGNIN_SUCCESS:
return state
.set('loggedIn', true)
.set('isAdmin', action.isAdmin)
.set('user', purge(action.user));
case actions.FETCH_SIGNIN_FAILURE:
return state
@@ -80,9 +83,7 @@ export default function auth (state = initialState, action) {
.set('isLoading', false)
.set('successSignUp', true);
case actions.LOGOUT_SUCCESS:
return state
.set('loggedIn', false)
.set('user', null);
return initialState;
case actions.INVALID_FORM:
return state
.set('error', action.error);
+1 -2
View File
@@ -45,8 +45,7 @@ class CommentBox extends Component {
postItem(comment, 'comments')
.then((postedComment) => {
const commentId = postedComment.id;
const status = postedComment.status;
if (status[0] && status[0].type === 'rejected') {
if (postedComment.status === 'rejected') {
addNotification('error', lang.t('comment-post-banned-word'));
} else if (premod === 'pre') {
addNotification('success', lang.t('comment-post-notif-premod'));
+10 -8
View File
@@ -18,14 +18,16 @@ export class TabBar extends React.Component {
return (
<div>
<ul className={`${styles.base} ${cStyle ? styles[cStyle] : ''}`}>
{React.Children.map(children, (child, tabId) =>
React.cloneElement(child, {
tabId,
active: tabId === activeTab,
onTabClick: this.handleClickTab,
cStyle
})
)}
{React.Children.toArray(children)
.filter(child => !child.props.restricted)
.map((child, tabId) =>
React.cloneElement(child, {
tabId,
active: tabId === activeTab,
onTabClick: this.handleClickTab,
cStyle
})
)}
</ul>
</div>
);