@selfcommunity/react-core 0.4.50-event.30 → 0.4.50-events.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/provider/SCAlertMessagesProvider/index.js +3 -4
- package/lib/cjs/components/provider/SCContextProvider/index.js +6 -5
- package/lib/cjs/components/provider/SCLocaleProvider/index.js +4 -6
- package/lib/cjs/components/provider/SCNotificationProvider/index.js +3 -2
- package/lib/cjs/components/provider/SCPreferencesProvider/index.js +18 -3
- package/lib/cjs/components/provider/SCRoutingProvider/index.js +3 -2
- package/lib/cjs/components/provider/SCThemeProvider/index.js +4 -5
- package/lib/cjs/components/provider/SCUserProvider/index.js +9 -2
- package/lib/cjs/components/provider/SCVoteProvider/index.js +3 -3
- package/lib/cjs/components/router/index.js +3 -2
- package/lib/cjs/constants/Cache.d.ts +8 -0
- package/lib/cjs/constants/Cache.js +11 -2
- package/lib/cjs/constants/Routes.d.ts +1 -0
- package/lib/cjs/constants/Routes.js +3 -1
- package/lib/cjs/hooks/useSCFetchEvent.d.ts +3 -1
- package/lib/cjs/hooks/useSCFetchEvent.js +18 -5
- package/lib/cjs/hooks/useSCFetchEvents.d.ts +22 -0
- package/lib/cjs/hooks/useSCFetchEvents.js +83 -0
- package/lib/cjs/hooks/useSCSubscribedEventsManager.d.ts +38 -0
- package/lib/cjs/hooks/useSCSubscribedEventsManager.js +297 -0
- package/lib/cjs/hooks/useSCWebPushMessaging.js +3 -4
- package/lib/cjs/index.d.ts +7 -3
- package/lib/cjs/index.js +11 -3
- package/lib/cjs/types/context.d.ts +52 -1
- package/lib/cjs/types/index.d.ts +2 -2
- package/lib/cjs/utils/event.d.ts +8 -0
- package/lib/cjs/utils/event.js +29 -0
- package/lib/cjs/utils/user.d.ts +7 -0
- package/lib/cjs/utils/user.js +11 -1
- package/lib/esm/components/provider/SCAlertMessagesProvider/index.js +3 -3
- package/lib/esm/components/provider/SCContextProvider/index.js +6 -5
- package/lib/esm/components/provider/SCLocaleProvider/index.js +4 -5
- package/lib/esm/components/provider/SCNotificationProvider/index.js +3 -2
- package/lib/esm/components/provider/SCPreferencesProvider/index.js +18 -2
- package/lib/esm/components/provider/SCRoutingProvider/index.js +3 -2
- package/lib/esm/components/provider/SCThemeProvider/index.js +4 -5
- package/lib/esm/components/provider/SCUserProvider/index.js +9 -2
- package/lib/esm/components/provider/SCVoteProvider/index.js +3 -2
- package/lib/esm/components/router/index.js +3 -2
- package/lib/esm/constants/Cache.d.ts +8 -0
- package/lib/esm/constants/Cache.js +8 -0
- package/lib/esm/constants/Routes.d.ts +1 -0
- package/lib/esm/constants/Routes.js +2 -0
- package/lib/esm/hooks/useSCFetchEvent.d.ts +3 -1
- package/lib/esm/hooks/useSCFetchEvent.js +19 -6
- package/lib/esm/hooks/useSCFetchEvents.d.ts +22 -0
- package/lib/esm/hooks/useSCFetchEvents.js +81 -0
- package/lib/esm/hooks/useSCSubscribedEventsManager.d.ts +38 -0
- package/lib/esm/hooks/useSCSubscribedEventsManager.js +293 -0
- package/lib/esm/hooks/useSCWebPushMessaging.js +3 -4
- package/lib/esm/index.d.ts +7 -3
- package/lib/esm/index.js +6 -2
- package/lib/esm/types/context.d.ts +52 -1
- package/lib/esm/types/index.d.ts +2 -2
- package/lib/esm/utils/event.d.ts +8 -0
- package/lib/esm/utils/event.js +25 -0
- package/lib/esm/utils/user.d.ts +7 -0
- package/lib/esm/utils/user.js +9 -0
- package/lib/umd/react-core.js +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { Endpoints, http } from '@selfcommunity/api-services';
|
|
2
|
+
import { SCEventSubscriptionStatusType, SCFeatureName, SCNotificationTopicType, SCNotificationTypologyType, } from '@selfcommunity/types';
|
|
3
|
+
import { Logger } from '@selfcommunity/utils';
|
|
4
|
+
import PubSub from 'pubsub-js';
|
|
5
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
6
|
+
import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect';
|
|
7
|
+
import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
|
|
8
|
+
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
9
|
+
import { SCNotificationMapping } from '../constants/Notification';
|
|
10
|
+
import useSCCachingManager from './useSCCachingManager';
|
|
11
|
+
import { getEventStatus } from '../utils/event';
|
|
12
|
+
/**
|
|
13
|
+
:::info
|
|
14
|
+
This custom hook is used to manage the events followed.
|
|
15
|
+
:::
|
|
16
|
+
|
|
17
|
+
:::tip How to use it:
|
|
18
|
+
Follow these steps:
|
|
19
|
+
```jsx
|
|
20
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
21
|
+
2. const scSubscribedEventsManager: SCSubscribedEventsManagerType = scUserContext.manager.events;
|
|
22
|
+
3. scSubscribedEventsManager.isSubscribed(event)
|
|
23
|
+
```
|
|
24
|
+
:::
|
|
25
|
+
*/
|
|
26
|
+
export default function useSCSubscribedEventsManager(user) {
|
|
27
|
+
const { cache, updateCache, emptyCache, data, setData, loading, setLoading, setUnLoading, isLoading } = useSCCachingManager();
|
|
28
|
+
const { features } = useSCPreferences();
|
|
29
|
+
const authUserId = user ? user.id : null;
|
|
30
|
+
const eventsEnabled = useMemo(() => features && features.includes(SCFeatureName.EVENT) && features.includes(SCFeatureName.TAGGING), [features]);
|
|
31
|
+
const notificationInvitedToJoinEvent = useRef(null);
|
|
32
|
+
const notificationRequestedToJoinEvent = useRef(null);
|
|
33
|
+
const notificationAcceptedToJoinEvent = useRef(null);
|
|
34
|
+
const notificationAddedToEvent = useRef(null);
|
|
35
|
+
/**
|
|
36
|
+
* Subscribe to notification types user_follow, user_unfollow
|
|
37
|
+
*/
|
|
38
|
+
useDeepCompareEffectNoCheck(() => {
|
|
39
|
+
notificationInvitedToJoinEvent.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_INVITED_TO_JOIN_EVENT}`, notificationSubscriber);
|
|
40
|
+
notificationRequestedToJoinEvent.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_EVENT}`, notificationSubscriber);
|
|
41
|
+
notificationAcceptedToJoinEvent.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_EVENT}`, notificationSubscriber);
|
|
42
|
+
notificationAddedToEvent.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ADDED_TO_EVENT}`, notificationSubscriber);
|
|
43
|
+
return () => {
|
|
44
|
+
PubSub.unsubscribe(notificationInvitedToJoinEvent.current);
|
|
45
|
+
PubSub.unsubscribe(notificationRequestedToJoinEvent.current);
|
|
46
|
+
PubSub.unsubscribe(notificationAcceptedToJoinEvent.current);
|
|
47
|
+
PubSub.unsubscribe(notificationAddedToEvent.current);
|
|
48
|
+
};
|
|
49
|
+
}, [data]);
|
|
50
|
+
/**
|
|
51
|
+
* Notification subscriber handler
|
|
52
|
+
* @param msg
|
|
53
|
+
* @param dataMsg
|
|
54
|
+
*/
|
|
55
|
+
const notificationSubscriber = (msg, dataMsg) => {
|
|
56
|
+
if (dataMsg.data.event !== undefined) {
|
|
57
|
+
let _status;
|
|
58
|
+
switch (SCNotificationMapping[dataMsg.data.activity_type]) {
|
|
59
|
+
case SCNotificationTypologyType.USER_INVITED_TO_JOIN_EVENT:
|
|
60
|
+
_status = SCEventSubscriptionStatusType.INVITED;
|
|
61
|
+
break;
|
|
62
|
+
case SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_EVENT:
|
|
63
|
+
_status = SCEventSubscriptionStatusType.REQUESTED;
|
|
64
|
+
break;
|
|
65
|
+
case SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_EVENT:
|
|
66
|
+
_status = SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
67
|
+
break;
|
|
68
|
+
case SCNotificationTypologyType.USER_ADDED_TO_EVENT:
|
|
69
|
+
_status = SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
updateCache([dataMsg.data.event.id]);
|
|
73
|
+
setData((prev) => getDataUpdated(prev, dataMsg.data.event.id, _status));
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Memoized refresh all events
|
|
78
|
+
* It makes a single request to the server and retrieves
|
|
79
|
+
* all the events followed by the user in a single solution
|
|
80
|
+
* It might be useful for multi-tab sync
|
|
81
|
+
*/
|
|
82
|
+
const refresh = useMemo(() => () => {
|
|
83
|
+
emptyCache();
|
|
84
|
+
if (user) {
|
|
85
|
+
// Only if user is authenticated
|
|
86
|
+
http
|
|
87
|
+
.request({
|
|
88
|
+
url: Endpoints.GetUserEvents.url(),
|
|
89
|
+
method: Endpoints.GetUserEvents.method,
|
|
90
|
+
})
|
|
91
|
+
.then((res) => {
|
|
92
|
+
if (res.status >= 300) {
|
|
93
|
+
return Promise.reject(res);
|
|
94
|
+
}
|
|
95
|
+
const eventsIds = res.data.results.map((e) => e.id);
|
|
96
|
+
updateCache(eventsIds);
|
|
97
|
+
setData(res.data.results.map((e) => ({ [e.id]: e.subscription_status })));
|
|
98
|
+
return Promise.resolve(res.data);
|
|
99
|
+
})
|
|
100
|
+
.catch((e) => {
|
|
101
|
+
Logger.error(SCOPE_SC_CORE, 'Unable to refresh the authenticated user events.');
|
|
102
|
+
Logger.error(SCOPE_SC_CORE, e);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}, [data, user, cache]);
|
|
106
|
+
/**
|
|
107
|
+
* Memoized toggleEventAttendance Event
|
|
108
|
+
* Toggle action
|
|
109
|
+
*/
|
|
110
|
+
const toggleEventAttendance = useMemo(() => (event, userId) => {
|
|
111
|
+
setLoading(event.id);
|
|
112
|
+
if (userId) {
|
|
113
|
+
return http
|
|
114
|
+
.request({
|
|
115
|
+
url: Endpoints.InviteOrAcceptEventRequest.url({ id: event.id }),
|
|
116
|
+
method: Endpoints.InviteOrAcceptEventRequest.method,
|
|
117
|
+
data: { users: [userId] },
|
|
118
|
+
})
|
|
119
|
+
.then((res) => {
|
|
120
|
+
if (res.status >= 300) {
|
|
121
|
+
return Promise.reject(res);
|
|
122
|
+
}
|
|
123
|
+
updateCache([event.id]);
|
|
124
|
+
setData((prev) => getDataUpdated(prev, event.id, SCEventSubscriptionStatusType.SUBSCRIBED));
|
|
125
|
+
setUnLoading(event.id);
|
|
126
|
+
return Promise.resolve(res.data);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const requestConfig = !event.subscription_status || event.subscription_status === SCEventSubscriptionStatusType.INVITED
|
|
131
|
+
? {
|
|
132
|
+
url: Endpoints.SubscribeToEvent.url({ id: event.id }),
|
|
133
|
+
method: Endpoints.SubscribeToEvent.method,
|
|
134
|
+
}
|
|
135
|
+
: event.subscription_status === SCEventSubscriptionStatusType.GOING
|
|
136
|
+
? {
|
|
137
|
+
url: Endpoints.RemoveGoingToEvent.url({ id: event.id }),
|
|
138
|
+
method: Endpoints.RemoveGoingToEvent.method,
|
|
139
|
+
}
|
|
140
|
+
: {
|
|
141
|
+
url: Endpoints.GoToEvent.url({ id: event.id }),
|
|
142
|
+
method: Endpoints.GoToEvent.method,
|
|
143
|
+
};
|
|
144
|
+
return http.request(requestConfig).then((res) => {
|
|
145
|
+
if (res.status >= 300) {
|
|
146
|
+
return Promise.reject(res);
|
|
147
|
+
}
|
|
148
|
+
updateCache([event.id]);
|
|
149
|
+
setData((prev) => getDataUpdated(prev, event.id, getEventStatus(event, true)));
|
|
150
|
+
setUnLoading(event.id);
|
|
151
|
+
return Promise.resolve(res.data);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}, [data, loading, cache]);
|
|
155
|
+
/**
|
|
156
|
+
* Memoized toggleEventNonattendance Event
|
|
157
|
+
* Toggle action
|
|
158
|
+
*/
|
|
159
|
+
const toggleEventNonattendance = useMemo(() => (event) => {
|
|
160
|
+
if (event.subscription_status !== SCEventSubscriptionStatusType.REQUESTED) {
|
|
161
|
+
setLoading(event.id);
|
|
162
|
+
const requestConfig = event.subscription_status === SCEventSubscriptionStatusType.NOT_GOING
|
|
163
|
+
? {
|
|
164
|
+
url: Endpoints.RemoveNotGoingToEvent.url({ id: event.id }),
|
|
165
|
+
method: Endpoints.RemoveNotGoingToEvent.method,
|
|
166
|
+
}
|
|
167
|
+
: {
|
|
168
|
+
url: Endpoints.NotGoingToEvent.url({ id: event.id }),
|
|
169
|
+
method: Endpoints.NotGoingToEvent.method,
|
|
170
|
+
};
|
|
171
|
+
return http.request(requestConfig).then((res) => {
|
|
172
|
+
if (res.status >= 300) {
|
|
173
|
+
return Promise.reject(res);
|
|
174
|
+
}
|
|
175
|
+
updateCache([event.id]);
|
|
176
|
+
setData((prev) => getDataUpdated(prev, event.id, getEventStatus(event, false)));
|
|
177
|
+
setUnLoading(event.id);
|
|
178
|
+
return Promise.resolve(res.data);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
setLoading(event.id);
|
|
183
|
+
return http
|
|
184
|
+
.request({ url: Endpoints.UnsubscribeFromEvent.url({ id: event.id }), method: Endpoints.UnsubscribeFromEvent.method })
|
|
185
|
+
.then((res) => {
|
|
186
|
+
if (res.status >= 300) {
|
|
187
|
+
return Promise.reject(res);
|
|
188
|
+
}
|
|
189
|
+
updateCache([event.id]);
|
|
190
|
+
setData((prev) => getDataUpdated(prev, event.id, null));
|
|
191
|
+
setUnLoading(event.id);
|
|
192
|
+
return Promise.resolve(res.data);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}, [data, loading, cache]);
|
|
196
|
+
/**
|
|
197
|
+
* Check the authenticated user subscription status to the event
|
|
198
|
+
* Update the events cached
|
|
199
|
+
* Update events subscription statuses
|
|
200
|
+
* @param event
|
|
201
|
+
*/
|
|
202
|
+
const checkEventSubscriptionStatus = (event) => {
|
|
203
|
+
setLoading(event.id);
|
|
204
|
+
return http
|
|
205
|
+
.request({
|
|
206
|
+
url: Endpoints.GetEventSubscriptionStatus.url({ id: event.id }),
|
|
207
|
+
method: Endpoints.GetEventSubscriptionStatus.method,
|
|
208
|
+
})
|
|
209
|
+
.then((res) => {
|
|
210
|
+
if (res.status >= 300) {
|
|
211
|
+
return Promise.reject(res);
|
|
212
|
+
}
|
|
213
|
+
setData((prev) => getDataUpdated(prev, event.id, res.data.status));
|
|
214
|
+
updateCache([event.id]);
|
|
215
|
+
setUnLoading(event.id);
|
|
216
|
+
return Promise.resolve(res.data);
|
|
217
|
+
})
|
|
218
|
+
.catch((e) => {
|
|
219
|
+
setUnLoading(event.id);
|
|
220
|
+
return Promise.reject(e);
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Get updated data
|
|
225
|
+
* @param data
|
|
226
|
+
* @param eventId
|
|
227
|
+
* @param subscriptionStatus
|
|
228
|
+
*/
|
|
229
|
+
const getDataUpdated = (data, eventId, subscriptionStatus) => {
|
|
230
|
+
const _index = data.findIndex((k) => parseInt(Object.keys(k)[0]) === eventId);
|
|
231
|
+
let _data;
|
|
232
|
+
if (_index < 0) {
|
|
233
|
+
_data = [...data, ...[{ [eventId]: subscriptionStatus }]];
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
_data = data.map((k, i) => {
|
|
237
|
+
if (parseInt(Object.keys(k)[0]) === eventId) {
|
|
238
|
+
return { [Object.keys(k)[0]]: subscriptionStatus };
|
|
239
|
+
}
|
|
240
|
+
return { [Object.keys(k)[0]]: data[i][Object.keys(k)[0]] };
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
return _data;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Return current event subscription status if exists,
|
|
247
|
+
* otherwise return null
|
|
248
|
+
*/
|
|
249
|
+
const getCurrentEventCacheStatus = useMemo(() => (event) => {
|
|
250
|
+
const d = data.filter((k) => parseInt(Object.keys(k)[0]) === event.id);
|
|
251
|
+
return d.length ? d[0][event.id] : !data.length ? event.subscription_status : null;
|
|
252
|
+
}, [data]);
|
|
253
|
+
/**
|
|
254
|
+
* Bypass remote check if the event is subscribed
|
|
255
|
+
*/
|
|
256
|
+
const getSubscriptionStatus = useMemo(() => (event) => {
|
|
257
|
+
updateCache([event.id]);
|
|
258
|
+
setData((prev) => getDataUpdated(prev, event.id, event.subscription_status));
|
|
259
|
+
return event.subscription_status;
|
|
260
|
+
}, [data, cache]);
|
|
261
|
+
/**
|
|
262
|
+
* Memoized subscriptionStatus
|
|
263
|
+
* If event is already in cache -> check if the event is in events,
|
|
264
|
+
* otherwise, check if user toggleEventAttendance the event
|
|
265
|
+
*/
|
|
266
|
+
const subscriptionStatus = useMemo(() => (event) => {
|
|
267
|
+
// Cache is valid also for anonymous user
|
|
268
|
+
if (cache.includes(event === null || event === void 0 ? void 0 : event.id)) {
|
|
269
|
+
return getCurrentEventCacheStatus(event);
|
|
270
|
+
}
|
|
271
|
+
if (authUserId && event) {
|
|
272
|
+
if ('subscription_status' in event) {
|
|
273
|
+
return getSubscriptionStatus(event);
|
|
274
|
+
}
|
|
275
|
+
if (!isLoading(event)) {
|
|
276
|
+
checkEventSubscriptionStatus(event);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return null;
|
|
280
|
+
}, [loading, cache, authUserId]);
|
|
281
|
+
/**
|
|
282
|
+
* Empty cache on logout
|
|
283
|
+
*/
|
|
284
|
+
useEffect(() => {
|
|
285
|
+
if (!authUserId) {
|
|
286
|
+
emptyCache();
|
|
287
|
+
}
|
|
288
|
+
}, [authUserId]);
|
|
289
|
+
if (!eventsEnabled || !user) {
|
|
290
|
+
return { events: data, loading, isLoading };
|
|
291
|
+
}
|
|
292
|
+
return { events: data, loading, isLoading, toggleEventAttendance, toggleEventNonattendance, subscriptionStatus, refresh, emptyCache };
|
|
293
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useEffect, useRef, useState } from 'react';
|
|
2
3
|
import { useSCContext } from '../components/provider/SCContextProvider';
|
|
3
4
|
import { useSCUser } from '../components/provider/SCUserProvider';
|
|
4
5
|
import { Logger } from '@selfcommunity/utils';
|
|
@@ -56,9 +57,7 @@ export default function useSCWebPushMessaging() {
|
|
|
56
57
|
const showCustomRequestNotificationSnackbar = () => {
|
|
57
58
|
if (!Cookies.get(NOTIFICATIONS_WEB_PUSH_MESSAGING_DIALOG_COOKIE)) {
|
|
58
59
|
enqueueSnackbar(intl.formatMessage({ id: 'ui.webPushNotification.requestPermission', defaultMessage: 'ui.webPushNotification.requestPermission' }), {
|
|
59
|
-
action: (snackbarId) => (
|
|
60
|
-
React.createElement(Button, { size: "small", sx: { color: '#FFF' }, onClick: () => requestNotificationPermission(snackbarId) }, intl.formatMessage({ id: 'ui.webPushNotification.allow', defaultMessage: 'ui.webPushNotification.allow' })),
|
|
61
|
-
React.createElement(Button, { size: "small", sx: { color: '#FFF' }, onClick: () => closeRequestNotificationSnackbar(snackbarId) }, intl.formatMessage({ id: 'ui.webPushNotification.block', defaultMessage: 'ui.webPushNotification.block' })))),
|
|
60
|
+
action: (snackbarId) => (_jsxs(_Fragment, { children: [_jsx(Button, Object.assign({ size: "small", sx: { color: '#FFF' }, onClick: () => requestNotificationPermission(snackbarId) }, { children: intl.formatMessage({ id: 'ui.webPushNotification.allow', defaultMessage: 'ui.webPushNotification.allow' }) })), _jsx(Button, Object.assign({ size: "small", sx: { color: '#FFF' }, onClick: () => closeRequestNotificationSnackbar(snackbarId) }, { children: intl.formatMessage({ id: 'ui.webPushNotification.block', defaultMessage: 'ui.webPushNotification.block' }) }))] })),
|
|
62
61
|
variant: 'default',
|
|
63
62
|
anchorOrigin: { horizontal: 'center', vertical: 'bottom' },
|
|
64
63
|
preventDuplicate: true,
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Types
|
|
3
3
|
*/
|
|
4
|
-
import { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCFollowedManagerType, SCFollowersManagerType, SCSettingsManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType } from './types';
|
|
4
|
+
import { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCFollowedManagerType, SCFollowersManagerType, SCSettingsManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* ContextProvider component
|
|
7
7
|
*/
|
|
@@ -63,6 +63,7 @@ import useSCUserIsBlocked from './hooks/useSCUserIsBlocked';
|
|
|
63
63
|
import useSCFetchGroup from './hooks/useSCFetchGroup';
|
|
64
64
|
import useSCFetchGroups from './hooks/useSCFetchGroups';
|
|
65
65
|
import useSCFetchEvent from './hooks/useSCFetchEvent';
|
|
66
|
+
import useSCFetchEvents from './hooks/useSCFetchEvents';
|
|
66
67
|
/**
|
|
67
68
|
* Routing component
|
|
68
69
|
*/
|
|
@@ -73,13 +74,16 @@ import * as SCRoutes from './constants/Routes';
|
|
|
73
74
|
* User, hooks (useIsComponentMountedRef)
|
|
74
75
|
*/
|
|
75
76
|
import * as UserUtils from './utils/user';
|
|
77
|
+
import getTheme from './themes/theme';
|
|
76
78
|
import { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect } from './utils/hooks';
|
|
79
|
+
import { getEventStatus } from './utils/event';
|
|
77
80
|
/**
|
|
78
81
|
* Constants:
|
|
79
|
-
* Locale
|
|
82
|
+
* Locale, Preferences
|
|
80
83
|
*/
|
|
81
84
|
import * as Locale from './constants/Locale';
|
|
85
|
+
import * as Preferences from './constants/Preferences';
|
|
82
86
|
/**
|
|
83
87
|
* List all exports
|
|
84
88
|
*/
|
|
85
|
-
export { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCSettingsManagerType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, Locale, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent };
|
|
89
|
+
export { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCSettingsManagerType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, };
|
package/lib/esm/index.js
CHANGED
|
@@ -59,6 +59,7 @@ import useSCUserIsBlocked from './hooks/useSCUserIsBlocked';
|
|
|
59
59
|
import useSCFetchGroup from './hooks/useSCFetchGroup';
|
|
60
60
|
import useSCFetchGroups from './hooks/useSCFetchGroups';
|
|
61
61
|
import useSCFetchEvent from './hooks/useSCFetchEvent';
|
|
62
|
+
import useSCFetchEvents from './hooks/useSCFetchEvents';
|
|
62
63
|
/**
|
|
63
64
|
* Routing component
|
|
64
65
|
*/
|
|
@@ -69,13 +70,16 @@ import * as SCRoutes from './constants/Routes';
|
|
|
69
70
|
* User, hooks (useIsComponentMountedRef)
|
|
70
71
|
*/
|
|
71
72
|
import * as UserUtils from './utils/user';
|
|
73
|
+
import getTheme from './themes/theme';
|
|
72
74
|
import { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect } from './utils/hooks';
|
|
75
|
+
import { getEventStatus } from './utils/event';
|
|
73
76
|
/**
|
|
74
77
|
* Constants:
|
|
75
|
-
* Locale
|
|
78
|
+
* Locale, Preferences
|
|
76
79
|
*/
|
|
77
80
|
import * as Locale from './constants/Locale';
|
|
81
|
+
import * as Preferences from './constants/Preferences';
|
|
78
82
|
/**
|
|
79
83
|
* List all exports
|
|
80
84
|
*/
|
|
81
|
-
export { SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, Locale, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent };
|
|
85
|
+
export { SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { SCAuthTokenType, SCIncubatorType, SCCategoryType, SCUserType, SCUserSettingsType, SCReactionType, SCGroupType } from '@selfcommunity/types';
|
|
2
|
+
import { SCAuthTokenType, SCIncubatorType, SCCategoryType, SCUserType, SCUserSettingsType, SCReactionType, SCGroupType, SCEventType } from '@selfcommunity/types';
|
|
3
3
|
import { SCThemeType } from './theme';
|
|
4
4
|
/**
|
|
5
5
|
* Interface SCSettingsType
|
|
@@ -147,6 +147,7 @@ export interface SCUserContextType {
|
|
|
147
147
|
incubators?: SCSubscribedIncubatorsManagerType;
|
|
148
148
|
blockedUsers?: SCBlockedUsersManagerType;
|
|
149
149
|
groups?: SCSubscribedGroupsManagerType;
|
|
150
|
+
events?: SCSubscribedEventsManagerType;
|
|
150
151
|
};
|
|
151
152
|
}
|
|
152
153
|
export interface SCSettingsManagerType {
|
|
@@ -253,6 +254,44 @@ export interface SCFollowedCategoriesManagerType {
|
|
|
253
254
|
*/
|
|
254
255
|
emptyCache?: () => void;
|
|
255
256
|
}
|
|
257
|
+
export interface SCSubscribedEventsManagerType {
|
|
258
|
+
/**
|
|
259
|
+
* List of all events ids followed by the authenticated user
|
|
260
|
+
*/
|
|
261
|
+
events: number[];
|
|
262
|
+
/**
|
|
263
|
+
* List of all events in loading state
|
|
264
|
+
*/
|
|
265
|
+
loading: number[];
|
|
266
|
+
/**
|
|
267
|
+
* List of current events in loading state
|
|
268
|
+
*/
|
|
269
|
+
isLoading: (event: SCEventType) => boolean;
|
|
270
|
+
/**
|
|
271
|
+
* Handle user subscription to an event
|
|
272
|
+
*/
|
|
273
|
+
subscribe?: (event: SCEventType, userId?: number) => Promise<any>;
|
|
274
|
+
/**
|
|
275
|
+
* Handle user going to an event
|
|
276
|
+
*/
|
|
277
|
+
toggleEventAttendance?: (event: SCEventType, userId?: number) => Promise<any>;
|
|
278
|
+
/**
|
|
279
|
+
* Handle user not going to an event
|
|
280
|
+
*/
|
|
281
|
+
toggleEventNonattendance?: (event: SCEventType, userId?: number) => Promise<any>;
|
|
282
|
+
/**
|
|
283
|
+
* Handles a user subscription status to an event, caching data
|
|
284
|
+
*/
|
|
285
|
+
subscriptionStatus?: (event: SCEventType) => string;
|
|
286
|
+
/**
|
|
287
|
+
* Refresh groups
|
|
288
|
+
*/
|
|
289
|
+
refresh?: () => void;
|
|
290
|
+
/**
|
|
291
|
+
* Empty cache to revalidate all groups
|
|
292
|
+
*/
|
|
293
|
+
emptyCache?: () => void;
|
|
294
|
+
}
|
|
256
295
|
export interface SCSubscribedGroupsManagerType {
|
|
257
296
|
/**
|
|
258
297
|
* List of all groups ids followed by the authenticated user
|
|
@@ -448,6 +487,18 @@ export interface SCPreferencesContextType {
|
|
|
448
487
|
* List of all community enabled features
|
|
449
488
|
*/
|
|
450
489
|
features: string[];
|
|
490
|
+
/**
|
|
491
|
+
* Set prefrerences
|
|
492
|
+
*/
|
|
493
|
+
setPreferences: (preferences: Record<string, any>) => void;
|
|
494
|
+
/**
|
|
495
|
+
* Set features
|
|
496
|
+
*/
|
|
497
|
+
setFeatures: (features: string[]) => void;
|
|
498
|
+
/**
|
|
499
|
+
* Force refresh
|
|
500
|
+
*/
|
|
501
|
+
refresh: () => void;
|
|
451
502
|
}
|
|
452
503
|
/**
|
|
453
504
|
* Interface SCVoteContextType
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SCUserContextType, SCFollowedManagerType, SCFollowersManagerType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCSubscribedIncubatorsManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCPreferencesContextType, SCNotificationContextType, SCLocaleType, SCVoteType, SCVoteContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCSubscribedGroupsManagerType } from './context';
|
|
1
|
+
import { SCUserContextType, SCFollowedManagerType, SCFollowersManagerType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCSubscribedIncubatorsManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCPreferencesContextType, SCNotificationContextType, SCLocaleType, SCVoteType, SCVoteContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType } from './context';
|
|
2
2
|
import { SCThemeAvatarVariableType, SCThemeUserVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType } from './theme';
|
|
3
|
-
export { SCUserContextType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCVoteType, SCVoteContextType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeUserVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, };
|
|
3
|
+
export { SCUserContextType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCVoteType, SCVoteContextType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeUserVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SCEventSubscriptionStatusType, SCEventType } from '@selfcommunity/types';
|
|
2
|
+
/**
|
|
3
|
+
* Get event status
|
|
4
|
+
* @returns status or null
|
|
5
|
+
* @param event
|
|
6
|
+
* @param going
|
|
7
|
+
*/
|
|
8
|
+
export declare function getEventStatus(event: SCEventType, going: boolean): SCEventSubscriptionStatusType | null;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SCEventPrivacyType, SCEventSubscriptionStatusType } from '@selfcommunity/types';
|
|
2
|
+
/**
|
|
3
|
+
* Get event status
|
|
4
|
+
* @returns status or null
|
|
5
|
+
* @param event
|
|
6
|
+
* @param going
|
|
7
|
+
*/
|
|
8
|
+
export function getEventStatus(event, going) {
|
|
9
|
+
const { subscription_status: status, privacy } = event;
|
|
10
|
+
if (!status) {
|
|
11
|
+
return privacy === SCEventPrivacyType.PRIVATE ? SCEventSubscriptionStatusType.REQUESTED : SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
12
|
+
}
|
|
13
|
+
switch (status) {
|
|
14
|
+
case SCEventSubscriptionStatusType.INVITED:
|
|
15
|
+
case SCEventSubscriptionStatusType.GOING:
|
|
16
|
+
case SCEventSubscriptionStatusType.NOT_GOING:
|
|
17
|
+
return SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
18
|
+
case SCEventSubscriptionStatusType.SUBSCRIBED:
|
|
19
|
+
return going ? SCEventSubscriptionStatusType.GOING : SCEventSubscriptionStatusType.NOT_GOING;
|
|
20
|
+
case SCEventSubscriptionStatusType.REQUESTED:
|
|
21
|
+
return privacy === SCEventPrivacyType.PRIVATE ? null : SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
22
|
+
default:
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/lib/esm/utils/user.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { SCUserType } from '@selfcommunity/types';
|
|
|
6
6
|
export declare const ADMIN_ROLE = "admin";
|
|
7
7
|
export declare const MODERATOR_ROLE = "moderator";
|
|
8
8
|
export declare const EDITOR_ROLE = "editor";
|
|
9
|
+
export declare const COMMUNITY_CREATOR = 1;
|
|
9
10
|
/**
|
|
10
11
|
* Get user role from roles(set)
|
|
11
12
|
* @param user
|
|
@@ -18,6 +19,12 @@ export declare function getUserRole(user: SCUserType): string | null;
|
|
|
18
19
|
* @returns boolean
|
|
19
20
|
*/
|
|
20
21
|
export declare function isAdmin(user: SCUserType): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Check if user is admin
|
|
24
|
+
* @param user
|
|
25
|
+
* @returns boolean
|
|
26
|
+
*/
|
|
27
|
+
export declare function isCommunityCreator(user: SCUserType): boolean;
|
|
21
28
|
/**
|
|
22
29
|
* Check if user is moderator
|
|
23
30
|
* @param user
|
package/lib/esm/utils/user.js
CHANGED
|
@@ -6,6 +6,7 @@ import { SCUserStatus } from '@selfcommunity/types';
|
|
|
6
6
|
export const ADMIN_ROLE = 'admin';
|
|
7
7
|
export const MODERATOR_ROLE = 'moderator';
|
|
8
8
|
export const EDITOR_ROLE = 'editor';
|
|
9
|
+
export const COMMUNITY_CREATOR = 1;
|
|
9
10
|
/**
|
|
10
11
|
* Get user role from roles(set)
|
|
11
12
|
* @param user
|
|
@@ -34,6 +35,14 @@ export function getUserRole(user) {
|
|
|
34
35
|
export function isAdmin(user) {
|
|
35
36
|
return getUserRole(user) === ADMIN_ROLE;
|
|
36
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if user is admin
|
|
40
|
+
* @param user
|
|
41
|
+
* @returns boolean
|
|
42
|
+
*/
|
|
43
|
+
export function isCommunityCreator(user) {
|
|
44
|
+
return user && user.id === COMMUNITY_CREATOR;
|
|
45
|
+
}
|
|
37
46
|
/**
|
|
38
47
|
* Check if user is moderator
|
|
39
48
|
* @param user
|