2020-01-23 21:00:13 +00:00
|
|
|
import api from '../api';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
2020-01-23 21:00:13 +00:00
|
|
|
import { normalizeAnnouncement } from './importer/normalizer';
|
|
|
|
|
|
|
|
export const ANNOUNCEMENTS_FETCH_REQUEST = 'ANNOUNCEMENTS_FETCH_REQUEST';
|
|
|
|
export const ANNOUNCEMENTS_FETCH_SUCCESS = 'ANNOUNCEMENTS_FETCH_SUCCESS';
|
|
|
|
export const ANNOUNCEMENTS_FETCH_FAIL = 'ANNOUNCEMENTS_FETCH_FAIL';
|
|
|
|
export const ANNOUNCEMENTS_UPDATE = 'ANNOUNCEMENTS_UPDATE';
|
2020-01-26 19:07:26 +00:00
|
|
|
export const ANNOUNCEMENTS_DELETE = 'ANNOUNCEMENTS_DELETE';
|
2020-01-23 21:00:13 +00:00
|
|
|
|
2020-02-03 00:53:09 +00:00
|
|
|
export const ANNOUNCEMENTS_DISMISS_REQUEST = 'ANNOUNCEMENTS_DISMISS_REQUEST';
|
|
|
|
export const ANNOUNCEMENTS_DISMISS_SUCCESS = 'ANNOUNCEMENTS_DISMISS_SUCCESS';
|
|
|
|
export const ANNOUNCEMENTS_DISMISS_FAIL = 'ANNOUNCEMENTS_DISMISS_FAIL';
|
|
|
|
|
2020-01-23 21:00:13 +00:00
|
|
|
export const ANNOUNCEMENTS_REACTION_ADD_REQUEST = 'ANNOUNCEMENTS_REACTION_ADD_REQUEST';
|
|
|
|
export const ANNOUNCEMENTS_REACTION_ADD_SUCCESS = 'ANNOUNCEMENTS_REACTION_ADD_SUCCESS';
|
|
|
|
export const ANNOUNCEMENTS_REACTION_ADD_FAIL = 'ANNOUNCEMENTS_REACTION_ADD_FAIL';
|
|
|
|
|
|
|
|
export const ANNOUNCEMENTS_REACTION_REMOVE_REQUEST = 'ANNOUNCEMENTS_REACTION_REMOVE_REQUEST';
|
|
|
|
export const ANNOUNCEMENTS_REACTION_REMOVE_SUCCESS = 'ANNOUNCEMENTS_REACTION_REMOVE_SUCCESS';
|
|
|
|
export const ANNOUNCEMENTS_REACTION_REMOVE_FAIL = 'ANNOUNCEMENTS_REACTION_REMOVE_FAIL';
|
|
|
|
|
|
|
|
export const ANNOUNCEMENTS_REACTION_UPDATE = 'ANNOUNCEMENTS_REACTION_UPDATE';
|
|
|
|
|
2020-01-25 15:35:33 +00:00
|
|
|
export const ANNOUNCEMENTS_TOGGLE_SHOW = 'ANNOUNCEMENTS_TOGGLE_SHOW';
|
|
|
|
|
2020-01-23 21:00:13 +00:00
|
|
|
const noOp = () => {};
|
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
export const fetchAnnouncements = (done = noOp) => (dispatch) => {
|
2020-01-23 21:00:13 +00:00
|
|
|
dispatch(fetchAnnouncementsRequest());
|
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
api().get('/api/v1/announcements').then(response => {
|
2020-01-23 21:00:13 +00:00
|
|
|
dispatch(fetchAnnouncementsSuccess(response.data.map(x => normalizeAnnouncement(x))));
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch(fetchAnnouncementsFail(error));
|
|
|
|
}).finally(() => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const fetchAnnouncementsRequest = () => ({
|
|
|
|
type: ANNOUNCEMENTS_FETCH_REQUEST,
|
|
|
|
skipLoading: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const fetchAnnouncementsSuccess = announcements => ({
|
|
|
|
type: ANNOUNCEMENTS_FETCH_SUCCESS,
|
|
|
|
announcements,
|
|
|
|
skipLoading: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const fetchAnnouncementsFail= error => ({
|
|
|
|
type: ANNOUNCEMENTS_FETCH_FAIL,
|
|
|
|
error,
|
|
|
|
skipLoading: true,
|
|
|
|
skipAlert: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const updateAnnouncements = announcement => ({
|
|
|
|
type: ANNOUNCEMENTS_UPDATE,
|
|
|
|
announcement: normalizeAnnouncement(announcement),
|
|
|
|
});
|
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
export const dismissAnnouncement = announcementId => (dispatch) => {
|
2020-02-03 00:53:09 +00:00
|
|
|
dispatch(dismissAnnouncementRequest(announcementId));
|
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
api().post(`/api/v1/announcements/${announcementId}/dismiss`).then(() => {
|
2020-02-03 00:53:09 +00:00
|
|
|
dispatch(dismissAnnouncementSuccess(announcementId));
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch(dismissAnnouncementFail(announcementId, error));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const dismissAnnouncementRequest = announcementId => ({
|
|
|
|
type: ANNOUNCEMENTS_DISMISS_REQUEST,
|
|
|
|
id: announcementId,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const dismissAnnouncementSuccess = announcementId => ({
|
|
|
|
type: ANNOUNCEMENTS_DISMISS_SUCCESS,
|
|
|
|
id: announcementId,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const dismissAnnouncementFail = (announcementId, error) => ({
|
|
|
|
type: ANNOUNCEMENTS_DISMISS_FAIL,
|
|
|
|
id: announcementId,
|
|
|
|
error,
|
|
|
|
});
|
|
|
|
|
2020-01-23 21:00:13 +00:00
|
|
|
export const addReaction = (announcementId, name) => (dispatch, getState) => {
|
2020-01-25 17:19:24 +00:00
|
|
|
const announcement = getState().getIn(['announcements', 'items']).find(x => x.get('id') === announcementId);
|
|
|
|
|
|
|
|
let alreadyAdded = false;
|
|
|
|
|
|
|
|
if (announcement) {
|
|
|
|
const reaction = announcement.get('reactions').find(x => x.get('name') === name);
|
|
|
|
if (reaction && reaction.get('me')) {
|
|
|
|
alreadyAdded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!alreadyAdded) {
|
|
|
|
dispatch(addReactionRequest(announcementId, name, alreadyAdded));
|
|
|
|
}
|
2020-01-23 21:00:13 +00:00
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
api().put(`/api/v1/announcements/${announcementId}/reactions/${encodeURIComponent(name)}`).then(() => {
|
2020-01-25 17:19:24 +00:00
|
|
|
dispatch(addReactionSuccess(announcementId, name, alreadyAdded));
|
2020-01-23 21:00:13 +00:00
|
|
|
}).catch(err => {
|
2020-01-25 17:19:24 +00:00
|
|
|
if (!alreadyAdded) {
|
|
|
|
dispatch(addReactionFail(announcementId, name, err));
|
|
|
|
}
|
2020-01-23 21:00:13 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const addReactionRequest = (announcementId, name) => ({
|
|
|
|
type: ANNOUNCEMENTS_REACTION_ADD_REQUEST,
|
|
|
|
id: announcementId,
|
|
|
|
name,
|
|
|
|
skipLoading: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const addReactionSuccess = (announcementId, name) => ({
|
|
|
|
type: ANNOUNCEMENTS_REACTION_ADD_SUCCESS,
|
|
|
|
id: announcementId,
|
|
|
|
name,
|
|
|
|
skipLoading: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const addReactionFail = (announcementId, name, error) => ({
|
|
|
|
type: ANNOUNCEMENTS_REACTION_ADD_FAIL,
|
|
|
|
id: announcementId,
|
|
|
|
name,
|
|
|
|
error,
|
|
|
|
skipLoading: true,
|
|
|
|
});
|
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
export const removeReaction = (announcementId, name) => (dispatch) => {
|
2020-01-23 21:00:13 +00:00
|
|
|
dispatch(removeReactionRequest(announcementId, name));
|
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
api().delete(`/api/v1/announcements/${announcementId}/reactions/${encodeURIComponent(name)}`).then(() => {
|
2020-01-23 21:00:13 +00:00
|
|
|
dispatch(removeReactionSuccess(announcementId, name));
|
|
|
|
}).catch(err => {
|
|
|
|
dispatch(removeReactionFail(announcementId, name, err));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const removeReactionRequest = (announcementId, name) => ({
|
|
|
|
type: ANNOUNCEMENTS_REACTION_REMOVE_REQUEST,
|
|
|
|
id: announcementId,
|
|
|
|
name,
|
|
|
|
skipLoading: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const removeReactionSuccess = (announcementId, name) => ({
|
|
|
|
type: ANNOUNCEMENTS_REACTION_REMOVE_SUCCESS,
|
|
|
|
id: announcementId,
|
|
|
|
name,
|
|
|
|
skipLoading: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const removeReactionFail = (announcementId, name, error) => ({
|
|
|
|
type: ANNOUNCEMENTS_REACTION_REMOVE_FAIL,
|
|
|
|
id: announcementId,
|
|
|
|
name,
|
|
|
|
error,
|
|
|
|
skipLoading: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const updateReaction = reaction => ({
|
|
|
|
type: ANNOUNCEMENTS_REACTION_UPDATE,
|
|
|
|
reaction,
|
|
|
|
});
|
2020-01-25 15:35:33 +00:00
|
|
|
|
2020-01-26 19:07:26 +00:00
|
|
|
export const toggleShowAnnouncements = () => ({
|
|
|
|
type: ANNOUNCEMENTS_TOGGLE_SHOW,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const deleteAnnouncement = id => ({
|
|
|
|
type: ANNOUNCEMENTS_DELETE,
|
|
|
|
id,
|
|
|
|
});
|