Settings stream tab

This commit is contained in:
Belen Curcio
2017-01-24 17:27:30 -03:00
parent 5750758cf1
commit ee9674cd23
4 changed files with 54 additions and 8 deletions
@@ -1,5 +1,6 @@
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {compose} from 'react-apollo';
import {I18n} from '../../coral-framework';
import {updateOpenStatus, updateConfiguration} from '../../coral-framework/actions/config';
@@ -14,7 +15,7 @@ class ConfigureStreamContainer extends Component {
super(props);
this.state = {
premod: props.config.moderation === 'pre',
premod: props.asset.settings.moderation.toLowerCase() === 'pre',
premodLinks: false
};
@@ -26,7 +27,7 @@ class ConfigureStreamContainer extends Component {
handleApply () {
const {premod, changed} = this.state;
const newConfig = {
moderation: premod ? 'pre' : 'post'
moderation: premod ? 'PRE' : 'POST'
};
if (changed) {
this.props.updateConfiguration(newConfig);
@@ -47,20 +48,18 @@ class ConfigureStreamContainer extends Component {
}
toggleStatus () {
this.props.updateStatus(this.props.config.status === 'open' ? 'closed' : 'open');
this.props.updateStatus(this.props.asset.closedAt === null ? 'closed' : 'open');
}
getClosedIn () {
const {closedTimeout} = this.props.config;
const {closedTimeout} = this.props.asset.settings;
const {created_at} = this.props.asset;
return lang.timeago(new Date(created_at).getTime() + (1000 * closedTimeout));
}
render () {
const {status} = this.props;
const status = this.props.asset.closedAt === null ? 'open' : 'closed';
// asset.closedAt === null
console.log(this.props.apollo.data);
return (
<div>
<ConfigureCommentStream
@@ -83,7 +82,7 @@ class ConfigureStreamContainer extends Component {
const mapStateToProps = (state) => ({
config: state.config.toJS(),
apollo: state.apollo
asset: state.asset.toJS()
});
const mapDispatchToProps = dispatch => ({
@@ -26,6 +26,7 @@ query AssetQuery($asset_url: String!) {
title
url
closedAt
created_at
settings {
moderation
infoBoxEnable
+45
View File
@@ -1 +1,46 @@
import coralApi from '../helpers/response';
import * as actions from '../constants/config';
import {addNotification} from '../actions/notification';
import I18n from 'coral-framework/modules/i18n/i18n';
import translations from './../translations';
const lang = new I18n(translations);
const updateConfigRequest = () => ({type: actions.UPDATE_CONFIG_REQUEST});
const updateConfigSuccess = config => ({type: actions.UPDATE_CONFIG_SUCCESS, config});
const updateConfigFailure = () => ({type: actions.UPDATE_CONFIG_FAILURE});
export const updateConfiguration = newConfig => (dispatch, getState) => {
const assetId = getState().asset.toJS().id;
dispatch(updateConfigRequest());
coralApi(`/assets/${assetId}/settings`, {method: 'PUT', body: newConfig})
.then(() => {
dispatch(addNotification('success', lang.t('successUpdateSettings')));
dispatch(updateConfigSuccess(newConfig));
})
.catch(error => dispatch(updateConfigFailure(error)));
};
export const updateOpenStream = closedBody => (dispatch, getState) => {
const assetId = getState().asset.toJS().id;
dispatch(updateConfigRequest());
coralApi(`/assets/${assetId}/status`, {method: 'PUT', body: closedBody})
.then(() => {
dispatch(addNotification('success', lang.t('successUpdateSettings')));
dispatch(updateConfigSuccess(closedBody));
})
.catch(error => dispatch(updateConfigFailure(error)));
};
const openStream = () => ({type: actions.OPEN_COMMENTS});
const closeStream = () => ({type: actions.CLOSE_COMMENTS});
export const updateOpenStatus = status => dispatch => {
if (status === 'open') {
dispatch(openStream());
dispatch(updateOpenStream({closedAt: null}));
} else {
dispatch(closeStream());
dispatch(updateOpenStream({closedAt: new Date().getTime()}));
}
};
+1
View File
@@ -115,6 +115,7 @@ type Asset {
comments: [Comment]
settings: Settings!
closedAt: String
created_at: String
}
enum COMMENT_STATUS {