@selfcommunity/react-core 0.7.0-alpha.2 → 0.7.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/constants/Cache.d.ts +12 -0
- package/lib/cjs/constants/Cache.js +17 -1
- package/lib/cjs/constants/Preferences.d.ts +18 -0
- package/lib/cjs/constants/Preferences.js +36 -2
- package/lib/cjs/constants/Routes.d.ts +6 -0
- package/lib/cjs/constants/Routes.js +14 -1
- package/lib/cjs/hooks/useFetchMenuFooter.d.ts +5 -0
- package/lib/cjs/hooks/useFetchMenuFooter.js +36 -0
- package/lib/cjs/hooks/useSCFeature.d.ts +22 -0
- package/lib/cjs/hooks/useSCFeature.js +38 -0
- 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/useSCFetchUsers.d.ts +21 -0
- package/lib/cjs/hooks/useSCFetchUsers.js +50 -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/useSCPreference.d.ts +36 -0
- package/lib/cjs/hooks/useSCPreference.js +69 -0
- package/lib/cjs/hooks/useSCPreferencesAndFeaturesEnabled.d.ts +17 -0
- package/lib/cjs/hooks/useSCPreferencesAndFeaturesEnabled.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 +10 -2
- package/lib/cjs/index.js +22 -2
- 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 +12 -0
- package/lib/esm/constants/Cache.js +12 -0
- package/lib/esm/constants/Preferences.d.ts +18 -0
- package/lib/esm/constants/Preferences.js +33 -0
- package/lib/esm/constants/Routes.d.ts +6 -0
- package/lib/esm/constants/Routes.js +12 -0
- package/lib/esm/hooks/useFetchMenuFooter.d.ts +5 -0
- package/lib/esm/hooks/useFetchMenuFooter.js +33 -0
- package/lib/esm/hooks/useSCFeature.d.ts +22 -0
- package/lib/esm/hooks/useSCFeature.js +33 -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/useSCFetchUsers.d.ts +21 -0
- package/lib/esm/hooks/useSCFetchUsers.js +48 -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/useSCPreference.d.ts +36 -0
- package/lib/esm/hooks/useSCPreference.js +65 -0
- package/lib/esm/hooks/useSCPreferencesAndFeaturesEnabled.d.ts +17 -0
- package/lib/esm/hooks/useSCPreferencesAndFeaturesEnabled.js +32 -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 +10 -2
- package/lib/esm/index.js +10 -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/react-core.js +1 -1
- package/package.json +6 -6
|
@@ -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 order.
|
|
13
|
+
:::
|
|
14
|
+
* @param object
|
|
15
|
+
* @param object.id
|
|
16
|
+
* @param object.paymentOrder
|
|
17
|
+
* @param object.cacheStrategy
|
|
18
|
+
*/
|
|
19
|
+
function useSCFetchPaymentOrder({ id = null, paymentOrder = null, cacheStrategy = utils_1.CacheStrategies.NETWORK_ONLY, }) {
|
|
20
|
+
const __paymentOrderId = (0, react_1.useMemo)(() => (paymentOrder === null || paymentOrder === void 0 ? void 0 : paymentOrder.id) || id, [paymentOrder, 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 __paymentOrderCacheKey = (0, react_1.useMemo)(() => (0, Cache_1.getPaymentOrderObjectCacheKey)(__paymentOrderId), [__paymentOrderId]);
|
|
26
|
+
const [scPaymentOrder, setScPaymentOrder] = (0, react_1.useState)(cacheStrategy !== utils_1.CacheStrategies.NETWORK_ONLY ? utils_1.LRUCache.get(__paymentOrderCacheKey, paymentOrder) : null);
|
|
27
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
28
|
+
const setSCPaymentOrder = (0, react_1.useCallback)((c) => {
|
|
29
|
+
setScPaymentOrder(c);
|
|
30
|
+
utils_1.LRUCache.set(__paymentOrderCacheKey, c);
|
|
31
|
+
}, [setScPaymentOrder, __paymentOrderCacheKey]);
|
|
32
|
+
/**
|
|
33
|
+
* Memoized fetch order
|
|
34
|
+
*/
|
|
35
|
+
const fetchPaymentOrder = (0, react_1.useMemo)(() => (id) => {
|
|
36
|
+
return api_services_1.http
|
|
37
|
+
.request({
|
|
38
|
+
url: api_services_1.Endpoints.GetPaymentOrder.url({ id }),
|
|
39
|
+
method: api_services_1.Endpoints.GetPaymentOrder.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 && !paymentOrder) {
|
|
53
|
+
fetchPaymentOrder(id)
|
|
54
|
+
.then((e) => {
|
|
55
|
+
setSCPaymentOrder(e);
|
|
56
|
+
})
|
|
57
|
+
.catch((err) => {
|
|
58
|
+
utils_1.LRUCache.delete(__paymentOrderCacheKey);
|
|
59
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}, [id, paymentOrder, authUserId]);
|
|
63
|
+
(0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
|
|
64
|
+
if (paymentOrder) {
|
|
65
|
+
setSCPaymentOrder(paymentOrder);
|
|
66
|
+
}
|
|
67
|
+
}, [paymentOrder, authUserId]);
|
|
68
|
+
return { scPaymentOrder, setSCPaymentOrder, error };
|
|
69
|
+
}
|
|
70
|
+
exports.default = useSCFetchPaymentOrder;
|
|
@@ -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,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,21 @@
|
|
|
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
|
+
exclude?: string;
|
|
17
|
+
}) => {
|
|
18
|
+
users: SCUserAutocompleteType[];
|
|
19
|
+
isLoading: boolean;
|
|
20
|
+
};
|
|
21
|
+
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 = '', exclude = '' } = props || {};
|
|
22
|
+
const [data, setData] = (0, react_1.useState)({ users: [], isLoading: false });
|
|
23
|
+
const fetchUsers = (next = api_services_1.Endpoints.UserAutocomplete.url(), searchParam, excludeParam) => 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: Object.assign({ search: searchParam }, (excludeParam && { exclude: excludeParam })),
|
|
28
|
+
});
|
|
29
|
+
const result = response.data;
|
|
30
|
+
if (result.next) {
|
|
31
|
+
return result.results.concat(yield fetchUsers(result.next, searchParam, excludeParam));
|
|
32
|
+
}
|
|
33
|
+
return result.results;
|
|
34
|
+
});
|
|
35
|
+
(0, react_1.useEffect)(() => {
|
|
36
|
+
if (!search)
|
|
37
|
+
return;
|
|
38
|
+
fetchUsers(undefined, search, exclude)
|
|
39
|
+
.then((users) => {
|
|
40
|
+
setData({ users, 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, exclude]);
|
|
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
|
|
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
|
-
|
|
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.
|
|
96
|
-
method: api_services_1.Endpoints.
|
|
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,
|
|
111
|
+
const join = (0, react_1.useMemo)(() => (course) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
118
112
|
setLoading(course.id);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom hook to recover a given preference.
|
|
3
|
+
* @param preferenceKey - full preference key (e.g., 'section.name')
|
|
4
|
+
* @param defaultValue - default returned value
|
|
5
|
+
* @returns the preference value or undefined/defaultValue if doesn't exist
|
|
6
|
+
*
|
|
7
|
+
* Ex.
|
|
8
|
+
* const customValue = useSCPreference<string>(SCPreferences.CUSTOM_SETTING);
|
|
9
|
+
* const numericValue = useSCPreference<number>(SCPreferences.CUSTOM_SETTING, 0);
|
|
10
|
+
*/
|
|
11
|
+
declare function useSCPreference<T = any>(preferenceKey: string, defaultValue?: T): T | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Custom hook to check if a given preference is present and has a value.
|
|
14
|
+
* @param preferenceKey - full preference key (e.g., 'section.name')
|
|
15
|
+
* @param defaultValue - default returned value (default=false)
|
|
16
|
+
* @returns boolean
|
|
17
|
+
*
|
|
18
|
+
* Ex.
|
|
19
|
+
* const isEnabled = useSCPreferenceEnabled(SCPreferences.CONFIGURATIONS_CONNECTION_ENABLED);
|
|
20
|
+
**/
|
|
21
|
+
declare function useSCPreferenceEnabled(preferenceKey: string, defaultValue?: boolean): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Custom hook to check if all specified preferences are enabled
|
|
24
|
+
* @param preferenceKeys - Array of preference keys to check
|
|
25
|
+
* @param defaultValue - Default value if a preference doesn't exist
|
|
26
|
+
* @returns boolean - true if all preferences are enabled
|
|
27
|
+
*
|
|
28
|
+
* Ex.
|
|
29
|
+
* const arePreferencesEnabled = useSCPreferencesEnabled([
|
|
30
|
+
* SCPreferences.CONFIGURATIONS_POST_USER_ADDRESSING_ENABLED,
|
|
31
|
+
* SCPreferences.CONFIGURATIONS_SCHEDULED_POSTS_ENABLED
|
|
32
|
+
* ]);
|
|
33
|
+
*/
|
|
34
|
+
declare function useSCPreferencesEnabled(preferenceKeys: string[], defaultValue?: boolean): boolean;
|
|
35
|
+
export { useSCPreferenceEnabled, useSCPreferencesEnabled };
|
|
36
|
+
export default useSCPreference;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSCPreferencesEnabled = exports.useSCPreferenceEnabled = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const SCPreferencesProvider_1 = require("../components/provider/SCPreferencesProvider");
|
|
6
|
+
/**
|
|
7
|
+
* Custom hook to recover a given preference.
|
|
8
|
+
* @param preferenceKey - full preference key (e.g., 'section.name')
|
|
9
|
+
* @param defaultValue - default returned value
|
|
10
|
+
* @returns the preference value or undefined/defaultValue if doesn't exist
|
|
11
|
+
*
|
|
12
|
+
* Ex.
|
|
13
|
+
* const customValue = useSCPreference<string>(SCPreferences.CUSTOM_SETTING);
|
|
14
|
+
* const numericValue = useSCPreference<number>(SCPreferences.CUSTOM_SETTING, 0);
|
|
15
|
+
*/
|
|
16
|
+
function useSCPreference(preferenceKey, defaultValue) {
|
|
17
|
+
const { preferences } = (0, SCPreferencesProvider_1.useSCPreferences)();
|
|
18
|
+
return (0, react_1.useMemo)(() => {
|
|
19
|
+
if (!preferences || !(preferenceKey in preferences)) {
|
|
20
|
+
return defaultValue;
|
|
21
|
+
}
|
|
22
|
+
const pref = preferences[preferenceKey];
|
|
23
|
+
return pref.value;
|
|
24
|
+
}, [preferences, preferenceKey, defaultValue]);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Custom hook to check if a given preference is present and has a value.
|
|
28
|
+
* @param preferenceKey - full preference key (e.g., 'section.name')
|
|
29
|
+
* @param defaultValue - default returned value (default=false)
|
|
30
|
+
* @returns boolean
|
|
31
|
+
*
|
|
32
|
+
* Ex.
|
|
33
|
+
* const isEnabled = useSCPreferenceEnabled(SCPreferences.CONFIGURATIONS_CONNECTION_ENABLED);
|
|
34
|
+
**/
|
|
35
|
+
function useSCPreferenceEnabled(preferenceKey, defaultValue = false) {
|
|
36
|
+
const value = useSCPreference(preferenceKey, defaultValue);
|
|
37
|
+
return value !== null && value !== void 0 ? value : defaultValue;
|
|
38
|
+
}
|
|
39
|
+
exports.useSCPreferenceEnabled = useSCPreferenceEnabled;
|
|
40
|
+
/**
|
|
41
|
+
* Custom hook to check if all specified preferences are enabled
|
|
42
|
+
* @param preferenceKeys - Array of preference keys to check
|
|
43
|
+
* @param defaultValue - Default value if a preference doesn't exist
|
|
44
|
+
* @returns boolean - true if all preferences are enabled
|
|
45
|
+
*
|
|
46
|
+
* Ex.
|
|
47
|
+
* const arePreferencesEnabled = useSCPreferencesEnabled([
|
|
48
|
+
* SCPreferences.CONFIGURATIONS_POST_USER_ADDRESSING_ENABLED,
|
|
49
|
+
* SCPreferences.CONFIGURATIONS_SCHEDULED_POSTS_ENABLED
|
|
50
|
+
* ]);
|
|
51
|
+
*/
|
|
52
|
+
function useSCPreferencesEnabled(preferenceKeys, defaultValue = false) {
|
|
53
|
+
const { preferences } = (0, SCPreferencesProvider_1.useSCPreferences)();
|
|
54
|
+
return (0, react_1.useMemo)(() => {
|
|
55
|
+
// Se non ci sono preferences o non è stato passato nessun preferenceKey, ritorna il valore di default
|
|
56
|
+
if (!preferences || !preferenceKeys.length) {
|
|
57
|
+
return defaultValue;
|
|
58
|
+
}
|
|
59
|
+
// Verifica che tutte le preferenze siano presenti e abbiano value = true
|
|
60
|
+
return preferenceKeys.every((key) => {
|
|
61
|
+
if (!(key in preferences)) {
|
|
62
|
+
return defaultValue;
|
|
63
|
+
}
|
|
64
|
+
return preferences[key].value;
|
|
65
|
+
});
|
|
66
|
+
}, [preferences, preferenceKeys, defaultValue]);
|
|
67
|
+
}
|
|
68
|
+
exports.useSCPreferencesEnabled = useSCPreferencesEnabled;
|
|
69
|
+
exports.default = useSCPreference;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SCFeatureName } from '@selfcommunity/types';
|
|
2
|
+
/**
|
|
3
|
+
* Custom hook preferences and features at the same time
|
|
4
|
+
* @param preferences - array of preference keys
|
|
5
|
+
* @param features - array of feature keys
|
|
6
|
+
* @returns boolean - true only if all preferences and features are enabled
|
|
7
|
+
*
|
|
8
|
+
* Ex.
|
|
9
|
+
* const isEnabled = useSCPreferencesAndFeaturesEnabled(
|
|
10
|
+
* [
|
|
11
|
+
* SCPreferences.CONFIGURATIONS_POST_USER_ADDRESSING_ENABLED,
|
|
12
|
+
* SCPreferences.CONFIGURATIONS_SCHEDULED_POSTS_ENABLED
|
|
13
|
+
* ],
|
|
14
|
+
* [SCFeatureName.TAGGING]
|
|
15
|
+
* );
|
|
16
|
+
*/
|
|
17
|
+
export default function useSCPreferencesAndFeaturesEnabled(preferences: string[], features?: SCFeatureName[]): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
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 preferences and features at the same time
|
|
7
|
+
* @param preferences - array of preference keys
|
|
8
|
+
* @param features - array of feature keys
|
|
9
|
+
* @returns boolean - true only if all preferences and features are enabled
|
|
10
|
+
*
|
|
11
|
+
* Ex.
|
|
12
|
+
* const isEnabled = useSCPreferencesAndFeaturesEnabled(
|
|
13
|
+
* [
|
|
14
|
+
* SCPreferences.CONFIGURATIONS_POST_USER_ADDRESSING_ENABLED,
|
|
15
|
+
* SCPreferences.CONFIGURATIONS_SCHEDULED_POSTS_ENABLED
|
|
16
|
+
* ],
|
|
17
|
+
* [SCFeatureName.TAGGING]
|
|
18
|
+
* );
|
|
19
|
+
*/
|
|
20
|
+
function useSCPreferencesAndFeaturesEnabled(preferences, features = []) {
|
|
21
|
+
const { preferences: preferencesContext, features: featuresContext } = (0, SCPreferencesProvider_1.useSCPreferences)();
|
|
22
|
+
return (0, react_1.useMemo)(() => {
|
|
23
|
+
// Check available context
|
|
24
|
+
if (!preferencesContext || !featuresContext) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
// Check every preferences
|
|
28
|
+
const preferencesEnabled = preferences.every((key) => key in preferencesContext && preferencesContext[key].value);
|
|
29
|
+
// Check every features
|
|
30
|
+
const featuresEnabled = features.every((feature) => featuresContext.includes(feature));
|
|
31
|
+
// Return true only if all preferences and features are enabled
|
|
32
|
+
return preferencesEnabled && featuresEnabled;
|
|
33
|
+
}, [preferencesContext, featuresContext, preferences, features]);
|
|
34
|
+
}
|
|
35
|
+
exports.default = useSCPreferencesAndFeaturesEnabled;
|