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

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 (77) hide show
  1. package/lib/cjs/components/provider/SCThemeProvider/index.js +3 -3
  2. package/lib/cjs/constants/Cache.d.ts +6 -0
  3. package/lib/cjs/constants/Cache.js +9 -1
  4. package/lib/cjs/constants/Preferences.d.ts +14 -0
  5. package/lib/cjs/constants/Preferences.js +25 -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/useSCJoinedCoursesManager.d.ts +1 -1
  20. package/lib/cjs/hooks/useSCJoinedCoursesManager.js +36 -67
  21. package/lib/cjs/hooks/useSCPaymentsEnabled.d.ts +18 -0
  22. package/lib/cjs/hooks/useSCPaymentsEnabled.js +35 -0
  23. package/lib/cjs/hooks/useSCSubscribedEventsManager.js +4 -14
  24. package/lib/cjs/hooks/useSCSubscribedGroupsManager.d.ts +1 -1
  25. package/lib/cjs/hooks/useSCSubscribedGroupsManager.js +29 -54
  26. package/lib/cjs/hooks/useSCWebPushMessaging.js +2 -2
  27. package/lib/cjs/index.d.ts +5 -2
  28. package/lib/cjs/index.js +8 -1
  29. package/lib/cjs/themes/theme.js +14 -2
  30. package/lib/cjs/types/theme.d.ts +53 -1
  31. package/lib/cjs/utils/hooks/index.d.ts +2 -1
  32. package/lib/cjs/utils/hooks/index.js +3 -1
  33. package/lib/cjs/utils/hooks/useResizeObserver.d.ts +1 -0
  34. package/lib/cjs/utils/hooks/useResizeObserver.js +16 -0
  35. package/lib/cjs/utils/user.d.ts +8 -1
  36. package/lib/cjs/utils/user.js +15 -2
  37. package/lib/esm/components/provider/SCThemeProvider/index.js +1 -1
  38. package/lib/esm/constants/Cache.d.ts +6 -0
  39. package/lib/esm/constants/Cache.js +6 -0
  40. package/lib/esm/constants/Preferences.d.ts +14 -0
  41. package/lib/esm/constants/Preferences.js +22 -0
  42. package/lib/esm/constants/Routes.d.ts +6 -0
  43. package/lib/esm/constants/Routes.js +12 -0
  44. package/lib/esm/hooks/useSCFetchCategory.d.ts +1 -0
  45. package/lib/esm/hooks/useSCFetchCategory.js +18 -1
  46. package/lib/esm/hooks/useSCFetchCourse.js +15 -15
  47. package/lib/esm/hooks/useSCFetchEvent.d.ts +1 -0
  48. package/lib/esm/hooks/useSCFetchEvent.js +16 -1
  49. package/lib/esm/hooks/useSCFetchGroup.d.ts +1 -0
  50. package/lib/esm/hooks/useSCFetchGroup.js +16 -1
  51. package/lib/esm/hooks/useSCFetchPaymentOrder.d.ts +20 -0
  52. package/lib/esm/hooks/useSCFetchPaymentOrder.js +67 -0
  53. package/lib/esm/hooks/useSCFetchPaymentProduct.d.ts +20 -0
  54. package/lib/esm/hooks/useSCFetchPaymentProduct.js +67 -0
  55. package/lib/esm/hooks/useSCJoinedCoursesManager.d.ts +1 -1
  56. package/lib/esm/hooks/useSCJoinedCoursesManager.js +37 -67
  57. package/lib/esm/hooks/useSCPaymentsEnabled.d.ts +18 -0
  58. package/lib/esm/hooks/useSCPaymentsEnabled.js +31 -0
  59. package/lib/esm/hooks/useSCSubscribedEventsManager.js +4 -14
  60. package/lib/esm/hooks/useSCSubscribedGroupsManager.d.ts +1 -1
  61. package/lib/esm/hooks/useSCSubscribedGroupsManager.js +29 -54
  62. package/lib/esm/hooks/useSCWebPushMessaging.js +1 -1
  63. package/lib/esm/index.d.ts +5 -2
  64. package/lib/esm/index.js +5 -2
  65. package/lib/esm/themes/theme.js +13 -1
  66. package/lib/esm/types/theme.d.ts +53 -1
  67. package/lib/esm/utils/hooks/index.d.ts +2 -1
  68. package/lib/esm/utils/hooks/index.js +2 -1
  69. package/lib/esm/utils/hooks/useResizeObserver.d.ts +1 -0
  70. package/lib/esm/utils/hooks/useResizeObserver.js +13 -0
  71. package/lib/esm/utils/user.d.ts +8 -1
  72. package/lib/esm/utils/user.js +13 -1
  73. package/lib/umd/440.js +2 -0
  74. package/lib/umd/react-core.js +1 -1
  75. package/package.json +6 -6
  76. package/lib/umd/258.js +0 -2
  77. /package/lib/umd/{258.js.LICENSE.txt → 440.js.LICENSE.txt} +0 -0
@@ -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;
@@ -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
+ }
@@ -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
  */
@@ -3,7 +3,7 @@ import { useContext, useEffect, useRef, useState } from 'react';
3
3
  import { useSCContext } from '../components/provider/SCContextProvider';
4
4
  import { useSCUser } from '../components/provider/SCUserProvider';
5
5
  import { Logger } from '@selfcommunity/utils';
6
- import Button from '@mui/material/Button';
6
+ import { Button } from '@mui/material';
7
7
  import { loadVersionBrowser, urlB64ToUint8Array } from '@selfcommunity/utils';
8
8
  import { SCOPE_SC_CORE } from '../constants/Errors';
9
9
  import { http, Endpoints } from '@selfcommunity/api-services';
@@ -71,6 +71,9 @@ import useSCGoogleApiLoader from './hooks/useSCGoogleApiLoader';
71
71
  import useSCFetchCourse from './hooks/useSCFetchCourse';
72
72
  import useSCFetchCourses from './hooks/useSCFetchCourses';
73
73
  import useSCFetchLesson from './hooks/useSCFetchLesson';
74
+ import useSCPaymentsEnabled from './hooks/useSCPaymentsEnabled';
75
+ import useSCFetchPaymentProduct from './hooks/useSCFetchPaymentProduct';
76
+ import useSCFetchPaymentOrder from './hooks/useSCFetchPaymentOrder';
74
77
  /**
75
78
  * Routing component
76
79
  */
@@ -82,7 +85,7 @@ import * as SCRoutes from './constants/Routes';
82
85
  */
83
86
  import * as UserUtils from './utils/user';
84
87
  import getTheme from './themes/theme';
85
- import { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility } from './utils/hooks';
88
+ import { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useResizeObserver } from './utils/hooks';
86
89
  import { getEventStatus } from './utils/event';
87
90
  /**
88
91
  * Constants:
@@ -93,4 +96,4 @@ import * as Preferences from './constants/Preferences';
93
96
  /**
94
97
  * List all exports
95
98
  */
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, };
99
+ 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, useResizeObserver, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, useSCGoogleApiLoader, useSCFetchCourse, useSCFetchCourses, useSCFetchLesson, useSCPaymentsEnabled, useSCFetchPaymentProduct, useSCFetchPaymentOrder, };
package/lib/esm/index.js CHANGED
@@ -67,6 +67,9 @@ import useSCGoogleApiLoader from './hooks/useSCGoogleApiLoader';
67
67
  import useSCFetchCourse from './hooks/useSCFetchCourse';
68
68
  import useSCFetchCourses from './hooks/useSCFetchCourses';
69
69
  import useSCFetchLesson from './hooks/useSCFetchLesson';
70
+ import useSCPaymentsEnabled from './hooks/useSCPaymentsEnabled';
71
+ import useSCFetchPaymentProduct from './hooks/useSCFetchPaymentProduct';
72
+ import useSCFetchPaymentOrder from './hooks/useSCFetchPaymentOrder';
70
73
  /**
71
74
  * Routing component
72
75
  */
@@ -78,7 +81,7 @@ import * as SCRoutes from './constants/Routes';
78
81
  */
79
82
  import * as UserUtils from './utils/user';
80
83
  import getTheme from './themes/theme';
81
- import { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, } from './utils/hooks';
84
+ import { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useResizeObserver, } from './utils/hooks';
82
85
  import { getEventStatus } from './utils/event';
83
86
  /**
84
87
  * Constants:
@@ -89,4 +92,4 @@ import * as Preferences from './constants/Preferences';
89
92
  /**
90
93
  * List all exports
91
94
  */
92
- export { SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, 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, };
95
+ export { SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, 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, };
@@ -1,4 +1,4 @@
1
- import createTheme from '@mui/material/styles/createTheme';
1
+ import { createTheme } from '@mui/material';
2
2
  import { mergeDeep } from '@selfcommunity/utils';
3
3
  import validateColor from 'validate-color';
4
4
  import { COLORS_COLORBACK, COLORS_COLORPRIMARY, COLORS_COLORSECONDARY, COLORS_COLORFONT, COLORS_COLORFONTSECONDARY, COLORS_NAVBARBACK, STYLE_FONT_FAMILY, } from '../constants/Preferences';
@@ -48,6 +48,18 @@ const getTheme = (options, preferences) => {
48
48
  sizeXLarge: 120,
49
49
  },
50
50
  },
51
+ contentProduct: {
52
+ icon: {
53
+ sizeSmall: 24,
54
+ sizeMedium: 40,
55
+ },
56
+ },
57
+ contentProductPrice: {
58
+ icon: {
59
+ sizeSmall: 24,
60
+ sizeMedium: 40,
61
+ },
62
+ },
51
63
  };
52
64
  const defaultOptions = preferences
53
65
  ? {
@@ -1,4 +1,4 @@
1
- import { Theme as MuiTheme } from '@mui/material/styles/createTheme';
1
+ import { Theme as MuiTheme } from '@mui/material';
2
2
  /**
3
3
  * Interface SCThemeAvatarVariableType
4
4
  */
@@ -55,6 +55,32 @@ export interface SCThemeCategoryIconVariableType {
55
55
  */
56
56
  sizeLarge: number;
57
57
  }
58
+ /**
59
+ * Interface SCThemeContentProductIconVariableType
60
+ */
61
+ export interface SCThemeContentProductIconVariableType {
62
+ /**
63
+ * ContentProduct size small
64
+ */
65
+ sizeSmall: number;
66
+ /**
67
+ * ContentProduct size medium
68
+ */
69
+ sizeMedium: number;
70
+ }
71
+ /**
72
+ * Interface SCThemeContentProductPriceIconVariableType
73
+ */
74
+ export interface SCThemeContentProductPriceIconVariableType {
75
+ /**
76
+ * ContentProductPrice size small
77
+ */
78
+ sizeSmall: number;
79
+ /**
80
+ * ContentProductPrice size medium
81
+ */
82
+ sizeMedium: number;
83
+ }
58
84
  /**
59
85
  * Interface SCThemeCategoryVariableType
60
86
  */
@@ -64,6 +90,24 @@ export interface SCThemeCategoryVariableType {
64
90
  */
65
91
  icon: SCThemeCategoryIconVariableType;
66
92
  }
93
+ /**
94
+ * Interface SCThemeContentProductVariableType
95
+ */
96
+ export interface SCThemeContentProductVariableType {
97
+ /**
98
+ * ContentProduct icon size
99
+ */
100
+ icon: SCThemeContentProductIconVariableType;
101
+ }
102
+ /**
103
+ * Interface SCThemeContentProductPriceVariableType
104
+ */
105
+ export interface SCThemeContentProductPriceVariableType {
106
+ /**
107
+ * ContentProductPrice icon size
108
+ */
109
+ icon: SCThemeContentProductPriceIconVariableType;
110
+ }
67
111
  /**
68
112
  * Interface SCThemeVariablesType
69
113
  */
@@ -80,6 +124,14 @@ export interface SCThemeVariablesType {
80
124
  * Group
81
125
  */
82
126
  group: SCThemeGroupVariableType;
127
+ /**
128
+ * ContentProduct
129
+ */
130
+ contentProduct: SCThemeContentProductVariableType;
131
+ /**
132
+ * ContentProductPrice
133
+ */
134
+ contentProductPrice: SCThemeContentProductPriceVariableType;
83
135
  }
84
136
  export interface SCThemeType extends MuiTheme {
85
137
  /**
@@ -4,4 +4,5 @@ import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';
4
4
  import useEffectOnce from './useEffectOnce';
5
5
  import useNoInitialEffect from './useNoInitialEffect';
6
6
  import usePageVisibility from './usePageVisibility';
7
- export { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility };
7
+ import useResizeObserver from './useResizeObserver';
8
+ export { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useResizeObserver, };
@@ -4,4 +4,5 @@ import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';
4
4
  import useEffectOnce from './useEffectOnce';
5
5
  import useNoInitialEffect from './useNoInitialEffect';
6
6
  import usePageVisibility from './usePageVisibility';
7
- export { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility };
7
+ import useResizeObserver from './useResizeObserver';
8
+ export { useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useResizeObserver, };
@@ -0,0 +1 @@
1
+ export default function useResizeObserver(element: Element | null, options: ResizeObserverOptions | undefined, observerCallback: ResizeObserverCallback): void;
@@ -0,0 +1,13 @@
1
+ import { useEffect } from 'react';
2
+ export default function useResizeObserver(element, options, observerCallback) {
3
+ useEffect(() => {
4
+ if (!element || !('ResizeObserver' in window)) {
5
+ return undefined;
6
+ }
7
+ const observer = new ResizeObserver(observerCallback);
8
+ observer.observe(element, options);
9
+ return () => {
10
+ observer.disconnect();
11
+ };
12
+ }, [element, options, observerCallback]);
13
+ }