2017-01-03 00:09:57 +11:00
|
|
|
import { connect } from 'react-redux';
|
2017-06-12 20:26:23 +10:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-01-03 00:09:57 +11:00
|
|
|
import ColumnSettings from '../components/column_settings';
|
2017-01-11 03:25:10 +11:00
|
|
|
import { changeSetting, saveSettings } from '../../../actions/settings';
|
2017-06-12 20:26:23 +10:00
|
|
|
import { clearNotifications } from '../../../actions/notifications';
|
2017-07-14 06:15:32 +10:00
|
|
|
import { changeAlerts as changePushNotifications, saveSettings as savePushNotificationSettings } from '../../../actions/push_notifications';
|
2017-06-12 20:26:23 +10:00
|
|
|
import { openModal } from '../../../actions/modal';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
clearMessage: { id: 'notifications.clear_confirmation', defaultMessage: 'Are you sure you want to permanently clear all your notifications?' },
|
|
|
|
clearConfirm: { id: 'notifications.clear', defaultMessage: 'Clear notifications' },
|
|
|
|
});
|
2017-01-03 00:09:57 +11:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2017-05-21 01:31:47 +10:00
|
|
|
settings: state.getIn(['settings', 'notifications']),
|
2017-07-14 06:15:32 +10:00
|
|
|
pushSettings: state.get('push_notifications'),
|
2017-01-03 00:09:57 +11:00
|
|
|
});
|
|
|
|
|
2017-06-12 20:26:23 +10:00
|
|
|
const mapDispatchToProps = (dispatch, { intl }) => ({
|
2017-01-03 00:09:57 +11:00
|
|
|
|
|
|
|
onChange (key, checked) {
|
2017-07-14 06:15:32 +10:00
|
|
|
if (key[0] === 'push') {
|
|
|
|
dispatch(changePushNotifications(key.slice(1), checked));
|
|
|
|
} else {
|
|
|
|
dispatch(changeSetting(['notifications', ...key], checked));
|
|
|
|
}
|
2017-01-11 03:25:10 +11:00
|
|
|
},
|
|
|
|
|
|
|
|
onSave () {
|
|
|
|
dispatch(saveSettings());
|
2017-07-14 06:15:32 +10:00
|
|
|
dispatch(savePushNotificationSettings());
|
2017-05-21 01:31:47 +10:00
|
|
|
},
|
2017-01-03 00:09:57 +11:00
|
|
|
|
2017-06-12 20:26:23 +10:00
|
|
|
onClear () {
|
|
|
|
dispatch(openModal('CONFIRM', {
|
|
|
|
message: intl.formatMessage(messages.clearMessage),
|
|
|
|
confirm: intl.formatMessage(messages.clearConfirm),
|
|
|
|
onConfirm: () => dispatch(clearNotifications()),
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2017-01-03 00:09:57 +11:00
|
|
|
});
|
|
|
|
|
2017-06-12 20:26:23 +10:00
|
|
|
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(ColumnSettings));
|