Created
October 23, 2015 05:11
-
-
Save jerairrest/bcfd0e6692e90625d8d1 to your computer and use it in GitHub Desktop.
Revisions
-
jerairrest created this gist
Oct 23, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ export const RECEIVE_MESSAGE = 'RECEIVE_MESSAGE'; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ import * as NotificationActions from './NotificationActionTypes'; export function resetNotification() { return { type: NotificationActions.RECEIVE_MESSAGE, payload: Object.assign({}, { title: "", message: "" }) } } export function displayNotification(title, message) { return { type: NotificationActions.RECEIVE_MESSAGE, payload: Object.assign({}, { title: title, message: message }) } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ import React, { Component } from 'react'; import toastr from 'react-toastr'; import { connect } from 'react-redux'; import _ from 'lodash'; import * as NotificationActions from './NotificationActions'; let {ToastContainer} = toastr; let ToastMessageFactory = React.createFactory(toastr.ToastMessage.jQuery); class Notification extends Component { constructor(props) { super(props); this.addAlert = this.addAlert.bind(this); } componentWillReceiveProps(nextprops) { if (this.props.notification.message != nextprops.notification.message && nextprops.notification.message != "") { this.addAlert(nextprops.notification); this.props.dispatch(NotificationActions.resetNotification()); } } render() { return ( <ToastContainer toastMessageFactory={ToastMessageFactory} ref="container" className="toast-container toast-bottom-right"/> ); } addAlert(message) { this.refs.container.success( message.message, message.title, { timeOut: 3000, extendedTimeOut: 1000 } ); } } function mapStateToProps(state) { return { notification: state.app.data.notification }; } export default connect(mapStateToProps)(Notification); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ import { combineReducers } from 'redux'; import * as NotificationActions from './NotificationActionTypes'; const initialState = { message: "", title: "" } function notification(state, action) { switch (action.type) { case 'RECEIVE_MESSAGE': return Object.assign({}, state, action.payload); default: return state; } } const reducer = combineReducers({ notification }); export default reducer;