@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
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useMemo, useRef } from 'react';
|
|
2
3
|
import { UserService } from '@selfcommunity/api-services';
|
|
3
4
|
import { SCContext } from '../SCContextProvider';
|
|
4
5
|
import useSCAuth, { userActionTypes } from '../../../hooks/useSCAuth';
|
|
5
|
-
import {
|
|
6
|
+
import { Logger } from '@selfcommunity/utils';
|
|
6
7
|
import PubSub from 'pubsub-js';
|
|
7
8
|
import { SCOPE_SC_CORE } from '../../../constants/Errors';
|
|
8
9
|
import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect';
|
|
@@ -16,6 +17,7 @@ import useSCSubscribedIncubatorsManager from '../../../hooks/useSCSubscribedIncu
|
|
|
16
17
|
import useSCBlockedUsersManager from '../../../hooks/useSCBlockedUsersManager';
|
|
17
18
|
import * as Session from '../../../constants/Session';
|
|
18
19
|
import useSCSubscribedGroupsManager from '../../../hooks/useSCSubscribedGroupsManager';
|
|
20
|
+
import useSCSubscribedEventsManager from '../../../hooks/useSCSubscribedEventsManager';
|
|
19
21
|
/**
|
|
20
22
|
* SCUserContext (Authentication Context)
|
|
21
23
|
*
|
|
@@ -68,6 +70,7 @@ export default function SCUserProvider({ children }) {
|
|
|
68
70
|
const categoriesManager = useSCFollowedCategoriesManager(state.user, updateUser);
|
|
69
71
|
const blockedUsersManager = useSCBlockedUsersManager(state.user);
|
|
70
72
|
const subscribedGroupsManager = useSCSubscribedGroupsManager(state.user);
|
|
73
|
+
const subscribedEventsManager = useSCSubscribedEventsManager(state.user);
|
|
71
74
|
/**
|
|
72
75
|
* Ref notifications subscribers: BLOCKED_USER, UNBLOCKED_USER
|
|
73
76
|
*/
|
|
@@ -100,17 +103,17 @@ export default function SCUserProvider({ children }) {
|
|
|
100
103
|
* and document is in foreground refresh the cache
|
|
101
104
|
*/
|
|
102
105
|
useEffect(() => {
|
|
103
|
-
|
|
106
|
+
window.document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
104
107
|
return () => {
|
|
105
|
-
|
|
108
|
+
window.document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
106
109
|
};
|
|
107
|
-
});
|
|
110
|
+
}, []);
|
|
108
111
|
/**
|
|
109
112
|
* handler handleVisibilityChange for this provider
|
|
110
113
|
* Refresh followed categories, users, etc..
|
|
111
114
|
*/
|
|
112
115
|
function handleVisibilityChange() {
|
|
113
|
-
if (
|
|
116
|
+
if (!window.document.hidden && state.user) {
|
|
114
117
|
settingsManager.refresh && settingsManager.refresh();
|
|
115
118
|
refreshCounters();
|
|
116
119
|
categoriesManager.refresh && categoriesManager.refresh();
|
|
@@ -119,6 +122,7 @@ export default function SCUserProvider({ children }) {
|
|
|
119
122
|
subscribedIncubatorsManager.refresh && subscribedIncubatorsManager.refresh();
|
|
120
123
|
blockedUsersManager.refresh && blockedUsersManager.refresh();
|
|
121
124
|
subscribedGroupsManager.refresh && subscribedGroupsManager.refresh();
|
|
125
|
+
subscribedEventsManager.refresh && subscribedEventsManager.refresh();
|
|
122
126
|
}
|
|
123
127
|
}
|
|
124
128
|
/**
|
|
@@ -215,6 +219,7 @@ export default function SCUserProvider({ children }) {
|
|
|
215
219
|
incubators: subscribedIncubatorsManager,
|
|
216
220
|
blockedUsers: blockedUsersManager,
|
|
217
221
|
groups: subscribedGroupsManager,
|
|
222
|
+
events: subscribedEventsManager,
|
|
218
223
|
},
|
|
219
224
|
}), [
|
|
220
225
|
state,
|
|
@@ -233,12 +238,14 @@ export default function SCUserProvider({ children }) {
|
|
|
233
238
|
subscribedIncubatorsManager.incubators,
|
|
234
239
|
subscribedGroupsManager.loading,
|
|
235
240
|
subscribedGroupsManager.groups,
|
|
241
|
+
subscribedEventsManager.loading,
|
|
242
|
+
subscribedEventsManager.events,
|
|
236
243
|
]);
|
|
237
244
|
/**
|
|
238
245
|
* We only want to render the underlying app after we
|
|
239
246
|
* assert for the presence of a current user.
|
|
240
247
|
*/
|
|
241
|
-
return
|
|
248
|
+
return _jsx(SCUserContext.Provider, Object.assign({ value: contextValue }, { children: children }));
|
|
242
249
|
}
|
|
243
250
|
/**
|
|
244
251
|
* Let's only export the `useSCUser` hook instead of the context.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
|
2
3
|
import { ReactionService } from '@selfcommunity/api-services';
|
|
3
4
|
import { Logger } from '@selfcommunity/utils';
|
|
4
5
|
import { SCOPE_SC_CORE } from '../../../constants/Errors';
|
|
@@ -78,7 +79,7 @@ export default function SCVoteProvider({ children = null }) {
|
|
|
78
79
|
* Nesting all necessary providers
|
|
79
80
|
* All child components will use help contexts to works
|
|
80
81
|
*/
|
|
81
|
-
return
|
|
82
|
+
return _jsx(SCVoteContext.Provider, Object.assign({ value: { reactions, isLoading, refreshReactions } }, { children: initialized && children }));
|
|
82
83
|
}
|
|
83
84
|
/**
|
|
84
85
|
* Let's only export the `useSCPreferences` hook instead of the context.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import React, { useContext } from 'react';
|
|
3
4
|
import { SCRoutingContext } from '../provider/SCRoutingProvider';
|
|
4
5
|
/**
|
|
@@ -19,10 +20,10 @@ const Link = (_a, ref) => {
|
|
|
19
20
|
const scRoutingContext = useContext(SCRoutingContext);
|
|
20
21
|
if (scRoutingContext.routerLink) {
|
|
21
22
|
const ComponentLink = scRoutingContext.routerLink;
|
|
22
|
-
return (
|
|
23
|
+
return (_jsx(ComponentLink, Object.assign({}, other, { ref: ref }, { children: children })));
|
|
23
24
|
}
|
|
24
25
|
const { to } = other, rest = __rest(other, ["to"]);
|
|
25
|
-
return (
|
|
26
|
+
return (_jsx("a", Object.assign({ href: to }, rest, { ref: ref }, { children: children })));
|
|
26
27
|
};
|
|
27
28
|
/**
|
|
28
29
|
:::info
|
|
@@ -17,6 +17,12 @@ export declare const getCategoriesObjectCacheKey: () => string;
|
|
|
17
17
|
/** CATEGORY OBJECT **/
|
|
18
18
|
export declare const CATEGORY_OBJECT_CACHE_PREFIX_KEY = "_ca_";
|
|
19
19
|
export declare const getCategoryObjectCacheKey: (id: any) => string;
|
|
20
|
+
/** EVENT OBJECT **/
|
|
21
|
+
export declare const EVENT_OBJECT_CACHE_PREFIX_KEY = "_evt_";
|
|
22
|
+
export declare const getEventObjectCacheKey: (id: any) => string;
|
|
23
|
+
/** EVENTS OBJECT **/
|
|
24
|
+
export declare const EVENTS_OBJECT_CACHE_PREFIX_KEY = "_evts_";
|
|
25
|
+
export declare const getEventsObjectCacheKey: () => string;
|
|
20
26
|
/** GROUP OBJECT **/
|
|
21
27
|
export declare const GROUP_OBJECT_CACHE_PREFIX_KEY = "_grp_";
|
|
22
28
|
export declare const getGroupObjectCacheKey: (id: any) => string;
|
|
@@ -58,6 +64,11 @@ export declare const CATEGORIES_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_cSug
|
|
|
58
64
|
export declare const CATEGORIES_POPULAR_TOOLS_STATE_CACHE_PREFIX_KEY = "_cPopWidget_";
|
|
59
65
|
export declare const USER_FOLLOWERS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uFolWidget_";
|
|
60
66
|
export declare const USER_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = "_uFoldWidget_";
|
|
67
|
+
export declare const USER_EVENTS_STATE_CACHE_PREFIX_KEY = "_uEvents_";
|
|
68
|
+
export declare const USER_OTHER_EVENTS_STATE_CACHE_PREFIX_KEY = "_uOtherEvents_";
|
|
69
|
+
export declare const USER_PARTECIPANTS_EVENTS_STATE_CACHE_PREFIX_KEY = "_uPartecipantsEvents_";
|
|
70
|
+
export declare const USER_INVITED_EVENTS_STATE_CACHE_PREFIX_KEY = "_uInvitedEvents_";
|
|
71
|
+
export declare const USER_REQUESTS_EVENTS_STATE_CACHE_PREFIX_KEY = "_uRequestsEvents_";
|
|
61
72
|
export declare const USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConWidget_";
|
|
62
73
|
export declare const USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConReqWidget_";
|
|
63
74
|
export declare const USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConReqSentWidget_";
|
|
@@ -17,6 +17,12 @@ export const getCategoriesObjectCacheKey = () => `${CATEGORIES_OBJECT_CACHE_PREF
|
|
|
17
17
|
/** CATEGORY OBJECT **/
|
|
18
18
|
export const CATEGORY_OBJECT_CACHE_PREFIX_KEY = '_ca_';
|
|
19
19
|
export const getCategoryObjectCacheKey = (id) => `${CATEGORY_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
20
|
+
/** EVENT OBJECT **/
|
|
21
|
+
export const EVENT_OBJECT_CACHE_PREFIX_KEY = '_evt_';
|
|
22
|
+
export const getEventObjectCacheKey = (id) => `${EVENT_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
23
|
+
/** EVENTS OBJECT **/
|
|
24
|
+
export const EVENTS_OBJECT_CACHE_PREFIX_KEY = '_evts_';
|
|
25
|
+
export const getEventsObjectCacheKey = () => `${EVENTS_OBJECT_CACHE_PREFIX_KEY}`;
|
|
20
26
|
/** GROUP OBJECT **/
|
|
21
27
|
export const GROUP_OBJECT_CACHE_PREFIX_KEY = '_grp_';
|
|
22
28
|
export const getGroupObjectCacheKey = (id) => `${GROUP_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
@@ -62,6 +68,11 @@ export const CATEGORIES_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_cSugWidget_'
|
|
|
62
68
|
export const CATEGORIES_POPULAR_TOOLS_STATE_CACHE_PREFIX_KEY = '_cPopWidget_';
|
|
63
69
|
export const USER_FOLLOWERS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uFolWidget_';
|
|
64
70
|
export const USER_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = '_uFoldWidget_';
|
|
71
|
+
export const USER_EVENTS_STATE_CACHE_PREFIX_KEY = '_uEvents_';
|
|
72
|
+
export const USER_OTHER_EVENTS_STATE_CACHE_PREFIX_KEY = '_uOtherEvents_';
|
|
73
|
+
export const USER_PARTECIPANTS_EVENTS_STATE_CACHE_PREFIX_KEY = '_uPartecipantsEvents_';
|
|
74
|
+
export const USER_INVITED_EVENTS_STATE_CACHE_PREFIX_KEY = '_uInvitedEvents_';
|
|
75
|
+
export const USER_REQUESTS_EVENTS_STATE_CACHE_PREFIX_KEY = '_uRequestsEvents_';
|
|
65
76
|
export const USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConWidget_';
|
|
66
77
|
export const USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConReqWidget_';
|
|
67
78
|
export const USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConReqSentWidget_';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const INTEGRATIONS_OPTION = "integrations";
|
|
2
|
+
export declare const INTEGRATIONS_OPENAI_OPTION = "openai";
|
|
3
|
+
export declare const INTEGRATIONS_OPENAI_SECRETKEY_OPTION = "secretKey";
|
|
4
|
+
export declare const INTEGRATIONS_GEOCODING_OPTION = "geocoding";
|
|
5
|
+
export declare const INTEGRATIONS_GEOCODING_APIKEY_OPTION = "apiKey";
|
|
6
|
+
export declare const DEFAULT_INTEGRATIONS_OPTION: {
|
|
7
|
+
openai: {
|
|
8
|
+
secretKey: any;
|
|
9
|
+
};
|
|
10
|
+
geocoding: {
|
|
11
|
+
apiKey: any;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// integrations
|
|
2
|
+
export const INTEGRATIONS_OPTION = 'integrations';
|
|
3
|
+
export const INTEGRATIONS_OPENAI_OPTION = 'openai';
|
|
4
|
+
export const INTEGRATIONS_OPENAI_SECRETKEY_OPTION = 'secretKey';
|
|
5
|
+
export const INTEGRATIONS_GEOCODING_OPTION = 'geocoding';
|
|
6
|
+
export const INTEGRATIONS_GEOCODING_APIKEY_OPTION = 'apiKey';
|
|
7
|
+
export const DEFAULT_INTEGRATIONS_OPTION = {
|
|
8
|
+
[INTEGRATIONS_OPENAI_OPTION]: {
|
|
9
|
+
[INTEGRATIONS_OPENAI_SECRETKEY_OPTION]: null,
|
|
10
|
+
},
|
|
11
|
+
[INTEGRATIONS_GEOCODING_OPTION]: {
|
|
12
|
+
[INTEGRATIONS_GEOCODING_APIKEY_OPTION]: null,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
@@ -9,6 +9,7 @@ export declare const NOTIFICATIONS_MOBILE_NATIVE_PUSH_MESSAGING_OPTION = "mobile
|
|
|
9
9
|
export declare const NOTIFICATIONS_WEB_PUSH_MESSAGING_DIALOG_COOKIE = "wpnDialogDisabled";
|
|
10
10
|
export declare const NOTIFICATIONS_DISABLE_TOAST_MESSAGE_OPTION = "disableToastMessage";
|
|
11
11
|
export declare const NOTIFICATIONS_MOBILE_NATIVE_DISABLE_OPTION = "disable";
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const NOTIFICATIONS_WEBSOCKET_SECURE_OPTION = "secure";
|
|
13
|
+
export declare const NOTIFICATIONS_WEBSOCKET_PREFIX_PATH_OPTION = "prefixPath";
|
|
13
14
|
export declare const NOTIFICATIONS_APPLICATION_SERVER_KEY_OPTION = "applicationServerKey";
|
|
14
15
|
export declare const DEFAULT_NOTIFICATIONS: SCNotificationsType;
|
|
@@ -5,12 +5,13 @@ export const NOTIFICATIONS_MOBILE_NATIVE_PUSH_MESSAGING_OPTION = 'mobileNativePu
|
|
|
5
5
|
export const NOTIFICATIONS_WEB_PUSH_MESSAGING_DIALOG_COOKIE = 'wpnDialogDisabled';
|
|
6
6
|
export const NOTIFICATIONS_DISABLE_TOAST_MESSAGE_OPTION = 'disableToastMessage';
|
|
7
7
|
export const NOTIFICATIONS_MOBILE_NATIVE_DISABLE_OPTION = 'disable';
|
|
8
|
-
export const
|
|
8
|
+
export const NOTIFICATIONS_WEBSOCKET_SECURE_OPTION = 'secure';
|
|
9
|
+
export const NOTIFICATIONS_WEBSOCKET_PREFIX_PATH_OPTION = 'prefixPath';
|
|
9
10
|
export const NOTIFICATIONS_APPLICATION_SERVER_KEY_OPTION = 'applicationServerKey';
|
|
10
11
|
export const DEFAULT_NOTIFICATIONS = {
|
|
11
12
|
[NOTIFICATIONS_WEB_SOCKET_OPTION]: {
|
|
12
13
|
[NOTIFICATIONS_DISABLE_TOAST_MESSAGE_OPTION]: false,
|
|
13
|
-
[
|
|
14
|
+
[NOTIFICATIONS_WEBSOCKET_SECURE_OPTION]: true,
|
|
14
15
|
},
|
|
15
16
|
[NOTIFICATIONS_WEB_PUSH_MESSAGING_OPTION]: {
|
|
16
17
|
[NOTIFICATIONS_DISABLE_TOAST_MESSAGE_OPTION]: true,
|
|
@@ -129,6 +129,9 @@ export declare const CONFIGURATIONS_CUSTOM_NAVBAR_ITEM_IMAGE: string;
|
|
|
129
129
|
export declare const CONFIGURATIONS_GROUPS_ONLY_STAFF_ENABLED: string;
|
|
130
130
|
export declare const CONFIGURATIONS_GROUPS_VISIBILITY_ENABLED: string;
|
|
131
131
|
export declare const CONFIGURATIONS_GROUPS_PRIVATE_ENABLED: string;
|
|
132
|
+
export declare const CONFIGURATIONS_EVENTS_ONLY_STAFF_ENABLED: string;
|
|
133
|
+
export declare const CONFIGURATIONS_EVENTS_VISIBILITY_ENABLED: string;
|
|
134
|
+
export declare const CONFIGURATIONS_EVENTS_PRIVATE_ENABLED: string;
|
|
132
135
|
/**
|
|
133
136
|
* PROVIDERS
|
|
134
137
|
*/
|
|
@@ -130,6 +130,9 @@ export const CONFIGURATIONS_CUSTOM_NAVBAR_ITEM_IMAGE = `${SCPreferenceSection.CO
|
|
|
130
130
|
export const CONFIGURATIONS_GROUPS_ONLY_STAFF_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.GROUPS_ONLY_STAFF_ENABLED}`;
|
|
131
131
|
export const CONFIGURATIONS_GROUPS_VISIBILITY_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.GROUPS_VISIBILITY_ENABLED}`;
|
|
132
132
|
export const CONFIGURATIONS_GROUPS_PRIVATE_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.GROUPS_PRIVATE_ENABLED}`;
|
|
133
|
+
export const CONFIGURATIONS_EVENTS_ONLY_STAFF_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.EVENTS_ONLY_STAFF_ENABLED}`;
|
|
134
|
+
export const CONFIGURATIONS_EVENTS_VISIBILITY_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.EVENTS_VISIBILITY_ENABLED}`;
|
|
135
|
+
export const CONFIGURATIONS_EVENTS_PRIVATE_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.EVENTS_PRIVATE_ENABLED}`;
|
|
133
136
|
/**
|
|
134
137
|
* PROVIDERS
|
|
135
138
|
*/
|
|
@@ -266,6 +269,9 @@ export const DATA_TYPES = {
|
|
|
266
269
|
[CONFIGURATIONS_CUSTOM_NAVBAR_ITEM_TEXT]: stringType,
|
|
267
270
|
[CONFIGURATIONS_CUSTOM_NAVBAR_ITEM_URL]: stringType,
|
|
268
271
|
[CONFIGURATIONS_CUSTOM_NAVBAR_ITEM_IMAGE]: stringType,
|
|
272
|
+
[CONFIGURATIONS_EVENTS_ONLY_STAFF_ENABLED]: booleanType,
|
|
273
|
+
[CONFIGURATIONS_EVENTS_VISIBILITY_ENABLED]: booleanType,
|
|
274
|
+
[CONFIGURATIONS_EVENTS_PRIVATE_ENABLED]: booleanType,
|
|
269
275
|
[CONFIGURATIONS_GROUPS_ONLY_STAFF_ENABLED]: booleanType,
|
|
270
276
|
[CONFIGURATIONS_GROUPS_VISIBILITY_ENABLED]: booleanType,
|
|
271
277
|
[CONFIGURATIONS_GROUPS_PRIVATE_ENABLED]: booleanType,
|
|
@@ -36,6 +36,11 @@ export declare const GROUP_MEMBERS_ROUTE_NAME = "group_members";
|
|
|
36
36
|
export declare const GROUP_MESSAGES_ROUTE_NAME = "group_messages";
|
|
37
37
|
export declare const GROUPS_ROUTE_NAME = "groups";
|
|
38
38
|
export declare const GROUPS_SUBSCRIBED_ROUTE_NAME = "groups_subscribed";
|
|
39
|
+
export declare const EVENT_ROUTE_NAME = "event";
|
|
40
|
+
export declare const EVENTS_ROUTE_NAME = "events";
|
|
41
|
+
export declare const EVENTS_SUGGESTED_ROUTE_NAME = "events_suggested";
|
|
42
|
+
export declare const EVENTS_SUBSCRIBED_ROUTE_NAME = "events_subscribed";
|
|
43
|
+
export declare const EVENTS_HIGHLIGHT_ROUTE_NAME = "events_highlight";
|
|
39
44
|
/**
|
|
40
45
|
* Default Routes
|
|
41
46
|
* @type {{[p: string]: string, '[POST_ROUTE_NAME]': string, '[INCUBATOR_ROUTE_NAME]': string, '[LOYALTY_ROUTE_NAME]': string, '[USER_NOTIFICATION_ROUTE_NAME]': string, '[USER_PRIVATE_MESSAGES_ROUTE_NAME]': string, '[COMMENT_ROUTE_NAME]': string, '[DISCUSSION_ROUTE_NAME]': string, '[CATEGORIES_ROUTE_NAME]': string, '[USER_PROFILE_ROUTE_NAME]': string, '[CATEGORY_ROUTE_NAME]': string, '[USER_PROFILE_SETTINGS_ROUTE_NAME]': string, '[STATUS_ROUTE_NAME]': string}}
|
|
@@ -36,6 +36,11 @@ export const GROUP_MEMBERS_ROUTE_NAME = 'group_members';
|
|
|
36
36
|
export const GROUP_MESSAGES_ROUTE_NAME = 'group_messages';
|
|
37
37
|
export const GROUPS_ROUTE_NAME = 'groups';
|
|
38
38
|
export const GROUPS_SUBSCRIBED_ROUTE_NAME = 'groups_subscribed';
|
|
39
|
+
export const EVENT_ROUTE_NAME = 'event';
|
|
40
|
+
export const EVENTS_ROUTE_NAME = 'events';
|
|
41
|
+
export const EVENTS_SUGGESTED_ROUTE_NAME = 'events_suggested';
|
|
42
|
+
export const EVENTS_SUBSCRIBED_ROUTE_NAME = 'events_subscribed';
|
|
43
|
+
export const EVENTS_HIGHLIGHT_ROUTE_NAME = 'events_highlight';
|
|
39
44
|
/**
|
|
40
45
|
* Default Routes
|
|
41
46
|
* @type {{[p: string]: string, '[POST_ROUTE_NAME]': string, '[INCUBATOR_ROUTE_NAME]': string, '[LOYALTY_ROUTE_NAME]': string, '[USER_NOTIFICATION_ROUTE_NAME]': string, '[USER_PRIVATE_MESSAGES_ROUTE_NAME]': string, '[COMMENT_ROUTE_NAME]': string, '[DISCUSSION_ROUTE_NAME]': string, '[CATEGORIES_ROUTE_NAME]': string, '[USER_PROFILE_ROUTE_NAME]': string, '[CATEGORY_ROUTE_NAME]': string, '[USER_PROFILE_SETTINGS_ROUTE_NAME]': string, '[STATUS_ROUTE_NAME]': string}}
|
|
@@ -74,4 +79,9 @@ export const defaultRoutes = {
|
|
|
74
79
|
[GROUP_MESSAGES_ROUTE_NAME]: '/group/:id/:slug/messages/',
|
|
75
80
|
[GROUPS_ROUTE_NAME]: '/groups/',
|
|
76
81
|
[GROUPS_SUBSCRIBED_ROUTE_NAME]: '/groups/subscribed/',
|
|
82
|
+
[EVENTS_ROUTE_NAME]: '/events/',
|
|
83
|
+
[EVENTS_SUGGESTED_ROUTE_NAME]: '/events/suggested',
|
|
84
|
+
[EVENT_ROUTE_NAME]: '/event/:id/:slug/',
|
|
85
|
+
[EVENTS_SUBSCRIBED_ROUTE_NAME]: '/events/subscribed/',
|
|
86
|
+
[EVENTS_HIGHLIGHT_ROUTE_NAME]: '/events/highlight/',
|
|
77
87
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SCEventType } from '@selfcommunity/types';
|
|
2
|
+
import { CacheStrategies } from '@selfcommunity/utils';
|
|
3
|
+
/**
|
|
4
|
+
:::info
|
|
5
|
+
This custom hook is used to fetch an event object.
|
|
6
|
+
:::
|
|
7
|
+
* @param object
|
|
8
|
+
* @param object.id
|
|
9
|
+
* @param object.event
|
|
10
|
+
* @param object.autosubscribe
|
|
11
|
+
* @param object.cacheStrategy
|
|
12
|
+
*/
|
|
13
|
+
export default function useSCFetchEvent({ id, event, autoSubscribe, cacheStrategy, }: {
|
|
14
|
+
id?: number | string;
|
|
15
|
+
event?: SCEventType;
|
|
16
|
+
autoSubscribe?: boolean;
|
|
17
|
+
cacheStrategy?: CacheStrategies;
|
|
18
|
+
}): {
|
|
19
|
+
scEvent: SCEventType;
|
|
20
|
+
setSCEvent: (event: SCEventType) => void;
|
|
21
|
+
error: string;
|
|
22
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
3
|
+
import { SCEventPrivacyType, SCEventSubscriptionStatusType } from '@selfcommunity/types';
|
|
4
|
+
import { Endpoints, EventService, http } from '@selfcommunity/api-services';
|
|
5
|
+
import { CacheStrategies, Logger, LRUCache, objectWithoutProperties } from '@selfcommunity/utils';
|
|
6
|
+
import { getEventObjectCacheKey } from '../constants/Cache';
|
|
7
|
+
import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect';
|
|
8
|
+
import { useSCUser } from '../components/provider/SCUserProvider';
|
|
9
|
+
/**
|
|
10
|
+
:::info
|
|
11
|
+
This custom hook is used to fetch an event object.
|
|
12
|
+
:::
|
|
13
|
+
* @param object
|
|
14
|
+
* @param object.id
|
|
15
|
+
* @param object.event
|
|
16
|
+
* @param object.autosubscribe
|
|
17
|
+
* @param object.cacheStrategy
|
|
18
|
+
*/
|
|
19
|
+
export default function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheStrategy = CacheStrategies.CACHE_FIRST, }) {
|
|
20
|
+
const __eventId = event ? event.id : id;
|
|
21
|
+
// CONTEXT
|
|
22
|
+
const scUserContext = useSCUser();
|
|
23
|
+
const authUserId = scUserContext.user ? scUserContext.user.id : null;
|
|
24
|
+
// CACHE
|
|
25
|
+
const __eventCacheKey = getEventObjectCacheKey(__eventId);
|
|
26
|
+
const __event = authUserId ? event : objectWithoutProperties(event, ['subscription_status']);
|
|
27
|
+
const [scEvent, setScEvent] = useState(cacheStrategy !== CacheStrategies.NETWORK_ONLY ? LRUCache.get(__eventCacheKey, __event) : null);
|
|
28
|
+
const [error, setError] = useState(null);
|
|
29
|
+
const setSCEvent = (event) => {
|
|
30
|
+
const _e = authUserId ? event : objectWithoutProperties(event, ['subscription_status']);
|
|
31
|
+
setScEvent(_e);
|
|
32
|
+
LRUCache.set(__eventCacheKey, _e);
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Memoized fetchTag
|
|
36
|
+
*/
|
|
37
|
+
const fetchEvent = useMemo(() => () => {
|
|
38
|
+
return http
|
|
39
|
+
.request({
|
|
40
|
+
url: Endpoints.GetEventInfo.url({ id: __eventId }),
|
|
41
|
+
method: Endpoints.GetEventInfo.method,
|
|
42
|
+
})
|
|
43
|
+
.then((res) => {
|
|
44
|
+
if (res.status >= 300) {
|
|
45
|
+
return Promise.reject(res);
|
|
46
|
+
}
|
|
47
|
+
return Promise.resolve(res.data);
|
|
48
|
+
});
|
|
49
|
+
}, [__eventId]);
|
|
50
|
+
/**
|
|
51
|
+
* If id attempt to get the event by id
|
|
52
|
+
*/
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (__eventId && scUserContext.user !== undefined && (!scEvent || (scEvent && __eventId !== scEvent.id))) {
|
|
55
|
+
fetchEvent()
|
|
56
|
+
.then((event) => {
|
|
57
|
+
if (autoSubscribe &&
|
|
58
|
+
authUserId !== null &&
|
|
59
|
+
((event.privacy === SCEventPrivacyType.PUBLIC && !event.subscription_status) ||
|
|
60
|
+
(event.privacy === SCEventPrivacyType.PRIVATE && event.subscription_status === SCEventSubscriptionStatusType.INVITED))) {
|
|
61
|
+
// Auto subscribe to the event
|
|
62
|
+
EventService.subscribeToEvent(event.id).then(() => {
|
|
63
|
+
setSCEvent(event);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
setSCEvent(event);
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
.catch((err) => {
|
|
71
|
+
LRUCache.delete(__eventCacheKey);
|
|
72
|
+
setError(`Event with id ${id} not found`);
|
|
73
|
+
Logger.error(SCOPE_SC_CORE, `Event with id ${id} not found`);
|
|
74
|
+
Logger.error(SCOPE_SC_CORE, err.message);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}, [__eventId, authUserId, scUserContext.user]);
|
|
78
|
+
useDeepCompareEffectNoCheck(() => {
|
|
79
|
+
if (event) {
|
|
80
|
+
setSCEvent(event);
|
|
81
|
+
}
|
|
82
|
+
}, [event, authUserId]);
|
|
83
|
+
return { scEvent, setSCEvent, error };
|
|
84
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SCEventType } from '@selfcommunity/types';
|
|
2
|
+
import { CacheStrategies } from '@selfcommunity/utils';
|
|
3
|
+
/**
|
|
4
|
+
:::info
|
|
5
|
+
This custom hook is used to fetch events.
|
|
6
|
+
@param object.cacheStrategy
|
|
7
|
+
|
|
8
|
+
:::tip Context can be consumed in this way:
|
|
9
|
+
|
|
10
|
+
```jsx
|
|
11
|
+
const {events, isLoading} = useSCFetchEvents();
|
|
12
|
+
```
|
|
13
|
+
:::
|
|
14
|
+
* @param props
|
|
15
|
+
*/
|
|
16
|
+
declare const useSCFetchEvents: (props?: {
|
|
17
|
+
cacheStrategy?: CacheStrategies;
|
|
18
|
+
}) => {
|
|
19
|
+
events: SCEventType[];
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
};
|
|
22
|
+
export default useSCFetchEvents;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
4
|
+
import { Endpoints, http } from '@selfcommunity/api-services';
|
|
5
|
+
import { CacheStrategies, Logger, LRUCache } from '@selfcommunity/utils';
|
|
6
|
+
import { getEventObjectCacheKey, getEventsObjectCacheKey } from '../constants/Cache';
|
|
7
|
+
const init = { events: [], isLoading: true };
|
|
8
|
+
// HYDRATE the cache
|
|
9
|
+
const hydrate = (ids) => {
|
|
10
|
+
if (!ids) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const events = ids.map((id) => {
|
|
14
|
+
const __eventCacheKey = getEventObjectCacheKey(id);
|
|
15
|
+
return LRUCache.get(__eventCacheKey);
|
|
16
|
+
});
|
|
17
|
+
if (events.filter((c) => !c).length > 0) {
|
|
18
|
+
// REVALIDATE CACHE
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return events;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
:::info
|
|
25
|
+
This custom hook is used to fetch events.
|
|
26
|
+
@param object.cacheStrategy
|
|
27
|
+
|
|
28
|
+
:::tip Context can be consumed in this way:
|
|
29
|
+
|
|
30
|
+
```jsx
|
|
31
|
+
const {events, isLoading} = useSCFetchEvents();
|
|
32
|
+
```
|
|
33
|
+
:::
|
|
34
|
+
* @param props
|
|
35
|
+
*/
|
|
36
|
+
const useSCFetchEvents = (props) => {
|
|
37
|
+
// PROPS
|
|
38
|
+
const { cacheStrategy = CacheStrategies.CACHE_FIRST } = props || {};
|
|
39
|
+
// CACHE
|
|
40
|
+
const __eventsCacheKey = getEventsObjectCacheKey();
|
|
41
|
+
// STATE
|
|
42
|
+
const events = cacheStrategy !== CacheStrategies.NETWORK_ONLY ? hydrate(LRUCache.get(__eventsCacheKey, null)) : null;
|
|
43
|
+
const [data, setData] = useState(events !== null ? { events, isLoading: false } : init);
|
|
44
|
+
/**
|
|
45
|
+
* Fetch events
|
|
46
|
+
*/
|
|
47
|
+
const fetchEvents = (next = Endpoints.GetUserEvents.url()) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
const response = yield http.request({
|
|
49
|
+
url: next,
|
|
50
|
+
method: Endpoints.GetUserEvents.method,
|
|
51
|
+
});
|
|
52
|
+
const data = response.data;
|
|
53
|
+
if (data.next) {
|
|
54
|
+
return data.results.concat(yield fetchEvents(data.next));
|
|
55
|
+
}
|
|
56
|
+
return data.results;
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Get events
|
|
60
|
+
*/
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (cacheStrategy === CacheStrategies.CACHE_FIRST && events) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
fetchEvents()
|
|
66
|
+
.then((data) => {
|
|
67
|
+
setData({ events: data, isLoading: false });
|
|
68
|
+
LRUCache.set(__eventsCacheKey, data.map((event) => {
|
|
69
|
+
const __eventCacheKey = getEventObjectCacheKey(event.id);
|
|
70
|
+
LRUCache.set(__eventCacheKey, event);
|
|
71
|
+
return event.id;
|
|
72
|
+
}));
|
|
73
|
+
})
|
|
74
|
+
.catch((error) => {
|
|
75
|
+
console.log(error);
|
|
76
|
+
Logger.error(SCOPE_SC_CORE, 'Unable to retrieve events');
|
|
77
|
+
});
|
|
78
|
+
}, []);
|
|
79
|
+
return data;
|
|
80
|
+
};
|
|
81
|
+
export default useSCFetchEvents;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SCEventType, SCUserType } from '@selfcommunity/types';
|
|
2
|
+
/**
|
|
3
|
+
:::info
|
|
4
|
+
This custom hook is used to manage the events followed.
|
|
5
|
+
:::
|
|
6
|
+
|
|
7
|
+
:::tip How to use it:
|
|
8
|
+
Follow these steps:
|
|
9
|
+
```jsx
|
|
10
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
11
|
+
2. const scSubscribedEventsManager: SCSubscribedEventsManagerType = scUserContext.manager.events;
|
|
12
|
+
3. scSubscribedEventsManager.isSubscribed(event)
|
|
13
|
+
```
|
|
14
|
+
:::
|
|
15
|
+
*/
|
|
16
|
+
export default function useSCSubscribedEventsManager(user?: SCUserType): {
|
|
17
|
+
events: any[];
|
|
18
|
+
loading: any[];
|
|
19
|
+
isLoading: (v: number | {
|
|
20
|
+
id: number;
|
|
21
|
+
}) => boolean;
|
|
22
|
+
toggleEventAttendance?: undefined;
|
|
23
|
+
toggleEventNonattendance?: undefined;
|
|
24
|
+
subscriptionStatus?: undefined;
|
|
25
|
+
refresh?: undefined;
|
|
26
|
+
emptyCache?: undefined;
|
|
27
|
+
} | {
|
|
28
|
+
events: any[];
|
|
29
|
+
loading: any[];
|
|
30
|
+
isLoading: (v: number | {
|
|
31
|
+
id: number;
|
|
32
|
+
}) => boolean;
|
|
33
|
+
toggleEventAttendance: (event: SCEventType, userId?: number) => Promise<any>;
|
|
34
|
+
toggleEventNonattendance: (event: SCEventType) => Promise<any>;
|
|
35
|
+
subscriptionStatus: (event?: SCEventType) => string;
|
|
36
|
+
refresh: () => void;
|
|
37
|
+
emptyCache: () => void;
|
|
38
|
+
};
|