@selfcommunity/react-core 0.7.0-alpha.1 → 0.7.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/provider/SCThemeProvider/index.js +3 -3
- package/lib/cjs/constants/Cache.d.ts +12 -0
- package/lib/cjs/constants/Cache.js +17 -1
- package/lib/cjs/constants/Preferences.d.ts +16 -0
- package/lib/cjs/constants/Preferences.js +31 -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/useSCFetchUsers.d.ts +20 -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/useSCPreferenceEnabled.d.ts +6 -0
- package/lib/cjs/hooks/useSCPreferenceEnabled.js +16 -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/hooks/useSCWebPushMessaging.js +2 -2
- package/lib/cjs/index.d.ts +7 -2
- package/lib/cjs/index.js +13 -2
- package/lib/cjs/themes/theme.js +14 -2
- package/lib/cjs/types/theme.d.ts +53 -1
- 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/components/provider/SCThemeProvider/index.js +1 -1
- package/lib/esm/constants/Cache.d.ts +12 -0
- package/lib/esm/constants/Cache.js +12 -0
- package/lib/esm/constants/Preferences.d.ts +16 -0
- package/lib/esm/constants/Preferences.js +28 -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/useSCFetchUsers.d.ts +20 -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/useSCPreferenceEnabled.d.ts +6 -0
- package/lib/esm/hooks/useSCPreferenceEnabled.js +13 -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/hooks/useSCWebPushMessaging.js +1 -1
- package/lib/esm/index.d.ts +7 -2
- package/lib/esm/index.js +7 -2
- package/lib/esm/themes/theme.js +13 -1
- package/lib/esm/types/theme.d.ts +53 -1
- 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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SCUserAutocompleteType } from '@selfcommunity/types';
|
|
2
|
+
/**
|
|
3
|
+
:::info
|
|
4
|
+
This custom hook is used to fetch users.
|
|
5
|
+
|
|
6
|
+
:::tip Context can be consumed in this way:
|
|
7
|
+
|
|
8
|
+
```jsx
|
|
9
|
+
const {users, isLoading} = useSCFetchUsers();
|
|
10
|
+
```
|
|
11
|
+
:::
|
|
12
|
+
* @param props
|
|
13
|
+
*/
|
|
14
|
+
declare const useSCFetchUsers: (props?: {
|
|
15
|
+
search?: string;
|
|
16
|
+
}) => {
|
|
17
|
+
users: SCUserAutocompleteType[];
|
|
18
|
+
isLoading: boolean;
|
|
19
|
+
};
|
|
20
|
+
export default useSCFetchUsers;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
4
|
+
import { Endpoints, http } from '@selfcommunity/api-services';
|
|
5
|
+
import { Logger } from '@selfcommunity/utils';
|
|
6
|
+
/**
|
|
7
|
+
:::info
|
|
8
|
+
This custom hook is used to fetch users.
|
|
9
|
+
|
|
10
|
+
:::tip Context can be consumed in this way:
|
|
11
|
+
|
|
12
|
+
```jsx
|
|
13
|
+
const {users, isLoading} = useSCFetchUsers();
|
|
14
|
+
```
|
|
15
|
+
:::
|
|
16
|
+
* @param props
|
|
17
|
+
*/
|
|
18
|
+
const useSCFetchUsers = (props) => {
|
|
19
|
+
const { search = '' } = props || {};
|
|
20
|
+
const [data, setData] = useState({ users: [], isLoading: false });
|
|
21
|
+
const fetchUsers = (next = Endpoints.UserAutocomplete.url(), searchParam) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const response = yield http.request({
|
|
23
|
+
url: next,
|
|
24
|
+
method: Endpoints.UserAutocomplete.method,
|
|
25
|
+
params: searchParam ? { search: searchParam } : undefined,
|
|
26
|
+
});
|
|
27
|
+
const data = response.data;
|
|
28
|
+
if (data.next) {
|
|
29
|
+
return data.results.concat(yield fetchUsers(data.next, searchParam));
|
|
30
|
+
}
|
|
31
|
+
return data.results;
|
|
32
|
+
});
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!search)
|
|
35
|
+
return;
|
|
36
|
+
fetchUsers(undefined, search)
|
|
37
|
+
.then((data) => {
|
|
38
|
+
setData({ users: data, isLoading: false });
|
|
39
|
+
})
|
|
40
|
+
.catch((error) => {
|
|
41
|
+
console.error(error);
|
|
42
|
+
Logger.error(SCOPE_SC_CORE, 'Unable to retrieve users');
|
|
43
|
+
setData((prev) => (Object.assign(Object.assign({}, prev), { isLoading: false })));
|
|
44
|
+
});
|
|
45
|
+
}, [search]);
|
|
46
|
+
return data;
|
|
47
|
+
};
|
|
48
|
+
export 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;
|
|
@@ -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
|
-
|
|
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.
|
|
93
|
-
method: Endpoints.
|
|
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,
|
|
109
|
+
const join = useMemo(() => (course) => __awaiter(this, void 0, void 0, function* () {
|
|
115
110
|
setLoading(course.id);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
160
|
-
.request({
|
|
132
|
+
const res = yield http.request({
|
|
161
133
|
url: Endpoints.LeaveOrRemoveCourseRequest.url({ id: course.id }),
|
|
162
134
|
method: Endpoints.LeaveOrRemoveCourseRequest.method,
|
|
163
|
-
})
|
|
164
|
-
.then((res) => {
|
|
165
|
-
if (res.status >= 300) {
|
|
166
|
-
return Promise.reject(res);
|
|
167
|
-
}
|
|
168
|
-
updateCache([course.id]);
|
|
169
|
-
setData((prev) => getDataUpdated(prev, course.id, null));
|
|
170
|
-
setUnLoading(course.id);
|
|
171
|
-
return Promise.resolve(res.data);
|
|
172
135
|
});
|
|
136
|
+
if (res.status >= 300) {
|
|
137
|
+
return Promise.reject(res);
|
|
138
|
+
}
|
|
139
|
+
updateCache([course.id]);
|
|
140
|
+
setData((prev) => getDataUpdated(prev, course.id, null));
|
|
141
|
+
setUnLoading(course.id);
|
|
142
|
+
return yield Promise.resolve(res.data);
|
|
173
143
|
}
|
|
174
|
-
}, [data, loading, cache]);
|
|
144
|
+
}), [data, loading, cache]);
|
|
175
145
|
/**
|
|
176
146
|
* Check the authenticated user subscription status to the course
|
|
177
147
|
* Update the courses cached
|
|
@@ -247,7 +217,7 @@ export default function useSCJoinedCoursesManager(user) {
|
|
|
247
217
|
if (cache.includes(course.id)) {
|
|
248
218
|
return getCurrentCourseCacheStatus(course);
|
|
249
219
|
}
|
|
250
|
-
if (authUserId) {
|
|
220
|
+
if (authUserId && course) {
|
|
251
221
|
if ('join_status' in course) {
|
|
252
222
|
return getJoinStatus(course);
|
|
253
223
|
}
|
|
@@ -256,7 +226,7 @@ export default function useSCJoinedCoursesManager(user) {
|
|
|
256
226
|
}
|
|
257
227
|
}
|
|
258
228
|
return null;
|
|
259
|
-
}, [loading, cache, authUserId]);
|
|
229
|
+
}, [loading, cache, authUserId, getJoinStatus, getCurrentCourseCacheStatus]);
|
|
260
230
|
/**
|
|
261
231
|
* Empty cache on logout
|
|
262
232
|
*/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
:::info
|
|
3
|
+
This custom hook is used to check if the payments are enabled
|
|
4
|
+
:::
|
|
5
|
+
:::tip How to use it:
|
|
6
|
+
|
|
7
|
+
Follow these steps:
|
|
8
|
+
```jsx
|
|
9
|
+
1. import useSCPaymentsEnabled from '@selfcommunity/react-core';
|
|
10
|
+
2. const {isPaymentsEnabled, stripePublicKey, stripeConnectedAccountId} = useSCPaymentsEnabled();
|
|
11
|
+
```
|
|
12
|
+
:::
|
|
13
|
+
*/
|
|
14
|
+
export default function useSCPaymentsEnabled(): {
|
|
15
|
+
isPaymentsEnabled: any;
|
|
16
|
+
stripePublicKey: any;
|
|
17
|
+
stripeConnectedAccountId: any;
|
|
18
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { SCFeatureName } from '@selfcommunity/types';
|
|
3
|
+
import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
|
|
4
|
+
import * as SCPreferences from '../constants/Preferences';
|
|
5
|
+
/**
|
|
6
|
+
:::info
|
|
7
|
+
This custom hook is used to check if the payments are enabled
|
|
8
|
+
:::
|
|
9
|
+
:::tip How to use it:
|
|
10
|
+
|
|
11
|
+
Follow these steps:
|
|
12
|
+
```jsx
|
|
13
|
+
1. import useSCPaymentsEnabled from '@selfcommunity/react-core';
|
|
14
|
+
2. const {isPaymentsEnabled, stripePublicKey, stripeConnectedAccountId} = useSCPaymentsEnabled();
|
|
15
|
+
```
|
|
16
|
+
:::
|
|
17
|
+
*/
|
|
18
|
+
export default function useSCPaymentsEnabled() {
|
|
19
|
+
// CONTEXT
|
|
20
|
+
const { preferences, features } = useSCPreferences();
|
|
21
|
+
const isPaymentsEnabled = useMemo(() => preferences &&
|
|
22
|
+
features &&
|
|
23
|
+
features.includes(SCFeatureName.PAYMENTS) &&
|
|
24
|
+
SCPreferences.CONFIGURATIONS_PAYMENTS_ENABLED in preferences &&
|
|
25
|
+
preferences[SCPreferences.CONFIGURATIONS_PAYMENTS_ENABLED].value, [preferences]);
|
|
26
|
+
const stripePublicKey = useMemo(() => preferences && SCPreferences.STATIC_STRIPE_PUBLIC_KEY in preferences && preferences[SCPreferences.STATIC_STRIPE_PUBLIC_KEY].value, [preferences]);
|
|
27
|
+
const stripeConnectedAccountId = useMemo(() => preferences &&
|
|
28
|
+
SCPreferences.CONFIGURATIONS_STRIPE_CONNECTED_ACCOUNT_ID in preferences &&
|
|
29
|
+
preferences[SCPreferences.CONFIGURATIONS_STRIPE_CONNECTED_ACCOUNT_ID].value, [preferences]);
|
|
30
|
+
return { isPaymentsEnabled, stripePublicKey, stripeConnectedAccountId };
|
|
31
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom hook to check if a given preference is present and has a value.
|
|
3
|
+
* @param preference - full preference key (e.g., 'section.name')
|
|
4
|
+
* @returns boolean - true if the preference exists and has a value
|
|
5
|
+
*/
|
|
6
|
+
export default function useSCPreferenceEnabled(preference: string): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
|
|
3
|
+
/**
|
|
4
|
+
* Custom hook to check if a given preference is present and has a value.
|
|
5
|
+
* @param preference - full preference key (e.g., 'section.name')
|
|
6
|
+
* @returns boolean - true if the preference exists and has a value
|
|
7
|
+
*/
|
|
8
|
+
export default function useSCPreferenceEnabled(preference) {
|
|
9
|
+
const { preferences } = useSCPreferences();
|
|
10
|
+
return useMemo(() => {
|
|
11
|
+
return preferences && preference in preferences && preferences[preference].value;
|
|
12
|
+
}, [preferences, preference]);
|
|
13
|
+
}
|
|
@@ -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.
|
|
94
|
-
method: Endpoints.
|
|
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
|
|
33
|
+
subscribe: (group: SCGroupType) => Promise<any>;
|
|
34
34
|
unsubscribe: (group: SCGroupType) => Promise<any>;
|
|
35
35
|
subscriptionStatus: (group: SCGroupType) => string;
|
|
36
36
|
refresh: () => void;
|