@selfcommunity/react-core 0.7.0-alpha.2 → 0.7.0-alpha.21

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.
Files changed (90) hide show
  1. package/lib/cjs/constants/Cache.d.ts +12 -0
  2. package/lib/cjs/constants/Cache.js +17 -1
  3. package/lib/cjs/constants/Preferences.d.ts +18 -0
  4. package/lib/cjs/constants/Preferences.js +36 -2
  5. package/lib/cjs/constants/Routes.d.ts +6 -0
  6. package/lib/cjs/constants/Routes.js +14 -1
  7. package/lib/cjs/hooks/useFetchMenuFooter.d.ts +5 -0
  8. package/lib/cjs/hooks/useFetchMenuFooter.js +36 -0
  9. package/lib/cjs/hooks/useSCFeature.d.ts +22 -0
  10. package/lib/cjs/hooks/useSCFeature.js +38 -0
  11. package/lib/cjs/hooks/useSCFetchCategory.d.ts +1 -0
  12. package/lib/cjs/hooks/useSCFetchCategory.js +18 -1
  13. package/lib/cjs/hooks/useSCFetchCourse.js +15 -15
  14. package/lib/cjs/hooks/useSCFetchEvent.d.ts +1 -0
  15. package/lib/cjs/hooks/useSCFetchEvent.js +16 -1
  16. package/lib/cjs/hooks/useSCFetchGroup.d.ts +1 -0
  17. package/lib/cjs/hooks/useSCFetchGroup.js +16 -1
  18. package/lib/cjs/hooks/useSCFetchPaymentOrder.d.ts +20 -0
  19. package/lib/cjs/hooks/useSCFetchPaymentOrder.js +70 -0
  20. package/lib/cjs/hooks/useSCFetchPaymentProduct.d.ts +20 -0
  21. package/lib/cjs/hooks/useSCFetchPaymentProduct.js +70 -0
  22. package/lib/cjs/hooks/useSCFetchUsers.d.ts +21 -0
  23. package/lib/cjs/hooks/useSCFetchUsers.js +50 -0
  24. package/lib/cjs/hooks/useSCJoinedCoursesManager.d.ts +1 -1
  25. package/lib/cjs/hooks/useSCJoinedCoursesManager.js +36 -67
  26. package/lib/cjs/hooks/useSCPaymentsEnabled.d.ts +18 -0
  27. package/lib/cjs/hooks/useSCPaymentsEnabled.js +35 -0
  28. package/lib/cjs/hooks/useSCPreference.d.ts +36 -0
  29. package/lib/cjs/hooks/useSCPreference.js +69 -0
  30. package/lib/cjs/hooks/useSCPreferencesAndFeaturesEnabled.d.ts +17 -0
  31. package/lib/cjs/hooks/useSCPreferencesAndFeaturesEnabled.js +35 -0
  32. package/lib/cjs/hooks/useSCSubscribedEventsManager.js +4 -14
  33. package/lib/cjs/hooks/useSCSubscribedGroupsManager.d.ts +1 -1
  34. package/lib/cjs/hooks/useSCSubscribedGroupsManager.js +29 -54
  35. package/lib/cjs/index.d.ts +10 -2
  36. package/lib/cjs/index.js +22 -2
  37. package/lib/cjs/themes/theme.js +12 -0
  38. package/lib/cjs/types/theme.d.ts +52 -0
  39. package/lib/cjs/utils/hooks/index.d.ts +2 -1
  40. package/lib/cjs/utils/hooks/index.js +3 -1
  41. package/lib/cjs/utils/hooks/useResizeObserver.d.ts +1 -0
  42. package/lib/cjs/utils/hooks/useResizeObserver.js +16 -0
  43. package/lib/cjs/utils/user.d.ts +8 -1
  44. package/lib/cjs/utils/user.js +15 -2
  45. package/lib/esm/constants/Cache.d.ts +12 -0
  46. package/lib/esm/constants/Cache.js +12 -0
  47. package/lib/esm/constants/Preferences.d.ts +18 -0
  48. package/lib/esm/constants/Preferences.js +33 -0
  49. package/lib/esm/constants/Routes.d.ts +6 -0
  50. package/lib/esm/constants/Routes.js +12 -0
  51. package/lib/esm/hooks/useFetchMenuFooter.d.ts +5 -0
  52. package/lib/esm/hooks/useFetchMenuFooter.js +33 -0
  53. package/lib/esm/hooks/useSCFeature.d.ts +22 -0
  54. package/lib/esm/hooks/useSCFeature.js +33 -0
  55. package/lib/esm/hooks/useSCFetchCategory.d.ts +1 -0
  56. package/lib/esm/hooks/useSCFetchCategory.js +18 -1
  57. package/lib/esm/hooks/useSCFetchCourse.js +15 -15
  58. package/lib/esm/hooks/useSCFetchEvent.d.ts +1 -0
  59. package/lib/esm/hooks/useSCFetchEvent.js +16 -1
  60. package/lib/esm/hooks/useSCFetchGroup.d.ts +1 -0
  61. package/lib/esm/hooks/useSCFetchGroup.js +16 -1
  62. package/lib/esm/hooks/useSCFetchPaymentOrder.d.ts +20 -0
  63. package/lib/esm/hooks/useSCFetchPaymentOrder.js +67 -0
  64. package/lib/esm/hooks/useSCFetchPaymentProduct.d.ts +20 -0
  65. package/lib/esm/hooks/useSCFetchPaymentProduct.js +67 -0
  66. package/lib/esm/hooks/useSCFetchUsers.d.ts +21 -0
  67. package/lib/esm/hooks/useSCFetchUsers.js +48 -0
  68. package/lib/esm/hooks/useSCJoinedCoursesManager.d.ts +1 -1
  69. package/lib/esm/hooks/useSCJoinedCoursesManager.js +37 -67
  70. package/lib/esm/hooks/useSCPaymentsEnabled.d.ts +18 -0
  71. package/lib/esm/hooks/useSCPaymentsEnabled.js +31 -0
  72. package/lib/esm/hooks/useSCPreference.d.ts +36 -0
  73. package/lib/esm/hooks/useSCPreference.js +65 -0
  74. package/lib/esm/hooks/useSCPreferencesAndFeaturesEnabled.d.ts +17 -0
  75. package/lib/esm/hooks/useSCPreferencesAndFeaturesEnabled.js +32 -0
  76. package/lib/esm/hooks/useSCSubscribedEventsManager.js +4 -14
  77. package/lib/esm/hooks/useSCSubscribedGroupsManager.d.ts +1 -1
  78. package/lib/esm/hooks/useSCSubscribedGroupsManager.js +29 -54
  79. package/lib/esm/index.d.ts +10 -2
  80. package/lib/esm/index.js +10 -2
  81. package/lib/esm/themes/theme.js +12 -0
  82. package/lib/esm/types/theme.d.ts +52 -0
  83. package/lib/esm/utils/hooks/index.d.ts +2 -1
  84. package/lib/esm/utils/hooks/index.js +2 -1
  85. package/lib/esm/utils/hooks/useResizeObserver.d.ts +1 -0
  86. package/lib/esm/utils/hooks/useResizeObserver.js +13 -0
  87. package/lib/esm/utils/user.d.ts +8 -1
  88. package/lib/esm/utils/user.js +13 -1
  89. package/lib/umd/react-core.js +1 -1
  90. package/package.json +6 -6
@@ -1,3 +1,4 @@
1
+ import { __awaiter } from "tslib";
1
2
  import { useEffect, useMemo, useRef } from 'react';
2
3
  import { Endpoints, http } from '@selfcommunity/api-services';
3
4
  import { SCFeatureName, SCCoursePrivacyType, SCCourseJoinStatusType, SCNotificationTopicType, SCNotificationTypologyType, } from '@selfcommunity/types';
@@ -33,21 +34,15 @@ export default function useSCJoinedCoursesManager(user) {
33
34
  CONFIGURATIONS_COURSES_ENABLED in preferences &&
34
35
  preferences[CONFIGURATIONS_COURSES_ENABLED].value, [preferences, features]);
35
36
  const notificationInvitedToJoinCourse = useRef(null);
36
- const notificationRequestedToJoinCourse = useRef(null);
37
- const notificationAcceptedToJoinCourse = useRef(null);
38
37
  const notificationAddedToCourse = useRef(null);
39
38
  /**
40
39
  * Subscribe to notification types user_follow, user_unfollow
41
40
  */
42
41
  useDeepCompareEffectNoCheck(() => {
43
42
  notificationInvitedToJoinCourse.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_INVITED_TO_JOIN_COURSE}`, notificationSubscriber);
44
- notificationRequestedToJoinCourse.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_COURSE}`, notificationSubscriber);
45
- notificationAcceptedToJoinCourse.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_COURSE}`, notificationSubscriber);
46
43
  notificationAddedToCourse.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ADDED_TO_COURSE}`, notificationSubscriber);
47
44
  return () => {
48
45
  PubSub.unsubscribe(notificationInvitedToJoinCourse.current);
49
- PubSub.unsubscribe(notificationRequestedToJoinCourse.current);
50
- PubSub.unsubscribe(notificationAcceptedToJoinCourse.current);
51
46
  PubSub.unsubscribe(notificationAddedToCourse.current);
52
47
  };
53
48
  }, [data]);
@@ -57,20 +52,20 @@ export default function useSCJoinedCoursesManager(user) {
57
52
  * @param dataMsg
58
53
  */
59
54
  const notificationSubscriber = (msg, dataMsg) => {
55
+ var _a;
60
56
  if (dataMsg.data.course !== undefined) {
61
57
  let _status;
62
58
  switch (SCNotificationMapping[dataMsg.data.activity_type]) {
63
59
  case SCNotificationTypologyType.USER_INVITED_TO_JOIN_COURSE:
64
60
  _status = SCCourseJoinStatusType.INVITED;
65
61
  break;
66
- case SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_COURSE:
67
- _status = SCCourseJoinStatusType.REQUESTED;
68
- break;
69
- case SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_COURSE:
70
- _status = SCCourseJoinStatusType.JOINED;
71
- break;
72
62
  case SCNotificationTypologyType.USER_ADDED_TO_COURSE:
73
- _status = SCCourseJoinStatusType.JOINED;
63
+ if (dataMsg.data.notification_obj.course && ((_a = dataMsg.data.notification_obj.course.paywalls) === null || _a === void 0 ? void 0 : _a.length)) {
64
+ _status = SCCourseJoinStatusType.PAYMENT_WAITING;
65
+ }
66
+ else {
67
+ _status = SCCourseJoinStatusType.JOINED;
68
+ }
74
69
  break;
75
70
  }
76
71
  updateCache([dataMsg.data.course]);
@@ -89,8 +84,8 @@ export default function useSCJoinedCoursesManager(user) {
89
84
  // Only if user is authenticated
90
85
  http
91
86
  .request({
92
- url: Endpoints.GetJoinedCourses.url(),
93
- method: Endpoints.GetJoinedCourses.method,
87
+ url: Endpoints.GetUserJoinedCourses.url({ id: user.id }),
88
+ method: Endpoints.GetUserJoinedCourses.method,
94
89
  })
95
90
  .then((res) => {
96
91
  if (res.status >= 300) {
@@ -111,67 +106,42 @@ export default function useSCJoinedCoursesManager(user) {
111
106
  * Memoized join Course
112
107
  * Toggle action
113
108
  */
114
- const join = useMemo(() => (course, userId) => {
109
+ const join = useMemo(() => (course) => __awaiter(this, void 0, void 0, function* () {
115
110
  setLoading(course.id);
116
- if (userId) {
117
- return http
118
- .request({
119
- url: Endpoints.InviteOrAcceptUsersToCourse.url({ id: course.id }),
120
- method: Endpoints.InviteOrAcceptUsersToCourse.method,
121
- data: { users: [userId] },
122
- })
123
- .then((res) => {
124
- if (res.status >= 300) {
125
- return Promise.reject(res);
126
- }
127
- updateCache([course.id]);
128
- setData((prev) => getDataUpdated(prev, course.id, SCCourseJoinStatusType.JOINED));
129
- setUnLoading(course.id);
130
- return Promise.resolve(res.data);
131
- });
132
- }
133
- else {
134
- return http
135
- .request({
136
- url: Endpoints.JoinOrAcceptInviteToCourse.url({ id: course.id }),
137
- method: Endpoints.JoinOrAcceptInviteToCourse.method,
138
- })
139
- .then((res) => {
140
- if (res.status >= 300) {
141
- return Promise.reject(res);
142
- }
143
- updateCache([course.id]);
144
- setData((prev) => getDataUpdated(prev, course.id, course.privacy === SCCoursePrivacyType.PRIVATE && course.join_status !== SCCourseJoinStatusType.INVITED
145
- ? SCCourseJoinStatusType.REQUESTED
146
- : SCCourseJoinStatusType.JOINED));
147
- setUnLoading(course.id);
148
- return Promise.resolve(res.data);
149
- });
111
+ const res = yield http.request({
112
+ url: Endpoints.JoinOrAcceptInviteToCourse.url({ id: course.id }),
113
+ method: Endpoints.JoinOrAcceptInviteToCourse.method,
114
+ });
115
+ if (res.status >= 300) {
116
+ return Promise.reject(res);
150
117
  }
151
- }, [data, loading, cache]);
118
+ updateCache([course.id]);
119
+ setData((prev) => getDataUpdated(prev, course.id, course.privacy === SCCoursePrivacyType.PRIVATE && course.join_status !== SCCourseJoinStatusType.INVITED
120
+ ? SCCourseJoinStatusType.REQUESTED
121
+ : SCCourseJoinStatusType.JOINED));
122
+ setUnLoading(course.id);
123
+ return yield Promise.resolve(res.data);
124
+ }), [data, loading, cache]);
152
125
  /**
153
126
  * Memoized leave Course
154
127
  * Toggle action
155
128
  */
156
- const leave = useMemo(() => (course) => {
157
- if (course.join_status !== SCCourseJoinStatusType.REQUESTED) {
129
+ const leave = useMemo(() => (course) => __awaiter(this, void 0, void 0, function* () {
130
+ if (data[course.id] !== SCCourseJoinStatusType.REQUESTED) {
158
131
  setLoading(course.id);
159
- return http
160
- .request({
132
+ const res = yield http.request({
161
133
  url: Endpoints.LeaveOrRemoveCourseRequest.url({ id: course.id }),
162
134
  method: Endpoints.LeaveOrRemoveCourseRequest.method,
163
- })
164
- .then((res) => {
165
- if (res.status >= 300) {
166
- return Promise.reject(res);
167
- }
168
- updateCache([course.id]);
169
- setData((prev) => getDataUpdated(prev, course.id, null));
170
- setUnLoading(course.id);
171
- return Promise.resolve(res.data);
172
135
  });
136
+ if (res.status >= 300) {
137
+ return Promise.reject(res);
138
+ }
139
+ updateCache([course.id]);
140
+ setData((prev) => getDataUpdated(prev, course.id, null));
141
+ setUnLoading(course.id);
142
+ return yield Promise.resolve(res.data);
173
143
  }
174
- }, [data, loading, cache]);
144
+ }), [data, loading, cache]);
175
145
  /**
176
146
  * Check the authenticated user subscription status to the course
177
147
  * Update the courses cached
@@ -247,7 +217,7 @@ export default function useSCJoinedCoursesManager(user) {
247
217
  if (cache.includes(course.id)) {
248
218
  return getCurrentCourseCacheStatus(course);
249
219
  }
250
- if (authUserId) {
220
+ if (authUserId && course) {
251
221
  if ('join_status' in course) {
252
222
  return getJoinStatus(course);
253
223
  }
@@ -256,7 +226,7 @@ export default function useSCJoinedCoursesManager(user) {
256
226
  }
257
227
  }
258
228
  return null;
259
- }, [loading, cache, authUserId]);
229
+ }, [loading, cache, authUserId, getJoinStatus, getCurrentCourseCacheStatus]);
260
230
  /**
261
231
  * Empty cache on logout
262
232
  */
@@ -0,0 +1,18 @@
1
+ /**
2
+ :::info
3
+ This custom hook is used to check if the payments are enabled
4
+ :::
5
+ :::tip How to use it:
6
+
7
+ Follow these steps:
8
+ ```jsx
9
+ 1. import useSCPaymentsEnabled from '@selfcommunity/react-core';
10
+ 2. const {isPaymentsEnabled, stripePublicKey, stripeConnectedAccountId} = useSCPaymentsEnabled();
11
+ ```
12
+ :::
13
+ */
14
+ export default function useSCPaymentsEnabled(): {
15
+ isPaymentsEnabled: any;
16
+ stripePublicKey: any;
17
+ stripeConnectedAccountId: any;
18
+ };
@@ -0,0 +1,31 @@
1
+ import { useMemo } from 'react';
2
+ import { SCFeatureName } from '@selfcommunity/types';
3
+ import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
4
+ import * as SCPreferences from '../constants/Preferences';
5
+ /**
6
+ :::info
7
+ This custom hook is used to check if the payments are enabled
8
+ :::
9
+ :::tip How to use it:
10
+
11
+ Follow these steps:
12
+ ```jsx
13
+ 1. import useSCPaymentsEnabled from '@selfcommunity/react-core';
14
+ 2. const {isPaymentsEnabled, stripePublicKey, stripeConnectedAccountId} = useSCPaymentsEnabled();
15
+ ```
16
+ :::
17
+ */
18
+ export default function useSCPaymentsEnabled() {
19
+ // CONTEXT
20
+ const { preferences, features } = useSCPreferences();
21
+ const isPaymentsEnabled = useMemo(() => preferences &&
22
+ features &&
23
+ features.includes(SCFeatureName.PAYMENTS) &&
24
+ SCPreferences.CONFIGURATIONS_PAYMENTS_ENABLED in preferences &&
25
+ preferences[SCPreferences.CONFIGURATIONS_PAYMENTS_ENABLED].value, [preferences]);
26
+ const stripePublicKey = useMemo(() => preferences && SCPreferences.STATIC_STRIPE_PUBLIC_KEY in preferences && preferences[SCPreferences.STATIC_STRIPE_PUBLIC_KEY].value, [preferences]);
27
+ const stripeConnectedAccountId = useMemo(() => preferences &&
28
+ SCPreferences.CONFIGURATIONS_STRIPE_CONNECTED_ACCOUNT_ID in preferences &&
29
+ preferences[SCPreferences.CONFIGURATIONS_STRIPE_CONNECTED_ACCOUNT_ID].value, [preferences]);
30
+ return { isPaymentsEnabled, stripePublicKey, stripeConnectedAccountId };
31
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Custom hook to recover a given preference.
3
+ * @param preferenceKey - full preference key (e.g., 'section.name')
4
+ * @param defaultValue - default returned value
5
+ * @returns the preference value or undefined/defaultValue if doesn't exist
6
+ *
7
+ * Ex.
8
+ * const customValue = useSCPreference<string>(SCPreferences.CUSTOM_SETTING);
9
+ * const numericValue = useSCPreference<number>(SCPreferences.CUSTOM_SETTING, 0);
10
+ */
11
+ declare function useSCPreference<T = any>(preferenceKey: string, defaultValue?: T): T | undefined;
12
+ /**
13
+ * Custom hook to check if a given preference is present and has a value.
14
+ * @param preferenceKey - full preference key (e.g., 'section.name')
15
+ * @param defaultValue - default returned value (default=false)
16
+ * @returns boolean
17
+ *
18
+ * Ex.
19
+ * const isEnabled = useSCPreferenceEnabled(SCPreferences.CONFIGURATIONS_CONNECTION_ENABLED);
20
+ **/
21
+ declare function useSCPreferenceEnabled(preferenceKey: string, defaultValue?: boolean): boolean;
22
+ /**
23
+ * Custom hook to check if all specified preferences are enabled
24
+ * @param preferenceKeys - Array of preference keys to check
25
+ * @param defaultValue - Default value if a preference doesn't exist
26
+ * @returns boolean - true if all preferences are enabled
27
+ *
28
+ * Ex.
29
+ * const arePreferencesEnabled = useSCPreferencesEnabled([
30
+ * SCPreferences.CONFIGURATIONS_POST_USER_ADDRESSING_ENABLED,
31
+ * SCPreferences.CONFIGURATIONS_SCHEDULED_POSTS_ENABLED
32
+ * ]);
33
+ */
34
+ declare function useSCPreferencesEnabled(preferenceKeys: string[], defaultValue?: boolean): boolean;
35
+ export { useSCPreferenceEnabled, useSCPreferencesEnabled };
36
+ export default useSCPreference;
@@ -0,0 +1,65 @@
1
+ import { useMemo } from 'react';
2
+ import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
3
+ /**
4
+ * Custom hook to recover a given preference.
5
+ * @param preferenceKey - full preference key (e.g., 'section.name')
6
+ * @param defaultValue - default returned value
7
+ * @returns the preference value or undefined/defaultValue if doesn't exist
8
+ *
9
+ * Ex.
10
+ * const customValue = useSCPreference&lt;string&gt;(SCPreferences.CUSTOM_SETTING);
11
+ * const numericValue = useSCPreference&lt;number&gt;(SCPreferences.CUSTOM_SETTING, 0);
12
+ */
13
+ function useSCPreference(preferenceKey, defaultValue) {
14
+ const { preferences } = useSCPreferences();
15
+ return useMemo(() => {
16
+ if (!preferences || !(preferenceKey in preferences)) {
17
+ return defaultValue;
18
+ }
19
+ const pref = preferences[preferenceKey];
20
+ return pref.value;
21
+ }, [preferences, preferenceKey, defaultValue]);
22
+ }
23
+ /**
24
+ * Custom hook to check if a given preference is present and has a value.
25
+ * @param preferenceKey - full preference key (e.g., 'section.name')
26
+ * @param defaultValue - default returned value (default=false)
27
+ * @returns boolean
28
+ *
29
+ * Ex.
30
+ * const isEnabled = useSCPreferenceEnabled(SCPreferences.CONFIGURATIONS_CONNECTION_ENABLED);
31
+ **/
32
+ function useSCPreferenceEnabled(preferenceKey, defaultValue = false) {
33
+ const value = useSCPreference(preferenceKey, defaultValue);
34
+ return value !== null && value !== void 0 ? value : defaultValue;
35
+ }
36
+ /**
37
+ * Custom hook to check if all specified preferences are enabled
38
+ * @param preferenceKeys - Array of preference keys to check
39
+ * @param defaultValue - Default value if a preference doesn't exist
40
+ * @returns boolean - true if all preferences are enabled
41
+ *
42
+ * Ex.
43
+ * const arePreferencesEnabled = useSCPreferencesEnabled([
44
+ * SCPreferences.CONFIGURATIONS_POST_USER_ADDRESSING_ENABLED,
45
+ * SCPreferences.CONFIGURATIONS_SCHEDULED_POSTS_ENABLED
46
+ * ]);
47
+ */
48
+ function useSCPreferencesEnabled(preferenceKeys, defaultValue = false) {
49
+ const { preferences } = useSCPreferences();
50
+ return useMemo(() => {
51
+ // Se non ci sono preferences o non è stato passato nessun preferenceKey, ritorna il valore di default
52
+ if (!preferences || !preferenceKeys.length) {
53
+ return defaultValue;
54
+ }
55
+ // Verifica che tutte le preferenze siano presenti e abbiano value = true
56
+ return preferenceKeys.every((key) => {
57
+ if (!(key in preferences)) {
58
+ return defaultValue;
59
+ }
60
+ return preferences[key].value;
61
+ });
62
+ }, [preferences, preferenceKeys, defaultValue]);
63
+ }
64
+ export { useSCPreferenceEnabled, useSCPreferencesEnabled };
65
+ export default useSCPreference;
@@ -0,0 +1,17 @@
1
+ import { SCFeatureName } from '@selfcommunity/types';
2
+ /**
3
+ * Custom hook preferences and features at the same time
4
+ * @param preferences - array of preference keys
5
+ * @param features - array of feature keys
6
+ * @returns boolean - true only if all preferences and features are enabled
7
+ *
8
+ * Ex.
9
+ * const isEnabled = useSCPreferencesAndFeaturesEnabled(
10
+ * [
11
+ * SCPreferences.CONFIGURATIONS_POST_USER_ADDRESSING_ENABLED,
12
+ * SCPreferences.CONFIGURATIONS_SCHEDULED_POSTS_ENABLED
13
+ * ],
14
+ * [SCFeatureName.TAGGING]
15
+ * );
16
+ */
17
+ export default function useSCPreferencesAndFeaturesEnabled(preferences: string[], features?: SCFeatureName[]): boolean;
@@ -0,0 +1,32 @@
1
+ import { useMemo } from 'react';
2
+ import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
3
+ /**
4
+ * Custom hook preferences and features at the same time
5
+ * @param preferences - array of preference keys
6
+ * @param features - array of feature keys
7
+ * @returns boolean - true only if all preferences and features are enabled
8
+ *
9
+ * Ex.
10
+ * const isEnabled = useSCPreferencesAndFeaturesEnabled(
11
+ * [
12
+ * SCPreferences.CONFIGURATIONS_POST_USER_ADDRESSING_ENABLED,
13
+ * SCPreferences.CONFIGURATIONS_SCHEDULED_POSTS_ENABLED
14
+ * ],
15
+ * [SCFeatureName.TAGGING]
16
+ * );
17
+ */
18
+ export default function useSCPreferencesAndFeaturesEnabled(preferences, features = []) {
19
+ const { preferences: preferencesContext, features: featuresContext } = useSCPreferences();
20
+ return useMemo(() => {
21
+ // Check available context
22
+ if (!preferencesContext || !featuresContext) {
23
+ return false;
24
+ }
25
+ // Check every preferences
26
+ const preferencesEnabled = preferences.every((key) => key in preferencesContext && preferencesContext[key].value);
27
+ // Check every features
28
+ const featuresEnabled = features.every((feature) => featuresContext.includes(feature));
29
+ // Return true only if all preferences and features are enabled
30
+ return preferencesEnabled && featuresEnabled;
31
+ }, [preferencesContext, featuresContext, preferences, features]);
32
+ }
@@ -34,21 +34,17 @@ export default function useSCSubscribedEventsManager(user) {
34
34
  CONFIGURATIONS_EVENTS_ENABLED in preferences &&
35
35
  preferences[CONFIGURATIONS_EVENTS_ENABLED].value, [preferences, features]);
36
36
  const notificationInvitedToJoinEvent = useRef(null);
37
- const notificationRequestedToJoinEvent = useRef(null);
38
- const notificationAcceptedToJoinEvent = useRef(null);
37
+ // const notificationRequestedToJoinEvent = useRef(null);
38
+ // const notificationAcceptedToJoinEvent = useRef(null);
39
39
  const notificationAddedToEvent = useRef(null);
40
40
  /**
41
41
  * Subscribe to notification types user_follow, user_unfollow
42
42
  */
43
43
  useDeepCompareEffectNoCheck(() => {
44
44
  notificationInvitedToJoinEvent.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_INVITED_TO_JOIN_EVENT}`, notificationSubscriber);
45
- notificationRequestedToJoinEvent.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_EVENT}`, notificationSubscriber);
46
- notificationAcceptedToJoinEvent.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_EVENT}`, notificationSubscriber);
47
45
  notificationAddedToEvent.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ADDED_TO_EVENT}`, notificationSubscriber);
48
46
  return () => {
49
47
  PubSub.unsubscribe(notificationInvitedToJoinEvent.current);
50
- PubSub.unsubscribe(notificationRequestedToJoinEvent.current);
51
- PubSub.unsubscribe(notificationAcceptedToJoinEvent.current);
52
48
  PubSub.unsubscribe(notificationAddedToEvent.current);
53
49
  };
54
50
  }, [data]);
@@ -64,12 +60,6 @@ export default function useSCSubscribedEventsManager(user) {
64
60
  case SCNotificationTypologyType.USER_INVITED_TO_JOIN_EVENT:
65
61
  _status = SCEventSubscriptionStatusType.INVITED;
66
62
  break;
67
- case SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_EVENT:
68
- _status = SCEventSubscriptionStatusType.REQUESTED;
69
- break;
70
- case SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_EVENT:
71
- _status = SCEventSubscriptionStatusType.SUBSCRIBED;
72
- break;
73
63
  case SCNotificationTypologyType.USER_ADDED_TO_EVENT:
74
64
  _status = SCEventSubscriptionStatusType.SUBSCRIBED;
75
65
  break;
@@ -90,8 +80,8 @@ export default function useSCSubscribedEventsManager(user) {
90
80
  // Only if user is authenticated
91
81
  http
92
82
  .request({
93
- url: Endpoints.GetUserEvents.url(),
94
- method: Endpoints.GetUserEvents.method,
83
+ url: Endpoints.GetUserSubscribedEvents.url({ id: user.id }),
84
+ method: Endpoints.GetUserSubscribedEvents.method,
95
85
  })
96
86
  .then((res) => {
97
87
  if (res.status >= 300) {
@@ -30,7 +30,7 @@ export default function useSCSubscribedGroupsManager(user?: SCUserType): {
30
30
  isLoading: (v: number | {
31
31
  id: number;
32
32
  }) => boolean;
33
- subscribe: (group: SCGroupType, userId?: number) => Promise<any>;
33
+ subscribe: (group: SCGroupType) => Promise<any>;
34
34
  unsubscribe: (group: SCGroupType) => Promise<any>;
35
35
  subscriptionStatus: (group: SCGroupType) => string;
36
36
  refresh: () => void;
@@ -34,21 +34,15 @@ export default function useSCSubscribedGroupsManager(user) {
34
34
  CONFIGURATIONS_GROUPS_ENABLED in preferences &&
35
35
  preferences[CONFIGURATIONS_GROUPS_ENABLED].value, [preferences, features]);
36
36
  const notificationInvitedToJoinGroup = useRef(null);
37
- const notificationRequestedToJoinGroup = useRef(null);
38
- const notificationAcceptedToJoinGroup = useRef(null);
39
37
  const notificationAddedToGroup = useRef(null);
40
38
  /**
41
39
  * Subscribe to notification types user_follow, user_unfollow
42
40
  */
43
41
  useDeepCompareEffectNoCheck(() => {
44
42
  notificationInvitedToJoinGroup.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_INVITED_TO_JOIN_GROUP}`, notificationSubscriber);
45
- notificationRequestedToJoinGroup.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_GROUP}`, notificationSubscriber);
46
- notificationAcceptedToJoinGroup.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_GROUP}`, notificationSubscriber);
47
43
  notificationAddedToGroup.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ADDED_TO_GROUP}`, notificationSubscriber);
48
44
  return () => {
49
45
  PubSub.unsubscribe(notificationInvitedToJoinGroup.current);
50
- PubSub.unsubscribe(notificationRequestedToJoinGroup.current);
51
- PubSub.unsubscribe(notificationAcceptedToJoinGroup.current);
52
46
  PubSub.unsubscribe(notificationAddedToGroup.current);
53
47
  };
54
48
  }, [data]);
@@ -58,20 +52,20 @@ export default function useSCSubscribedGroupsManager(user) {
58
52
  * @param dataMsg
59
53
  */
60
54
  const notificationSubscriber = (msg, dataMsg) => {
55
+ var _a;
61
56
  if (dataMsg.data.group !== undefined) {
62
57
  let _status;
63
58
  switch (SCNotificationMapping[dataMsg.data.activity_type]) {
64
59
  case SCNotificationTypologyType.USER_INVITED_TO_JOIN_GROUP:
65
60
  _status = SCGroupSubscriptionStatusType.INVITED;
66
61
  break;
67
- case SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_GROUP:
68
- _status = SCGroupSubscriptionStatusType.REQUESTED;
69
- break;
70
- case SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_GROUP:
71
- _status = SCGroupSubscriptionStatusType.SUBSCRIBED;
72
- break;
73
62
  case SCNotificationTypologyType.USER_ADDED_TO_GROUP:
74
- _status = SCGroupSubscriptionStatusType.SUBSCRIBED;
63
+ if (dataMsg.data.notification_obj.group && ((_a = dataMsg.data.notification_obj.group.paywalls) === null || _a === void 0 ? void 0 : _a.length)) {
64
+ _status = SCGroupSubscriptionStatusType.PAYMENT_WAITING;
65
+ }
66
+ else {
67
+ _status = SCGroupSubscriptionStatusType.SUBSCRIBED;
68
+ }
75
69
  break;
76
70
  }
77
71
  updateCache([dataMsg.data.group]);
@@ -90,8 +84,8 @@ export default function useSCSubscribedGroupsManager(user) {
90
84
  // Only if user is authenticated
91
85
  http
92
86
  .request({
93
- url: Endpoints.GetUserGroups.url(),
94
- method: Endpoints.GetUserGroups.method,
87
+ url: Endpoints.GetUserSubscribedGroups.url({ id: user.id }),
88
+ method: Endpoints.GetUserSubscribedGroups.method,
95
89
  })
96
90
  .then((res) => {
97
91
  if (res.status >= 300) {
@@ -112,50 +106,31 @@ export default function useSCSubscribedGroupsManager(user) {
112
106
  * Memoized subscribe Group
113
107
  * Toggle action
114
108
  */
115
- const subscribe = useMemo(() => (group, userId) => {
109
+ const subscribe = useMemo(() => (group) => {
116
110
  setLoading(group.id);
117
- if (userId) {
118
- return http
119
- .request({
120
- url: Endpoints.InviteOrAcceptGroupRequest.url({ id: group.id }),
121
- method: Endpoints.InviteOrAcceptGroupRequest.method,
122
- data: { users: [userId] },
123
- })
124
- .then((res) => {
125
- if (res.status >= 300) {
126
- return Promise.reject(res);
127
- }
128
- updateCache([group.id]);
129
- setData((prev) => getDataUpdated(prev, group.id, SCGroupSubscriptionStatusType.SUBSCRIBED));
130
- setUnLoading(group.id);
131
- return Promise.resolve(res.data);
132
- });
133
- }
134
- else {
135
- return http
136
- .request({
137
- url: Endpoints.SubscribeToGroup.url({ id: group.id }),
138
- method: Endpoints.SubscribeToGroup.method,
139
- })
140
- .then((res) => {
141
- if (res.status >= 300) {
142
- return Promise.reject(res);
143
- }
144
- updateCache([group.id]);
145
- setData((prev) => getDataUpdated(prev, group.id, group.privacy === SCGroupPrivacyType.PRIVATE && group.subscription_status !== SCGroupSubscriptionStatusType.INVITED
146
- ? SCGroupSubscriptionStatusType.REQUESTED
147
- : SCGroupSubscriptionStatusType.SUBSCRIBED));
148
- setUnLoading(group.id);
149
- return Promise.resolve(res.data);
150
- });
151
- }
111
+ return http
112
+ .request({
113
+ url: Endpoints.SubscribeToGroup.url({ id: group.id }),
114
+ method: Endpoints.SubscribeToGroup.method,
115
+ })
116
+ .then((res) => {
117
+ if (res.status >= 300) {
118
+ return Promise.reject(res);
119
+ }
120
+ updateCache([group.id]);
121
+ setData((prev) => getDataUpdated(prev, group.id, group.privacy === SCGroupPrivacyType.PRIVATE && group.subscription_status !== SCGroupSubscriptionStatusType.INVITED
122
+ ? SCGroupSubscriptionStatusType.REQUESTED
123
+ : SCGroupSubscriptionStatusType.SUBSCRIBED));
124
+ setUnLoading(group.id);
125
+ return Promise.resolve(res.data);
126
+ });
152
127
  }, [data, loading, cache]);
153
128
  /**
154
129
  * Memoized subscribe Group
155
130
  * Toggle action
156
131
  */
157
132
  const unsubscribe = useMemo(() => (group) => {
158
- if (group.subscription_status !== SCGroupSubscriptionStatusType.REQUESTED) {
133
+ if (data[group.id] !== SCGroupSubscriptionStatusType.REQUESTED) {
159
134
  setLoading(group.id);
160
135
  return http
161
136
  .request({
@@ -248,7 +223,7 @@ export default function useSCSubscribedGroupsManager(user) {
248
223
  if (cache.includes(group.id)) {
249
224
  return getCurrentGroupCacheStatus(group);
250
225
  }
251
- if (authUserId) {
226
+ if (authUserId && group) {
252
227
  if ('subscription_status' in group) {
253
228
  return getSubscriptionStatus(group);
254
229
  }
@@ -257,7 +232,7 @@ export default function useSCSubscribedGroupsManager(user) {
257
232
  }
258
233
  }
259
234
  return null;
260
- }, [loading, cache, authUserId]);
235
+ }, [loading, cache, authUserId, getSubscriptionStatus, getCurrentGroupCacheStatus]);
261
236
  /**
262
237
  * Empty cache on logout
263
238
  */
@@ -42,6 +42,7 @@ import * as SCCache from './constants/Cache';
42
42
  * Custom Hooks
43
43
  */
44
44
  import useSCFetchUser from './hooks/useSCFetchUser';
45
+ import useSCFetchUsers from './hooks/useSCFetchUsers';
45
46
  import useSCFetchUserProviders from './hooks/useSCFetchUserProviders';
46
47
  import useSCFetchVote from './hooks/useSCFetchVote';
47
48
  import useSCFetchFeedObject from './hooks/useSCFetchFeedObject';
@@ -71,6 +72,13 @@ import useSCGoogleApiLoader from './hooks/useSCGoogleApiLoader';
71
72
  import useSCFetchCourse from './hooks/useSCFetchCourse';
72
73
  import useSCFetchCourses from './hooks/useSCFetchCourses';
73
74
  import useSCFetchLesson from './hooks/useSCFetchLesson';
75
+ import useSCPaymentsEnabled from './hooks/useSCPaymentsEnabled';
76
+ import useSCFetchPaymentProduct from './hooks/useSCFetchPaymentProduct';
77
+ import useSCFetchPaymentOrder from './hooks/useSCFetchPaymentOrder';
78
+ import useFetchMenuFooter from './hooks/useFetchMenuFooter';
79
+ import useSCPreference, { useSCPreferenceEnabled, useSCPreferencesEnabled } from './hooks/useSCPreference';
80
+ import { useSCFeatureEnabled, useSCFeaturesEnabled } from './hooks/useSCFeature';
81
+ import useSCPreferencesAndFeaturesEnabled from './hooks/useSCPreferencesAndFeaturesEnabled';
74
82
  /**
75
83
  * Routing component
76
84
  */
@@ -82,7 +90,7 @@ import * as SCRoutes from './constants/Routes';
82
90
  */
83
91
  import * as UserUtils from './utils/user';
84
92
  import getTheme from './themes/theme';
85
- import { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility } from './utils/hooks';
93
+ import { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useResizeObserver } from './utils/hooks';
86
94
  import { getEventStatus } from './utils/event';
87
95
  /**
88
96
  * Constants:
@@ -93,4 +101,4 @@ import * as Preferences from './constants/Preferences';
93
101
  /**
94
102
  * List all exports
95
103
  */
96
- 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, SCJoinedCoursesManagerType, 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, useSCFetchLessonCommentObject, useSCFetchLessonCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, useSCGoogleApiLoader, useSCFetchCourse, useSCFetchCourses, useSCFetchLesson, };
104
+ 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, SCJoinedCoursesManagerType, 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, useSCFetchUsers, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchLessonCommentObject, useSCFetchLessonCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useResizeObserver, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, useSCGoogleApiLoader, useSCFetchCourse, useSCFetchCourses, useSCFetchLesson, useSCPaymentsEnabled, useSCFetchPaymentProduct, useSCFetchPaymentOrder, useFetchMenuFooter, useSCPreference, useSCPreferenceEnabled, useSCPreferencesEnabled, useSCFeatureEnabled, useSCFeaturesEnabled, useSCPreferencesAndFeaturesEnabled, };