@selfcommunity/react-core 0.7.0-alpha.1 → 0.7.0-alpha.11

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 (85) hide show
  1. package/lib/cjs/components/provider/SCThemeProvider/index.js +3 -3
  2. package/lib/cjs/constants/Cache.d.ts +12 -0
  3. package/lib/cjs/constants/Cache.js +17 -1
  4. package/lib/cjs/constants/Preferences.d.ts +16 -0
  5. package/lib/cjs/constants/Preferences.js +31 -2
  6. package/lib/cjs/constants/Routes.d.ts +6 -0
  7. package/lib/cjs/constants/Routes.js +14 -1
  8. package/lib/cjs/hooks/useSCFetchCategory.d.ts +1 -0
  9. package/lib/cjs/hooks/useSCFetchCategory.js +18 -1
  10. package/lib/cjs/hooks/useSCFetchCourse.js +15 -15
  11. package/lib/cjs/hooks/useSCFetchEvent.d.ts +1 -0
  12. package/lib/cjs/hooks/useSCFetchEvent.js +16 -1
  13. package/lib/cjs/hooks/useSCFetchGroup.d.ts +1 -0
  14. package/lib/cjs/hooks/useSCFetchGroup.js +16 -1
  15. package/lib/cjs/hooks/useSCFetchPaymentOrder.d.ts +20 -0
  16. package/lib/cjs/hooks/useSCFetchPaymentOrder.js +70 -0
  17. package/lib/cjs/hooks/useSCFetchPaymentProduct.d.ts +20 -0
  18. package/lib/cjs/hooks/useSCFetchPaymentProduct.js +70 -0
  19. package/lib/cjs/hooks/useSCFetchUsers.d.ts +20 -0
  20. package/lib/cjs/hooks/useSCFetchUsers.js +50 -0
  21. package/lib/cjs/hooks/useSCJoinedCoursesManager.d.ts +1 -1
  22. package/lib/cjs/hooks/useSCJoinedCoursesManager.js +36 -67
  23. package/lib/cjs/hooks/useSCPaymentsEnabled.d.ts +18 -0
  24. package/lib/cjs/hooks/useSCPaymentsEnabled.js +35 -0
  25. package/lib/cjs/hooks/useSCPreferenceEnabled.d.ts +6 -0
  26. package/lib/cjs/hooks/useSCPreferenceEnabled.js +16 -0
  27. package/lib/cjs/hooks/useSCSubscribedEventsManager.js +4 -14
  28. package/lib/cjs/hooks/useSCSubscribedGroupsManager.d.ts +1 -1
  29. package/lib/cjs/hooks/useSCSubscribedGroupsManager.js +29 -54
  30. package/lib/cjs/hooks/useSCWebPushMessaging.js +2 -2
  31. package/lib/cjs/index.d.ts +7 -2
  32. package/lib/cjs/index.js +13 -2
  33. package/lib/cjs/themes/theme.js +14 -2
  34. package/lib/cjs/types/theme.d.ts +53 -1
  35. package/lib/cjs/utils/hooks/index.d.ts +2 -1
  36. package/lib/cjs/utils/hooks/index.js +3 -1
  37. package/lib/cjs/utils/hooks/useResizeObserver.d.ts +1 -0
  38. package/lib/cjs/utils/hooks/useResizeObserver.js +16 -0
  39. package/lib/cjs/utils/user.d.ts +8 -1
  40. package/lib/cjs/utils/user.js +15 -2
  41. package/lib/esm/components/provider/SCThemeProvider/index.js +1 -1
  42. package/lib/esm/constants/Cache.d.ts +12 -0
  43. package/lib/esm/constants/Cache.js +12 -0
  44. package/lib/esm/constants/Preferences.d.ts +16 -0
  45. package/lib/esm/constants/Preferences.js +28 -0
  46. package/lib/esm/constants/Routes.d.ts +6 -0
  47. package/lib/esm/constants/Routes.js +12 -0
  48. package/lib/esm/hooks/useSCFetchCategory.d.ts +1 -0
  49. package/lib/esm/hooks/useSCFetchCategory.js +18 -1
  50. package/lib/esm/hooks/useSCFetchCourse.js +15 -15
  51. package/lib/esm/hooks/useSCFetchEvent.d.ts +1 -0
  52. package/lib/esm/hooks/useSCFetchEvent.js +16 -1
  53. package/lib/esm/hooks/useSCFetchGroup.d.ts +1 -0
  54. package/lib/esm/hooks/useSCFetchGroup.js +16 -1
  55. package/lib/esm/hooks/useSCFetchPaymentOrder.d.ts +20 -0
  56. package/lib/esm/hooks/useSCFetchPaymentOrder.js +67 -0
  57. package/lib/esm/hooks/useSCFetchPaymentProduct.d.ts +20 -0
  58. package/lib/esm/hooks/useSCFetchPaymentProduct.js +67 -0
  59. package/lib/esm/hooks/useSCFetchUsers.d.ts +20 -0
  60. package/lib/esm/hooks/useSCFetchUsers.js +48 -0
  61. package/lib/esm/hooks/useSCJoinedCoursesManager.d.ts +1 -1
  62. package/lib/esm/hooks/useSCJoinedCoursesManager.js +37 -67
  63. package/lib/esm/hooks/useSCPaymentsEnabled.d.ts +18 -0
  64. package/lib/esm/hooks/useSCPaymentsEnabled.js +31 -0
  65. package/lib/esm/hooks/useSCPreferenceEnabled.d.ts +6 -0
  66. package/lib/esm/hooks/useSCPreferenceEnabled.js +13 -0
  67. package/lib/esm/hooks/useSCSubscribedEventsManager.js +4 -14
  68. package/lib/esm/hooks/useSCSubscribedGroupsManager.d.ts +1 -1
  69. package/lib/esm/hooks/useSCSubscribedGroupsManager.js +29 -54
  70. package/lib/esm/hooks/useSCWebPushMessaging.js +1 -1
  71. package/lib/esm/index.d.ts +7 -2
  72. package/lib/esm/index.js +7 -2
  73. package/lib/esm/themes/theme.js +13 -1
  74. package/lib/esm/types/theme.d.ts +53 -1
  75. package/lib/esm/utils/hooks/index.d.ts +2 -1
  76. package/lib/esm/utils/hooks/index.js +2 -1
  77. package/lib/esm/utils/hooks/useResizeObserver.d.ts +1 -0
  78. package/lib/esm/utils/hooks/useResizeObserver.js +13 -0
  79. package/lib/esm/utils/user.d.ts +8 -1
  80. package/lib/esm/utils/user.js +13 -1
  81. package/lib/umd/440.js +2 -0
  82. package/lib/umd/react-core.js +1 -1
  83. package/package.json +6 -6
  84. package/lib/umd/258.js +0 -2
  85. /package/lib/umd/{258.js.LICENSE.txt → 440.js.LICENSE.txt} +0 -0
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const api_services_1 = require("@selfcommunity/api-services");
4
+ const utils_1 = require("@selfcommunity/utils");
5
+ const react_1 = require("react");
6
+ const use_deep_compare_effect_1 = require("use-deep-compare-effect");
7
+ const SCUserProvider_1 = require("../components/provider/SCUserProvider");
8
+ const Cache_1 = require("../constants/Cache");
9
+ const Errors_1 = require("../constants/Errors");
10
+ /**
11
+ :::info
12
+ This custom hook is used to fetch a payment product.
13
+ :::
14
+ * @param object
15
+ * @param object.id
16
+ * @param object.paymentProduct
17
+ * @param object.cacheStrategy
18
+ */
19
+ function useSCFetchPaymentProduct({ id = null, paymentProduct = null, cacheStrategy = utils_1.CacheStrategies.NETWORK_ONLY, }) {
20
+ const __paymentProductId = (0, react_1.useMemo)(() => (paymentProduct === null || paymentProduct === void 0 ? void 0 : paymentProduct.id) || id, [paymentProduct, id]);
21
+ // CONTEXT
22
+ const scUserContext = (0, SCUserProvider_1.useSCUser)();
23
+ const authUserId = (0, react_1.useMemo)(() => { var _a; return ((_a = scUserContext.user) === null || _a === void 0 ? void 0 : _a.id) || null; }, [scUserContext.user]);
24
+ // CACHE
25
+ const __paymentProductCacheKey = (0, react_1.useMemo)(() => (0, Cache_1.getPaymentProductObjectCacheKey)(__paymentProductId), [__paymentProductId]);
26
+ const [scPaymentProduct, setScPaymentProduct] = (0, react_1.useState)(cacheStrategy !== utils_1.CacheStrategies.NETWORK_ONLY ? utils_1.LRUCache.get(__paymentProductCacheKey, paymentProduct) : null);
27
+ const [error, setError] = (0, react_1.useState)(null);
28
+ const setSCPaymentProduct = (0, react_1.useCallback)((c) => {
29
+ setScPaymentProduct(c);
30
+ utils_1.LRUCache.set(__paymentProductCacheKey, c);
31
+ }, [setScPaymentProduct, __paymentProductCacheKey]);
32
+ /**
33
+ * Memoized fetch product
34
+ */
35
+ const fetchPaymentProduct = (0, react_1.useMemo)(() => (id) => {
36
+ return api_services_1.http
37
+ .request({
38
+ url: api_services_1.Endpoints.GetPaymentProduct.url({ id }),
39
+ method: api_services_1.Endpoints.GetPaymentProduct.method,
40
+ })
41
+ .then((res) => {
42
+ if (res.status >= 300) {
43
+ return Promise.reject(res);
44
+ }
45
+ return Promise.resolve(res.data);
46
+ });
47
+ }, []);
48
+ /**
49
+ * If id attempt to get the course by id
50
+ */
51
+ (0, react_1.useEffect)(() => {
52
+ if (id !== null && id !== undefined && !paymentProduct) {
53
+ fetchPaymentProduct(id)
54
+ .then((e) => {
55
+ setSCPaymentProduct(e);
56
+ })
57
+ .catch((err) => {
58
+ utils_1.LRUCache.delete(__paymentProductCacheKey);
59
+ utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
60
+ });
61
+ }
62
+ }, [id, paymentProduct, authUserId]);
63
+ (0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
64
+ if (paymentProduct) {
65
+ setSCPaymentProduct(paymentProduct);
66
+ }
67
+ }, [paymentProduct, authUserId]);
68
+ return { scPaymentProduct, setSCPaymentProduct, error };
69
+ }
70
+ exports.default = useSCFetchPaymentProduct;
@@ -0,0 +1,20 @@
1
+ import { SCUserAutocompleteType } from '@selfcommunity/types';
2
+ /**
3
+ :::info
4
+ This custom hook is used to fetch users.
5
+
6
+ :::tip Context can be consumed in this way:
7
+
8
+ ```jsx
9
+ const {users, isLoading} = useSCFetchUsers();
10
+ ```
11
+ :::
12
+ * @param props
13
+ */
14
+ declare const useSCFetchUsers: (props?: {
15
+ search?: string;
16
+ }) => {
17
+ users: SCUserAutocompleteType[];
18
+ isLoading: boolean;
19
+ };
20
+ export default useSCFetchUsers;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = require("react");
5
+ const Errors_1 = require("../constants/Errors");
6
+ const api_services_1 = require("@selfcommunity/api-services");
7
+ const utils_1 = require("@selfcommunity/utils");
8
+ /**
9
+ :::info
10
+ This custom hook is used to fetch users.
11
+
12
+ :::tip Context can be consumed in this way:
13
+
14
+ ```jsx
15
+ const {users, isLoading} = useSCFetchUsers();
16
+ ```
17
+ :::
18
+ * @param props
19
+ */
20
+ const useSCFetchUsers = (props) => {
21
+ const { search = '' } = props || {};
22
+ const [data, setData] = (0, react_1.useState)({ users: [], isLoading: false });
23
+ const fetchUsers = (next = api_services_1.Endpoints.UserAutocomplete.url(), searchParam) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
24
+ const response = yield api_services_1.http.request({
25
+ url: next,
26
+ method: api_services_1.Endpoints.UserAutocomplete.method,
27
+ params: searchParam ? { search: searchParam } : undefined,
28
+ });
29
+ const data = response.data;
30
+ if (data.next) {
31
+ return data.results.concat(yield fetchUsers(data.next, searchParam));
32
+ }
33
+ return data.results;
34
+ });
35
+ (0, react_1.useEffect)(() => {
36
+ if (!search)
37
+ return;
38
+ fetchUsers(undefined, search)
39
+ .then((data) => {
40
+ setData({ users: data, isLoading: false });
41
+ })
42
+ .catch((error) => {
43
+ console.error(error);
44
+ utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, 'Unable to retrieve users');
45
+ setData((prev) => (Object.assign(Object.assign({}, prev), { isLoading: false })));
46
+ });
47
+ }, [search]);
48
+ return data;
49
+ };
50
+ exports.default = useSCFetchUsers;
@@ -30,7 +30,7 @@ export default function useSCJoinedCoursesManager(user?: SCUserType): {
30
30
  isLoading: (v: number | {
31
31
  id: number;
32
32
  }) => boolean;
33
- join: (course: SCCourseType, userId?: number) => Promise<any>;
33
+ join: (course: SCCourseType) => Promise<any>;
34
34
  leave: (course: SCCourseType) => Promise<any>;
35
35
  joinStatus: (course: SCCourseType) => string;
36
36
  refresh: () => void;
@@ -36,21 +36,15 @@ function useSCJoinedCoursesManager(user) {
36
36
  Preferences_1.CONFIGURATIONS_COURSES_ENABLED in preferences &&
37
37
  preferences[Preferences_1.CONFIGURATIONS_COURSES_ENABLED].value, [preferences, features]);
38
38
  const notificationInvitedToJoinCourse = (0, react_1.useRef)(null);
39
- const notificationRequestedToJoinCourse = (0, react_1.useRef)(null);
40
- const notificationAcceptedToJoinCourse = (0, react_1.useRef)(null);
41
39
  const notificationAddedToCourse = (0, react_1.useRef)(null);
42
40
  /**
43
41
  * Subscribe to notification types user_follow, user_unfollow
44
42
  */
45
43
  (0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
46
44
  notificationInvitedToJoinCourse.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_COURSE}`, notificationSubscriber);
47
- notificationRequestedToJoinCourse.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_COURSE}`, notificationSubscriber);
48
- notificationAcceptedToJoinCourse.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_COURSE}`, notificationSubscriber);
49
45
  notificationAddedToCourse.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_ADDED_TO_COURSE}`, notificationSubscriber);
50
46
  return () => {
51
47
  pubsub_js_1.default.unsubscribe(notificationInvitedToJoinCourse.current);
52
- pubsub_js_1.default.unsubscribe(notificationRequestedToJoinCourse.current);
53
- pubsub_js_1.default.unsubscribe(notificationAcceptedToJoinCourse.current);
54
48
  pubsub_js_1.default.unsubscribe(notificationAddedToCourse.current);
55
49
  };
56
50
  }, [data]);
@@ -60,20 +54,20 @@ function useSCJoinedCoursesManager(user) {
60
54
  * @param dataMsg
61
55
  */
62
56
  const notificationSubscriber = (msg, dataMsg) => {
57
+ var _a;
63
58
  if (dataMsg.data.course !== undefined) {
64
59
  let _status;
65
60
  switch (Notification_1.SCNotificationMapping[dataMsg.data.activity_type]) {
66
61
  case types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_COURSE:
67
62
  _status = types_1.SCCourseJoinStatusType.INVITED;
68
63
  break;
69
- case types_1.SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_COURSE:
70
- _status = types_1.SCCourseJoinStatusType.REQUESTED;
71
- break;
72
- case types_1.SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_COURSE:
73
- _status = types_1.SCCourseJoinStatusType.JOINED;
74
- break;
75
64
  case types_1.SCNotificationTypologyType.USER_ADDED_TO_COURSE:
76
- _status = types_1.SCCourseJoinStatusType.JOINED;
65
+ if (dataMsg.data.notification_obj.course && ((_a = dataMsg.data.notification_obj.course.paywalls) === null || _a === void 0 ? void 0 : _a.length)) {
66
+ _status = types_1.SCCourseJoinStatusType.PAYMENT_WAITING;
67
+ }
68
+ else {
69
+ _status = types_1.SCCourseJoinStatusType.JOINED;
70
+ }
77
71
  break;
78
72
  }
79
73
  updateCache([dataMsg.data.course]);
@@ -92,8 +86,8 @@ function useSCJoinedCoursesManager(user) {
92
86
  // Only if user is authenticated
93
87
  api_services_1.http
94
88
  .request({
95
- url: api_services_1.Endpoints.GetJoinedCourses.url(),
96
- method: api_services_1.Endpoints.GetJoinedCourses.method,
89
+ url: api_services_1.Endpoints.GetUserJoinedCourses.url({ id: user.id }),
90
+ method: api_services_1.Endpoints.GetUserJoinedCourses.method,
97
91
  })
98
92
  .then((res) => {
99
93
  if (res.status >= 300) {
@@ -114,67 +108,42 @@ function useSCJoinedCoursesManager(user) {
114
108
  * Memoized join Course
115
109
  * Toggle action
116
110
  */
117
- const join = (0, react_1.useMemo)(() => (course, userId) => {
111
+ const join = (0, react_1.useMemo)(() => (course) => tslib_1.__awaiter(this, void 0, void 0, function* () {
118
112
  setLoading(course.id);
119
- if (userId) {
120
- return api_services_1.http
121
- .request({
122
- url: api_services_1.Endpoints.InviteOrAcceptUsersToCourse.url({ id: course.id }),
123
- method: api_services_1.Endpoints.InviteOrAcceptUsersToCourse.method,
124
- data: { users: [userId] },
125
- })
126
- .then((res) => {
127
- if (res.status >= 300) {
128
- return Promise.reject(res);
129
- }
130
- updateCache([course.id]);
131
- setData((prev) => getDataUpdated(prev, course.id, types_1.SCCourseJoinStatusType.JOINED));
132
- setUnLoading(course.id);
133
- return Promise.resolve(res.data);
134
- });
135
- }
136
- else {
137
- return api_services_1.http
138
- .request({
139
- url: api_services_1.Endpoints.JoinOrAcceptInviteToCourse.url({ id: course.id }),
140
- method: api_services_1.Endpoints.JoinOrAcceptInviteToCourse.method,
141
- })
142
- .then((res) => {
143
- if (res.status >= 300) {
144
- return Promise.reject(res);
145
- }
146
- updateCache([course.id]);
147
- setData((prev) => getDataUpdated(prev, course.id, course.privacy === types_1.SCCoursePrivacyType.PRIVATE && course.join_status !== types_1.SCCourseJoinStatusType.INVITED
148
- ? types_1.SCCourseJoinStatusType.REQUESTED
149
- : types_1.SCCourseJoinStatusType.JOINED));
150
- setUnLoading(course.id);
151
- return Promise.resolve(res.data);
152
- });
113
+ const res = yield api_services_1.http.request({
114
+ url: api_services_1.Endpoints.JoinOrAcceptInviteToCourse.url({ id: course.id }),
115
+ method: api_services_1.Endpoints.JoinOrAcceptInviteToCourse.method,
116
+ });
117
+ if (res.status >= 300) {
118
+ return Promise.reject(res);
153
119
  }
154
- }, [data, loading, cache]);
120
+ updateCache([course.id]);
121
+ setData((prev) => getDataUpdated(prev, course.id, course.privacy === types_1.SCCoursePrivacyType.PRIVATE && course.join_status !== types_1.SCCourseJoinStatusType.INVITED
122
+ ? types_1.SCCourseJoinStatusType.REQUESTED
123
+ : types_1.SCCourseJoinStatusType.JOINED));
124
+ setUnLoading(course.id);
125
+ return yield Promise.resolve(res.data);
126
+ }), [data, loading, cache]);
155
127
  /**
156
128
  * Memoized leave Course
157
129
  * Toggle action
158
130
  */
159
- const leave = (0, react_1.useMemo)(() => (course) => {
160
- if (course.join_status !== types_1.SCCourseJoinStatusType.REQUESTED) {
131
+ const leave = (0, react_1.useMemo)(() => (course) => tslib_1.__awaiter(this, void 0, void 0, function* () {
132
+ if (data[course.id] !== types_1.SCCourseJoinStatusType.REQUESTED) {
161
133
  setLoading(course.id);
162
- return api_services_1.http
163
- .request({
134
+ const res = yield api_services_1.http.request({
164
135
  url: api_services_1.Endpoints.LeaveOrRemoveCourseRequest.url({ id: course.id }),
165
136
  method: api_services_1.Endpoints.LeaveOrRemoveCourseRequest.method,
166
- })
167
- .then((res) => {
168
- if (res.status >= 300) {
169
- return Promise.reject(res);
170
- }
171
- updateCache([course.id]);
172
- setData((prev) => getDataUpdated(prev, course.id, null));
173
- setUnLoading(course.id);
174
- return Promise.resolve(res.data);
175
137
  });
138
+ if (res.status >= 300) {
139
+ return Promise.reject(res);
140
+ }
141
+ updateCache([course.id]);
142
+ setData((prev) => getDataUpdated(prev, course.id, null));
143
+ setUnLoading(course.id);
144
+ return yield Promise.resolve(res.data);
176
145
  }
177
- }, [data, loading, cache]);
146
+ }), [data, loading, cache]);
178
147
  /**
179
148
  * Check the authenticated user subscription status to the course
180
149
  * Update the courses cached
@@ -250,7 +219,7 @@ function useSCJoinedCoursesManager(user) {
250
219
  if (cache.includes(course.id)) {
251
220
  return getCurrentCourseCacheStatus(course);
252
221
  }
253
- if (authUserId) {
222
+ if (authUserId && course) {
254
223
  if ('join_status' in course) {
255
224
  return getJoinStatus(course);
256
225
  }
@@ -259,7 +228,7 @@ function useSCJoinedCoursesManager(user) {
259
228
  }
260
229
  }
261
230
  return null;
262
- }, [loading, cache, authUserId]);
231
+ }, [loading, cache, authUserId, getJoinStatus, getCurrentCourseCacheStatus]);
263
232
  /**
264
233
  * Empty cache on logout
265
234
  */
@@ -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,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = require("react");
5
+ const types_1 = require("@selfcommunity/types");
6
+ const SCPreferencesProvider_1 = require("../components/provider/SCPreferencesProvider");
7
+ const SCPreferences = tslib_1.__importStar(require("../constants/Preferences"));
8
+ /**
9
+ :::info
10
+ This custom hook is used to check if the payments are enabled
11
+ :::
12
+ :::tip How to use it:
13
+
14
+ Follow these steps:
15
+ ```jsx
16
+ 1. import useSCPaymentsEnabled from '@selfcommunity/react-core';
17
+ 2. const {isPaymentsEnabled, stripePublicKey, stripeConnectedAccountId} = useSCPaymentsEnabled();
18
+ ```
19
+ :::
20
+ */
21
+ function useSCPaymentsEnabled() {
22
+ // CONTEXT
23
+ const { preferences, features } = (0, SCPreferencesProvider_1.useSCPreferences)();
24
+ const isPaymentsEnabled = (0, react_1.useMemo)(() => preferences &&
25
+ features &&
26
+ features.includes(types_1.SCFeatureName.PAYMENTS) &&
27
+ SCPreferences.CONFIGURATIONS_PAYMENTS_ENABLED in preferences &&
28
+ preferences[SCPreferences.CONFIGURATIONS_PAYMENTS_ENABLED].value, [preferences]);
29
+ const stripePublicKey = (0, react_1.useMemo)(() => preferences && SCPreferences.STATIC_STRIPE_PUBLIC_KEY in preferences && preferences[SCPreferences.STATIC_STRIPE_PUBLIC_KEY].value, [preferences]);
30
+ const stripeConnectedAccountId = (0, react_1.useMemo)(() => preferences &&
31
+ SCPreferences.CONFIGURATIONS_STRIPE_CONNECTED_ACCOUNT_ID in preferences &&
32
+ preferences[SCPreferences.CONFIGURATIONS_STRIPE_CONNECTED_ACCOUNT_ID].value, [preferences]);
33
+ return { isPaymentsEnabled, stripePublicKey, stripeConnectedAccountId };
34
+ }
35
+ exports.default = useSCPaymentsEnabled;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Custom hook to check if a given preference is present and has a value.
3
+ * @param preference - full preference key (e.g., 'section.name')
4
+ * @returns boolean - true if the preference exists and has a value
5
+ */
6
+ export default function useSCPreferenceEnabled(preference: string): boolean;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("react");
4
+ const SCPreferencesProvider_1 = require("../components/provider/SCPreferencesProvider");
5
+ /**
6
+ * Custom hook to check if a given preference is present and has a value.
7
+ * @param preference - full preference key (e.g., 'section.name')
8
+ * @returns boolean - true if the preference exists and has a value
9
+ */
10
+ function useSCPreferenceEnabled(preference) {
11
+ const { preferences } = (0, SCPreferencesProvider_1.useSCPreferences)();
12
+ return (0, react_1.useMemo)(() => {
13
+ return preferences && preference in preferences && preferences[preference].value;
14
+ }, [preferences, preference]);
15
+ }
16
+ exports.default = useSCPreferenceEnabled;
@@ -37,21 +37,17 @@ function useSCSubscribedEventsManager(user) {
37
37
  Preferences_1.CONFIGURATIONS_EVENTS_ENABLED in preferences &&
38
38
  preferences[Preferences_1.CONFIGURATIONS_EVENTS_ENABLED].value, [preferences, features]);
39
39
  const notificationInvitedToJoinEvent = (0, react_1.useRef)(null);
40
- const notificationRequestedToJoinEvent = (0, react_1.useRef)(null);
41
- const notificationAcceptedToJoinEvent = (0, react_1.useRef)(null);
40
+ // const notificationRequestedToJoinEvent = useRef(null);
41
+ // const notificationAcceptedToJoinEvent = useRef(null);
42
42
  const notificationAddedToEvent = (0, react_1.useRef)(null);
43
43
  /**
44
44
  * Subscribe to notification types user_follow, user_unfollow
45
45
  */
46
46
  (0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
47
47
  notificationInvitedToJoinEvent.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_EVENT}`, notificationSubscriber);
48
- notificationRequestedToJoinEvent.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_EVENT}`, notificationSubscriber);
49
- notificationAcceptedToJoinEvent.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_EVENT}`, notificationSubscriber);
50
48
  notificationAddedToEvent.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_ADDED_TO_EVENT}`, notificationSubscriber);
51
49
  return () => {
52
50
  pubsub_js_1.default.unsubscribe(notificationInvitedToJoinEvent.current);
53
- pubsub_js_1.default.unsubscribe(notificationRequestedToJoinEvent.current);
54
- pubsub_js_1.default.unsubscribe(notificationAcceptedToJoinEvent.current);
55
51
  pubsub_js_1.default.unsubscribe(notificationAddedToEvent.current);
56
52
  };
57
53
  }, [data]);
@@ -67,12 +63,6 @@ function useSCSubscribedEventsManager(user) {
67
63
  case types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_EVENT:
68
64
  _status = types_1.SCEventSubscriptionStatusType.INVITED;
69
65
  break;
70
- case types_1.SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_EVENT:
71
- _status = types_1.SCEventSubscriptionStatusType.REQUESTED;
72
- break;
73
- case types_1.SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_EVENT:
74
- _status = types_1.SCEventSubscriptionStatusType.SUBSCRIBED;
75
- break;
76
66
  case types_1.SCNotificationTypologyType.USER_ADDED_TO_EVENT:
77
67
  _status = types_1.SCEventSubscriptionStatusType.SUBSCRIBED;
78
68
  break;
@@ -93,8 +83,8 @@ function useSCSubscribedEventsManager(user) {
93
83
  // Only if user is authenticated
94
84
  api_services_1.http
95
85
  .request({
96
- url: api_services_1.Endpoints.GetUserEvents.url(),
97
- method: api_services_1.Endpoints.GetUserEvents.method,
86
+ url: api_services_1.Endpoints.GetUserSubscribedEvents.url({ id: user.id }),
87
+ method: api_services_1.Endpoints.GetUserSubscribedEvents.method,
98
88
  })
99
89
  .then((res) => {
100
90
  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;
@@ -37,21 +37,15 @@ function useSCSubscribedGroupsManager(user) {
37
37
  Preferences_1.CONFIGURATIONS_GROUPS_ENABLED in preferences &&
38
38
  preferences[Preferences_1.CONFIGURATIONS_GROUPS_ENABLED].value, [preferences, features]);
39
39
  const notificationInvitedToJoinGroup = (0, react_1.useRef)(null);
40
- const notificationRequestedToJoinGroup = (0, react_1.useRef)(null);
41
- const notificationAcceptedToJoinGroup = (0, react_1.useRef)(null);
42
40
  const notificationAddedToGroup = (0, react_1.useRef)(null);
43
41
  /**
44
42
  * Subscribe to notification types user_follow, user_unfollow
45
43
  */
46
44
  (0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
47
45
  notificationInvitedToJoinGroup.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_GROUP}`, notificationSubscriber);
48
- notificationRequestedToJoinGroup.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_GROUP}`, notificationSubscriber);
49
- notificationAcceptedToJoinGroup.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_GROUP}`, notificationSubscriber);
50
46
  notificationAddedToGroup.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_ADDED_TO_GROUP}`, notificationSubscriber);
51
47
  return () => {
52
48
  pubsub_js_1.default.unsubscribe(notificationInvitedToJoinGroup.current);
53
- pubsub_js_1.default.unsubscribe(notificationRequestedToJoinGroup.current);
54
- pubsub_js_1.default.unsubscribe(notificationAcceptedToJoinGroup.current);
55
49
  pubsub_js_1.default.unsubscribe(notificationAddedToGroup.current);
56
50
  };
57
51
  }, [data]);
@@ -61,20 +55,20 @@ function useSCSubscribedGroupsManager(user) {
61
55
  * @param dataMsg
62
56
  */
63
57
  const notificationSubscriber = (msg, dataMsg) => {
58
+ var _a;
64
59
  if (dataMsg.data.group !== undefined) {
65
60
  let _status;
66
61
  switch (Notification_1.SCNotificationMapping[dataMsg.data.activity_type]) {
67
62
  case types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_GROUP:
68
63
  _status = types_1.SCGroupSubscriptionStatusType.INVITED;
69
64
  break;
70
- case types_1.SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_GROUP:
71
- _status = types_1.SCGroupSubscriptionStatusType.REQUESTED;
72
- break;
73
- case types_1.SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_GROUP:
74
- _status = types_1.SCGroupSubscriptionStatusType.SUBSCRIBED;
75
- break;
76
65
  case types_1.SCNotificationTypologyType.USER_ADDED_TO_GROUP:
77
- _status = types_1.SCGroupSubscriptionStatusType.SUBSCRIBED;
66
+ if (dataMsg.data.notification_obj.group && ((_a = dataMsg.data.notification_obj.group.paywalls) === null || _a === void 0 ? void 0 : _a.length)) {
67
+ _status = types_1.SCGroupSubscriptionStatusType.PAYMENT_WAITING;
68
+ }
69
+ else {
70
+ _status = types_1.SCGroupSubscriptionStatusType.SUBSCRIBED;
71
+ }
78
72
  break;
79
73
  }
80
74
  updateCache([dataMsg.data.group]);
@@ -93,8 +87,8 @@ function useSCSubscribedGroupsManager(user) {
93
87
  // Only if user is authenticated
94
88
  api_services_1.http
95
89
  .request({
96
- url: api_services_1.Endpoints.GetUserGroups.url(),
97
- method: api_services_1.Endpoints.GetUserGroups.method,
90
+ url: api_services_1.Endpoints.GetUserSubscribedGroups.url({ id: user.id }),
91
+ method: api_services_1.Endpoints.GetUserSubscribedGroups.method,
98
92
  })
99
93
  .then((res) => {
100
94
  if (res.status >= 300) {
@@ -115,50 +109,31 @@ function useSCSubscribedGroupsManager(user) {
115
109
  * Memoized subscribe Group
116
110
  * Toggle action
117
111
  */
118
- const subscribe = (0, react_1.useMemo)(() => (group, userId) => {
112
+ const subscribe = (0, react_1.useMemo)(() => (group) => {
119
113
  setLoading(group.id);
120
- if (userId) {
121
- return api_services_1.http
122
- .request({
123
- url: api_services_1.Endpoints.InviteOrAcceptGroupRequest.url({ id: group.id }),
124
- method: api_services_1.Endpoints.InviteOrAcceptGroupRequest.method,
125
- data: { users: [userId] },
126
- })
127
- .then((res) => {
128
- if (res.status >= 300) {
129
- return Promise.reject(res);
130
- }
131
- updateCache([group.id]);
132
- setData((prev) => getDataUpdated(prev, group.id, types_1.SCGroupSubscriptionStatusType.SUBSCRIBED));
133
- setUnLoading(group.id);
134
- return Promise.resolve(res.data);
135
- });
136
- }
137
- else {
138
- return api_services_1.http
139
- .request({
140
- url: api_services_1.Endpoints.SubscribeToGroup.url({ id: group.id }),
141
- method: api_services_1.Endpoints.SubscribeToGroup.method,
142
- })
143
- .then((res) => {
144
- if (res.status >= 300) {
145
- return Promise.reject(res);
146
- }
147
- updateCache([group.id]);
148
- setData((prev) => getDataUpdated(prev, group.id, group.privacy === types_1.SCGroupPrivacyType.PRIVATE && group.subscription_status !== types_1.SCGroupSubscriptionStatusType.INVITED
149
- ? types_1.SCGroupSubscriptionStatusType.REQUESTED
150
- : types_1.SCGroupSubscriptionStatusType.SUBSCRIBED));
151
- setUnLoading(group.id);
152
- return Promise.resolve(res.data);
153
- });
154
- }
114
+ return api_services_1.http
115
+ .request({
116
+ url: api_services_1.Endpoints.SubscribeToGroup.url({ id: group.id }),
117
+ method: api_services_1.Endpoints.SubscribeToGroup.method,
118
+ })
119
+ .then((res) => {
120
+ if (res.status >= 300) {
121
+ return Promise.reject(res);
122
+ }
123
+ updateCache([group.id]);
124
+ setData((prev) => getDataUpdated(prev, group.id, group.privacy === types_1.SCGroupPrivacyType.PRIVATE && group.subscription_status !== types_1.SCGroupSubscriptionStatusType.INVITED
125
+ ? types_1.SCGroupSubscriptionStatusType.REQUESTED
126
+ : types_1.SCGroupSubscriptionStatusType.SUBSCRIBED));
127
+ setUnLoading(group.id);
128
+ return Promise.resolve(res.data);
129
+ });
155
130
  }, [data, loading, cache]);
156
131
  /**
157
132
  * Memoized subscribe Group
158
133
  * Toggle action
159
134
  */
160
135
  const unsubscribe = (0, react_1.useMemo)(() => (group) => {
161
- if (group.subscription_status !== types_1.SCGroupSubscriptionStatusType.REQUESTED) {
136
+ if (data[group.id] !== types_1.SCGroupSubscriptionStatusType.REQUESTED) {
162
137
  setLoading(group.id);
163
138
  return api_services_1.http
164
139
  .request({
@@ -251,7 +226,7 @@ function useSCSubscribedGroupsManager(user) {
251
226
  if (cache.includes(group.id)) {
252
227
  return getCurrentGroupCacheStatus(group);
253
228
  }
254
- if (authUserId) {
229
+ if (authUserId && group) {
255
230
  if ('subscription_status' in group) {
256
231
  return getSubscriptionStatus(group);
257
232
  }
@@ -260,7 +235,7 @@ function useSCSubscribedGroupsManager(user) {
260
235
  }
261
236
  }
262
237
  return null;
263
- }, [loading, cache, authUserId]);
238
+ }, [loading, cache, authUserId, getSubscriptionStatus, getCurrentGroupCacheStatus]);
264
239
  /**
265
240
  * Empty cache on logout
266
241
  */
@@ -7,7 +7,7 @@ const react_1 = require("react");
7
7
  const SCContextProvider_1 = require("../components/provider/SCContextProvider");
8
8
  const SCUserProvider_1 = require("../components/provider/SCUserProvider");
9
9
  const utils_1 = require("@selfcommunity/utils");
10
- const Button_1 = tslib_1.__importDefault(require("@mui/material/Button"));
10
+ const material_1 = require("@mui/material");
11
11
  const utils_2 = require("@selfcommunity/utils");
12
12
  const Errors_1 = require("../constants/Errors");
13
13
  const api_services_1 = require("@selfcommunity/api-services");
@@ -61,7 +61,7 @@ function useSCWebPushMessaging() {
61
61
  const showCustomRequestNotificationSnackbar = () => {
62
62
  if (!js_cookie_1.default.get(Notifications_1.NOTIFICATIONS_WEB_PUSH_MESSAGING_DIALOG_COOKIE)) {
63
63
  enqueueSnackbar(intl.formatMessage({ id: 'ui.webPushNotification.requestPermission', defaultMessage: 'ui.webPushNotification.requestPermission' }), {
64
- action: (snackbarId) => ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Button_1.default, Object.assign({ size: "small", sx: { color: '#FFF' }, onClick: () => requestNotificationPermission(snackbarId) }, { children: intl.formatMessage({ id: 'ui.webPushNotification.allow', defaultMessage: 'ui.webPushNotification.allow' }) })), (0, jsx_runtime_1.jsx)(Button_1.default, Object.assign({ size: "small", sx: { color: '#FFF' }, onClick: () => closeRequestNotificationSnackbar(snackbarId) }, { children: intl.formatMessage({ id: 'ui.webPushNotification.block', defaultMessage: 'ui.webPushNotification.block' }) }))] })),
64
+ action: (snackbarId) => ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ size: "small", sx: { color: '#FFF' }, onClick: () => requestNotificationPermission(snackbarId) }, { children: intl.formatMessage({ id: 'ui.webPushNotification.allow', defaultMessage: 'ui.webPushNotification.allow' }) })), (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ size: "small", sx: { color: '#FFF' }, onClick: () => closeRequestNotificationSnackbar(snackbarId) }, { children: intl.formatMessage({ id: 'ui.webPushNotification.block', defaultMessage: 'ui.webPushNotification.block' }) }))] })),
65
65
  variant: 'default',
66
66
  anchorOrigin: { horizontal: 'center', vertical: 'bottom' },
67
67
  preventDuplicate: true,