@selfcommunity/react-ui 0.7.9-alpha.2 → 0.7.9-alpha.4
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/Composer/Attributes/Attributes.d.ts +1 -1
- package/lib/cjs/components/Composer/Attributes/Attributes.js +7 -0
- package/lib/cjs/components/Composer/Composer.d.ts +2 -1
- package/lib/cjs/components/Composer/Composer.js +40 -11
- package/lib/cjs/components/Composer/Content/ContentDiscussion/ContentDiscussion.js +7 -3
- package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +9 -2
- package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.js +35 -13
- 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 +57 -0
- package/lib/cjs/components/EditGroupButton/index.d.ts +3 -0
- package/lib/cjs/components/EditGroupButton/index.js +5 -0
- package/lib/cjs/components/Group/Group.d.ts +4 -3
- package/lib/cjs/components/Group/Group.js +2 -2
- 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.js +4 -2
- package/lib/cjs/components/GroupInfoWidget/GroupInfoWidget.js +8 -8
- package/lib/cjs/components/GroupInviteButton/GroupInviteButton.js +6 -4
- package/lib/cjs/components/GroupMembersWidget/GroupMembersWidget.js +19 -14
- package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.js +11 -1
- package/lib/cjs/components/Groups/Groups.d.ts +65 -0
- package/lib/cjs/components/Groups/Groups.js +181 -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/NavigationToolbar/NavigationToolbar.js +5 -1
- package/lib/cjs/index.d.ts +5 -3
- package/lib/cjs/index.js +10 -4
- package/lib/esm/components/BottomNavigation/BottomNavigation.js +3 -1
- package/lib/esm/components/Composer/Attributes/Attributes.d.ts +1 -1
- package/lib/esm/components/Composer/Attributes/Attributes.js +7 -0
- package/lib/esm/components/Composer/Composer.d.ts +2 -1
- package/lib/esm/components/Composer/Composer.js +40 -11
- package/lib/esm/components/Composer/Content/ContentDiscussion/ContentDiscussion.js +7 -3
- package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +9 -2
- package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.js +34 -13
- 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 +54 -0
- package/lib/esm/components/EditGroupButton/index.d.ts +3 -0
- package/lib/esm/components/EditGroupButton/index.js +2 -0
- package/lib/esm/components/Group/Group.d.ts +4 -3
- package/lib/esm/components/Group/Group.js +2 -2
- 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.js +4 -2
- package/lib/esm/components/GroupInfoWidget/GroupInfoWidget.js +8 -8
- package/lib/esm/components/GroupInviteButton/GroupInviteButton.js +6 -4
- package/lib/esm/components/GroupMembersWidget/GroupMembersWidget.js +20 -15
- package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.js +11 -1
- package/lib/esm/components/Groups/Groups.d.ts +65 -0
- package/lib/esm/components/Groups/Groups.js +178 -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/NavigationToolbar/NavigationToolbar.js +5 -1
- package/lib/esm/index.d.ts +5 -3
- package/lib/esm/index.js +4 -2
- 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
|
@@ -36,7 +36,7 @@ const Root = (0, styles_1.styled)(BaseItem_1.default, {
|
|
|
36
36
|
*/
|
|
37
37
|
function GroupSkeleton(props) {
|
|
38
38
|
const theme = (0, material_1.useTheme)();
|
|
39
|
-
return (react_1.default.createElement(Root, Object.assign({ className: classes.root }, props, { image: react_1.default.createElement(Skeleton_1.default, { animation: "wave", variant: "circular", width: theme.selfcommunity.
|
|
39
|
+
return (react_1.default.createElement(Root, Object.assign({ className: classes.root }, props, { image: react_1.default.createElement(Skeleton_1.default, { animation: "wave", variant: "circular", width: theme.selfcommunity.group.avatar.sizeSmall, height: theme.selfcommunity.group.avatar.sizeSmall }), primary: react_1.default.createElement(Skeleton_1.default, { animation: "wave", height: 10, width: 120, style: { marginBottom: 10 } }), secondary: react_1.default.createElement(Skeleton_1.default, { animation: "wave", height: 10, width: 70, style: { marginBottom: 10 } }), actions: react_1.default.createElement(material_1.Button, { size: "small", variant: "outlined", disabled: true },
|
|
40
40
|
react_1.default.createElement(Skeleton_1.default, { animation: "wave", height: 10, width: 30, style: { marginTop: 5, marginBottom: 5 } })) })));
|
|
41
41
|
}
|
|
42
42
|
exports.default = GroupSkeleton;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { TextFieldProps } from '@mui/material/TextField';
|
|
2
|
+
import { AutocompleteProps } from '@mui/material';
|
|
3
|
+
import { SCGroupType } from '@selfcommunity/types/src/index';
|
|
4
|
+
export interface GroupAutocompleteProps extends Pick<AutocompleteProps<SCGroupType | null, any, any, any>, Exclude<keyof AutocompleteProps<SCGroupType | null, any, any, any>, 'open' | 'onOpen' | 'onClose' | 'onChange' | 'filterSelectedOptions' | 'disableCloseOnSelect' | 'options' | 'getOptionLabel' | 'value' | 'selectOnFocus' | 'clearOnBlur' | 'blurOnSelect' | 'handleHomeEndKeys' | 'clearIcon' | 'noOptionsText' | 'isOptionEqualToValue' | 'renderTags' | 'renderOption' | 'renderInput'>> {
|
|
5
|
+
/**
|
|
6
|
+
* The maximum number of groups that will be visible when not focused.
|
|
7
|
+
* @default 0
|
|
8
|
+
*/
|
|
9
|
+
limitCountGroups?: number;
|
|
10
|
+
/**
|
|
11
|
+
* If checkbox is selected
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
checkboxSelect?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The props applied to text field
|
|
17
|
+
* @default {variant: 'outlined, label: groups_label}
|
|
18
|
+
*/
|
|
19
|
+
TextFieldProps?: TextFieldProps;
|
|
20
|
+
/**
|
|
21
|
+
* Callback for change event on poll object
|
|
22
|
+
* @param value
|
|
23
|
+
*/
|
|
24
|
+
onChange?: (value: any) => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* > API documentation for the Community-JS Group Autocomplete component. Learn about the available props and the CSS API.
|
|
28
|
+
*
|
|
29
|
+
*
|
|
30
|
+
* This component renders a bar that allows users to search (with autocomplete) for all the groups available in the application.
|
|
31
|
+
* Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/GroupAutocomplete)
|
|
32
|
+
*
|
|
33
|
+
* #### Import
|
|
34
|
+
* ```jsx
|
|
35
|
+
* import {GroupAutocomplete} from '@selfcommunity/react-ui';
|
|
36
|
+
* ```
|
|
37
|
+
* #### Component Name
|
|
38
|
+
* The name `SCGroupAutocomplete` can be used when providing style overrides in the theme.
|
|
39
|
+
*
|
|
40
|
+
* #### CSS
|
|
41
|
+
*
|
|
42
|
+
* |Rule Name|Global class|Description|
|
|
43
|
+
* |---|---|---|
|
|
44
|
+
* |root|.SCGroupAutocomplete-root|Styles applied to the root element.|
|
|
45
|
+
*
|
|
46
|
+
* @param inProps
|
|
47
|
+
*/
|
|
48
|
+
declare const GroupAutocomplete: (inProps: GroupAutocompleteProps) => JSX.Element;
|
|
49
|
+
export default GroupAutocomplete;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
|
+
const react_intl_1 = require("react-intl");
|
|
6
|
+
const Autocomplete_1 = tslib_1.__importDefault(require("@mui/material/Autocomplete"));
|
|
7
|
+
const TextField_1 = tslib_1.__importDefault(require("@mui/material/TextField"));
|
|
8
|
+
const CircularProgress_1 = tslib_1.__importDefault(require("@mui/material/CircularProgress"));
|
|
9
|
+
const parse_1 = tslib_1.__importDefault(require("autosuggest-highlight/parse"));
|
|
10
|
+
const match_1 = tslib_1.__importDefault(require("autosuggest-highlight/match"));
|
|
11
|
+
const material_1 = require("@mui/material");
|
|
12
|
+
const react_core_1 = require("@selfcommunity/react-core");
|
|
13
|
+
const styles_1 = require("@mui/material/styles");
|
|
14
|
+
const system_1 = require("@mui/system");
|
|
15
|
+
const PREFIX = 'SCGroupAutocomplete';
|
|
16
|
+
const classes = {
|
|
17
|
+
root: `${PREFIX}-root`
|
|
18
|
+
};
|
|
19
|
+
const Root = (0, styles_1.styled)(Autocomplete_1.default, {
|
|
20
|
+
name: PREFIX,
|
|
21
|
+
slot: 'Root',
|
|
22
|
+
overridesResolver: (props, styles) => styles.root
|
|
23
|
+
})(() => ({}));
|
|
24
|
+
/**
|
|
25
|
+
* > API documentation for the Community-JS Group Autocomplete component. Learn about the available props and the CSS API.
|
|
26
|
+
*
|
|
27
|
+
*
|
|
28
|
+
* This component renders a bar that allows users to search (with autocomplete) for all the groups available in the application.
|
|
29
|
+
* Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/GroupAutocomplete)
|
|
30
|
+
*
|
|
31
|
+
* #### Import
|
|
32
|
+
* ```jsx
|
|
33
|
+
* import {GroupAutocomplete} from '@selfcommunity/react-ui';
|
|
34
|
+
* ```
|
|
35
|
+
* #### Component Name
|
|
36
|
+
* The name `SCGroupAutocomplete` can be used when providing style overrides in the theme.
|
|
37
|
+
*
|
|
38
|
+
* #### CSS
|
|
39
|
+
*
|
|
40
|
+
* |Rule Name|Global class|Description|
|
|
41
|
+
* |---|---|---|
|
|
42
|
+
* |root|.SCGroupAutocomplete-root|Styles applied to the root element.|
|
|
43
|
+
*
|
|
44
|
+
* @param inProps
|
|
45
|
+
*/
|
|
46
|
+
const GroupAutocomplete = (inProps) => {
|
|
47
|
+
const props = (0, system_1.useThemeProps)({
|
|
48
|
+
props: inProps,
|
|
49
|
+
name: PREFIX
|
|
50
|
+
});
|
|
51
|
+
// Props
|
|
52
|
+
const { onChange, defaultValue = null, disabled = false, TextFieldProps = {
|
|
53
|
+
variant: 'outlined',
|
|
54
|
+
label: react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupAutocomplete.label", defaultMessage: "ui.groupAutocomplete.label" })
|
|
55
|
+
} } = props, rest = tslib_1.__rest(props, ["onChange", "defaultValue", "disabled", "TextFieldProps"]);
|
|
56
|
+
// State
|
|
57
|
+
const [open, setOpen] = (0, react_1.useState)(false);
|
|
58
|
+
const [value, setValue] = (0, react_1.useState)(typeof defaultValue === 'string' ? null : defaultValue);
|
|
59
|
+
// HOOKS
|
|
60
|
+
const { groups, isLoading } = (0, react_core_1.useSCFetchGroups)();
|
|
61
|
+
(0, react_1.useEffect)(() => {
|
|
62
|
+
if (value === null) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
onChange && onChange(value);
|
|
66
|
+
}, [value]);
|
|
67
|
+
(0, react_1.useEffect)(() => {
|
|
68
|
+
if (!isLoading && typeof defaultValue === 'string') {
|
|
69
|
+
setValue(groups.find((g) => g.id === Number(defaultValue)));
|
|
70
|
+
}
|
|
71
|
+
}, [isLoading]);
|
|
72
|
+
// Handlers
|
|
73
|
+
const handleOpen = () => {
|
|
74
|
+
setOpen(true);
|
|
75
|
+
};
|
|
76
|
+
const handleClose = () => {
|
|
77
|
+
setOpen(false);
|
|
78
|
+
};
|
|
79
|
+
const handleChange = (event, value) => {
|
|
80
|
+
setValue(value);
|
|
81
|
+
};
|
|
82
|
+
// Render
|
|
83
|
+
return (react_1.default.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_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupAutocomplete.empty", defaultMessage: "ui.groupAutocomplete.empty" }), onChange: handleChange, isOptionEqualToValue: (option, value) => value.id === option.id,
|
|
84
|
+
// renderTags={(value, getTagProps) => {
|
|
85
|
+
// return value.map((option: any, index) => (
|
|
86
|
+
// <Chip key={option.id} id={option.id} label={option.name} color={option.color} {...getTagProps({index})} />
|
|
87
|
+
// ));
|
|
88
|
+
// }}
|
|
89
|
+
renderOption: (props, option, { inputValue }) => {
|
|
90
|
+
const matches = (0, match_1.default)(option.name, inputValue);
|
|
91
|
+
const parts = (0, parse_1.default)(option.name, matches);
|
|
92
|
+
return (react_1.default.createElement(material_1.Box, Object.assign({ component: "li" }, props),
|
|
93
|
+
react_1.default.createElement(material_1.Avatar, { alt: option.name, src: option.image_small, sx: { marginRight: 1 } }),
|
|
94
|
+
react_1.default.createElement(react_1.default.Fragment, null, parts.map((part, index) => (react_1.default.createElement(material_1.Typography, { key: index, sx: { fontWeight: part.highlight ? 700 : 400, marginRight: 0.2 } }, part.text))))));
|
|
95
|
+
}, renderInput: (params) => {
|
|
96
|
+
return (react_1.default.createElement(TextField_1.default, Object.assign({}, params, TextFieldProps, { margin: "dense", InputProps: Object.assign(Object.assign({}, params.InputProps), { autoComplete: 'groups', endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
97
|
+
isLoading ? react_1.default.createElement(CircularProgress_1.default, { color: "inherit", size: 20 }) : null,
|
|
98
|
+
params.InputProps.endAdornment)) }) })));
|
|
99
|
+
} }, rest)));
|
|
100
|
+
};
|
|
101
|
+
exports.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,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
|
+
const system_1 = require("@mui/system");
|
|
6
|
+
const styles_1 = require("@mui/material/styles");
|
|
7
|
+
const material_1 = require("@mui/material");
|
|
8
|
+
const react_intl_1 = require("react-intl");
|
|
9
|
+
const react_core_1 = require("@selfcommunity/react-core");
|
|
10
|
+
const classnames_1 = tslib_1.__importDefault(require("classnames"));
|
|
11
|
+
const constants_1 = require("./constants");
|
|
12
|
+
const BaseDialog_1 = tslib_1.__importDefault(require("../../shared/BaseDialog"));
|
|
13
|
+
const lab_1 = require("@mui/lab");
|
|
14
|
+
const ChangeGroupPicture_1 = tslib_1.__importDefault(require("../ChangeGroupPicture"));
|
|
15
|
+
const ChangeGroupCover_1 = tslib_1.__importDefault(require("../ChangeGroupCover"));
|
|
16
|
+
const Group_1 = require("../../constants/Group");
|
|
17
|
+
const GroupInviteButton_1 = tslib_1.__importDefault(require("../GroupInviteButton"));
|
|
18
|
+
const types_1 = require("@selfcommunity/types");
|
|
19
|
+
const Errors_1 = require("../../constants/Errors");
|
|
20
|
+
const api_services_1 = require("@selfcommunity/api-services");
|
|
21
|
+
const utils_1 = require("@selfcommunity/utils");
|
|
22
|
+
const messages = (0, react_intl_1.defineMessages)({
|
|
23
|
+
name: {
|
|
24
|
+
id: 'ui.groupForm.name.placeholder',
|
|
25
|
+
defaultMessage: 'ui.groupForm.name.placeholder'
|
|
26
|
+
},
|
|
27
|
+
description: {
|
|
28
|
+
id: 'ui.groupForm.description.placeholder',
|
|
29
|
+
defaultMessage: 'ui.groupForm.description.placeholder'
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const classes = {
|
|
33
|
+
root: `${constants_1.PREFIX}-root`,
|
|
34
|
+
active: `${constants_1.PREFIX}-active`,
|
|
35
|
+
title: `${constants_1.PREFIX}-title`,
|
|
36
|
+
header: `${constants_1.PREFIX}-header`,
|
|
37
|
+
cover: `${constants_1.PREFIX}-cover`,
|
|
38
|
+
avatar: `${constants_1.PREFIX}-avatar`,
|
|
39
|
+
form: `${constants_1.PREFIX}-form`,
|
|
40
|
+
switch: `${constants_1.PREFIX}-switch`,
|
|
41
|
+
switchLabel: `${constants_1.PREFIX}-switch-label`,
|
|
42
|
+
name: `${constants_1.PREFIX}-name`,
|
|
43
|
+
description: `${constants_1.PREFIX}-description`,
|
|
44
|
+
content: `${constants_1.PREFIX}-content`,
|
|
45
|
+
privacySection: `${constants_1.PREFIX}-privacy-section`,
|
|
46
|
+
privacySectionInfo: `${constants_1.PREFIX}-privacy-section-info`,
|
|
47
|
+
visibilitySection: `${constants_1.PREFIX}-visibility-section`,
|
|
48
|
+
visibilitySectionInfo: `${constants_1.PREFIX}-visibility-section-info`,
|
|
49
|
+
inviteSection: `${constants_1.PREFIX}-invite-section`,
|
|
50
|
+
error: `${constants_1.PREFIX}-error`
|
|
51
|
+
};
|
|
52
|
+
const Root = (0, styles_1.styled)(BaseDialog_1.default, {
|
|
53
|
+
name: constants_1.PREFIX,
|
|
54
|
+
slot: 'Root'
|
|
55
|
+
})(() => ({}));
|
|
56
|
+
/**
|
|
57
|
+
*> API documentation for the Community-JS Group Form component. Learn about the available props and the CSS API.
|
|
58
|
+
*
|
|
59
|
+
#### Import
|
|
60
|
+
```jsx
|
|
61
|
+
import {GroupForm} from '@selfcommunity/react-ui';
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### Component Name
|
|
65
|
+
The name `SCGroupForm` can be used when providing style overrides in the theme.
|
|
66
|
+
|
|
67
|
+
#### CSS
|
|
68
|
+
|
|
69
|
+
|Rule Name|Global class|Description|
|
|
70
|
+
|---|---|---|
|
|
71
|
+
|root|.SCGroupForm-root|Styles applied to the root element.|
|
|
72
|
+
|active|.SCGroupForm-active|Styles applied to the active element.|
|
|
73
|
+
|title|.SCGroupForm-title|Styles applied to the title element.|
|
|
74
|
+
|header|.SCGroupForm-header|Styles applied to the header element.|
|
|
75
|
+
|cover|.SCGroupForm-cover|Styles applied to the cover field.|
|
|
76
|
+
|avatar|.SCGroupForm-avatar|Styles applied to the avatar field.|
|
|
77
|
+
|form|.SCGroupForm-form|Styles applied to the form element.|
|
|
78
|
+
|switch|.SCGroupForm-switch|Styles applied to the switch element.|
|
|
79
|
+
|switchLabel|.SCGroupForm-switch-label|Styles applied to the switchLabel element.|
|
|
80
|
+
|name|.SCGroupForm-name|Styles applied to the name field.|
|
|
81
|
+
|description|.SCGroupForm-description|Styles applied to the description field.|
|
|
82
|
+
|content|.SCGroupForm-content|Styles applied to the element.|
|
|
83
|
+
|privacySection|.SCGroupForm-privacy-section|Styles applied to the privacy section.|
|
|
84
|
+
|privacySectionInfo|.SCGroupForm-privacy-section-info|Styles applied to the privacy info section.|
|
|
85
|
+
|visibilitySection|.SCGroupForm-visibility-section|Styles applied to the visibility section.|
|
|
86
|
+
|visibilitySectionInfo|.SCGroupForm-visibility-section-info|Styles applied to the visibility section info.|
|
|
87
|
+
|inviteSection|.SCGroupForm-invite-section|Styles applied to the invite section.|
|
|
88
|
+
|error|.SCGroupForm-error|Styles applied to the error elements.|
|
|
89
|
+
|
|
90
|
+
* @param inProps
|
|
91
|
+
*/
|
|
92
|
+
function GroupForm(inProps) {
|
|
93
|
+
//PROPS
|
|
94
|
+
const props = (0, system_1.useThemeProps)({
|
|
95
|
+
props: inProps,
|
|
96
|
+
name: constants_1.PREFIX
|
|
97
|
+
});
|
|
98
|
+
const { className, open = true, onClose, onSuccess, group = null } = props, rest = tslib_1.__rest(props, ["className", "open", "onClose", "onSuccess", "group"]);
|
|
99
|
+
const initialFieldState = {
|
|
100
|
+
imageOriginal: group ? group.image_medium : '',
|
|
101
|
+
imageOriginalFile: '',
|
|
102
|
+
emotionalImageOriginal: group ? group.emotional_image : '',
|
|
103
|
+
emotionalImageOriginalFile: '',
|
|
104
|
+
name: group ? group.name : '',
|
|
105
|
+
description: group ? group.description : '',
|
|
106
|
+
isPublic: group && group.privacy === types_1.SCGroupPrivacyType.PUBLIC,
|
|
107
|
+
isVisible: group ? group.visible : true,
|
|
108
|
+
invitedUsers: null,
|
|
109
|
+
isSubmitting: false
|
|
110
|
+
};
|
|
111
|
+
// STATE
|
|
112
|
+
const [field, setField] = (0, react_1.useState)(initialFieldState);
|
|
113
|
+
const [error, setError] = (0, react_1.useState)({});
|
|
114
|
+
// INTL
|
|
115
|
+
const intl = (0, react_intl_1.useIntl)();
|
|
116
|
+
// PREFERENCES
|
|
117
|
+
const scPreferences = (0, react_core_1.useSCPreferences)();
|
|
118
|
+
const _backgroundCover = Object.assign({}, (field.emotionalImageOriginal
|
|
119
|
+
? { background: `url('${field.emotionalImageOriginal}') center / cover` }
|
|
120
|
+
: { background: `url('${scPreferences.preferences[react_core_1.SCPreferences.IMAGES_USER_DEFAULT_COVER].value}') center / cover` }));
|
|
121
|
+
function handleChangeAvatar(avatar) {
|
|
122
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['imageOriginalFile']: avatar })));
|
|
123
|
+
const reader = new FileReader();
|
|
124
|
+
reader.onloadend = () => {
|
|
125
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['imageOriginal']: reader.result })));
|
|
126
|
+
};
|
|
127
|
+
reader.readAsDataURL(avatar);
|
|
128
|
+
if (error.imageOriginalError) {
|
|
129
|
+
delete error.imageOriginalError;
|
|
130
|
+
setError(error);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function handleChangeCover(cover) {
|
|
134
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['emotionalImageOriginalFile']: cover })));
|
|
135
|
+
const reader = new FileReader();
|
|
136
|
+
reader.onloadend = () => {
|
|
137
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['emotionalImageOriginal']: reader.result })));
|
|
138
|
+
};
|
|
139
|
+
reader.readAsDataURL(cover);
|
|
140
|
+
if (error.emotionalImageOriginalError) {
|
|
141
|
+
delete error.emotionalImageOriginalError;
|
|
142
|
+
setError(error);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const handleSubmit = () => {
|
|
146
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: true })));
|
|
147
|
+
const formData = new FormData();
|
|
148
|
+
formData.append('name', field.name);
|
|
149
|
+
formData.append('description', field.description);
|
|
150
|
+
formData.append('privacy', field.isPublic ? types_1.SCGroupPrivacyType.PUBLIC : types_1.SCGroupPrivacyType.PRIVATE);
|
|
151
|
+
formData.append('visible', field.isVisible);
|
|
152
|
+
if (field.imageOriginalFile) {
|
|
153
|
+
formData.append('image_original', field.imageOriginalFile);
|
|
154
|
+
}
|
|
155
|
+
if (field.emotionalImageOriginalFile) {
|
|
156
|
+
formData.append('emotional_image_original', field.emotionalImageOriginalFile);
|
|
157
|
+
}
|
|
158
|
+
for (const key in field.invitedUsers) {
|
|
159
|
+
formData.append(key, field.invitedUsers[key]);
|
|
160
|
+
}
|
|
161
|
+
let groupService;
|
|
162
|
+
if (group) {
|
|
163
|
+
groupService = api_services_1.GroupService.updateGroup(group.id, formData, { headers: { 'Content-Type': 'multipart/form-data' } });
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
groupService = api_services_1.GroupService.createGroup(formData, { headers: { 'Content-Type': 'multipart/form-data' } });
|
|
167
|
+
}
|
|
168
|
+
groupService
|
|
169
|
+
.then((data) => {
|
|
170
|
+
onSuccess && onSuccess(data);
|
|
171
|
+
onClose && onClose();
|
|
172
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: false })));
|
|
173
|
+
})
|
|
174
|
+
.catch((e) => {
|
|
175
|
+
setError(Object.assign(Object.assign({}, error), (0, api_services_1.formatHttpErrorCode)(e)));
|
|
176
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: false })));
|
|
177
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_UI, e);
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
const handleInviteSection = (data) => {
|
|
181
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { ['invitedUsers']: data })));
|
|
182
|
+
};
|
|
183
|
+
const handleChange = (event) => {
|
|
184
|
+
const { name, value } = event.target;
|
|
185
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { [name]: value })));
|
|
186
|
+
if (error[`${name}Error`]) {
|
|
187
|
+
delete error[`${name}Error`];
|
|
188
|
+
setError(error);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Renders root object
|
|
193
|
+
*/
|
|
194
|
+
return (react_1.default.createElement(Root, Object.assign({ DialogContentProps: { dividers: false }, title: group ? (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.title.edit", defaultMessage: "ui.groupForm.title.edit" })) : (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.title", defaultMessage: "ui.groupForm.title" })), open: open, onClose: onClose, className: (0, classnames_1.default)(classes.root, className), actions: react_1.default.createElement(lab_1.LoadingButton, { loading: field.isSubmitting, disabled: !field.name || Object.keys(error).length !== 0, variant: "contained", onClick: handleSubmit, color: "secondary" }, group ? (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.button.edit", defaultMessage: "ui.groupForm.button.edit" })) : (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.button.create", defaultMessage: "ui.groupForm.button.create" }))) }, rest),
|
|
195
|
+
react_1.default.createElement(react_1.default.Fragment, null,
|
|
196
|
+
react_1.default.createElement(react_1.default.Fragment, null,
|
|
197
|
+
react_1.default.createElement(material_1.Paper, { style: _backgroundCover, classes: { root: classes.cover } },
|
|
198
|
+
react_1.default.createElement(material_1.Box, { className: classes.avatar },
|
|
199
|
+
react_1.default.createElement(material_1.Avatar, null, field.imageOriginal ? react_1.default.createElement("img", { src: field.imageOriginal, alt: "avatar" }) : react_1.default.createElement(material_1.Icon, null, "icon_image"))),
|
|
200
|
+
react_1.default.createElement(react_1.default.Fragment, null,
|
|
201
|
+
react_1.default.createElement(ChangeGroupPicture_1.default, { isCreationMode: true, onChange: handleChangeAvatar }),
|
|
202
|
+
react_1.default.createElement(ChangeGroupCover_1.default, { isCreationMode: true, onChange: handleChangeCover }))),
|
|
203
|
+
react_1.default.createElement(material_1.Typography, { className: (0, classnames_1.default)(classes.header, { [classes.error]: error.emotionalImageOriginalError || error.imageOriginalError }), align: "center" }, error.emotionalImageOriginalError || error.imageOriginalError ? (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.header.error", defaultMessage: "ui.groupForm.header.error" })) : (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.header", defaultMessage: "ui.groupForm.header" })))),
|
|
204
|
+
react_1.default.createElement(material_1.FormGroup, { className: classes.form },
|
|
205
|
+
react_1.default.createElement(material_1.TextField, { required: true, className: classes.name, placeholder: `${intl.formatMessage(messages.name)}`, margin: "normal", value: field.name, name: "name", onChange: handleChange, InputProps: {
|
|
206
|
+
endAdornment: react_1.default.createElement(material_1.Typography, { variant: "body2" }, Group_1.GROUP_TITLE_MAX_LENGTH - field.name.length)
|
|
207
|
+
} }),
|
|
208
|
+
react_1.default.createElement(material_1.TextField, { multiline: true, className: classes.description, placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: {
|
|
209
|
+
endAdornment: react_1.default.createElement(material_1.Typography, { variant: "body2" }, Group_1.GROUP_DESCRIPTION_MAX_LENGTH - field.description.length)
|
|
210
|
+
} }),
|
|
211
|
+
react_1.default.createElement(material_1.Box, { className: classes.privacySection },
|
|
212
|
+
react_1.default.createElement(material_1.Typography, { variant: "h4" },
|
|
213
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.privacy.title", defaultMessage: "ui.groupForm.privacy.title", values: { b: (chunks) => react_1.default.createElement("strong", null, chunks) } })),
|
|
214
|
+
react_1.default.createElement(material_1.Stack, { direction: "row", spacing: 1, alignItems: "center" },
|
|
215
|
+
react_1.default.createElement(material_1.Typography, { className: (0, classnames_1.default)(classes.switchLabel, { [classes.active]: !field.isPublic }) },
|
|
216
|
+
react_1.default.createElement(material_1.Icon, null, "private"),
|
|
217
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.privacy.private", defaultMessage: "ui.groupForm.privacy.private" })),
|
|
218
|
+
react_1.default.createElement(material_1.Switch, { className: classes.switch, checked: field.isPublic, onClick: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['isPublic']: !field.isPublic }))) }),
|
|
219
|
+
react_1.default.createElement(material_1.Typography, { className: (0, classnames_1.default)(classes.switchLabel, { [classes.active]: field.isPublic }) },
|
|
220
|
+
react_1.default.createElement(material_1.Icon, null, "public"),
|
|
221
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.privacy.public", defaultMessage: "ui.groupForm.privacy.public" }))),
|
|
222
|
+
react_1.default.createElement(material_1.Typography, { variant: "body2", className: classes.privacySectionInfo }, field.isPublic ? (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.privacy.public.info", defaultMessage: "ui.groupForm.privacy.public.info", values: { b: (chunks) => react_1.default.createElement("strong", null, chunks) } })) : (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.privacy.private.info", defaultMessage: "ui.groupForm.private.public.info", values: { b: (chunks) => react_1.default.createElement("strong", null, chunks) } })))),
|
|
223
|
+
react_1.default.createElement(material_1.Box, { className: classes.visibilitySection }, !field.isPublic && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
224
|
+
react_1.default.createElement(material_1.Typography, { variant: "h4" },
|
|
225
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.visibility.title", defaultMessage: "ui.groupForm.visibility.title", values: { b: (chunks) => react_1.default.createElement("strong", null, chunks) } })),
|
|
226
|
+
react_1.default.createElement(material_1.Stack, { direction: "row", spacing: 1, alignItems: "center" },
|
|
227
|
+
react_1.default.createElement(material_1.Typography, { className: (0, classnames_1.default)(classes.switchLabel, { [classes.active]: !field.isVisible }) },
|
|
228
|
+
react_1.default.createElement(material_1.Icon, null, "visibility_off"),
|
|
229
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.visibility.hidden", defaultMessage: "ui.groupForm.visibility.hidden" })),
|
|
230
|
+
react_1.default.createElement(material_1.Switch, { className: classes.switch, checked: field.isVisible, onClick: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['isVisible']: !field.isVisible }))) }),
|
|
231
|
+
react_1.default.createElement(material_1.Typography, { className: (0, classnames_1.default)(classes.switchLabel, { [classes.active]: field.isVisible }) },
|
|
232
|
+
react_1.default.createElement(material_1.Icon, null, "visibility"),
|
|
233
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.visibility.visible", defaultMessage: "ui.groupForm.visibility.visible" }))),
|
|
234
|
+
react_1.default.createElement(material_1.Typography, { variant: "body2", className: classes.visibilitySectionInfo }, !field.isVisible ? (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.visibility.hidden.info", defaultMessage: "ui.groupForm.visibility.hidden.info", values: { b: (chunks) => react_1.default.createElement("strong", null, chunks) } })) : (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.visibility.visible.info", defaultMessage: "ui.groupForm.visibility.visible.info", values: { b: (chunks) => react_1.default.createElement("strong", null, chunks) } }))))))),
|
|
235
|
+
react_1.default.createElement(material_1.Divider, null),
|
|
236
|
+
react_1.default.createElement(material_1.Box, { className: classes.inviteSection },
|
|
237
|
+
react_1.default.createElement(GroupInviteButton_1.default, { handleInvitations: handleInviteSection })))));
|
|
238
|
+
}
|
|
239
|
+
exports.default = GroupForm;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PREFIX = "SCGroupForm";
|
|
@@ -15,6 +15,7 @@ const react_intl_1 = require("react-intl");
|
|
|
15
15
|
const Bullet_1 = tslib_1.__importDefault(require("../../shared/Bullet"));
|
|
16
16
|
const ChangeGroupPicture_1 = tslib_1.__importDefault(require("../ChangeGroupPicture"));
|
|
17
17
|
const GroupMembersButton_1 = tslib_1.__importDefault(require("../GroupMembersButton"));
|
|
18
|
+
const EditGroupButton_1 = tslib_1.__importDefault(require("../EditGroupButton"));
|
|
18
19
|
const classes = {
|
|
19
20
|
root: `${constants_1.PREFIX}-root`,
|
|
20
21
|
cover: `${constants_1.PREFIX}-cover`,
|
|
@@ -65,7 +66,7 @@ const Root = (0, styles_1.styled)(material_1.Box, {
|
|
|
65
66
|
* @param inProps
|
|
66
67
|
*/
|
|
67
68
|
function GroupHeader(inProps) {
|
|
68
|
-
var _a
|
|
69
|
+
var _a;
|
|
69
70
|
// PROPS
|
|
70
71
|
const props = (0, system_1.useThemeProps)({
|
|
71
72
|
props: inProps,
|
|
@@ -79,7 +80,7 @@ function GroupHeader(inProps) {
|
|
|
79
80
|
// HOOKS
|
|
80
81
|
const { scGroup, setSCGroup } = (0, react_core_1.useSCFetchGroup)({ id: groupId, group });
|
|
81
82
|
// CONST
|
|
82
|
-
const canEdit = (0, react_1.useMemo)(() => { var _a
|
|
83
|
+
const canEdit = (0, react_1.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]);
|
|
83
84
|
/**
|
|
84
85
|
* Handles Change Avatar
|
|
85
86
|
* @param avatar
|
|
@@ -115,6 +116,7 @@ function GroupHeader(inProps) {
|
|
|
115
116
|
react_1.default.createElement("div", { className: classes.changeCover },
|
|
116
117
|
react_1.default.createElement(ChangeGroupCover_1.default, Object.assign({ groupId: scGroup.id, onChange: handleChangeCover }, ChangeCoverProps)))))),
|
|
117
118
|
react_1.default.createElement(material_1.Box, { className: classes.info },
|
|
119
|
+
canEdit && react_1.default.createElement(EditGroupButton_1.default, { group: scGroup, groupId: scGroup.id, onEditSuccess: (data) => setSCGroup(data) }),
|
|
118
120
|
react_1.default.createElement(material_1.Typography, { variant: "h5", className: classes.name }, scGroup.name),
|
|
119
121
|
react_1.default.createElement(material_1.Box, { className: classes.visibility },
|
|
120
122
|
scGroup.privacy === types_1.SCGroupPrivacyType.PUBLIC ? (react_1.default.createElement(material_1.Typography, { className: classes.visibilityItem },
|
|
@@ -75,25 +75,25 @@ function GroupInfoWidget(inProps) {
|
|
|
75
75
|
react_1.default.createElement(material_1.Typography, { component: "div", className: classes.privacy }, scGroup.privacy === types_1.SCGroupPrivacyType.PUBLIC ? (react_1.default.createElement(react_1.default.Fragment, null,
|
|
76
76
|
react_1.default.createElement(material_1.Typography, { className: classes.privacyTitle },
|
|
77
77
|
react_1.default.createElement(material_1.Icon, null, "public"),
|
|
78
|
-
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.
|
|
78
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.privacy.public", defaultMessage: "ui.groupForm.privacy.public" })),
|
|
79
79
|
react_1.default.createElement(material_1.Typography, { variant: "body2" },
|
|
80
|
-
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.
|
|
80
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.privacy.public.info", defaultMessage: "ui.groupForm.privacy.public.info", values: { b: (chunks) => react_1.default.createElement("strong", null, chunks) } })))) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
81
81
|
react_1.default.createElement(material_1.Typography, { className: classes.privacyTitle },
|
|
82
82
|
react_1.default.createElement(material_1.Icon, null, "private"),
|
|
83
|
-
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.
|
|
83
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.privacy.private", defaultMessage: "ui.groupForm.privacy.private" })),
|
|
84
84
|
react_1.default.createElement(material_1.Typography, { variant: "body2" },
|
|
85
|
-
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.
|
|
85
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.privacy.private.info", defaultMessage: "ui.groupForm.private.public.info", values: { b: (chunks) => react_1.default.createElement("strong", null, chunks) } }))))),
|
|
86
86
|
scGroup.privacy === types_1.SCGroupPrivacyType.PRIVATE && (react_1.default.createElement(material_1.Typography, { component: "div", className: classes.visibility }, scGroup.visible ? (react_1.default.createElement(react_1.default.Fragment, null,
|
|
87
87
|
react_1.default.createElement(material_1.Typography, { className: classes.visibilityTitle },
|
|
88
88
|
react_1.default.createElement(material_1.Icon, null, "visibility"),
|
|
89
|
-
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.
|
|
89
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.visibility.visible", defaultMessage: "ui.groupForm.visibility.visible" })),
|
|
90
90
|
react_1.default.createElement(material_1.Typography, { variant: "body2" },
|
|
91
|
-
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.
|
|
91
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.visibility.visible.info", defaultMessage: "ui.groupForm.visibility.visible.info", values: { b: (chunks) => react_1.default.createElement("strong", null, chunks) } })))) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
92
92
|
react_1.default.createElement(material_1.Typography, { className: classes.visibilityTitle },
|
|
93
93
|
react_1.default.createElement(material_1.Icon, null, "visibility_off"),
|
|
94
|
-
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.
|
|
94
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.visibility.hidden", defaultMessage: "ui.groupForm.visibility.hidden" })),
|
|
95
95
|
react_1.default.createElement(material_1.Typography, { variant: "body2" },
|
|
96
|
-
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.
|
|
96
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupForm.visibility.hidden.info", defaultMessage: "ui.groupForm.visibility.hidden.info", values: { b: (chunks) => react_1.default.createElement("strong", null, chunks) } })))))),
|
|
97
97
|
react_1.default.createElement(material_1.Typography, { variant: "body2", className: classes.date },
|
|
98
98
|
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupInfoWidget.date", defaultMessage: "ui.groupInfoWidget.date", values: { date: intl.formatDate(scGroup.created_at, { day: 'numeric', year: 'numeric', month: 'long' }) } })))));
|
|
99
99
|
}
|
|
@@ -73,6 +73,7 @@ const DialogRoot = (0, styles_1.styled)(BaseDialog_1.default, {
|
|
|
73
73
|
* @param inProps
|
|
74
74
|
*/
|
|
75
75
|
function GroupInviteButton(inProps) {
|
|
76
|
+
var _a;
|
|
76
77
|
//PROPS
|
|
77
78
|
const props = (0, system_1.useThemeProps)({
|
|
78
79
|
props: inProps,
|
|
@@ -107,10 +108,9 @@ function GroupInviteButton(inProps) {
|
|
|
107
108
|
}
|
|
108
109
|
return [invited];
|
|
109
110
|
}, [invited]);
|
|
110
|
-
// CONST
|
|
111
|
-
const authUserId = scUserContext.user ? scUserContext.user.id : null;
|
|
112
111
|
// HOOKS
|
|
113
112
|
const { scGroup } = (0, react_core_1.useSCFetchGroup)({ id: groupId, group });
|
|
113
|
+
const canEdit = (0, react_1.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]);
|
|
114
114
|
// INTL
|
|
115
115
|
const intl = (0, react_intl_1.useIntl)();
|
|
116
116
|
function fetchResults() {
|
|
@@ -180,8 +180,10 @@ function GroupInviteButton(inProps) {
|
|
|
180
180
|
api_services_1.GroupService.inviteOrAcceptGroupRequest(scGroup.id, data)
|
|
181
181
|
.then(() => {
|
|
182
182
|
setIsSending(false);
|
|
183
|
+
setOpen(false);
|
|
183
184
|
})
|
|
184
185
|
.catch((error) => {
|
|
186
|
+
setOpen(false);
|
|
185
187
|
setLoading(false);
|
|
186
188
|
utils_1.Logger.error(Errors_1.SCOPE_SC_UI, error);
|
|
187
189
|
});
|
|
@@ -225,14 +227,14 @@ function GroupInviteButton(inProps) {
|
|
|
225
227
|
/**
|
|
226
228
|
* If there's no authUserId, component is hidden.
|
|
227
229
|
// */
|
|
228
|
-
if (!
|
|
230
|
+
if (!canEdit) {
|
|
229
231
|
return null;
|
|
230
232
|
}
|
|
231
233
|
/**
|
|
232
234
|
* Renders root object
|
|
233
235
|
*/
|
|
234
236
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
235
|
-
react_1.default.createElement(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className), onClick: handleClose,
|
|
237
|
+
react_1.default.createElement(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className), onClick: handleClose, variant: scGroup ? 'contained' : 'outlined', color: scGroup ? 'secondary' : 'inherit', startIcon: react_1.default.createElement(material_1.Icon, { fontSize: "small" }, "add") }, rest),
|
|
236
238
|
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupInviteButton", defaultMessage: "ui.groupInviteButton" })),
|
|
237
239
|
open && (react_1.default.createElement(DialogRoot, { DialogContentProps: { dividers: false }, open: true, className: classes.dialogRoot, title: react_1.default.createElement(react_1.default.Fragment, null,
|
|
238
240
|
react_1.default.createElement(material_1.IconButton, { onClick: handleClose },
|