@selfcommunity/react-ui 0.7.9-alpha.2 → 0.7.9-alpha.20
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/BottomNavigation/BottomNavigation.js +3 -1
- package/lib/cjs/components/ChangeGroupCover/ChangeGroupCover.js +24 -1
- package/lib/cjs/components/ChangeGroupPicture/ChangeGroupPicture.js +32 -11
- package/lib/cjs/components/Composer/Attributes/Attributes.d.ts +1 -1
- package/lib/cjs/components/Composer/Attributes/Attributes.js +9 -2
- package/lib/cjs/components/Composer/Composer.d.ts +2 -1
- package/lib/cjs/components/Composer/Composer.js +39 -12
- package/lib/cjs/components/Composer/Content/ContentDiscussion/ContentDiscussion.js +7 -3
- package/lib/cjs/components/Composer/Content/ContentPost/ContentPost.js +4 -3
- package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +7 -1
- package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.js +46 -12
- package/lib/cjs/components/CreateGroupButton/CreateGroupButton.d.ts +2 -2
- package/lib/cjs/components/CreateGroupButton/CreateGroupButton.js +5 -6
- package/lib/cjs/components/CustomAdv/CustomAdv.d.ts +4 -0
- package/lib/cjs/components/{CreateGroup/CreateGroup.d.ts → EditGroupButton/EditGroupButton.d.ts} +11 -16
- package/lib/cjs/components/EditGroupButton/EditGroupButton.js +61 -0
- package/lib/cjs/components/EditGroupButton/index.d.ts +3 -0
- package/lib/cjs/components/EditGroupButton/index.js +5 -0
- package/lib/cjs/components/FeedObject/FeedObject.d.ts +1 -0
- package/lib/cjs/components/FeedObject/FeedObject.js +23 -6
- package/lib/cjs/components/Group/Group.d.ts +4 -3
- package/lib/cjs/components/Group/Group.js +5 -4
- package/lib/cjs/components/Group/Skeleton.js +1 -1
- package/lib/cjs/components/GroupAutocomplete/GroupAutocomplete.d.ts +49 -0
- package/lib/cjs/components/GroupAutocomplete/GroupAutocomplete.js +101 -0
- package/lib/cjs/components/GroupAutocomplete/index.d.ts +3 -0
- package/lib/cjs/components/GroupAutocomplete/index.js +5 -0
- package/lib/cjs/components/GroupForm/GroupForm.d.ts +70 -0
- package/lib/cjs/components/GroupForm/GroupForm.js +239 -0
- package/lib/cjs/components/GroupForm/constants.d.ts +1 -0
- package/lib/cjs/components/{CreateGroup → GroupForm}/constants.js +1 -1
- package/lib/cjs/components/GroupForm/index.d.ts +3 -0
- package/lib/cjs/components/GroupForm/index.js +5 -0
- package/lib/cjs/components/GroupHeader/GroupHeader.d.ts +6 -5
- package/lib/cjs/components/GroupHeader/GroupHeader.js +21 -11
- package/lib/cjs/components/GroupHeader/Skeleton.d.ts +2 -4
- package/lib/cjs/components/GroupHeader/Skeleton.js +10 -10
- package/lib/cjs/components/GroupInfoWidget/GroupInfoWidget.js +8 -8
- package/lib/cjs/components/GroupInviteButton/GroupInviteButton.js +9 -6
- package/lib/cjs/components/GroupMembersButton/GroupMembersButton.d.ts +5 -0
- package/lib/cjs/components/GroupMembersButton/GroupMembersButton.js +3 -2
- package/lib/cjs/components/GroupMembersWidget/GroupMembersWidget.js +29 -14
- package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +0 -5
- package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.js +17 -7
- package/lib/cjs/components/GroupSettingsIconButton/GroupSettingsIconButton.d.ts +56 -0
- package/lib/cjs/components/GroupSettingsIconButton/GroupSettingsIconButton.js +137 -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 +7 -2
- package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.js +24 -9
- package/lib/cjs/components/Groups/Groups.d.ts +65 -0
- package/lib/cjs/components/Groups/Groups.js +135 -0
- package/lib/cjs/components/Groups/Skeleton.d.ts +34 -0
- package/lib/cjs/components/Groups/Skeleton.js +45 -0
- package/lib/cjs/components/Groups/constants.d.ts +1 -0
- package/lib/cjs/components/Groups/constants.js +4 -0
- package/lib/cjs/components/Groups/index.d.ts +4 -0
- package/lib/cjs/components/Groups/index.js +8 -0
- package/lib/cjs/components/InlineComposerWidget/InlineComposerWidget.d.ts +2 -1
- package/lib/cjs/components/NavigationMenuIconButton/NavigationMenuIconButton.js +1 -1
- package/lib/cjs/components/NavigationToolbar/NavigationToolbar.js +5 -1
- package/lib/cjs/components/NavigationToolbarMobile/NavigationToolbarMobile.d.ts +4 -0
- package/lib/cjs/components/NavigationToolbarMobile/NavigationToolbarMobile.js +2 -3
- package/lib/cjs/components/PrivateMessageComponent/PrivateMessageComponent.d.ts +1 -1
- package/lib/cjs/components/PrivateMessageComponent/PrivateMessageComponent.js +10 -7
- package/lib/cjs/components/PrivateMessageSnippetItem/PrivateMessageSnippetItem.js +11 -6
- package/lib/cjs/components/PrivateMessageSnippets/PrivateMessageSnippets.d.ts +3 -3
- 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 +45 -20
- package/lib/cjs/index.d.ts +7 -3
- package/lib/cjs/index.js +14 -4
- package/lib/esm/components/BottomNavigation/BottomNavigation.js +3 -1
- package/lib/esm/components/ChangeGroupCover/ChangeGroupCover.js +24 -1
- package/lib/esm/components/ChangeGroupPicture/ChangeGroupPicture.js +32 -11
- package/lib/esm/components/Composer/Attributes/Attributes.d.ts +1 -1
- package/lib/esm/components/Composer/Attributes/Attributes.js +9 -2
- package/lib/esm/components/Composer/Composer.d.ts +2 -1
- package/lib/esm/components/Composer/Composer.js +39 -12
- package/lib/esm/components/Composer/Content/ContentDiscussion/ContentDiscussion.js +7 -3
- package/lib/esm/components/Composer/Content/ContentPost/ContentPost.js +4 -3
- package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +7 -1
- package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.js +45 -12
- package/lib/esm/components/CreateGroupButton/CreateGroupButton.d.ts +2 -2
- package/lib/esm/components/CreateGroupButton/CreateGroupButton.js +5 -6
- package/lib/esm/components/CustomAdv/CustomAdv.d.ts +4 -0
- package/lib/esm/components/{CreateGroup/CreateGroup.d.ts → EditGroupButton/EditGroupButton.d.ts} +11 -16
- package/lib/esm/components/EditGroupButton/EditGroupButton.js +58 -0
- package/lib/esm/components/EditGroupButton/index.d.ts +3 -0
- package/lib/esm/components/EditGroupButton/index.js +2 -0
- package/lib/esm/components/FeedObject/FeedObject.d.ts +1 -0
- package/lib/esm/components/FeedObject/FeedObject.js +24 -7
- package/lib/esm/components/Group/Group.d.ts +4 -3
- package/lib/esm/components/Group/Group.js +5 -4
- package/lib/esm/components/Group/Skeleton.js +1 -1
- package/lib/esm/components/GroupAutocomplete/GroupAutocomplete.d.ts +49 -0
- package/lib/esm/components/GroupAutocomplete/GroupAutocomplete.js +99 -0
- package/lib/esm/components/GroupAutocomplete/index.d.ts +3 -0
- package/lib/esm/components/GroupAutocomplete/index.js +2 -0
- package/lib/esm/components/GroupForm/GroupForm.d.ts +70 -0
- package/lib/esm/components/GroupForm/GroupForm.js +236 -0
- package/lib/esm/components/GroupForm/constants.d.ts +1 -0
- package/lib/esm/components/GroupForm/constants.js +1 -0
- package/lib/esm/components/GroupForm/index.d.ts +3 -0
- package/lib/esm/components/GroupForm/index.js +2 -0
- package/lib/esm/components/GroupHeader/GroupHeader.d.ts +6 -5
- package/lib/esm/components/GroupHeader/GroupHeader.js +21 -11
- package/lib/esm/components/GroupHeader/Skeleton.d.ts +2 -4
- package/lib/esm/components/GroupHeader/Skeleton.js +10 -10
- package/lib/esm/components/GroupInfoWidget/GroupInfoWidget.js +8 -8
- package/lib/esm/components/GroupInviteButton/GroupInviteButton.js +9 -6
- package/lib/esm/components/GroupMembersButton/GroupMembersButton.d.ts +5 -0
- package/lib/esm/components/GroupMembersButton/GroupMembersButton.js +4 -3
- package/lib/esm/components/GroupMembersWidget/GroupMembersWidget.js +31 -16
- package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +0 -5
- package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.js +17 -7
- package/lib/esm/components/GroupSettingsIconButton/GroupSettingsIconButton.d.ts +56 -0
- package/lib/esm/components/GroupSettingsIconButton/GroupSettingsIconButton.js +134 -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 +7 -2
- package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.js +25 -10
- package/lib/esm/components/Groups/Groups.d.ts +65 -0
- package/lib/esm/components/Groups/Groups.js +132 -0
- package/lib/esm/components/Groups/Skeleton.d.ts +34 -0
- package/lib/esm/components/Groups/Skeleton.js +42 -0
- package/lib/esm/components/Groups/constants.d.ts +1 -0
- package/lib/esm/components/Groups/constants.js +1 -0
- package/lib/esm/components/Groups/index.d.ts +4 -0
- package/lib/esm/components/Groups/index.js +4 -0
- package/lib/esm/components/InlineComposerWidget/InlineComposerWidget.d.ts +2 -1
- package/lib/esm/components/NavigationMenuIconButton/NavigationMenuIconButton.js +1 -1
- package/lib/esm/components/NavigationToolbar/NavigationToolbar.js +5 -1
- package/lib/esm/components/NavigationToolbarMobile/NavigationToolbarMobile.d.ts +4 -0
- package/lib/esm/components/NavigationToolbarMobile/NavigationToolbarMobile.js +2 -3
- package/lib/esm/components/PrivateMessageComponent/PrivateMessageComponent.d.ts +1 -1
- package/lib/esm/components/PrivateMessageComponent/PrivateMessageComponent.js +11 -8
- package/lib/esm/components/PrivateMessageSnippetItem/PrivateMessageSnippetItem.js +11 -6
- package/lib/esm/components/PrivateMessageSnippets/PrivateMessageSnippets.d.ts +3 -3
- 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 +47 -22
- package/lib/esm/index.d.ts +7 -3
- package/lib/esm/index.js +8 -4
- package/lib/umd/react-ui.js +1 -1
- package/package.json +6 -6
- package/lib/cjs/components/CreateGroup/CreateGroup.js +0 -187
- package/lib/cjs/components/CreateGroup/constants.d.ts +0 -1
- package/lib/cjs/components/CreateGroup/index.d.ts +0 -3
- package/lib/cjs/components/CreateGroup/index.js +0 -5
- package/lib/esm/components/CreateGroup/CreateGroup.js +0 -184
- package/lib/esm/components/CreateGroup/constants.d.ts +0 -1
- package/lib/esm/components/CreateGroup/constants.js +0 -1
- package/lib/esm/components/CreateGroup/index.d.ts +0 -3
- package/lib/esm/components/CreateGroup/index.js +0 -2
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
|
+
import { FormattedMessage } from 'react-intl';
|
|
4
|
+
import Autocomplete from '@mui/material/Autocomplete';
|
|
5
|
+
import TextField from '@mui/material/TextField';
|
|
6
|
+
import CircularProgress from '@mui/material/CircularProgress';
|
|
7
|
+
import parse from 'autosuggest-highlight/parse';
|
|
8
|
+
import match from 'autosuggest-highlight/match';
|
|
9
|
+
import { Avatar, Box, Typography } from '@mui/material';
|
|
10
|
+
import { useSCFetchGroups } from '@selfcommunity/react-core';
|
|
11
|
+
import { styled } from '@mui/material/styles';
|
|
12
|
+
import { useThemeProps } from '@mui/system';
|
|
13
|
+
const PREFIX = 'SCGroupAutocomplete';
|
|
14
|
+
const classes = {
|
|
15
|
+
root: `${PREFIX}-root`
|
|
16
|
+
};
|
|
17
|
+
const Root = styled(Autocomplete, {
|
|
18
|
+
name: PREFIX,
|
|
19
|
+
slot: 'Root',
|
|
20
|
+
overridesResolver: (props, styles) => styles.root
|
|
21
|
+
})(() => ({}));
|
|
22
|
+
/**
|
|
23
|
+
* > API documentation for the Community-JS Group Autocomplete component. Learn about the available props and the CSS API.
|
|
24
|
+
*
|
|
25
|
+
*
|
|
26
|
+
* This component renders a bar that allows users to search (with autocomplete) for all the groups available in the application.
|
|
27
|
+
* Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/GroupAutocomplete)
|
|
28
|
+
*
|
|
29
|
+
* #### Import
|
|
30
|
+
* ```jsx
|
|
31
|
+
* import {GroupAutocomplete} from '@selfcommunity/react-ui';
|
|
32
|
+
* ```
|
|
33
|
+
* #### Component Name
|
|
34
|
+
* The name `SCGroupAutocomplete` can be used when providing style overrides in the theme.
|
|
35
|
+
*
|
|
36
|
+
* #### CSS
|
|
37
|
+
*
|
|
38
|
+
* |Rule Name|Global class|Description|
|
|
39
|
+
* |---|---|---|
|
|
40
|
+
* |root|.SCGroupAutocomplete-root|Styles applied to the root element.|
|
|
41
|
+
*
|
|
42
|
+
* @param inProps
|
|
43
|
+
*/
|
|
44
|
+
const GroupAutocomplete = (inProps) => {
|
|
45
|
+
const props = useThemeProps({
|
|
46
|
+
props: inProps,
|
|
47
|
+
name: PREFIX
|
|
48
|
+
});
|
|
49
|
+
// Props
|
|
50
|
+
const { onChange, defaultValue = null, disabled = false, TextFieldProps = {
|
|
51
|
+
variant: 'outlined',
|
|
52
|
+
label: React.createElement(FormattedMessage, { id: "ui.groupAutocomplete.label", defaultMessage: "ui.groupAutocomplete.label" })
|
|
53
|
+
} } = props, rest = __rest(props, ["onChange", "defaultValue", "disabled", "TextFieldProps"]);
|
|
54
|
+
// State
|
|
55
|
+
const [open, setOpen] = useState(false);
|
|
56
|
+
const [value, setValue] = useState(typeof defaultValue === 'string' ? null : defaultValue);
|
|
57
|
+
// HOOKS
|
|
58
|
+
const { groups, isLoading } = useSCFetchGroups();
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (value === null) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
onChange && onChange(value);
|
|
64
|
+
}, [value]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!isLoading && typeof defaultValue === 'string') {
|
|
67
|
+
setValue(groups.find((g) => g.id === Number(defaultValue)));
|
|
68
|
+
}
|
|
69
|
+
}, [isLoading]);
|
|
70
|
+
// Handlers
|
|
71
|
+
const handleOpen = () => {
|
|
72
|
+
setOpen(true);
|
|
73
|
+
};
|
|
74
|
+
const handleClose = () => {
|
|
75
|
+
setOpen(false);
|
|
76
|
+
};
|
|
77
|
+
const handleChange = (event, value) => {
|
|
78
|
+
setValue(value);
|
|
79
|
+
};
|
|
80
|
+
// Render
|
|
81
|
+
return (React.createElement(Root, Object.assign({ freeSolo: true, className: classes.root, open: open, onOpen: handleOpen, onClose: handleClose, options: groups || [], getOptionLabel: (option) => option.name || '', value: value, selectOnFocus: true, clearOnBlur: true, blurOnSelect: true, handleHomeEndKeys: true, clearIcon: null, disabled: disabled || isLoading, noOptionsText: React.createElement(FormattedMessage, { id: "ui.groupAutocomplete.empty", defaultMessage: "ui.groupAutocomplete.empty" }), onChange: handleChange, isOptionEqualToValue: (option, value) => value.id === option.id,
|
|
82
|
+
// renderTags={(value, getTagProps) => {
|
|
83
|
+
// return value.map((option: any, index) => (
|
|
84
|
+
// <Chip key={option.id} id={option.id} label={option.name} color={option.color} {...getTagProps({index})} />
|
|
85
|
+
// ));
|
|
86
|
+
// }}
|
|
87
|
+
renderOption: (props, option, { inputValue }) => {
|
|
88
|
+
const matches = match(option.name, inputValue);
|
|
89
|
+
const parts = parse(option.name, matches);
|
|
90
|
+
return (React.createElement(Box, Object.assign({ component: "li" }, props),
|
|
91
|
+
React.createElement(Avatar, { alt: option.name, src: option.image_small, sx: { marginRight: 1 } }),
|
|
92
|
+
React.createElement(React.Fragment, null, parts.map((part, index) => (React.createElement(Typography, { key: index, sx: { fontWeight: part.highlight ? 700 : 400, marginRight: 0.2 } }, part.text))))));
|
|
93
|
+
}, renderInput: (params) => {
|
|
94
|
+
return (React.createElement(TextField, Object.assign({}, params, TextFieldProps, { margin: "dense", InputProps: Object.assign(Object.assign({}, params.InputProps), { autoComplete: 'groups', endAdornment: (React.createElement(React.Fragment, null,
|
|
95
|
+
isLoading ? React.createElement(CircularProgress, { color: "inherit", size: 20 }) : null,
|
|
96
|
+
params.InputProps.endAdornment)) }) })));
|
|
97
|
+
} }, rest)));
|
|
98
|
+
};
|
|
99
|
+
export default GroupAutocomplete;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { BaseDialogProps } from '../../shared/BaseDialog';
|
|
2
|
+
import { SCGroupType } from '@selfcommunity/types';
|
|
3
|
+
export interface GroupFormProps extends BaseDialogProps {
|
|
4
|
+
/**
|
|
5
|
+
* Overrides or extends the styles applied to the component.
|
|
6
|
+
* @default null
|
|
7
|
+
*/
|
|
8
|
+
className?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Open dialog
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
open?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* On dialog close callback function
|
|
16
|
+
* @default null
|
|
17
|
+
*/
|
|
18
|
+
onClose?: () => void;
|
|
19
|
+
/**
|
|
20
|
+
* Group Object
|
|
21
|
+
* @default null
|
|
22
|
+
*/
|
|
23
|
+
group?: SCGroupType;
|
|
24
|
+
/**
|
|
25
|
+
* On success callback function
|
|
26
|
+
* @default null
|
|
27
|
+
*/
|
|
28
|
+
onSuccess?: (data: SCGroupType) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Any other properties
|
|
31
|
+
*/
|
|
32
|
+
[p: string]: any;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
*> API documentation for the Community-JS Group Form component. Learn about the available props and the CSS API.
|
|
36
|
+
*
|
|
37
|
+
#### Import
|
|
38
|
+
```jsx
|
|
39
|
+
import {GroupForm} from '@selfcommunity/react-ui';
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
#### Component Name
|
|
43
|
+
The name `SCGroupForm` can be used when providing style overrides in the theme.
|
|
44
|
+
|
|
45
|
+
#### CSS
|
|
46
|
+
|
|
47
|
+
|Rule Name|Global class|Description|
|
|
48
|
+
|---|---|---|
|
|
49
|
+
|root|.SCGroupForm-root|Styles applied to the root element.|
|
|
50
|
+
|active|.SCGroupForm-active|Styles applied to the active element.|
|
|
51
|
+
|title|.SCGroupForm-title|Styles applied to the title element.|
|
|
52
|
+
|header|.SCGroupForm-header|Styles applied to the header element.|
|
|
53
|
+
|cover|.SCGroupForm-cover|Styles applied to the cover field.|
|
|
54
|
+
|avatar|.SCGroupForm-avatar|Styles applied to the avatar field.|
|
|
55
|
+
|form|.SCGroupForm-form|Styles applied to the form element.|
|
|
56
|
+
|switch|.SCGroupForm-switch|Styles applied to the switch element.|
|
|
57
|
+
|switchLabel|.SCGroupForm-switch-label|Styles applied to the switchLabel element.|
|
|
58
|
+
|name|.SCGroupForm-name|Styles applied to the name field.|
|
|
59
|
+
|description|.SCGroupForm-description|Styles applied to the description field.|
|
|
60
|
+
|content|.SCGroupForm-content|Styles applied to the element.|
|
|
61
|
+
|privacySection|.SCGroupForm-privacy-section|Styles applied to the privacy section.|
|
|
62
|
+
|privacySectionInfo|.SCGroupForm-privacy-section-info|Styles applied to the privacy info section.|
|
|
63
|
+
|visibilitySection|.SCGroupForm-visibility-section|Styles applied to the visibility section.|
|
|
64
|
+
|visibilitySectionInfo|.SCGroupForm-visibility-section-info|Styles applied to the visibility section info.|
|
|
65
|
+
|inviteSection|.SCGroupForm-invite-section|Styles applied to the invite section.|
|
|
66
|
+
|error|.SCGroupForm-error|Styles applied to the error elements.|
|
|
67
|
+
|
|
68
|
+
* @param inProps
|
|
69
|
+
*/
|
|
70
|
+
export default function GroupForm(inProps: GroupFormProps): JSX.Element;
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { useThemeProps } from '@mui/system';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
|
+
import { Avatar, Box, Divider, FormGroup, Icon, Paper, Stack, Switch, TextField, Typography } from '@mui/material';
|
|
6
|
+
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
|
7
|
+
import { SCPreferences, useSCPreferences } from '@selfcommunity/react-core';
|
|
8
|
+
import classNames from 'classnames';
|
|
9
|
+
import { PREFIX } from './constants';
|
|
10
|
+
import BaseDialog from '../../shared/BaseDialog';
|
|
11
|
+
import { LoadingButton } from '@mui/lab';
|
|
12
|
+
import ChangeGroupPicture from '../ChangeGroupPicture';
|
|
13
|
+
import ChangeGroupCover from '../ChangeGroupCover';
|
|
14
|
+
import { GROUP_DESCRIPTION_MAX_LENGTH, GROUP_TITLE_MAX_LENGTH } from '../../constants/Group';
|
|
15
|
+
import GroupInviteButton from '../GroupInviteButton';
|
|
16
|
+
import { SCGroupPrivacyType } from '@selfcommunity/types';
|
|
17
|
+
import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
18
|
+
import { formatHttpErrorCode, GroupService } from '@selfcommunity/api-services';
|
|
19
|
+
import { Logger } from '@selfcommunity/utils';
|
|
20
|
+
const messages = defineMessages({
|
|
21
|
+
name: {
|
|
22
|
+
id: 'ui.groupForm.name.placeholder',
|
|
23
|
+
defaultMessage: 'ui.groupForm.name.placeholder'
|
|
24
|
+
},
|
|
25
|
+
description: {
|
|
26
|
+
id: 'ui.groupForm.description.placeholder',
|
|
27
|
+
defaultMessage: 'ui.groupForm.description.placeholder'
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const classes = {
|
|
31
|
+
root: `${PREFIX}-root`,
|
|
32
|
+
active: `${PREFIX}-active`,
|
|
33
|
+
title: `${PREFIX}-title`,
|
|
34
|
+
header: `${PREFIX}-header`,
|
|
35
|
+
cover: `${PREFIX}-cover`,
|
|
36
|
+
avatar: `${PREFIX}-avatar`,
|
|
37
|
+
form: `${PREFIX}-form`,
|
|
38
|
+
switch: `${PREFIX}-switch`,
|
|
39
|
+
switchLabel: `${PREFIX}-switch-label`,
|
|
40
|
+
name: `${PREFIX}-name`,
|
|
41
|
+
description: `${PREFIX}-description`,
|
|
42
|
+
content: `${PREFIX}-content`,
|
|
43
|
+
privacySection: `${PREFIX}-privacy-section`,
|
|
44
|
+
privacySectionInfo: `${PREFIX}-privacy-section-info`,
|
|
45
|
+
visibilitySection: `${PREFIX}-visibility-section`,
|
|
46
|
+
visibilitySectionInfo: `${PREFIX}-visibility-section-info`,
|
|
47
|
+
inviteSection: `${PREFIX}-invite-section`,
|
|
48
|
+
error: `${PREFIX}-error`
|
|
49
|
+
};
|
|
50
|
+
const Root = styled(BaseDialog, {
|
|
51
|
+
name: PREFIX,
|
|
52
|
+
slot: 'Root'
|
|
53
|
+
})(() => ({}));
|
|
54
|
+
/**
|
|
55
|
+
*> API documentation for the Community-JS Group Form component. Learn about the available props and the CSS API.
|
|
56
|
+
*
|
|
57
|
+
#### Import
|
|
58
|
+
```jsx
|
|
59
|
+
import {GroupForm} from '@selfcommunity/react-ui';
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### Component Name
|
|
63
|
+
The name `SCGroupForm` can be used when providing style overrides in the theme.
|
|
64
|
+
|
|
65
|
+
#### CSS
|
|
66
|
+
|
|
67
|
+
|Rule Name|Global class|Description|
|
|
68
|
+
|---|---|---|
|
|
69
|
+
|root|.SCGroupForm-root|Styles applied to the root element.|
|
|
70
|
+
|active|.SCGroupForm-active|Styles applied to the active element.|
|
|
71
|
+
|title|.SCGroupForm-title|Styles applied to the title element.|
|
|
72
|
+
|header|.SCGroupForm-header|Styles applied to the header element.|
|
|
73
|
+
|cover|.SCGroupForm-cover|Styles applied to the cover field.|
|
|
74
|
+
|avatar|.SCGroupForm-avatar|Styles applied to the avatar field.|
|
|
75
|
+
|form|.SCGroupForm-form|Styles applied to the form element.|
|
|
76
|
+
|switch|.SCGroupForm-switch|Styles applied to the switch element.|
|
|
77
|
+
|switchLabel|.SCGroupForm-switch-label|Styles applied to the switchLabel element.|
|
|
78
|
+
|name|.SCGroupForm-name|Styles applied to the name field.|
|
|
79
|
+
|description|.SCGroupForm-description|Styles applied to the description field.|
|
|
80
|
+
|content|.SCGroupForm-content|Styles applied to the element.|
|
|
81
|
+
|privacySection|.SCGroupForm-privacy-section|Styles applied to the privacy section.|
|
|
82
|
+
|privacySectionInfo|.SCGroupForm-privacy-section-info|Styles applied to the privacy info section.|
|
|
83
|
+
|visibilitySection|.SCGroupForm-visibility-section|Styles applied to the visibility section.|
|
|
84
|
+
|visibilitySectionInfo|.SCGroupForm-visibility-section-info|Styles applied to the visibility section info.|
|
|
85
|
+
|inviteSection|.SCGroupForm-invite-section|Styles applied to the invite section.|
|
|
86
|
+
|error|.SCGroupForm-error|Styles applied to the error elements.|
|
|
87
|
+
|
|
88
|
+
* @param inProps
|
|
89
|
+
*/
|
|
90
|
+
export default function GroupForm(inProps) {
|
|
91
|
+
//PROPS
|
|
92
|
+
const props = useThemeProps({
|
|
93
|
+
props: inProps,
|
|
94
|
+
name: PREFIX
|
|
95
|
+
});
|
|
96
|
+
const { className, open = true, onClose, onSuccess, group = null } = props, rest = __rest(props, ["className", "open", "onClose", "onSuccess", "group"]);
|
|
97
|
+
const initialFieldState = {
|
|
98
|
+
imageOriginal: group ? group.image_medium : '',
|
|
99
|
+
imageOriginalFile: '',
|
|
100
|
+
emotionalImageOriginal: group ? group.emotional_image : '',
|
|
101
|
+
emotionalImageOriginalFile: '',
|
|
102
|
+
name: group ? group.name : '',
|
|
103
|
+
description: group ? group.description : '',
|
|
104
|
+
isPublic: group && group.privacy === SCGroupPrivacyType.PUBLIC,
|
|
105
|
+
isVisible: group ? group.visible : true,
|
|
106
|
+
invitedUsers: null,
|
|
107
|
+
isSubmitting: false
|
|
108
|
+
};
|
|
109
|
+
// STATE
|
|
110
|
+
const [field, setField] = useState(initialFieldState);
|
|
111
|
+
const [error, setError] = useState({});
|
|
112
|
+
// INTL
|
|
113
|
+
const intl = useIntl();
|
|
114
|
+
// PREFERENCES
|
|
115
|
+
const scPreferences = useSCPreferences();
|
|
116
|
+
const _backgroundCover = Object.assign({}, (field.emotionalImageOriginal
|
|
117
|
+
? { background: `url('${field.emotionalImageOriginal}') center / cover` }
|
|
118
|
+
: { background: `url('${scPreferences.preferences[SCPreferences.IMAGES_USER_DEFAULT_COVER].value}') center / cover` }));
|
|
119
|
+
function handleChangeAvatar(avatar) {
|
|
120
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['imageOriginalFile']: avatar })));
|
|
121
|
+
const reader = new FileReader();
|
|
122
|
+
reader.onloadend = () => {
|
|
123
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['imageOriginal']: reader.result })));
|
|
124
|
+
};
|
|
125
|
+
reader.readAsDataURL(avatar);
|
|
126
|
+
if (error.imageOriginalError) {
|
|
127
|
+
delete error.imageOriginalError;
|
|
128
|
+
setError(error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function handleChangeCover(cover) {
|
|
132
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['emotionalImageOriginalFile']: cover })));
|
|
133
|
+
const reader = new FileReader();
|
|
134
|
+
reader.onloadend = () => {
|
|
135
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['emotionalImageOriginal']: reader.result })));
|
|
136
|
+
};
|
|
137
|
+
reader.readAsDataURL(cover);
|
|
138
|
+
if (error.emotionalImageOriginalError) {
|
|
139
|
+
delete error.emotionalImageOriginalError;
|
|
140
|
+
setError(error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const handleSubmit = () => {
|
|
144
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: true })));
|
|
145
|
+
const formData = new FormData();
|
|
146
|
+
formData.append('name', field.name);
|
|
147
|
+
formData.append('description', field.description);
|
|
148
|
+
formData.append('privacy', field.isPublic ? SCGroupPrivacyType.PUBLIC : SCGroupPrivacyType.PRIVATE);
|
|
149
|
+
formData.append('visible', field.isVisible);
|
|
150
|
+
if (field.imageOriginalFile) {
|
|
151
|
+
formData.append('image_original', field.imageOriginalFile);
|
|
152
|
+
}
|
|
153
|
+
if (field.emotionalImageOriginalFile) {
|
|
154
|
+
formData.append('emotional_image_original', field.emotionalImageOriginalFile);
|
|
155
|
+
}
|
|
156
|
+
for (const key in field.invitedUsers) {
|
|
157
|
+
formData.append(key, field.invitedUsers[key]);
|
|
158
|
+
}
|
|
159
|
+
let groupService;
|
|
160
|
+
if (group) {
|
|
161
|
+
groupService = GroupService.updateGroup(group.id, formData, { headers: { 'Content-Type': 'multipart/form-data' } });
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
groupService = GroupService.createGroup(formData, { headers: { 'Content-Type': 'multipart/form-data' } });
|
|
165
|
+
}
|
|
166
|
+
groupService
|
|
167
|
+
.then((data) => {
|
|
168
|
+
onSuccess && onSuccess(data);
|
|
169
|
+
onClose && onClose();
|
|
170
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: false })));
|
|
171
|
+
})
|
|
172
|
+
.catch((e) => {
|
|
173
|
+
setError(Object.assign(Object.assign({}, error), formatHttpErrorCode(e)));
|
|
174
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: false })));
|
|
175
|
+
Logger.error(SCOPE_SC_UI, e);
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
const handleInviteSection = (data) => {
|
|
179
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['invitedUsers']: data })));
|
|
180
|
+
};
|
|
181
|
+
const handleChange = (event) => {
|
|
182
|
+
const { name, value } = event.target;
|
|
183
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { [name]: value })));
|
|
184
|
+
if (error[`${name}Error`]) {
|
|
185
|
+
delete error[`${name}Error`];
|
|
186
|
+
setError(error);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Renders root object
|
|
191
|
+
*/
|
|
192
|
+
return (React.createElement(Root, Object.assign({ DialogContentProps: { dividers: false }, title: group ? (React.createElement(FormattedMessage, { id: "ui.groupForm.title.edit", defaultMessage: "ui.groupForm.title.edit" })) : (React.createElement(FormattedMessage, { id: "ui.groupForm.title", defaultMessage: "ui.groupForm.title" })), open: open, onClose: onClose, className: classNames(classes.root, className), actions: React.createElement(LoadingButton, { loading: field.isSubmitting, disabled: !field.name || Object.keys(error).length !== 0, variant: "contained", onClick: handleSubmit, color: "secondary" }, group ? (React.createElement(FormattedMessage, { id: "ui.groupForm.button.edit", defaultMessage: "ui.groupForm.button.edit" })) : (React.createElement(FormattedMessage, { id: "ui.groupForm.button.create", defaultMessage: "ui.groupForm.button.create" }))) }, rest),
|
|
193
|
+
React.createElement(React.Fragment, null,
|
|
194
|
+
React.createElement(React.Fragment, null,
|
|
195
|
+
React.createElement(Paper, { style: _backgroundCover, classes: { root: classes.cover } },
|
|
196
|
+
React.createElement(Box, { className: classes.avatar },
|
|
197
|
+
React.createElement(Avatar, null, field.imageOriginal ? React.createElement("img", { src: field.imageOriginal, alt: "avatar" }) : React.createElement(Icon, null, "icon_image"))),
|
|
198
|
+
React.createElement(React.Fragment, null,
|
|
199
|
+
React.createElement(ChangeGroupPicture, { isCreationMode: true, onChange: handleChangeAvatar }),
|
|
200
|
+
React.createElement(ChangeGroupCover, { isCreationMode: true, onChange: handleChangeCover }))),
|
|
201
|
+
React.createElement(Typography, { className: classNames(classes.header, { [classes.error]: error.emotionalImageOriginalError || error.imageOriginalError }), align: "center" }, error.emotionalImageOriginalError || error.imageOriginalError ? (React.createElement(FormattedMessage, { id: "ui.groupForm.header.error", defaultMessage: "ui.groupForm.header.error" })) : (React.createElement(FormattedMessage, { id: "ui.groupForm.header", defaultMessage: "ui.groupForm.header" })))),
|
|
202
|
+
React.createElement(FormGroup, { className: classes.form },
|
|
203
|
+
React.createElement(TextField, { required: true, className: classes.name, placeholder: `${intl.formatMessage(messages.name)}`, margin: "normal", value: field.name, name: "name", onChange: handleChange, InputProps: {
|
|
204
|
+
endAdornment: React.createElement(Typography, { variant: "body2" }, GROUP_TITLE_MAX_LENGTH - field.name.length)
|
|
205
|
+
} }),
|
|
206
|
+
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)
|
|
208
|
+
} }),
|
|
209
|
+
(!group || (group && group.privacy !== SCGroupPrivacyType.PRIVATE)) && (React.createElement(Box, { className: classes.privacySection },
|
|
210
|
+
React.createElement(Typography, { variant: "h4" },
|
|
211
|
+
React.createElement(FormattedMessage, { id: "ui.groupForm.privacy.title", defaultMessage: "ui.groupForm.privacy.title", values: { b: (chunks) => React.createElement("strong", null, chunks) } })),
|
|
212
|
+
React.createElement(Stack, { direction: "row", spacing: 1, alignItems: "center" },
|
|
213
|
+
React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: !field.isPublic }) },
|
|
214
|
+
React.createElement(Icon, null, "private"),
|
|
215
|
+
React.createElement(FormattedMessage, { id: "ui.groupForm.privacy.private", defaultMessage: "ui.groupForm.privacy.private" })),
|
|
216
|
+
React.createElement(Switch, { className: classes.switch, checked: field.isPublic, onClick: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['isPublic']: !field.isPublic }))) }),
|
|
217
|
+
React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: field.isPublic }) },
|
|
218
|
+
React.createElement(Icon, null, "public"),
|
|
219
|
+
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: { b: (chunks) => React.createElement("strong", null, chunks) } })) : (React.createElement(FormattedMessage, { id: "ui.groupForm.privacy.private.info", defaultMessage: "ui.groupForm.private.public.info", values: { b: (chunks) => React.createElement("strong", null, chunks) } }))))),
|
|
221
|
+
React.createElement(Box, { className: classes.visibilitySection }, ((!field.isPublic && !group) || (group && !field.isPublic)) && (React.createElement(React.Fragment, null,
|
|
222
|
+
React.createElement(Typography, { variant: "h4" },
|
|
223
|
+
React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.title", defaultMessage: "ui.groupForm.visibility.title", values: { b: (chunks) => React.createElement("strong", null, chunks) } })),
|
|
224
|
+
React.createElement(Stack, { direction: "row", spacing: 1, alignItems: "center" },
|
|
225
|
+
React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: !field.isVisible }) },
|
|
226
|
+
React.createElement(Icon, null, "visibility_off"),
|
|
227
|
+
React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.hidden", defaultMessage: "ui.groupForm.visibility.hidden" })),
|
|
228
|
+
React.createElement(Switch, { className: classes.switch, checked: field.isVisible, onClick: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['isVisible']: !field.isVisible }))) }),
|
|
229
|
+
React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: field.isVisible }) },
|
|
230
|
+
React.createElement(Icon, null, "visibility"),
|
|
231
|
+
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: { b: (chunks) => React.createElement("strong", null, chunks) } })) : (React.createElement(FormattedMessage, { id: "ui.groupForm.visibility.visible.info", defaultMessage: "ui.groupForm.visibility.visible.info", values: { b: (chunks) => React.createElement("strong", null, chunks) } }))))))),
|
|
233
|
+
React.createElement(Divider, null),
|
|
234
|
+
React.createElement(Box, { className: classes.inviteSection },
|
|
235
|
+
React.createElement(GroupInviteButton, { handleInvitations: handleInviteSection })))));
|
|
236
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PREFIX = "SCGroupForm";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PREFIX = 'SCGroupForm';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { SCGroupType } from '@selfcommunity/types';
|
|
3
2
|
import { ChangeGroupCoverProps } from '../ChangeGroupCover';
|
|
4
3
|
import { ChangeGroupPictureProps } from '../ChangeGroupPicture';
|
|
5
4
|
import { GroupMembersButtonProps } from '../GroupMembersButton';
|
|
5
|
+
import { GroupSubscribeButtonProps } from '../GroupSubscribeButton';
|
|
6
6
|
export interface GroupHeaderProps {
|
|
7
7
|
/**
|
|
8
8
|
* Id of group object
|
|
@@ -35,14 +35,15 @@ 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
|
-
|
|
41
|
+
GroupSubscribeButtonProps?: GroupSubscribeButtonProps;
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Props to spread to the group memebers button
|
|
44
|
+
* @default {}
|
|
44
45
|
*/
|
|
45
|
-
|
|
46
|
+
GroupMembersButtonProps?: GroupMembersButtonProps;
|
|
46
47
|
/**
|
|
47
48
|
* Any other properties
|
|
48
49
|
*/
|
|
@@ -13,6 +13,9 @@ import { FormattedMessage } from 'react-intl';
|
|
|
13
13
|
import Bullet from '../../shared/Bullet';
|
|
14
14
|
import ChangeGroupPicture from '../ChangeGroupPicture';
|
|
15
15
|
import GroupMembersButton from '../GroupMembersButton';
|
|
16
|
+
import EditGroupButton from '../EditGroupButton';
|
|
17
|
+
import GroupSubscribeButton from '../GroupSubscribeButton';
|
|
18
|
+
import GroupInviteButton from '../GroupInviteButton';
|
|
16
19
|
const classes = {
|
|
17
20
|
root: `${PREFIX}-root`,
|
|
18
21
|
cover: `${PREFIX}-cover`,
|
|
@@ -63,13 +66,13 @@ const Root = styled(Box, {
|
|
|
63
66
|
* @param inProps
|
|
64
67
|
*/
|
|
65
68
|
export default function GroupHeader(inProps) {
|
|
66
|
-
var _a
|
|
69
|
+
var _a;
|
|
67
70
|
// PROPS
|
|
68
71
|
const props = useThemeProps({
|
|
69
72
|
props: inProps,
|
|
70
73
|
name: PREFIX
|
|
71
74
|
});
|
|
72
|
-
const { id = null, className = null, group, groupId = null, ChangePictureProps = {}, ChangeCoverProps = {},
|
|
75
|
+
const { id = null, className = null, group, groupId = null, ChangePictureProps = {}, ChangeCoverProps = {}, GroupSubscribeButtonProps = {}, GroupMembersButtonProps = {} } = props, rest = __rest(props, ["id", "className", "group", "groupId", "ChangePictureProps", "ChangeCoverProps", "GroupSubscribeButtonProps", "GroupMembersButtonProps"]);
|
|
73
76
|
// PREFERENCES
|
|
74
77
|
const scPreferences = useSCPreferences();
|
|
75
78
|
// CONTEXT
|
|
@@ -77,14 +80,14 @@ export default function GroupHeader(inProps) {
|
|
|
77
80
|
// HOOKS
|
|
78
81
|
const { scGroup, setSCGroup } = useSCFetchGroup({ id: groupId, group });
|
|
79
82
|
// CONST
|
|
80
|
-
const
|
|
83
|
+
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]);
|
|
81
84
|
/**
|
|
82
85
|
* Handles Change Avatar
|
|
83
86
|
* @param avatar
|
|
84
87
|
*/
|
|
85
88
|
function handleChangeAvatar(avatar) {
|
|
86
|
-
if (
|
|
87
|
-
setSCGroup(Object.assign({}, scGroup, {
|
|
89
|
+
if (isGroupAdmin) {
|
|
90
|
+
setSCGroup(Object.assign({}, scGroup, { image_big: avatar }));
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
93
|
/**
|
|
@@ -92,10 +95,16 @@ export default function GroupHeader(inProps) {
|
|
|
92
95
|
* @param cover
|
|
93
96
|
*/
|
|
94
97
|
function handleChangeCover(cover) {
|
|
95
|
-
if (
|
|
98
|
+
if (isGroupAdmin) {
|
|
96
99
|
setSCGroup(Object.assign({}, scGroup, { emotional_image: cover }));
|
|
97
100
|
}
|
|
98
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Handles callback subscribe/unsubscribe group
|
|
104
|
+
*/
|
|
105
|
+
const handleSubscribe = (group, status) => {
|
|
106
|
+
setSCGroup(Object.assign(Object.assign({}, group), { subscribers_counter: group.subscribers_counter + (status ? 1 : -1) }));
|
|
107
|
+
};
|
|
99
108
|
// RENDER
|
|
100
109
|
if (!scGroup) {
|
|
101
110
|
return React.createElement(GroupHeaderSkeleton, null);
|
|
@@ -107,12 +116,13 @@ export default function GroupHeader(inProps) {
|
|
|
107
116
|
React.createElement(Paper, { style: _backgroundCover, classes: { root: classes.cover } },
|
|
108
117
|
React.createElement(Box, { className: classes.avatar },
|
|
109
118
|
React.createElement(Avatar, null,
|
|
110
|
-
React.createElement("img", { alt: "group", src: scGroup.
|
|
111
|
-
|
|
119
|
+
React.createElement("img", { alt: "group", src: scGroup.image_big ? scGroup.image_big : '' }))),
|
|
120
|
+
isGroupAdmin && (React.createElement(React.Fragment, null,
|
|
112
121
|
React.createElement(ChangeGroupPicture, Object.assign({ groupId: scGroup.id, onChange: handleChangeAvatar, className: classes.changePicture }, ChangePictureProps)),
|
|
113
122
|
React.createElement("div", { className: classes.changeCover },
|
|
114
123
|
React.createElement(ChangeGroupCover, Object.assign({ groupId: scGroup.id, onChange: handleChangeCover }, ChangeCoverProps)))))),
|
|
115
124
|
React.createElement(Box, { className: classes.info },
|
|
125
|
+
isGroupAdmin && React.createElement(EditGroupButton, { group: scGroup, groupId: scGroup.id, onEditSuccess: (data) => setSCGroup(data) }),
|
|
116
126
|
React.createElement(Typography, { variant: "h5", className: classes.name }, scGroup.name),
|
|
117
127
|
React.createElement(Box, { className: classes.visibility },
|
|
118
128
|
scGroup.privacy === SCGroupPrivacyType.PUBLIC ? (React.createElement(Typography, { className: classes.visibilityItem },
|
|
@@ -126,9 +136,9 @@ export default function GroupHeader(inProps) {
|
|
|
126
136
|
React.createElement(FormattedMessage, { id: "ui.groupHeader.visibility.visible", defaultMessage: "ui.groupHeader.visibility.visible" }))) : (React.createElement(Typography, { className: classes.visibilityItem },
|
|
127
137
|
React.createElement(Icon, null, "visibility_off"),
|
|
128
138
|
React.createElement(FormattedMessage, { id: "ui.groupHeader.visibility.hidden", defaultMessage: "ui.groupHeader.visibility.hidden" })))),
|
|
129
|
-
React.createElement(Box, { className: classes.members },
|
|
139
|
+
React.createElement(React.Fragment, null, ((scGroup && scGroup.privacy === SCGroupPrivacyType.PUBLIC) || isGroupAdmin) && (React.createElement(Box, { className: classes.members },
|
|
130
140
|
React.createElement(Typography, { className: classes.membersCounter, component: "div" },
|
|
131
141
|
React.createElement(FormattedMessage, { id: "ui.groupHeader.members", defaultMessage: "ui.groupHeader.members", values: { total: scGroup.subscribers_counter } })),
|
|
132
|
-
React.createElement(GroupMembersButton, Object.assign({ groupId: scGroup === null || scGroup === void 0 ? void 0 : scGroup.id, group: scGroup }, GroupMembersButtonProps))),
|
|
133
|
-
|
|
142
|
+
React.createElement(GroupMembersButton, Object.assign({ groupId: scGroup === null || scGroup === void 0 ? void 0 : scGroup.id, group: scGroup, autoHide: !isGroupAdmin }, GroupMembersButtonProps))))),
|
|
143
|
+
isGroupAdmin ? (React.createElement(GroupInviteButton, { group: scGroup, groupId: scGroup.id })) : (React.createElement(GroupSubscribeButton, Object.assign({ group: scGroup, onSubscribe: handleSubscribe }, GroupSubscribeButtonProps))))));
|
|
134
144
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* > API documentation for the Community-JS Group
|
|
2
|
+
* > API documentation for the Community-JS Group Header Skeleton component. Learn about the available props and the CSS API.
|
|
3
3
|
|
|
4
4
|
#### Import
|
|
5
5
|
|
|
@@ -18,9 +18,7 @@
|
|
|
18
18
|
|root|.SCGroupHeader-skeleton-root|Styles applied to the root element.|
|
|
19
19
|
|avatar|.SCGroupHeader-avatar|Styles applied to the avatar element.|
|
|
20
20
|
|cover|.SCGroupHeader-cover|Styles applied to the cover element.|
|
|
21
|
-
|
|
|
22
|
-
|section|.SCGroupHeader-section|Styles applied to the info section.|
|
|
23
|
-
|username|.SCGroupHeader-username|Styles applied to the username element.|
|
|
21
|
+
|info|.SCGroupHeader-info|Styles applied to the info info.|
|
|
24
22
|
*
|
|
25
23
|
*/
|
|
26
24
|
declare function GroupHeaderSkeleton(): JSX.Element;
|
|
@@ -7,16 +7,14 @@ const classes = {
|
|
|
7
7
|
root: `${PREFIX}-skeleton-root`,
|
|
8
8
|
cover: `${PREFIX}-cover`,
|
|
9
9
|
avatar: `${PREFIX}-avatar`,
|
|
10
|
-
|
|
11
|
-
section: `${PREFIX}-section`,
|
|
12
|
-
username: `${PREFIX}-username`
|
|
10
|
+
info: `${PREFIX}-info`
|
|
13
11
|
};
|
|
14
12
|
const Root = styled(Box, {
|
|
15
13
|
name: PREFIX,
|
|
16
14
|
slot: 'SkeletonRoot'
|
|
17
15
|
})(() => ({}));
|
|
18
16
|
/**
|
|
19
|
-
* > API documentation for the Community-JS Group
|
|
17
|
+
* > API documentation for the Community-JS Group Header Skeleton component. Learn about the available props and the CSS API.
|
|
20
18
|
|
|
21
19
|
#### Import
|
|
22
20
|
|
|
@@ -35,9 +33,7 @@ const Root = styled(Box, {
|
|
|
35
33
|
|root|.SCGroupHeader-skeleton-root|Styles applied to the root element.|
|
|
36
34
|
|avatar|.SCGroupHeader-avatar|Styles applied to the avatar element.|
|
|
37
35
|
|cover|.SCGroupHeader-cover|Styles applied to the cover element.|
|
|
38
|
-
|
|
|
39
|
-
|section|.SCGroupHeader-section|Styles applied to the info section.|
|
|
40
|
-
|username|.SCGroupHeader-username|Styles applied to the username element.|
|
|
36
|
+
|info|.SCGroupHeader-info|Styles applied to the info info.|
|
|
41
37
|
*
|
|
42
38
|
*/
|
|
43
39
|
function GroupHeaderSkeleton() {
|
|
@@ -46,8 +42,12 @@ function GroupHeaderSkeleton() {
|
|
|
46
42
|
React.createElement(Skeleton, { className: classes.cover, animation: "wave", variant: "rectangular" }),
|
|
47
43
|
React.createElement(Box, { className: classes.avatar },
|
|
48
44
|
React.createElement(Skeleton, { animation: "wave", variant: "circular", width: theme.selfcommunity.group.avatar.sizeLarge, height: theme.selfcommunity.group.avatar.sizeLarge })),
|
|
49
|
-
React.createElement(Box, { className: classes.
|
|
50
|
-
React.createElement(Typography, { variant: "h5"
|
|
51
|
-
React.createElement(Skeleton, { animation: "wave", sx: { height: 30, width:
|
|
45
|
+
React.createElement(Box, { className: classes.info },
|
|
46
|
+
React.createElement(Typography, { variant: "h5" },
|
|
47
|
+
React.createElement(Skeleton, { animation: "wave", sx: { height: 30, width: 200 } })),
|
|
48
|
+
React.createElement(Typography, null,
|
|
49
|
+
React.createElement(Skeleton, { animation: "wave", sx: { height: 20, width: 150 } })),
|
|
50
|
+
React.createElement(Typography, null,
|
|
51
|
+
React.createElement(Skeleton, { animation: "wave", sx: { height: 20, width: 100 } })))));
|
|
52
52
|
}
|
|
53
53
|
export default GroupHeaderSkeleton;
|