@selfcommunity/react-ui 0.7.9-alpha.8 → 0.7.9-alpha.81
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 +6 -6
- package/lib/cjs/components/GroupHeader/GroupHeader.js +53 -12
- package/lib/cjs/components/GroupInfoWidget/GroupInfoWidget.js +63 -9
- package/lib/cjs/components/GroupInviteButton/GroupInviteButton.js +31 -9
- 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.d.ts +5 -0
- package/lib/cjs/components/GroupMembersButton/GroupMembersButton.js +8 -3
- package/lib/cjs/components/GroupMembersWidget/GroupMembersWidget.js +25 -4
- package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +12 -7
- package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.js +19 -9
- package/lib/cjs/components/GroupSettingsIconButton/GroupSettingsIconButton.d.ts +48 -0
- package/lib/cjs/components/GroupSettingsIconButton/GroupSettingsIconButton.js +151 -0
- package/lib/cjs/components/GroupSettingsIconButton/index.d.ts +3 -0
- package/lib/cjs/components/GroupSettingsIconButton/index.js +5 -0
- package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.d.ts +8 -3
- package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.js +30 -11
- 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 +9 -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 +78 -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 +31 -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 +6 -3
- package/lib/cjs/index.js +13 -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 +6 -6
- package/lib/esm/components/GroupHeader/GroupHeader.js +55 -14
- package/lib/esm/components/GroupInfoWidget/GroupInfoWidget.js +63 -9
- package/lib/esm/components/GroupInviteButton/GroupInviteButton.js +31 -9
- 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.d.ts +5 -0
- package/lib/esm/components/GroupMembersButton/GroupMembersButton.js +9 -4
- package/lib/esm/components/GroupMembersWidget/GroupMembersWidget.js +26 -5
- package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +12 -7
- package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.js +19 -9
- package/lib/esm/components/GroupSettingsIconButton/GroupSettingsIconButton.d.ts +48 -0
- package/lib/esm/components/GroupSettingsIconButton/GroupSettingsIconButton.js +148 -0
- package/lib/esm/components/GroupSettingsIconButton/index.d.ts +3 -0
- package/lib/esm/components/GroupSettingsIconButton/index.js +2 -0
- package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.d.ts +8 -3
- package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.js +30 -11
- 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 +10 -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 +75 -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 +31 -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 +6 -3
- package/lib/esm/index.js +6 -3
- 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 +9 -9
- package/lib/umd/871.js +0 -2
- /package/lib/umd/{871.js.LICENSE.txt → 311.js.LICENSE.txt} +0 -0
|
@@ -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
|
|
@@ -108,7 +120,7 @@ export default function GroupInviteButton(inProps) {
|
|
|
108
120
|
}, [invited]);
|
|
109
121
|
// HOOKS
|
|
110
122
|
const { scGroup } = useSCFetchGroup({ id: groupId, group });
|
|
111
|
-
const
|
|
123
|
+
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]);
|
|
112
124
|
// INTL
|
|
113
125
|
const intl = useIntl();
|
|
114
126
|
function fetchResults() {
|
|
@@ -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,10 +238,17 @@ 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
|
// */
|
|
229
|
-
if (group && !
|
|
251
|
+
if (group && !isGroupAdmin) {
|
|
230
252
|
return null;
|
|
231
253
|
}
|
|
232
254
|
/**
|
|
@@ -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;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import React, { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
import List from '@mui/material/List';
|
|
5
|
+
import { Button, CardContent, ListItem, Typography, useMediaQuery, useTheme } from '@mui/material';
|
|
6
|
+
import Widget from '../Widget';
|
|
7
|
+
import { http, Endpoints, GroupService } from '@selfcommunity/api-services';
|
|
8
|
+
import { CacheStrategies, isInteger, Logger } from '@selfcommunity/utils';
|
|
9
|
+
import { SCCache, SCPreferences, useSCFetchGroup, useSCPreferences, useSCUser } from '@selfcommunity/react-core';
|
|
10
|
+
import { actionWidgetTypes, dataWidgetReducer, stateWidgetInitializer } from '../../utils/widget';
|
|
11
|
+
import Skeleton from './Skeleton';
|
|
12
|
+
import { FormattedMessage } from 'react-intl';
|
|
13
|
+
import classNames from 'classnames';
|
|
14
|
+
import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
15
|
+
import BaseDialog from '../../shared/BaseDialog';
|
|
16
|
+
import InfiniteScroll from '../../shared/InfiniteScroll';
|
|
17
|
+
import { useThemeProps } from '@mui/system';
|
|
18
|
+
import HiddenPlaceholder from '../../shared/HiddenPlaceholder';
|
|
19
|
+
import { PREFIX } from './constants';
|
|
20
|
+
import User, { UserSkeleton } from '../User';
|
|
21
|
+
import PubSub from 'pubsub-js';
|
|
22
|
+
import { SCEventType, SCTopicType } from '../../constants/PubSub';
|
|
23
|
+
const classes = {
|
|
24
|
+
root: `${PREFIX}-root`,
|
|
25
|
+
title: `${PREFIX}-title`,
|
|
26
|
+
noResults: `${PREFIX}-no-results`,
|
|
27
|
+
showMore: `${PREFIX}-show-more`,
|
|
28
|
+
dialogRoot: `${PREFIX}-dialog-root`,
|
|
29
|
+
endMessage: `${PREFIX}-end-message`
|
|
30
|
+
};
|
|
31
|
+
const Root = styled(Widget, {
|
|
32
|
+
name: PREFIX,
|
|
33
|
+
slot: 'Root'
|
|
34
|
+
})(() => ({}));
|
|
35
|
+
const DialogRoot = styled(BaseDialog, {
|
|
36
|
+
name: PREFIX,
|
|
37
|
+
slot: 'DialogRoot'
|
|
38
|
+
})(() => ({}));
|
|
39
|
+
/**
|
|
40
|
+
* > API documentation for the Community-JS Group Invited Widget component. Learn about the available props and the CSS API.
|
|
41
|
+
*
|
|
42
|
+
*
|
|
43
|
+
* This component renders the list of users who have been invited to join the specified group.
|
|
44
|
+
|
|
45
|
+
#### Import
|
|
46
|
+
|
|
47
|
+
```jsx
|
|
48
|
+
import {GroupInvitedWidget} from '@selfcommunity/react-ui';
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
#### Component Name
|
|
52
|
+
|
|
53
|
+
The name `SCGroupInvitedWidget` can be used when providing style overrides in the theme.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
#### CSS
|
|
57
|
+
|
|
58
|
+
|Rule Name|Global class|Description|
|
|
59
|
+
|---|---|---|
|
|
60
|
+
|root|.SCGroupInvitedWidget-root|Styles applied to the root element.|
|
|
61
|
+
|title|.SCGroupInvitedWidget-title|Styles applied to the title element.|
|
|
62
|
+
|noResults|.SCGroupInvitedWidget-no-results|Styles applied to no results section.|
|
|
63
|
+
|showMore|.SCGroupInvitedWidget-show-more|Styles applied to show more button element.|
|
|
64
|
+
|dialogRoot|.SCGroupInvitedWidget-dialog-root|Styles applied to the dialog root element.|
|
|
65
|
+
|endMessage|.SCGroupInvitedWidget-end-message|Styles applied to the end message element.|
|
|
66
|
+
|
|
67
|
+
* @param inProps
|
|
68
|
+
*/
|
|
69
|
+
export default function GroupInvitedWidget(inProps) {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
// PROPS
|
|
72
|
+
const props = useThemeProps({
|
|
73
|
+
props: inProps,
|
|
74
|
+
name: PREFIX
|
|
75
|
+
});
|
|
76
|
+
const { groupId, group, limit = 5, className, cacheStrategy = CacheStrategies.NETWORK_ONLY, onHeightChange, onStateChange, UserProps = {}, DialogProps = {} } = props, rest = __rest(props, ["groupId", "group", "limit", "className", "cacheStrategy", "onHeightChange", "onStateChange", "UserProps", "DialogProps"]);
|
|
77
|
+
// STATE
|
|
78
|
+
const [state, dispatch] = useReducer(dataWidgetReducer, {
|
|
79
|
+
isLoadingNext: false,
|
|
80
|
+
next: null,
|
|
81
|
+
cacheKey: SCCache.getWidgetStateCacheKey(SCCache.GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY, isInteger(groupId) ? groupId : group.id),
|
|
82
|
+
cacheStrategy,
|
|
83
|
+
visibleItems: limit
|
|
84
|
+
}, stateWidgetInitializer);
|
|
85
|
+
const [openDialog, setOpenDialog] = useState(false);
|
|
86
|
+
// CONTEXT
|
|
87
|
+
const scUserContext = useSCUser();
|
|
88
|
+
const scPreferencesContext = useSCPreferences();
|
|
89
|
+
const { scGroup } = useSCFetchGroup({ id: groupId, group });
|
|
90
|
+
// MEMO
|
|
91
|
+
const contentAvailability = useMemo(() => SCPreferences.CONFIGURATIONS_CONTENT_AVAILABILITY in scPreferencesContext.preferences &&
|
|
92
|
+
scPreferencesContext.preferences[SCPreferences.CONFIGURATIONS_CONTENT_AVAILABILITY].value, [scPreferencesContext.preferences]);
|
|
93
|
+
// HOOKS
|
|
94
|
+
const theme = useTheme();
|
|
95
|
+
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
|
|
96
|
+
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]);
|
|
97
|
+
// REFS
|
|
98
|
+
const updatesSubscription = useRef(null);
|
|
99
|
+
/**
|
|
100
|
+
* Initialize component
|
|
101
|
+
* Fetch data only if the component is not initialized and it is not loading data
|
|
102
|
+
*/
|
|
103
|
+
const _initComponent = useMemo(() => () => {
|
|
104
|
+
if (!state.initialized && !state.isLoadingNext) {
|
|
105
|
+
dispatch({ type: actionWidgetTypes.LOADING_NEXT });
|
|
106
|
+
GroupService.getGroupInvitedUsers(scGroup.id, { limit })
|
|
107
|
+
.then((payload) => {
|
|
108
|
+
dispatch({ type: actionWidgetTypes.LOAD_NEXT_SUCCESS, payload: Object.assign(Object.assign({}, payload), { initialized: true }) });
|
|
109
|
+
})
|
|
110
|
+
.catch((error) => {
|
|
111
|
+
dispatch({ type: actionWidgetTypes.LOAD_NEXT_FAILURE, payload: { errorLoadNext: error } });
|
|
112
|
+
Logger.error(SCOPE_SC_UI, error);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}, [state.isLoadingNext, state.initialized, scGroup, limit, dispatch]);
|
|
116
|
+
// EFFECTS
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
var _a;
|
|
119
|
+
let _t;
|
|
120
|
+
if ((contentAvailability || (!contentAvailability && ((_a = scUserContext.user) === null || _a === void 0 ? void 0 : _a.id))) && scGroup && scUserContext.user !== undefined) {
|
|
121
|
+
_t = setTimeout(_initComponent);
|
|
122
|
+
return () => {
|
|
123
|
+
_t && clearTimeout(_t);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}, [scUserContext.user, contentAvailability, scGroup]);
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
if (openDialog && state.next && state.results.length === limit && state.initialized) {
|
|
129
|
+
dispatch({ type: actionWidgetTypes.LOADING_NEXT });
|
|
130
|
+
GroupService.getGroupInvitedUsers(scGroup.id, { offset: limit, limit: 10 })
|
|
131
|
+
.then((payload) => {
|
|
132
|
+
dispatch({ type: actionWidgetTypes.LOAD_NEXT_SUCCESS, payload: payload });
|
|
133
|
+
})
|
|
134
|
+
.catch((error) => {
|
|
135
|
+
dispatch({ type: actionWidgetTypes.LOAD_NEXT_FAILURE, payload: { errorLoadNext: error } });
|
|
136
|
+
Logger.error(SCOPE_SC_UI, error);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}, [openDialog, state.next, state.results.length, state.initialized, limit]);
|
|
140
|
+
/**
|
|
141
|
+
* Virtual feed update
|
|
142
|
+
*/
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
onHeightChange && onHeightChange();
|
|
145
|
+
}, [state.results]);
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
if (!scGroup || (!contentAvailability && !scUserContext.user)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
else if (cacheStrategy === CacheStrategies.NETWORK_ONLY) {
|
|
151
|
+
onStateChange && onStateChange({ cacheStrategy: CacheStrategies.CACHE_FIRST });
|
|
152
|
+
}
|
|
153
|
+
}, [scUserContext.user, scGroup, contentAvailability]);
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (!scGroup || !scUserContext.user || !state.initialized) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
}, []);
|
|
159
|
+
/**
|
|
160
|
+
* Subscriber for pubsub callback
|
|
161
|
+
*/
|
|
162
|
+
const onChangeGroupHandler = useCallback((_msg, newInvited) => {
|
|
163
|
+
dispatch({
|
|
164
|
+
type: actionWidgetTypes.SET_RESULTS,
|
|
165
|
+
payload: { results: [...state.results, ...newInvited], count: state.count + newInvited.length }
|
|
166
|
+
});
|
|
167
|
+
}, [scGroup, dispatch, state.results]);
|
|
168
|
+
/**
|
|
169
|
+
* On mount, subscribe to receive groups updates (only edit)
|
|
170
|
+
*/
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
if (scGroup && state.results) {
|
|
173
|
+
updatesSubscription.current = PubSub.subscribe(`${SCTopicType.GROUP}.${SCEventType.INVITE_MEMBER}`, onChangeGroupHandler);
|
|
174
|
+
}
|
|
175
|
+
return () => {
|
|
176
|
+
updatesSubscription.current && PubSub.unsubscribe(updatesSubscription.current);
|
|
177
|
+
};
|
|
178
|
+
}, [scGroup, state.results]);
|
|
179
|
+
// HANDLERS
|
|
180
|
+
const handleNext = useMemo(() => () => {
|
|
181
|
+
dispatch({ type: actionWidgetTypes.LOADING_NEXT });
|
|
182
|
+
http
|
|
183
|
+
.request({
|
|
184
|
+
url: state.next,
|
|
185
|
+
method: Endpoints.getGroupInvitedUsers.method
|
|
186
|
+
})
|
|
187
|
+
.then((res) => {
|
|
188
|
+
dispatch({ type: actionWidgetTypes.LOAD_NEXT_SUCCESS, payload: res.data });
|
|
189
|
+
});
|
|
190
|
+
}, [dispatch, state.next, state.isLoadingNext, state.initialized]);
|
|
191
|
+
const handleToggleDialogOpen = () => {
|
|
192
|
+
setOpenDialog((prev) => !prev);
|
|
193
|
+
};
|
|
194
|
+
// RENDER
|
|
195
|
+
if ((!state.count && state.initialized) || !contentAvailability || !scGroup || !state.count || !state.results.length || !isGroupAdmin) {
|
|
196
|
+
return React.createElement(HiddenPlaceholder, null);
|
|
197
|
+
}
|
|
198
|
+
if (!state.initialized) {
|
|
199
|
+
return React.createElement(Skeleton, null);
|
|
200
|
+
}
|
|
201
|
+
const content = (React.createElement(CardContent, null,
|
|
202
|
+
React.createElement(Typography, { className: classes.title, variant: "h5" },
|
|
203
|
+
React.createElement(FormattedMessage, { id: "ui.groupInvitedWidget.title", defaultMessage: "ui.groupInvitedWidget.title" })),
|
|
204
|
+
React.createElement(React.Fragment, null,
|
|
205
|
+
React.createElement(List, null, state.results.slice(0, state.visibleItems).map((user) => (React.createElement(ListItem, { key: user.id },
|
|
206
|
+
React.createElement(User, { elevation: 0, actions: React.createElement(Button, { disabled: true, size: "small" },
|
|
207
|
+
React.createElement(FormattedMessage, { id: "ui.groupInvitedWidget.status", defaultMessage: "ui.groupInvitedWidget.status" })), user: user, userId: user.id }))))),
|
|
208
|
+
state.count > state.visibleItems && (React.createElement(Button, { className: classes.showMore, onClick: handleToggleDialogOpen },
|
|
209
|
+
React.createElement(FormattedMessage, { id: "ui.groupInvitedWidget.button.showMore", defaultMessage: "ui.groupInvitedWidget.button.showMore" })))),
|
|
210
|
+
openDialog && (React.createElement(DialogRoot, Object.assign({ className: classes.dialogRoot, title: React.createElement(FormattedMessage, { defaultMessage: "ui.groupInvitedWidget.dialogTitle", id: "ui.groupInvitedWidget.dialogTitle", values: { total: (_b = state === null || state === void 0 ? void 0 : state.results) === null || _b === void 0 ? void 0 : _b.length } }), onClose: handleToggleDialogOpen, open: openDialog }, DialogProps),
|
|
211
|
+
React.createElement(InfiniteScroll, { dataLength: state.results.length, next: handleNext, hasMoreNext: Boolean(state.next), loaderNext: React.createElement(UserSkeleton, Object.assign({ elevation: 0 }, UserProps)), height: isMobile ? '100%' : 400, endMessage: React.createElement(Typography, { className: classes.endMessage },
|
|
212
|
+
React.createElement(FormattedMessage, { id: "ui.groupInvitedWidget.noMoreResults", defaultMessage: "ui.groupInvitedWidget.noMoreResults" })) },
|
|
213
|
+
React.createElement(List, null, state.results.map((user) => (React.createElement(ListItem, { key: user.id },
|
|
214
|
+
React.createElement(User, { elevation: 0, actions: React.createElement(Button, { disabled: true, size: "small" },
|
|
215
|
+
React.createElement(FormattedMessage, { id: "ui.groupInvitedWidget.status", defaultMessage: "ui.groupInvitedWidget.status" })), user: user, userId: user.id }))))))))));
|
|
216
|
+
return (React.createElement(Root, Object.assign({ className: classNames(classes.root, className) }, rest), content));
|
|
217
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { WidgetProps } from '../Widget';
|
|
2
|
+
/**
|
|
3
|
+
* > API documentation for the Community-JS Group Invited Widget Skeleton component. Learn about the available props and the CSS API.
|
|
4
|
+
|
|
5
|
+
#### Import
|
|
6
|
+
|
|
7
|
+
```jsx
|
|
8
|
+
import {GroupInvitedWidgetSkeleton} from '@selfcommunity/react-ui';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
#### Component Name
|
|
12
|
+
|
|
13
|
+
The name `SCGroupInvitedWidget-skeleton-root` can be used when providing style overrides in the theme.
|
|
14
|
+
|
|
15
|
+
#### CSS
|
|
16
|
+
|
|
17
|
+
|Rule Name|Global class|Description|
|
|
18
|
+
|---|---|---|
|
|
19
|
+
|root|.SCGroupInvitedWidget-skeleton-root|Styles applied to the root element.|
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export default function GroupInvitedWidgetSkeleton(props: WidgetProps): JSX.Element;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CategoryTrendingPeopleWidgetSkeleton } from '../CategoryTrendingUsersWidget';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
import { PREFIX } from './constants';
|
|
5
|
+
const classes = {
|
|
6
|
+
root: `${PREFIX}-skeleton-root`
|
|
7
|
+
};
|
|
8
|
+
const Root = styled(CategoryTrendingPeopleWidgetSkeleton, {
|
|
9
|
+
name: PREFIX,
|
|
10
|
+
slot: 'SkeletonRoot'
|
|
11
|
+
})(() => ({}));
|
|
12
|
+
/**
|
|
13
|
+
* > API documentation for the Community-JS Group Invited Widget Skeleton component. Learn about the available props and the CSS API.
|
|
14
|
+
|
|
15
|
+
#### Import
|
|
16
|
+
|
|
17
|
+
```jsx
|
|
18
|
+
import {GroupInvitedWidgetSkeleton} from '@selfcommunity/react-ui';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
#### Component Name
|
|
22
|
+
|
|
23
|
+
The name `SCGroupInvitedWidget-skeleton-root` can be used when providing style overrides in the theme.
|
|
24
|
+
|
|
25
|
+
#### CSS
|
|
26
|
+
|
|
27
|
+
|Rule Name|Global class|Description|
|
|
28
|
+
|---|---|---|
|
|
29
|
+
|root|.SCGroupInvitedWidget-skeleton-root|Styles applied to the root element.|
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
export default function GroupInvitedWidgetSkeleton(props) {
|
|
33
|
+
return React.createElement(Root, Object.assign({ className: classes.root }, props));
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PREFIX = "SCGroupInvitedWidget";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PREFIX = 'SCGroupInvitedWidget';
|
|
@@ -17,6 +17,11 @@ export interface GroupMembersButtonProps extends Pick<ButtonProps, Exclude<keyof
|
|
|
17
17
|
* @default {}
|
|
18
18
|
*/
|
|
19
19
|
DialogProps?: BaseDialogProps;
|
|
20
|
+
/**
|
|
21
|
+
* Hides this component
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
autoHide?: boolean;
|
|
20
25
|
/**
|
|
21
26
|
* Any other properties
|
|
22
27
|
*/
|
|
@@ -6,8 +6,9 @@ import BaseDialog from '../../shared/BaseDialog';
|
|
|
6
6
|
import { FormattedMessage } from 'react-intl';
|
|
7
7
|
import InfiniteScroll from '../../shared/InfiniteScroll';
|
|
8
8
|
import User, { UserSkeleton } from '../User';
|
|
9
|
-
import {
|
|
9
|
+
import { Endpoints, GroupService, http } from '@selfcommunity/api-services';
|
|
10
10
|
import { useSCFetchGroup } from '@selfcommunity/react-core';
|
|
11
|
+
import { SCGroupPrivacyType, SCGroupSubscriptionStatusType } from '@selfcommunity/types';
|
|
11
12
|
import AvatarGroupSkeleton from '../Skeleton/AvatarGroupSkeleton';
|
|
12
13
|
import classNames from 'classnames';
|
|
13
14
|
import { useThemeProps } from '@mui/system';
|
|
@@ -58,7 +59,7 @@ export default function GroupMembersButton(inProps) {
|
|
|
58
59
|
props: inProps,
|
|
59
60
|
name: PREFIX
|
|
60
61
|
});
|
|
61
|
-
const { className, groupId, group, DialogProps = {} } = props, rest = __rest(props, ["className", "groupId", "group", "DialogProps"]);
|
|
62
|
+
const { className, groupId, group, DialogProps = {}, autoHide = false } = props, rest = __rest(props, ["className", "groupId", "group", "DialogProps", "autoHide"]);
|
|
62
63
|
// STATE
|
|
63
64
|
const [loading, setLoading] = useState(true);
|
|
64
65
|
const [next, setNext] = useState(null);
|
|
@@ -69,7 +70,11 @@ export default function GroupMembersButton(inProps) {
|
|
|
69
70
|
const { scGroup } = useSCFetchGroup({ id: groupId, group });
|
|
70
71
|
// FETCH FIRST FOLLOWERS
|
|
71
72
|
useDeepCompareEffectNoCheck(() => {
|
|
72
|
-
if (!scGroup
|
|
73
|
+
if (!scGroup ||
|
|
74
|
+
(scGroup &&
|
|
75
|
+
scGroup.privacy !== SCGroupPrivacyType.PUBLIC &&
|
|
76
|
+
scGroup.subscription_status !== SCGroupSubscriptionStatusType.SUBSCRIBED &&
|
|
77
|
+
autoHide)) {
|
|
73
78
|
return;
|
|
74
79
|
}
|
|
75
80
|
if (members.length === 0) {
|
|
@@ -128,5 +133,5 @@ export default function GroupMembersButton(inProps) {
|
|
|
128
133
|
React.createElement(InfiniteScroll, { dataLength: members.length, next: fetchMembers, hasMoreNext: next !== null || loading, loaderNext: React.createElement(UserSkeleton, { elevation: 0 }), height: isMobile ? '100%' : 400, endMessage: React.createElement(Typography, { className: classes.endMessage },
|
|
129
134
|
React.createElement(FormattedMessage, { id: "ui.groupMembersButton.noOtherMembers", defaultMessage: "ui.groupMembersButton.noOtherMembers" })) },
|
|
130
135
|
React.createElement(List, null, members.map((member) => (React.createElement(ListItem, { key: member.id },
|
|
131
|
-
React.createElement(User, { elevation: 0, user: member }))))))))));
|
|
136
|
+
React.createElement(User, { elevation: 0, user: member, onClick: handleToggleDialogOpen }))))))))));
|
|
132
137
|
}
|
|
@@ -6,7 +6,7 @@ import { Button, CardActions, CardContent, ListItem, Typography, useMediaQuery,
|
|
|
6
6
|
import Widget from '../Widget';
|
|
7
7
|
import { http, Endpoints, GroupService } from '@selfcommunity/api-services';
|
|
8
8
|
import { CacheStrategies, isInteger, Logger } from '@selfcommunity/utils';
|
|
9
|
-
import { SCCache, SCPreferences, useSCFetchGroup, useSCPreferences, useSCUser } from '@selfcommunity/react-core';
|
|
9
|
+
import { Link, SCCache, SCPreferences, SCRoutes, useSCFetchGroup, useSCPreferences, useSCRouting, useSCUser } from '@selfcommunity/react-core';
|
|
10
10
|
import { actionWidgetTypes, dataWidgetReducer, stateWidgetInitializer } from '../../utils/widget';
|
|
11
11
|
import Skeleton from './Skeleton';
|
|
12
12
|
import { FormattedMessage } from 'react-intl';
|
|
@@ -19,6 +19,7 @@ import HiddenPlaceholder from '../../shared/HiddenPlaceholder';
|
|
|
19
19
|
import { PREFIX } from './constants';
|
|
20
20
|
import User, { UserSkeleton } from '../User';
|
|
21
21
|
import GroupInviteButton from '../GroupInviteButton';
|
|
22
|
+
import GroupSettingsIconButton from '../GroupSettingsIconButton';
|
|
22
23
|
const classes = {
|
|
23
24
|
root: `${PREFIX}-root`,
|
|
24
25
|
title: `${PREFIX}-title`,
|
|
@@ -68,6 +69,7 @@ const DialogRoot = styled(BaseDialog, {
|
|
|
68
69
|
* @param inProps
|
|
69
70
|
*/
|
|
70
71
|
export default function GroupMembersWidget(inProps) {
|
|
72
|
+
var _a;
|
|
71
73
|
// PROPS
|
|
72
74
|
const props = useThemeProps({
|
|
73
75
|
props: inProps,
|
|
@@ -85,8 +87,11 @@ export default function GroupMembersWidget(inProps) {
|
|
|
85
87
|
const [openDialog, setOpenDialog] = useState(false);
|
|
86
88
|
// CONTEXT
|
|
87
89
|
const scUserContext = useSCUser();
|
|
90
|
+
const scRoutingContext = useSCRouting();
|
|
88
91
|
const scPreferencesContext = useSCPreferences();
|
|
89
92
|
const { scGroup } = useSCFetchGroup({ id: groupId, group });
|
|
93
|
+
// CONST
|
|
94
|
+
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]);
|
|
90
95
|
// MEMO
|
|
91
96
|
const contentAvailability = useMemo(() => SCPreferences.CONFIGURATIONS_CONTENT_AVAILABILITY in scPreferencesContext.preferences &&
|
|
92
97
|
scPreferencesContext.preferences[SCPreferences.CONFIGURATIONS_CONTENT_AVAILABILITY].value, [scPreferencesContext.preferences]);
|
|
@@ -168,6 +173,14 @@ export default function GroupMembersWidget(inProps) {
|
|
|
168
173
|
const handleToggleDialogOpen = () => {
|
|
169
174
|
setOpenDialog((prev) => !prev);
|
|
170
175
|
};
|
|
176
|
+
const handleRefresh = useMemo(() => (userId) => {
|
|
177
|
+
const newMembers = [...state.results];
|
|
178
|
+
const _updated = newMembers.filter((u) => u.id !== userId);
|
|
179
|
+
dispatch({
|
|
180
|
+
type: actionWidgetTypes.SET_RESULTS,
|
|
181
|
+
payload: { results: newMembers.length > 1 ? _updated : [] }
|
|
182
|
+
});
|
|
183
|
+
}, [dispatch, state.count, state.results]);
|
|
171
184
|
// RENDER
|
|
172
185
|
if ((autoHide && !state.count && state.initialized) || (!contentAvailability && !scUserContext.user) || !scGroup) {
|
|
173
186
|
return React.createElement(HiddenPlaceholder, null);
|
|
@@ -181,15 +194,23 @@ export default function GroupMembersWidget(inProps) {
|
|
|
181
194
|
React.createElement(FormattedMessage, { id: "ui.groupMembersWidget.title", defaultMessage: "ui.groupMembersWidget.title" })),
|
|
182
195
|
!state.count ? (React.createElement(Typography, { className: classes.noResults, variant: "body2" },
|
|
183
196
|
React.createElement(FormattedMessage, { id: "ui.groupMembersWidget.subtitle.noResults", defaultMessage: "" }))) : (React.createElement(React.Fragment, null,
|
|
184
|
-
React.createElement(List, null, state.results.slice(0, state.visibleItems).map((user) =>
|
|
185
|
-
|
|
197
|
+
React.createElement(List, null, state.results.slice(0, state.visibleItems).map((user) => {
|
|
198
|
+
var _a, _b;
|
|
199
|
+
return (React.createElement(ListItem, { key: user.id },
|
|
200
|
+
React.createElement(User, { elevation: 0, actions: isGroupAdmin ? (React.createElement(GroupSettingsIconButton, { group: scGroup, user: user, onRemoveSuccess: () => handleRefresh(user.id) })) : ((_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.id) !== user.id ? (React.createElement(Button, { size: "small", variant: "outlined", component: Link, to: scRoutingContext.url(SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, user) },
|
|
201
|
+
React.createElement(FormattedMessage, { id: "ui.groupSettingsIconButton.item.message", defaultMessage: "ui.groupSettingsIconButton.item.message" }))) : null, isGroupAdmin: ((_b = scGroup === null || scGroup === void 0 ? void 0 : scGroup.managed_by) === null || _b === void 0 ? void 0 : _b.id) === user.id, user: user, userId: user.id })));
|
|
202
|
+
})),
|
|
186
203
|
state.count > state.visibleItems && (React.createElement(Button, { className: classes.showMore, onClick: handleToggleDialogOpen },
|
|
187
204
|
React.createElement(FormattedMessage, { id: "ui.groupMembersWidget.button.showMore", defaultMessage: "ui.groupMembersWidget.button.showMore" }))))),
|
|
188
205
|
openDialog && (React.createElement(DialogRoot, Object.assign({ className: classes.dialogRoot, title: React.createElement(FormattedMessage, { defaultMessage: "ui.groupMembersWidget.dialogTitle", id: "ui.groupMembersWidget.dialogTitle", values: { total: scGroup.subscribers_counter } }), onClose: handleToggleDialogOpen, open: openDialog }, DialogProps),
|
|
189
206
|
React.createElement(InfiniteScroll, { dataLength: state.results.length, next: handleNext, hasMoreNext: Boolean(state.next), loaderNext: React.createElement(UserSkeleton, Object.assign({ elevation: 0 }, UserProps)), height: isMobile ? '100%' : 400, endMessage: React.createElement(Typography, { className: classes.endMessage },
|
|
190
207
|
React.createElement(FormattedMessage, { id: "ui.groupMembersWidget.noMoreResults", defaultMessage: "ui.groupMembersWidget.noMoreResults" })) },
|
|
191
|
-
React.createElement(List, null, state.results.map((user) =>
|
|
192
|
-
|
|
208
|
+
React.createElement(List, null, state.results.map((user) => {
|
|
209
|
+
var _a, _b;
|
|
210
|
+
return (React.createElement(ListItem, { key: user.id },
|
|
211
|
+
React.createElement(User, { elevation: 0, actions: isGroupAdmin ? (React.createElement(GroupSettingsIconButton, { group: scGroup, user: user, onRemoveSuccess: () => handleRefresh(user.id) })) : ((_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.id) !== user.id ? (React.createElement(Button, { size: "small", variant: "outlined", component: Link, to: scRoutingContext.url(SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, user) },
|
|
212
|
+
React.createElement(FormattedMessage, { id: "ui.groupSettingsIconButton.item.message", defaultMessage: "ui.groupSettingsIconButton.item.message" }))) : null, isGroupAdmin: ((_b = scGroup === null || scGroup === void 0 ? void 0 : scGroup.managed_by) === null || _b === void 0 ? void 0 : _b.id) === user.id, user: user, userId: user.id })));
|
|
213
|
+
})))))),
|
|
193
214
|
React.createElement(CardActions, { className: classes.actions },
|
|
194
215
|
React.createElement(GroupInviteButton, { groupId: scGroup === null || scGroup === void 0 ? void 0 : scGroup.id, group: scGroup }))));
|
|
195
216
|
return (React.createElement(Root, Object.assign({ className: classNames(classes.root, className) }, rest), content));
|
|
@@ -4,6 +4,7 @@ import { CacheStrategies } from '@selfcommunity/utils';
|
|
|
4
4
|
import { BaseDialogProps } from '../../shared/BaseDialog';
|
|
5
5
|
import { VirtualScrollerItemProps } from '../../types/virtualScroller';
|
|
6
6
|
import { UserProps } from '../User';
|
|
7
|
+
import { GroupSubscribeButtonProps } from '../GroupSubscribeButton';
|
|
7
8
|
export interface GroupRequestsWidgetProps extends VirtualScrollerItemProps, WidgetProps {
|
|
8
9
|
/**
|
|
9
10
|
* Group Object
|
|
@@ -15,11 +16,6 @@ export interface GroupRequestsWidgetProps extends VirtualScrollerItemProps, Widg
|
|
|
15
16
|
* @default null
|
|
16
17
|
*/
|
|
17
18
|
groupId?: number | string;
|
|
18
|
-
/**
|
|
19
|
-
* Hides this component
|
|
20
|
-
* @default false
|
|
21
|
-
*/
|
|
22
|
-
autoHide?: boolean;
|
|
23
19
|
/**
|
|
24
20
|
* Limit the number of users to show
|
|
25
21
|
* @default false
|
|
@@ -40,6 +36,16 @@ export interface GroupRequestsWidgetProps extends VirtualScrollerItemProps, Widg
|
|
|
40
36
|
* @default {}
|
|
41
37
|
*/
|
|
42
38
|
DialogProps?: BaseDialogProps;
|
|
39
|
+
/**
|
|
40
|
+
* Props to spread to group subscribe button component
|
|
41
|
+
* @default {}
|
|
42
|
+
*/
|
|
43
|
+
GroupSubscribeButtonProps?: GroupSubscribeButtonProps;
|
|
44
|
+
/**
|
|
45
|
+
* onSubscribeAction callback
|
|
46
|
+
* @param user
|
|
47
|
+
*/
|
|
48
|
+
onSubscribeActon?: (userId: number | string) => any;
|
|
43
49
|
/**
|
|
44
50
|
* Other props
|
|
45
51
|
*/
|
|
@@ -49,8 +55,7 @@ export interface GroupRequestsWidgetProps extends VirtualScrollerItemProps, Widg
|
|
|
49
55
|
* > API documentation for the Community-JS Group Requests Widget component. Learn about the available props and the CSS API.
|
|
50
56
|
*
|
|
51
57
|
*
|
|
52
|
-
* This component
|
|
53
|
-
* Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/GroupRequests)
|
|
58
|
+
* This component displays the list of users who have requested access to the specified group.
|
|
54
59
|
|
|
55
60
|
#### Import
|
|
56
61
|
|