Skip to content

Commit 2b091d3

Browse files
francoisTouchardEdificevmourot
authored andcommitted
feat(communities): PEDAGO-2918 adding notif handler
1 parent c9c2dec commit 2b091d3

File tree

2 files changed

+86
-5
lines changed

2 files changed

+86
-5
lines changed

assets/i18n/fr.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,7 @@
13861386
"timeline-apptype-collaborativeeditor": "Pad",
13871387
"timeline-apptype-collaborativewall": "Mur collaboratif",
13881388
"timeline-apptype-community": "Communautés",
1389+
"timeline-apptype-communities": "Communautés",
13891390
"timeline-apptype-crre": "CRRE",
13901391
"timeline-apptype-exercizer": "Exercices",
13911392
"timeline-apptype-formulaire": "Formulaires",
@@ -1457,6 +1458,15 @@
14571458
"timeline-notiftype-collaborativeeditor-unused": "Pad non modifié",
14581459
"timeline-notiftype-collaborativewall-share": "Partage de mur collaboratif",
14591460
"timeline-notiftype-community-share": "Partage d'une communauté",
1461+
"timeline-notiftype-communities-addmember": "Nouvel ajout à une communauté",
1462+
"timeline-notiftype-communities-announcementnew": "Nouveauté dans le fil d'annonces",
1463+
"timeline-notiftype-communities-coursepagenew": "Nouvelle page de cours",
1464+
"timeline-notiftype-communities-discussionmessagenew": "Nouveau message dans une discussion",
1465+
"timeline-notiftype-communities-joinrequestaccepted": "Demande d'ajout acceptée",
1466+
"timeline-notiftype-communities-joinrequestnew": "Nouvelle demande d'ajout",
1467+
"timeline-notiftype-communities-joinrequestpending": "Demande d'ajout en attente",
1468+
"timeline-notiftype-communities-joinrequestrejected": "Demande d'ajout refusée",
1469+
"timeline-notiftype-communities-resourcenew": "Nouveau document dans la communauté",
14601470
"timeline-notiftype-crre-newbasketnotification": "Nouvelle demande en attente de validation dans l'établissement",
14611471
"timeline-notiftype-crre-newordernotification": "Nouvelle demande en attente de traitement par la région",
14621472
"timeline-notiftype-crre-orderprescriptornotification": "Mise à jour du statut d'un panier",
Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,78 @@
1-
/**
2-
* Communities notif handler
3-
*/
1+
import { CommonActions } from '@react-navigation/native';
42

5-
import { registerNotifHandlers } from '~/framework/util/notifications/routing';
3+
import { communitiesRouteNames } from './navigation';
64

7-
export default () => registerNotifHandlers([]);
5+
import timelineModuleConfig from '~/framework/modules/timeline/module-config';
6+
import { computeTabRouteName } from '~/framework/navigation/tabModules';
7+
import { getAsResourceUriNotification } from '~/framework/util/notifications';
8+
import {
9+
handleNotificationNavigationAction,
10+
NotifHandlerThunkAction,
11+
registerNotifHandlers,
12+
} from '~/framework/util/notifications/routing';
13+
14+
const COMMUNITY_ID_REGEX = /\/community\/id\/([a-f0-9-]+)/i;
15+
16+
const handleCommunitiesNotificationAction: NotifHandlerThunkAction =
17+
(notification, allowSwitchTab) => async (dispatch, getState) => {
18+
try {
19+
const communityNotif = getAsResourceUriNotification(notification);
20+
if (!communityNotif) return { managed: 0 };
21+
22+
const communityUri = communityNotif?.resource.uri;
23+
const communityId = communityUri?.match(COMMUNITY_ID_REGEX)?.[1];
24+
if (!communityId) return { managed: 0 };
25+
26+
const navAction = CommonActions.navigate(
27+
allowSwitchTab
28+
? {
29+
name: computeTabRouteName(timelineModuleConfig.routeName),
30+
params: {
31+
initial: false,
32+
params: {
33+
fromTimeline: false,
34+
notification: communityNotif,
35+
resourceId: communityId,
36+
},
37+
screen: communitiesRouteNames.home,
38+
},
39+
}
40+
: {
41+
name: communitiesRouteNames.home,
42+
params: {
43+
fromTimeline: true,
44+
id: communityId,
45+
notification: communityNotif,
46+
},
47+
},
48+
);
49+
50+
handleNotificationNavigationAction(navAction);
51+
52+
return {
53+
managed: 1,
54+
trackInfo: { action: 'Communities', name: `${notification.type}.${notification['event-type']}` },
55+
};
56+
} catch {
57+
return { managed: 0 };
58+
}
59+
};
60+
61+
export default () =>
62+
registerNotifHandlers([
63+
{
64+
'event-type': [
65+
'add_member',
66+
'announcement_new',
67+
'course_page_new',
68+
'discussion_message_new',
69+
'join_request_new',
70+
'join_request_pending',
71+
'join_request_accepted',
72+
'join_request_rejected',
73+
'resource_new',
74+
],
75+
'notifHandlerAction': handleCommunitiesNotificationAction,
76+
'type': 'communities',
77+
},
78+
]);

0 commit comments

Comments
 (0)