@selfcommunity/react-core 0.7.0-alpha.2 → 0.7.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/constants/Cache.d.ts +6 -0
- package/lib/cjs/constants/Cache.js +9 -1
- package/lib/cjs/constants/Preferences.d.ts +14 -0
- package/lib/cjs/constants/Preferences.js +25 -2
- package/lib/cjs/constants/Routes.d.ts +6 -0
- package/lib/cjs/constants/Routes.js +14 -1
- package/lib/cjs/hooks/useSCFetchCategory.d.ts +1 -0
- package/lib/cjs/hooks/useSCFetchCategory.js +18 -1
- package/lib/cjs/hooks/useSCFetchCourse.js +15 -15
- package/lib/cjs/hooks/useSCFetchEvent.d.ts +1 -0
- package/lib/cjs/hooks/useSCFetchEvent.js +16 -1
- package/lib/cjs/hooks/useSCFetchGroup.d.ts +1 -0
- package/lib/cjs/hooks/useSCFetchGroup.js +16 -1
- package/lib/cjs/hooks/useSCFetchPaymentOrder.d.ts +20 -0
- package/lib/cjs/hooks/useSCFetchPaymentOrder.js +70 -0
- package/lib/cjs/hooks/useSCFetchPaymentProduct.d.ts +20 -0
- package/lib/cjs/hooks/useSCFetchPaymentProduct.js +70 -0
- package/lib/cjs/hooks/useSCJoinedCoursesManager.d.ts +1 -1
- package/lib/cjs/hooks/useSCJoinedCoursesManager.js +36 -67
- package/lib/cjs/hooks/useSCPaymentsEnabled.d.ts +18 -0
- package/lib/cjs/hooks/useSCPaymentsEnabled.js +35 -0
- package/lib/cjs/hooks/useSCSubscribedEventsManager.js +4 -14
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.d.ts +1 -1
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.js +29 -54
- package/lib/cjs/index.d.ts +5 -2
- package/lib/cjs/index.js +8 -1
- package/lib/cjs/themes/theme.js +12 -0
- package/lib/cjs/types/theme.d.ts +52 -0
- package/lib/cjs/utils/hooks/index.d.ts +2 -1
- package/lib/cjs/utils/hooks/index.js +3 -1
- package/lib/cjs/utils/hooks/useResizeObserver.d.ts +1 -0
- package/lib/cjs/utils/hooks/useResizeObserver.js +16 -0
- package/lib/cjs/utils/user.d.ts +8 -1
- package/lib/cjs/utils/user.js +15 -2
- package/lib/esm/constants/Cache.d.ts +6 -0
- package/lib/esm/constants/Cache.js +6 -0
- package/lib/esm/constants/Preferences.d.ts +14 -0
- package/lib/esm/constants/Preferences.js +22 -0
- package/lib/esm/constants/Routes.d.ts +6 -0
- package/lib/esm/constants/Routes.js +12 -0
- package/lib/esm/hooks/useSCFetchCategory.d.ts +1 -0
- package/lib/esm/hooks/useSCFetchCategory.js +18 -1
- package/lib/esm/hooks/useSCFetchCourse.js +15 -15
- package/lib/esm/hooks/useSCFetchEvent.d.ts +1 -0
- package/lib/esm/hooks/useSCFetchEvent.js +16 -1
- package/lib/esm/hooks/useSCFetchGroup.d.ts +1 -0
- package/lib/esm/hooks/useSCFetchGroup.js +16 -1
- package/lib/esm/hooks/useSCFetchPaymentOrder.d.ts +20 -0
- package/lib/esm/hooks/useSCFetchPaymentOrder.js +67 -0
- package/lib/esm/hooks/useSCFetchPaymentProduct.d.ts +20 -0
- package/lib/esm/hooks/useSCFetchPaymentProduct.js +67 -0
- package/lib/esm/hooks/useSCJoinedCoursesManager.d.ts +1 -1
- package/lib/esm/hooks/useSCJoinedCoursesManager.js +37 -67
- package/lib/esm/hooks/useSCPaymentsEnabled.d.ts +18 -0
- package/lib/esm/hooks/useSCPaymentsEnabled.js +31 -0
- package/lib/esm/hooks/useSCSubscribedEventsManager.js +4 -14
- package/lib/esm/hooks/useSCSubscribedGroupsManager.d.ts +1 -1
- package/lib/esm/hooks/useSCSubscribedGroupsManager.js +29 -54
- package/lib/esm/index.d.ts +5 -2
- package/lib/esm/index.js +5 -2
- package/lib/esm/themes/theme.js +12 -0
- package/lib/esm/types/theme.d.ts +52 -0
- package/lib/esm/utils/hooks/index.d.ts +2 -1
- package/lib/esm/utils/hooks/index.js +2 -1
- package/lib/esm/utils/hooks/useResizeObserver.d.ts +1 -0
- package/lib/esm/utils/hooks/useResizeObserver.js +13 -0
- package/lib/esm/utils/user.d.ts +8 -1
- package/lib/esm/utils/user.js +13 -1
- package/lib/umd/440.js +2 -0
- package/lib/umd/react-core.js +1 -1
- package/package.json +6 -6
- package/lib/umd/258.js +0 -2
- /package/lib/umd/{258.js.LICENSE.txt → 440.js.LICENSE.txt} +0 -0
package/lib/cjs/utils/user.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { SCUserType } from '@selfcommunity/types';
|
|
|
6
6
|
export declare const ADMIN_ROLE = "admin";
|
|
7
7
|
export declare const MODERATOR_ROLE = "moderator";
|
|
8
8
|
export declare const EDITOR_ROLE = "editor";
|
|
9
|
+
export declare const PUBLISHER_ROLE = "publisher";
|
|
9
10
|
export declare const COMMUNITY_CREATOR = 1;
|
|
10
11
|
/**
|
|
11
12
|
* Get user role from roles(set)
|
|
@@ -38,7 +39,13 @@ export declare function isModerator(user: SCUserType): boolean;
|
|
|
38
39
|
*/
|
|
39
40
|
export declare function isEditor(user: SCUserType): boolean;
|
|
40
41
|
/**
|
|
41
|
-
* Check if user is
|
|
42
|
+
* Check if user is publisher
|
|
43
|
+
* @param user
|
|
44
|
+
* @returns boolean
|
|
45
|
+
*/
|
|
46
|
+
export declare function isPublisher(user: SCUserType): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Check if user is admin, moderator, editor or publisher
|
|
42
49
|
* @param user
|
|
43
50
|
* @returns boolean
|
|
44
51
|
*/
|
package/lib/cjs/utils/user.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isBlocked = exports.isStaff = exports.isEditor = exports.isModerator = exports.isCommunityCreator = exports.isAdmin = exports.getUserRole = exports.COMMUNITY_CREATOR = exports.EDITOR_ROLE = exports.MODERATOR_ROLE = exports.ADMIN_ROLE = void 0;
|
|
3
|
+
exports.isBlocked = exports.isStaff = exports.isPublisher = exports.isEditor = exports.isModerator = exports.isCommunityCreator = exports.isAdmin = exports.getUserRole = exports.COMMUNITY_CREATOR = exports.PUBLISHER_ROLE = exports.EDITOR_ROLE = exports.MODERATOR_ROLE = exports.ADMIN_ROLE = void 0;
|
|
4
4
|
const types_1 = require("@selfcommunity/types");
|
|
5
5
|
/**
|
|
6
6
|
* Staff Roles
|
|
@@ -9,6 +9,7 @@ const types_1 = require("@selfcommunity/types");
|
|
|
9
9
|
exports.ADMIN_ROLE = 'admin';
|
|
10
10
|
exports.MODERATOR_ROLE = 'moderator';
|
|
11
11
|
exports.EDITOR_ROLE = 'editor';
|
|
12
|
+
exports.PUBLISHER_ROLE = 'publisher';
|
|
12
13
|
exports.COMMUNITY_CREATOR = 1;
|
|
13
14
|
/**
|
|
14
15
|
* Get user role from roles(set)
|
|
@@ -27,6 +28,9 @@ function getUserRole(user) {
|
|
|
27
28
|
else if (role === exports.EDITOR_ROLE) {
|
|
28
29
|
return exports.EDITOR_ROLE;
|
|
29
30
|
}
|
|
31
|
+
else if (role === exports.PUBLISHER_ROLE) {
|
|
32
|
+
return exports.PUBLISHER_ROLE;
|
|
33
|
+
}
|
|
30
34
|
}
|
|
31
35
|
return null;
|
|
32
36
|
}
|
|
@@ -68,7 +72,16 @@ function isEditor(user) {
|
|
|
68
72
|
}
|
|
69
73
|
exports.isEditor = isEditor;
|
|
70
74
|
/**
|
|
71
|
-
* Check if user is
|
|
75
|
+
* Check if user is publisher
|
|
76
|
+
* @param user
|
|
77
|
+
* @returns boolean
|
|
78
|
+
*/
|
|
79
|
+
function isPublisher(user) {
|
|
80
|
+
return getUserRole(user) === exports.PUBLISHER_ROLE;
|
|
81
|
+
}
|
|
82
|
+
exports.isPublisher = isPublisher;
|
|
83
|
+
/**
|
|
84
|
+
* Check if user is admin, moderator, editor or publisher
|
|
72
85
|
* @param user
|
|
73
86
|
* @returns boolean
|
|
74
87
|
*/
|
|
@@ -76,6 +76,12 @@ export declare const getPmSnippetsObjectCacheKey: () => string;
|
|
|
76
76
|
/** PRIVATE MESSAGE SNIPPET OBJECT **/
|
|
77
77
|
export declare const PM_SNIPPET_OBJECT_CACHE_PREFIX_KEY = "_pms_";
|
|
78
78
|
export declare const getPmSnippetObjectCacheKey: (id: any) => string;
|
|
79
|
+
/** PAYMENT PRODUCT OBJECT **/
|
|
80
|
+
export declare const PAYMENT_PRODUCT_OBJECT_CACHE_PREFIX_KEY = "_ppo_";
|
|
81
|
+
export declare const getPaymentProductObjectCacheKey: (id: any) => string;
|
|
82
|
+
/** PAYMENT PRODUCT OBJECT **/
|
|
83
|
+
export declare const PAYMENT_ORDER_OBJECT_CACHE_PREFIX_KEY = "_pord_";
|
|
84
|
+
export declare const getPaymentOrderObjectCacheKey: (id: any) => string;
|
|
79
85
|
/** TOOLS */
|
|
80
86
|
export declare const CATEGORIES_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = "_cListWidget_";
|
|
81
87
|
export declare const CATEGORIES_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = "_cFolWidget_";
|
|
@@ -80,6 +80,12 @@ export const getPmSnippetsObjectCacheKey = () => `${PM_SNIPPETS_OBJECT_CACHE_PRE
|
|
|
80
80
|
/** PRIVATE MESSAGE SNIPPET OBJECT **/
|
|
81
81
|
export const PM_SNIPPET_OBJECT_CACHE_PREFIX_KEY = '_pms_';
|
|
82
82
|
export const getPmSnippetObjectCacheKey = (id) => `${PM_SNIPPET_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
83
|
+
/** PAYMENT PRODUCT OBJECT **/
|
|
84
|
+
export const PAYMENT_PRODUCT_OBJECT_CACHE_PREFIX_KEY = '_ppo_';
|
|
85
|
+
export const getPaymentProductObjectCacheKey = (id) => `${PAYMENT_PRODUCT_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
86
|
+
/** PAYMENT PRODUCT OBJECT **/
|
|
87
|
+
export const PAYMENT_ORDER_OBJECT_CACHE_PREFIX_KEY = '_pord_';
|
|
88
|
+
export const getPaymentOrderObjectCacheKey = (id) => `${PAYMENT_ORDER_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
83
89
|
/** TOOLS */
|
|
84
90
|
export const CATEGORIES_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = '_cListWidget_';
|
|
85
91
|
export const CATEGORIES_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = '_cFolWidget_';
|
|
@@ -81,6 +81,8 @@ export declare const ADDONS_POST_GEOLOCATION_ENABLED: string;
|
|
|
81
81
|
export declare const ADDONS_SHARE_POST_ON_FACEBOOK_ENABLED: string;
|
|
82
82
|
export declare const ADDONS_SHARE_POST_ON_TWITTER_ENABLED: string;
|
|
83
83
|
export declare const ADDONS_SHARE_POST_ON_LINKEDIN_ENABLED: string;
|
|
84
|
+
export declare const ADDONS_PRIVATE_MESSAGES_ENABLED: string;
|
|
85
|
+
export declare const ADDONS_SHARE_POST_ENABLED: string;
|
|
84
86
|
/**
|
|
85
87
|
* ADVERTISING
|
|
86
88
|
*/
|
|
@@ -89,6 +91,7 @@ export declare const ADVERTISING_CUSTOM_ADV_ONLY_FOR_ANONYMOUS_USERS_ENABLED: st
|
|
|
89
91
|
/**
|
|
90
92
|
* CONFIGURATIONS
|
|
91
93
|
*/
|
|
94
|
+
export declare const CONFIGURATIONS_CONNECTION_ENABLED: string;
|
|
92
95
|
export declare const CONFIGURATIONS_FOLLOW_ENABLED: string;
|
|
93
96
|
export declare const CONFIGURATIONS_EXPLORE_STREAM_ENABLED: string;
|
|
94
97
|
export declare const CONFIGURATIONS_EXPLORE_STREAM_ORDER_BY: string;
|
|
@@ -146,6 +149,16 @@ export declare const CONFIGURATIONS_LIVE_STREAM_ENABLED: string;
|
|
|
146
149
|
export declare const CONFIGURATIONS_LIVE_STREAM_ONLY_STAFF_ENABLED: string;
|
|
147
150
|
export declare const CONFIGURATIONS_LIVE_VIDEO_CONFERENCE_ENABLED: string;
|
|
148
151
|
export declare const CONFIGURATIONS_SUBSCRIPTION_TIER: string;
|
|
152
|
+
export declare const CONFIGURATIONS_PAYMENTS_ENABLED: string;
|
|
153
|
+
export declare const CONFIGURATIONS_STRIPE_CONNECTED_ACCOUNT_ID: string;
|
|
154
|
+
export declare const CONFIGURATIONS_CONTEXT_MENU_ENABLED: string;
|
|
155
|
+
export declare const CONFIGURATIONS_CATEGORY_FOLLOW_ENABLED: string;
|
|
156
|
+
export declare const CONFIGURATIONS_COMMENTS_ENABLED: string;
|
|
157
|
+
export declare const CONFIGURATIONS_SIDEBAR_SHOW_ALL_CATEGORIES_ENABLED: string;
|
|
158
|
+
export declare const CONFIGURATIONS_VIDEO_AUTOPLAY_ENABLED: string;
|
|
159
|
+
export declare const CONFIGURATIONS_SCHEDULED_POSTS_ENABLED: string;
|
|
160
|
+
export declare const CONFIGURATIONS_POST_CATEGORY_REQUIRED_ENABLED: string;
|
|
161
|
+
export declare const CONFIGURATIONS_POST_ADDRESSING_REQUIRED_ENABLED: string;
|
|
149
162
|
/**
|
|
150
163
|
* PROVIDERS
|
|
151
164
|
*/
|
|
@@ -177,6 +190,7 @@ export declare const WEBMASTER_META_DESCRIPTION: string;
|
|
|
177
190
|
*/
|
|
178
191
|
export declare const STATIC_ENVIRONMENT: string;
|
|
179
192
|
export declare const STATIC_STACKID: string;
|
|
193
|
+
export declare const STATIC_STRIPE_PUBLIC_KEY: string;
|
|
180
194
|
export declare const getPreferenceSection: (value: any) => any;
|
|
181
195
|
export declare const getPreferenceName: (value: any) => any;
|
|
182
196
|
export declare const getPreference: (value: any) => {
|
|
@@ -82,6 +82,8 @@ export const ADDONS_POST_GEOLOCATION_ENABLED = `${SCPreferenceSection.ADDONS}.${
|
|
|
82
82
|
export const ADDONS_SHARE_POST_ON_FACEBOOK_ENABLED = `${SCPreferenceSection.ADDONS}.${SCPreferenceName.SHARE_POST_ON_FACEBOOK_ENABLED}`;
|
|
83
83
|
export const ADDONS_SHARE_POST_ON_TWITTER_ENABLED = `${SCPreferenceSection.ADDONS}.${SCPreferenceName.SHARE_POST_ON_TWITTER_ENABLED}`;
|
|
84
84
|
export const ADDONS_SHARE_POST_ON_LINKEDIN_ENABLED = `${SCPreferenceSection.ADDONS}.${SCPreferenceName.SHARE_POST_ON_LINKEDIN_ENABLED}`;
|
|
85
|
+
export const ADDONS_PRIVATE_MESSAGES_ENABLED = `${SCPreferenceSection.ADDONS}.${SCPreferenceName.PRIVATE_MESSAGES_ENABLED}`;
|
|
86
|
+
export const ADDONS_SHARE_POST_ENABLED = `${SCPreferenceSection.ADDONS}.${SCPreferenceName.SHARE_POST_ENABLED}`;
|
|
85
87
|
/**
|
|
86
88
|
* ADVERTISING
|
|
87
89
|
*/
|
|
@@ -90,6 +92,7 @@ export const ADVERTISING_CUSTOM_ADV_ONLY_FOR_ANONYMOUS_USERS_ENABLED = `${SCPref
|
|
|
90
92
|
/**
|
|
91
93
|
* CONFIGURATIONS
|
|
92
94
|
*/
|
|
95
|
+
export const CONFIGURATIONS_CONNECTION_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.CONNECTION_ENABLED}`;
|
|
93
96
|
export const CONFIGURATIONS_FOLLOW_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.FOLLOW_ENABLED}`;
|
|
94
97
|
export const CONFIGURATIONS_EXPLORE_STREAM_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.EXPLORE_STREAM_ENABLED}`;
|
|
95
98
|
export const CONFIGURATIONS_EXPLORE_STREAM_ORDER_BY = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.EXPLORE_STREAM_ORDER_BY}`;
|
|
@@ -147,6 +150,16 @@ export const CONFIGURATIONS_LIVE_STREAM_ENABLED = `${SCPreferenceSection.CONFIGU
|
|
|
147
150
|
export const CONFIGURATIONS_LIVE_STREAM_ONLY_STAFF_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.LIVE_STREAM_ONLY_STAFF_ENABLED}`;
|
|
148
151
|
export const CONFIGURATIONS_LIVE_VIDEO_CONFERENCE_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.LIVE_STREAM_VIDEO_CONFERENCE_ENABLED}`;
|
|
149
152
|
export const CONFIGURATIONS_SUBSCRIPTION_TIER = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.SUBSCRIPTION_TIER}`;
|
|
153
|
+
export const CONFIGURATIONS_PAYMENTS_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.PAYMENTS_ENABLED}`;
|
|
154
|
+
export const CONFIGURATIONS_STRIPE_CONNECTED_ACCOUNT_ID = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.STRIPE_CONNECTED_ACCOUNT_ID}`;
|
|
155
|
+
export const CONFIGURATIONS_CONTEXT_MENU_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.CONTEXT_MENU_ENABLED}`;
|
|
156
|
+
export const CONFIGURATIONS_CATEGORY_FOLLOW_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.CATEGORY_FOLLOW_ENABLED}`;
|
|
157
|
+
export const CONFIGURATIONS_COMMENTS_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.COMMENTS_ENABLED}`;
|
|
158
|
+
export const CONFIGURATIONS_SIDEBAR_SHOW_ALL_CATEGORIES_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.SIDEBAR_SHOW_ALL_CATEGORIES_ENABLED}`;
|
|
159
|
+
export const CONFIGURATIONS_VIDEO_AUTOPLAY_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.VIDEO_AUTOPLAY_ENABLED}`;
|
|
160
|
+
export const CONFIGURATIONS_SCHEDULED_POSTS_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.SCHEDULED_POSTS_ENABLED}`;
|
|
161
|
+
export const CONFIGURATIONS_POST_CATEGORY_REQUIRED_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.POST_CATEGORY_REQUIRED_ENABLED}`;
|
|
162
|
+
export const CONFIGURATIONS_POST_ADDRESSING_REQUIRED_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.POST_ADDRESSING_REQUIRED_ENABLED}`;
|
|
150
163
|
/**
|
|
151
164
|
* PROVIDERS
|
|
152
165
|
*/
|
|
@@ -178,6 +191,7 @@ export const WEBMASTER_META_DESCRIPTION = `${SCPreferenceSection.WEBMASTER}.${SC
|
|
|
178
191
|
*/
|
|
179
192
|
export const STATIC_ENVIRONMENT = `${SCPreferenceSection.STATIC}.${SCPreferenceName.ENVIRONMENT}`;
|
|
180
193
|
export const STATIC_STACKID = `${SCPreferenceSection.STATIC}.${SCPreferenceName.STACK_ID}`;
|
|
194
|
+
export const STATIC_STRIPE_PUBLIC_KEY = `${SCPreferenceSection.STATIC}.${SCPreferenceName.STRIPE_PUBLIC_KEY}`;
|
|
181
195
|
const booleanType = (value) => {
|
|
182
196
|
if (value === 'True') {
|
|
183
197
|
return true;
|
|
@@ -252,6 +266,7 @@ export const DATA_TYPES = {
|
|
|
252
266
|
[ADDONS_SHARE_POST_ON_FACEBOOK_ENABLED]: booleanType,
|
|
253
267
|
[ADDONS_SHARE_POST_ON_TWITTER_ENABLED]: booleanType,
|
|
254
268
|
[ADDONS_SHARE_POST_ON_LINKEDIN_ENABLED]: booleanType,
|
|
269
|
+
[ADDONS_SHARE_POST_ENABLED]: booleanType,
|
|
255
270
|
[CONFIGURATIONS_FOLLOW_ENABLED]: booleanType,
|
|
256
271
|
[CONFIGURATIONS_EXPLORE_STREAM_ENABLED]: booleanType,
|
|
257
272
|
[CONFIGURATIONS_EXPLORE_STREAM_ORDER_BY]: stringType,
|
|
@@ -308,6 +323,12 @@ export const DATA_TYPES = {
|
|
|
308
323
|
[CONFIGURATIONS_LIVE_STREAM_ONLY_STAFF_ENABLED]: booleanType,
|
|
309
324
|
[CONFIGURATIONS_LIVE_VIDEO_CONFERENCE_ENABLED]: booleanType,
|
|
310
325
|
[CONFIGURATIONS_SUBSCRIPTION_TIER]: stringType,
|
|
326
|
+
[CONFIGURATIONS_PAYMENTS_ENABLED]: booleanType,
|
|
327
|
+
[CONFIGURATIONS_STRIPE_CONNECTED_ACCOUNT_ID]: stringType,
|
|
328
|
+
[CONFIGURATIONS_CONTEXT_MENU_ENABLED]: booleanType,
|
|
329
|
+
[CONFIGURATIONS_COMMENTS_ENABLED]: booleanType,
|
|
330
|
+
[CONFIGURATIONS_SIDEBAR_SHOW_ALL_CATEGORIES_ENABLED]: booleanType,
|
|
331
|
+
[CONFIGURATIONS_VIDEO_AUTOPLAY_ENABLED]: booleanType,
|
|
311
332
|
[PROVIDERS_APP_URL_ON_APP_STORE]: stringType,
|
|
312
333
|
[PROVIDERS_APP_URL_ON_GOOGLE_PLAY]: stringType,
|
|
313
334
|
[PROVIDERS_FACEBOOK_SIGNIN_ENABLED]: stringType,
|
|
@@ -330,4 +351,5 @@ export const DATA_TYPES = {
|
|
|
330
351
|
[WEBMASTER_META_DESCRIPTION]: stringType,
|
|
331
352
|
[STATIC_ENVIRONMENT]: stringType,
|
|
332
353
|
[STATIC_STACKID]: stringType,
|
|
354
|
+
[STATIC_STRIPE_PUBLIC_KEY]: stringType,
|
|
333
355
|
};
|
|
@@ -23,7 +23,12 @@ export declare const USER_PROFILE_CONNECTIONS_REQUESTS_ROUTE_NAME = "user_connec
|
|
|
23
23
|
export declare const USER_PROFILE_CONNECTIONS_REQUESTS_SENT_ROUTE_NAME = "user_connections_requests_sent";
|
|
24
24
|
export declare const USER_PROFILE_CATEGORIES_ROUTE_NAME = "user_categories";
|
|
25
25
|
export declare const USER_PROFILE_FOLLOWED_POSTS_ROUTE_NAME = "user_followed_posts";
|
|
26
|
+
export declare const USER_PROFILE_SCHEDULED_POSTS_ROUTE_NAME = "user_scheduled_posts";
|
|
27
|
+
export declare const USER_PROFILE_SCHEDULED_DISCUSSIONS_ROUTE_NAME = "user_scheduled_discussions";
|
|
26
28
|
export declare const USER_PROFILE_FOLLOWED_DISCUSSIONS_ROUTE_NAME = "user_followed_discussions";
|
|
29
|
+
export declare const USER_PAYMENTS_HISTORY_ORDERS_ROUTE_NAME = "user_payments_history_orders";
|
|
30
|
+
export declare const USER_PAYMENTS_ORDER_PDF_ROUTE_NAME = "user_payments_order_pdf";
|
|
31
|
+
export declare const USER_PAYMENT_METHODS_ROUTE_NAME = "user_payment_methods";
|
|
27
32
|
export declare const LOYALTY_ROUTE_NAME = "loyalty";
|
|
28
33
|
export declare const INCUBATOR_ROUTE_NAME = "incubator";
|
|
29
34
|
export declare const SIGNIN_ROUTE_NAME = "signin";
|
|
@@ -50,6 +55,7 @@ export declare const EVENTS_SUGGESTED_ROUTE_NAME = "events_suggested";
|
|
|
50
55
|
export declare const EVENTS_SUBSCRIBED_ROUTE_NAME = "events_subscribed";
|
|
51
56
|
export declare const EVENTS_HIGHLIGHT_ROUTE_NAME = "events_highlight";
|
|
52
57
|
export declare const LIVESTREAM_ROUTE_NAME = "live";
|
|
58
|
+
export declare const CHECKOUT_PAYMENT = "checkout_payment";
|
|
53
59
|
/**
|
|
54
60
|
* Default Routes
|
|
55
61
|
* @type {{[p: string]: string, '[POST_ROUTE_NAME]': string, '[INCUBATOR_ROUTE_NAME]': string, '[LOYALTY_ROUTE_NAME]': string, '[USER_NOTIFICATION_ROUTE_NAME]': string, '[USER_PRIVATE_MESSAGES_ROUTE_NAME]': string, '[COMMENT_ROUTE_NAME]': string, '[DISCUSSION_ROUTE_NAME]': string, '[CATEGORIES_ROUTE_NAME]': string, '[USER_PROFILE_ROUTE_NAME]': string, '[CATEGORY_ROUTE_NAME]': string, '[USER_PROFILE_SETTINGS_ROUTE_NAME]': string, '[STATUS_ROUTE_NAME]': string}}
|
|
@@ -23,7 +23,12 @@ export const USER_PROFILE_CONNECTIONS_REQUESTS_ROUTE_NAME = 'user_connections_re
|
|
|
23
23
|
export const USER_PROFILE_CONNECTIONS_REQUESTS_SENT_ROUTE_NAME = 'user_connections_requests_sent';
|
|
24
24
|
export const USER_PROFILE_CATEGORIES_ROUTE_NAME = 'user_categories';
|
|
25
25
|
export const USER_PROFILE_FOLLOWED_POSTS_ROUTE_NAME = 'user_followed_posts';
|
|
26
|
+
export const USER_PROFILE_SCHEDULED_POSTS_ROUTE_NAME = 'user_scheduled_posts';
|
|
27
|
+
export const USER_PROFILE_SCHEDULED_DISCUSSIONS_ROUTE_NAME = 'user_scheduled_discussions';
|
|
26
28
|
export const USER_PROFILE_FOLLOWED_DISCUSSIONS_ROUTE_NAME = 'user_followed_discussions';
|
|
29
|
+
export const USER_PAYMENTS_HISTORY_ORDERS_ROUTE_NAME = 'user_payments_history_orders';
|
|
30
|
+
export const USER_PAYMENTS_ORDER_PDF_ROUTE_NAME = 'user_payments_order_pdf';
|
|
31
|
+
export const USER_PAYMENT_METHODS_ROUTE_NAME = 'user_payment_methods';
|
|
27
32
|
export const LOYALTY_ROUTE_NAME = 'loyalty';
|
|
28
33
|
export const INCUBATOR_ROUTE_NAME = 'incubator';
|
|
29
34
|
export const SIGNIN_ROUTE_NAME = 'signin';
|
|
@@ -50,6 +55,7 @@ export const EVENTS_SUGGESTED_ROUTE_NAME = 'events_suggested';
|
|
|
50
55
|
export const EVENTS_SUBSCRIBED_ROUTE_NAME = 'events_subscribed';
|
|
51
56
|
export const EVENTS_HIGHLIGHT_ROUTE_NAME = 'events_highlight';
|
|
52
57
|
export const LIVESTREAM_ROUTE_NAME = 'live';
|
|
58
|
+
export const CHECKOUT_PAYMENT = 'checkout_payment';
|
|
53
59
|
/**
|
|
54
60
|
* Default Routes
|
|
55
61
|
* @type {{[p: string]: string, '[POST_ROUTE_NAME]': string, '[INCUBATOR_ROUTE_NAME]': string, '[LOYALTY_ROUTE_NAME]': string, '[USER_NOTIFICATION_ROUTE_NAME]': string, '[USER_PRIVATE_MESSAGES_ROUTE_NAME]': string, '[COMMENT_ROUTE_NAME]': string, '[DISCUSSION_ROUTE_NAME]': string, '[CATEGORIES_ROUTE_NAME]': string, '[USER_PROFILE_ROUTE_NAME]': string, '[CATEGORY_ROUTE_NAME]': string, '[USER_PROFILE_SETTINGS_ROUTE_NAME]': string, '[STATUS_ROUTE_NAME]': string}}
|
|
@@ -75,7 +81,12 @@ export const defaultRoutes = {
|
|
|
75
81
|
[USER_PROFILE_CONNECTIONS_REQUESTS_SENT_ROUTE_NAME]: '/user/:id/connections/requests/sent/',
|
|
76
82
|
[USER_PROFILE_CATEGORIES_ROUTE_NAME]: '/user/:id/categories/',
|
|
77
83
|
[USER_PROFILE_FOLLOWED_POSTS_ROUTE_NAME]: '/user/:id/posts/followed/',
|
|
84
|
+
[USER_PROFILE_SCHEDULED_POSTS_ROUTE_NAME]: '/user/:id/posts/scheduled/',
|
|
78
85
|
[USER_PROFILE_FOLLOWED_DISCUSSIONS_ROUTE_NAME]: '/user/:id/discussions/followed/',
|
|
86
|
+
[USER_PROFILE_SCHEDULED_DISCUSSIONS_ROUTE_NAME]: '/user/:id/discussions/scheduled/',
|
|
87
|
+
[USER_PAYMENTS_HISTORY_ORDERS_ROUTE_NAME]: '/user/:id/:username/history_orders/',
|
|
88
|
+
[USER_PAYMENTS_ORDER_PDF_ROUTE_NAME]: '/user/:id/:username/order/:pid/pdf/',
|
|
89
|
+
[USER_PAYMENT_METHODS_ROUTE_NAME]: '/user/:id/:username/payment_methods/',
|
|
79
90
|
[LOYALTY_ROUTE_NAME]: '/loyalty/',
|
|
80
91
|
[INCUBATOR_ROUTE_NAME]: '/incubator/:id/',
|
|
81
92
|
[SIGNIN_ROUTE_NAME]: '/signin/',
|
|
@@ -102,4 +113,5 @@ export const defaultRoutes = {
|
|
|
102
113
|
[COURSE_LESSON_COMMENTS_ROUTE_NAME]: '/course/:id/:slug/section/:section_id/lesson/:lesson_id/comments',
|
|
103
114
|
[COURSE_LESSON_EDIT_ROUTE_NAME]: '/course/:id/:slug/section/:section_id/lesson/:lesson_id/edit',
|
|
104
115
|
[LIVESTREAM_ROUTE_NAME]: '/live/:slug/',
|
|
116
|
+
[CHECKOUT_PAYMENT]: '/checkout/:content_type/:content_id/price/:price_id',
|
|
105
117
|
};
|
|
@@ -40,6 +40,23 @@ export default function useSCFetchCategory({ id = null, category = null, cacheSt
|
|
|
40
40
|
return Promise.resolve(res.data);
|
|
41
41
|
});
|
|
42
42
|
}, [__categoryId]);
|
|
43
|
+
/**
|
|
44
|
+
* Refresh category
|
|
45
|
+
*/
|
|
46
|
+
const refreshCategory = useMemo(() => () => {
|
|
47
|
+
fetchCategory()
|
|
48
|
+
.then((obj) => {
|
|
49
|
+
const _c = authUserId ? obj : objectWithoutProperties(obj, ['followed']);
|
|
50
|
+
setSCCategory(_c);
|
|
51
|
+
LRUCache.set(__categoryCacheKey, _c);
|
|
52
|
+
})
|
|
53
|
+
.catch((err) => {
|
|
54
|
+
LRUCache.delete(__categoryCacheKey);
|
|
55
|
+
setError(`Error on refresh category with id ${id}`);
|
|
56
|
+
Logger.error(SCOPE_SC_CORE, `Error on refresh category with id ${id}`);
|
|
57
|
+
Logger.error(SCOPE_SC_CORE, err.message);
|
|
58
|
+
});
|
|
59
|
+
}, [__categoryId, setSCCategory, __categoryCacheKey]);
|
|
43
60
|
/**
|
|
44
61
|
* If id attempt to get the category by id
|
|
45
62
|
*/
|
|
@@ -66,5 +83,5 @@ export default function useSCFetchCategory({ id = null, category = null, cacheSt
|
|
|
66
83
|
LRUCache.set(__categoryCacheKey, _c);
|
|
67
84
|
}
|
|
68
85
|
}, [category]);
|
|
69
|
-
return { scCategory, setSCCategory, error };
|
|
86
|
+
return { scCategory, setSCCategory, error, refreshCategory };
|
|
70
87
|
}
|
|
@@ -46,6 +46,21 @@ export default function useSCFetchCourse({ id = null, course = null, cacheStrate
|
|
|
46
46
|
return Promise.resolve(res.data);
|
|
47
47
|
});
|
|
48
48
|
}, []);
|
|
49
|
+
/**
|
|
50
|
+
* Refresh course
|
|
51
|
+
*/
|
|
52
|
+
const refreshCourse = useMemo(() => () => {
|
|
53
|
+
fetchCourse(id)
|
|
54
|
+
.then((e) => {
|
|
55
|
+
setSCCourse(e);
|
|
56
|
+
})
|
|
57
|
+
.catch((err) => {
|
|
58
|
+
LRUCache.delete(__courseCacheKey);
|
|
59
|
+
setError(`Error on refresh course with id ${id}`);
|
|
60
|
+
Logger.error(SCOPE_SC_CORE, `Error on refresh course with id ${id}`);
|
|
61
|
+
Logger.error(SCOPE_SC_CORE, err.message);
|
|
62
|
+
});
|
|
63
|
+
}, [id, __courseCacheKey, setSCCourse]);
|
|
49
64
|
/**
|
|
50
65
|
* If id attempt to get the course by id
|
|
51
66
|
*/
|
|
@@ -74,20 +89,5 @@ export default function useSCFetchCourse({ id = null, course = null, cacheStrate
|
|
|
74
89
|
setSCCourse(course);
|
|
75
90
|
}
|
|
76
91
|
}, [course, authUserId]);
|
|
77
|
-
/**
|
|
78
|
-
* Refreshes course data from the network
|
|
79
|
-
*/
|
|
80
|
-
const refreshCourse = useCallback(() => {
|
|
81
|
-
if (id) {
|
|
82
|
-
fetchCourse(id)
|
|
83
|
-
.then((e) => {
|
|
84
|
-
setSCCourse(e);
|
|
85
|
-
})
|
|
86
|
-
.catch((err) => {
|
|
87
|
-
setError(`Failed to refresh course data: ${err.message}`);
|
|
88
|
-
Logger.error(SCOPE_SC_CORE, err.message);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}, [id, fetchCourse]);
|
|
92
92
|
return { scCourse, setSCCourse, error, refreshCourse };
|
|
93
93
|
}
|
|
@@ -66,6 +66,21 @@ export default function useSCFetchEvent({ id = null, event = null, autoSubscribe
|
|
|
66
66
|
return Promise.resolve(res.data);
|
|
67
67
|
});
|
|
68
68
|
}, []);
|
|
69
|
+
/**
|
|
70
|
+
* Refresh event
|
|
71
|
+
*/
|
|
72
|
+
const refreshEvent = useMemo(() => () => () => {
|
|
73
|
+
fetchEvent(id)
|
|
74
|
+
.then((e) => {
|
|
75
|
+
setSCEvent(e);
|
|
76
|
+
})
|
|
77
|
+
.catch((err) => {
|
|
78
|
+
LRUCache.delete(__eventCacheKey);
|
|
79
|
+
setError(`Error on refresh event with id ${id}`);
|
|
80
|
+
Logger.error(SCOPE_SC_CORE, `Error on refresh event with id ${id}`);
|
|
81
|
+
Logger.error(SCOPE_SC_CORE, err.message);
|
|
82
|
+
});
|
|
83
|
+
}, [id, setSCEvent, __eventCacheKey]);
|
|
69
84
|
/**
|
|
70
85
|
* If id attempt to get the event by id
|
|
71
86
|
*/
|
|
@@ -88,5 +103,5 @@ export default function useSCFetchEvent({ id = null, event = null, autoSubscribe
|
|
|
88
103
|
setSCEvent(event);
|
|
89
104
|
}
|
|
90
105
|
}, [event, authUserId]);
|
|
91
|
-
return { scEvent, setSCEvent, error };
|
|
106
|
+
return { scEvent, setSCEvent, error, refreshEvent };
|
|
92
107
|
}
|
|
@@ -45,6 +45,21 @@ export default function useSCFetchGroup({ id = null, group = null, cacheStrategy
|
|
|
45
45
|
return Promise.resolve(res.data);
|
|
46
46
|
});
|
|
47
47
|
}, [__groupId]);
|
|
48
|
+
/**
|
|
49
|
+
* Refresh group
|
|
50
|
+
*/
|
|
51
|
+
const refreshGroup = useMemo(() => () => {
|
|
52
|
+
fetchGroup()
|
|
53
|
+
.then((obj) => {
|
|
54
|
+
setSCGroup(obj);
|
|
55
|
+
})
|
|
56
|
+
.catch((err) => {
|
|
57
|
+
LRUCache.delete(__groupCacheKey);
|
|
58
|
+
setError(`Error on refresh group with id ${id}`);
|
|
59
|
+
Logger.error(SCOPE_SC_CORE, `Error on refresh group with id ${id}`);
|
|
60
|
+
Logger.error(SCOPE_SC_CORE, err.message);
|
|
61
|
+
});
|
|
62
|
+
}, [__groupCacheKey, setSCGroup]);
|
|
48
63
|
/**
|
|
49
64
|
* If id attempt to get the group by id
|
|
50
65
|
*/
|
|
@@ -67,5 +82,5 @@ export default function useSCFetchGroup({ id = null, group = null, cacheStrategy
|
|
|
67
82
|
setSCGroup(group);
|
|
68
83
|
}
|
|
69
84
|
}, [group, authUserId]);
|
|
70
|
-
return { scGroup, setSCGroup, error };
|
|
85
|
+
return { scGroup, setSCGroup, error, refreshGroup };
|
|
71
86
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SCPaymentOrder } from '@selfcommunity/types';
|
|
2
|
+
import { CacheStrategies } from '@selfcommunity/utils';
|
|
3
|
+
/**
|
|
4
|
+
:::info
|
|
5
|
+
This custom hook is used to fetch a payment order.
|
|
6
|
+
:::
|
|
7
|
+
* @param object
|
|
8
|
+
* @param object.id
|
|
9
|
+
* @param object.paymentOrder
|
|
10
|
+
* @param object.cacheStrategy
|
|
11
|
+
*/
|
|
12
|
+
export default function useSCFetchPaymentOrder({ id, paymentOrder, cacheStrategy, }: {
|
|
13
|
+
id?: number | string;
|
|
14
|
+
paymentOrder?: SCPaymentOrder;
|
|
15
|
+
cacheStrategy?: CacheStrategies;
|
|
16
|
+
}): {
|
|
17
|
+
scPaymentOrder: SCPaymentOrder;
|
|
18
|
+
setSCPaymentOrder: (c: SCPaymentOrder) => void;
|
|
19
|
+
error: string;
|
|
20
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Endpoints, http } from '@selfcommunity/api-services';
|
|
2
|
+
import { CacheStrategies, Logger, LRUCache } from '@selfcommunity/utils';
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
|
+
import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect';
|
|
5
|
+
import { useSCUser } from '../components/provider/SCUserProvider';
|
|
6
|
+
import { getPaymentOrderObjectCacheKey } from '../constants/Cache';
|
|
7
|
+
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
8
|
+
/**
|
|
9
|
+
:::info
|
|
10
|
+
This custom hook is used to fetch a payment order.
|
|
11
|
+
:::
|
|
12
|
+
* @param object
|
|
13
|
+
* @param object.id
|
|
14
|
+
* @param object.paymentOrder
|
|
15
|
+
* @param object.cacheStrategy
|
|
16
|
+
*/
|
|
17
|
+
export default function useSCFetchPaymentOrder({ id = null, paymentOrder = null, cacheStrategy = CacheStrategies.NETWORK_ONLY, }) {
|
|
18
|
+
const __paymentOrderId = useMemo(() => (paymentOrder === null || paymentOrder === void 0 ? void 0 : paymentOrder.id) || id, [paymentOrder, id]);
|
|
19
|
+
// CONTEXT
|
|
20
|
+
const scUserContext = useSCUser();
|
|
21
|
+
const authUserId = useMemo(() => { var _a; return ((_a = scUserContext.user) === null || _a === void 0 ? void 0 : _a.id) || null; }, [scUserContext.user]);
|
|
22
|
+
// CACHE
|
|
23
|
+
const __paymentOrderCacheKey = useMemo(() => getPaymentOrderObjectCacheKey(__paymentOrderId), [__paymentOrderId]);
|
|
24
|
+
const [scPaymentOrder, setScPaymentOrder] = useState(cacheStrategy !== CacheStrategies.NETWORK_ONLY ? LRUCache.get(__paymentOrderCacheKey, paymentOrder) : null);
|
|
25
|
+
const [error, setError] = useState(null);
|
|
26
|
+
const setSCPaymentOrder = useCallback((c) => {
|
|
27
|
+
setScPaymentOrder(c);
|
|
28
|
+
LRUCache.set(__paymentOrderCacheKey, c);
|
|
29
|
+
}, [setScPaymentOrder, __paymentOrderCacheKey]);
|
|
30
|
+
/**
|
|
31
|
+
* Memoized fetch order
|
|
32
|
+
*/
|
|
33
|
+
const fetchPaymentOrder = useMemo(() => (id) => {
|
|
34
|
+
return http
|
|
35
|
+
.request({
|
|
36
|
+
url: Endpoints.GetPaymentOrder.url({ id }),
|
|
37
|
+
method: Endpoints.GetPaymentOrder.method,
|
|
38
|
+
})
|
|
39
|
+
.then((res) => {
|
|
40
|
+
if (res.status >= 300) {
|
|
41
|
+
return Promise.reject(res);
|
|
42
|
+
}
|
|
43
|
+
return Promise.resolve(res.data);
|
|
44
|
+
});
|
|
45
|
+
}, []);
|
|
46
|
+
/**
|
|
47
|
+
* If id attempt to get the course by id
|
|
48
|
+
*/
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (id !== null && id !== undefined && !paymentOrder) {
|
|
51
|
+
fetchPaymentOrder(id)
|
|
52
|
+
.then((e) => {
|
|
53
|
+
setSCPaymentOrder(e);
|
|
54
|
+
})
|
|
55
|
+
.catch((err) => {
|
|
56
|
+
LRUCache.delete(__paymentOrderCacheKey);
|
|
57
|
+
Logger.error(SCOPE_SC_CORE, err.message);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}, [id, paymentOrder, authUserId]);
|
|
61
|
+
useDeepCompareEffectNoCheck(() => {
|
|
62
|
+
if (paymentOrder) {
|
|
63
|
+
setSCPaymentOrder(paymentOrder);
|
|
64
|
+
}
|
|
65
|
+
}, [paymentOrder, authUserId]);
|
|
66
|
+
return { scPaymentOrder, setSCPaymentOrder, error };
|
|
67
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SCPaymentProduct } from '@selfcommunity/types';
|
|
2
|
+
import { CacheStrategies } from '@selfcommunity/utils';
|
|
3
|
+
/**
|
|
4
|
+
:::info
|
|
5
|
+
This custom hook is used to fetch a payment product.
|
|
6
|
+
:::
|
|
7
|
+
* @param object
|
|
8
|
+
* @param object.id
|
|
9
|
+
* @param object.paymentProduct
|
|
10
|
+
* @param object.cacheStrategy
|
|
11
|
+
*/
|
|
12
|
+
export default function useSCFetchPaymentProduct({ id, paymentProduct, cacheStrategy, }: {
|
|
13
|
+
id?: number | string;
|
|
14
|
+
paymentProduct?: SCPaymentProduct;
|
|
15
|
+
cacheStrategy?: CacheStrategies;
|
|
16
|
+
}): {
|
|
17
|
+
scPaymentProduct: SCPaymentProduct;
|
|
18
|
+
setSCPaymentProduct: (c: SCPaymentProduct) => void;
|
|
19
|
+
error: string;
|
|
20
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Endpoints, http } from '@selfcommunity/api-services';
|
|
2
|
+
import { CacheStrategies, Logger, LRUCache } from '@selfcommunity/utils';
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
|
+
import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect';
|
|
5
|
+
import { useSCUser } from '../components/provider/SCUserProvider';
|
|
6
|
+
import { getPaymentProductObjectCacheKey } from '../constants/Cache';
|
|
7
|
+
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
8
|
+
/**
|
|
9
|
+
:::info
|
|
10
|
+
This custom hook is used to fetch a payment product.
|
|
11
|
+
:::
|
|
12
|
+
* @param object
|
|
13
|
+
* @param object.id
|
|
14
|
+
* @param object.paymentProduct
|
|
15
|
+
* @param object.cacheStrategy
|
|
16
|
+
*/
|
|
17
|
+
export default function useSCFetchPaymentProduct({ id = null, paymentProduct = null, cacheStrategy = CacheStrategies.NETWORK_ONLY, }) {
|
|
18
|
+
const __paymentProductId = useMemo(() => (paymentProduct === null || paymentProduct === void 0 ? void 0 : paymentProduct.id) || id, [paymentProduct, id]);
|
|
19
|
+
// CONTEXT
|
|
20
|
+
const scUserContext = useSCUser();
|
|
21
|
+
const authUserId = useMemo(() => { var _a; return ((_a = scUserContext.user) === null || _a === void 0 ? void 0 : _a.id) || null; }, [scUserContext.user]);
|
|
22
|
+
// CACHE
|
|
23
|
+
const __paymentProductCacheKey = useMemo(() => getPaymentProductObjectCacheKey(__paymentProductId), [__paymentProductId]);
|
|
24
|
+
const [scPaymentProduct, setScPaymentProduct] = useState(cacheStrategy !== CacheStrategies.NETWORK_ONLY ? LRUCache.get(__paymentProductCacheKey, paymentProduct) : null);
|
|
25
|
+
const [error, setError] = useState(null);
|
|
26
|
+
const setSCPaymentProduct = useCallback((c) => {
|
|
27
|
+
setScPaymentProduct(c);
|
|
28
|
+
LRUCache.set(__paymentProductCacheKey, c);
|
|
29
|
+
}, [setScPaymentProduct, __paymentProductCacheKey]);
|
|
30
|
+
/**
|
|
31
|
+
* Memoized fetch product
|
|
32
|
+
*/
|
|
33
|
+
const fetchPaymentProduct = useMemo(() => (id) => {
|
|
34
|
+
return http
|
|
35
|
+
.request({
|
|
36
|
+
url: Endpoints.GetPaymentProduct.url({ id }),
|
|
37
|
+
method: Endpoints.GetPaymentProduct.method,
|
|
38
|
+
})
|
|
39
|
+
.then((res) => {
|
|
40
|
+
if (res.status >= 300) {
|
|
41
|
+
return Promise.reject(res);
|
|
42
|
+
}
|
|
43
|
+
return Promise.resolve(res.data);
|
|
44
|
+
});
|
|
45
|
+
}, []);
|
|
46
|
+
/**
|
|
47
|
+
* If id attempt to get the course by id
|
|
48
|
+
*/
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (id !== null && id !== undefined && !paymentProduct) {
|
|
51
|
+
fetchPaymentProduct(id)
|
|
52
|
+
.then((e) => {
|
|
53
|
+
setSCPaymentProduct(e);
|
|
54
|
+
})
|
|
55
|
+
.catch((err) => {
|
|
56
|
+
LRUCache.delete(__paymentProductCacheKey);
|
|
57
|
+
Logger.error(SCOPE_SC_CORE, err.message);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}, [id, paymentProduct, authUserId]);
|
|
61
|
+
useDeepCompareEffectNoCheck(() => {
|
|
62
|
+
if (paymentProduct) {
|
|
63
|
+
setSCPaymentProduct(paymentProduct);
|
|
64
|
+
}
|
|
65
|
+
}, [paymentProduct, authUserId]);
|
|
66
|
+
return { scPaymentProduct, setSCPaymentProduct, error };
|
|
67
|
+
}
|
|
@@ -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
|
|
33
|
+
join: (course: SCCourseType) => Promise<any>;
|
|
34
34
|
leave: (course: SCCourseType) => Promise<any>;
|
|
35
35
|
joinStatus: (course: SCCourseType) => string;
|
|
36
36
|
refresh: () => void;
|