Skip to content

after merge #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__coverage__
.build-info
.sass-cache
dist
#dist
node_modules
_auto_doc_
.vscode
17 changes: 17 additions & 0 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
@@ -106,6 +106,18 @@ Object {
"getUserSrmDone": [Function],
"getUserSrmInit": [Function],
},
"notifications": Object {
"dismissChallengeNotificationsDone": [Function],
"dismissChallengeNotificationsInit": [Function],
"getNotificationsDone": [Function],
"getNotificationsInit": [Function],
"markAllNotificationAsReadDone": [Function],
"markAllNotificationAsReadInit": [Function],
"markAllNotificationAsSeenDone": [Function],
"markAllNotificationAsSeenInit": [Function],
"markNotificationAsReadDone": [Function],
"markNotificationAsReadInit": [Function],
},
"profile": Object {
"addSkillDone": [Function],
"addSkillInit": [Function],
@@ -255,6 +267,7 @@ Object {
"memberTasks": [Function],
"members": [Function],
"mySubmissionsManagement": [Function],
"notifications": [Function],
"profile": [Function],
"reviewOpportunity": [Function],
"settings": [Function],
@@ -312,6 +325,10 @@ Object {
"default": undefined,
"getService": [Function],
},
"notifications": Object {
"default": undefined,
"getService": [Function],
},
"reviewOpportunities": Object {
"default": undefined,
"getReviewOpportunitiesService": [Function],
2 changes: 2 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ import lookupActions from './lookup';
import settingsActions from './settings';
import lookerActions from './looker';
import memberSearchActions from './member-search';
import notificationActions from './notifications';

export const actions = {
auth: authActions.auth,
@@ -32,6 +33,7 @@ export const actions = {
settings: settingsActions.settings,
looker: lookerActions.looker,
memberSearch: memberSearchActions.memberSearch,
notifications: notificationActions.notifications,
};

export default undefined;
173 changes: 173 additions & 0 deletions src/actions/notifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/**
* @module "actions.notifications"
* @desc Actions related to notifications data.
*/

import _ from 'lodash';
import { createActions } from 'redux-actions';
import { getService } from '../services/notifications';

/**
* TODO: We will need to change this based on API and
* frontend mapping we need later.
*/
function processData(data) {
const retData = _.map(data, (item) => {
const object = {};
object.id = item.id;
object.sourceId = item.contents.id;
object.sourceName = item.contents.name || item.contents.title;
object.eventType = item.type;
object.isRead = item.read;
object.isSeen = item.seen;
object.contents = item.contents.message || item.contents.title;
object.version = item.version;
object.date = item.createdAt;
return object;
});
return retData;
}

/**
* @static
* @desc Creates an action that signals beginning of notifications
* loading.
* @return {Action}
*/
function getNotificationsInit() {
return { };
}

/**
* @static
* @desc Creates an action that loads member achievements.
* @param {String} tokenV3 v3 auth token.
* @return {Action}
*/
async function getNotificationsDone(tokenV3) {
let data;
try {
data = await getService(tokenV3).getNotifications();
} catch (e) {
data = [];
}
return processData(data.items || []);
}

/**
* @static
* @desc Creates an action that signals beginning of mark notification as read
* loading.
* @return {Action}
*/
function markNotificationAsReadInit() {
return { };
}

/**
* @static
* @desc Creates an action that marks notification as read.
* @param {String} tokenV3 v3 auth token.
* @return {Action}
*/
async function markNotificationAsReadDone(item, tokenV3) {
try {
await getService(tokenV3).markNotificationAsRead(item.id);
} catch (e) {
return e;
}
return item;
}

/**
* @static
* @desc Creates an action that signals beginning of mark all notification as read
* loading.
* @return {Action}
*/
function markAllNotificationAsReadInit() {
return { };
}

/**
* @static
* @desc Creates an action that marks all notification as read.
* @param {String} tokenV3 v3 auth token.
* @return {Action}
*/
async function markAllNotificationAsReadDone(tokenV3) {
try {
await getService(tokenV3).markAllNotificationAsRead();
} catch (e) {
return e;
}
return true;
}


/**
* @static
* @desc Creates an action that signals beginning of mark all notification as seen
* loading.
* @return {Action}
*/
function markAllNotificationAsSeenInit() {
return { };
}

/**
* @static
* @desc Creates an action that marks all notification as seen.
* @param {String} tokenV3 v3 auth token.
* @return {Action}
*/
async function markAllNotificationAsSeenDone(items, tokenV3) {
try {
await getService(tokenV3).markAllNotificationAsSeen(items);
} catch (e) {
return e;
}
return items;
}


/**
* @static
* @desc Creates an action that signals beginning of dismiss all challenge notifications
* loading.
* @return {Action}
*/
function dismissChallengeNotificationsInit() {
return { };
}

/**
* @static
* @desc Creates an action that dismisses all challenge notifications
* @param {String} tokenV3 v3 auth token.
* @return {Action}
*/
async function dismissChallengeNotificationsDone(challengeId, tokenV3) {
try {
await getService(tokenV3).dismissChallengeNotifications(challengeId);
} catch (e) {
return e;
}
return true;
}


export default createActions({
NOTIFICATIONS: {
GET_NOTIFICATIONS_INIT: getNotificationsInit,
GET_NOTIFICATIONS_DONE: getNotificationsDone,
MARK_NOTIFICATION_AS_READ_INIT: markNotificationAsReadInit,
MARK_NOTIFICATION_AS_READ_DONE: markNotificationAsReadDone,
MARK_ALL_NOTIFICATION_AS_READ_INIT: markAllNotificationAsReadInit,
MARK_ALL_NOTIFICATION_AS_READ_DONE: markAllNotificationAsReadDone,
MARK_ALL_NOTIFICATION_AS_SEEN_INIT: markAllNotificationAsSeenInit,
MARK_ALL_NOTIFICATION_AS_SEEN_DONE: markAllNotificationAsSeenDone,
DISMISS_CHALLENGE_NOTIFICATIONS_INIT: dismissChallengeNotificationsInit,
DISMISS_CHALLENGE_NOTIFICATIONS_DONE: dismissChallengeNotificationsDone,
},
});
3 changes: 3 additions & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import errors, { factory as errorsFactory } from './errors';
import challenge, { factory as challengeFactory } from './challenge';
import profile, { factory as profileFactory } from './profile';
import members, { factory as membersFactory } from './members';
import notifications, { factory as notificationsFactory } from './notifications';
import lookup, { factory as lookupFactory } from './lookup';
import memberTasks, { factory as memberTasksFactory } from './member-tasks';
import reviewOpportunity, { factory as reviewOpportunityFactory }
@@ -42,6 +43,7 @@ export function factory(options) {
settings: settingsFactory(options),
looker: lookerFactory(options),
memberSearch: memberSearchFactory(options),
notifications: notificationsFactory(options),
});
}

@@ -62,4 +64,5 @@ export default ({
settings,
looker,
memberSearch,
notifications,
});
Loading