@selfcommunity/react-ui 0.7.9-alpha.3 → 0.7.9-alpha.30

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 (167) hide show
  1. package/lib/cjs/components/ChangeGroupCover/ChangeGroupCover.js +24 -1
  2. package/lib/cjs/components/ChangeGroupPicture/ChangeGroupPicture.js +32 -11
  3. package/lib/cjs/components/Composer/Attributes/Attributes.d.ts +1 -1
  4. package/lib/cjs/components/Composer/Attributes/Attributes.js +9 -2
  5. package/lib/cjs/components/Composer/Composer.d.ts +2 -1
  6. package/lib/cjs/components/Composer/Composer.js +39 -12
  7. package/lib/cjs/components/Composer/Content/ContentDiscussion/ContentDiscussion.js +7 -3
  8. package/lib/cjs/components/Composer/Content/ContentPost/ContentPost.js +4 -3
  9. package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +7 -1
  10. package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.js +46 -12
  11. package/lib/cjs/components/CreateGroupButton/CreateGroupButton.d.ts +2 -2
  12. package/lib/cjs/components/CreateGroupButton/CreateGroupButton.js +5 -6
  13. package/lib/cjs/components/CustomAdv/CustomAdv.d.ts +4 -0
  14. package/lib/cjs/components/{CreateGroup/CreateGroup.d.ts → EditGroupButton/EditGroupButton.d.ts} +11 -16
  15. package/lib/cjs/components/EditGroupButton/EditGroupButton.js +61 -0
  16. package/lib/cjs/components/EditGroupButton/index.d.ts +3 -0
  17. package/lib/cjs/components/EditGroupButton/index.js +5 -0
  18. package/lib/cjs/components/FeedObject/Actions/Follow/Follow.js +18 -0
  19. package/lib/cjs/components/FeedObject/Actions/Share/Share.js +18 -0
  20. package/lib/cjs/components/FeedObject/FeedObject.d.ts +1 -0
  21. package/lib/cjs/components/FeedObject/FeedObject.js +43 -9
  22. package/lib/cjs/components/Group/Group.d.ts +4 -3
  23. package/lib/cjs/components/Group/Group.js +5 -4
  24. package/lib/cjs/components/Group/Skeleton.js +1 -1
  25. package/lib/cjs/components/GroupAutocomplete/GroupAutocomplete.d.ts +49 -0
  26. package/lib/cjs/components/GroupAutocomplete/GroupAutocomplete.js +101 -0
  27. package/lib/cjs/components/GroupAutocomplete/index.d.ts +3 -0
  28. package/lib/cjs/components/GroupAutocomplete/index.js +5 -0
  29. package/lib/cjs/components/GroupForm/GroupForm.d.ts +70 -0
  30. package/lib/cjs/components/GroupForm/GroupForm.js +239 -0
  31. package/lib/cjs/components/GroupForm/constants.d.ts +1 -0
  32. package/lib/cjs/components/{CreateGroup → GroupForm}/constants.js +1 -1
  33. package/lib/cjs/components/GroupForm/index.d.ts +3 -0
  34. package/lib/cjs/components/GroupForm/index.js +5 -0
  35. package/lib/cjs/components/GroupHeader/GroupHeader.d.ts +6 -5
  36. package/lib/cjs/components/GroupHeader/GroupHeader.js +21 -11
  37. package/lib/cjs/components/GroupHeader/Skeleton.d.ts +2 -4
  38. package/lib/cjs/components/GroupHeader/Skeleton.js +10 -10
  39. package/lib/cjs/components/GroupInfoWidget/GroupInfoWidget.js +12 -8
  40. package/lib/cjs/components/GroupInviteButton/GroupInviteButton.js +7 -6
  41. package/lib/cjs/components/GroupMembersButton/GroupMembersButton.d.ts +5 -0
  42. package/lib/cjs/components/GroupMembersButton/GroupMembersButton.js +3 -2
  43. package/lib/cjs/components/GroupMembersWidget/GroupMembersWidget.js +36 -16
  44. package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +0 -5
  45. package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.js +17 -7
  46. package/lib/cjs/components/GroupSettingsIconButton/GroupSettingsIconButton.d.ts +48 -0
  47. package/lib/cjs/components/GroupSettingsIconButton/GroupSettingsIconButton.js +132 -0
  48. package/lib/cjs/components/GroupSettingsIconButton/index.d.ts +3 -0
  49. package/lib/cjs/components/GroupSettingsIconButton/index.js +5 -0
  50. package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.d.ts +8 -3
  51. package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.js +24 -9
  52. package/lib/cjs/components/Groups/Groups.d.ts +16 -16
  53. package/lib/cjs/components/Groups/Groups.js +47 -96
  54. package/lib/cjs/components/Groups/Skeleton.d.ts +14 -2
  55. package/lib/cjs/components/Groups/Skeleton.js +12 -5
  56. package/lib/cjs/components/InlineComposerWidget/InlineComposerWidget.d.ts +2 -1
  57. package/lib/cjs/components/NavigationMenuIconButton/NavigationMenuIconButton.js +1 -1
  58. package/lib/cjs/components/NavigationToolbarMobile/NavigationToolbarMobile.d.ts +4 -0
  59. package/lib/cjs/components/NavigationToolbarMobile/NavigationToolbarMobile.js +2 -3
  60. package/lib/cjs/components/Notification/Group/Group.d.ts +15 -0
  61. package/lib/cjs/components/Notification/Group/Group.js +79 -0
  62. package/lib/cjs/components/Notification/Group/index.d.ts +3 -0
  63. package/lib/cjs/components/Notification/Group/index.js +5 -0
  64. package/lib/cjs/components/Notification/Notification.js +32 -1
  65. package/lib/cjs/components/Notification/PrivateMessage/PrivateMessage.js +16 -5
  66. package/lib/cjs/components/PrivateMessageComponent/PrivateMessageComponent.d.ts +1 -1
  67. package/lib/cjs/components/PrivateMessageComponent/PrivateMessageComponent.js +10 -7
  68. package/lib/cjs/components/PrivateMessageSnippetItem/PrivateMessageSnippetItem.js +11 -6
  69. package/lib/cjs/components/PrivateMessageSnippets/PrivateMessageSnippets.d.ts +3 -3
  70. package/lib/cjs/components/PrivateMessageSnippets/PrivateMessageSnippets.js +24 -6
  71. package/lib/cjs/components/PrivateMessageThread/PrivateMessageThread.d.ts +6 -1
  72. package/lib/cjs/components/PrivateMessageThread/PrivateMessageThread.js +45 -20
  73. package/lib/cjs/components/SearchAutocomplete/SearchAutocomplete.js +22 -5
  74. package/lib/cjs/components/SnippetNotifications/SnippetNotifications.js +7 -0
  75. package/lib/cjs/components/ToastNotifications/ToastNotifications.js +7 -0
  76. package/lib/cjs/components/VoteButton/VoteButton.js +19 -0
  77. package/lib/cjs/index.d.ts +7 -4
  78. package/lib/cjs/index.js +13 -6
  79. package/lib/esm/components/ChangeGroupCover/ChangeGroupCover.js +24 -1
  80. package/lib/esm/components/ChangeGroupPicture/ChangeGroupPicture.js +32 -11
  81. package/lib/esm/components/Composer/Attributes/Attributes.d.ts +1 -1
  82. package/lib/esm/components/Composer/Attributes/Attributes.js +9 -2
  83. package/lib/esm/components/Composer/Composer.d.ts +2 -1
  84. package/lib/esm/components/Composer/Composer.js +39 -12
  85. package/lib/esm/components/Composer/Content/ContentDiscussion/ContentDiscussion.js +7 -3
  86. package/lib/esm/components/Composer/Content/ContentPost/ContentPost.js +4 -3
  87. package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +7 -1
  88. package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.js +45 -12
  89. package/lib/esm/components/CreateGroupButton/CreateGroupButton.d.ts +2 -2
  90. package/lib/esm/components/CreateGroupButton/CreateGroupButton.js +5 -6
  91. package/lib/esm/components/CustomAdv/CustomAdv.d.ts +4 -0
  92. package/lib/esm/components/{CreateGroup/CreateGroup.d.ts → EditGroupButton/EditGroupButton.d.ts} +11 -16
  93. package/lib/esm/components/EditGroupButton/EditGroupButton.js +58 -0
  94. package/lib/esm/components/EditGroupButton/index.d.ts +3 -0
  95. package/lib/esm/components/EditGroupButton/index.js +2 -0
  96. package/lib/esm/components/FeedObject/Actions/Follow/Follow.js +20 -2
  97. package/lib/esm/components/FeedObject/Actions/Share/Share.js +20 -2
  98. package/lib/esm/components/FeedObject/FeedObject.d.ts +1 -0
  99. package/lib/esm/components/FeedObject/FeedObject.js +45 -11
  100. package/lib/esm/components/Group/Group.d.ts +4 -3
  101. package/lib/esm/components/Group/Group.js +5 -4
  102. package/lib/esm/components/Group/Skeleton.js +1 -1
  103. package/lib/esm/components/GroupAutocomplete/GroupAutocomplete.d.ts +49 -0
  104. package/lib/esm/components/GroupAutocomplete/GroupAutocomplete.js +99 -0
  105. package/lib/esm/components/GroupAutocomplete/index.d.ts +3 -0
  106. package/lib/esm/components/GroupAutocomplete/index.js +2 -0
  107. package/lib/esm/components/GroupForm/GroupForm.d.ts +70 -0
  108. package/lib/esm/components/GroupForm/GroupForm.js +236 -0
  109. package/lib/esm/components/GroupForm/constants.d.ts +1 -0
  110. package/lib/esm/components/GroupForm/constants.js +1 -0
  111. package/lib/esm/components/GroupForm/index.d.ts +3 -0
  112. package/lib/esm/components/GroupForm/index.js +2 -0
  113. package/lib/esm/components/GroupHeader/GroupHeader.d.ts +6 -5
  114. package/lib/esm/components/GroupHeader/GroupHeader.js +21 -11
  115. package/lib/esm/components/GroupHeader/Skeleton.d.ts +2 -4
  116. package/lib/esm/components/GroupHeader/Skeleton.js +10 -10
  117. package/lib/esm/components/GroupInfoWidget/GroupInfoWidget.js +12 -8
  118. package/lib/esm/components/GroupInviteButton/GroupInviteButton.js +7 -6
  119. package/lib/esm/components/GroupMembersButton/GroupMembersButton.d.ts +5 -0
  120. package/lib/esm/components/GroupMembersButton/GroupMembersButton.js +4 -3
  121. package/lib/esm/components/GroupMembersWidget/GroupMembersWidget.js +38 -18
  122. package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +0 -5
  123. package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.js +17 -7
  124. package/lib/esm/components/GroupSettingsIconButton/GroupSettingsIconButton.d.ts +48 -0
  125. package/lib/esm/components/GroupSettingsIconButton/GroupSettingsIconButton.js +129 -0
  126. package/lib/esm/components/GroupSettingsIconButton/index.d.ts +3 -0
  127. package/lib/esm/components/GroupSettingsIconButton/index.js +2 -0
  128. package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.d.ts +8 -3
  129. package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.js +25 -10
  130. package/lib/esm/components/Groups/Groups.d.ts +16 -16
  131. package/lib/esm/components/Groups/Groups.js +52 -101
  132. package/lib/esm/components/Groups/Skeleton.d.ts +14 -2
  133. package/lib/esm/components/Groups/Skeleton.js +13 -5
  134. package/lib/esm/components/InlineComposerWidget/InlineComposerWidget.d.ts +2 -1
  135. package/lib/esm/components/NavigationMenuIconButton/NavigationMenuIconButton.js +1 -1
  136. package/lib/esm/components/NavigationToolbarMobile/NavigationToolbarMobile.d.ts +4 -0
  137. package/lib/esm/components/NavigationToolbarMobile/NavigationToolbarMobile.js +2 -3
  138. package/lib/esm/components/Notification/Group/Group.d.ts +15 -0
  139. package/lib/esm/components/Notification/Group/Group.js +76 -0
  140. package/lib/esm/components/Notification/Group/index.d.ts +3 -0
  141. package/lib/esm/components/Notification/Group/index.js +2 -0
  142. package/lib/esm/components/Notification/Notification.js +32 -1
  143. package/lib/esm/components/Notification/PrivateMessage/PrivateMessage.js +16 -5
  144. package/lib/esm/components/PrivateMessageComponent/PrivateMessageComponent.d.ts +1 -1
  145. package/lib/esm/components/PrivateMessageComponent/PrivateMessageComponent.js +11 -8
  146. package/lib/esm/components/PrivateMessageSnippetItem/PrivateMessageSnippetItem.js +11 -6
  147. package/lib/esm/components/PrivateMessageSnippets/PrivateMessageSnippets.d.ts +3 -3
  148. package/lib/esm/components/PrivateMessageSnippets/PrivateMessageSnippets.js +26 -8
  149. package/lib/esm/components/PrivateMessageThread/PrivateMessageThread.d.ts +6 -1
  150. package/lib/esm/components/PrivateMessageThread/PrivateMessageThread.js +47 -22
  151. package/lib/esm/components/SearchAutocomplete/SearchAutocomplete.js +22 -5
  152. package/lib/esm/components/SnippetNotifications/SnippetNotifications.js +7 -0
  153. package/lib/esm/components/ToastNotifications/ToastNotifications.js +7 -0
  154. package/lib/esm/components/VoteButton/VoteButton.js +20 -1
  155. package/lib/esm/index.d.ts +7 -4
  156. package/lib/esm/index.js +8 -5
  157. package/lib/umd/react-ui.js +1 -1
  158. package/package.json +6 -6
  159. package/lib/cjs/components/CreateGroup/CreateGroup.js +0 -187
  160. package/lib/cjs/components/CreateGroup/constants.d.ts +0 -1
  161. package/lib/cjs/components/CreateGroup/index.d.ts +0 -3
  162. package/lib/cjs/components/CreateGroup/index.js +0 -5
  163. package/lib/esm/components/CreateGroup/CreateGroup.js +0 -184
  164. package/lib/esm/components/CreateGroup/constants.d.ts +0 -1
  165. package/lib/esm/components/CreateGroup/constants.js +0 -1
  166. package/lib/esm/components/CreateGroup/index.d.ts +0 -3
  167. package/lib/esm/components/CreateGroup/index.js +0 -2
@@ -0,0 +1,58 @@
1
+ import { __rest } from "tslib";
2
+ import React from 'react';
3
+ import { useThemeProps } from '@mui/system';
4
+ import { styled } from '@mui/material/styles';
5
+ import { FormattedMessage } from 'react-intl';
6
+ import { useSCFetchGroup, useSCUser } from '@selfcommunity/react-core';
7
+ import classNames from 'classnames';
8
+ import CreateGroupButton from '../CreateGroupButton';
9
+ const PREFIX = 'SCEditGroupButton';
10
+ const classes = {
11
+ root: `${PREFIX}-root`
12
+ };
13
+ const Root = styled(CreateGroupButton, {
14
+ name: PREFIX,
15
+ slot: 'Root',
16
+ overridesResolver: (props, styles) => styles.root
17
+ })(({ theme }) => ({}));
18
+ /**
19
+ *> API documentation for the Community-JS Create Group Button component. Learn about the available props and the CSS API.
20
+ *
21
+ #### Import
22
+ ```jsx
23
+ import {CreateGroupButton} from '@selfcommunity/react-ui';
24
+ ```
25
+
26
+ #### Component Name
27
+ The name `SCEditGroupButton` can be used when providing style overrides in the theme.
28
+
29
+ #### CSS
30
+
31
+ |Rule Name|Global class|Description|
32
+ |---|---|---|
33
+ |root|.SCEditGroupButton-root|Styles applied to the root element.|
34
+
35
+ * @param inProps
36
+ */
37
+ export default function EditGroupButton(inProps) {
38
+ //PROPS
39
+ const props = useThemeProps({
40
+ props: inProps,
41
+ name: PREFIX
42
+ });
43
+ const { className, groupId, group, onEditSuccess } = props, rest = __rest(props, ["className", "groupId", "group", "onEditSuccess"]);
44
+ const { scGroup, setSCGroup } = useSCFetchGroup({ id: groupId, group });
45
+ const scUserContext = useSCUser();
46
+ const handleSuccess = (data) => {
47
+ setSCGroup(data);
48
+ onEditSuccess && onEditSuccess(data);
49
+ };
50
+ if (!scUserContext.user) {
51
+ return null;
52
+ }
53
+ /**
54
+ * Renders root object
55
+ */
56
+ return (React.createElement(Root, Object.assign({ variant: "outlined", className: classNames(classes.root, className), GroupFormProps: { group: scGroup, onSuccess: handleSuccess } }, rest),
57
+ React.createElement(FormattedMessage, { id: "ui.editGroupButton", defaultMessage: "ui.editGroupButton" })));
58
+ }
@@ -0,0 +1,3 @@
1
+ import EditGroupButton, { EditGroupButtonProps } from './EditGroupButton';
2
+ export default EditGroupButton;
3
+ export { EditGroupButtonProps };
@@ -0,0 +1,2 @@
1
+ import EditGroupButton from './EditGroupButton';
2
+ export default EditGroupButton;
@@ -1,5 +1,5 @@
1
1
  import { __rest } from "tslib";
2
- import React, { useMemo, useState } from 'react';
2
+ import React, { useEffect, useMemo, useState } from 'react';
3
3
  import { FormattedMessage } from 'react-intl';
4
4
  import LoadingButton from '@mui/lab/LoadingButton';
5
5
  import { styled } from '@mui/material/styles';
@@ -8,7 +8,7 @@ import { SCOPE_SC_UI } from '../../../../constants/Errors';
8
8
  import classNames from 'classnames';
9
9
  import { useSnackbar } from 'notistack';
10
10
  import Icon from '@mui/material/Icon';
11
- import { SCContributionType } from '@selfcommunity/types';
11
+ import { SCContributionType, SCGroupSubscriptionStatusType } from '@selfcommunity/types';
12
12
  import { Endpoints, http } from '@selfcommunity/api-services';
13
13
  import { Logger } from '@selfcommunity/utils';
14
14
  import { useSCContext, useSCFetchFeedObject, useSCUser } from '@selfcommunity/react-core';
@@ -25,15 +25,27 @@ const Root = styled(Box, {
25
25
  slot: 'ActionFollowRoot'
26
26
  })(() => ({}));
27
27
  export default function Follow(props) {
28
+ var _a;
28
29
  // PROPS
29
30
  const { className = null, feedObjectId = null, feedObject = null, feedObjectType = SCContributionType.POST, handleFollow, iconized = true } = props, rest = __rest(props, ["className", "feedObjectId", "feedObject", "feedObjectType", "handleFollow", "iconized"]);
30
31
  // STATE
31
32
  const { obj, setObj } = useSCFetchFeedObject({ id: feedObjectId, feedObject, feedObjectType });
32
33
  const [isFollowing, setIsFollowing] = useState(false);
34
+ const [status, setStatus] = useState(null);
33
35
  // CONTEXT
34
36
  const scContext = useSCContext();
35
37
  const scUserContext = useSCUser();
38
+ const scGroupsManager = scUserContext.managers.groups;
36
39
  const { enqueueSnackbar } = useSnackbar();
40
+ /**
41
+ * If the obj has a group, checks the subscription status for the authenticated user
42
+ */
43
+ useEffect(() => {
44
+ var _a;
45
+ if (((_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.id) && (obj === null || obj === void 0 ? void 0 : obj.group)) {
46
+ setStatus(scGroupsManager.subscriptionStatus(obj === null || obj === void 0 ? void 0 : obj.group));
47
+ }
48
+ }, [(_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.id, scGroupsManager.subscriptionStatus, obj === null || obj === void 0 ? void 0 : obj.group]);
37
49
  /**
38
50
  * Perform follow/unfollow
39
51
  * Post, Discussion, Status
@@ -59,6 +71,12 @@ export default function Follow(props) {
59
71
  if (!scUserContext.user) {
60
72
  scContext.settings.handleAnonymousAction();
61
73
  }
74
+ else if ((obj === null || obj === void 0 ? void 0 : obj.group) && status !== SCGroupSubscriptionStatusType.SUBSCRIBED) {
75
+ enqueueSnackbar(React.createElement(FormattedMessage, { id: "ui.common.group.actions.unsubscribed", defaultMessage: "ui.common.group.actions.unsubscribed" }), {
76
+ variant: 'warning',
77
+ autoHideDuration: 3000
78
+ });
79
+ }
62
80
  else {
63
81
  setIsFollowing(true);
64
82
  performFollow()
@@ -1,5 +1,5 @@
1
1
  import { __rest } from "tslib";
2
- import React, { useContext, useMemo, useState } from 'react';
2
+ import React, { useContext, useEffect, useMemo, useState } from 'react';
3
3
  import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
4
4
  import Icon from '@mui/material/Icon';
5
5
  import LoadingButton from '@mui/lab/LoadingButton';
@@ -13,7 +13,7 @@ import { SCOPE_SC_UI } from '../../../../constants/Errors';
13
13
  import classNames from 'classnames';
14
14
  import { useSnackbar } from 'notistack';
15
15
  import Skeleton from '@mui/material/Skeleton';
16
- import { SCContributionType } from '@selfcommunity/types';
16
+ import { SCContributionType, SCGroupSubscriptionStatusType } from '@selfcommunity/types';
17
17
  import { Endpoints, http } from '@selfcommunity/api-services';
18
18
  import { copyTextToClipboard, Logger } from '@selfcommunity/utils';
19
19
  import { SCPreferences, SCPreferencesContext, UserUtils, useSCContext, useSCFetchFeedObject, useSCRouting, useSCUser } from '@selfcommunity/react-core';
@@ -43,6 +43,7 @@ const Root = styled(Box, {
43
43
  slot: 'ActionShareRoot'
44
44
  })(() => ({}));
45
45
  export default function Share(props) {
46
+ var _a;
46
47
  // PROPS
47
48
  const { className = null, feedObjectId = null, feedObject = null, feedObjectType = SCContributionType.POST, withAction = true, withAudience = true, inlineAction = false } = props, rest = __rest(props, ["className", "feedObjectId", "feedObject", "feedObjectType", "withAction", "withAudience", "inlineAction"]);
48
49
  // STATE
@@ -54,6 +55,7 @@ export default function Share(props) {
54
55
  const [composerShareProps, setComposerShareProps] = useState(null);
55
56
  const [openSharesDialog, setOpenSharesDialog] = useState(false);
56
57
  const [anchorEl, setAnchorEl] = React.useState(null);
58
+ const [status, setStatus] = useState(null);
57
59
  // CONTEXT
58
60
  const scContext = useSCContext();
59
61
  const scRoutingContext = useSCRouting();
@@ -65,6 +67,7 @@ export default function Share(props) {
65
67
  const linkedinShareEnabled = SCPreferences.ADDONS_SHARE_POST_ON_LINKEDIN_ENABLED in scPreferencesContext.preferences &&
66
68
  scPreferencesContext.preferences[SCPreferences.ADDONS_SHARE_POST_ON_LINKEDIN_ENABLED].value;
67
69
  const scUserContext = useSCUser();
70
+ const scGroupsManager = scUserContext.managers.groups;
68
71
  const { enqueueSnackbar } = useSnackbar();
69
72
  const domain = typeof location !== 'undefined' && location.origin ? location.origin : '';
70
73
  const url = domain + scRoutingContext.url(getContributionRouteName(obj), getRouteData(obj));
@@ -97,6 +100,15 @@ export default function Share(props) {
97
100
  setObj(Object.assign({}, obj, { share_count: obj.share_count + 1 }));
98
101
  handleComposerOnClose();
99
102
  }
103
+ /**
104
+ * If the obj has a group, checks the subscription status for the authenticated user
105
+ */
106
+ useEffect(() => {
107
+ var _a;
108
+ if (((_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.id) && (obj === null || obj === void 0 ? void 0 : obj.group)) {
109
+ setStatus(scGroupsManager.subscriptionStatus(obj === null || obj === void 0 ? void 0 : obj.group));
110
+ }
111
+ }, [(_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.id, scGroupsManager.subscriptionStatus, obj === null || obj === void 0 ? void 0 : obj.group]);
100
112
  /**
101
113
  * Performs follow/unfollow
102
114
  * Post, Discussion, Status
@@ -139,6 +151,12 @@ export default function Share(props) {
139
151
  autoHideDuration: 3000
140
152
  });
141
153
  }
154
+ else if ((obj === null || obj === void 0 ? void 0 : obj.group) && status !== SCGroupSubscriptionStatusType.SUBSCRIBED) {
155
+ enqueueSnackbar(React.createElement(FormattedMessage, { id: "ui.common.group.actions.unsubscribed", defaultMessage: "ui.common.group.actions.unsubscribed" }), {
156
+ variant: 'warning',
157
+ autoHideDuration: 3000
158
+ });
159
+ }
142
160
  else {
143
161
  setIsSharing(true);
144
162
  performCreateMediaShare()
@@ -188,6 +188,7 @@ export interface FeedObjectProps extends CardProps, VirtualScrollerItemProps {
188
188
  |deleted|.SCFeedObject-deleted|Styles applied to the feed obj when is deleted (visible only for admin and moderator).|
189
189
  |header|.SCFeedObject-header|Styles applied to the header of the card.|
190
190
  |category|.SCFeedObject-category|Styles applied to the category element.|
191
+ |group|.SCFeedObject-group|Styles applied to the group element.|
191
192
  |avatar|.SCFeedObject-avatar|Styles applied to the avatar element.|
192
193
  |username|.SCFeedObject-username|Styles applied to the username element.|
193
194
  |activityAt|.SCFeedObject-activity-at|Styles applied to the activity at section.|
@@ -2,7 +2,7 @@ import { __rest } from "tslib";
2
2
  import React, { useCallback, useEffect, useMemo, useState } from 'react';
3
3
  import { styled } from '@mui/material/styles';
4
4
  import CardContent from '@mui/material/CardContent';
5
- import { Avatar, Box, Button, CardActions, CardHeader, Collapse, Stack, Tooltip, Typography } from '@mui/material';
5
+ import { Avatar, Box, Button, CardActions, CardHeader, Chip, Collapse, Stack, Tooltip, Typography } from '@mui/material';
6
6
  import FeedObjectSkeleton from './Skeleton';
7
7
  import DateTimeAgo from '../../shared/DateTimeAgo';
8
8
  import Bullet from '../../shared/Bullet';
@@ -25,7 +25,7 @@ import Activities from './Activities';
25
25
  import CommentObjectReply from '../CommentObjectReply';
26
26
  import { SCOPE_SC_UI } from '../../constants/Errors';
27
27
  import { useSnackbar } from 'notistack';
28
- import { SCContributionType } from '@selfcommunity/types';
28
+ import { SCContributionType, SCGroupSubscriptionStatusType } from '@selfcommunity/types';
29
29
  import { Endpoints, http } from '@selfcommunity/api-services';
30
30
  import { CacheStrategies, Logger, LRUCache } from '@selfcommunity/utils';
31
31
  import { catchUnauthorizedActionByBlockedUser } from '../../utils/errors';
@@ -40,6 +40,10 @@ const messages = defineMessages({
40
40
  visibleToAll: {
41
41
  id: 'ui.feedObject.visibleToAll',
42
42
  defaultMessage: 'ui.feedObject.visibleToAll'
43
+ },
44
+ visibleToGroup: {
45
+ id: 'ui.feedObject.visibleToGroup',
46
+ defaultMessage: 'ui.feedObject.visibleToGroup'
43
47
  }
44
48
  });
45
49
  const classes = {
@@ -47,6 +51,7 @@ const classes = {
47
51
  deleted: `${PREFIX}-deleted`,
48
52
  header: `${PREFIX}-header`,
49
53
  category: `${PREFIX}-category`,
54
+ group: `${PREFIX}-group`,
50
55
  avatar: `${PREFIX}-avatar`,
51
56
  username: `${PREFIX}-username`,
52
57
  activityAt: `${PREFIX}-activity-at`,
@@ -100,6 +105,7 @@ const Root = styled(Widget, {
100
105
  |deleted|.SCFeedObject-deleted|Styles applied to the feed obj when is deleted (visible only for admin and moderator).|
101
106
  |header|.SCFeedObject-header|Styles applied to the header of the card.|
102
107
  |category|.SCFeedObject-category|Styles applied to the category element.|
108
+ |group|.SCFeedObject-group|Styles applied to the group element.|
103
109
  |avatar|.SCFeedObject-avatar|Styles applied to the avatar element.|
104
110
  |username|.SCFeedObject-username|Styles applied to the username element.|
105
111
  |activityAt|.SCFeedObject-activity-at|Styles applied to the activity at section.|
@@ -125,7 +131,7 @@ const Root = styled(Widget, {
125
131
  * @param inProps
126
132
  */
127
133
  export default function FeedObject(inProps) {
128
- var _a;
134
+ var _a, _b;
129
135
  // PROPS
130
136
  const props = useThemeProps({
131
137
  props: inProps,
@@ -136,6 +142,7 @@ export default function FeedObject(inProps) {
136
142
  const scContext = useSCContext();
137
143
  const scRoutingContext = useSCRouting();
138
144
  const scUserContext = useSCUser();
145
+ const scGroupsManager = scUserContext.managers.groups;
139
146
  const { enqueueSnackbar } = useSnackbar();
140
147
  // OBJECTS
141
148
  const { obj, setObj, error } = useSCFetchFeedObject({ id: feedObjectId, feedObject, feedObjectType, cacheStrategy });
@@ -154,6 +161,7 @@ export default function FeedObject(inProps) {
154
161
  const [isReplying, setIsReplying] = useState(false);
155
162
  const [selectedActivities, setSelectedActivities] = useState(getInitialSelectedActivitiesType());
156
163
  const [expanded, setExpanded] = useState(summaryExpanded);
164
+ const [status, setStatus] = useState(null);
157
165
  // INTL
158
166
  const intl = useIntl();
159
167
  /**
@@ -167,7 +175,7 @@ export default function FeedObject(inProps) {
167
175
  }, [onStateChange, onHeightChange]);
168
176
  /**
169
177
  * Update state object
170
- * @param obj
178
+ * @param newObj
171
179
  */
172
180
  const updateObject = (newObj) => {
173
181
  setObj(newObj);
@@ -185,6 +193,15 @@ export default function FeedObject(inProps) {
185
193
  }
186
194
  return SCFeedObjectActivitiesType.RECENT_COMMENTS;
187
195
  }
196
+ /**
197
+ * If the obj has a group, checks the subscription status for the authenticated user
198
+ */
199
+ useEffect(() => {
200
+ var _a;
201
+ if (((_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.id) && (feedObject === null || feedObject === void 0 ? void 0 : feedObject.group)) {
202
+ setStatus(scGroupsManager.subscriptionStatus(feedObject === null || feedObject === void 0 ? void 0 : feedObject.group));
203
+ }
204
+ }, [(_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.id, scGroupsManager.subscriptionStatus, feedObject === null || feedObject === void 0 ? void 0 : feedObject.group]);
188
205
  /**
189
206
  * Open expanded activities
190
207
  */
@@ -342,6 +359,12 @@ export default function FeedObject(inProps) {
342
359
  autoHideDuration: 3000
343
360
  });
344
361
  }
362
+ else if ((feedObject === null || feedObject === void 0 ? void 0 : feedObject.group) && status !== SCGroupSubscriptionStatusType.SUBSCRIBED) {
363
+ enqueueSnackbar(React.createElement(FormattedMessage, { id: "ui.common.group.actions.unsubscribed", defaultMessage: "ui.common.group.actions.unsubscribed" }), {
364
+ variant: 'warning',
365
+ autoHideDuration: 3000
366
+ });
367
+ }
345
368
  else {
346
369
  setIsReplying(true);
347
370
  performReply(comment)
@@ -424,8 +447,13 @@ export default function FeedObject(inProps) {
424
447
  template === SCFeedObjectTemplateType.DETAIL ||
425
448
  template === SCFeedObjectTemplateType.SEARCH) {
426
449
  objElement = (React.createElement(React.Fragment, null, obj ? (React.createElement(Box, { className: classNames({ [classes.deleted]: obj && obj.deleted }) },
427
- obj.categories.length > 0 && (React.createElement("div", { className: classes.category }, obj.categories.map((c) => (React.createElement(Link, { to: scRoutingContext.url(SCRoutes.CATEGORY_ROUTE_NAME, c), key: c.id },
428
- React.createElement(Typography, { variant: "overline" }, c.name)))))),
450
+ obj.categories.length > 0 && (React.createElement("div", { className: classes.category },
451
+ React.createElement(React.Fragment, null, obj.group && (React.createElement("div", { className: classes.group },
452
+ React.createElement(Chip, { color: "secondary", size: "small", key: obj.group.id, icon: React.createElement(Icon, null, "groups"), component: Link, to: scRoutingContext.url(SCRoutes.GROUP_ROUTE_NAME, obj.group), clickable: true })))),
453
+ obj.categories.map((c) => (React.createElement(Link, { to: scRoutingContext.url(SCRoutes.CATEGORY_ROUTE_NAME, c), key: c.id },
454
+ React.createElement(Typography, { variant: "overline" }, c.name)))))),
455
+ obj.group && !obj.categories.length && (React.createElement("div", { className: classes.group },
456
+ React.createElement(Chip, { color: "secondary", size: "small", key: obj.group.id, icon: React.createElement(Icon, null, "groups"), label: obj.group.name, component: Link, to: scRoutingContext.url(SCRoutes.GROUP_ROUTE_NAME, obj.group), clickable: true }))),
429
457
  React.createElement(CardHeader, { className: classes.header, avatar: React.createElement(Link, Object.assign({}, (!obj.author.deleted && { to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author) }), { onClick: obj.author.deleted ? () => setOpenAlert(true) : null }),
430
458
  React.createElement(UserAvatar, { hide: !obj.author.community_badge },
431
459
  React.createElement(Avatar, { "aria-label": "recipe", src: obj.author.avatar, className: classes.avatar }, obj.author.username))), title: React.createElement(Link, Object.assign({}, (!obj.author.deleted && { to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author) }), { onClick: obj.author.deleted ? () => setOpenAlert(true) : null, className: classes.username }), obj.author.username), subheader: React.createElement(React.Fragment, null,
@@ -434,10 +462,11 @@ export default function FeedObject(inProps) {
434
462
  obj.location && (React.createElement(React.Fragment, null,
435
463
  React.createElement(Bullet, null),
436
464
  React.createElement(Box, { className: classes.location },
437
- React.createElement(Icon, null, "add_location_alt"), (_a = obj.location) === null || _a === void 0 ? void 0 :
438
- _a.location))),
465
+ React.createElement(Icon, null, "add_location_alt"), (_b = obj.location) === null || _b === void 0 ? void 0 :
466
+ _b.location))),
439
467
  React.createElement(Bullet, null),
440
- React.createElement(Box, { className: classes.tag }, obj.addressing.length > 0 ? (React.createElement(Tags, { tags: obj.addressing, TagChipProps: { disposable: false, clickable: false } })) : (React.createElement(Tooltip, { title: `${intl.formatMessage(messages.visibleToAll)}` },
468
+ React.createElement(Box, { className: classes.tag }, obj.addressing.length > 0 ? (React.createElement(Tags, { tags: obj.addressing, TagChipProps: { disposable: false, clickable: false } })) : obj.group ? (React.createElement(Tooltip, { title: `${intl.formatMessage(messages.visibleToGroup, { group: obj.group.name })}` },
469
+ React.createElement(Icon, { color: "disabled", fontSize: "small" }, "groups"))) : (React.createElement(Tooltip, { title: `${intl.formatMessage(messages.visibleToAll)}` },
441
470
  React.createElement(Icon, { color: "disabled", fontSize: "small" }, "public"))))), action: renderHeaderAction() }),
442
471
  React.createElement(CardContent, { classes: { root: classes.content } },
443
472
  React.createElement(Box, { className: classes.titleSection }, 'title' in obj && (React.createElement(React.Fragment, null, template === SCFeedObjectTemplateType.DETAIL ? (React.createElement(Typography, { variant: "body1", gutterBottom: true, className: classes.title }, obj.title)) : (React.createElement(Link, { to: scRoutingContext.url(getContributionRouteName(obj), getRouteData(obj)) },
@@ -466,8 +495,13 @@ export default function FeedObject(inProps) {
466
495
  }
467
496
  else if (template === SCFeedObjectTemplateType.SHARE) {
468
497
  objElement = (React.createElement(React.Fragment, null, obj ? (React.createElement(React.Fragment, null,
469
- obj.categories.length > 0 && (React.createElement("div", { className: classes.category }, obj.categories.map((c) => (React.createElement(Link, { to: scRoutingContext.url(SCRoutes.CATEGORY_ROUTE_NAME, c), key: c.id },
470
- React.createElement(Typography, { variant: "overline" }, c.name)))))),
498
+ obj.categories.length > 0 && (React.createElement("div", { className: classes.category },
499
+ React.createElement(React.Fragment, null, obj.group && (React.createElement("div", { className: classes.group },
500
+ React.createElement(Chip, { color: "secondary", size: "small", key: obj.group.id, icon: React.createElement(Icon, null, "groups"), component: Link, to: scRoutingContext.url(SCRoutes.GROUP_ROUTE_NAME, obj.group), clickable: true })))),
501
+ obj.categories.map((c) => (React.createElement(Link, { to: scRoutingContext.url(SCRoutes.CATEGORY_ROUTE_NAME, c), key: c.id },
502
+ React.createElement(Typography, { variant: "overline" }, c.name)))))),
503
+ obj.group && !obj.categories.length && (React.createElement("div", { className: classes.group },
504
+ React.createElement(Chip, { color: "secondary", size: "small", key: obj.group.id, icon: React.createElement(Icon, null, "groups"), label: obj.group.name, component: Link, to: scRoutingContext.url(SCRoutes.GROUP_ROUTE_NAME, obj.group), clickable: true }))),
471
505
  React.createElement(CardHeader, { classes: { root: classes.header }, avatar: React.createElement(Link, Object.assign({}, (!obj.author.deleted && { to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author) }), { onClick: obj.author.deleted ? () => setOpenAlert(true) : null, className: classes.username }),
472
506
  React.createElement(UserAvatar, { hide: !obj.author.community_badge },
473
507
  React.createElement(Avatar, { "aria-label": "recipe", src: obj.author.avatar, className: classes.avatar }, obj.author.username))), title: React.createElement(Link, Object.assign({}, (!obj.author.deleted && { to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author) }), { onClick: obj.author.deleted ? () => setOpenAlert(true) : null, className: classes.username }), obj.author.username), subheader: React.createElement(Link, { to: scRoutingContext.url(getContributionRouteName(obj), getRouteData(obj)), className: classes.activityAt },
@@ -1,6 +1,7 @@
1
1
  import { ButtonBaseProps } from '@mui/material';
2
2
  import { SCGroupType } from '@selfcommunity/types';
3
3
  import { WidgetProps } from '../Widget';
4
+ import { GroupSubscribeButtonProps } from '../GroupSubscribeButton';
4
5
  export interface GroupProps extends WidgetProps {
5
6
  /**
6
7
  * Group Object
@@ -13,10 +14,10 @@ export interface GroupProps extends WidgetProps {
13
14
  */
14
15
  groupId?: number;
15
16
  /**
16
- * Handles actions ignore
17
- * @default null
17
+ * Props to spread to group subscribe/unsubscribe button
18
+ * @default {}
18
19
  */
19
- handleIgnoreAction?: (u: any) => void;
20
+ groupSubscribeButtonProps?: GroupSubscribeButtonProps;
20
21
  /**
21
22
  * Badge content to show as group avatar badge if show reaction is true.
22
23
  */
@@ -2,6 +2,7 @@ import { __rest } from "tslib";
2
2
  import React, { useState } from 'react';
3
3
  import { styled } from '@mui/material/styles';
4
4
  import { Avatar, Icon, Stack } from '@mui/material';
5
+ import { SCGroupPrivacyType } from '@selfcommunity/types';
5
6
  import { Link, SCRoutes, useSCFetchGroup, useSCRouting } from '@selfcommunity/react-core';
6
7
  import { defineMessages, useIntl } from 'react-intl';
7
8
  import classNames from 'classnames';
@@ -61,7 +62,7 @@ export default function Group(inProps) {
61
62
  props: inProps,
62
63
  name: PREFIX
63
64
  });
64
- const { groupId = null, group = null, handleIgnoreAction, className = null, elevation, hideActions = false, buttonProps = {}, visible = true } = props, rest = __rest(props, ["groupId", "group", "handleIgnoreAction", "className", "elevation", "hideActions", "buttonProps", "visible"]);
65
+ const { groupId = null, group = null, className = null, elevation, hideActions = false, groupSubscribeButtonProps = {} } = props, rest = __rest(props, ["groupId", "group", "className", "elevation", "hideActions", "groupSubscribeButtonProps"]);
65
66
  // STATE
66
67
  const { scGroup } = useSCFetchGroup({ id: groupId, group });
67
68
  // CONTEXT
@@ -75,8 +76,8 @@ export default function Group(inProps) {
75
76
  */
76
77
  function renderAuthenticatedActions() {
77
78
  return (React.createElement(Stack, { className: classes.actions, direction: "row", alignItems: "center", justifyContent: "center", spacing: 2 },
78
- React.createElement(Icon, null, !visible ? 'private' : 'public'),
79
- React.createElement(GroupSubscribeButton, { group: group, groupId: groupId })));
79
+ React.createElement(Icon, null, (group === null || group === void 0 ? void 0 : group.privacy) === SCGroupPrivacyType.PRIVATE ? 'private' : 'public'),
80
+ React.createElement(GroupSubscribeButton, Object.assign({ group: group, groupId: groupId }, groupSubscribeButtonProps))));
80
81
  }
81
82
  /**
82
83
  * Renders group object
@@ -88,6 +89,6 @@ export default function Group(inProps) {
88
89
  * Renders root object
89
90
  */
90
91
  return (React.createElement(React.Fragment, null,
91
- React.createElement(Root, Object.assign({ elevation: elevation }, rest, { className: classNames(classes.root, className), ButtonBaseProps: buttonProps !== null && buttonProps !== void 0 ? buttonProps : { component: Link, to: scRoutingContext.url(SCRoutes.GROUP_ROUTE_NAME, scGroup) }, image: React.createElement(Avatar, { alt: scGroup.name, src: scGroup.image_medium, className: classes.avatar }), primary: scGroup.name, secondary: `${intl.formatMessage(messages.groupMembers, { total: scGroup.subscribers_counter })}`, actions: hideActions ? null : renderAuthenticatedActions() })),
92
+ React.createElement(Root, Object.assign({ elevation: elevation }, rest, { className: classNames(classes.root, className), ButtonBaseProps: { component: Link, to: scRoutingContext.url(SCRoutes.GROUP_ROUTE_NAME, scGroup) }, image: React.createElement(Avatar, { alt: scGroup.name, src: scGroup.image_medium, className: classes.avatar }), primary: scGroup.name, secondary: `${intl.formatMessage(messages.groupMembers, { total: scGroup.subscribers_counter })}`, actions: hideActions ? null : renderAuthenticatedActions() })),
92
93
  openAlert && React.createElement(UserDeletedSnackBar, { open: openAlert, handleClose: () => setOpenAlert(false) })));
93
94
  }
@@ -33,6 +33,6 @@ const Root = styled(BaseItem, {
33
33
  */
34
34
  export default function GroupSkeleton(props) {
35
35
  const theme = useTheme();
36
- return (React.createElement(Root, Object.assign({ className: classes.root }, props, { image: React.createElement(Skeleton, { animation: "wave", variant: "circular", width: theme.selfcommunity.user.avatar.sizeMedium, height: theme.selfcommunity.user.avatar.sizeMedium }), primary: React.createElement(Skeleton, { animation: "wave", height: 10, width: 120, style: { marginBottom: 10 } }), secondary: React.createElement(Skeleton, { animation: "wave", height: 10, width: 70, style: { marginBottom: 10 } }), actions: React.createElement(Button, { size: "small", variant: "outlined", disabled: true },
36
+ return (React.createElement(Root, Object.assign({ className: classes.root }, props, { image: React.createElement(Skeleton, { animation: "wave", variant: "circular", width: theme.selfcommunity.group.avatar.sizeSmall, height: theme.selfcommunity.group.avatar.sizeSmall }), primary: React.createElement(Skeleton, { animation: "wave", height: 10, width: 120, style: { marginBottom: 10 } }), secondary: React.createElement(Skeleton, { animation: "wave", height: 10, width: 70, style: { marginBottom: 10 } }), actions: React.createElement(Button, { size: "small", variant: "outlined", disabled: true },
37
37
  React.createElement(Skeleton, { animation: "wave", height: 10, width: 30, style: { marginTop: 5, marginBottom: 5 } })) })));
38
38
  }
@@ -0,0 +1,49 @@
1
+ import { TextFieldProps } from '@mui/material/TextField';
2
+ import { AutocompleteProps } from '@mui/material';
3
+ import { SCGroupType } from '@selfcommunity/types/src/index';
4
+ export interface GroupAutocompleteProps extends Pick<AutocompleteProps<SCGroupType | null, any, any, any>, Exclude<keyof AutocompleteProps<SCGroupType | null, any, any, any>, 'open' | 'onOpen' | 'onClose' | 'onChange' | 'filterSelectedOptions' | 'disableCloseOnSelect' | 'options' | 'getOptionLabel' | 'value' | 'selectOnFocus' | 'clearOnBlur' | 'blurOnSelect' | 'handleHomeEndKeys' | 'clearIcon' | 'noOptionsText' | 'isOptionEqualToValue' | 'renderTags' | 'renderOption' | 'renderInput'>> {
5
+ /**
6
+ * The maximum number of groups that will be visible when not focused.
7
+ * @default 0
8
+ */
9
+ limitCountGroups?: number;
10
+ /**
11
+ * If checkbox is selected
12
+ * @default false
13
+ */
14
+ checkboxSelect?: boolean;
15
+ /**
16
+ * The props applied to text field
17
+ * @default {variant: 'outlined, label: groups_label}
18
+ */
19
+ TextFieldProps?: TextFieldProps;
20
+ /**
21
+ * Callback for change event on poll object
22
+ * @param value
23
+ */
24
+ onChange?: (value: any) => void;
25
+ }
26
+ /**
27
+ * > API documentation for the Community-JS Group Autocomplete component. Learn about the available props and the CSS API.
28
+ *
29
+ *
30
+ * This component renders a bar that allows users to search (with autocomplete) for all the groups available in the application.
31
+ * Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/GroupAutocomplete)
32
+ *
33
+ * #### Import
34
+ * ```jsx
35
+ * import {GroupAutocomplete} from '@selfcommunity/react-ui';
36
+ * ```
37
+ * #### Component Name
38
+ * The name `SCGroupAutocomplete` can be used when providing style overrides in the theme.
39
+ *
40
+ * #### CSS
41
+ *
42
+ * |Rule Name|Global class|Description|
43
+ * |---|---|---|
44
+ * |root|.SCGroupAutocomplete-root|Styles applied to the root element.|
45
+ *
46
+ * @param inProps
47
+ */
48
+ declare const GroupAutocomplete: (inProps: GroupAutocompleteProps) => JSX.Element;
49
+ export default GroupAutocomplete;
@@ -0,0 +1,99 @@
1
+ import { __rest } from "tslib";
2
+ import React, { useEffect, useState } from 'react';
3
+ import { FormattedMessage } from 'react-intl';
4
+ import Autocomplete from '@mui/material/Autocomplete';
5
+ import TextField from '@mui/material/TextField';
6
+ import CircularProgress from '@mui/material/CircularProgress';
7
+ import parse from 'autosuggest-highlight/parse';
8
+ import match from 'autosuggest-highlight/match';
9
+ import { Avatar, Box, Typography } from '@mui/material';
10
+ import { useSCFetchGroups } from '@selfcommunity/react-core';
11
+ import { styled } from '@mui/material/styles';
12
+ import { useThemeProps } from '@mui/system';
13
+ const PREFIX = 'SCGroupAutocomplete';
14
+ const classes = {
15
+ root: `${PREFIX}-root`
16
+ };
17
+ const Root = styled(Autocomplete, {
18
+ name: PREFIX,
19
+ slot: 'Root',
20
+ overridesResolver: (props, styles) => styles.root
21
+ })(() => ({}));
22
+ /**
23
+ * > API documentation for the Community-JS Group Autocomplete component. Learn about the available props and the CSS API.
24
+ *
25
+ *
26
+ * This component renders a bar that allows users to search (with autocomplete) for all the groups available in the application.
27
+ * Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/GroupAutocomplete)
28
+ *
29
+ * #### Import
30
+ * ```jsx
31
+ * import {GroupAutocomplete} from '@selfcommunity/react-ui';
32
+ * ```
33
+ * #### Component Name
34
+ * The name `SCGroupAutocomplete` can be used when providing style overrides in the theme.
35
+ *
36
+ * #### CSS
37
+ *
38
+ * |Rule Name|Global class|Description|
39
+ * |---|---|---|
40
+ * |root|.SCGroupAutocomplete-root|Styles applied to the root element.|
41
+ *
42
+ * @param inProps
43
+ */
44
+ const GroupAutocomplete = (inProps) => {
45
+ const props = useThemeProps({
46
+ props: inProps,
47
+ name: PREFIX
48
+ });
49
+ // Props
50
+ const { onChange, defaultValue = null, disabled = false, TextFieldProps = {
51
+ variant: 'outlined',
52
+ label: React.createElement(FormattedMessage, { id: "ui.groupAutocomplete.label", defaultMessage: "ui.groupAutocomplete.label" })
53
+ } } = props, rest = __rest(props, ["onChange", "defaultValue", "disabled", "TextFieldProps"]);
54
+ // State
55
+ const [open, setOpen] = useState(false);
56
+ const [value, setValue] = useState(typeof defaultValue === 'string' ? null : defaultValue);
57
+ // HOOKS
58
+ const { groups, isLoading } = useSCFetchGroups();
59
+ useEffect(() => {
60
+ if (value === null) {
61
+ return;
62
+ }
63
+ onChange && onChange(value);
64
+ }, [value]);
65
+ useEffect(() => {
66
+ if (!isLoading && typeof defaultValue === 'string') {
67
+ setValue(groups.find((g) => g.id === Number(defaultValue)));
68
+ }
69
+ }, [isLoading]);
70
+ // Handlers
71
+ const handleOpen = () => {
72
+ setOpen(true);
73
+ };
74
+ const handleClose = () => {
75
+ setOpen(false);
76
+ };
77
+ const handleChange = (event, value) => {
78
+ setValue(value);
79
+ };
80
+ // Render
81
+ return (React.createElement(Root, Object.assign({ freeSolo: true, className: classes.root, open: open, onOpen: handleOpen, onClose: handleClose, options: groups || [], getOptionLabel: (option) => option.name || '', value: value, selectOnFocus: true, clearOnBlur: true, blurOnSelect: true, handleHomeEndKeys: true, clearIcon: null, disabled: disabled || isLoading, noOptionsText: React.createElement(FormattedMessage, { id: "ui.groupAutocomplete.empty", defaultMessage: "ui.groupAutocomplete.empty" }), onChange: handleChange, isOptionEqualToValue: (option, value) => value.id === option.id,
82
+ // renderTags={(value, getTagProps) => {
83
+ // return value.map((option: any, index) => (
84
+ // <Chip key={option.id} id={option.id} label={option.name} color={option.color} {...getTagProps({index})} />
85
+ // ));
86
+ // }}
87
+ renderOption: (props, option, { inputValue }) => {
88
+ const matches = match(option.name, inputValue);
89
+ const parts = parse(option.name, matches);
90
+ return (React.createElement(Box, Object.assign({ component: "li" }, props),
91
+ React.createElement(Avatar, { alt: option.name, src: option.image_small, sx: { marginRight: 1 } }),
92
+ React.createElement(React.Fragment, null, parts.map((part, index) => (React.createElement(Typography, { key: index, sx: { fontWeight: part.highlight ? 700 : 400, marginRight: 0.2 } }, part.text))))));
93
+ }, renderInput: (params) => {
94
+ return (React.createElement(TextField, Object.assign({}, params, TextFieldProps, { margin: "dense", InputProps: Object.assign(Object.assign({}, params.InputProps), { autoComplete: 'groups', endAdornment: (React.createElement(React.Fragment, null,
95
+ isLoading ? React.createElement(CircularProgress, { color: "inherit", size: 20 }) : null,
96
+ params.InputProps.endAdornment)) }) })));
97
+ } }, rest)));
98
+ };
99
+ export default GroupAutocomplete;
@@ -0,0 +1,3 @@
1
+ import GroupAutocomplete, { GroupAutocompleteProps } from './GroupAutocomplete';
2
+ export default GroupAutocomplete;
3
+ export { GroupAutocompleteProps };
@@ -0,0 +1,2 @@
1
+ import GroupAutocomplete from './GroupAutocomplete';
2
+ export default GroupAutocomplete;