diff --git a/src/notifications/actions/GetNotificationById.js b/src/notifications/actions/GetNotificationById.js
index e3383945f1eb7388a05432bde25eed1a251d99c8..f7302091cfa2f7766e2839e776f3bb9977085881 100644
--- a/src/notifications/actions/GetNotificationById.js
+++ b/src/notifications/actions/GetNotificationById.js
@@ -6,6 +6,8 @@ export const GET_NOTIFICATION_BY_ID = 'GET_NOTIFICATION_BY_ID';
export const GET_NOTIFICATION_BY_ID_SUCCESS = 'GET_NOTIFICATION_BY_ID_SUCCESS';
export const GET_NOTIFICATION_BY_ID_FAILURE = 'GET_NOTIFICATION_BY_ID_FAILURE';
+export const SET_NOTIFICATION = 'SET_NOTIFICATION';
+
export const getNotificationById = (notificationId, visibility) => ({
[RSAA]: {
endpoint: `${process.env.REACT_APP_BASE_URL}/notifications/${notificationId}`,
@@ -18,3 +20,9 @@ export const getNotificationById = (notificationId, visibility) => ({
types: [GET_NOTIFICATION_BY_ID, GET_NOTIFICATION_BY_ID_SUCCESS, GET_NOTIFICATION_BY_ID_FAILURE],
},
});
+
+export const setNotification = () => {
+ return {
+ type: SET_NOTIFICATION,
+ };
+};
diff --git a/src/notifications/components/NotificationDisplay/NotificationDisplay.js b/src/notifications/components/NotificationDisplay/NotificationDisplay.js
index 16d5c60c256ea12d89fa11deda3cca78564cff66..d1a51777cb70560126faad8bdc5c5fd1b3e11984 100644
--- a/src/notifications/components/NotificationDisplay/NotificationDisplay.js
+++ b/src/notifications/components/NotificationDisplay/NotificationDisplay.js
@@ -25,6 +25,7 @@ import * as getNotificationTargetGroupsActionCreator from 'notifications/actions
import NotificationComponent from './NotificationComponent';
import './NotificationDisplay.scss';
import {isAdmin} from 'auth/utils/authUtils';
+import * as setNotificationActionCreator from 'notifications/actions/GetNotificationById';
const NotificationDisplay = ({
notification,
@@ -35,6 +36,7 @@ const NotificationDisplay = ({
getAuditById,
loadingAudit,
deleteNotificationById,
+ setNotification,
targetGroups,
targetUsers,
getNotificationTargetUsers,
@@ -60,6 +62,12 @@ const NotificationDisplay = ({
notification,
]);
+ useEffect(() => {
+ return () => {
+ setNotification();
+ };
+ }, [setNotification]);
+
async function copyNotificationLinkToClipboard() {
navigator.clipboard.writeText(
`${window.location.origin}/channels/${channelId}/notifications/${notification.id}/`
@@ -299,6 +307,7 @@ const mapDispatchToProps = dispatch => {
...bindActionCreators(showSnackBarActionCreator, dispatch),
...bindActionCreators(getAuditByIdActionCreator, dispatch),
...bindActionCreators(deleteNotificationByIdCreator, dispatch),
+ ...bindActionCreators(setNotificationActionCreator, dispatch),
...bindActionCreators(getNotificationTargetUsersActionCreator, dispatch),
...bindActionCreators(getNotificationTargetGroupsActionCreator, dispatch),
};
diff --git a/src/notifications/components/NotificationsList/NotificationsList.js b/src/notifications/components/NotificationsList/NotificationsList.js
index 2b84d99893ca0186d9bc935fa2f15999f43d6b92..64b7b81e5d025c736ee82eabd08940dc9a4af676 100644
--- a/src/notifications/components/NotificationsList/NotificationsList.js
+++ b/src/notifications/components/NotificationsList/NotificationsList.js
@@ -1,6 +1,6 @@
import React, {useEffect, useState} from 'react';
import {Grid, Item, Pagination, Icon} from 'semantic-ui-react';
-import {connect, useDispatch} from 'react-redux';
+import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {useParams} from 'react-router-dom';
@@ -11,9 +11,6 @@ import * as getPublicNotificationsActionCreators from 'notifications/actions/Get
import './NotificationsList.scss';
import NotificationsListItem from './NotificationsListItem';
-import {setNotification} from 'notifications/reducers/Notification';
-import {SET_NOTIFICATION} from 'notifications/reducers/Notification';
-
const NotificationsList = props => {
const {
notifications,
@@ -33,11 +30,9 @@ const NotificationsList = props => {
const [showNotification, setShowNotification] = useState(null);
const activePage = getNotificationsQuery.skip / getNotificationsQuery.take + 1;
const totalPages = Math.ceil(count / getNotificationsQuery.take);
- const dispatch = useDispatch();
const closeNotificationModal = () => {
window.history.pushState({}, document.title, `/channels/${channelId}/notifications`);
- dispatch(setNotification({type: SET_NOTIFICATION, payload: {}}));
setShowNotification(null);
};
diff --git a/src/notifications/reducers/Notification.js b/src/notifications/reducers/Notification.js
index 52c3953618526dfe9a9e78df238567ca9e64c987..b5ce2b6f9fc2bbd19ce7b1f82a05e1a95c73fe73 100644
--- a/src/notifications/reducers/Notification.js
+++ b/src/notifications/reducers/Notification.js
@@ -2,6 +2,7 @@ import {
GET_NOTIFICATION_BY_ID,
GET_NOTIFICATION_BY_ID_SUCCESS,
GET_NOTIFICATION_BY_ID_FAILURE,
+ SET_NOTIFICATION,
} from 'notifications/actions/GetNotificationById';
import {
@@ -16,8 +17,6 @@ import {
GET_TARGET_GROUPS_FAILURE,
} from 'notifications/actions/GetNotificationTargetGroups';
-export const SET_NOTIFICATION = 'SET_NOTIFICATION';
-
const INITIAL_STATE = {
notification: null,
channelId: '',
@@ -60,7 +59,7 @@ function processGetNotificationByIdFailure(state, error) {
};
}
-export function setNotification(state) {
+function processSetNotification(state) {
return {
...state,
notification: state.payload,
@@ -134,7 +133,7 @@ export default function (state = INITIAL_STATE, action) {
return processGetNotificationByIdFailure(state, error);
}
case SET_NOTIFICATION: {
- return setNotification(state, action.payload);
+ return processSetNotification(state, action.payload);
}
case GET_TARGET_USERS: