Skip to content

Commit e201446

Browse files
authored
Merge pull request topcoder-platform#147 from topcoder-platform/develop
Feature - Notification
2 parents 97506da + 4ad8a9b commit e201446

File tree

9 files changed

+536
-2
lines changed

9 files changed

+536
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__coverage__
22
.build-info
33
.sass-cache
4-
dist
4+
#dist
55
node_modules
66
_auto_doc_
77
.vscode

__tests__/__snapshots__/index.js.snap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ Object {
106106
"getUserSrmDone": [Function],
107107
"getUserSrmInit": [Function],
108108
},
109+
"notifications": Object {
110+
"dismissChallengeNotificationsDone": [Function],
111+
"dismissChallengeNotificationsInit": [Function],
112+
"getNotificationsDone": [Function],
113+
"getNotificationsInit": [Function],
114+
"markAllNotificationAsReadDone": [Function],
115+
"markAllNotificationAsReadInit": [Function],
116+
"markAllNotificationAsSeenDone": [Function],
117+
"markAllNotificationAsSeenInit": [Function],
118+
"markNotificationAsReadDone": [Function],
119+
"markNotificationAsReadInit": [Function],
120+
},
109121
"profile": Object {
110122
"addSkillDone": [Function],
111123
"addSkillInit": [Function],
@@ -255,6 +267,7 @@ Object {
255267
"memberTasks": [Function],
256268
"members": [Function],
257269
"mySubmissionsManagement": [Function],
270+
"notifications": [Function],
258271
"profile": [Function],
259272
"reviewOpportunity": [Function],
260273
"settings": [Function],
@@ -312,6 +325,10 @@ Object {
312325
"default": undefined,
313326
"getService": [Function],
314327
},
328+
"notifications": Object {
329+
"default": undefined,
330+
"getService": [Function],
331+
},
315332
"reviewOpportunities": Object {
316333
"default": undefined,
317334
"getReviewOpportunitiesService": [Function],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
3232
"test": "npm run lint && npm run jest"
3333
},
34-
"version": "0.12.0",
34+
"version": "0.13.0",
3535
"dependencies": {
3636
"auth0-js": "^6.8.4",
3737
"config": "^3.2.0",

src/actions/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import lookupActions from './lookup';
1414
import settingsActions from './settings';
1515
import lookerActions from './looker';
1616
import memberSearchActions from './member-search';
17+
import notificationActions from './notifications';
1718

1819
export const actions = {
1920
auth: authActions.auth,
@@ -32,6 +33,7 @@ export const actions = {
3233
settings: settingsActions.settings,
3334
looker: lookerActions.looker,
3435
memberSearch: memberSearchActions.memberSearch,
36+
notifications: notificationActions.notifications,
3537
};
3638

3739
export default undefined;

src/actions/notifications.js

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/**
2+
* @module "actions.notifications"
3+
* @desc Actions related to notifications data.
4+
*/
5+
6+
import _ from 'lodash';
7+
import { createActions } from 'redux-actions';
8+
import { getService } from '../services/notifications';
9+
10+
/**
11+
* TODO: We will need to change this based on API and
12+
* frontend mapping we need later.
13+
*/
14+
function processData(data) {
15+
const retData = _.map(data, (item) => {
16+
const object = {};
17+
object.id = item.id;
18+
object.sourceId = item.contents.id;
19+
object.sourceName = item.contents.name || item.contents.title;
20+
object.eventType = item.type;
21+
object.isRead = item.read;
22+
object.isSeen = item.seen;
23+
object.contents = item.contents.message || item.contents.title;
24+
object.version = item.version;
25+
object.date = item.createdAt;
26+
return object;
27+
});
28+
return retData;
29+
}
30+
31+
/**
32+
* @static
33+
* @desc Creates an action that signals beginning of notifications
34+
* loading.
35+
* @return {Action}
36+
*/
37+
function getNotificationsInit() {
38+
return { };
39+
}
40+
41+
/**
42+
* @static
43+
* @desc Creates an action that loads member achievements.
44+
* @param {String} tokenV3 v3 auth token.
45+
* @return {Action}
46+
*/
47+
async function getNotificationsDone(tokenV3) {
48+
let data;
49+
try {
50+
data = await getService(tokenV3).getNotifications();
51+
} catch (e) {
52+
data = [];
53+
}
54+
return processData(data.items || []);
55+
}
56+
57+
/**
58+
* @static
59+
* @desc Creates an action that signals beginning of mark notification as read
60+
* loading.
61+
* @return {Action}
62+
*/
63+
function markNotificationAsReadInit() {
64+
return { };
65+
}
66+
67+
/**
68+
* @static
69+
* @desc Creates an action that marks notification as read.
70+
* @param {String} tokenV3 v3 auth token.
71+
* @return {Action}
72+
*/
73+
async function markNotificationAsReadDone(item, tokenV3) {
74+
try {
75+
await getService(tokenV3).markNotificationAsRead(item.id);
76+
} catch (e) {
77+
return e;
78+
}
79+
return item;
80+
}
81+
82+
/**
83+
* @static
84+
* @desc Creates an action that signals beginning of mark all notification as read
85+
* loading.
86+
* @return {Action}
87+
*/
88+
function markAllNotificationAsReadInit() {
89+
return { };
90+
}
91+
92+
/**
93+
* @static
94+
* @desc Creates an action that marks all notification as read.
95+
* @param {String} tokenV3 v3 auth token.
96+
* @return {Action}
97+
*/
98+
async function markAllNotificationAsReadDone(tokenV3) {
99+
try {
100+
await getService(tokenV3).markAllNotificationAsRead();
101+
} catch (e) {
102+
return e;
103+
}
104+
return true;
105+
}
106+
107+
108+
/**
109+
* @static
110+
* @desc Creates an action that signals beginning of mark all notification as seen
111+
* loading.
112+
* @return {Action}
113+
*/
114+
function markAllNotificationAsSeenInit() {
115+
return { };
116+
}
117+
118+
/**
119+
* @static
120+
* @desc Creates an action that marks all notification as seen.
121+
* @param {String} tokenV3 v3 auth token.
122+
* @return {Action}
123+
*/
124+
async function markAllNotificationAsSeenDone(items, tokenV3) {
125+
try {
126+
await getService(tokenV3).markAllNotificationAsSeen(items);
127+
} catch (e) {
128+
return e;
129+
}
130+
return items;
131+
}
132+
133+
134+
/**
135+
* @static
136+
* @desc Creates an action that signals beginning of dismiss all challenge notifications
137+
* loading.
138+
* @return {Action}
139+
*/
140+
function dismissChallengeNotificationsInit() {
141+
return { };
142+
}
143+
144+
/**
145+
* @static
146+
* @desc Creates an action that dismisses all challenge notifications
147+
* @param {String} tokenV3 v3 auth token.
148+
* @return {Action}
149+
*/
150+
async function dismissChallengeNotificationsDone(challengeId, tokenV3) {
151+
try {
152+
await getService(tokenV3).dismissChallengeNotifications(challengeId);
153+
} catch (e) {
154+
return e;
155+
}
156+
return true;
157+
}
158+
159+
160+
export default createActions({
161+
NOTIFICATIONS: {
162+
GET_NOTIFICATIONS_INIT: getNotificationsInit,
163+
GET_NOTIFICATIONS_DONE: getNotificationsDone,
164+
MARK_NOTIFICATION_AS_READ_INIT: markNotificationAsReadInit,
165+
MARK_NOTIFICATION_AS_READ_DONE: markNotificationAsReadDone,
166+
MARK_ALL_NOTIFICATION_AS_READ_INIT: markAllNotificationAsReadInit,
167+
MARK_ALL_NOTIFICATION_AS_READ_DONE: markAllNotificationAsReadDone,
168+
MARK_ALL_NOTIFICATION_AS_SEEN_INIT: markAllNotificationAsSeenInit,
169+
MARK_ALL_NOTIFICATION_AS_SEEN_DONE: markAllNotificationAsSeenDone,
170+
DISMISS_CHALLENGE_NOTIFICATIONS_INIT: dismissChallengeNotificationsInit,
171+
DISMISS_CHALLENGE_NOTIFICATIONS_DONE: dismissChallengeNotificationsDone,
172+
},
173+
});

src/reducers/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import errors, { factory as errorsFactory } from './errors';
1212
import challenge, { factory as challengeFactory } from './challenge';
1313
import profile, { factory as profileFactory } from './profile';
1414
import members, { factory as membersFactory } from './members';
15+
import notifications, { factory as notificationsFactory } from './notifications';
1516
import lookup, { factory as lookupFactory } from './lookup';
1617
import memberTasks, { factory as memberTasksFactory } from './member-tasks';
1718
import reviewOpportunity, { factory as reviewOpportunityFactory }
@@ -42,6 +43,7 @@ export function factory(options) {
4243
settings: settingsFactory(options),
4344
looker: lookerFactory(options),
4445
memberSearch: memberSearchFactory(options),
46+
notifications: notificationsFactory(options),
4547
});
4648
}
4749

@@ -62,4 +64,5 @@ export default ({
6264
settings,
6365
looker,
6466
memberSearch,
67+
notifications,
6568
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy