@selfcommunity/react-core 0.4.50-alpha.1 → 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 +13 -6
- 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 +11 -0
- package/lib/cjs/constants/Cache.js +15 -2
- package/lib/cjs/constants/Integrations.d.ts +13 -0
- package/lib/cjs/constants/Integrations.js +17 -0
- package/lib/cjs/constants/Notifications.d.ts +2 -1
- package/lib/cjs/constants/Notifications.js +4 -3
- package/lib/cjs/constants/Preferences.d.ts +3 -0
- package/lib/cjs/constants/Preferences.js +8 -2
- package/lib/cjs/constants/Routes.d.ts +5 -0
- package/lib/cjs/constants/Routes.js +11 -1
- package/lib/cjs/hooks/useSCFetchEvent.d.ts +22 -0
- package/lib/cjs/hooks/useSCFetchEvent.js +87 -0
- 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 +8 -3
- package/lib/cjs/index.js +13 -3
- package/lib/cjs/types/context.d.ts +89 -1
- package/lib/cjs/types/index.d.ts +2 -2
- package/lib/cjs/utils/errors.d.ts +6 -0
- package/lib/cjs/utils/errors.js +12 -0
- package/lib/cjs/utils/event.d.ts +8 -0
- package/lib/cjs/utils/event.js +29 -0
- package/lib/cjs/utils/hooks/useIsomorphicLayoutEffect.js +2 -1
- package/lib/cjs/utils/notification.js +1 -1
- package/lib/cjs/utils/user.d.ts +7 -0
- package/lib/cjs/utils/user.js +11 -1
- package/lib/cjs/utils/validator.d.ts +103 -28
- package/lib/cjs/utils/validator.js +178 -31
- 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 +14 -7
- 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 +11 -0
- package/lib/esm/constants/Cache.js +11 -0
- package/lib/esm/constants/Integrations.d.ts +13 -0
- package/lib/esm/constants/Integrations.js +14 -0
- package/lib/esm/constants/Notifications.d.ts +2 -1
- package/lib/esm/constants/Notifications.js +3 -2
- package/lib/esm/constants/Preferences.d.ts +3 -0
- package/lib/esm/constants/Preferences.js +6 -0
- package/lib/esm/constants/Routes.d.ts +5 -0
- package/lib/esm/constants/Routes.js +10 -0
- package/lib/esm/hooks/useSCFetchEvent.d.ts +22 -0
- package/lib/esm/hooks/useSCFetchEvent.js +84 -0
- 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 +8 -3
- package/lib/esm/index.js +7 -2
- package/lib/esm/types/context.d.ts +89 -1
- package/lib/esm/types/index.d.ts +2 -2
- package/lib/esm/utils/errors.d.ts +6 -0
- package/lib/esm/utils/errors.js +12 -0
- package/lib/esm/utils/event.d.ts +8 -0
- package/lib/esm/utils/event.js +25 -0
- package/lib/esm/utils/hooks/useIsomorphicLayoutEffect.js +2 -1
- package/lib/esm/utils/notification.js +2 -2
- package/lib/esm/utils/user.d.ts +7 -0
- package/lib/esm/utils/user.js +9 -0
- package/lib/esm/utils/validator.d.ts +103 -28
- package/lib/esm/utils/validator.js +171 -30
- 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
|
*/
|
|
@@ -62,6 +62,8 @@ import useSCFetchUserBlockedBy from './hooks/useSCFetchUserBlockedBy';
|
|
|
62
62
|
import useSCUserIsBlocked from './hooks/useSCUserIsBlocked';
|
|
63
63
|
import useSCFetchGroup from './hooks/useSCFetchGroup';
|
|
64
64
|
import useSCFetchGroups from './hooks/useSCFetchGroups';
|
|
65
|
+
import useSCFetchEvent from './hooks/useSCFetchEvent';
|
|
66
|
+
import useSCFetchEvents from './hooks/useSCFetchEvents';
|
|
65
67
|
/**
|
|
66
68
|
* Routing component
|
|
67
69
|
*/
|
|
@@ -72,13 +74,16 @@ import * as SCRoutes from './constants/Routes';
|
|
|
72
74
|
* User, hooks (useIsComponentMountedRef)
|
|
73
75
|
*/
|
|
74
76
|
import * as UserUtils from './utils/user';
|
|
77
|
+
import getTheme from './themes/theme';
|
|
75
78
|
import { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect } from './utils/hooks';
|
|
79
|
+
import { getEventStatus } from './utils/event';
|
|
76
80
|
/**
|
|
77
81
|
* Constants:
|
|
78
|
-
* Locale
|
|
82
|
+
* Locale, Preferences
|
|
79
83
|
*/
|
|
80
84
|
import * as Locale from './constants/Locale';
|
|
85
|
+
import * as Preferences from './constants/Preferences';
|
|
81
86
|
/**
|
|
82
87
|
* List all exports
|
|
83
88
|
*/
|
|
84
|
-
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, };
|
|
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
|
@@ -58,6 +58,8 @@ import useSCFetchUserBlockedBy from './hooks/useSCFetchUserBlockedBy';
|
|
|
58
58
|
import useSCUserIsBlocked from './hooks/useSCUserIsBlocked';
|
|
59
59
|
import useSCFetchGroup from './hooks/useSCFetchGroup';
|
|
60
60
|
import useSCFetchGroups from './hooks/useSCFetchGroups';
|
|
61
|
+
import useSCFetchEvent from './hooks/useSCFetchEvent';
|
|
62
|
+
import useSCFetchEvents from './hooks/useSCFetchEvents';
|
|
61
63
|
/**
|
|
62
64
|
* Routing component
|
|
63
65
|
*/
|
|
@@ -68,13 +70,16 @@ import * as SCRoutes from './constants/Routes';
|
|
|
68
70
|
* User, hooks (useIsComponentMountedRef)
|
|
69
71
|
*/
|
|
70
72
|
import * as UserUtils from './utils/user';
|
|
73
|
+
import getTheme from './themes/theme';
|
|
71
74
|
import { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect } from './utils/hooks';
|
|
75
|
+
import { getEventStatus } from './utils/event';
|
|
72
76
|
/**
|
|
73
77
|
* Constants:
|
|
74
|
-
* Locale
|
|
78
|
+
* Locale, Preferences
|
|
75
79
|
*/
|
|
76
80
|
import * as Locale from './constants/Locale';
|
|
81
|
+
import * as Preferences from './constants/Preferences';
|
|
77
82
|
/**
|
|
78
83
|
* List all exports
|
|
79
84
|
*/
|
|
80
|
-
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, };
|
|
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
|
|
@@ -37,6 +37,10 @@ export interface SCSettingsType {
|
|
|
37
37
|
* Object conf of notification.
|
|
38
38
|
*/
|
|
39
39
|
notifications?: SCNotificationsType;
|
|
40
|
+
/**
|
|
41
|
+
* Integrations conf
|
|
42
|
+
*/
|
|
43
|
+
integrations?: SCIntegrationsType;
|
|
40
44
|
/**
|
|
41
45
|
* Callback to handle anonymous action
|
|
42
46
|
* Ex. an anonymous user attempt to post a comment
|
|
@@ -143,6 +147,7 @@ export interface SCUserContextType {
|
|
|
143
147
|
incubators?: SCSubscribedIncubatorsManagerType;
|
|
144
148
|
blockedUsers?: SCBlockedUsersManagerType;
|
|
145
149
|
groups?: SCSubscribedGroupsManagerType;
|
|
150
|
+
events?: SCSubscribedEventsManagerType;
|
|
146
151
|
};
|
|
147
152
|
}
|
|
148
153
|
export interface SCSettingsManagerType {
|
|
@@ -249,6 +254,44 @@ export interface SCFollowedCategoriesManagerType {
|
|
|
249
254
|
*/
|
|
250
255
|
emptyCache?: () => void;
|
|
251
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
|
+
}
|
|
252
295
|
export interface SCSubscribedGroupsManagerType {
|
|
253
296
|
/**
|
|
254
297
|
* List of all groups ids followed by the authenticated user
|
|
@@ -444,6 +487,18 @@ export interface SCPreferencesContextType {
|
|
|
444
487
|
* List of all community enabled features
|
|
445
488
|
*/
|
|
446
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;
|
|
447
502
|
}
|
|
448
503
|
/**
|
|
449
504
|
* Interface SCVoteContextType
|
|
@@ -620,3 +675,36 @@ export interface SCAlertMessagesContextType {
|
|
|
620
675
|
*/
|
|
621
676
|
setOptions: (options: any) => void;
|
|
622
677
|
}
|
|
678
|
+
/**
|
|
679
|
+
* Interface SCIntegrationsType
|
|
680
|
+
*/
|
|
681
|
+
export interface SCIntegrationsType {
|
|
682
|
+
/**
|
|
683
|
+
* OpenAI
|
|
684
|
+
*/
|
|
685
|
+
openai?: SCIntegrationsOpenAIType;
|
|
686
|
+
/**
|
|
687
|
+
* Geocoding
|
|
688
|
+
*/
|
|
689
|
+
geocoding?: SCGeocodingType;
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Interface SCIntegrationsOpenAIType
|
|
693
|
+
*/
|
|
694
|
+
export interface SCIntegrationsOpenAIType {
|
|
695
|
+
/**
|
|
696
|
+
* Set secretKey OpenAI
|
|
697
|
+
* Default: null
|
|
698
|
+
*/
|
|
699
|
+
secretKey: string | null;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Interface SCGeocodingType
|
|
703
|
+
*/
|
|
704
|
+
export interface SCGeocodingType {
|
|
705
|
+
/**
|
|
706
|
+
* Set secretKey geocoding service
|
|
707
|
+
* Default: null
|
|
708
|
+
*/
|
|
709
|
+
apiKey: string | null;
|
|
710
|
+
}
|
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, };
|
|
@@ -21,6 +21,7 @@ export declare class ValidationError {
|
|
|
21
21
|
static ERROR_INVALID_NOTIFICATIONS_WEBSOCKET: number;
|
|
22
22
|
static ERROR_INVALID_NOTIFICATIONS_WEBSOCKET_DISABLE_TOAST_MESSAGE: number;
|
|
23
23
|
static ERROR_INVALID_NOTIFICATIONS_WEBSOCKET_SECURE: number;
|
|
24
|
+
static ERROR_INVALID_NOTIFICATIONS_WEBSOCKET_PREFIX_PATH: number;
|
|
24
25
|
static ERROR_INVALID_NOTIFICATIONS_WEB_PUSH_MESSAGING: number;
|
|
25
26
|
static ERROR_INVALID_NOTIFICATIONS_WEB_PUSH_MESSAGING_DISABLE_TOAST_MESSAGE: number;
|
|
26
27
|
static ERROR_INVALID_NOTIFICATIONS_WEB_PUSH_MESSAGING_APPLICATION_SERVER_KEY: number;
|
|
@@ -32,6 +33,11 @@ export declare class ValidationError {
|
|
|
32
33
|
static ERROR_INVALID_VOTE: number;
|
|
33
34
|
static ERROR_INVALID_VOTE_REACTIONS: number;
|
|
34
35
|
static ERROR_INVALID_VOTE_REACTIONS_STRUCTURE: number;
|
|
36
|
+
static ERROR_INVALID_INTEGRATIONS: number;
|
|
37
|
+
static ERROR_INVALID_INTEGRATIONS_OPENAI: number;
|
|
38
|
+
static ERROR_INVALID_INTEGRATIONS_OPENAI_SECRETKEY: number;
|
|
39
|
+
static ERROR_INVALID_INTEGRATIONS_GEOCODING: number;
|
|
40
|
+
static ERROR_INVALID_INTEGRATIONS_GEOCODING_APIKEY: number;
|
|
35
41
|
static defaultErrorMessageMap: {
|
|
36
42
|
[x: number]: string;
|
|
37
43
|
};
|
package/lib/esm/utils/errors.js
CHANGED
|
@@ -33,6 +33,7 @@ ValidationError.ERROR_INVALID_NOTIFICATIONS = 4900;
|
|
|
33
33
|
ValidationError.ERROR_INVALID_NOTIFICATIONS_WEBSOCKET = 4901;
|
|
34
34
|
ValidationError.ERROR_INVALID_NOTIFICATIONS_WEBSOCKET_DISABLE_TOAST_MESSAGE = 4902;
|
|
35
35
|
ValidationError.ERROR_INVALID_NOTIFICATIONS_WEBSOCKET_SECURE = 4903;
|
|
36
|
+
ValidationError.ERROR_INVALID_NOTIFICATIONS_WEBSOCKET_PREFIX_PATH = 4904;
|
|
36
37
|
ValidationError.ERROR_INVALID_NOTIFICATIONS_WEB_PUSH_MESSAGING = 4921;
|
|
37
38
|
ValidationError.ERROR_INVALID_NOTIFICATIONS_WEB_PUSH_MESSAGING_DISABLE_TOAST_MESSAGE = 4922;
|
|
38
39
|
ValidationError.ERROR_INVALID_NOTIFICATIONS_WEB_PUSH_MESSAGING_APPLICATION_SERVER_KEY = 4923;
|
|
@@ -44,6 +45,11 @@ ValidationError.ERROR_INVALID_PREFERENCES_FEATURES = 5002;
|
|
|
44
45
|
ValidationError.ERROR_INVALID_VOTE = 6000;
|
|
45
46
|
ValidationError.ERROR_INVALID_VOTE_REACTIONS = 6001;
|
|
46
47
|
ValidationError.ERROR_INVALID_VOTE_REACTIONS_STRUCTURE = 6002;
|
|
48
|
+
ValidationError.ERROR_INVALID_INTEGRATIONS = 6100;
|
|
49
|
+
ValidationError.ERROR_INVALID_INTEGRATIONS_OPENAI = 6101;
|
|
50
|
+
ValidationError.ERROR_INVALID_INTEGRATIONS_OPENAI_SECRETKEY = 6102;
|
|
51
|
+
ValidationError.ERROR_INVALID_INTEGRATIONS_GEOCODING = 6103;
|
|
52
|
+
ValidationError.ERROR_INVALID_INTEGRATIONS_GEOCODING_APIKEY = 6104;
|
|
47
53
|
ValidationError.defaultErrorMessageMap = {
|
|
48
54
|
[ValidationError.ERROR_INVALID_CONF]: 'Invalid or missing library configuration. Check the configuration that is passed to the SCContextProvider.',
|
|
49
55
|
[ValidationError.ERROR_INVALID_SESSION]: 'Invalid session format.',
|
|
@@ -63,6 +69,7 @@ ValidationError.defaultErrorMessageMap = {
|
|
|
63
69
|
[ValidationError.ERROR_INVALID_NOTIFICATIONS_WEBSOCKET]: 'Invalid notifications (websocket) option.',
|
|
64
70
|
[ValidationError.ERROR_INVALID_NOTIFICATIONS_WEBSOCKET_DISABLE_TOAST_MESSAGE]: 'Invalid notifications websocket conf: disableToastMessage must be a boolean value.',
|
|
65
71
|
[ValidationError.ERROR_INVALID_NOTIFICATIONS_WEBSOCKET_SECURE]: 'Invalid notifications websocket conf: secure must be a boolean value.',
|
|
72
|
+
[ValidationError.ERROR_INVALID_NOTIFICATIONS_WEBSOCKET_PREFIX_PATH]: 'Invalid notifications websocket conf: prefixPath must be a string value.',
|
|
66
73
|
[ValidationError.ERROR_INVALID_NOTIFICATIONS_WEB_PUSH_MESSAGING]: 'Invalid notifications (web push messaging) option.',
|
|
67
74
|
[ValidationError.ERROR_INVALID_NOTIFICATIONS_WEB_PUSH_MESSAGING_DISABLE_TOAST_MESSAGE]: "Invalid notifications web push messaging option. 'disableToastMessage' must be a boolean value.",
|
|
68
75
|
[ValidationError.ERROR_INVALID_NOTIFICATIONS_WEB_PUSH_MESSAGING_APPLICATION_SERVER_KEY]: "Invalid notifications web push messaging option. 'applicationServerKey' must be a string value.",
|
|
@@ -74,6 +81,11 @@ ValidationError.defaultErrorMessageMap = {
|
|
|
74
81
|
[ValidationError.ERROR_INVALID_VOTE]: 'Invalid vote option.',
|
|
75
82
|
[ValidationError.ERROR_INVALID_VOTE_REACTIONS]: "Invalid vote option. 'reactions' must be a valid array of reaction objects.",
|
|
76
83
|
[ValidationError.ERROR_INVALID_VOTE_REACTIONS_STRUCTURE]: "Invalid vote option. 'reactions' must be a valid array of reaction with attributes (id, label, sentiment, image, active).",
|
|
84
|
+
[ValidationError.ERROR_INVALID_INTEGRATIONS]: 'Invalid integrations conf.',
|
|
85
|
+
[ValidationError.ERROR_INVALID_INTEGRATIONS_OPENAI]: 'Invalid integrations (openai) option.',
|
|
86
|
+
[ValidationError.ERROR_INVALID_INTEGRATIONS_OPENAI_SECRETKEY]: 'Invalid integrations openai conf: secretKey must be a string value.',
|
|
87
|
+
[ValidationError.ERROR_INVALID_INTEGRATIONS_GEOCODING]: 'Invalid integrations (geocoding) option.',
|
|
88
|
+
[ValidationError.ERROR_INVALID_INTEGRATIONS_GEOCODING_APIKEY]: 'Invalid integrations geocoding conf: apiKey must be a string value.',
|
|
77
89
|
};
|
|
78
90
|
/**
|
|
79
91
|
* Manage Validation Warnings
|
|
@@ -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
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useEffect, useLayoutEffect } from 'react';
|
|
2
|
+
import { isClientSideRendering } from '@selfcommunity/utils';
|
|
2
3
|
// Ensure that the SSR uses React.useEffect instead of React.useLayoutEffect
|
|
3
4
|
// because document is undefined on the server-side.
|
|
4
|
-
const useIsomorphicLayoutEffect =
|
|
5
|
+
const useIsomorphicLayoutEffect = isClientSideRendering() ? useLayoutEffect : useEffect;
|
|
5
6
|
export default useIsomorphicLayoutEffect;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { PLATFORM, PLATFORM_KEY, PLATFORMS } from '../constants/Device';
|
|
2
|
-
import { LocalStorageDB } from '@selfcommunity/utils';
|
|
2
|
+
import { isClientSideRendering, LocalStorageDB } from '@selfcommunity/utils';
|
|
3
3
|
/**
|
|
4
4
|
* Check if mobile native push notification is enabled
|
|
5
5
|
*/
|
|
6
6
|
export function isMobileNativeNotificationEnabled() {
|
|
7
|
-
return ((
|
|
7
|
+
return ((isClientSideRendering() && window[PLATFORM_KEY] && window[PLATFORM_KEY] in PLATFORM) ||
|
|
8
8
|
(LocalStorageDB.checkifSupport() && LocalStorageDB.get(PLATFORM_KEY) && PLATFORMS.includes(LocalStorageDB.get(PLATFORM_KEY))));
|
|
9
9
|
}
|
|
10
10
|
/**
|
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
|