Recovered community admin.

This commit is contained in:
gaba
2016-11-29 12:42:25 -08:00
parent a5f67e10d6
commit 8af9e14971
9 changed files with 65 additions and 22 deletions
+9 -1
View File
@@ -6,7 +6,8 @@ import {
FETCH_COMMENTERS_FAILURE,
SORT_UPDATE,
COMMENTERS_NEW_PAGE,
SET_ROLE
SET_ROLE,
SET_COMMENTER_STATUS
} from '../constants/community';
import {base, getInit, handleResp} from '../../../coral-framework/helpers/response';
@@ -47,3 +48,10 @@ export const setRole = (id, role) => dispatch => {
return dispatch({type: SET_ROLE, id, role});
});
};
export const setCommenterStatus = (id, status) => dispatch => {
return fetch(`${base}/user/${id}/status`, getInit('POST', {status}))
.then(() => {
return dispatch({type: SET_COMMENTER_STATUS, id, status});
});
};
+7 -7
View File
@@ -1,7 +1,7 @@
// /**
// * Action disptacher related to users
// */
//
// export const updateUserStatus = (status, id) => (dispatch) => {
// dispatch({type: 'USER_STATUS_UPDATE', id, status});
// };
/**
* Action disptacher related to users
*/
export const updateUserStatus = (status, id) => (dispatch) => {
dispatch({type: 'USER_STATUS_UPDATE', id, status});
};
@@ -4,3 +4,4 @@ export const FETCH_COMMENTERS_FAILURE = 'FETCH_COMMENTERS_FAILURE';
export const SORT_UPDATE = 'SORT_UPDATE';
export const COMMENTERS_NEW_PAGE = 'COMMENTERS_NEW_PAGE';
export const SET_ROLE = 'SET_ROLE';
export const SET_COMMENTER_STATUS = 'SET_COMMENTER_STATUS';
@@ -1,7 +1,3 @@
.dataTable {
width: 100%;
}
.roleButton {
display: block;
}
@@ -9,14 +5,13 @@
.searchInput {
display: block;
padding-left: 40px;
/*border: none;*/
width: auto;
}
.searchBox {
/*border: 1px solid rgba(0,0,0,.12);*/
background: white;
}
.email {
display: block;
}
}
@@ -20,6 +20,10 @@ const tableHeaders = [
title: lang.t('community.account_creation_date'),
field: 'created_at'
},
{
title: lang.t('community.status'),
field: 'status'
},
{
title: lang.t('community.newsroom_role'),
field: 'role'
@@ -30,7 +34,7 @@ const Community = ({isFetching, commenters, ...props}) => {
const hasResults = !isFetching && !!commenters.length;
return (
<Grid>
<Cell col={4}>
<Cell col={2}>
<form action="">
<div className={`mdl-textfield ${styles.searchBox}`}>
<label className="mdl-button mdl-js-button mdl-button--icon" htmlFor="commenters-search">
@@ -49,7 +53,7 @@ const Community = ({isFetching, commenters, ...props}) => {
</div>
</form>
</Cell>
<Cell col={8}>
<Cell col={6}>
{ isFetching && <Loading /> }
{ !hasResults && <NoResults /> }
{ hasResults &&
@@ -4,7 +4,7 @@ import {SelectField, Option} from 'react-mdl-selectfield';
import styles from './Community.css';
import I18n from 'coral-framework/modules/i18n/i18n';
import translations from '../../translations';
import {setRole} from '../../actions/community';
import {setRole, setCommenterStatus} from '../../actions/community';
const lang = new I18n(translations);
@@ -19,6 +19,10 @@ class Table extends Component {
this.props.dispatch(setRole(id, role));
}
onCommenterStatusChange (id, status) {
this.props.dispatch(setCommenterStatus(id, status));
}
render () {
const {headers, commenters, onHeaderClickHandler} = this.props;
@@ -46,6 +50,14 @@ class Table extends Component {
<td className="mdl-data-table__cell--non-numeric">
{row.created_at}
</td>
<td className="mdl-data-table__cell--non-numeric">
<SelectField label={'Select me'} value={row.status || ''}
label={lang.t('community.status')}
onChange={status => this.onCommenterStatusChange(row.id, status)}>
<Option value={'active'}>{lang.t('community.active')}</Option>
<Option value={'banned'}>{lang.t('community.banned')}</Option>
</SelectField>
</td>
<td className="mdl-data-table__cell--non-numeric">
<SelectField label={'Select me'} value={row.roles[0] || ''}
label={lang.t('community.role')}
+10 -1
View File
@@ -5,7 +5,8 @@ import {
FETCH_COMMENTERS_FAILURE,
FETCH_COMMENTERS_SUCCESS,
SORT_UPDATE,
SET_ROLE
SET_ROLE,
SET_COMMENTER_STATUS
} from '../constants/community';
const initialState = Map({
@@ -45,6 +46,14 @@ export default function community (state = initialState, action) {
commenters[idx].roles[0] = action.role;
return state.set('commenters', commenters.map(id => id));
}
case SET_COMMENTER_STATUS: {
const commenters = state.get('commenters');
const idx = commenters.findIndex(el => el.id === action.id);
commenters[idx].status = action.status;
return state.set('commenters', commenters.map(id => id));
}
case SORT_UPDATE :
return state
.set('field', action.sort.field)
+1 -1
View File
@@ -10,7 +10,7 @@ const initialState = Map({
// Handle the users actions
export default (state = initialState, action) => {
switch (action.type) {
case 'USER_STATUS_UPDATE': return updateUserStatus(state, action);
case 'SET_COMMENTER_STATUS': return updateUserStatus(state, action);
default: return state;
}
};
+16 -2
View File
@@ -6,7 +6,14 @@
"newsroom_role": "Newsroom Role",
"admin": "Administrator",
"moderator": "Moderator",
"role": "Select role..."
"role": "Select role...",
"no-results": "No users found with that user name or email address.",
"status": "Status",
"select-status": "Select status...",
"active": "Active",
"banned": "Banned",
"banned-user": "Banned User",
"loading": "Loading results"
},
"modqueue": {
"pending": "pending",
@@ -51,7 +58,14 @@
"newsroom_role": "Rol en la redacción",
"admin": "Administrador",
"moderator": "Moderador",
"role": "Select role..."
"role": "Select role...",
"no-results": "No se encontraron usuarios con ese nombre de usuario o correo electronico.",
"status": "Estado",
"select-status": "Seleccionar estado...",
"active": "Activa",
"banned": "Suspendido",
"banned-user": "Usuario Suspendido",
"loading": "Cargando resultados"
},
"modqueue": {
"pending": "pendiente",