@selfcommunity/react-ui 0.7.50-alpha.0 → 0.7.50-event.28

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 (176) hide show
  1. package/lib/cjs/assets/logo.d.ts +2 -0
  2. package/lib/cjs/assets/logo.js +3 -0
  3. package/lib/cjs/components/Category/Category.d.ts +1 -1
  4. package/lib/cjs/components/Category/Category.js +1 -1
  5. package/lib/cjs/components/ChangeCover/ChangeCover.js +3 -3
  6. package/lib/cjs/components/ChangePicture/ChangePictureDialog/ChangePictureDialog.js +1 -1
  7. package/lib/cjs/components/Composer/Composer.js +9 -7
  8. package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +1 -1
  9. package/lib/cjs/components/Composer/Layer/CategoryLayer/CategoryLayer.d.ts +1 -1
  10. package/lib/cjs/components/Composer/Layer/CloseLayer/CloseLayer.d.ts +1 -1
  11. package/lib/cjs/components/Composer/Layer/LocationLayer/LocationLayer.d.ts +1 -1
  12. package/lib/cjs/components/ComposerIconButton/ComposerIconButton.d.ts +1 -1
  13. package/lib/cjs/components/CreateEventButton/CreateEventButton.d.ts +38 -0
  14. package/lib/cjs/components/CreateEventButton/CreateEventButton.js +79 -0
  15. package/lib/cjs/components/CreateEventButton/index.d.ts +3 -0
  16. package/lib/cjs/components/CreateEventButton/index.js +5 -0
  17. package/lib/cjs/components/CreateGroupButton/CreateGroupButton.js +1 -1
  18. package/lib/cjs/components/Event/Event.d.ts +57 -0
  19. package/lib/cjs/components/Event/Event.js +90 -0
  20. package/lib/cjs/components/Event/Skeleton.d.ts +22 -0
  21. package/lib/cjs/components/Event/Skeleton.js +44 -0
  22. package/lib/cjs/components/Event/constants.d.ts +1 -0
  23. package/lib/cjs/components/Event/constants.js +4 -0
  24. package/lib/cjs/components/Event/index.d.ts +4 -0
  25. package/lib/cjs/components/Event/index.js +8 -0
  26. package/lib/cjs/components/EventForm/EventAddress.d.ts +12 -0
  27. package/lib/cjs/components/EventForm/EventAddress.js +129 -0
  28. package/lib/cjs/components/EventForm/EventForm.d.ts +59 -0
  29. package/lib/cjs/components/EventForm/EventForm.js +323 -0
  30. package/lib/cjs/components/EventForm/UploadEventCover.d.ts +40 -0
  31. package/lib/cjs/components/EventForm/UploadEventCover.js +98 -0
  32. package/lib/cjs/components/EventForm/constants.d.ts +1 -0
  33. package/lib/cjs/components/EventForm/constants.js +4 -0
  34. package/lib/cjs/components/EventForm/index.d.ts +3 -0
  35. package/lib/cjs/components/EventForm/index.js +5 -0
  36. package/lib/cjs/components/EventLocationWidget/EventLocationWidget.d.ts +55 -0
  37. package/lib/cjs/components/EventLocationWidget/EventLocationWidget.js +103 -0
  38. package/lib/cjs/components/EventLocationWidget/Skeleton.d.ts +22 -0
  39. package/lib/cjs/components/EventLocationWidget/Skeleton.js +47 -0
  40. package/lib/cjs/components/EventLocationWidget/constants.d.ts +1 -0
  41. package/lib/cjs/components/EventLocationWidget/constants.js +4 -0
  42. package/lib/cjs/components/EventLocationWidget/index.d.ts +4 -0
  43. package/lib/cjs/components/EventLocationWidget/index.js +8 -0
  44. package/lib/cjs/components/Feed/Feed.js +1 -1
  45. package/lib/cjs/components/FeedObject/Actions/Share/Share.js +5 -5
  46. package/lib/cjs/components/GroupForm/GroupForm.js +2 -2
  47. package/lib/cjs/components/GroupHeader/GroupHeader.js +3 -3
  48. package/lib/cjs/components/GroupInfoWidget/GroupInfoWidget.js +1 -1
  49. package/lib/cjs/components/GroupInviteButton/GroupInviteButton.js +3 -3
  50. package/lib/cjs/components/GroupInvitedWidget/GroupInvitedWidget.js +1 -1
  51. package/lib/cjs/components/GroupSettingsIconButton/GroupSettingsIconButton.js +1 -1
  52. package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.js +1 -1
  53. package/lib/cjs/components/IncubatorListWidget/IncubatorListWidget.js +1 -1
  54. package/lib/cjs/components/NavigationMenuIconButton/DefaultDrawerContent.d.ts +3 -2
  55. package/lib/cjs/components/NavigationMenuIconButton/DefaultDrawerContent.js +19 -3
  56. package/lib/cjs/components/NavigationMenuIconButton/DefaultHeaderContent.d.ts +3 -1
  57. package/lib/cjs/components/NavigationMenuIconButton/DefaultHeaderContent.js +22 -3
  58. package/lib/cjs/components/NavigationMenuIconButton/index.d.ts +2 -1
  59. package/lib/cjs/components/NavigationMenuIconButton/index.js +3 -1
  60. package/lib/cjs/components/Notification/Notification.js +1 -1
  61. package/lib/cjs/components/PlatformWidget/PlatformWidget.d.ts +24 -2
  62. package/lib/cjs/components/PlatformWidget/PlatformWidget.js +256 -18
  63. package/lib/cjs/components/PlatformWidget/constants.d.ts +4 -0
  64. package/lib/cjs/components/PlatformWidget/constants.js +5 -1
  65. package/lib/cjs/components/PrivateMessageEditor/MessageMediaUploader/index.js +1 -1
  66. package/lib/cjs/components/PrivateMessageSettingsIconButton/PrivateMessageSettingsIconButton.js +6 -6
  67. package/lib/cjs/components/PrivateMessageSnippets/PrivateMessageSnippets.js +1 -1
  68. package/lib/cjs/components/PrivateMessageThread/PrivateMessageThread.js +1 -1
  69. package/lib/cjs/constants/Event.d.ts +2 -0
  70. package/lib/cjs/constants/Event.js +5 -0
  71. package/lib/cjs/constants/PubSub.d.ts +1 -1
  72. package/lib/cjs/constants/PubSub.js +10 -10
  73. package/lib/cjs/index.d.ts +12 -4
  74. package/lib/cjs/index.js +21 -5
  75. package/lib/cjs/shared/BaseDialog/BaseDialog.js +3 -2
  76. package/lib/cjs/shared/EmojiPicker/EmojiPicker.js +4 -2
  77. package/lib/cjs/shared/Media/File/PreviewComponent.d.ts +1 -1
  78. package/lib/cjs/shared/Media/Link/LayerComponent.d.ts +1 -1
  79. package/lib/cjs/shared/Media/Link/PreviewComponent.d.ts +1 -1
  80. package/lib/cjs/shared/MetadataField/index.d.ts +2 -1
  81. package/lib/cjs/types/index.d.ts +2 -1
  82. package/lib/cjs/types/platformWidget.d.ts +15 -0
  83. package/lib/cjs/types/platformWidget.js +2 -0
  84. package/lib/cjs/utils/string.d.ts +1 -0
  85. package/lib/cjs/utils/string.js +9 -1
  86. package/lib/esm/assets/logo.d.ts +2 -0
  87. package/lib/esm/assets/logo.js +1 -0
  88. package/lib/esm/components/Category/Category.d.ts +1 -1
  89. package/lib/esm/components/Category/Category.js +1 -1
  90. package/lib/esm/components/ChangeCover/ChangeCover.js +3 -3
  91. package/lib/esm/components/ChangePicture/ChangePictureDialog/ChangePictureDialog.js +1 -1
  92. package/lib/esm/components/Composer/Composer.js +9 -7
  93. package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +1 -1
  94. package/lib/esm/components/Composer/Layer/CategoryLayer/CategoryLayer.d.ts +1 -1
  95. package/lib/esm/components/Composer/Layer/CloseLayer/CloseLayer.d.ts +1 -1
  96. package/lib/esm/components/Composer/Layer/LocationLayer/LocationLayer.d.ts +1 -1
  97. package/lib/esm/components/ComposerIconButton/ComposerIconButton.d.ts +1 -1
  98. package/lib/esm/components/CreateEventButton/CreateEventButton.d.ts +38 -0
  99. package/lib/esm/components/CreateEventButton/CreateEventButton.js +76 -0
  100. package/lib/esm/components/CreateEventButton/index.d.ts +3 -0
  101. package/lib/esm/components/CreateEventButton/index.js +2 -0
  102. package/lib/esm/components/CreateGroupButton/CreateGroupButton.js +1 -1
  103. package/lib/esm/components/Event/Event.d.ts +57 -0
  104. package/lib/esm/components/Event/Event.js +87 -0
  105. package/lib/esm/components/Event/Skeleton.d.ts +22 -0
  106. package/lib/esm/components/Event/Skeleton.js +40 -0
  107. package/lib/esm/components/Event/constants.d.ts +1 -0
  108. package/lib/esm/components/Event/constants.js +1 -0
  109. package/lib/esm/components/Event/index.d.ts +4 -0
  110. package/lib/esm/components/Event/index.js +4 -0
  111. package/lib/esm/components/EventForm/EventAddress.d.ts +12 -0
  112. package/lib/esm/components/EventForm/EventAddress.js +126 -0
  113. package/lib/esm/components/EventForm/EventForm.d.ts +59 -0
  114. package/lib/esm/components/EventForm/EventForm.js +320 -0
  115. package/lib/esm/components/EventForm/UploadEventCover.d.ts +40 -0
  116. package/lib/esm/components/EventForm/UploadEventCover.js +95 -0
  117. package/lib/esm/components/EventForm/constants.d.ts +1 -0
  118. package/lib/esm/components/EventForm/constants.js +1 -0
  119. package/lib/esm/components/EventForm/index.d.ts +3 -0
  120. package/lib/esm/components/EventForm/index.js +2 -0
  121. package/lib/esm/components/EventLocationWidget/EventLocationWidget.d.ts +55 -0
  122. package/lib/esm/components/EventLocationWidget/EventLocationWidget.js +100 -0
  123. package/lib/esm/components/EventLocationWidget/Skeleton.d.ts +22 -0
  124. package/lib/esm/components/EventLocationWidget/Skeleton.js +43 -0
  125. package/lib/esm/components/EventLocationWidget/constants.d.ts +1 -0
  126. package/lib/esm/components/EventLocationWidget/constants.js +1 -0
  127. package/lib/esm/components/EventLocationWidget/index.d.ts +4 -0
  128. package/lib/esm/components/EventLocationWidget/index.js +4 -0
  129. package/lib/esm/components/Feed/Feed.js +2 -2
  130. package/lib/esm/components/FeedObject/Actions/Share/Share.js +5 -5
  131. package/lib/esm/components/GroupForm/GroupForm.js +3 -3
  132. package/lib/esm/components/GroupHeader/GroupHeader.js +4 -4
  133. package/lib/esm/components/GroupInfoWidget/GroupInfoWidget.js +2 -2
  134. package/lib/esm/components/GroupInviteButton/GroupInviteButton.js +4 -4
  135. package/lib/esm/components/GroupInvitedWidget/GroupInvitedWidget.js +2 -2
  136. package/lib/esm/components/GroupSettingsIconButton/GroupSettingsIconButton.js +2 -2
  137. package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.js +2 -2
  138. package/lib/esm/components/IncubatorListWidget/IncubatorListWidget.js +1 -1
  139. package/lib/esm/components/NavigationMenuIconButton/DefaultDrawerContent.d.ts +3 -2
  140. package/lib/esm/components/NavigationMenuIconButton/DefaultDrawerContent.js +21 -4
  141. package/lib/esm/components/NavigationMenuIconButton/DefaultHeaderContent.d.ts +3 -1
  142. package/lib/esm/components/NavigationMenuIconButton/DefaultHeaderContent.js +23 -3
  143. package/lib/esm/components/NavigationMenuIconButton/index.d.ts +2 -1
  144. package/lib/esm/components/NavigationMenuIconButton/index.js +2 -1
  145. package/lib/esm/components/Notification/Notification.js +1 -1
  146. package/lib/esm/components/PlatformWidget/PlatformWidget.d.ts +24 -2
  147. package/lib/esm/components/PlatformWidget/PlatformWidget.js +260 -22
  148. package/lib/esm/components/PlatformWidget/constants.d.ts +4 -0
  149. package/lib/esm/components/PlatformWidget/constants.js +4 -0
  150. package/lib/esm/components/PrivateMessageEditor/MessageMediaUploader/index.js +1 -1
  151. package/lib/esm/components/PrivateMessageSettingsIconButton/PrivateMessageSettingsIconButton.js +6 -6
  152. package/lib/esm/components/PrivateMessageSnippets/PrivateMessageSnippets.js +1 -1
  153. package/lib/esm/components/PrivateMessageThread/PrivateMessageThread.js +1 -1
  154. package/lib/esm/constants/Event.d.ts +2 -0
  155. package/lib/esm/constants/Event.js +2 -0
  156. package/lib/esm/constants/PubSub.d.ts +1 -1
  157. package/lib/esm/constants/PubSub.js +9 -9
  158. package/lib/esm/index.d.ts +12 -4
  159. package/lib/esm/index.js +13 -3
  160. package/lib/esm/shared/BaseDialog/BaseDialog.js +3 -2
  161. package/lib/esm/shared/EmojiPicker/EmojiPicker.js +4 -2
  162. package/lib/esm/shared/Media/File/PreviewComponent.d.ts +1 -1
  163. package/lib/esm/shared/Media/Link/LayerComponent.d.ts +1 -1
  164. package/lib/esm/shared/Media/Link/PreviewComponent.d.ts +1 -1
  165. package/lib/esm/shared/MetadataField/index.d.ts +2 -1
  166. package/lib/esm/types/index.d.ts +2 -1
  167. package/lib/esm/types/platformWidget.d.ts +15 -0
  168. package/lib/esm/types/platformWidget.js +1 -0
  169. package/lib/esm/utils/string.d.ts +1 -0
  170. package/lib/esm/utils/string.js +7 -0
  171. package/lib/umd/204.js +2 -0
  172. package/lib/umd/204.js.LICENSE.txt +22 -0
  173. package/lib/umd/react-ui.js +1 -1
  174. package/package.json +24 -7
  175. package/lib/umd/311.js +0 -2
  176. package/lib/umd/311.js.LICENSE.txt +0 -7
@@ -0,0 +1,126 @@
1
+ import { __awaiter } from "tslib";
2
+ import React, { useEffect, useMemo, useState } from 'react';
3
+ import { styled } from '@mui/material/styles';
4
+ import { Autocomplete, Box, InputAdornment, Tab, Tabs, TextField } from '@mui/material';
5
+ import Icon from '@mui/material/Icon';
6
+ import classNames from 'classnames';
7
+ import { useThemeProps } from '@mui/system';
8
+ import { PREFIX } from './constants';
9
+ import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
10
+ import UrlTextField from '../../shared/UrlTextField';
11
+ import axios from 'axios';
12
+ import { useSCContext } from '@selfcommunity/react-core';
13
+ import HiddenPlaceholder from '../../shared/HiddenPlaceholder';
14
+ import { SCEventLocationType } from '@selfcommunity/types';
15
+ import { useLoadScript } from '@react-google-maps/api';
16
+ const messages = defineMessages({
17
+ virtualPlaceholder: {
18
+ id: 'ui.eventForm.address.online.placeholder',
19
+ defaultMessage: 'ui.eventForm.address.online.placeholder'
20
+ }
21
+ });
22
+ const classes = {
23
+ root: `${PREFIX}-event-address-root`,
24
+ tabs: `${PREFIX}-event-address-tabs`,
25
+ tab: `${PREFIX}-event-address-tab`,
26
+ tabContent: `${PREFIX}-event-address-tab-content`
27
+ };
28
+ const Root = styled(Box, {
29
+ name: PREFIX,
30
+ slot: 'EventAddressRoot'
31
+ })(() => ({}));
32
+ export default function EventAddress(inProps) {
33
+ //PROPS
34
+ const props = useThemeProps({
35
+ props: inProps,
36
+ name: PREFIX
37
+ });
38
+ // INTL
39
+ const intl = useIntl();
40
+ // PROPS
41
+ const { className, forwardGeolocationData } = props;
42
+ // STATE
43
+ const [location, setLocation] = useState(SCEventLocationType.PERSON);
44
+ const [geolocation, setGeoLocation] = useState(null);
45
+ const [inputValue, setInputValue] = useState('');
46
+ const [suggestions, setSuggestions] = useState([]);
47
+ const [timeoutId, setTimeoutId] = useState(null);
48
+ // CONTEXT
49
+ const scContext = useSCContext();
50
+ const geocodingApiKey = useMemo(() => scContext.settings.integrations && scContext.settings.integrations.geocoding.apiKey, [scContext.settings.integrations]);
51
+ const { isLoaded } = useLoadScript({
52
+ googleMapsApiKey: scContext.settings.integrations.geocoding.apiKey,
53
+ libraries: ['places', 'geocoding']
54
+ });
55
+ // HANDLERS
56
+ const handleChange = (event, newValue) => {
57
+ setLocation(newValue);
58
+ };
59
+ const handleSelection = (event, newValue) => __awaiter(this, void 0, void 0, function* () {
60
+ if (newValue) {
61
+ try {
62
+ const response = yield axios.get(`https://maps.googleapis.com/maps/api/geocode/json`, {
63
+ params: {
64
+ place_id: newValue.place_id,
65
+ key: geocodingApiKey
66
+ }
67
+ });
68
+ const place = response.data.results[0];
69
+ setGeoLocation(newValue);
70
+ forwardGeolocationData({
71
+ location: location,
72
+ geolocation: place.formatted_address,
73
+ lat: place.geometry.location.lat,
74
+ lng: place.geometry.location.lng
75
+ });
76
+ }
77
+ catch (error) {
78
+ console.error('Error fetching place details:', error);
79
+ }
80
+ }
81
+ });
82
+ const handleLocationChange = (event, newInputValue) => {
83
+ setInputValue(newInputValue);
84
+ };
85
+ const handleLinkChange = (event) => {
86
+ forwardGeolocationData({ location: location, link: event.target.value });
87
+ };
88
+ useEffect(() => {
89
+ if (timeoutId) {
90
+ clearTimeout(timeoutId);
91
+ }
92
+ if (inputValue === '') {
93
+ setSuggestions([]);
94
+ return;
95
+ }
96
+ if (inputValue.length >= 3) {
97
+ const newTimeoutId = window.setTimeout(() => {
98
+ const autocompleteService = new window.google.maps.places.AutocompleteService();
99
+ autocompleteService.getPlacePredictions({ input: inputValue }, (predictions, status) => {
100
+ if (status === window.google.maps.places.PlacesServiceStatus.OK && predictions) {
101
+ setSuggestions(predictions.map((prediction) => ({
102
+ description: prediction.description,
103
+ place_id: prediction.place_id
104
+ })));
105
+ }
106
+ });
107
+ }, 300);
108
+ setTimeoutId(newTimeoutId);
109
+ }
110
+ }, [inputValue]);
111
+ if (!geocodingApiKey && !isLoaded) {
112
+ return React.createElement(HiddenPlaceholder, null);
113
+ }
114
+ return (React.createElement(Root, { className: classNames(classes.root, className) },
115
+ React.createElement(Tabs, { className: classes.tabs, value: location, onChange: handleChange, indicatorColor: "secondary", textColor: "secondary", variant: "fullWidth" },
116
+ React.createElement(Tab, { value: SCEventLocationType.PERSON, classes: { root: classes.tab }, icon: React.createElement(Icon, null, "add_location_alt"), iconPosition: "start", label: React.createElement(FormattedMessage, { id: "ui.eventForm.address.live.label", defaultMessage: "ui.eventForm.address.live.label" }) }),
117
+ React.createElement(Tab, { value: SCEventLocationType.ONLINE, classes: { root: classes.tab }, icon: React.createElement(Icon, null, "play_circle_outline"), iconPosition: "start", label: React.createElement(FormattedMessage, { id: "ui.eventForm.address.online.label", defaultMessage: "ui.eventForm.address.online.label" }) })),
118
+ React.createElement(Box, { className: classes.tabContent },
119
+ location === SCEventLocationType.PERSON && (React.createElement(Autocomplete, { freeSolo: true, size: "small", value: geolocation, onChange: handleSelection, inputValue: inputValue, onInputChange: handleLocationChange, options: suggestions, getOptionLabel: (option) => option.description, noOptionsText: React.createElement(FormattedMessage, { id: "ui.eventForm.address.live.noResults", defaultMessage: "ui.eventForm.address.live.noResults" }), renderInput: (params) => (React.createElement(TextField, Object.assign({}, params, { label: React.createElement(FormattedMessage, { id: "ui.eventForm.address.live.placeholder", defaultMessage: "ui.eventForm.address.live.placeholder" }), variant: "outlined", fullWidth: true, InputProps: Object.assign(Object.assign({}, params.InputProps), { endAdornment: (React.createElement(React.Fragment, null,
120
+ React.createElement(InputAdornment, { position: "start" },
121
+ React.createElement(Icon, null, "add_location_alt")),
122
+ params.InputProps.endAdornment)) }) }))) })),
123
+ location === SCEventLocationType.ONLINE && (React.createElement(UrlTextField, { size: "small", fullWidth: true, type: "url", placeholder: `${intl.formatMessage(messages.virtualPlaceholder)}`, helperText: React.createElement(FormattedMessage, { id: "ui.eventForm.address.online.help", defaultMessage: "ui.eventForm.address.online.help" }), InputProps: {
124
+ endAdornment: React.createElement(Icon, null, "play_circle_outline")
125
+ }, onChange: handleLinkChange })))));
126
+ }
@@ -0,0 +1,59 @@
1
+ import { BaseDialogProps } from '../../shared/BaseDialog';
2
+ export interface EventFormProps extends BaseDialogProps {
3
+ /**
4
+ * Overrides or extends the styles applied to the component.
5
+ * @default null
6
+ */
7
+ className?: string;
8
+ /**
9
+ * Open dialog
10
+ * @default true
11
+ */
12
+ open?: boolean;
13
+ /**
14
+ * On dialog close callback function
15
+ * @default null
16
+ */
17
+ onClose?: () => void;
18
+ /**
19
+ * On success callback function
20
+ * @default null
21
+ */
22
+ onSuccess?: (data: any) => void;
23
+ /**
24
+ * Any other properties
25
+ */
26
+ [p: string]: any;
27
+ }
28
+ /**
29
+ *> API documentation for the Community-JS Event Form component. Learn about the available props and the CSS API.
30
+ *
31
+ #### Import
32
+ ```jsx
33
+ import {EventForm} from '@selfcommunity/react-ui';
34
+ ```
35
+
36
+ #### Component Name
37
+ The name `SCEventForm` can be used when providing style overrides in the theme.
38
+
39
+ #### CSS
40
+
41
+ |Rule Name|Global class|Description|
42
+ |---|---|---|
43
+ |root|.SCEventForm-root|Styles applied to the root element.|
44
+ |active|.SCEventForm-active|Styles applied to the active element.|
45
+ |title|.SCEventForm-title|Styles applied to the title element.|
46
+ |cover|.SCEventForm-cover|Styles applied to the cover field.|
47
+ |form|.SCEventForm-form|Styles applied to the form element.|
48
+ |switch|.SCEventForm-switch|Styles applied to the switch element.|
49
+ |switchLabel|.SCEventForm-switch-label|Styles applied to the switchLabel element.|
50
+ |name|.SCEventForm-name|Styles applied to the name field.|
51
+ |description|.SCEventForm-description|Styles applied to the description field.|
52
+ |content|.SCEventForm-content|Styles applied to the element.|
53
+ |privacySection|.SCEventForm-privacy-section|Styles applied to the privacy section.|
54
+ |privacySectionInfo|.SCEventForm-privacy-section-info|Styles applied to the privacy info section.|
55
+ |error|.SCEventForm-error|Styles applied to the error elements.|
56
+
57
+ * @param inProps
58
+ */
59
+ export default function EventForm(inProps: EventFormProps): JSX.Element;
@@ -0,0 +1,320 @@
1
+ import { __rest } from "tslib";
2
+ import React, { useMemo, useState } from 'react';
3
+ import { useThemeProps } from '@mui/system';
4
+ import { styled } from '@mui/material/styles';
5
+ import { Box, Button, FormControl, FormGroup, Icon, IconButton, InputAdornment, InputLabel, MenuItem, Paper, Select, Stack, Switch, TextField, Typography } from '@mui/material';
6
+ import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
7
+ import { SCPreferences, useSCContext, 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 { EVENT_DESCRIPTION_MAX_LENGTH, EVENT_TITLE_MAX_LENGTH } from '../../constants/Event';
13
+ import { SCEventLocationType, SCEventPrivacyType, SCEventRecurrenceType } from '@selfcommunity/types';
14
+ import { SCOPE_SC_UI } from '../../constants/Errors';
15
+ import { EventService, formatHttpErrorCode } from '@selfcommunity/api-services';
16
+ import { Logger } from '@selfcommunity/utils';
17
+ import UploadEventCover from './UploadEventCover';
18
+ import { LocalizationProvider, MobileDatePicker, MobileTimePicker } from '@mui/x-date-pickers';
19
+ import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
20
+ import EventAddress from './EventAddress';
21
+ import itLocale from 'date-fns/locale/it';
22
+ import enLocale from 'date-fns/locale/en-US';
23
+ const messages = defineMessages({
24
+ name: {
25
+ id: 'ui.eventForm.name.placeholder',
26
+ defaultMessage: 'ui.eventForm.name.placeholder'
27
+ },
28
+ description: {
29
+ id: 'ui.eventForm.description.placeholder',
30
+ defaultMessage: 'ui.eventForm.description.placeholder'
31
+ },
32
+ startDate: {
33
+ id: 'ui.eventForm.date.placeholder',
34
+ defaultMessage: 'ui.eventForm.date.placeholder'
35
+ },
36
+ startTime: {
37
+ id: 'ui.eventForm.time.placeholder',
38
+ defaultMessage: 'ui.eventForm.time.placeholder'
39
+ },
40
+ frequency: {
41
+ id: 'ui.eventForm.frequency.label',
42
+ defaultMessage: 'ui.eventForm.frequency.label'
43
+ },
44
+ frequencyPlaceholder: {
45
+ id: 'ui.eventForm.frequency.none.placeholder',
46
+ defaultMessage: 'ui.eventForm.frequency.none.placeholder'
47
+ },
48
+ endDate: {
49
+ id: 'ui.eventForm.date.end.placeholder',
50
+ defaultMessage: 'ui.eventForm.date.end.placeholder'
51
+ },
52
+ endTime: {
53
+ id: 'ui.eventForm.time.end.placeholder',
54
+ defaultMessage: 'ui.eventForm.time.end.placeholder'
55
+ }
56
+ });
57
+ const classes = {
58
+ root: `${PREFIX}-root`,
59
+ active: `${PREFIX}-active`,
60
+ title: `${PREFIX}-title`,
61
+ cover: `${PREFIX}-cover`,
62
+ picker: `${PREFIX}-picker`,
63
+ dateTime: `${PREFIX}-date-time`,
64
+ frequency: `${PREFIX}-frequency`,
65
+ form: `${PREFIX}-form`,
66
+ switch: `${PREFIX}-switch`,
67
+ switchLabel: `${PREFIX}-switch-label`,
68
+ name: `${PREFIX}-name`,
69
+ description: `${PREFIX}-description`,
70
+ content: `${PREFIX}-content`,
71
+ privacySection: `${PREFIX}-privacy-section`,
72
+ privacySectionInfo: `${PREFIX}-privacy-section-info`,
73
+ error: `${PREFIX}-error`
74
+ };
75
+ const Root = styled(BaseDialog, {
76
+ name: PREFIX,
77
+ slot: 'Root'
78
+ })(() => ({}));
79
+ /**
80
+ *> API documentation for the Community-JS Event Form component. Learn about the available props and the CSS API.
81
+ *
82
+ #### Import
83
+ ```jsx
84
+ import {EventForm} from '@selfcommunity/react-ui';
85
+ ```
86
+
87
+ #### Component Name
88
+ The name `SCEventForm` can be used when providing style overrides in the theme.
89
+
90
+ #### CSS
91
+
92
+ |Rule Name|Global class|Description|
93
+ |---|---|---|
94
+ |root|.SCEventForm-root|Styles applied to the root element.|
95
+ |active|.SCEventForm-active|Styles applied to the active element.|
96
+ |title|.SCEventForm-title|Styles applied to the title element.|
97
+ |cover|.SCEventForm-cover|Styles applied to the cover field.|
98
+ |form|.SCEventForm-form|Styles applied to the form element.|
99
+ |switch|.SCEventForm-switch|Styles applied to the switch element.|
100
+ |switchLabel|.SCEventForm-switch-label|Styles applied to the switchLabel element.|
101
+ |name|.SCEventForm-name|Styles applied to the name field.|
102
+ |description|.SCEventForm-description|Styles applied to the description field.|
103
+ |content|.SCEventForm-content|Styles applied to the element.|
104
+ |privacySection|.SCEventForm-privacy-section|Styles applied to the privacy section.|
105
+ |privacySectionInfo|.SCEventForm-privacy-section-info|Styles applied to the privacy info section.|
106
+ |error|.SCEventForm-error|Styles applied to the error elements.|
107
+
108
+ * @param inProps
109
+ */
110
+ export default function EventForm(inProps) {
111
+ var _a, _b, _c, _d, _e;
112
+ //PROPS
113
+ const props = useThemeProps({
114
+ props: inProps,
115
+ name: PREFIX
116
+ });
117
+ const { className, open = true, onClose, onSuccess } = props, rest = __rest(props, ["className", "open", "onClose", "onSuccess"]);
118
+ // CONTEXT
119
+ const scContext = useSCContext();
120
+ // INTL
121
+ const intl = useIntl();
122
+ const initialFieldState = {
123
+ emotionalImageOriginal: '',
124
+ emotionalImageOriginalFile: '',
125
+ startDate: null,
126
+ startTime: null,
127
+ endDate: null,
128
+ endTime: null,
129
+ location: '',
130
+ geolocation: '',
131
+ lat: null,
132
+ lng: null,
133
+ link: '',
134
+ recurring: SCEventRecurrenceType.NEVER,
135
+ name: '',
136
+ description: '',
137
+ isPublic: true,
138
+ isSubmitting: false,
139
+ showEndDateTime: false
140
+ };
141
+ // STATE
142
+ const [field, setField] = useState(initialFieldState);
143
+ const [error, setError] = useState({});
144
+ // PREFERENCES
145
+ const scPreferences = useSCPreferences();
146
+ const privateEnabled = useMemo(() => scPreferences.preferences[SCPreferences.CONFIGURATIONS_EVENTS_PRIVATE_ENABLED].value, [scPreferences.preferences]);
147
+ const _backgroundCover = Object.assign({}, (field.emotionalImageOriginal
148
+ ? { background: `url('${field.emotionalImageOriginal}') center / cover` }
149
+ : { background: `url('${scPreferences.preferences[SCPreferences.IMAGES_USER_DEFAULT_COVER].value}') center / cover` }));
150
+ const combineDateAndTime = (date, time) => {
151
+ if (date && time) {
152
+ const combined = new Date(date);
153
+ combined.setHours(time.getHours());
154
+ combined.setMinutes(time.getMinutes());
155
+ combined.setSeconds(time.getSeconds());
156
+ combined.setMilliseconds(time.getMilliseconds());
157
+ return combined.toISOString();
158
+ }
159
+ return null;
160
+ };
161
+ function handleChangeCover(cover) {
162
+ setField((prev) => (Object.assign(Object.assign({}, prev), { ['emotionalImageOriginalFile']: cover })));
163
+ const reader = new FileReader();
164
+ reader.onloadend = () => {
165
+ setField((prev) => (Object.assign(Object.assign({}, prev), { ['emotionalImageOriginal']: reader.result })));
166
+ };
167
+ reader.readAsDataURL(cover);
168
+ if (error.emotionalImageOriginalError) {
169
+ delete error.emotionalImageOriginalError;
170
+ setError(error);
171
+ }
172
+ }
173
+ const handleGeoData = (data) => {
174
+ setField((prev) => (Object.assign(Object.assign({}, prev), data)));
175
+ };
176
+ const handleSubmit = () => {
177
+ setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: true })));
178
+ const formData = new FormData();
179
+ if (field.emotionalImageOriginalFile) {
180
+ formData.append('emotional_image_original', field.emotionalImageOriginalFile);
181
+ }
182
+ formData.append('name', field.name);
183
+ formData.append('start_date', combineDateAndTime(field.startDate, field.startTime));
184
+ formData.append('recurring', field.recurring);
185
+ if (field.endDate) {
186
+ formData.append('end_date', combineDateAndTime(field.endDate, field.endTime));
187
+ }
188
+ formData.append('location', field.location);
189
+ if (field.location === SCEventLocationType.ONLINE) {
190
+ formData.append('link', field.link);
191
+ }
192
+ if (field.location === SCEventLocationType.PERSON) {
193
+ formData.append('geolocation', field.geolocation);
194
+ formData.append('geolocation_lat', field.lat);
195
+ formData.append('geolocation_lng', field.lng);
196
+ }
197
+ if (privateEnabled) {
198
+ formData.append('privacy', field.isPublic ? SCEventPrivacyType.PUBLIC : SCEventPrivacyType.PRIVATE);
199
+ }
200
+ formData.append('description', field.description);
201
+ EventService.createEvent(formData, { headers: { 'Content-Type': 'multipart/form-data' } })
202
+ .then((data) => {
203
+ onSuccess && onSuccess(data);
204
+ onClose && onClose();
205
+ setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: false })));
206
+ })
207
+ .catch((e) => {
208
+ setError(Object.assign(Object.assign({}, error), formatHttpErrorCode(e)));
209
+ setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: false })));
210
+ Logger.error(SCOPE_SC_UI, e);
211
+ });
212
+ };
213
+ const handleChange = (event) => {
214
+ const { name, value } = event.target;
215
+ setField((prev) => (Object.assign(Object.assign({}, prev), { [name]: value })));
216
+ if (error[`${name}Error`]) {
217
+ delete error[`${name}Error`];
218
+ setError(error);
219
+ }
220
+ };
221
+ const handleChangeDateTime = (value, name) => {
222
+ setField((prev) => (Object.assign(Object.assign({}, prev), { [name]: value })));
223
+ if (error[`${name}Error`]) {
224
+ delete error[`${name}Error`];
225
+ setError(error);
226
+ }
227
+ };
228
+ /**
229
+ * Renders root object
230
+ */
231
+ return (React.createElement(Root, Object.assign({ DialogContentProps: { dividers: false }, title: React.createElement(FormattedMessage, { id: "ui.eventForm.title", defaultMessage: "ui.eventForm.title" }), open: open, onClose: onClose, className: classNames(classes.root, className), actions: React.createElement(LoadingButton, { loading: field.isSubmitting, disabled: !field.name ||
232
+ (!field.startDate && !field.startTime) ||
233
+ (SCEventLocationType.ONLINE && !field.link) ||
234
+ ((field.recurring !== SCEventRecurrenceType.NEVER) && (!field.endDate && !field.endTime)) ||
235
+ Object.keys(error).length !== 0 ||
236
+ field.name.length > EVENT_TITLE_MAX_LENGTH ||
237
+ field.description.length > EVENT_DESCRIPTION_MAX_LENGTH, variant: "contained", onClick: handleSubmit, color: "secondary" }, React.createElement(FormattedMessage, { id: "ui.eventForm.button.create", defaultMessage: "ui.eventForm.button.create" })) }, rest),
238
+ React.createElement(React.Fragment, null,
239
+ React.createElement(Paper, { style: _backgroundCover, classes: { root: classes.cover } },
240
+ React.createElement(UploadEventCover, { onChange: handleChangeCover })),
241
+ React.createElement(FormGroup, { className: classes.form },
242
+ React.createElement(TextField, { required: true, className: classes.name, placeholder: `${intl.formatMessage(messages.name)}`, margin: "normal", value: field.name, name: "name", onChange: handleChange, InputProps: {
243
+ endAdornment: React.createElement(Typography, { variant: "body2" }, EVENT_TITLE_MAX_LENGTH - field.name.length)
244
+ }, error: Boolean(((_a = field === null || field === void 0 ? void 0 : field.name) === null || _a === void 0 ? void 0 : _a.length) > EVENT_TITLE_MAX_LENGTH), helperText: ((_b = field === null || field === void 0 ? void 0 : field.name) === null || _b === void 0 ? void 0 : _b.length) > EVENT_TITLE_MAX_LENGTH ? (React.createElement(FormattedMessage, { id: "ui.eventForm.name.error.maxLength", defaultMessage: "ui.eventForm.name.error.maxLength" })) : null }),
245
+ React.createElement(Box, { className: classes.dateTime },
246
+ React.createElement(LocalizationProvider, { dateAdapter: AdapterDateFns, adapterLocale: scContext.settings.locale.default === 'it' ? itLocale : enLocale },
247
+ React.createElement(MobileDatePicker, { className: classes.picker, disablePast: true, label: field.startDate && React.createElement(FormattedMessage, { id: "ui.eventForm.date.placeholder", defaultMessage: "ui.eventForm.date.placeholder" }), value: field.startDate, slots: {
248
+ textField: (params) => (React.createElement(TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.startDate)}`, startAdornment: (React.createElement(InputAdornment, { position: "start" },
249
+ React.createElement(IconButton, null,
250
+ React.createElement(Icon, null, "calendar_off")))) }) })))
251
+ }, slotProps: {
252
+ toolbar: {
253
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
254
+ // @ts-ignore
255
+ toolbarTitle: React.createElement(FormattedMessage, { id: "ui.eventForm.date.title", defaultMessage: "ui.eventForm.date.title" })
256
+ }
257
+ }, onChange: (value) => handleChangeDateTime(value, 'startDate') }),
258
+ React.createElement(MobileTimePicker, { className: classes.picker, label: field.startTime && React.createElement(FormattedMessage, { id: "ui.eventForm.time.placeholder", defaultMessage: "ui.eventForm.time.placeholder" }), value: field.startTime, slots: {
259
+ textField: (params) => (React.createElement(TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.startTime)}`, startAdornment: (React.createElement(InputAdornment, { position: "start" },
260
+ React.createElement(IconButton, null,
261
+ React.createElement(Icon, null, "access_time")))) }) })))
262
+ }, slotProps: {
263
+ toolbar: {
264
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
265
+ // @ts-ignore
266
+ toolbarTitle: React.createElement(FormattedMessage, { id: "ui.eventForm.time.title", defaultMessage: "ui.eventForm.time.title" })
267
+ }
268
+ }, onChange: (value) => handleChangeDateTime(value, 'startTime') }))),
269
+ React.createElement(FormControl, { className: classes.frequency },
270
+ field.recurring !== SCEventRecurrenceType.NEVER && React.createElement(InputLabel, { id: "frequency" }, `${intl.formatMessage(messages.frequency)}`),
271
+ React.createElement(Select, { name: "recurring", label: field.recurring !== SCEventRecurrenceType.NEVER && `${intl.formatMessage(messages.frequency)}`, labelId: "recurring", value: field.recurring, onChange: handleChange, displayEmpty: true, renderValue: (selected) => {
272
+ if (!selected) {
273
+ return React.createElement("em", null, `${intl.formatMessage(messages.frequencyPlaceholder)}`);
274
+ }
275
+ return (React.createElement(FormattedMessage, { id: `ui.eventForm.frequency.${selected}.placeholder`, defaultMessage: `ui.eventForm.frequency.${selected}.placeholder` }));
276
+ }, startAdornment: React.createElement(InputAdornment, { position: "start" },
277
+ React.createElement(IconButton, null,
278
+ React.createElement(Icon, null, "frequency"))) }, Object.values(SCEventRecurrenceType).map((f) => (React.createElement(MenuItem, { value: f, key: f },
279
+ React.createElement(FormattedMessage, { id: `ui.eventForm.frequency.${f}.placeholder`, defaultMessage: `ui.eventForm.frequency.${f}.placeholder` })))))),
280
+ (field.showEndDateTime || field.recurring !== SCEventRecurrenceType.NEVER) && (React.createElement(Box, { className: classes.dateTime },
281
+ React.createElement(LocalizationProvider, { dateAdapter: AdapterDateFns, adapterLocale: scContext.settings.locale.default === 'it' ? itLocale : enLocale },
282
+ React.createElement(MobileDatePicker, { className: classes.picker, disablePast: true, label: field.endDate && React.createElement(FormattedMessage, { id: "ui.eventForm.date.end.placeholder", defaultMessage: "ui.eventForm.date.end.placeholder" }), value: field.endDate, slots: {
283
+ textField: (params) => (React.createElement(TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.endDate)}`, startAdornment: (React.createElement(InputAdornment, { position: "start" },
284
+ React.createElement(IconButton, null,
285
+ React.createElement(Icon, null, "calendar_off")))) }) })))
286
+ }, onChange: (value) => handleChangeDateTime(value, 'endDate') }),
287
+ React.createElement(MobileTimePicker, { className: classes.picker, label: field.endTime && React.createElement(FormattedMessage, { id: "ui.eventForm.time.end.placeholder", defaultMessage: "ui.eventForm.time.end.placeholder" }), value: field.endTime, slots: {
288
+ textField: (params) => (React.createElement(TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.endTime)}`, startAdornment: (React.createElement(InputAdornment, { position: "start" },
289
+ React.createElement(IconButton, null,
290
+ React.createElement(Icon, null, "access_time")))) }) })))
291
+ }, onChange: (value) => handleChangeDateTime(value, 'endTime') })))),
292
+ React.createElement(Button, { variant: "text", color: "secondary", onClick: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['showEndDateTime']: !field.showEndDateTime }))) },
293
+ React.createElement(FormattedMessage, { id: "ui.eventForm.dateTime.placeholder", defaultMessage: "ui.eventForm.dateTime.placeholder", values: { symbol: field.showEndDateTime ? '-' : '+' } })),
294
+ React.createElement(EventAddress, { forwardGeolocationData: handleGeoData }),
295
+ privateEnabled && (React.createElement(Box, { className: classes.privacySection },
296
+ React.createElement(Stack, { direction: "row", spacing: 1, alignItems: "center", justifyContent: "center" },
297
+ React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: !field.isPublic }) },
298
+ React.createElement(Icon, null, "private"),
299
+ React.createElement(FormattedMessage, { id: "ui.eventForm.privacy.private", defaultMessage: "ui.eventForm.privacy.private" })),
300
+ React.createElement(Switch, { className: classes.switch, checked: field.isPublic, onChange: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['isPublic']: !field.isPublic }))) }),
301
+ React.createElement(Typography, { className: classNames(classes.switchLabel, { [classes.active]: field.isPublic }) },
302
+ React.createElement(Icon, null, "public"),
303
+ React.createElement(FormattedMessage, { id: "ui.eventForm.privacy.public", defaultMessage: "ui.eventForm.privacy.public" }))),
304
+ React.createElement(Typography, { variant: "body2", textAlign: "center", className: classes.privacySectionInfo }, field.isPublic ? (React.createElement(FormattedMessage, { id: "ui.eventForm.privacy.public.info", defaultMessage: "ui.eventForm.privacy.public.info", values: {
305
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
306
+ // @ts-ignore
307
+ b: (chunks) => React.createElement("strong", null, chunks)
308
+ } })) : (React.createElement(React.Fragment, null, field.privacy === true ? (React.createElement(FormattedMessage, { id: "ui.eventForm.privacy.private.info.edit", defaultMessage: "ui.eventForm.private.public.info.edit", values: {
309
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
310
+ // @ts-ignore
311
+ b: (chunks) => React.createElement("strong", null, chunks)
312
+ } })) : (React.createElement(FormattedMessage, { id: "ui.eventForm.privacy.private.info", defaultMessage: "ui.eventForm.private.public.info", values: {
313
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
314
+ // @ts-ignore
315
+ b: (chunks) => React.createElement("strong", null, chunks)
316
+ } }))))))),
317
+ React.createElement(TextField, { multiline: true, className: classes.description, placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: {
318
+ endAdornment: (React.createElement(Typography, { variant: "body2" }, ((_c = field.description) === null || _c === void 0 ? void 0 : _c.length) ? EVENT_DESCRIPTION_MAX_LENGTH - field.description.length : EVENT_DESCRIPTION_MAX_LENGTH))
319
+ }, error: Boolean(((_d = field.description) === null || _d === void 0 ? void 0 : _d.length) > EVENT_DESCRIPTION_MAX_LENGTH), helperText: ((_e = field.description) === null || _e === void 0 ? void 0 : _e.length) > EVENT_DESCRIPTION_MAX_LENGTH ? (React.createElement(FormattedMessage, { id: "ui.eventForm.description.error.maxLength", defaultMessage: "ui.eventForm.description.error.maxLength" })) : null })))));
320
+ }
@@ -0,0 +1,40 @@
1
+ export interface UploadEventCoverProps {
2
+ /**
3
+ * On change function.
4
+ * @default null
5
+ */
6
+ onChange?: (cover: any) => void;
7
+ /**
8
+ * Overrides or extends the styles applied to the component.
9
+ * @default null
10
+ */
11
+ className?: string;
12
+ /**
13
+ * Any other properties
14
+ */
15
+ [p: string]: any;
16
+ }
17
+ /**
18
+ * > API documentation for the Community-JS Change Group Cover component. Learn about the available props and the CSS API.
19
+ *
20
+ *
21
+ * This component renders a button that allows admins to edit the group cover and a popover that specifies format and sizes allowed.
22
+ * Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/UploadEventCover)
23
+
24
+ #### Import
25
+ ```jsx
26
+ import {UploadEventCover} from '@selfcommunity/react-ui';
27
+ ```
28
+
29
+ #### Component Name
30
+ The name `SCUploadEventCover` can be used when providing style overrides in the theme.
31
+
32
+ #### CSS
33
+
34
+ |Rule Name|Global class|Description|
35
+ |---|---|---|
36
+ |root|.SCUploadEventCover-root|Styles applied to the root element.|
37
+
38
+ * @param inProps
39
+ */
40
+ export default function UploadEventCover(inProps: UploadEventCoverProps): JSX.Element;
@@ -0,0 +1,95 @@
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 classNames from 'classnames';
8
+ import { useThemeProps } from '@mui/system';
9
+ import { PREFIX } from './constants';
10
+ import { LoadingButton } from '@mui/lab';
11
+ const classes = {
12
+ root: `${PREFIX}-upload-event-cover-root`
13
+ };
14
+ const Root = styled(LoadingButton, {
15
+ name: PREFIX,
16
+ slot: 'UploadEventCoverRoot'
17
+ })(() => ({}));
18
+ /**
19
+ * > API documentation for the Community-JS Change Group Cover component. Learn about the available props and the CSS API.
20
+ *
21
+ *
22
+ * This component renders a button that allows admins to edit the group cover and a popover that specifies format and sizes allowed.
23
+ * Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/UploadEventCover)
24
+
25
+ #### Import
26
+ ```jsx
27
+ import {UploadEventCover} from '@selfcommunity/react-ui';
28
+ ```
29
+
30
+ #### Component Name
31
+ The name `SCUploadEventCover` can be used when providing style overrides in the theme.
32
+
33
+ #### CSS
34
+
35
+ |Rule Name|Global class|Description|
36
+ |---|---|---|
37
+ |root|.SCUploadEventCover-root|Styles applied to the root element.|
38
+
39
+ * @param inProps
40
+ */
41
+ export default function UploadEventCover(inProps) {
42
+ //PROPS
43
+ const props = useThemeProps({
44
+ props: inProps,
45
+ name: PREFIX
46
+ });
47
+ const { onChange, className = false } = props, rest = __rest(props, ["onChange", "className"]);
48
+ //CONTEXT
49
+ const scUserContext = useContext(SCUserContext);
50
+ //STATE
51
+ let fileInput = useRef(null);
52
+ const [loading, setLoading] = useState(false);
53
+ const [alert, setAlert] = useState(null);
54
+ // Anonymous
55
+ if (!scUserContext.user) {
56
+ return null;
57
+ }
58
+ /**
59
+ * Handles file upload
60
+ * @param event
61
+ */
62
+ const handleUpload = (event) => {
63
+ fileInput = event.target.files[0];
64
+ if (fileInput) {
65
+ const reader = new FileReader();
66
+ reader.onload = (e) => {
67
+ const img = new Image();
68
+ img.onload = () => {
69
+ onChange && onChange(fileInput);
70
+ // if (img.width < 1920) {
71
+ // setAlert(intl.formatMessage(messages.errorImageSize));
72
+ // } else {
73
+ // isCreationMode ? onChange && onChange(fileInput) : handleSave();
74
+ // }
75
+ };
76
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
77
+ // @ts-ignore
78
+ img.src = e.target.result;
79
+ };
80
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
81
+ // @ts-ignore
82
+ reader.readAsDataURL(fileInput);
83
+ }
84
+ };
85
+ /**
86
+ * If there is an error
87
+ */
88
+ if (alert) {
89
+ return (React.createElement(Alert, { color: "error", onClose: () => setAlert(null) }, alert));
90
+ }
91
+ return (React.createElement(React.Fragment, null,
92
+ React.createElement("input", { type: "file", onChange: handleUpload, ref: fileInput, hidden: true, accept: ".gif,.png,.jpg,.jpeg" }),
93
+ React.createElement(Root, Object.assign({ className: classNames(classes.root, className), size: "medium", variant: "contained", disabled: loading, onClick: () => fileInput.current.click(), loading: loading }, rest),
94
+ React.createElement(Icon, null, "image"))));
95
+ }
@@ -0,0 +1 @@
1
+ export declare const PREFIX = "SCEventForm";
@@ -0,0 +1 @@
1
+ export const PREFIX = 'SCEventForm';
@@ -0,0 +1,3 @@
1
+ import EventForm, { EventFormProps } from './EventForm';
2
+ export default EventForm;
3
+ export { EventFormProps };
@@ -0,0 +1,2 @@
1
+ import EventForm from './EventForm';
2
+ export default EventForm;