@selfcommunity/react-ui 0.7.9-alpha.1 → 0.7.9-alpha.3

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.
Files changed (186) hide show
  1. package/lib/cjs/components/BottomNavigation/BottomNavigation.js +3 -1
  2. package/lib/cjs/components/ChangeGroupCover/ChangeGroupCover.d.ts +55 -0
  3. package/lib/cjs/components/ChangeGroupCover/ChangeGroupCover.js +117 -0
  4. package/lib/cjs/components/ChangeGroupCover/constants.d.ts +1 -0
  5. package/lib/cjs/components/ChangeGroupCover/constants.js +4 -0
  6. package/lib/cjs/components/ChangeGroupCover/index.d.ts +3 -0
  7. package/lib/cjs/components/ChangeGroupCover/index.js +5 -0
  8. package/lib/cjs/components/ChangeGroupPicture/ChangeGroupPicture.d.ts +57 -0
  9. package/lib/cjs/components/ChangeGroupPicture/ChangeGroupPicture.js +117 -0
  10. package/lib/cjs/components/ChangeGroupPicture/constants.d.ts +1 -0
  11. package/lib/cjs/components/ChangeGroupPicture/constants.js +4 -0
  12. package/lib/cjs/components/ChangeGroupPicture/index.d.ts +3 -0
  13. package/lib/cjs/components/ChangeGroupPicture/index.js +5 -0
  14. package/lib/cjs/components/CreateGroup/CreateGroup.d.ts +48 -0
  15. package/lib/cjs/components/CreateGroup/CreateGroup.js +187 -0
  16. package/lib/cjs/components/CreateGroup/constants.d.ts +1 -0
  17. package/lib/cjs/components/CreateGroup/constants.js +4 -0
  18. package/lib/cjs/components/CreateGroup/index.d.ts +3 -0
  19. package/lib/cjs/components/CreateGroup/index.js +5 -0
  20. package/lib/cjs/components/CreateGroupButton/CreateGroupButton.d.ts +38 -0
  21. package/lib/cjs/components/CreateGroupButton/CreateGroupButton.js +73 -0
  22. package/lib/cjs/components/CreateGroupButton/index.d.ts +3 -0
  23. package/lib/cjs/components/CreateGroupButton/index.js +5 -0
  24. package/lib/cjs/components/Group/Group.d.ts +67 -0
  25. package/lib/cjs/components/Group/Group.js +96 -0
  26. package/lib/cjs/components/Group/Skeleton.d.ts +22 -0
  27. package/lib/cjs/components/Group/Skeleton.js +42 -0
  28. package/lib/cjs/components/Group/constants.d.ts +1 -0
  29. package/lib/cjs/components/Group/constants.js +4 -0
  30. package/lib/cjs/components/Group/index.d.ts +4 -0
  31. package/lib/cjs/components/Group/index.js +8 -0
  32. package/lib/cjs/components/GroupHeader/GroupHeader.d.ts +83 -0
  33. package/lib/cjs/components/GroupHeader/GroupHeader.js +137 -0
  34. package/lib/cjs/components/GroupHeader/Skeleton.d.ts +27 -0
  35. package/lib/cjs/components/GroupHeader/Skeleton.js +56 -0
  36. package/lib/cjs/components/GroupHeader/constants.d.ts +1 -0
  37. package/lib/cjs/components/GroupHeader/constants.js +4 -0
  38. package/lib/cjs/components/GroupHeader/index.d.ts +4 -0
  39. package/lib/cjs/components/GroupHeader/index.js +8 -0
  40. package/lib/cjs/components/GroupInfoWidget/GroupInfoWidget.d.ts +52 -0
  41. package/lib/cjs/components/GroupInfoWidget/GroupInfoWidget.js +100 -0
  42. package/lib/cjs/components/GroupInfoWidget/Skeleton.d.ts +21 -0
  43. package/lib/cjs/components/GroupInfoWidget/Skeleton.js +38 -0
  44. package/lib/cjs/components/GroupInfoWidget/constants.d.ts +1 -0
  45. package/lib/cjs/components/GroupInfoWidget/constants.js +4 -0
  46. package/lib/cjs/components/GroupInfoWidget/index.d.ts +4 -0
  47. package/lib/cjs/components/GroupInfoWidget/index.js +8 -0
  48. package/lib/cjs/components/GroupInviteButton/GroupInviteButton.d.ts +57 -0
  49. package/lib/cjs/components/GroupInviteButton/GroupInviteButton.js +261 -0
  50. package/lib/cjs/components/GroupInviteButton/index.d.ts +3 -0
  51. package/lib/cjs/components/GroupInviteButton/index.js +5 -0
  52. package/lib/cjs/components/GroupMembersButton/GroupMembersButton.d.ts +46 -0
  53. package/lib/cjs/components/GroupMembersButton/GroupMembersButton.js +135 -0
  54. package/lib/cjs/components/GroupMembersButton/index.d.ts +3 -0
  55. package/lib/cjs/components/GroupMembersButton/index.js +5 -0
  56. package/lib/cjs/components/GroupMembersWidget/GroupMembersWidget.d.ts +79 -0
  57. package/lib/cjs/components/GroupMembersWidget/GroupMembersWidget.js +197 -0
  58. package/lib/cjs/components/GroupMembersWidget/Skeleton.d.ts +22 -0
  59. package/lib/cjs/components/GroupMembersWidget/Skeleton.js +38 -0
  60. package/lib/cjs/components/GroupMembersWidget/constants.d.ts +1 -0
  61. package/lib/cjs/components/GroupMembersWidget/constants.js +4 -0
  62. package/lib/cjs/components/GroupMembersWidget/index.d.ts +4 -0
  63. package/lib/cjs/components/GroupMembersWidget/index.js +8 -0
  64. package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +79 -0
  65. package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.js +194 -0
  66. package/lib/cjs/components/GroupRequestsWidget/Skeleton.d.ts +22 -0
  67. package/lib/cjs/components/GroupRequestsWidget/Skeleton.js +38 -0
  68. package/lib/cjs/components/GroupRequestsWidget/constants.d.ts +1 -0
  69. package/lib/cjs/components/GroupRequestsWidget/constants.js +4 -0
  70. package/lib/cjs/components/GroupRequestsWidget/index.d.ts +4 -0
  71. package/lib/cjs/components/GroupRequestsWidget/index.js +8 -0
  72. package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.d.ts +51 -0
  73. package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.js +117 -0
  74. package/lib/cjs/components/GroupSubscribeButton/index.d.ts +3 -0
  75. package/lib/cjs/components/GroupSubscribeButton/index.js +5 -0
  76. package/lib/cjs/components/Groups/Groups.d.ts +65 -0
  77. package/lib/cjs/components/Groups/Groups.js +184 -0
  78. package/lib/cjs/components/Groups/Skeleton.d.ts +22 -0
  79. package/lib/cjs/components/Groups/Skeleton.js +38 -0
  80. package/lib/cjs/components/Groups/constants.d.ts +1 -0
  81. package/lib/cjs/components/Groups/constants.js +4 -0
  82. package/lib/cjs/components/Groups/index.d.ts +4 -0
  83. package/lib/cjs/components/Groups/index.js +8 -0
  84. package/lib/cjs/components/InlineComposerWidget/InlineComposerWidget.d.ts +4 -0
  85. package/lib/cjs/components/InlineComposerWidget/InlineComposerWidget.js +2 -3
  86. package/lib/cjs/components/NavigationToolbar/NavigationToolbar.js +5 -1
  87. package/lib/cjs/components/User/User.d.ts +12 -0
  88. package/lib/cjs/components/User/User.js +5 -3
  89. package/lib/cjs/constants/Group.d.ts +2 -0
  90. package/lib/cjs/constants/Group.js +5 -0
  91. package/lib/cjs/index.d.ts +14 -1
  92. package/lib/cjs/index.js +34 -2
  93. package/lib/esm/components/BottomNavigation/BottomNavigation.js +3 -1
  94. package/lib/esm/components/ChangeGroupCover/ChangeGroupCover.d.ts +55 -0
  95. package/lib/esm/components/ChangeGroupCover/ChangeGroupCover.js +114 -0
  96. package/lib/esm/components/ChangeGroupCover/constants.d.ts +1 -0
  97. package/lib/esm/components/ChangeGroupCover/constants.js +1 -0
  98. package/lib/esm/components/ChangeGroupCover/index.d.ts +3 -0
  99. package/lib/esm/components/ChangeGroupCover/index.js +2 -0
  100. package/lib/esm/components/ChangeGroupPicture/ChangeGroupPicture.d.ts +57 -0
  101. package/lib/esm/components/ChangeGroupPicture/ChangeGroupPicture.js +114 -0
  102. package/lib/esm/components/ChangeGroupPicture/constants.d.ts +1 -0
  103. package/lib/esm/components/ChangeGroupPicture/constants.js +1 -0
  104. package/lib/esm/components/ChangeGroupPicture/index.d.ts +3 -0
  105. package/lib/esm/components/ChangeGroupPicture/index.js +2 -0
  106. package/lib/esm/components/CreateGroup/CreateGroup.d.ts +48 -0
  107. package/lib/esm/components/CreateGroup/CreateGroup.js +184 -0
  108. package/lib/esm/components/CreateGroup/constants.d.ts +1 -0
  109. package/lib/esm/components/CreateGroup/constants.js +1 -0
  110. package/lib/esm/components/CreateGroup/index.d.ts +3 -0
  111. package/lib/esm/components/CreateGroup/index.js +2 -0
  112. package/lib/esm/components/CreateGroupButton/CreateGroupButton.d.ts +38 -0
  113. package/lib/esm/components/CreateGroupButton/CreateGroupButton.js +70 -0
  114. package/lib/esm/components/CreateGroupButton/index.d.ts +3 -0
  115. package/lib/esm/components/CreateGroupButton/index.js +2 -0
  116. package/lib/esm/components/Group/Group.d.ts +67 -0
  117. package/lib/esm/components/Group/Group.js +93 -0
  118. package/lib/esm/components/Group/Skeleton.d.ts +22 -0
  119. package/lib/esm/components/Group/Skeleton.js +38 -0
  120. package/lib/esm/components/Group/constants.d.ts +1 -0
  121. package/lib/esm/components/Group/constants.js +1 -0
  122. package/lib/esm/components/Group/index.d.ts +4 -0
  123. package/lib/esm/components/Group/index.js +4 -0
  124. package/lib/esm/components/GroupHeader/GroupHeader.d.ts +83 -0
  125. package/lib/esm/components/GroupHeader/GroupHeader.js +134 -0
  126. package/lib/esm/components/GroupHeader/Skeleton.d.ts +27 -0
  127. package/lib/esm/components/GroupHeader/Skeleton.js +53 -0
  128. package/lib/esm/components/GroupHeader/constants.d.ts +1 -0
  129. package/lib/esm/components/GroupHeader/constants.js +1 -0
  130. package/lib/esm/components/GroupHeader/index.d.ts +4 -0
  131. package/lib/esm/components/GroupHeader/index.js +4 -0
  132. package/lib/esm/components/GroupInfoWidget/GroupInfoWidget.d.ts +52 -0
  133. package/lib/esm/components/GroupInfoWidget/GroupInfoWidget.js +97 -0
  134. package/lib/esm/components/GroupInfoWidget/Skeleton.d.ts +21 -0
  135. package/lib/esm/components/GroupInfoWidget/Skeleton.js +34 -0
  136. package/lib/esm/components/GroupInfoWidget/constants.d.ts +1 -0
  137. package/lib/esm/components/GroupInfoWidget/constants.js +1 -0
  138. package/lib/esm/components/GroupInfoWidget/index.d.ts +4 -0
  139. package/lib/esm/components/GroupInfoWidget/index.js +4 -0
  140. package/lib/esm/components/GroupInviteButton/GroupInviteButton.d.ts +57 -0
  141. package/lib/esm/components/GroupInviteButton/GroupInviteButton.js +258 -0
  142. package/lib/esm/components/GroupInviteButton/index.d.ts +3 -0
  143. package/lib/esm/components/GroupInviteButton/index.js +2 -0
  144. package/lib/esm/components/GroupMembersButton/GroupMembersButton.d.ts +46 -0
  145. package/lib/esm/components/GroupMembersButton/GroupMembersButton.js +132 -0
  146. package/lib/esm/components/GroupMembersButton/index.d.ts +3 -0
  147. package/lib/esm/components/GroupMembersButton/index.js +2 -0
  148. package/lib/esm/components/GroupMembersWidget/GroupMembersWidget.d.ts +79 -0
  149. package/lib/esm/components/GroupMembersWidget/GroupMembersWidget.js +194 -0
  150. package/lib/esm/components/GroupMembersWidget/Skeleton.d.ts +22 -0
  151. package/lib/esm/components/GroupMembersWidget/Skeleton.js +34 -0
  152. package/lib/esm/components/GroupMembersWidget/constants.d.ts +1 -0
  153. package/lib/esm/components/GroupMembersWidget/constants.js +1 -0
  154. package/lib/esm/components/GroupMembersWidget/index.d.ts +4 -0
  155. package/lib/esm/components/GroupMembersWidget/index.js +4 -0
  156. package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +79 -0
  157. package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.js +191 -0
  158. package/lib/esm/components/GroupRequestsWidget/Skeleton.d.ts +22 -0
  159. package/lib/esm/components/GroupRequestsWidget/Skeleton.js +34 -0
  160. package/lib/esm/components/GroupRequestsWidget/constants.d.ts +1 -0
  161. package/lib/esm/components/GroupRequestsWidget/constants.js +1 -0
  162. package/lib/esm/components/GroupRequestsWidget/index.d.ts +4 -0
  163. package/lib/esm/components/GroupRequestsWidget/index.js +4 -0
  164. package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.d.ts +51 -0
  165. package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.js +114 -0
  166. package/lib/esm/components/GroupSubscribeButton/index.d.ts +3 -0
  167. package/lib/esm/components/GroupSubscribeButton/index.js +2 -0
  168. package/lib/esm/components/Groups/Groups.d.ts +65 -0
  169. package/lib/esm/components/Groups/Groups.js +181 -0
  170. package/lib/esm/components/Groups/Skeleton.d.ts +22 -0
  171. package/lib/esm/components/Groups/Skeleton.js +34 -0
  172. package/lib/esm/components/Groups/constants.d.ts +1 -0
  173. package/lib/esm/components/Groups/constants.js +1 -0
  174. package/lib/esm/components/Groups/index.d.ts +4 -0
  175. package/lib/esm/components/Groups/index.js +4 -0
  176. package/lib/esm/components/InlineComposerWidget/InlineComposerWidget.d.ts +4 -0
  177. package/lib/esm/components/InlineComposerWidget/InlineComposerWidget.js +3 -4
  178. package/lib/esm/components/NavigationToolbar/NavigationToolbar.js +5 -1
  179. package/lib/esm/components/User/User.d.ts +12 -0
  180. package/lib/esm/components/User/User.js +5 -3
  181. package/lib/esm/constants/Group.d.ts +2 -0
  182. package/lib/esm/constants/Group.js +2 -0
  183. package/lib/esm/index.d.ts +14 -1
  184. package/lib/esm/index.js +14 -1
  185. package/lib/umd/react-ui.js +1 -1
  186. package/package.json +6 -6
@@ -0,0 +1,114 @@
1
+ import { __rest } from "tslib";
2
+ import React, { useContext, useRef, useState } from 'react';
3
+ import { styled } from '@mui/material/styles';
4
+ import { Alert } from '@mui/material';
5
+ import { SCUserContext } from '@selfcommunity/react-core';
6
+ import Icon from '@mui/material/Icon';
7
+ import { defineMessages, useIntl } from 'react-intl';
8
+ import classNames from 'classnames';
9
+ import { useThemeProps } from '@mui/system';
10
+ import { PREFIX } from './constants';
11
+ import { LoadingButton } from '@mui/lab';
12
+ import { GroupService } from '@selfcommunity/api-services';
13
+ import { SCOPE_SC_UI } from '../../constants/Errors';
14
+ import { Logger } from '@selfcommunity/utils';
15
+ const classes = {
16
+ root: `${PREFIX}-root`
17
+ };
18
+ const Root = styled(LoadingButton, {
19
+ name: PREFIX,
20
+ slot: 'Root'
21
+ })(() => ({}));
22
+ const messages = defineMessages({
23
+ errorLoadImage: {
24
+ id: 'ui.changeGroupCover.button.change.alertErrorImage',
25
+ defaultMessage: 'ui.changeGroupCover.button.change.alertErrorImage'
26
+ }
27
+ });
28
+ /**
29
+ * > API documentation for the Community-JS Change Group Cover component. Learn about the available props and the CSS API.
30
+ *
31
+ *
32
+ * This component renders a button that allows admins to edit the group cover and a popover that specifies format and sizes allowed.
33
+ * Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/ChangeGroupCover)
34
+
35
+ #### Import
36
+ ```jsx
37
+ import {ChangeGroupCover} from '@selfcommunity/react-ui';
38
+ ```
39
+
40
+ #### Component Name
41
+ The name `SCChangeGroupCoverButton` can be used when providing style overrides in the theme.
42
+
43
+ #### CSS
44
+
45
+ |Rule Name|Global class|Description|
46
+ |---|---|---|
47
+ |root|.SCChangeGroupCoverButton-root|Styles applied to the root element.|
48
+
49
+ * @param inProps
50
+ */
51
+ export default function ChangeGroupCover(inProps) {
52
+ //PROPS
53
+ const props = useThemeProps({
54
+ props: inProps,
55
+ name: PREFIX
56
+ });
57
+ const { groupId, onChange, autoHide, className, isCreationMode = false } = props, rest = __rest(props, ["groupId", "onChange", "autoHide", "className", "isCreationMode"]);
58
+ //CONTEXT
59
+ const scUserContext = useContext(SCUserContext);
60
+ //STATE
61
+ let fileInput = useRef(null);
62
+ const [loading, setLoading] = useState(false);
63
+ const [alert, setAlert] = useState(null);
64
+ // INTL
65
+ const intl = useIntl();
66
+ // Anonymous
67
+ if (!scUserContext.user) {
68
+ return null;
69
+ }
70
+ /**
71
+ * Handles file upload
72
+ * @param event
73
+ */
74
+ const handleUpload = (event) => {
75
+ fileInput = event.target.files[0];
76
+ isCreationMode ? onChange && onChange(fileInput) : handleSave();
77
+ };
78
+ /**
79
+ * Handles cover saving after upload action
80
+ */
81
+ function handleSave() {
82
+ setLoading(true);
83
+ const formData = new FormData();
84
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
85
+ // @ts-ignore
86
+ formData.append('emotional_image_original', fileInput);
87
+ GroupService.changeGroupAvatarOrCover(groupId, formData, { headers: { 'Content-Type': 'multipart/form-data' } })
88
+ .then((data) => {
89
+ onChange && onChange(data.emotional_image);
90
+ setLoading(false);
91
+ })
92
+ .catch((error) => {
93
+ Logger.error(SCOPE_SC_UI, error);
94
+ setLoading(false);
95
+ setAlert(intl.formatMessage(messages.errorLoadImage));
96
+ });
97
+ }
98
+ /**
99
+ * If there is an error
100
+ */
101
+ if (alert) {
102
+ return (React.createElement(Alert, { color: "error", onClose: () => setAlert(null) }, alert));
103
+ }
104
+ /**
105
+ * Renders root object (if not hidden by autoHide prop)
106
+ */
107
+ if (!autoHide) {
108
+ return (React.createElement(React.Fragment, null,
109
+ React.createElement("input", { type: "file", onChange: handleUpload, ref: fileInput, hidden: true, accept: ".gif,.png,.jpg,.jpeg" }),
110
+ React.createElement(Root, Object.assign({ className: classNames(classes.root, className), size: "medium", variant: "contained", disabled: loading, onClick: () => fileInput.current.click(), loading: loading }, rest),
111
+ React.createElement(Icon, null, "image"))));
112
+ }
113
+ return null;
114
+ }
@@ -0,0 +1 @@
1
+ export declare const PREFIX = "SCChangeGroupCoverButton";
@@ -0,0 +1 @@
1
+ export const PREFIX = 'SCChangeGroupCoverButton';
@@ -0,0 +1,3 @@
1
+ import ChangeGroupCover, { ChangeGroupCoverProps } from './ChangeGroupCover';
2
+ export default ChangeGroupCover;
3
+ export { ChangeGroupCoverProps };
@@ -0,0 +1,2 @@
1
+ import ChangeGroupCover from './ChangeGroupCover';
2
+ export default ChangeGroupCover;
@@ -0,0 +1,57 @@
1
+ export interface ChangeGroupPictureProps {
2
+ /**
3
+ * Id of the group. It is optional only for group creation modal.
4
+ * @default null
5
+ */
6
+ groupId?: number;
7
+ /**
8
+ * On change function.
9
+ * @default null
10
+ */
11
+ onChange?: (cover: any) => void;
12
+ /**
13
+ * Hides this component
14
+ * @default false
15
+ */
16
+ autoHide?: boolean;
17
+ /**
18
+ * Overrides or extends the styles applied to the component.
19
+ * @default null
20
+ */
21
+ className?: string;
22
+ /**
23
+ * Prop to handle avatar loading in the create group modal.
24
+ * @default false
25
+ */
26
+ isCreationMode?: boolean;
27
+ /**
28
+ * Any other properties
29
+ */
30
+ [p: string]: any;
31
+ }
32
+ /**
33
+ * > API documentation for the Community-JS Change Group Picture component. Learn about the available props and the CSS API.
34
+ *
35
+ *
36
+ * This component renders a button that allows admins to manage their group pictures.
37
+ * Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/ChangeGroupPicture)
38
+
39
+ #### Import
40
+
41
+ ```jsx
42
+ import {ChangeGroupPicture} from '@selfcommunity/react-ui';
43
+ ```
44
+
45
+ #### Component Name
46
+
47
+ The name `SCChangeGroupPictureButton` can be used when providing style overrides in the theme.
48
+
49
+ #### CSS
50
+
51
+ |Rule Name|Global class|Description|
52
+ |---|---|---|
53
+ |root|.SCChangeGroupPictureButton-root|Styles applied to the root element.|
54
+
55
+ * @param inProps
56
+ */
57
+ export default function ChangeGroupPicture(inProps: ChangeGroupPictureProps): JSX.Element;
@@ -0,0 +1,114 @@
1
+ import { __rest } from "tslib";
2
+ import React, { useContext, useRef, useState } from 'react';
3
+ import { styled } from '@mui/material/styles';
4
+ import { Alert } from '@mui/material';
5
+ import Icon from '@mui/material/Icon';
6
+ import { SCUserContext } from '@selfcommunity/react-core';
7
+ import classNames from 'classnames';
8
+ import { useThemeProps } from '@mui/system';
9
+ import { PREFIX } from './constants';
10
+ import { SCOPE_SC_UI } from '../../constants/Errors';
11
+ import { GroupService } from '@selfcommunity/api-services';
12
+ import { Logger } from '@selfcommunity/utils';
13
+ import { defineMessages, useIntl } from 'react-intl';
14
+ import { LoadingButton } from '@mui/lab';
15
+ const messages = defineMessages({
16
+ errorLoadImage: {
17
+ id: 'ui.changeGroupCover.button.change.alertErrorImage',
18
+ defaultMessage: 'ui.changeGroupCover.button.change.alertErrorImage'
19
+ }
20
+ });
21
+ const classes = {
22
+ root: `${PREFIX}-root`
23
+ };
24
+ const Root = styled(LoadingButton, {
25
+ name: PREFIX,
26
+ slot: 'Root'
27
+ })(() => ({}));
28
+ /**
29
+ * > API documentation for the Community-JS Change Group Picture component. Learn about the available props and the CSS API.
30
+ *
31
+ *
32
+ * This component renders a button that allows admins to manage their group pictures.
33
+ * Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/ChangeGroupPicture)
34
+
35
+ #### Import
36
+
37
+ ```jsx
38
+ import {ChangeGroupPicture} from '@selfcommunity/react-ui';
39
+ ```
40
+
41
+ #### Component Name
42
+
43
+ The name `SCChangeGroupPictureButton` can be used when providing style overrides in the theme.
44
+
45
+ #### CSS
46
+
47
+ |Rule Name|Global class|Description|
48
+ |---|---|---|
49
+ |root|.SCChangeGroupPictureButton-root|Styles applied to the root element.|
50
+
51
+ * @param inProps
52
+ */
53
+ export default function ChangeGroupPicture(inProps) {
54
+ //PROPS
55
+ const props = useThemeProps({
56
+ props: inProps,
57
+ name: PREFIX
58
+ });
59
+ const { groupId, onChange, autoHide, className, isCreationMode = false } = props, rest = __rest(props, ["groupId", "onChange", "autoHide", "className", "isCreationMode"]);
60
+ //STATE
61
+ const [loading, setLoading] = useState(false);
62
+ const [alert, setAlert] = useState(null);
63
+ let fileInput = useRef(null);
64
+ //CONTEXT
65
+ const scUserContext = useContext(SCUserContext);
66
+ // INTL
67
+ const intl = useIntl();
68
+ // Anonymous
69
+ if (!scUserContext.user) {
70
+ return null;
71
+ }
72
+ /**
73
+ * Handles avatar upload
74
+ * @param event
75
+ */
76
+ function handleUpload(event) {
77
+ fileInput = event.target.files[0];
78
+ isCreationMode ? onChange && onChange(fileInput) : handleSave();
79
+ }
80
+ /**
81
+ * Performs save avatar after upload
82
+ */
83
+ function handleSave() {
84
+ setLoading(true);
85
+ const formData = new FormData();
86
+ formData.append('image_original', fileInput);
87
+ GroupService.changeGroupAvatarOrCover(groupId, formData, { headers: { 'Content-Type': 'multipart/form-data' } })
88
+ .then((data) => {
89
+ setLoading(false);
90
+ onChange && onChange(data.image_bigger);
91
+ })
92
+ .catch((error) => {
93
+ setAlert(intl.formatMessage(messages.errorLoadImage));
94
+ setLoading(false);
95
+ Logger.error(SCOPE_SC_UI, error);
96
+ });
97
+ }
98
+ /**
99
+ * If there is an error
100
+ */
101
+ if (alert) {
102
+ return (React.createElement(Alert, { color: "error", onClose: () => setAlert(null) }, alert));
103
+ }
104
+ /**
105
+ * Renders the component (if not hidden by autoHide prop)
106
+ */
107
+ if (!autoHide) {
108
+ return (React.createElement(React.Fragment, null,
109
+ React.createElement("input", { type: "file", onChange: handleUpload, ref: fileInput, hidden: true, accept: ".gif,.png,.jpg,.jpeg" }),
110
+ React.createElement(Root, Object.assign({ className: classNames(classes.root, className), size: "small", variant: "contained", disabled: loading, onClick: () => fileInput.current.click(), loading: loading }, rest),
111
+ React.createElement(Icon, null, "photo_camera"))));
112
+ }
113
+ return null;
114
+ }
@@ -0,0 +1 @@
1
+ export declare const PREFIX = "SCChangeGroupPictureButton";
@@ -0,0 +1 @@
1
+ export const PREFIX = 'SCChangeGroupPictureButton';
@@ -0,0 +1,3 @@
1
+ import ChangeGroupPicture, { ChangeGroupPictureProps } from './ChangeGroupPicture';
2
+ export default ChangeGroupPicture;
3
+ export { ChangeGroupPictureProps };
@@ -0,0 +1,2 @@
1
+ import ChangeGroupPicture from './ChangeGroupPicture';
2
+ export default ChangeGroupPicture;
@@ -0,0 +1,48 @@
1
+ import { BaseDialogProps } from '../../shared/BaseDialog';
2
+ import { SCGroupType } from '@selfcommunity/types';
3
+ export interface CreateGroupProps 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
+ * Any other properties
26
+ */
27
+ [p: string]: any;
28
+ }
29
+ /**
30
+ *> API documentation for the Community-JS Create Group Button component. Learn about the available props and the CSS API.
31
+ *
32
+ #### Import
33
+ ```jsx
34
+ import {CreateGroupButton} from '@selfcommunity/react-ui';
35
+ ```
36
+
37
+ #### Component Name
38
+ The name `SCCreateGroup` can be used when providing style overrides in the theme.
39
+
40
+ #### CSS
41
+
42
+ |Rule Name|Global class|Description|
43
+ |---|---|---|
44
+ |root|.SCCreateGroup-root|Styles applied to the root element.|
45
+
46
+ * @param inProps
47
+ */
48
+ export default function CreateGroup(inProps: CreateGroupProps): JSX.Element;
@@ -0,0 +1,184 @@
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 { GroupService } from '@selfcommunity/api-services';
19
+ import { Logger } from '@selfcommunity/utils';
20
+ const messages = defineMessages({
21
+ name: {
22
+ id: 'ui.createGroup.name.placeholder',
23
+ defaultMessage: 'ui.createGroup.name.placeholder'
24
+ },
25
+ description: {
26
+ id: 'ui.createGroup.description.placeholder',
27
+ defaultMessage: 'ui.createGroup.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
+ };
49
+ const Root = styled(BaseDialog, {
50
+ name: PREFIX,
51
+ slot: 'Root'
52
+ })(() => ({}));
53
+ /**
54
+ *> API documentation for the Community-JS Create Group Button component. Learn about the available props and the CSS API.
55
+ *
56
+ #### Import
57
+ ```jsx
58
+ import {CreateGroupButton} from '@selfcommunity/react-ui';
59
+ ```
60
+
61
+ #### Component Name
62
+ The name `SCCreateGroup` can be used when providing style overrides in the theme.
63
+
64
+ #### CSS
65
+
66
+ |Rule Name|Global class|Description|
67
+ |---|---|---|
68
+ |root|.SCCreateGroup-root|Styles applied to the root element.|
69
+
70
+ * @param inProps
71
+ */
72
+ export default function CreateGroup(inProps) {
73
+ //PROPS
74
+ const props = useThemeProps({
75
+ props: inProps,
76
+ name: PREFIX
77
+ });
78
+ const { className, open = true, onClose, group } = props, rest = __rest(props, ["className", "open", "onClose", "group"]);
79
+ // TODO: fare initial state con tutti i fields per la gestione dell'edit
80
+ // STATE
81
+ const [avatar, setAvatar] = useState('');
82
+ const [cover, setCover] = useState('');
83
+ const [name, setName] = useState('');
84
+ const [invitedUsers, setInvitedUsers] = useState(null);
85
+ const [description, setDescription] = useState('');
86
+ const [isPublic, setIsPublic] = useState(true);
87
+ const [isVisible, setIsVisible] = useState(true);
88
+ const [isSubmitting, setIsSubmitting] = useState(false);
89
+ // INTL
90
+ const intl = useIntl();
91
+ // CONTEXT
92
+ // PREFERENCES
93
+ const scPreferences = useSCPreferences();
94
+ const _backgroundCover = Object.assign({}, (cover
95
+ ? { background: `url('${cover}') center / cover` }
96
+ : { background: `url('${scPreferences.preferences[SCPreferences.IMAGES_USER_DEFAULT_COVER].value}') center / cover` }));
97
+ function handleChangeAvatar(avatar) {
98
+ const reader = new FileReader();
99
+ reader.onloadend = () => {
100
+ setAvatar(reader.result);
101
+ };
102
+ reader.readAsDataURL(avatar);
103
+ }
104
+ function handleChangeCover(cover) {
105
+ const reader = new FileReader();
106
+ reader.onloadend = () => {
107
+ setCover(reader.result);
108
+ };
109
+ reader.readAsDataURL(cover);
110
+ }
111
+ const handleSubmit = () => {
112
+ setIsSubmitting(true);
113
+ const formData = new FormData();
114
+ formData.append('name', name);
115
+ formData.append('description', description);
116
+ formData.append('privacy', isPublic ? SCGroupPrivacyType.PUBLIC : SCGroupPrivacyType.PRIVATE);
117
+ formData.append('image_original', avatar);
118
+ formData.append('emotional_image_original', cover);
119
+ formData.append('visible', isVisible);
120
+ for (const key in invitedUsers) {
121
+ formData.append(key, invitedUsers[key]);
122
+ }
123
+ GroupService.createGroup(formData, { headers: { 'Content-Type': 'multipart/form-data' } })
124
+ .then((data) => {
125
+ console.log(data);
126
+ setIsSubmitting(false);
127
+ })
128
+ .catch((error) => {
129
+ setIsSubmitting(false);
130
+ Logger.error(SCOPE_SC_UI, error);
131
+ });
132
+ };
133
+ const handleInviteSection = (data) => {
134
+ setInvitedUsers(data);
135
+ };
136
+ /**
137
+ * Renders root object
138
+ */
139
+ return (React.createElement(Root, Object.assign({ DialogContentProps: { dividers: false }, title: group ? (React.createElement(FormattedMessage, { id: "ui.createGroup.title.edit", defaultMessage: "ui.createGroup.title.edit" })) : (React.createElement(FormattedMessage, { id: "ui.createGroup.title", defaultMessage: "ui.createGroup.title" })), open: open, onClose: onClose, className: classNames(classes.root, className), actions: React.createElement(LoadingButton, { loading: isSubmitting, disabled: !name, variant: "contained", onClick: handleSubmit, color: "secondary" }, group ? (React.createElement(FormattedMessage, { id: "ui.createGroup.button.edit", defaultMessage: "ui.createGroup.button.edit" })) : (React.createElement(FormattedMessage, { id: "ui.createGroup.button.create", defaultMessage: "ui.createGroup.button.create" }))) }, rest),
140
+ React.createElement(React.Fragment, null,
141
+ React.createElement(React.Fragment, null,
142
+ React.createElement(Paper, { style: _backgroundCover, classes: { root: classes.cover } },
143
+ React.createElement(Box, { className: classes.avatar },
144
+ React.createElement(Avatar, null, avatar ? React.createElement("img", { src: avatar, alt: "avatar" }) : React.createElement(Icon, null, "icon_image"))),
145
+ React.createElement(React.Fragment, null,
146
+ React.createElement(ChangeGroupPicture, { isCreationMode: true, onChange: handleChangeAvatar }),
147
+ React.createElement(ChangeGroupCover, { isCreationMode: true, onChange: handleChangeCover }))),
148
+ React.createElement(Typography, { className: classes.header, align: "center" },
149
+ React.createElement(FormattedMessage, { id: "ui.createGroup.header", defaultMessage: "ui.createGroup.header" }))),
150
+ React.createElement(FormGroup, { className: classes.form },
151
+ React.createElement(TextField, { required: true, className: classes.name, placeholder: `${intl.formatMessage(messages.name)}`, margin: "normal", value: name, onChange: (event) => setName(event.target.value), InputProps: {
152
+ endAdornment: React.createElement(Typography, { variant: "body2" }, GROUP_TITLE_MAX_LENGTH - name.length)
153
+ } }),
154
+ React.createElement(TextField, { multiline: true, className: classes.description, placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: description, onChange: (event) => setDescription(event.target.value), InputProps: {
155
+ endAdornment: React.createElement(Typography, { variant: "body2" }, GROUP_DESCRIPTION_MAX_LENGTH - description.length)
156
+ } }),
157
+ React.createElement(Box, { className: classes.privacySection },
158
+ React.createElement(Typography, { variant: "h4" },
159
+ React.createElement(FormattedMessage, { id: "ui.createGroup.privacy.title", defaultMessage: "ui.createGroup.privacy.title", values: { b: (chunks) => React.createElement("strong", null, chunks) } })),
160
+ React.createElement(Stack, { direction: "row", spacing: 1, alignItems: "center" },
161
+ React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: !isPublic }) },
162
+ React.createElement(Icon, null, "private"),
163
+ React.createElement(FormattedMessage, { id: "ui.createGroup.privacy.private", defaultMessage: "ui.createGroup.privacy.private" })),
164
+ React.createElement(Switch, { className: classes.switch, checked: isPublic, onClick: () => setIsPublic(!isPublic) }),
165
+ React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: isPublic }) },
166
+ React.createElement(Icon, null, "public"),
167
+ React.createElement(FormattedMessage, { id: "ui.createGroup.privacy.public", defaultMessage: "ui.createGroup.privacy.public" }))),
168
+ React.createElement(Typography, { variant: "body2", className: classes.privacySectionInfo }, isPublic ? (React.createElement(FormattedMessage, { id: "ui.createGroup.privacy.public.info", defaultMessage: "ui.createGroup.privacy.public.info", values: { b: (chunks) => React.createElement("strong", null, chunks) } })) : (React.createElement(FormattedMessage, { id: "ui.createGroup.privacy.private.info", defaultMessage: "ui.createGroup.private.public.info", values: { b: (chunks) => React.createElement("strong", null, chunks) } })))),
169
+ React.createElement(Box, { className: classes.visibilitySection }, !isPublic && (React.createElement(React.Fragment, null,
170
+ React.createElement(Typography, { variant: "h4" },
171
+ React.createElement(FormattedMessage, { id: "ui.createGroup.visibility.title", defaultMessage: "ui.createGroup.visibility.title", values: { b: (chunks) => React.createElement("strong", null, chunks) } })),
172
+ React.createElement(Stack, { direction: "row", spacing: 1, alignItems: "center" },
173
+ React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: !isVisible }) },
174
+ React.createElement(Icon, null, "visibility_off"),
175
+ React.createElement(FormattedMessage, { id: "ui.createGroup.visibility.hidden", defaultMessage: "ui.createGroup.visibility.hidden" })),
176
+ React.createElement(Switch, { className: classes.switch, checked: isVisible, onClick: () => setIsVisible(!isVisible) }),
177
+ React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: isVisible }) },
178
+ React.createElement(Icon, null, "visibility"),
179
+ React.createElement(FormattedMessage, { id: "ui.createGroup.visibility.visible", defaultMessage: "ui.createGroup.visibility.visible" }))),
180
+ React.createElement(Typography, { variant: "body2", className: classes.visibilitySectionInfo }, !isVisible ? (React.createElement(FormattedMessage, { id: "ui.createGroup.visibility.hidden.info", defaultMessage: "ui.createGroup.visibility.hidden.info", values: { b: (chunks) => React.createElement("strong", null, chunks) } })) : (React.createElement(FormattedMessage, { id: "ui.createGroup.visibility.visible.info", defaultMessage: "ui.createGroup.visibility.visible.info", values: { b: (chunks) => React.createElement("strong", null, chunks) } }))))))),
181
+ React.createElement(Divider, null),
182
+ React.createElement(Box, { className: classes.inviteSection },
183
+ React.createElement(GroupInviteButton, { handleInvitations: handleInviteSection })))));
184
+ }
@@ -0,0 +1 @@
1
+ export declare const PREFIX = "SCCreateGroup";
@@ -0,0 +1 @@
1
+ export const PREFIX = 'SCCreateGroup';
@@ -0,0 +1,3 @@
1
+ import CreateGroup, { CreateGroupProps } from './CreateGroup';
2
+ export default CreateGroup;
3
+ export { CreateGroupProps };
@@ -0,0 +1,2 @@
1
+ import CreateGroup from './CreateGroup';
2
+ export default CreateGroup;
@@ -0,0 +1,38 @@
1
+ import { ButtonProps } from '@mui/material/Button/Button';
2
+ import { CreateGroupProps } from '../CreateGroup';
3
+ export interface CreateGroupButtonProps extends ButtonProps {
4
+ /**
5
+ * Overrides or extends the styles applied to the component.
6
+ * @default null
7
+ */
8
+ className?: string;
9
+ /**
10
+ * Props to spread to CreateGroup component
11
+ * @default empty object
12
+ */
13
+ CreateGroupProps?: CreateGroupProps;
14
+ /**
15
+ * Any other properties
16
+ */
17
+ [p: string]: any;
18
+ }
19
+ /**
20
+ *> API documentation for the Community-JS Create Group Button component. Learn about the available props and the CSS API.
21
+ *
22
+ #### Import
23
+ ```jsx
24
+ import {CreateGroupButton} from '@selfcommunity/react-ui';
25
+ ```
26
+
27
+ #### Component Name
28
+ The name `SCCreateGroupButton` can be used when providing style overrides in the theme.
29
+
30
+ #### CSS
31
+
32
+ |Rule Name|Global class|Description|
33
+ |---|---|---|
34
+ |root|.SCCreateGroupButton-root|Styles applied to the root element.|
35
+
36
+ * @param inProps
37
+ */
38
+ export default function CreateGroupButton(inProps: CreateGroupButtonProps): JSX.Element;