As I'm new to redux can someone help me if it is possible to make a change in one action based on the state change from different another file.
actions.js
export function setChangeNotification(changeNotification: boolean) {
return {
type: SET_CHANGE_NOTIFICATION,
changeNotification
};
}
Toolbar.js
endMeetingForAll () {
const { _changeNotification } = this.props;
this.props.dispatch(setChangeNotification(true)); //changed value set to true but at default it's false in my initial state.
console.log(_changeNotification,'changeNotification from end meeting'); //Checked if value changed using mapStateToProps.
}
function _mapStateToProps(state) {
return {
_changeNotification: Boolean(state['features/toolbox'].changeNotification)
};
}
export default translate(connect(_mapStateToProps)(Toolbox));
Another action.js where I need to make a change
export function notifyKickedOut(participant: Object, _: ?Function) { // eslint-disable-line
no-unused-vars
return (dispatch: Dispatch<any>, getState: Function) => {
const args = {
participantDisplayName:
getParticipantDisplayName(getState, participant.getId())
};
dispatch(showNotification({
appearance: NOTIFICATION_TYPE.ERROR,
hideErrorSupportLink: true,
descriptionKey: 'dialog.kickMessage',
descriptionArguments: args,
titleKey: 'dialog.kickTitle',
titleArguments: args
}));
//JAAM CODE
// when the paticipant removed after redirect to the website.
setTimeout(
() => {
window.APP.conference.hangup(false);
executeCommand('hangup');
window.close();
},
NOTIFICATION_TIMEOUT);
};
}
In the above action.js I need to dispatch another shownotification if setChangeNotification is true like
if(changeNotification){
dispatch(showNotification({
appearance: NOTIFICATION_TYPE.ERROR,
descriptionKey: 'dialog.changed',
titleKey: 'dialog.changed'
}));
}else{
dispatch(showNotification({
appearance: NOTIFICATION_TYPE.ERROR,
hideErrorSupportLink: true,
descriptionKey: 'dialog.kickMessage',
descriptionArguments: args,
titleKey: 'dialog.kickTitle',
titleArguments: args
}));
}
You have access to the state via calling getState(). Since this looks like a thunk (async action creator) you can dispatch any action you'd like there.