@selfcommunity/react-core 0.7.0-alpha.8 → 0.7.0-mui7.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/lib/cjs/components/provider/SCLocaleProvider/index.d.ts +1 -1
  2. package/lib/cjs/components/provider/SCThemeProvider/index.d.ts +1 -1
  3. package/lib/cjs/components/router/index.d.ts +2 -2
  4. package/lib/cjs/constants/Cache.d.ts +6 -0
  5. package/lib/cjs/constants/Cache.js +9 -1
  6. package/lib/cjs/constants/Preferences.d.ts +2 -0
  7. package/lib/cjs/constants/Preferences.js +7 -2
  8. package/lib/cjs/hooks/useFetchMenuFooter.d.ts +5 -0
  9. package/lib/cjs/hooks/useFetchMenuFooter.js +36 -0
  10. package/lib/cjs/hooks/useSCFeature.d.ts +22 -0
  11. package/lib/cjs/hooks/useSCFeature.js +38 -0
  12. package/lib/cjs/hooks/useSCFetchUsers.d.ts +3 -4
  13. package/lib/cjs/hooks/useSCFetchUsers.js +15 -44
  14. package/lib/cjs/hooks/useSCPreference.d.ts +36 -0
  15. package/lib/cjs/hooks/useSCPreference.js +69 -0
  16. package/lib/cjs/hooks/useSCPreferencesAndFeaturesEnabled.d.ts +17 -0
  17. package/lib/cjs/hooks/useSCPreferencesAndFeaturesEnabled.js +35 -0
  18. package/lib/cjs/index.d.ts +5 -2
  19. package/lib/cjs/index.js +12 -3
  20. package/lib/cjs/utils/hooks/usePreviousValue.d.ts +1 -1
  21. package/lib/cjs/utils/hooks/usePreviousValue.js +1 -1
  22. package/lib/esm/components/provider/SCLocaleProvider/index.d.ts +1 -1
  23. package/lib/esm/components/provider/SCThemeProvider/index.d.ts +1 -1
  24. package/lib/esm/components/router/index.d.ts +2 -2
  25. package/lib/esm/constants/Cache.d.ts +6 -0
  26. package/lib/esm/constants/Cache.js +6 -0
  27. package/lib/esm/constants/Preferences.d.ts +2 -0
  28. package/lib/esm/constants/Preferences.js +5 -0
  29. package/lib/esm/hooks/useFetchMenuFooter.d.ts +5 -0
  30. package/lib/esm/hooks/useFetchMenuFooter.js +33 -0
  31. package/lib/esm/hooks/useSCFeature.d.ts +22 -0
  32. package/lib/esm/hooks/useSCFeature.js +33 -0
  33. package/lib/esm/hooks/useSCFetchUsers.d.ts +3 -4
  34. package/lib/esm/hooks/useSCFetchUsers.js +16 -45
  35. package/lib/esm/hooks/useSCPreference.d.ts +36 -0
  36. package/lib/esm/hooks/useSCPreference.js +65 -0
  37. package/lib/esm/hooks/useSCPreferencesAndFeaturesEnabled.d.ts +17 -0
  38. package/lib/esm/hooks/useSCPreferencesAndFeaturesEnabled.js +32 -0
  39. package/lib/esm/index.d.ts +5 -2
  40. package/lib/esm/index.js +5 -2
  41. package/lib/esm/utils/hooks/usePreviousValue.d.ts +1 -1
  42. package/lib/esm/utils/hooks/usePreviousValue.js +1 -1
  43. package/lib/umd/0.js +2 -0
  44. package/lib/umd/{440.js.LICENSE.txt → 0.js.LICENSE.txt} +2 -0
  45. package/lib/umd/react-core.js +1 -1
  46. package/lib/umd/react-core.js.LICENSE.txt +1 -1
  47. package/package.json +12 -12
  48. package/lib/cjs/hooks/useSCPreferenceEnabled.d.ts +0 -6
  49. package/lib/cjs/hooks/useSCPreferenceEnabled.js +0 -16
  50. package/lib/esm/hooks/useSCPreferenceEnabled.d.ts +0 -6
  51. package/lib/esm/hooks/useSCPreferenceEnabled.js +0 -13
  52. package/lib/umd/440.js +0 -2
@@ -82,6 +82,12 @@ export declare const getPaymentProductObjectCacheKey: (id: any) => string;
82
82
  /** PAYMENT PRODUCT OBJECT **/
83
83
  export declare const PAYMENT_ORDER_OBJECT_CACHE_PREFIX_KEY = "_pord_";
84
84
  export declare const getPaymentOrderObjectCacheKey: (id: any) => string;
85
+ /** USER OBJECT **/
86
+ export declare const USER_OBJECT_CACHE_PREFIX_KEY = "_usr_";
87
+ export declare const getUserObjectCacheKey: (id: number) => string;
88
+ /** USERS OBJECT **/
89
+ export declare const USERS_OBJECT_CACHE_PREFIX_KEY = "_usrs_";
90
+ export declare const getUsersObjectCacheKey: (search?: string) => string;
85
91
  /** TOOLS */
86
92
  export declare const CATEGORIES_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = "_cListWidget_";
87
93
  export declare const CATEGORIES_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = "_cFolWidget_";
@@ -86,6 +86,12 @@ export const getPaymentProductObjectCacheKey = (id) => `${PAYMENT_PRODUCT_OBJECT
86
86
  /** PAYMENT PRODUCT OBJECT **/
87
87
  export const PAYMENT_ORDER_OBJECT_CACHE_PREFIX_KEY = '_pord_';
88
88
  export const getPaymentOrderObjectCacheKey = (id) => `${PAYMENT_ORDER_OBJECT_CACHE_PREFIX_KEY}${id}`;
89
+ /** USER OBJECT **/
90
+ export const USER_OBJECT_CACHE_PREFIX_KEY = '_usr_';
91
+ export const getUserObjectCacheKey = (id) => `${USER_OBJECT_CACHE_PREFIX_KEY}${id}`;
92
+ /** USERS OBJECT **/
93
+ export const USERS_OBJECT_CACHE_PREFIX_KEY = '_usrs_';
94
+ export const getUsersObjectCacheKey = (search) => search ? `${USERS_OBJECT_CACHE_PREFIX_KEY}${encodeURIComponent(search)}` : `${USERS_OBJECT_CACHE_PREFIX_KEY}`;
89
95
  /** TOOLS */
90
96
  export const CATEGORIES_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = '_cListWidget_';
91
97
  export const CATEGORIES_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = '_cFolWidget_';
@@ -161,6 +161,8 @@ export declare const CONFIGURATIONS_SCHEDULED_POSTS_ENABLED: string;
161
161
  export declare const CONFIGURATIONS_POST_CATEGORY_REQUIRED_ENABLED: string;
162
162
  export declare const CONFIGURATIONS_POST_ADDRESSING_REQUIRED_ENABLED: string;
163
163
  export declare const CONFIGURATIONS_POST_USER_ADDRESSING_ENABLED: string;
164
+ export declare const CONFIGURATIONS_CONTACT_API_ENABLED: string;
165
+ export declare const CONFIGURATIONS_ACCEPTED_MEDIA_MIMETYPES: string;
164
166
  /**
165
167
  * PROVIDERS
166
168
  */
@@ -162,6 +162,8 @@ export const CONFIGURATIONS_SCHEDULED_POSTS_ENABLED = `${SCPreferenceSection.CON
162
162
  export const CONFIGURATIONS_POST_CATEGORY_REQUIRED_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.POST_CATEGORY_REQUIRED_ENABLED}`;
163
163
  export const CONFIGURATIONS_POST_ADDRESSING_REQUIRED_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.POST_ADDRESSING_REQUIRED_ENABLED}`;
164
164
  export const CONFIGURATIONS_POST_USER_ADDRESSING_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.POST_USER_ADDRESSING_ENABLED}`;
165
+ export const CONFIGURATIONS_CONTACT_API_ENABLED = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.CONTACT_API_ENABLED}`;
166
+ export const CONFIGURATIONS_ACCEPTED_MEDIA_MIMETYPES = `${SCPreferenceSection.CONFIGURATIONS}.${SCPreferenceName.ACCEPTED_MEDIA_MIMETYPES}`;
165
167
  /**
166
168
  * PROVIDERS
167
169
  */
@@ -335,6 +337,7 @@ export const DATA_TYPES = {
335
337
  [CONFIGURATIONS_SCHEDULED_POSTS_ENABLED]: booleanType,
336
338
  [CONFIGURATIONS_POST_CATEGORY_REQUIRED_ENABLED]: booleanType,
337
339
  [CONFIGURATIONS_POST_ADDRESSING_REQUIRED_ENABLED]: booleanType,
340
+ [CONFIGURATIONS_ACCEPTED_MEDIA_MIMETYPES]: stringType,
338
341
  [PROVIDERS_APP_URL_ON_APP_STORE]: stringType,
339
342
  [PROVIDERS_APP_URL_ON_GOOGLE_PLAY]: stringType,
340
343
  [PROVIDERS_FACEBOOK_SIGNIN_ENABLED]: stringType,
@@ -358,4 +361,6 @@ export const DATA_TYPES = {
358
361
  [STATIC_ENVIRONMENT]: stringType,
359
362
  [STATIC_STACKID]: stringType,
360
363
  [STATIC_STRIPE_PUBLIC_KEY]: stringType,
364
+ [CONFIGURATIONS_POST_USER_ADDRESSING_ENABLED]: booleanType,
365
+ [CONFIGURATIONS_CONTACT_API_ENABLED]: booleanType,
361
366
  };
@@ -0,0 +1,5 @@
1
+ import { SCCustomMenu, SCCustomMenuType } from '@selfcommunity/types';
2
+ export default function useFetchMenuFooter(id: SCCustomMenu, menu?: SCCustomMenuType | null): {
3
+ _menu: SCCustomMenuType;
4
+ loading: boolean;
5
+ };
@@ -0,0 +1,33 @@
1
+ import { CustomMenuService } from '@selfcommunity/api-services';
2
+ import { Logger } from '@selfcommunity/utils';
3
+ import { useCallback, useEffect, useState } from 'react';
4
+ import { SCOPE_SC_CORE } from '../constants/Errors';
5
+ export default function useFetchMenuFooter(id, menu = null) {
6
+ // STATES
7
+ const [_menu, setMenu] = useState(menu);
8
+ const [loading, setLoading] = useState(!menu);
9
+ /**
10
+ * Fetches custom pages
11
+ */
12
+ const fetchMenu = useCallback(() => {
13
+ setLoading(true);
14
+ CustomMenuService.getASpecificCustomMenu(id)
15
+ .then((menu) => {
16
+ setMenu(menu);
17
+ })
18
+ .catch((error) => {
19
+ Logger.error(SCOPE_SC_CORE, error);
20
+ })
21
+ .then(() => setLoading(false));
22
+ }, []);
23
+ /**
24
+ * On mount, fetches legal and custom pages
25
+ */
26
+ useEffect(() => {
27
+ if (menu) {
28
+ return;
29
+ }
30
+ fetchMenu();
31
+ }, [id]);
32
+ return { _menu, loading };
33
+ }
@@ -0,0 +1,22 @@
1
+ import { SCFeatureName } from '@selfcommunity/types';
2
+ /**
3
+ * Custom hook to check if the feature is enabled
4
+ * @param featureName - feature name
5
+ * @returns boolean - true if the feature is in the list of features
6
+ *
7
+ * Ex.
8
+ * const isTaggingEnabled = useSCFeatureEnabled(SCFeatureName.TAGGING);
9
+ */
10
+ export declare function useSCFeatureEnabled(featureName: SCFeatureName): boolean;
11
+ /**
12
+ * Custom hook to check if a list of features are enabled
13
+ * @param featureNames - feature names
14
+ * @returns boolean - true if all features are in the features list
15
+ *
16
+ * Ex.
17
+ * const hasRequiredFeatures = useSCFeaturesEnabled([
18
+ * SCFeatureName.TAGGING,
19
+ * SCFeatureName.GROUPING
20
+ * ]);
21
+ */
22
+ export declare function useSCFeaturesEnabled(featureNames: SCFeatureName[]): boolean;
@@ -0,0 +1,33 @@
1
+ import { useMemo } from 'react';
2
+ import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
3
+ /**
4
+ * Custom hook to check if the feature is enabled
5
+ * @param featureName - feature name
6
+ * @returns boolean - true if the feature is in the list of features
7
+ *
8
+ * Ex.
9
+ * const isTaggingEnabled = useSCFeatureEnabled(SCFeatureName.TAGGING);
10
+ */
11
+ export function useSCFeatureEnabled(featureName) {
12
+ const { features } = useSCPreferences();
13
+ return useMemo(() => {
14
+ return Boolean(features && features.includes(featureName));
15
+ }, [features, featureName]);
16
+ }
17
+ /**
18
+ * Custom hook to check if a list of features are enabled
19
+ * @param featureNames - feature names
20
+ * @returns boolean - true if all features are in the features list
21
+ *
22
+ * Ex.
23
+ * const hasRequiredFeatures = useSCFeaturesEnabled([
24
+ * SCFeatureName.TAGGING,
25
+ * SCFeatureName.GROUPING
26
+ * ]);
27
+ */
28
+ export function useSCFeaturesEnabled(featureNames) {
29
+ const { features } = useSCPreferences();
30
+ return useMemo(() => {
31
+ return Boolean(features && featureNames.every((name) => features.includes(name)));
32
+ }, [features, featureNames]);
33
+ }
@@ -1,10 +1,8 @@
1
1
  import { SCUserAutocompleteType } from '@selfcommunity/types';
2
- import { CacheStrategies } from '@selfcommunity/utils';
3
2
  /**
4
3
  :::info
5
4
  This custom hook is used to fetch users.
6
- @param object.cacheStrategy
7
-
5
+
8
6
  :::tip Context can be consumed in this way:
9
7
 
10
8
  ```jsx
@@ -14,7 +12,8 @@ import { CacheStrategies } from '@selfcommunity/utils';
14
12
  * @param props
15
13
  */
16
14
  declare const useSCFetchUsers: (props?: {
17
- cacheStrategy?: CacheStrategies;
15
+ search: string;
16
+ exclude?: string;
18
17
  }) => {
19
18
  users: SCUserAutocompleteType[];
20
19
  isLoading: boolean;
@@ -2,29 +2,11 @@ import { __awaiter } from "tslib";
2
2
  import { useEffect, useState } from 'react';
3
3
  import { SCOPE_SC_CORE } from '../constants/Errors';
4
4
  import { Endpoints, http } from '@selfcommunity/api-services';
5
- import { CacheStrategies, Logger, LRUCache } from '@selfcommunity/utils';
6
- const init = { users: [], isLoading: true };
7
- // --- Cache keys
8
- const getUsersObjectCacheKey = () => '__sc_usersAct_object__';
9
- const getUserObjectCacheKey = (id) => `__sc_userAct_object__${id}`;
10
- // Hydrate cache
11
- const hydrate = (ids) => {
12
- if (!ids)
13
- return null;
14
- const users = ids.map((id) => {
15
- const __userCacheKey = getUserObjectCacheKey(id);
16
- return LRUCache.get(__userCacheKey);
17
- });
18
- if (users.filter((u) => !u).length > 0) {
19
- return null; // revalidate cache
20
- }
21
- return users;
22
- };
5
+ import { Logger } from '@selfcommunity/utils';
23
6
  /**
24
7
  :::info
25
8
  This custom hook is used to fetch users.
26
- @param object.cacheStrategy
27
-
9
+
28
10
  :::tip Context can be consumed in this way:
29
11
 
30
12
  ```jsx
@@ -34,44 +16,33 @@ const hydrate = (ids) => {
34
16
  * @param props
35
17
  */
36
18
  const useSCFetchUsers = (props) => {
37
- const { cacheStrategy = CacheStrategies.CACHE_FIRST } = props || {};
38
- // Cache
39
- const __usersCacheKey = getUsersObjectCacheKey();
40
- // State
41
- const users = cacheStrategy !== CacheStrategies.NETWORK_ONLY ? hydrate(LRUCache.get(__usersCacheKey, null)) : null;
42
- const [data, setData] = useState(users !== null ? { users, isLoading: false } : init);
43
- /**
44
- * Fetch all users
45
- */
46
- const fetchUsers = (next = Endpoints.UserAutocomplete.url()) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const { search = '', exclude = '' } = props || {};
20
+ const [data, setData] = useState({ users: [], isLoading: false });
21
+ const fetchUsers = (next = Endpoints.UserAutocomplete.url(), searchParam, excludeParam) => __awaiter(void 0, void 0, void 0, function* () {
47
22
  const response = yield http.request({
48
23
  url: next,
49
24
  method: Endpoints.UserAutocomplete.method,
25
+ params: Object.assign({ search: searchParam }, (excludeParam && { exclude: excludeParam })),
50
26
  });
51
- const data = response.data;
52
- if (data.next) {
53
- return data.results.concat(yield fetchUsers(data.next));
27
+ const result = response.data;
28
+ if (result.next) {
29
+ return result.results.concat(yield fetchUsers(result.next, searchParam, excludeParam));
54
30
  }
55
- return data.results;
31
+ return result.results;
56
32
  });
57
33
  useEffect(() => {
58
- if (cacheStrategy === CacheStrategies.CACHE_FIRST && users) {
34
+ if (!search)
59
35
  return;
60
- }
61
- fetchUsers()
62
- .then((data) => {
63
- setData({ users: data, isLoading: false });
64
- LRUCache.set(__usersCacheKey, data.map((u) => {
65
- const __userCacheKey = getUserObjectCacheKey(u.id);
66
- LRUCache.set(__userCacheKey, u);
67
- return u.id;
68
- }));
36
+ fetchUsers(undefined, search, exclude)
37
+ .then((users) => {
38
+ setData({ users, isLoading: false });
69
39
  })
70
40
  .catch((error) => {
71
41
  console.error(error);
72
42
  Logger.error(SCOPE_SC_CORE, 'Unable to retrieve users');
43
+ setData((prev) => (Object.assign(Object.assign({}, prev), { isLoading: false })));
73
44
  });
74
- }, []);
45
+ }, [search, exclude]);
75
46
  return data;
76
47
  };
77
48
  export default useSCFetchUsers;
@@ -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,65 @@
1
+ import { useMemo } from 'react';
2
+ import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
3
+ /**
4
+ * Custom hook to recover a given preference.
5
+ * @param preferenceKey - full preference key (e.g., 'section.name')
6
+ * @param defaultValue - default returned value
7
+ * @returns the preference value or undefined/defaultValue if doesn't exist
8
+ *
9
+ * Ex.
10
+ * const customValue = useSCPreference&lt;string&gt;(SCPreferences.CUSTOM_SETTING);
11
+ * const numericValue = useSCPreference&lt;number&gt;(SCPreferences.CUSTOM_SETTING, 0);
12
+ */
13
+ function useSCPreference(preferenceKey, defaultValue) {
14
+ const { preferences } = useSCPreferences();
15
+ return useMemo(() => {
16
+ if (!preferences || !(preferenceKey in preferences)) {
17
+ return defaultValue;
18
+ }
19
+ const pref = preferences[preferenceKey];
20
+ return pref.value;
21
+ }, [preferences, preferenceKey, defaultValue]);
22
+ }
23
+ /**
24
+ * Custom hook to check if a given preference is present and has a value.
25
+ * @param preferenceKey - full preference key (e.g., 'section.name')
26
+ * @param defaultValue - default returned value (default=false)
27
+ * @returns boolean
28
+ *
29
+ * Ex.
30
+ * const isEnabled = useSCPreferenceEnabled(SCPreferences.CONFIGURATIONS_CONNECTION_ENABLED);
31
+ **/
32
+ function useSCPreferenceEnabled(preferenceKey, defaultValue = false) {
33
+ const value = useSCPreference(preferenceKey, defaultValue);
34
+ return value !== null && value !== void 0 ? value : defaultValue;
35
+ }
36
+ /**
37
+ * Custom hook to check if all specified preferences are enabled
38
+ * @param preferenceKeys - Array of preference keys to check
39
+ * @param defaultValue - Default value if a preference doesn't exist
40
+ * @returns boolean - true if all preferences are enabled
41
+ *
42
+ * Ex.
43
+ * const arePreferencesEnabled = useSCPreferencesEnabled([
44
+ * SCPreferences.CONFIGURATIONS_POST_USER_ADDRESSING_ENABLED,
45
+ * SCPreferences.CONFIGURATIONS_SCHEDULED_POSTS_ENABLED
46
+ * ]);
47
+ */
48
+ function useSCPreferencesEnabled(preferenceKeys, defaultValue = false) {
49
+ const { preferences } = useSCPreferences();
50
+ return useMemo(() => {
51
+ // Se non ci sono preferences o non è stato passato nessun preferenceKey, ritorna il valore di default
52
+ if (!preferences || !preferenceKeys.length) {
53
+ return defaultValue;
54
+ }
55
+ // Verifica che tutte le preferenze siano presenti e abbiano value = true
56
+ return preferenceKeys.every((key) => {
57
+ if (!(key in preferences)) {
58
+ return defaultValue;
59
+ }
60
+ return preferences[key].value;
61
+ });
62
+ }, [preferences, preferenceKeys, defaultValue]);
63
+ }
64
+ export { useSCPreferenceEnabled, useSCPreferencesEnabled };
65
+ export 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,32 @@
1
+ import { useMemo } from 'react';
2
+ import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
3
+ /**
4
+ * Custom hook preferences and features at the same time
5
+ * @param preferences - array of preference keys
6
+ * @param features - array of feature keys
7
+ * @returns boolean - true only if all preferences and features are enabled
8
+ *
9
+ * Ex.
10
+ * const isEnabled = useSCPreferencesAndFeaturesEnabled(
11
+ * [
12
+ * SCPreferences.CONFIGURATIONS_POST_USER_ADDRESSING_ENABLED,
13
+ * SCPreferences.CONFIGURATIONS_SCHEDULED_POSTS_ENABLED
14
+ * ],
15
+ * [SCFeatureName.TAGGING]
16
+ * );
17
+ */
18
+ export default function useSCPreferencesAndFeaturesEnabled(preferences, features = []) {
19
+ const { preferences: preferencesContext, features: featuresContext } = useSCPreferences();
20
+ return useMemo(() => {
21
+ // Check available context
22
+ if (!preferencesContext || !featuresContext) {
23
+ return false;
24
+ }
25
+ // Check every preferences
26
+ const preferencesEnabled = preferences.every((key) => key in preferencesContext && preferencesContext[key].value);
27
+ // Check every features
28
+ const featuresEnabled = features.every((feature) => featuresContext.includes(feature));
29
+ // Return true only if all preferences and features are enabled
30
+ return preferencesEnabled && featuresEnabled;
31
+ }, [preferencesContext, featuresContext, preferences, features]);
32
+ }
@@ -75,7 +75,10 @@ import useSCFetchLesson from './hooks/useSCFetchLesson';
75
75
  import useSCPaymentsEnabled from './hooks/useSCPaymentsEnabled';
76
76
  import useSCFetchPaymentProduct from './hooks/useSCFetchPaymentProduct';
77
77
  import useSCFetchPaymentOrder from './hooks/useSCFetchPaymentOrder';
78
- import useSCPreferenceEnabled from './hooks/useSCPreferenceEnabled';
78
+ import useFetchMenuFooter from './hooks/useFetchMenuFooter';
79
+ import useSCPreference, { useSCPreferenceEnabled, useSCPreferencesEnabled } from './hooks/useSCPreference';
80
+ import { useSCFeatureEnabled, useSCFeaturesEnabled } from './hooks/useSCFeature';
81
+ import useSCPreferencesAndFeaturesEnabled from './hooks/useSCPreferencesAndFeaturesEnabled';
79
82
  /**
80
83
  * Routing component
81
84
  */
@@ -98,4 +101,4 @@ import * as Preferences from './constants/Preferences';
98
101
  /**
99
102
  * List all exports
100
103
  */
101
- export { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCSettingsManagerType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, SCJoinedCoursesManagerType, SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUsers, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchLessonCommentObject, useSCFetchLessonCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useResizeObserver, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, useSCGoogleApiLoader, useSCFetchCourse, useSCFetchCourses, useSCFetchLesson, useSCPaymentsEnabled, useSCFetchPaymentProduct, useSCFetchPaymentOrder, useSCPreferenceEnabled, };
104
+ export { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCSettingsManagerType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, SCJoinedCoursesManagerType, SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUsers, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchLessonCommentObject, useSCFetchLessonCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useResizeObserver, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, useSCGoogleApiLoader, useSCFetchCourse, useSCFetchCourses, useSCFetchLesson, useSCPaymentsEnabled, useSCFetchPaymentProduct, useSCFetchPaymentOrder, useFetchMenuFooter, useSCPreference, useSCPreferenceEnabled, useSCPreferencesEnabled, useSCFeatureEnabled, useSCFeaturesEnabled, useSCPreferencesAndFeaturesEnabled, };
package/lib/esm/index.js CHANGED
@@ -71,7 +71,10 @@ import useSCFetchLesson from './hooks/useSCFetchLesson';
71
71
  import useSCPaymentsEnabled from './hooks/useSCPaymentsEnabled';
72
72
  import useSCFetchPaymentProduct from './hooks/useSCFetchPaymentProduct';
73
73
  import useSCFetchPaymentOrder from './hooks/useSCFetchPaymentOrder';
74
- import useSCPreferenceEnabled from './hooks/useSCPreferenceEnabled';
74
+ import useFetchMenuFooter from './hooks/useFetchMenuFooter';
75
+ import useSCPreference, { useSCPreferenceEnabled, useSCPreferencesEnabled } from './hooks/useSCPreference';
76
+ import { useSCFeatureEnabled, useSCFeaturesEnabled } from './hooks/useSCFeature';
77
+ import useSCPreferencesAndFeaturesEnabled from './hooks/useSCPreferencesAndFeaturesEnabled';
75
78
  /**
76
79
  * Routing component
77
80
  */
@@ -94,4 +97,4 @@ import * as Preferences from './constants/Preferences';
94
97
  /**
95
98
  * List all exports
96
99
  */
97
- export { SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUsers, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchLessonCommentObject, useSCFetchLessonCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useResizeObserver, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, useSCGoogleApiLoader, useSCFetchCourse, useSCFetchCourses, useSCFetchLesson, useSCPaymentsEnabled, useSCFetchPaymentProduct, useSCFetchPaymentOrder, useSCPreferenceEnabled, };
100
+ export { SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUsers, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchLessonCommentObject, useSCFetchLessonCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useResizeObserver, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, useSCGoogleApiLoader, useSCFetchCourse, useSCFetchCourses, useSCFetchLesson, useSCPaymentsEnabled, useSCFetchPaymentProduct, useSCFetchPaymentOrder, useFetchMenuFooter, useSCPreference, useSCPreferenceEnabled, useSCPreferencesEnabled, useSCFeatureEnabled, useSCFeaturesEnabled, useSCPreferencesAndFeaturesEnabled, };
@@ -10,5 +10,5 @@
10
10
  * return (<div> {count} | {prevCount}</div>);
11
11
  * }
12
12
  */
13
- declare const usePreviousValue: (value: any) => undefined;
13
+ declare const usePreviousValue: (value: any) => any;
14
14
  export default usePreviousValue;
@@ -12,7 +12,7 @@ import { useEffect, useRef } from 'react';
12
12
  * }
13
13
  */
14
14
  const usePreviousValue = (value) => {
15
- const ref = useRef();
15
+ const ref = useRef(null);
16
16
  useEffect(() => {
17
17
  ref.current = value;
18
18
  });