@selfcommunity/react-ui 0.7.9-alpha.0 → 0.7.9-alpha.2
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/ChangeGroupCover/ChangeGroupCover.d.ts +55 -0
- package/lib/cjs/components/ChangeGroupCover/ChangeGroupCover.js +117 -0
- package/lib/cjs/components/ChangeGroupCover/constants.d.ts +1 -0
- package/lib/cjs/components/ChangeGroupCover/constants.js +4 -0
- package/lib/cjs/components/ChangeGroupCover/index.d.ts +3 -0
- package/lib/cjs/components/ChangeGroupCover/index.js +5 -0
- package/lib/cjs/components/ChangeGroupPicture/ChangeGroupPicture.d.ts +57 -0
- package/lib/cjs/components/ChangeGroupPicture/ChangeGroupPicture.js +117 -0
- package/lib/cjs/components/ChangeGroupPicture/constants.d.ts +1 -0
- package/lib/cjs/components/ChangeGroupPicture/constants.js +4 -0
- package/lib/cjs/components/ChangeGroupPicture/index.d.ts +3 -0
- package/lib/cjs/components/ChangeGroupPicture/index.js +5 -0
- package/lib/cjs/components/CreateGroup/CreateGroup.d.ts +48 -0
- package/lib/cjs/components/CreateGroup/CreateGroup.js +187 -0
- package/lib/cjs/components/CreateGroup/constants.d.ts +1 -0
- package/lib/cjs/components/CreateGroup/constants.js +4 -0
- package/lib/cjs/components/CreateGroup/index.d.ts +3 -0
- package/lib/cjs/components/CreateGroup/index.js +5 -0
- package/lib/cjs/components/CreateGroupButton/CreateGroupButton.d.ts +38 -0
- package/lib/cjs/components/CreateGroupButton/CreateGroupButton.js +73 -0
- package/lib/cjs/components/CreateGroupButton/index.d.ts +3 -0
- package/lib/cjs/components/CreateGroupButton/index.js +5 -0
- package/lib/cjs/components/Group/Group.d.ts +67 -0
- package/lib/cjs/components/Group/Group.js +96 -0
- package/lib/cjs/components/Group/Skeleton.d.ts +22 -0
- package/lib/cjs/components/Group/Skeleton.js +42 -0
- package/lib/cjs/components/Group/constants.d.ts +1 -0
- package/lib/cjs/components/Group/constants.js +4 -0
- package/lib/cjs/components/Group/index.d.ts +4 -0
- package/lib/cjs/components/Group/index.js +8 -0
- package/lib/cjs/components/GroupHeader/GroupHeader.d.ts +83 -0
- package/lib/cjs/components/GroupHeader/GroupHeader.js +137 -0
- package/lib/cjs/components/GroupHeader/Skeleton.d.ts +27 -0
- package/lib/cjs/components/GroupHeader/Skeleton.js +56 -0
- package/lib/cjs/components/GroupHeader/constants.d.ts +1 -0
- package/lib/cjs/components/GroupHeader/constants.js +4 -0
- package/lib/cjs/components/GroupHeader/index.d.ts +4 -0
- package/lib/cjs/components/GroupHeader/index.js +8 -0
- package/lib/cjs/components/GroupInfoWidget/GroupInfoWidget.d.ts +52 -0
- package/lib/cjs/components/GroupInfoWidget/GroupInfoWidget.js +100 -0
- package/lib/cjs/components/GroupInfoWidget/Skeleton.d.ts +21 -0
- package/lib/cjs/components/GroupInfoWidget/Skeleton.js +38 -0
- package/lib/cjs/components/GroupInfoWidget/constants.d.ts +1 -0
- package/lib/cjs/components/GroupInfoWidget/constants.js +4 -0
- package/lib/cjs/components/GroupInfoWidget/index.d.ts +4 -0
- package/lib/cjs/components/GroupInfoWidget/index.js +8 -0
- package/lib/cjs/components/GroupInviteButton/GroupInviteButton.d.ts +57 -0
- package/lib/cjs/components/GroupInviteButton/GroupInviteButton.js +259 -0
- package/lib/cjs/components/GroupInviteButton/index.d.ts +3 -0
- package/lib/cjs/components/GroupInviteButton/index.js +5 -0
- package/lib/cjs/components/GroupMembersButton/GroupMembersButton.d.ts +46 -0
- package/lib/cjs/components/GroupMembersButton/GroupMembersButton.js +135 -0
- package/lib/cjs/components/GroupMembersButton/index.d.ts +3 -0
- package/lib/cjs/components/GroupMembersButton/index.js +5 -0
- package/lib/cjs/components/GroupMembersWidget/GroupMembersWidget.d.ts +79 -0
- package/lib/cjs/components/GroupMembersWidget/GroupMembersWidget.js +194 -0
- package/lib/cjs/components/GroupMembersWidget/Skeleton.d.ts +22 -0
- package/lib/cjs/components/GroupMembersWidget/Skeleton.js +38 -0
- package/lib/cjs/components/GroupMembersWidget/constants.d.ts +1 -0
- package/lib/cjs/components/GroupMembersWidget/constants.js +4 -0
- package/lib/cjs/components/GroupMembersWidget/index.d.ts +4 -0
- package/lib/cjs/components/GroupMembersWidget/index.js +8 -0
- package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +79 -0
- package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.js +194 -0
- package/lib/cjs/components/GroupRequestsWidget/Skeleton.d.ts +22 -0
- package/lib/cjs/components/GroupRequestsWidget/Skeleton.js +38 -0
- package/lib/cjs/components/GroupRequestsWidget/constants.d.ts +1 -0
- package/lib/cjs/components/GroupRequestsWidget/constants.js +4 -0
- package/lib/cjs/components/GroupRequestsWidget/index.d.ts +4 -0
- package/lib/cjs/components/GroupRequestsWidget/index.js +8 -0
- package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.d.ts +51 -0
- package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.js +117 -0
- package/lib/cjs/components/GroupSubscribeButton/index.d.ts +3 -0
- package/lib/cjs/components/GroupSubscribeButton/index.js +5 -0
- package/lib/cjs/components/InlineComposerWidget/InlineComposerWidget.d.ts +4 -0
- package/lib/cjs/components/InlineComposerWidget/InlineComposerWidget.js +2 -3
- package/lib/cjs/components/NavigationMenuIconButton/index.d.ts +2 -1
- package/lib/cjs/components/NavigationMenuIconButton/index.js +3 -0
- package/lib/cjs/components/NavigationToolbarMobile/NavigationToolbarMobile.d.ts +5 -0
- package/lib/cjs/components/NavigationToolbarMobile/NavigationToolbarMobile.js +2 -2
- package/lib/cjs/components/User/User.d.ts +12 -0
- package/lib/cjs/components/User/User.js +5 -3
- package/lib/cjs/constants/Group.d.ts +2 -0
- package/lib/cjs/constants/Group.js +5 -0
- package/lib/cjs/index.d.ts +14 -2
- package/lib/cjs/index.js +34 -5
- package/lib/esm/components/ChangeGroupCover/ChangeGroupCover.d.ts +55 -0
- package/lib/esm/components/ChangeGroupCover/ChangeGroupCover.js +114 -0
- package/lib/esm/components/ChangeGroupCover/constants.d.ts +1 -0
- package/lib/esm/components/ChangeGroupCover/constants.js +1 -0
- package/lib/esm/components/ChangeGroupCover/index.d.ts +3 -0
- package/lib/esm/components/ChangeGroupCover/index.js +2 -0
- package/lib/esm/components/ChangeGroupPicture/ChangeGroupPicture.d.ts +57 -0
- package/lib/esm/components/ChangeGroupPicture/ChangeGroupPicture.js +114 -0
- package/lib/esm/components/ChangeGroupPicture/constants.d.ts +1 -0
- package/lib/esm/components/ChangeGroupPicture/constants.js +1 -0
- package/lib/esm/components/ChangeGroupPicture/index.d.ts +3 -0
- package/lib/esm/components/ChangeGroupPicture/index.js +2 -0
- package/lib/esm/components/CreateGroup/CreateGroup.d.ts +48 -0
- package/lib/esm/components/CreateGroup/CreateGroup.js +184 -0
- package/lib/esm/components/CreateGroup/constants.d.ts +1 -0
- package/lib/esm/components/CreateGroup/constants.js +1 -0
- package/lib/esm/components/CreateGroup/index.d.ts +3 -0
- package/lib/esm/components/CreateGroup/index.js +2 -0
- package/lib/esm/components/CreateGroupButton/CreateGroupButton.d.ts +38 -0
- package/lib/esm/components/CreateGroupButton/CreateGroupButton.js +70 -0
- package/lib/esm/components/CreateGroupButton/index.d.ts +3 -0
- package/lib/esm/components/CreateGroupButton/index.js +2 -0
- package/lib/esm/components/Group/Group.d.ts +67 -0
- package/lib/esm/components/Group/Group.js +93 -0
- package/lib/esm/components/Group/Skeleton.d.ts +22 -0
- package/lib/esm/components/Group/Skeleton.js +38 -0
- package/lib/esm/components/Group/constants.d.ts +1 -0
- package/lib/esm/components/Group/constants.js +1 -0
- package/lib/esm/components/Group/index.d.ts +4 -0
- package/lib/esm/components/Group/index.js +4 -0
- package/lib/esm/components/GroupHeader/GroupHeader.d.ts +83 -0
- package/lib/esm/components/GroupHeader/GroupHeader.js +134 -0
- package/lib/esm/components/GroupHeader/Skeleton.d.ts +27 -0
- package/lib/esm/components/GroupHeader/Skeleton.js +53 -0
- package/lib/esm/components/GroupHeader/constants.d.ts +1 -0
- package/lib/esm/components/GroupHeader/constants.js +1 -0
- package/lib/esm/components/GroupHeader/index.d.ts +4 -0
- package/lib/esm/components/GroupHeader/index.js +4 -0
- package/lib/esm/components/GroupInfoWidget/GroupInfoWidget.d.ts +52 -0
- package/lib/esm/components/GroupInfoWidget/GroupInfoWidget.js +97 -0
- package/lib/esm/components/GroupInfoWidget/Skeleton.d.ts +21 -0
- package/lib/esm/components/GroupInfoWidget/Skeleton.js +34 -0
- package/lib/esm/components/GroupInfoWidget/constants.d.ts +1 -0
- package/lib/esm/components/GroupInfoWidget/constants.js +1 -0
- package/lib/esm/components/GroupInfoWidget/index.d.ts +4 -0
- package/lib/esm/components/GroupInfoWidget/index.js +4 -0
- package/lib/esm/components/GroupInviteButton/GroupInviteButton.d.ts +57 -0
- package/lib/esm/components/GroupInviteButton/GroupInviteButton.js +256 -0
- package/lib/esm/components/GroupInviteButton/index.d.ts +3 -0
- package/lib/esm/components/GroupInviteButton/index.js +2 -0
- package/lib/esm/components/GroupMembersButton/GroupMembersButton.d.ts +46 -0
- package/lib/esm/components/GroupMembersButton/GroupMembersButton.js +132 -0
- package/lib/esm/components/GroupMembersButton/index.d.ts +3 -0
- package/lib/esm/components/GroupMembersButton/index.js +2 -0
- package/lib/esm/components/GroupMembersWidget/GroupMembersWidget.d.ts +79 -0
- package/lib/esm/components/GroupMembersWidget/GroupMembersWidget.js +191 -0
- package/lib/esm/components/GroupMembersWidget/Skeleton.d.ts +22 -0
- package/lib/esm/components/GroupMembersWidget/Skeleton.js +34 -0
- package/lib/esm/components/GroupMembersWidget/constants.d.ts +1 -0
- package/lib/esm/components/GroupMembersWidget/constants.js +1 -0
- package/lib/esm/components/GroupMembersWidget/index.d.ts +4 -0
- package/lib/esm/components/GroupMembersWidget/index.js +4 -0
- package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +79 -0
- package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.js +191 -0
- package/lib/esm/components/GroupRequestsWidget/Skeleton.d.ts +22 -0
- package/lib/esm/components/GroupRequestsWidget/Skeleton.js +34 -0
- package/lib/esm/components/GroupRequestsWidget/constants.d.ts +1 -0
- package/lib/esm/components/GroupRequestsWidget/constants.js +1 -0
- package/lib/esm/components/GroupRequestsWidget/index.d.ts +4 -0
- package/lib/esm/components/GroupRequestsWidget/index.js +4 -0
- package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.d.ts +51 -0
- package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.js +114 -0
- package/lib/esm/components/GroupSubscribeButton/index.d.ts +3 -0
- package/lib/esm/components/GroupSubscribeButton/index.js +2 -0
- package/lib/esm/components/InlineComposerWidget/InlineComposerWidget.d.ts +4 -0
- package/lib/esm/components/InlineComposerWidget/InlineComposerWidget.js +3 -4
- package/lib/esm/components/NavigationMenuIconButton/index.d.ts +2 -1
- package/lib/esm/components/NavigationMenuIconButton/index.js +2 -0
- package/lib/esm/components/NavigationToolbarMobile/NavigationToolbarMobile.d.ts +5 -0
- package/lib/esm/components/NavigationToolbarMobile/NavigationToolbarMobile.js +3 -3
- package/lib/esm/components/User/User.d.ts +12 -0
- package/lib/esm/components/User/User.js +5 -3
- package/lib/esm/constants/Group.d.ts +2 -0
- package/lib/esm/constants/Group.js +2 -0
- package/lib/esm/index.d.ts +14 -2
- package/lib/esm/index.js +41 -29
- package/lib/umd/react-ui.js +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { useThemeProps } from '@mui/system';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
|
+
import { Avatar, Box, Button, Chip, Icon, IconButton, InputAdornment, TextField, Typography } from '@mui/material';
|
|
6
|
+
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
|
7
|
+
import { SCUserContext, useSCFetchGroup } from '@selfcommunity/react-core';
|
|
8
|
+
import classNames from 'classnames';
|
|
9
|
+
import BaseDialog from '../../shared/BaseDialog';
|
|
10
|
+
import { LoadingButton } from '@mui/lab';
|
|
11
|
+
import { GroupService } from '@selfcommunity/api-services';
|
|
12
|
+
import Autocomplete from '@mui/material/Autocomplete';
|
|
13
|
+
import User from '../User';
|
|
14
|
+
import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
15
|
+
import { Logger } from '@selfcommunity/utils';
|
|
16
|
+
const messages = defineMessages({
|
|
17
|
+
placeholder: {
|
|
18
|
+
id: 'ui.groupInviteButton.searchBar.placeholder',
|
|
19
|
+
defaultMessage: 'ui.groupInviteButton.searchBar.placeholder'
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const PREFIX = 'SCGroupInviteButton';
|
|
23
|
+
const classes = {
|
|
24
|
+
root: `${PREFIX}-root`,
|
|
25
|
+
dialogRoot: `${PREFIX}-dialog-root`,
|
|
26
|
+
dialogTitle: `${PREFIX}-dialog-title`,
|
|
27
|
+
dialogContent: `${PREFIX}-dialog-content`,
|
|
28
|
+
autocomplete: `${PREFIX}-autocomplete`,
|
|
29
|
+
icon: `${PREFIX}-icon`,
|
|
30
|
+
input: `${PREFIX}-input`,
|
|
31
|
+
clear: `${PREFIX}-clear`,
|
|
32
|
+
invitedBox: `${PREFIX}-invited-box`,
|
|
33
|
+
suggested: `${PREFIX}-suggested`
|
|
34
|
+
};
|
|
35
|
+
const Root = styled(Button, {
|
|
36
|
+
name: PREFIX,
|
|
37
|
+
slot: 'Root',
|
|
38
|
+
overridesResolver: (props, styles) => styles.root
|
|
39
|
+
})(({ theme }) => ({}));
|
|
40
|
+
const DialogRoot = styled(BaseDialog, {
|
|
41
|
+
name: PREFIX,
|
|
42
|
+
slot: 'Root',
|
|
43
|
+
overridesResolver: (props, styles) => styles.dialogRoot
|
|
44
|
+
})(({ theme }) => ({}));
|
|
45
|
+
/**
|
|
46
|
+
*> API documentation for the Community-JS Group Invite Button component. Learn about the available props and the CSS API.
|
|
47
|
+
*
|
|
48
|
+
#### Import
|
|
49
|
+
```jsx
|
|
50
|
+
import {SCGroupInviteButton} from '@selfcommunity/react-ui';
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### Component Name
|
|
54
|
+
The name `SCGroupInviteButton` can be used when providing style overrides in the theme.
|
|
55
|
+
|
|
56
|
+
#### CSS
|
|
57
|
+
|
|
58
|
+
|Rule Name|Global class|Description|
|
|
59
|
+
|---|---|---|
|
|
60
|
+
|root|.SCGroupInviteButton-root|Styles applied to the root element.|
|
|
61
|
+
|dialogRoot|.SCGroupInviteButton-dialog-root|Styles applied to the dialog root.|
|
|
62
|
+
|dialogTitle|.SCGroupInviteButton-dialog-title|Styles applied to the dialog title element.|
|
|
63
|
+
|dialogContent|.SCGroupInviteButton-dialog-content|Styles applied to the dialog content.|
|
|
64
|
+
|autocomplete|.SCGroupInviteButton-autocomplete|Styles applied to the autocomplete element.|
|
|
65
|
+
|icon|.SCGroupInviteButton-icon|Styles applied to the autocomplete icon element.|
|
|
66
|
+
|input|.SCGroupInviteButton-input|Styles applied to the autocomplete input element.|
|
|
67
|
+
|clear|.SCGroupInviteButton-clear|Styles applied to the autocomplete clear icon element.|
|
|
68
|
+
|invitedBox|.SCGroupInviteButton-invited-box|Styles applied to the invited users box.|
|
|
69
|
+
|suggested|.SCGroupInviteButton-suggested|Styles applied to the suggested users box.|
|
|
70
|
+
|
|
71
|
+
* @param inProps
|
|
72
|
+
*/
|
|
73
|
+
export default function GroupInviteButton(inProps) {
|
|
74
|
+
//PROPS
|
|
75
|
+
const props = useThemeProps({
|
|
76
|
+
props: inProps,
|
|
77
|
+
name: PREFIX
|
|
78
|
+
});
|
|
79
|
+
const { className, group, groupId, handleInvitations = null } = props, rest = __rest(props, ["className", "group", "groupId", "handleInvitations"]);
|
|
80
|
+
// CONTEXT
|
|
81
|
+
const scUserContext = useContext(SCUserContext);
|
|
82
|
+
// STATE
|
|
83
|
+
const [open, setOpen] = useState(false);
|
|
84
|
+
const [isSending, setIsSending] = useState(false);
|
|
85
|
+
const [value, setValue] = useState('');
|
|
86
|
+
const [suggested, setSuggested] = useState([]);
|
|
87
|
+
const [list, setList] = useState([]);
|
|
88
|
+
const [loading, setLoading] = useState(false);
|
|
89
|
+
const [invited, setInvited] = useState([]);
|
|
90
|
+
function convertToInvitedUsersObject(data) {
|
|
91
|
+
const invited_users = {};
|
|
92
|
+
data.forEach((user, index) => {
|
|
93
|
+
invited_users[`invited_users[${index}]`] = user.id;
|
|
94
|
+
});
|
|
95
|
+
return invited_users;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Memoized users invited ids
|
|
99
|
+
*/
|
|
100
|
+
const ids = useMemo(() => {
|
|
101
|
+
if (invited) {
|
|
102
|
+
return invited.map((u) => {
|
|
103
|
+
return parseInt(u.id, 10);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return [invited];
|
|
107
|
+
}, [invited]);
|
|
108
|
+
// CONST
|
|
109
|
+
const authUserId = scUserContext.user ? scUserContext.user.id : null;
|
|
110
|
+
// HOOKS
|
|
111
|
+
const { scGroup } = useSCFetchGroup({ id: groupId, group });
|
|
112
|
+
// INTL
|
|
113
|
+
const intl = useIntl();
|
|
114
|
+
function fetchResults() {
|
|
115
|
+
setLoading(true);
|
|
116
|
+
GroupService.getGroupSuggestedUsers(scGroup === null || scGroup === void 0 ? void 0 : scGroup.id, value)
|
|
117
|
+
.then((data) => {
|
|
118
|
+
setLoading(false);
|
|
119
|
+
setSuggested(data.results);
|
|
120
|
+
})
|
|
121
|
+
.catch((error) => {
|
|
122
|
+
setLoading(false);
|
|
123
|
+
Logger.error(SCOPE_SC_UI, error);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function fetchGeneralResults() {
|
|
127
|
+
setLoading(true);
|
|
128
|
+
GroupService.getGroupsSuggestedUsers(value)
|
|
129
|
+
.then((data) => {
|
|
130
|
+
setLoading(false);
|
|
131
|
+
setSuggested(data.results);
|
|
132
|
+
})
|
|
133
|
+
.catch((error) => {
|
|
134
|
+
setLoading(false);
|
|
135
|
+
Logger.error(SCOPE_SC_UI, error);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
if (scGroup === null || scGroup === void 0 ? void 0 : scGroup.id) {
|
|
140
|
+
GroupService.getGroupSuggestedUsers(scGroup === null || scGroup === void 0 ? void 0 : scGroup.id, value).then((data) => {
|
|
141
|
+
setLoading(false);
|
|
142
|
+
setList(data.results);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
GroupService.getGroupsSuggestedUsers(value).then((data) => {
|
|
147
|
+
setLoading(false);
|
|
148
|
+
setList(data.results);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}, [scGroup === null || scGroup === void 0 ? void 0 : scGroup.id]);
|
|
152
|
+
/**
|
|
153
|
+
* If a value is entered in new message field, it fetches user suggested
|
|
154
|
+
*/
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
if (value && !handleInvitations) {
|
|
157
|
+
fetchResults();
|
|
158
|
+
}
|
|
159
|
+
fetchGeneralResults();
|
|
160
|
+
}, [value, handleInvitations]);
|
|
161
|
+
/**
|
|
162
|
+
* Handles dialog close
|
|
163
|
+
*/
|
|
164
|
+
const handleClose = () => {
|
|
165
|
+
setOpen((p) => !p);
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Handles invitation sending
|
|
169
|
+
*/
|
|
170
|
+
const handleSendInvitations = () => {
|
|
171
|
+
if (handleInvitations) {
|
|
172
|
+
handleInvitations(convertToInvitedUsersObject(invited));
|
|
173
|
+
setOpen(false);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
const data = { users: ids };
|
|
177
|
+
setIsSending(true);
|
|
178
|
+
GroupService.inviteOrAcceptGroupRequest(scGroup.id, data)
|
|
179
|
+
.then(() => {
|
|
180
|
+
setIsSending(false);
|
|
181
|
+
})
|
|
182
|
+
.catch((error) => {
|
|
183
|
+
setLoading(false);
|
|
184
|
+
Logger.error(SCOPE_SC_UI, error);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
// Autocomplete Handlers
|
|
189
|
+
const handleInputChange = (event, value, reason) => {
|
|
190
|
+
switch (reason) {
|
|
191
|
+
case 'input':
|
|
192
|
+
setValue(value);
|
|
193
|
+
!value && setSuggested([]);
|
|
194
|
+
break;
|
|
195
|
+
case 'reset':
|
|
196
|
+
setValue(value);
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
const handleChange = (event, value, reason, details) => {
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
event.stopPropagation();
|
|
203
|
+
switch (reason) {
|
|
204
|
+
case 'selectOption':
|
|
205
|
+
setInvited(value);
|
|
206
|
+
setList((prev) => prev.filter((u) => u.id !== details.option.id));
|
|
207
|
+
break;
|
|
208
|
+
case 'removeOption':
|
|
209
|
+
setInvited(value);
|
|
210
|
+
setList((prev) => [...prev, details.option]);
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
return false;
|
|
214
|
+
};
|
|
215
|
+
const handleUserInvite = (user) => {
|
|
216
|
+
setInvited((prev) => [...prev, user]);
|
|
217
|
+
setList((prev) => prev.filter((u) => u.id !== user.id));
|
|
218
|
+
};
|
|
219
|
+
const handleDelete = (option) => {
|
|
220
|
+
setInvited(invited.filter((v) => v !== option));
|
|
221
|
+
setList((prev) => [...prev, option]);
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* If there's no authUserId, component is hidden.
|
|
225
|
+
// */
|
|
226
|
+
if (!authUserId) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Renders root object
|
|
231
|
+
*/
|
|
232
|
+
return (React.createElement(React.Fragment, null,
|
|
233
|
+
React.createElement(Root, Object.assign({ className: classNames(classes.root, className), onClick: handleClose, size: "small", variant: "outlined", startIcon: React.createElement(Icon, { fontSize: "small" }, "add") }, rest),
|
|
234
|
+
React.createElement(FormattedMessage, { id: "ui.groupInviteButton", defaultMessage: "ui.groupInviteButton" })),
|
|
235
|
+
open && (React.createElement(DialogRoot, { DialogContentProps: { dividers: false }, open: true, className: classes.dialogRoot, title: React.createElement(React.Fragment, null,
|
|
236
|
+
React.createElement(IconButton, { onClick: handleClose },
|
|
237
|
+
React.createElement(Icon, { fontSize: "medium" }, "arrow_back")),
|
|
238
|
+
React.createElement(Typography, { className: classes.dialogTitle },
|
|
239
|
+
React.createElement(FormattedMessage, { id: "ui.groupInviteButton.dialog.title", defaultMessage: "ui.groupInviteButton.dialog.title" })),
|
|
240
|
+
React.createElement(LoadingButton, { size: "small", color: "secondary", variant: "contained", onClick: handleSendInvitations, loading: isSending },
|
|
241
|
+
React.createElement(FormattedMessage, { id: "ui.groupInviteButton.dialog.button.end", defaultMessage: "ui.groupInviteButton.dialog.button.end" }))) },
|
|
242
|
+
React.createElement(Box, { className: classes.dialogContent },
|
|
243
|
+
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),
|
|
244
|
+
React.createElement(Avatar, { alt: option.username, src: option.avatar }),
|
|
245
|
+
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,
|
|
246
|
+
React.createElement(InputAdornment, { position: "start" },
|
|
247
|
+
React.createElement(Icon, { className: classes.icon }, "search")),
|
|
248
|
+
params.InputProps.startAdornment)) }) }))) }),
|
|
249
|
+
React.createElement(Box, { className: classes.invitedBox }, invited.map((option, index) => (React.createElement(Chip, { key: index, avatar: React.createElement(Avatar, { alt: option.username, src: option.avatar }), label: option.username, onDelete: () => {
|
|
250
|
+
handleDelete(option);
|
|
251
|
+
}, style: { marginRight: 8 } })))),
|
|
252
|
+
React.createElement(Box, { className: classes.suggested },
|
|
253
|
+
list.length !== 0 && (React.createElement(Typography, { variant: "h4", fontWeight: "bold" },
|
|
254
|
+
React.createElement(FormattedMessage, { id: "ui.groupInviteButton.dialog.content.list", defaultMessage: "ui.groupInviteButton.dialog.content.list" }))),
|
|
255
|
+
list.slice(0, 5).map((user, index) => (React.createElement(User, { elevation: 0, actions: React.createElement(React.Fragment, null), user: user, userId: user.id, key: index, buttonProps: { onClick: () => handleUserInvite(user) } })))))))));
|
|
256
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BaseDialogProps } from '../../shared/BaseDialog';
|
|
2
|
+
import { SCGroupType } from '@selfcommunity/types';
|
|
3
|
+
import { ButtonProps } from '@mui/material/Button/Button';
|
|
4
|
+
export interface GroupMembersButtonProps extends Pick<ButtonProps, Exclude<keyof ButtonProps, 'onClick' | 'disabled'>> {
|
|
5
|
+
/**
|
|
6
|
+
* Group Object
|
|
7
|
+
* @default null
|
|
8
|
+
*/
|
|
9
|
+
group?: SCGroupType;
|
|
10
|
+
/**
|
|
11
|
+
* Id of the group
|
|
12
|
+
* @default null
|
|
13
|
+
*/
|
|
14
|
+
groupId?: number | string;
|
|
15
|
+
/**
|
|
16
|
+
* Props to spread to followedBy dialog
|
|
17
|
+
* @default {}
|
|
18
|
+
*/
|
|
19
|
+
DialogProps?: BaseDialogProps;
|
|
20
|
+
/**
|
|
21
|
+
* Any other properties
|
|
22
|
+
*/
|
|
23
|
+
[p: string]: any;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
*> API documentation for the Community-JS Group Members Button component. Learn about the available props and the CSS API.
|
|
27
|
+
*
|
|
28
|
+
#### Import
|
|
29
|
+
```jsx
|
|
30
|
+
import {GroupMembersButton} from '@selfcommunity/react-ui';
|
|
31
|
+
```
|
|
32
|
+
#### Component Name
|
|
33
|
+
|
|
34
|
+
The name `SCGroupMembersButton` can be used when providing style overrides in the theme.
|
|
35
|
+
|
|
36
|
+
* #### CSS
|
|
37
|
+
*
|
|
38
|
+
|Rule Name|Global class|Description|
|
|
39
|
+
|---|---|---|
|
|
40
|
+
|root|.SCGroupMembersButton-root|Styles applied to the root element.|
|
|
41
|
+
|dialogRoot|.SCGroupMembersButton-dialog-root|Styles applied to the root element.|
|
|
42
|
+
|endMessage|.SCCategoriesFollowedWidget-end-message|Styles applied to the end message element.|
|
|
43
|
+
|
|
44
|
+
* @param inProps
|
|
45
|
+
*/
|
|
46
|
+
export default function GroupMembersButton(inProps: GroupMembersButtonProps): JSX.Element;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
import { Avatar, AvatarGroup, Button, List, ListItem, Typography, useTheme } from '@mui/material';
|
|
5
|
+
import BaseDialog from '../../shared/BaseDialog';
|
|
6
|
+
import { FormattedMessage } from 'react-intl';
|
|
7
|
+
import InfiniteScroll from '../../shared/InfiniteScroll';
|
|
8
|
+
import User, { UserSkeleton } from '../User';
|
|
9
|
+
import { GroupService, Endpoints, http } from '@selfcommunity/api-services';
|
|
10
|
+
import { useSCFetchGroup } from '@selfcommunity/react-core';
|
|
11
|
+
import AvatarGroupSkeleton from '../Skeleton/AvatarGroupSkeleton';
|
|
12
|
+
import classNames from 'classnames';
|
|
13
|
+
import { useThemeProps } from '@mui/system';
|
|
14
|
+
import useMediaQuery from '@mui/material/useMediaQuery';
|
|
15
|
+
import { Logger } from '@selfcommunity/utils';
|
|
16
|
+
import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
17
|
+
import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect';
|
|
18
|
+
const PREFIX = 'SCGroupMembersButton';
|
|
19
|
+
const classes = {
|
|
20
|
+
root: `${PREFIX}-root`,
|
|
21
|
+
dialogRoot: `${PREFIX}-dialog-root`,
|
|
22
|
+
endMessage: `${PREFIX}-end-message`
|
|
23
|
+
};
|
|
24
|
+
const Root = styled(Button, {
|
|
25
|
+
name: PREFIX,
|
|
26
|
+
slot: 'Root',
|
|
27
|
+
overridesResolver: (props, styles) => styles.root
|
|
28
|
+
})(() => ({}));
|
|
29
|
+
const DialogRoot = styled(BaseDialog, {
|
|
30
|
+
name: PREFIX,
|
|
31
|
+
slot: 'Root',
|
|
32
|
+
overridesResolver: (props, styles) => styles.dialogRoot
|
|
33
|
+
})(() => ({}));
|
|
34
|
+
/**
|
|
35
|
+
*> API documentation for the Community-JS Group Members Button component. Learn about the available props and the CSS API.
|
|
36
|
+
*
|
|
37
|
+
#### Import
|
|
38
|
+
```jsx
|
|
39
|
+
import {GroupMembersButton} from '@selfcommunity/react-ui';
|
|
40
|
+
```
|
|
41
|
+
#### Component Name
|
|
42
|
+
|
|
43
|
+
The name `SCGroupMembersButton` can be used when providing style overrides in the theme.
|
|
44
|
+
|
|
45
|
+
* #### CSS
|
|
46
|
+
*
|
|
47
|
+
|Rule Name|Global class|Description|
|
|
48
|
+
|---|---|---|
|
|
49
|
+
|root|.SCGroupMembersButton-root|Styles applied to the root element.|
|
|
50
|
+
|dialogRoot|.SCGroupMembersButton-dialog-root|Styles applied to the root element.|
|
|
51
|
+
|endMessage|.SCCategoriesFollowedWidget-end-message|Styles applied to the end message element.|
|
|
52
|
+
|
|
53
|
+
* @param inProps
|
|
54
|
+
*/
|
|
55
|
+
export default function GroupMembersButton(inProps) {
|
|
56
|
+
// PROPS
|
|
57
|
+
const props = useThemeProps({
|
|
58
|
+
props: inProps,
|
|
59
|
+
name: PREFIX
|
|
60
|
+
});
|
|
61
|
+
const { className, groupId, group, DialogProps = {} } = props, rest = __rest(props, ["className", "groupId", "group", "DialogProps"]);
|
|
62
|
+
// STATE
|
|
63
|
+
const [loading, setLoading] = useState(true);
|
|
64
|
+
const [next, setNext] = useState(null);
|
|
65
|
+
const [offset, setOffset] = useState(null);
|
|
66
|
+
const [members, setMembers] = useState([]);
|
|
67
|
+
const [open, setOpen] = useState(false);
|
|
68
|
+
// HOOKS
|
|
69
|
+
const { scGroup } = useSCFetchGroup({ id: groupId, group });
|
|
70
|
+
// FETCH FIRST FOLLOWERS
|
|
71
|
+
useDeepCompareEffectNoCheck(() => {
|
|
72
|
+
if (!scGroup) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (members.length === 0) {
|
|
76
|
+
GroupService.getGroupMembers(scGroup.id, { limit: 3 }).then((res) => {
|
|
77
|
+
setMembers([...res.results]);
|
|
78
|
+
setOffset(3);
|
|
79
|
+
setLoading(false);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
setOffset(0);
|
|
84
|
+
}
|
|
85
|
+
}, [scGroup]);
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (open && offset !== null) {
|
|
88
|
+
setLoading(true);
|
|
89
|
+
GroupService.getGroupMembers(scGroup.id, { offset, limit: 20 }).then((res) => {
|
|
90
|
+
setMembers([...(offset === 0 ? [] : members), ...res.results]);
|
|
91
|
+
setNext(res.next);
|
|
92
|
+
setLoading(false);
|
|
93
|
+
setOffset(null);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}, [open, members, offset]);
|
|
97
|
+
/**
|
|
98
|
+
* Memoized fetchMembers
|
|
99
|
+
*/
|
|
100
|
+
const fetchMembers = useMemo(() => () => {
|
|
101
|
+
if (!next) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
http
|
|
105
|
+
.request({
|
|
106
|
+
url: next,
|
|
107
|
+
method: Endpoints.GetGroupSubscribers.method
|
|
108
|
+
})
|
|
109
|
+
.then((res) => {
|
|
110
|
+
setMembers([...members, ...res.data.results]);
|
|
111
|
+
setNext(res.data.next);
|
|
112
|
+
})
|
|
113
|
+
.catch((error) => Logger.error(SCOPE_SC_UI, error))
|
|
114
|
+
.then(() => setLoading(false));
|
|
115
|
+
}, [members, scGroup, next]);
|
|
116
|
+
/**
|
|
117
|
+
* Opens dialog votes
|
|
118
|
+
*/
|
|
119
|
+
const handleToggleDialogOpen = useMemo(() => () => {
|
|
120
|
+
setOpen((prev) => !prev);
|
|
121
|
+
}, [setOpen]);
|
|
122
|
+
// RENDER
|
|
123
|
+
const theme = useTheme();
|
|
124
|
+
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
|
|
125
|
+
return (React.createElement(React.Fragment, null,
|
|
126
|
+
React.createElement(Root, Object.assign({ className: classNames(classes.root, className), onClick: handleToggleDialogOpen, disabled: loading || !scGroup || scGroup.subscribers_counter === 0 }, rest), loading || !scGroup ? (React.createElement(AvatarGroupSkeleton, Object.assign({}, rest))) : (React.createElement(AvatarGroup, { total: scGroup.subscribers_counter }, members.map((c) => (React.createElement(Avatar, { key: c.id, alt: c.username, src: c.avatar })))))),
|
|
127
|
+
open && (React.createElement(DialogRoot, Object.assign({ className: classes.dialogRoot, title: React.createElement(FormattedMessage, { defaultMessage: "ui.groupMembersButton.dialogTitle", id: "ui.groupMembersButton.dialogTitle", values: { total: scGroup.subscribers_counter } }), onClose: handleToggleDialogOpen, open: open }, DialogProps),
|
|
128
|
+
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
|
+
React.createElement(FormattedMessage, { id: "ui.groupMembersButton.noOtherMembers", defaultMessage: "ui.groupMembersButton.noOtherMembers" })) },
|
|
130
|
+
React.createElement(List, null, members.map((member) => (React.createElement(ListItem, { key: member.id },
|
|
131
|
+
React.createElement(User, { elevation: 0, user: member }))))))))));
|
|
132
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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 GroupMembersWidgetProps 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
|
+
* Hides this component
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
autoHide?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Limit the number of users to show
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
27
|
+
limit?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Caching strategies
|
|
30
|
+
* @default CacheStrategies.CACHE_FIRST
|
|
31
|
+
*/
|
|
32
|
+
cacheStrategy?: CacheStrategies;
|
|
33
|
+
/**
|
|
34
|
+
* Props to spread to single user object
|
|
35
|
+
* @default empty object
|
|
36
|
+
*/
|
|
37
|
+
UserProps?: UserProps;
|
|
38
|
+
/**
|
|
39
|
+
* Props to spread to followers users dialog
|
|
40
|
+
* @default {}
|
|
41
|
+
*/
|
|
42
|
+
DialogProps?: BaseDialogProps;
|
|
43
|
+
/**
|
|
44
|
+
* Other props
|
|
45
|
+
*/
|
|
46
|
+
[p: string]: any;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* > API documentation for the Community-JS Group Members Widget component. Learn about the available props and the CSS API.
|
|
50
|
+
*
|
|
51
|
+
*
|
|
52
|
+
* This component renders the list of the follows of the given group.
|
|
53
|
+
* Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/GroupMembers)
|
|
54
|
+
|
|
55
|
+
#### Import
|
|
56
|
+
|
|
57
|
+
```jsx
|
|
58
|
+
import {GroupMembersWidget} from '@selfcommunity/react-ui';
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### Component Name
|
|
62
|
+
|
|
63
|
+
The name `SCGroupMembersWidget` can be used when providing style overrides in the theme.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
#### CSS
|
|
67
|
+
|
|
68
|
+
|Rule Name|Global class|Description|
|
|
69
|
+
|---|---|---|
|
|
70
|
+
|root|.SCGroupMembersWidget-root|Styles applied to the root element.|
|
|
71
|
+
|title|.SCGroupMembersWidget-title|Styles applied to the title element.|
|
|
72
|
+
|noResults|.SCGroupMembersWidget-no-results|Styles applied to no results section.|
|
|
73
|
+
|showMore|.SCGroupMembersWidget-show-more|Styles applied to show more button element.|
|
|
74
|
+
|dialogRoot|.SCGroupMembersWidget-dialog-root|Styles applied to the dialog root element.|
|
|
75
|
+
|endMessage|.SCGroupMembersWidget-end-message|Styles applied to the end message element.|
|
|
76
|
+
|
|
77
|
+
* @param inProps
|
|
78
|
+
*/
|
|
79
|
+
export default function GroupMembersWidget(inProps: GroupMembersWidgetProps): JSX.Element;
|