@selfcommunity/react-ui 0.7.9-alpha.9 → 0.7.10-alpha.0
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/AccountRecover/AccountRecover.js +6 -1
- package/lib/cjs/components/BottomNavigation/BottomNavigation.js +4 -3
- package/lib/cjs/components/CategoryHeader/Skeleton.js +3 -2
- package/lib/cjs/components/ChangeGroupCover/ChangeGroupCover.js +6 -6
- package/lib/cjs/components/ChangeGroupPicture/ChangeGroupPicture.js +19 -16
- package/lib/cjs/components/Composer/Attributes/Attributes.js +3 -3
- package/lib/cjs/components/Composer/Composer.js +3 -3
- package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +1 -1
- package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.js +9 -19
- package/lib/cjs/components/Editor/Editor.js +2 -0
- package/lib/cjs/components/Editor/nodes/ImageNode.js +6 -0
- package/lib/cjs/components/Editor/plugins/ImagePlugin.js +4 -0
- package/lib/cjs/components/Editor/plugins/ToolbarPlugin.js +17 -3
- package/lib/cjs/components/FeedObject/Actions/Share/Share.js +18 -16
- package/lib/cjs/components/FeedObject/Contributors/Contributors.js +1 -1
- package/lib/cjs/components/FeedObject/FeedObject.d.ts +1 -0
- package/lib/cjs/components/FeedObject/FeedObject.js +27 -8
- package/lib/cjs/components/FeedObject/Poll/Poll.js +20 -20
- package/lib/cjs/components/FeedUpdatesWidget/FeedUpdatesWidget.js +1 -1
- package/lib/cjs/components/Footer/Footer.js +1 -1
- package/lib/cjs/components/Group/Group.d.ts +9 -1
- package/lib/cjs/components/Group/Group.js +18 -6
- package/lib/cjs/components/GroupAutocomplete/GroupAutocomplete.d.ts +0 -1
- package/lib/cjs/components/GroupAutocomplete/GroupAutocomplete.js +1 -2
- package/lib/cjs/components/GroupForm/GroupForm.js +64 -13
- package/lib/cjs/components/GroupHeader/GroupHeader.d.ts +2 -3
- package/lib/cjs/components/GroupHeader/GroupHeader.js +38 -5
- package/lib/cjs/components/GroupInfoWidget/GroupInfoWidget.js +65 -9
- package/lib/cjs/components/GroupInviteButton/GroupInviteButton.js +29 -7
- package/lib/cjs/components/GroupInvitedWidget/GroupInvitedWidget.d.ts +73 -0
- package/lib/cjs/components/GroupInvitedWidget/GroupInvitedWidget.js +220 -0
- package/lib/cjs/components/GroupInvitedWidget/Skeleton.d.ts +22 -0
- package/lib/cjs/components/GroupInvitedWidget/Skeleton.js +38 -0
- package/lib/cjs/components/GroupInvitedWidget/constants.d.ts +1 -0
- package/lib/cjs/components/GroupInvitedWidget/constants.js +4 -0
- package/lib/cjs/components/GroupInvitedWidget/index.d.ts +4 -0
- package/lib/cjs/components/GroupInvitedWidget/index.js +8 -0
- package/lib/cjs/components/GroupMembersButton/GroupMembersButton.js +6 -2
- package/lib/cjs/components/GroupMembersWidget/GroupMembersWidget.js +21 -6
- package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +12 -2
- package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.js +13 -12
- package/lib/cjs/components/GroupSettingsIconButton/GroupSettingsIconButton.d.ts +4 -12
- package/lib/cjs/components/GroupSettingsIconButton/GroupSettingsIconButton.js +33 -19
- package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.d.ts +3 -3
- package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.js +22 -6
- package/lib/cjs/components/Groups/Groups.d.ts +15 -8
- package/lib/cjs/components/Groups/Groups.js +86 -32
- package/lib/cjs/components/Groups/Skeleton.d.ts +4 -0
- package/lib/cjs/components/Groups/Skeleton.js +2 -2
- package/lib/cjs/components/InlineComposerWidget/InlineComposerWidget.js +7 -0
- package/lib/cjs/components/NavigationSettingsIconButton/NavigationSettingsIconButton.js +4 -4
- package/lib/cjs/components/NavigationToolbar/NavigationToolbar.js +10 -2
- package/lib/cjs/components/NavigationToolbarMobile/NavigationToolbarMobile.d.ts +1 -0
- package/lib/cjs/components/NavigationToolbarMobile/NavigationToolbarMobile.js +9 -1
- package/lib/cjs/components/Notification/Group/Group.d.ts +15 -0
- package/lib/cjs/components/Notification/Group/Group.js +87 -0
- package/lib/cjs/components/Notification/Group/index.d.ts +3 -0
- package/lib/cjs/components/Notification/Group/index.js +5 -0
- package/lib/cjs/components/Notification/Notification.js +34 -1
- package/lib/cjs/components/Notification/PrivateMessage/PrivateMessage.js +16 -5
- package/lib/cjs/components/PrivateMessageComponent/PrivateMessageComponent.d.ts +7 -1
- package/lib/cjs/components/PrivateMessageComponent/PrivateMessageComponent.js +16 -8
- package/lib/cjs/components/PrivateMessageSettingsIconButton/PrivateMessageSettingsIconButton.js +1 -1
- package/lib/cjs/components/PrivateMessageSnippetItem/PrivateMessageSnippetItem.js +11 -6
- package/lib/cjs/components/PrivateMessageSnippets/PrivateMessageSnippets.d.ts +9 -4
- package/lib/cjs/components/PrivateMessageSnippets/PrivateMessageSnippets.js +24 -6
- package/lib/cjs/components/PrivateMessageThread/PrivateMessageThread.d.ts +6 -1
- package/lib/cjs/components/PrivateMessageThread/PrivateMessageThread.js +46 -20
- package/lib/cjs/components/PrivateMessageThreadItem/PrivateMessageThreadItem.js +6 -0
- package/lib/cjs/components/SearchAutocomplete/SearchAutocomplete.js +22 -5
- package/lib/cjs/components/SnippetNotifications/SnippetNotifications.js +7 -0
- package/lib/cjs/components/ToastNotifications/ToastNotifications.js +7 -0
- package/lib/cjs/components/User/User.d.ts +6 -1
- package/lib/cjs/components/User/User.js +5 -4
- package/lib/cjs/components/UserSubscribedGroupsWidget/Skeleton.d.ts +21 -0
- package/lib/cjs/components/UserSubscribedGroupsWidget/Skeleton.js +46 -0
- package/lib/cjs/components/UserSubscribedGroupsWidget/UserSubscribedGroupsWidget.d.ts +68 -0
- package/lib/cjs/components/UserSubscribedGroupsWidget/UserSubscribedGroupsWidget.js +183 -0
- package/lib/cjs/components/UserSubscribedGroupsWidget/constants.d.ts +1 -0
- package/lib/cjs/components/UserSubscribedGroupsWidget/constants.js +4 -0
- package/lib/cjs/components/UserSubscribedGroupsWidget/index.d.ts +4 -0
- package/lib/cjs/components/UserSubscribedGroupsWidget/index.js +8 -0
- package/lib/cjs/components/VoteAudienceButton/VoteAudienceButton.js +1 -1
- package/lib/cjs/constants/PubSub.d.ts +28 -0
- package/lib/cjs/constants/PubSub.js +22 -0
- package/lib/cjs/index.d.ts +5 -3
- package/lib/cjs/index.js +11 -4
- package/lib/cjs/types/index.d.ts +2 -1
- package/lib/esm/components/AccountRecover/AccountRecover.js +6 -1
- package/lib/esm/components/BottomNavigation/BottomNavigation.js +5 -4
- package/lib/esm/components/CategoryHeader/Skeleton.js +3 -2
- package/lib/esm/components/ChangeGroupCover/ChangeGroupCover.js +6 -6
- package/lib/esm/components/ChangeGroupPicture/ChangeGroupPicture.js +19 -16
- package/lib/esm/components/Composer/Attributes/Attributes.js +3 -3
- package/lib/esm/components/Composer/Composer.js +3 -3
- package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +1 -1
- package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.js +9 -19
- package/lib/esm/components/Editor/Editor.js +2 -0
- package/lib/esm/components/Editor/nodes/ImageNode.js +6 -0
- package/lib/esm/components/Editor/plugins/ImagePlugin.js +4 -0
- package/lib/esm/components/Editor/plugins/ToolbarPlugin.js +19 -5
- package/lib/esm/components/FeedObject/Actions/Share/Share.js +19 -17
- package/lib/esm/components/FeedObject/Contributors/Contributors.js +1 -1
- package/lib/esm/components/FeedObject/FeedObject.d.ts +1 -0
- package/lib/esm/components/FeedObject/FeedObject.js +28 -9
- package/lib/esm/components/FeedObject/Poll/Poll.js +20 -20
- package/lib/esm/components/FeedUpdatesWidget/FeedUpdatesWidget.js +1 -1
- package/lib/esm/components/Footer/Footer.js +2 -2
- package/lib/esm/components/Group/Group.d.ts +9 -1
- package/lib/esm/components/Group/Group.js +22 -10
- package/lib/esm/components/GroupAutocomplete/GroupAutocomplete.d.ts +0 -1
- package/lib/esm/components/GroupAutocomplete/GroupAutocomplete.js +1 -2
- package/lib/esm/components/GroupForm/GroupForm.js +64 -13
- package/lib/esm/components/GroupHeader/GroupHeader.d.ts +2 -3
- package/lib/esm/components/GroupHeader/GroupHeader.js +40 -7
- package/lib/esm/components/GroupInfoWidget/GroupInfoWidget.js +65 -9
- package/lib/esm/components/GroupInviteButton/GroupInviteButton.js +29 -7
- package/lib/esm/components/GroupInvitedWidget/GroupInvitedWidget.d.ts +73 -0
- package/lib/esm/components/GroupInvitedWidget/GroupInvitedWidget.js +217 -0
- package/lib/esm/components/GroupInvitedWidget/Skeleton.d.ts +22 -0
- package/lib/esm/components/GroupInvitedWidget/Skeleton.js +34 -0
- package/lib/esm/components/GroupInvitedWidget/constants.d.ts +1 -0
- package/lib/esm/components/GroupInvitedWidget/constants.js +1 -0
- package/lib/esm/components/GroupInvitedWidget/index.d.ts +4 -0
- package/lib/esm/components/GroupInvitedWidget/index.js +4 -0
- package/lib/esm/components/GroupMembersButton/GroupMembersButton.js +7 -3
- package/lib/esm/components/GroupMembersWidget/GroupMembersWidget.js +22 -7
- package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +12 -2
- package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.js +13 -12
- package/lib/esm/components/GroupSettingsIconButton/GroupSettingsIconButton.d.ts +4 -12
- package/lib/esm/components/GroupSettingsIconButton/GroupSettingsIconButton.js +33 -19
- package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.d.ts +3 -3
- package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.js +22 -6
- package/lib/esm/components/Groups/Groups.d.ts +15 -8
- package/lib/esm/components/Groups/Groups.js +91 -37
- package/lib/esm/components/Groups/Skeleton.d.ts +4 -0
- package/lib/esm/components/Groups/Skeleton.js +2 -2
- package/lib/esm/components/InlineComposerWidget/InlineComposerWidget.js +9 -2
- package/lib/esm/components/NavigationSettingsIconButton/NavigationSettingsIconButton.js +4 -4
- package/lib/esm/components/NavigationToolbar/NavigationToolbar.js +11 -3
- package/lib/esm/components/NavigationToolbarMobile/NavigationToolbarMobile.d.ts +1 -0
- package/lib/esm/components/NavigationToolbarMobile/NavigationToolbarMobile.js +11 -3
- package/lib/esm/components/Notification/Group/Group.d.ts +15 -0
- package/lib/esm/components/Notification/Group/Group.js +84 -0
- package/lib/esm/components/Notification/Group/index.d.ts +3 -0
- package/lib/esm/components/Notification/Group/index.js +2 -0
- package/lib/esm/components/Notification/Notification.js +34 -1
- package/lib/esm/components/Notification/PrivateMessage/PrivateMessage.js +16 -5
- package/lib/esm/components/PrivateMessageComponent/PrivateMessageComponent.d.ts +7 -1
- package/lib/esm/components/PrivateMessageComponent/PrivateMessageComponent.js +17 -9
- package/lib/esm/components/PrivateMessageSettingsIconButton/PrivateMessageSettingsIconButton.js +1 -1
- package/lib/esm/components/PrivateMessageSnippetItem/PrivateMessageSnippetItem.js +11 -6
- package/lib/esm/components/PrivateMessageSnippets/PrivateMessageSnippets.d.ts +9 -4
- package/lib/esm/components/PrivateMessageSnippets/PrivateMessageSnippets.js +26 -8
- package/lib/esm/components/PrivateMessageThread/PrivateMessageThread.d.ts +6 -1
- package/lib/esm/components/PrivateMessageThread/PrivateMessageThread.js +48 -22
- package/lib/esm/components/PrivateMessageThreadItem/PrivateMessageThreadItem.js +7 -1
- package/lib/esm/components/SearchAutocomplete/SearchAutocomplete.js +22 -5
- package/lib/esm/components/SnippetNotifications/SnippetNotifications.js +7 -0
- package/lib/esm/components/ToastNotifications/ToastNotifications.js +7 -0
- package/lib/esm/components/User/User.d.ts +6 -1
- package/lib/esm/components/User/User.js +5 -4
- package/lib/esm/components/UserSubscribedGroupsWidget/Skeleton.d.ts +21 -0
- package/lib/esm/components/UserSubscribedGroupsWidget/Skeleton.js +42 -0
- package/lib/esm/components/UserSubscribedGroupsWidget/UserSubscribedGroupsWidget.d.ts +68 -0
- package/lib/esm/components/UserSubscribedGroupsWidget/UserSubscribedGroupsWidget.js +180 -0
- package/lib/esm/components/UserSubscribedGroupsWidget/constants.d.ts +1 -0
- package/lib/esm/components/UserSubscribedGroupsWidget/constants.js +1 -0
- package/lib/esm/components/UserSubscribedGroupsWidget/index.d.ts +4 -0
- package/lib/esm/components/UserSubscribedGroupsWidget/index.js +4 -0
- package/lib/esm/components/VoteAudienceButton/VoteAudienceButton.js +1 -1
- package/lib/esm/constants/PubSub.d.ts +28 -0
- package/lib/esm/constants/PubSub.js +19 -0
- package/lib/esm/index.d.ts +5 -3
- package/lib/esm/index.js +4 -2
- package/lib/esm/types/index.d.ts +2 -1
- package/lib/umd/311.js +2 -0
- package/lib/umd/react-ui.js +1 -1
- package/package.json +10 -10
- package/lib/umd/871.js +0 -2
- /package/lib/umd/{871.js.LICENSE.txt → 311.js.LICENSE.txt} +0 -0
|
@@ -28,7 +28,6 @@ export interface GroupAutocompleteProps extends Pick<AutocompleteProps<SCGroupTy
|
|
|
28
28
|
*
|
|
29
29
|
*
|
|
30
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
31
|
*
|
|
33
32
|
* #### Import
|
|
34
33
|
* ```jsx
|
|
@@ -24,7 +24,6 @@ const Root = styled(Autocomplete, {
|
|
|
24
24
|
*
|
|
25
25
|
*
|
|
26
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
27
|
*
|
|
29
28
|
* #### Import
|
|
30
29
|
* ```jsx
|
|
@@ -78,7 +77,7 @@ const GroupAutocomplete = (inProps) => {
|
|
|
78
77
|
setValue(value);
|
|
79
78
|
};
|
|
80
79
|
// Render
|
|
81
|
-
return (React.createElement(Root, Object.assign({
|
|
80
|
+
return (React.createElement(Root, Object.assign({ 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
81
|
// renderTags={(value, getTagProps) => {
|
|
83
82
|
// return value.map((option: any, index) => (
|
|
84
83
|
// <Chip key={option.id} id={option.id} label={option.name} color={option.color} {...getTagProps({index})} />
|
|
@@ -13,10 +13,12 @@ import ChangeGroupPicture from '../ChangeGroupPicture';
|
|
|
13
13
|
import ChangeGroupCover from '../ChangeGroupCover';
|
|
14
14
|
import { GROUP_DESCRIPTION_MAX_LENGTH, GROUP_TITLE_MAX_LENGTH } from '../../constants/Group';
|
|
15
15
|
import GroupInviteButton from '../GroupInviteButton';
|
|
16
|
+
import PubSub from 'pubsub-js';
|
|
16
17
|
import { SCGroupPrivacyType } from '@selfcommunity/types';
|
|
17
18
|
import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
18
19
|
import { formatHttpErrorCode, GroupService } from '@selfcommunity/api-services';
|
|
19
20
|
import { Logger } from '@selfcommunity/utils';
|
|
21
|
+
import { SCEventType, SCTopicType } from '../../constants/PubSub';
|
|
20
22
|
const messages = defineMessages({
|
|
21
23
|
name: {
|
|
22
24
|
id: 'ui.groupForm.name.placeholder',
|
|
@@ -88,6 +90,7 @@ const Root = styled(BaseDialog, {
|
|
|
88
90
|
* @param inProps
|
|
89
91
|
*/
|
|
90
92
|
export default function GroupForm(inProps) {
|
|
93
|
+
var _a;
|
|
91
94
|
//PROPS
|
|
92
95
|
const props = useThemeProps({
|
|
93
96
|
props: inProps,
|
|
@@ -140,6 +143,22 @@ export default function GroupForm(inProps) {
|
|
|
140
143
|
setError(error);
|
|
141
144
|
}
|
|
142
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Notify when a group info changed
|
|
148
|
+
* @param data
|
|
149
|
+
*/
|
|
150
|
+
function notifyChanges(data) {
|
|
151
|
+
if (data) {
|
|
152
|
+
if (group) {
|
|
153
|
+
// Edit group
|
|
154
|
+
PubSub.publish(`${SCTopicType.GROUP}.${SCEventType.EDIT}`, data);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
// Create group
|
|
158
|
+
PubSub.publish(`${SCTopicType.GROUP}.${SCEventType.CREATE}`, data);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
143
162
|
const handleSubmit = () => {
|
|
144
163
|
setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: true })));
|
|
145
164
|
const formData = new FormData();
|
|
@@ -153,8 +172,10 @@ export default function GroupForm(inProps) {
|
|
|
153
172
|
if (field.emotionalImageOriginalFile) {
|
|
154
173
|
formData.append('emotional_image_original', field.emotionalImageOriginalFile);
|
|
155
174
|
}
|
|
156
|
-
|
|
157
|
-
|
|
175
|
+
if (!group) {
|
|
176
|
+
for (const key in field.invitedUsers) {
|
|
177
|
+
formData.append(key, field.invitedUsers[key]);
|
|
178
|
+
}
|
|
158
179
|
}
|
|
159
180
|
let groupService;
|
|
160
181
|
if (group) {
|
|
@@ -166,6 +187,7 @@ export default function GroupForm(inProps) {
|
|
|
166
187
|
groupService
|
|
167
188
|
.then((data) => {
|
|
168
189
|
onSuccess && onSuccess(data);
|
|
190
|
+
notifyChanges(data);
|
|
169
191
|
onClose && onClose();
|
|
170
192
|
setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: false })));
|
|
171
193
|
})
|
|
@@ -204,33 +226,62 @@ export default function GroupForm(inProps) {
|
|
|
204
226
|
endAdornment: React.createElement(Typography, { variant: "body2" }, GROUP_TITLE_MAX_LENGTH - field.name.length)
|
|
205
227
|
} }),
|
|
206
228
|
React.createElement(TextField, { multiline: true, className: classes.description, placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: {
|
|
207
|
-
endAdornment: React.createElement(Typography, { variant: "body2" }, GROUP_DESCRIPTION_MAX_LENGTH - field.description.length)
|
|
229
|
+
endAdornment: (React.createElement(Typography, { variant: "body2" }, ((_a = field.description) === null || _a === void 0 ? void 0 : _a.length) ? GROUP_DESCRIPTION_MAX_LENGTH - field.description.length : GROUP_DESCRIPTION_MAX_LENGTH))
|
|
208
230
|
} }),
|
|
209
231
|
React.createElement(Box, { className: classes.privacySection },
|
|
210
232
|
React.createElement(Typography, { variant: "h4" },
|
|
211
|
-
React.createElement(FormattedMessage, { id: "ui.groupForm.privacy.title", defaultMessage: "ui.groupForm.privacy.title", values: {
|
|
233
|
+
React.createElement(FormattedMessage, { id: "ui.groupForm.privacy.title", defaultMessage: "ui.groupForm.privacy.title", values: {
|
|
234
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
235
|
+
// @ts-ignore
|
|
236
|
+
b: (chunks) => React.createElement("strong", null, chunks)
|
|
237
|
+
} })),
|
|
212
238
|
React.createElement(Stack, { direction: "row", spacing: 1, alignItems: "center" },
|
|
213
239
|
React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: !field.isPublic }) },
|
|
214
240
|
React.createElement(Icon, null, "private"),
|
|
215
241
|
React.createElement(FormattedMessage, { id: "ui.groupForm.privacy.private", defaultMessage: "ui.groupForm.privacy.private" })),
|
|
216
|
-
React.createElement(Switch, { className: classes.switch, checked: field.isPublic,
|
|
242
|
+
React.createElement(Switch, { className: classes.switch, checked: field.isPublic, onChange: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['isPublic']: !field.isPublic }))), disabled: group && group.privacy === SCGroupPrivacyType.PRIVATE }),
|
|
217
243
|
React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: field.isPublic }) },
|
|
218
244
|
React.createElement(Icon, null, "public"),
|
|
219
245
|
React.createElement(FormattedMessage, { id: "ui.groupForm.privacy.public", defaultMessage: "ui.groupForm.privacy.public" }))),
|
|
220
|
-
React.createElement(Typography, { variant: "body2", className: classes.privacySectionInfo }, field.isPublic ? (React.createElement(FormattedMessage, { id: "ui.groupForm.privacy.public.info", defaultMessage: "ui.groupForm.privacy.public.info", values: {
|
|
221
|
-
|
|
246
|
+
React.createElement(Typography, { variant: "body2", className: classes.privacySectionInfo }, field.isPublic ? (React.createElement(FormattedMessage, { id: "ui.groupForm.privacy.public.info", defaultMessage: "ui.groupForm.privacy.public.info", values: {
|
|
247
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
248
|
+
// @ts-ignore
|
|
249
|
+
b: (chunks) => React.createElement("strong", null, chunks)
|
|
250
|
+
} })) : (React.createElement(React.Fragment, null, group && group.privacy === SCGroupPrivacyType.PRIVATE ? (React.createElement(FormattedMessage, { id: "ui.groupForm.privacy.private.info.edit", defaultMessage: "ui.groupForm.private.public.info.edit", values: {
|
|
251
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
252
|
+
// @ts-ignore
|
|
253
|
+
b: (chunks) => React.createElement("strong", null, chunks)
|
|
254
|
+
} })) : (React.createElement(FormattedMessage, { id: "ui.groupForm.privacy.private.info", defaultMessage: "ui.groupForm.private.public.info", values: {
|
|
255
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
256
|
+
// @ts-ignore
|
|
257
|
+
b: (chunks) => React.createElement("strong", null, chunks)
|
|
258
|
+
} })))))),
|
|
259
|
+
React.createElement(Box, { className: classes.visibilitySection }, ((!field.isPublic && !group) || (group && !field.isPublic)) && (React.createElement(React.Fragment, null,
|
|
222
260
|
React.createElement(Typography, { variant: "h4" },
|
|
223
|
-
React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.title", defaultMessage: "ui.groupForm.visibility.title", values: {
|
|
261
|
+
React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.title", defaultMessage: "ui.groupForm.visibility.title", values: {
|
|
262
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
263
|
+
// @ts-ignore
|
|
264
|
+
b: (chunks) => React.createElement("strong", null, chunks)
|
|
265
|
+
} })),
|
|
224
266
|
React.createElement(Stack, { direction: "row", spacing: 1, alignItems: "center" },
|
|
225
267
|
React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: !field.isVisible }) },
|
|
226
268
|
React.createElement(Icon, null, "visibility_off"),
|
|
227
269
|
React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.hidden", defaultMessage: "ui.groupForm.visibility.hidden" })),
|
|
228
|
-
React.createElement(Switch, { className: classes.switch, checked: field.isVisible,
|
|
270
|
+
React.createElement(Switch, { className: classes.switch, checked: field.isVisible, onChange: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['isVisible']: !field.isVisible }))) }),
|
|
229
271
|
React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: field.isVisible }) },
|
|
230
272
|
React.createElement(Icon, null, "visibility"),
|
|
231
273
|
React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.visible", defaultMessage: "ui.groupForm.visibility.visible" }))),
|
|
232
|
-
React.createElement(Typography, { variant: "body2", className: classes.visibilitySectionInfo }, !field.isVisible ? (React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.hidden.info", defaultMessage: "ui.groupForm.visibility.hidden.info", values: {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
274
|
+
React.createElement(Typography, { variant: "body2", className: classes.visibilitySectionInfo }, !field.isVisible ? (React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.hidden.info", defaultMessage: "ui.groupForm.visibility.hidden.info", values: {
|
|
275
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
276
|
+
// @ts-ignore
|
|
277
|
+
b: (chunks) => React.createElement("strong", null, chunks)
|
|
278
|
+
} })) : (React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.visible.info", defaultMessage: "ui.groupForm.visibility.visible.info", values: {
|
|
279
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
280
|
+
// @ts-ignore
|
|
281
|
+
b: (chunks) => React.createElement("strong", null, chunks)
|
|
282
|
+
} }))))))),
|
|
283
|
+
!group && (React.createElement(React.Fragment, null,
|
|
284
|
+
React.createElement(Divider, null),
|
|
285
|
+
React.createElement(Box, { className: classes.inviteSection },
|
|
286
|
+
React.createElement(GroupInviteButton, { handleInvitations: handleInviteSection })))))));
|
|
236
287
|
}
|
|
@@ -35,10 +35,10 @@ export interface GroupHeaderProps {
|
|
|
35
35
|
*/
|
|
36
36
|
ChangeCoverProps?: ChangeGroupCoverProps;
|
|
37
37
|
/**
|
|
38
|
-
* Props to spread
|
|
38
|
+
* Props to spread group button followed
|
|
39
39
|
* @default {}
|
|
40
40
|
*/
|
|
41
|
-
GroupSubscribeButtonProps?:
|
|
41
|
+
GroupSubscribeButtonProps?: GroupSubscribeButtonProps;
|
|
42
42
|
/**
|
|
43
43
|
* Props to spread to the group memebers button
|
|
44
44
|
* @default {}
|
|
@@ -54,7 +54,6 @@ export interface GroupHeaderProps {
|
|
|
54
54
|
*
|
|
55
55
|
*
|
|
56
56
|
* This component renders the groups top section.
|
|
57
|
-
* Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/UserProfileHeader)
|
|
58
57
|
|
|
59
58
|
#### Import
|
|
60
59
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
|
-
import React, { useMemo } from 'react';
|
|
2
|
+
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
3
3
|
import { styled } from '@mui/material/styles';
|
|
4
4
|
import { Avatar, Box, Icon, Paper, Typography } from '@mui/material';
|
|
5
|
-
import { SCGroupPrivacyType } from '@selfcommunity/types';
|
|
5
|
+
import { SCGroupPrivacyType, SCGroupSubscriptionStatusType } from '@selfcommunity/types';
|
|
6
6
|
import { SCPreferences, useSCFetchGroup, useSCPreferences, useSCUser } from '@selfcommunity/react-core';
|
|
7
7
|
import GroupHeaderSkeleton from './Skeleton';
|
|
8
8
|
import classNames from 'classnames';
|
|
@@ -16,6 +16,8 @@ import GroupMembersButton from '../GroupMembersButton';
|
|
|
16
16
|
import EditGroupButton from '../EditGroupButton';
|
|
17
17
|
import GroupSubscribeButton from '../GroupSubscribeButton';
|
|
18
18
|
import GroupInviteButton from '../GroupInviteButton';
|
|
19
|
+
import { SCEventType, SCTopicType } from '../../constants/PubSub';
|
|
20
|
+
import PubSub from 'pubsub-js';
|
|
19
21
|
const classes = {
|
|
20
22
|
root: `${PREFIX}-root`,
|
|
21
23
|
cover: `${PREFIX}-cover`,
|
|
@@ -38,7 +40,6 @@ const Root = styled(Box, {
|
|
|
38
40
|
*
|
|
39
41
|
*
|
|
40
42
|
* This component renders the groups top section.
|
|
41
|
-
* Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/UserProfileHeader)
|
|
42
43
|
|
|
43
44
|
#### Import
|
|
44
45
|
|
|
@@ -79,6 +80,8 @@ export default function GroupHeader(inProps) {
|
|
|
79
80
|
const scUserContext = useSCUser();
|
|
80
81
|
// HOOKS
|
|
81
82
|
const { scGroup, setSCGroup } = useSCFetchGroup({ id: groupId, group });
|
|
83
|
+
// REFS
|
|
84
|
+
const updatesSubscription = useRef(null);
|
|
82
85
|
// CONST
|
|
83
86
|
const isGroupAdmin = useMemo(() => { var _a; return scUserContext.user && ((_a = scGroup === null || scGroup === void 0 ? void 0 : scGroup.managed_by) === null || _a === void 0 ? void 0 : _a.id) === scUserContext.user.id; }, [scUserContext.user, (_a = scGroup === null || scGroup === void 0 ? void 0 : scGroup.managed_by) === null || _a === void 0 ? void 0 : _a.id]);
|
|
84
87
|
/**
|
|
@@ -87,7 +90,7 @@ export default function GroupHeader(inProps) {
|
|
|
87
90
|
*/
|
|
88
91
|
function handleChangeAvatar(avatar) {
|
|
89
92
|
if (isGroupAdmin) {
|
|
90
|
-
setSCGroup(Object.assign({}, scGroup, {
|
|
93
|
+
setSCGroup(Object.assign({}, scGroup, { image_big: avatar }));
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
/**
|
|
@@ -105,6 +108,34 @@ export default function GroupHeader(inProps) {
|
|
|
105
108
|
const handleSubscribe = (group, status) => {
|
|
106
109
|
setSCGroup(Object.assign(Object.assign({}, group), { subscribers_counter: group.subscribers_counter + (status ? 1 : -1) }));
|
|
107
110
|
};
|
|
111
|
+
/**
|
|
112
|
+
* Subscriber for pubsub callback
|
|
113
|
+
*/
|
|
114
|
+
const onChangeGroupMembersHandler = useCallback((msg, data) => {
|
|
115
|
+
var _a;
|
|
116
|
+
if (data && ((_a = data === null || data === void 0 ? void 0 : data.group) === null || _a === void 0 ? void 0 : _a.id) === (scGroup === null || scGroup === void 0 ? void 0 : scGroup.id)) {
|
|
117
|
+
let _group = Object.assign({}, scGroup);
|
|
118
|
+
if (msg === `${SCTopicType.GROUP}.${SCEventType.ADD_MEMBER}`) {
|
|
119
|
+
_group.subscribers_counter = _group.subscribers_counter + 1;
|
|
120
|
+
}
|
|
121
|
+
else if (msg === `${SCTopicType.GROUP}.${SCEventType.REMOVE_MEMBER}`) {
|
|
122
|
+
_group.subscribers_counter = Math.max(_group.subscribers_counter - 1, 0);
|
|
123
|
+
}
|
|
124
|
+
console.log(_group);
|
|
125
|
+
setSCGroup(_group);
|
|
126
|
+
}
|
|
127
|
+
}, [scGroup, setSCGroup]);
|
|
128
|
+
/**
|
|
129
|
+
* On mount, subscribe to receive groups updates (only edit)
|
|
130
|
+
*/
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
if (scGroup) {
|
|
133
|
+
updatesSubscription.current = PubSub.subscribe(`${SCTopicType.GROUP}.${SCEventType.MEMBERS}`, onChangeGroupMembersHandler);
|
|
134
|
+
}
|
|
135
|
+
return () => {
|
|
136
|
+
updatesSubscription.current && PubSub.unsubscribe(updatesSubscription.current);
|
|
137
|
+
};
|
|
138
|
+
}, [scGroup]);
|
|
108
139
|
// RENDER
|
|
109
140
|
if (!scGroup) {
|
|
110
141
|
return React.createElement(GroupHeaderSkeleton, null);
|
|
@@ -116,7 +147,7 @@ export default function GroupHeader(inProps) {
|
|
|
116
147
|
React.createElement(Paper, { style: _backgroundCover, classes: { root: classes.cover } },
|
|
117
148
|
React.createElement(Box, { className: classes.avatar },
|
|
118
149
|
React.createElement(Avatar, null,
|
|
119
|
-
React.createElement("img", { alt: "group", src: scGroup.
|
|
150
|
+
React.createElement("img", { alt: "group", src: scGroup.image_big ? scGroup.image_big : '' }))),
|
|
120
151
|
isGroupAdmin && (React.createElement(React.Fragment, null,
|
|
121
152
|
React.createElement(ChangeGroupPicture, Object.assign({ groupId: scGroup.id, onChange: handleChangeAvatar, className: classes.changePicture }, ChangePictureProps)),
|
|
122
153
|
React.createElement("div", { className: classes.changeCover },
|
|
@@ -136,9 +167,11 @@ export default function GroupHeader(inProps) {
|
|
|
136
167
|
React.createElement(FormattedMessage, { id: "ui.groupHeader.visibility.visible", defaultMessage: "ui.groupHeader.visibility.visible" }))) : (React.createElement(Typography, { className: classes.visibilityItem },
|
|
137
168
|
React.createElement(Icon, null, "visibility_off"),
|
|
138
169
|
React.createElement(FormattedMessage, { id: "ui.groupHeader.visibility.hidden", defaultMessage: "ui.groupHeader.visibility.hidden" })))),
|
|
139
|
-
React.createElement(React.Fragment, null, ((scGroup && scGroup.privacy === SCGroupPrivacyType.PUBLIC) ||
|
|
170
|
+
React.createElement(React.Fragment, null, ((scGroup && scGroup.privacy === SCGroupPrivacyType.PUBLIC) ||
|
|
171
|
+
scGroup.subscription_status === SCGroupSubscriptionStatusType.SUBSCRIBED ||
|
|
172
|
+
isGroupAdmin) && (React.createElement(Box, { className: classes.members },
|
|
140
173
|
React.createElement(Typography, { className: classes.membersCounter, component: "div" },
|
|
141
174
|
React.createElement(FormattedMessage, { id: "ui.groupHeader.members", defaultMessage: "ui.groupHeader.members", values: { total: scGroup.subscribers_counter } })),
|
|
142
|
-
React.createElement(GroupMembersButton, Object.assign({ groupId: scGroup === null || scGroup === void 0 ? void 0 : scGroup.id, group: scGroup, autoHide: !isGroupAdmin }, GroupMembersButtonProps))))),
|
|
175
|
+
React.createElement(GroupMembersButton, Object.assign({ key: scGroup.subscribers_counter, groupId: scGroup === null || scGroup === void 0 ? void 0 : scGroup.id, group: scGroup, autoHide: !isGroupAdmin }, GroupMembersButtonProps))))),
|
|
143
176
|
isGroupAdmin ? (React.createElement(GroupInviteButton, { group: scGroup, groupId: scGroup.id })) : (React.createElement(GroupSubscribeButton, Object.assign({ group: scGroup, onSubscribe: handleSubscribe }, GroupSubscribeButtonProps))))));
|
|
144
177
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useCallback, useEffect, useRef } from 'react';
|
|
3
3
|
import { styled } from '@mui/material/styles';
|
|
4
4
|
import { CardContent, Icon, Typography } from '@mui/material';
|
|
5
5
|
import classNames from 'classnames';
|
|
@@ -8,7 +8,11 @@ import { useThemeProps } from '@mui/system';
|
|
|
8
8
|
import { PREFIX } from './constants';
|
|
9
9
|
import { FormattedMessage, useIntl } from 'react-intl';
|
|
10
10
|
import { SCGroupPrivacyType } from '@selfcommunity/types';
|
|
11
|
+
import PubSub from 'pubsub-js';
|
|
11
12
|
import { useSCFetchGroup } from '@selfcommunity/react-core';
|
|
13
|
+
import GroupInfoWidgetSkeleton from './Skeleton';
|
|
14
|
+
import { SCEventType, SCTopicType } from '../../constants/PubSub';
|
|
15
|
+
import User from '../User';
|
|
12
16
|
const classes = {
|
|
13
17
|
root: `${PREFIX}-root`,
|
|
14
18
|
title: `${PREFIX}-title`,
|
|
@@ -17,6 +21,7 @@ const classes = {
|
|
|
17
21
|
privacyTitle: `${PREFIX}-privacy-title`,
|
|
18
22
|
visibility: `${PREFIX}-visibility`,
|
|
19
23
|
visibilityTitle: `${PREFIX}-visibility-title`,
|
|
24
|
+
admin: `${PREFIX}-admin`,
|
|
20
25
|
date: `${PREFIX}-date`
|
|
21
26
|
};
|
|
22
27
|
const Root = styled(Widget, {
|
|
@@ -52,6 +57,7 @@ const Root = styled(Widget, {
|
|
|
52
57
|
* @param inProps
|
|
53
58
|
*/
|
|
54
59
|
export default function GroupInfoWidget(inProps) {
|
|
60
|
+
var _a;
|
|
55
61
|
// PROPS
|
|
56
62
|
const props = useThemeProps({
|
|
57
63
|
props: inProps,
|
|
@@ -59,9 +65,36 @@ export default function GroupInfoWidget(inProps) {
|
|
|
59
65
|
});
|
|
60
66
|
const { className, group, groupId, onHeightChange, onStateChange } = props, rest = __rest(props, ["className", "group", "groupId", "onHeightChange", "onStateChange"]);
|
|
61
67
|
// HOOKS
|
|
62
|
-
const { scGroup } = useSCFetchGroup({ id: groupId, group });
|
|
68
|
+
const { scGroup, setSCGroup } = useSCFetchGroup({ id: groupId, group });
|
|
63
69
|
// INTL
|
|
64
70
|
const intl = useIntl();
|
|
71
|
+
// REFS
|
|
72
|
+
const updatesSubscription = useRef(null);
|
|
73
|
+
/**
|
|
74
|
+
* Subscriber for pubsub callback
|
|
75
|
+
*/
|
|
76
|
+
const onChangeGroupHandler = useCallback((_msg, data) => {
|
|
77
|
+
if (data && scGroup.id === data.id) {
|
|
78
|
+
setSCGroup(data);
|
|
79
|
+
}
|
|
80
|
+
}, [scGroup, setSCGroup]);
|
|
81
|
+
/**
|
|
82
|
+
* On mount, subscribe to receive groups updates (only edit)
|
|
83
|
+
*/
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (scGroup) {
|
|
86
|
+
updatesSubscription.current = PubSub.subscribe(`${SCTopicType.GROUP}.${SCEventType.EDIT}`, onChangeGroupHandler);
|
|
87
|
+
}
|
|
88
|
+
return () => {
|
|
89
|
+
updatesSubscription.current && PubSub.unsubscribe(updatesSubscription.current);
|
|
90
|
+
};
|
|
91
|
+
}, [scGroup]);
|
|
92
|
+
/**
|
|
93
|
+
* Loading group
|
|
94
|
+
*/
|
|
95
|
+
if (!scGroup) {
|
|
96
|
+
return React.createElement(GroupInfoWidgetSkeleton, null);
|
|
97
|
+
}
|
|
65
98
|
/**
|
|
66
99
|
* Renders root object
|
|
67
100
|
*/
|
|
@@ -73,25 +106,48 @@ export default function GroupInfoWidget(inProps) {
|
|
|
73
106
|
React.createElement(Typography, { component: "div", className: classes.privacy }, scGroup.privacy === SCGroupPrivacyType.PUBLIC ? (React.createElement(React.Fragment, null,
|
|
74
107
|
React.createElement(Typography, { className: classes.privacyTitle },
|
|
75
108
|
React.createElement(Icon, null, "public"),
|
|
76
|
-
React.createElement(FormattedMessage, { id: "ui.
|
|
109
|
+
React.createElement(FormattedMessage, { id: "ui.groupInfoWidget.privacy.public", defaultMessage: "ui.groupInfoWidget.privacy.public" })),
|
|
77
110
|
React.createElement(Typography, { variant: "body2" },
|
|
78
|
-
React.createElement(FormattedMessage, { id: "ui.
|
|
111
|
+
React.createElement(FormattedMessage, { id: "ui.groupInfoWidget.privacy.public.info", defaultMessage: "ui.groupInfoWidget.privacy.public.info", values: {
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
b: (chunks) => React.createElement("strong", null, chunks)
|
|
115
|
+
} })))) : (React.createElement(React.Fragment, null,
|
|
79
116
|
React.createElement(Typography, { className: classes.privacyTitle },
|
|
80
117
|
React.createElement(Icon, null, "private"),
|
|
81
|
-
React.createElement(FormattedMessage, { id: "ui.
|
|
118
|
+
React.createElement(FormattedMessage, { id: "ui.groupInfoWidget.privacy.private", defaultMessage: "ui.groupInfoWidget.privacy.private" })),
|
|
82
119
|
React.createElement(Typography, { variant: "body2" },
|
|
83
|
-
React.createElement(FormattedMessage, { id: "ui.
|
|
120
|
+
React.createElement(FormattedMessage, { id: "ui.groupInfoWidget.privacy.private.info", defaultMessage: "ui.groupInfoWidget.private.public.info", values: {
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
b: (chunks) => React.createElement("strong", null, chunks)
|
|
124
|
+
} }))))),
|
|
84
125
|
scGroup.privacy === SCGroupPrivacyType.PRIVATE && (React.createElement(Typography, { component: "div", className: classes.visibility }, scGroup.visible ? (React.createElement(React.Fragment, null,
|
|
85
126
|
React.createElement(Typography, { className: classes.visibilityTitle },
|
|
86
127
|
React.createElement(Icon, null, "visibility"),
|
|
87
128
|
React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.visible", defaultMessage: "ui.groupForm.visibility.visible" })),
|
|
88
129
|
React.createElement(Typography, { variant: "body2" },
|
|
89
|
-
React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.visible.info", defaultMessage: "ui.groupForm.visibility.visible.info", values: {
|
|
130
|
+
React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.visible.info", defaultMessage: "ui.groupForm.visibility.visible.info", values: {
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
132
|
+
// @ts-ignore
|
|
133
|
+
b: (chunks) => React.createElement("strong", null, chunks)
|
|
134
|
+
} })))) : (React.createElement(React.Fragment, null,
|
|
90
135
|
React.createElement(Typography, { className: classes.visibilityTitle },
|
|
91
136
|
React.createElement(Icon, null, "visibility_off"),
|
|
92
137
|
React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.hidden", defaultMessage: "ui.groupForm.visibility.hidden" })),
|
|
93
138
|
React.createElement(Typography, { variant: "body2" },
|
|
94
|
-
React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.hidden.info", defaultMessage: "ui.groupForm.visibility.hidden.info", values: {
|
|
139
|
+
React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.hidden.info", defaultMessage: "ui.groupForm.visibility.hidden.info", values: {
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
b: (chunks) => React.createElement("strong", null, chunks)
|
|
143
|
+
} })))))),
|
|
95
144
|
React.createElement(Typography, { variant: "body2", className: classes.date },
|
|
96
|
-
React.createElement(FormattedMessage, { id: "ui.groupInfoWidget.date", defaultMessage: "ui.groupInfoWidget.date", values: { date: intl.formatDate(scGroup.created_at, { day: 'numeric', year: 'numeric', month: 'long' }) } }))
|
|
145
|
+
React.createElement(FormattedMessage, { id: "ui.groupInfoWidget.date", defaultMessage: "ui.groupInfoWidget.date", values: { date: intl.formatDate(scGroup.created_at, { day: 'numeric', year: 'numeric', month: 'long' }) } })),
|
|
146
|
+
React.createElement(Typography, { variant: "body2", className: classes.admin },
|
|
147
|
+
React.createElement(FormattedMessage, { id: "ui.groupInfoWidget.admin", defaultMessage: "ui.groupInfoWidget.admin", values: {
|
|
148
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
b: (chunks) => React.createElement("strong", null, chunks)
|
|
151
|
+
} }),
|
|
152
|
+
React.createElement(User, { userId: (_a = scGroup === null || scGroup === void 0 ? void 0 : scGroup.managed_by) === null || _a === void 0 ? void 0 : _a.id, elevation: 0, actions: React.createElement(React.Fragment, null) })))));
|
|
97
153
|
}
|
|
@@ -13,6 +13,8 @@ import Autocomplete from '@mui/material/Autocomplete';
|
|
|
13
13
|
import User from '../User';
|
|
14
14
|
import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
15
15
|
import { Logger } from '@selfcommunity/utils';
|
|
16
|
+
import { SCEventType, SCTopicType } from '../../constants/PubSub';
|
|
17
|
+
import PubSub from 'pubsub-js';
|
|
16
18
|
const messages = defineMessages({
|
|
17
19
|
placeholder: {
|
|
18
20
|
id: 'ui.groupInviteButton.searchBar.placeholder',
|
|
@@ -88,12 +90,22 @@ export default function GroupInviteButton(inProps) {
|
|
|
88
90
|
const [list, setList] = useState([]);
|
|
89
91
|
const [loading, setLoading] = useState(false);
|
|
90
92
|
const [invited, setInvited] = useState([]);
|
|
93
|
+
/**
|
|
94
|
+
* Notify UI when a member is invited to a group
|
|
95
|
+
* @param group
|
|
96
|
+
* @param usersInvited
|
|
97
|
+
*/
|
|
98
|
+
function notifyChanges(group, usersInvited) {
|
|
99
|
+
if (group && usersInvited) {
|
|
100
|
+
PubSub.publish(`${SCTopicType.GROUP}.${SCEventType.INVITE_MEMBER}`, usersInvited);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
91
103
|
function convertToInvitedUsersObject(data) {
|
|
92
|
-
const
|
|
104
|
+
const invite_users = {};
|
|
93
105
|
data.forEach((user, index) => {
|
|
94
|
-
|
|
106
|
+
invite_users[`invite_users[${index}]`] = user.id;
|
|
95
107
|
});
|
|
96
|
-
return
|
|
108
|
+
return invite_users;
|
|
97
109
|
}
|
|
98
110
|
/**
|
|
99
111
|
* Memoized users invited ids
|
|
@@ -153,11 +165,13 @@ export default function GroupInviteButton(inProps) {
|
|
|
153
165
|
* If a value is entered in new message field, it fetches user suggested
|
|
154
166
|
*/
|
|
155
167
|
useEffect(() => {
|
|
156
|
-
if (
|
|
168
|
+
if (scGroup) {
|
|
157
169
|
fetchResults();
|
|
158
170
|
}
|
|
159
|
-
|
|
160
|
-
|
|
171
|
+
else {
|
|
172
|
+
fetchGeneralResults();
|
|
173
|
+
}
|
|
174
|
+
}, [value, scGroup]);
|
|
161
175
|
/**
|
|
162
176
|
* Handles dialog close
|
|
163
177
|
*/
|
|
@@ -180,6 +194,7 @@ export default function GroupInviteButton(inProps) {
|
|
|
180
194
|
setIsSending(false);
|
|
181
195
|
setOpen(false);
|
|
182
196
|
setInvited([]);
|
|
197
|
+
notifyChanges(scGroup, invited);
|
|
183
198
|
})
|
|
184
199
|
.catch((error) => {
|
|
185
200
|
setOpen(false);
|
|
@@ -223,6 +238,13 @@ export default function GroupInviteButton(inProps) {
|
|
|
223
238
|
setInvited(invited.filter((v) => v !== option));
|
|
224
239
|
setList((prev) => [...prev, option]);
|
|
225
240
|
};
|
|
241
|
+
const filterOptions = (options, { inputValue }) => {
|
|
242
|
+
return options.filter((option) => {
|
|
243
|
+
const usernameMatch = option.username.toLowerCase().includes(inputValue.toLowerCase());
|
|
244
|
+
const nameMatch = option.real_name.toLowerCase().includes(inputValue.toLowerCase());
|
|
245
|
+
return usernameMatch || nameMatch;
|
|
246
|
+
});
|
|
247
|
+
};
|
|
226
248
|
/**
|
|
227
249
|
* If in group edit mode and logged-in user is not also the group manager, the component is hidden.
|
|
228
250
|
// */
|
|
@@ -243,7 +265,7 @@ export default function GroupInviteButton(inProps) {
|
|
|
243
265
|
React.createElement(LoadingButton, { size: "small", color: "secondary", variant: "contained", onClick: handleSendInvitations, loading: isSending, disabled: !invited.length },
|
|
244
266
|
React.createElement(FormattedMessage, { id: "ui.groupInviteButton.dialog.button.end", defaultMessage: "ui.groupInviteButton.dialog.button.end" }))) },
|
|
245
267
|
React.createElement(Box, { className: classes.dialogContent },
|
|
246
|
-
React.createElement(Autocomplete, { className: classes.autocomplete, loading: loading, size: "small", multiple: true, freeSolo: true, disableClearable: true, options: suggested, onChange: handleChange, onInputChange: handleInputChange, inputValue: value, value: invited, getOptionLabel: (option) => (option ? option.username : '...'), isOptionEqualToValue: (option, value) => (option ? value.id === option.id : false), renderTags: () => null, renderOption: (props, option) => (React.createElement(Box, Object.assign({ component: "li" }, props),
|
|
268
|
+
React.createElement(Autocomplete, { className: classes.autocomplete, loading: loading, size: "small", multiple: true, freeSolo: true, disableClearable: true, options: suggested, onChange: handleChange, onInputChange: handleInputChange, inputValue: value, filterOptions: filterOptions, value: invited, getOptionLabel: (option) => (option ? option.username : '...'), isOptionEqualToValue: (option, value) => (option ? value.id === option.id : false), renderTags: () => null, renderOption: (props, option) => (React.createElement(Box, Object.assign({ component: "li" }, props),
|
|
247
269
|
React.createElement(Avatar, { alt: option.username, src: option.avatar }),
|
|
248
270
|
React.createElement(Typography, { ml: 1 }, option.username))), renderInput: (params) => (React.createElement(TextField, Object.assign({}, params, { variant: "outlined", placeholder: `${intl.formatMessage(messages.placeholder)}`, InputProps: Object.assign(Object.assign({}, params.InputProps), { className: classes.input, startAdornment: (React.createElement(React.Fragment, null,
|
|
249
271
|
React.createElement(InputAdornment, { position: "start" },
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { WidgetProps } from '../Widget';
|
|
2
|
+
import { SCGroupType } from '@selfcommunity/types';
|
|
3
|
+
import { CacheStrategies } from '@selfcommunity/utils';
|
|
4
|
+
import { BaseDialogProps } from '../../shared/BaseDialog';
|
|
5
|
+
import { VirtualScrollerItemProps } from '../../types/virtualScroller';
|
|
6
|
+
import { UserProps } from '../User';
|
|
7
|
+
export interface GroupInvitedWidgetProps extends VirtualScrollerItemProps, WidgetProps {
|
|
8
|
+
/**
|
|
9
|
+
* Group Object
|
|
10
|
+
* @default null
|
|
11
|
+
*/
|
|
12
|
+
group?: SCGroupType;
|
|
13
|
+
/**
|
|
14
|
+
* Id of the group
|
|
15
|
+
* @default null
|
|
16
|
+
*/
|
|
17
|
+
groupId?: number | string;
|
|
18
|
+
/**
|
|
19
|
+
* Limit the number of users to show
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
limit?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Caching strategies
|
|
25
|
+
* @default CacheStrategies.CACHE_FIRST
|
|
26
|
+
*/
|
|
27
|
+
cacheStrategy?: CacheStrategies;
|
|
28
|
+
/**
|
|
29
|
+
* Props to spread to single user object
|
|
30
|
+
* @default empty object
|
|
31
|
+
*/
|
|
32
|
+
UserProps?: UserProps;
|
|
33
|
+
/**
|
|
34
|
+
* Props to spread to followers users dialog
|
|
35
|
+
* @default {}
|
|
36
|
+
*/
|
|
37
|
+
DialogProps?: BaseDialogProps;
|
|
38
|
+
/**
|
|
39
|
+
* Other props
|
|
40
|
+
*/
|
|
41
|
+
[p: string]: any;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* > API documentation for the Community-JS Group Invited Widget component. Learn about the available props and the CSS API.
|
|
45
|
+
*
|
|
46
|
+
*
|
|
47
|
+
* This component renders the list of users who have been invited to join the specified group.
|
|
48
|
+
|
|
49
|
+
#### Import
|
|
50
|
+
|
|
51
|
+
```jsx
|
|
52
|
+
import {GroupInvitedWidget} from '@selfcommunity/react-ui';
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### Component Name
|
|
56
|
+
|
|
57
|
+
The name `SCGroupInvitedWidget` can be used when providing style overrides in the theme.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
#### CSS
|
|
61
|
+
|
|
62
|
+
|Rule Name|Global class|Description|
|
|
63
|
+
|---|---|---|
|
|
64
|
+
|root|.SCGroupInvitedWidget-root|Styles applied to the root element.|
|
|
65
|
+
|title|.SCGroupInvitedWidget-title|Styles applied to the title element.|
|
|
66
|
+
|noResults|.SCGroupInvitedWidget-no-results|Styles applied to no results section.|
|
|
67
|
+
|showMore|.SCGroupInvitedWidget-show-more|Styles applied to show more button element.|
|
|
68
|
+
|dialogRoot|.SCGroupInvitedWidget-dialog-root|Styles applied to the dialog root element.|
|
|
69
|
+
|endMessage|.SCGroupInvitedWidget-end-message|Styles applied to the end message element.|
|
|
70
|
+
|
|
71
|
+
* @param inProps
|
|
72
|
+
*/
|
|
73
|
+
export default function GroupInvitedWidget(inProps: GroupInvitedWidgetProps): JSX.Element;
|