@selfcommunity/react-ui 0.7.50-events.51 → 0.7.50-events.53

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 (69) hide show
  1. package/lib/cjs/components/Composer/Attributes/Attributes.d.ts +1 -1
  2. package/lib/cjs/components/Composer/Attributes/Attributes.js +8 -2
  3. package/lib/cjs/components/Composer/Composer.d.ts +3 -2
  4. package/lib/cjs/components/Composer/Composer.js +52 -35
  5. package/lib/cjs/components/Composer/Content/ContentDiscussion/ContentDiscussion.js +1 -0
  6. package/lib/cjs/components/Composer/Content/ContentPost/ContentPost.js +1 -0
  7. package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +2 -1
  8. package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.js +17 -7
  9. package/lib/cjs/components/Event/Event.js +2 -2
  10. package/lib/cjs/components/EventAutocomplete/EventAutocomplete.d.ts +48 -0
  11. package/lib/cjs/components/EventAutocomplete/EventAutocomplete.js +97 -0
  12. package/lib/cjs/components/EventAutocomplete/index.d.ts +3 -0
  13. package/lib/cjs/components/EventAutocomplete/index.js +5 -0
  14. package/lib/cjs/components/Events/Events.js +6 -1
  15. package/lib/cjs/components/FeedObjectMediaPreview/FeedObjectMediaPreview.js +1 -1
  16. package/lib/cjs/components/InlineComposerWidget/InlineComposerWidget.d.ts +2 -1
  17. package/lib/cjs/components/MyEventsWidget/MyEventsWidget.js +1 -4
  18. package/lib/cjs/constants/Media.d.ts +1 -0
  19. package/lib/cjs/constants/Media.js +2 -1
  20. package/lib/cjs/index.d.ts +2 -2
  21. package/lib/cjs/index.js +13 -3
  22. package/lib/cjs/shared/Media/Share/DisplayComponent.js +4 -1
  23. package/lib/cjs/shared/Media/Share/filter.js +1 -1
  24. package/lib/cjs/shared/Media/index.d.ts +1 -2
  25. package/lib/cjs/shared/Media/index.js +1 -3
  26. package/lib/esm/components/Composer/Attributes/Attributes.d.ts +1 -1
  27. package/lib/esm/components/Composer/Attributes/Attributes.js +8 -2
  28. package/lib/esm/components/Composer/Composer.d.ts +3 -2
  29. package/lib/esm/components/Composer/Composer.js +52 -35
  30. package/lib/esm/components/Composer/Content/ContentDiscussion/ContentDiscussion.js +1 -0
  31. package/lib/esm/components/Composer/Content/ContentPost/ContentPost.js +1 -0
  32. package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +2 -1
  33. package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.js +17 -7
  34. package/lib/esm/components/Event/Event.js +2 -2
  35. package/lib/esm/components/EventAutocomplete/EventAutocomplete.d.ts +48 -0
  36. package/lib/esm/components/EventAutocomplete/EventAutocomplete.js +95 -0
  37. package/lib/esm/components/EventAutocomplete/index.d.ts +3 -0
  38. package/lib/esm/components/EventAutocomplete/index.js +2 -0
  39. package/lib/esm/components/Events/Events.js +7 -2
  40. package/lib/esm/components/FeedObjectMediaPreview/FeedObjectMediaPreview.js +2 -2
  41. package/lib/esm/components/InlineComposerWidget/InlineComposerWidget.d.ts +2 -1
  42. package/lib/esm/components/InlineComposerWidget/InlineComposerWidget.js +1 -1
  43. package/lib/esm/components/MyEventsWidget/MyEventsWidget.js +1 -4
  44. package/lib/esm/constants/Media.d.ts +1 -0
  45. package/lib/esm/constants/Media.js +1 -0
  46. package/lib/esm/index.d.ts +2 -2
  47. package/lib/esm/index.js +2 -2
  48. package/lib/esm/shared/Media/Share/DisplayComponent.js +5 -2
  49. package/lib/esm/shared/Media/Share/filter.js +2 -2
  50. package/lib/esm/shared/Media/index.d.ts +1 -2
  51. package/lib/esm/shared/Media/index.js +1 -2
  52. package/lib/umd/react-ui.js +1 -1
  53. package/package.json +7 -7
  54. package/lib/cjs/shared/Media/Event/DisplayComponent.d.ts +0 -15
  55. package/lib/cjs/shared/Media/Event/DisplayComponent.js +0 -31
  56. package/lib/cjs/shared/Media/Event/constants.d.ts +0 -1
  57. package/lib/cjs/shared/Media/Event/constants.js +0 -4
  58. package/lib/cjs/shared/Media/Event/filter.d.ts +0 -3
  59. package/lib/cjs/shared/Media/Event/filter.js +0 -4
  60. package/lib/cjs/shared/Media/Event/index.d.ts +0 -3
  61. package/lib/cjs/shared/Media/Event/index.js +0 -14
  62. package/lib/esm/shared/Media/Event/DisplayComponent.d.ts +0 -15
  63. package/lib/esm/shared/Media/Event/DisplayComponent.js +0 -29
  64. package/lib/esm/shared/Media/Event/constants.d.ts +0 -1
  65. package/lib/esm/shared/Media/Event/constants.js +0 -1
  66. package/lib/esm/shared/Media/Event/filter.d.ts +0 -3
  67. package/lib/esm/shared/Media/Event/filter.js +0 -2
  68. package/lib/esm/shared/Media/Event/index.d.ts +0 -3
  69. package/lib/esm/shared/Media/Event/index.js +0 -11
@@ -16,7 +16,7 @@ export interface AttributesProps extends Omit<BoxProps, 'value' | 'onChange' | '
16
16
  * @param value
17
17
  * @default empty object
18
18
  */
19
- onClick?: (attribute: 'categories' | 'group' | 'addressing' | 'location') => void;
19
+ onClick?: (attribute: 'categories' | 'event' | 'group' | 'addressing' | 'location') => void;
20
20
  }
21
21
  declare const _default: (props: AttributesProps) => JSX.Element;
22
22
  export default _default;
@@ -17,7 +17,7 @@ const Root = (0, styles_1.styled)(material_1.Box, {
17
17
  slot: 'AttributesRoot'
18
18
  })(() => ({}));
19
19
  exports.default = (props) => {
20
- var _a, _b, _c;
20
+ var _a, _b, _c, _d;
21
21
  // PROPS
22
22
  const { className = null, value = null, onChange = null, onClick = null } = props;
23
23
  // HANDLERS
@@ -27,6 +27,12 @@ exports.default = (props) => {
27
27
  const handleClickCategory = (0, react_1.useCallback)(() => {
28
28
  onClick && onClick('categories');
29
29
  }, [onClick]);
30
+ const handleDeleteEvent = (0, react_1.useCallback)(() => {
31
+ onChange && onChange(Object.assign(Object.assign({}, value), { event: null }));
32
+ }, [value, onChange]);
33
+ const handleClickEvent = (0, react_1.useCallback)(() => {
34
+ onClick && onClick('event');
35
+ }, [onClick]);
30
36
  const handleDeleteGroup = (0, react_1.useCallback)(() => {
31
37
  onChange && onChange(Object.assign(Object.assign({}, value), { group: null }));
32
38
  }, [value, onChange]);
@@ -46,6 +52,6 @@ exports.default = (props) => {
46
52
  onClick && onClick('location');
47
53
  }, [onClick]);
48
54
  return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, { children: [((_a = value === null || value === void 0 ? void 0 : value.categories) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
49
- (value === null || value === void 0 ? void 0 : value.categories.map((c) => ((0, jsx_runtime_1.jsx)(material_1.Chip, { label: c.name, onDelete: handleDeleteCategory(c.id), icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "category" }), onClick: handleClickCategory }, c.id)))), (value === null || value === void 0 ? void 0 : value.group) && ((0, jsx_runtime_1.jsx)(material_1.Chip, { label: value === null || value === void 0 ? void 0 : value.group.name, onDelete: handleDeleteGroup, icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "groups" }), onClick: handleClickGroup, disabled: !((_b = value === null || value === void 0 ? void 0 : value.group) === null || _b === void 0 ? void 0 : _b.subscription_status) }, value === null || value === void 0 ? void 0 : value.group.id)), ((_c = value === null || value === void 0 ? void 0 : value.addressing) === null || _c === void 0 ? void 0 : _c.length) > 0 &&
55
+ (value === null || value === void 0 ? void 0 : value.categories.map((c) => ((0, jsx_runtime_1.jsx)(material_1.Chip, { label: c.name, onDelete: handleDeleteCategory(c.id), icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "category" }), onClick: handleClickCategory }, c.id)))), (value === null || value === void 0 ? void 0 : value.group) && ((0, jsx_runtime_1.jsx)(material_1.Chip, { label: value === null || value === void 0 ? void 0 : value.group.name, onDelete: handleDeleteGroup, icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "groups" }), onClick: handleClickGroup, disabled: !((_b = value === null || value === void 0 ? void 0 : value.group) === null || _b === void 0 ? void 0 : _b.subscription_status) }, value === null || value === void 0 ? void 0 : value.group.id)), (value === null || value === void 0 ? void 0 : value.event) && ((0, jsx_runtime_1.jsx)(material_1.Chip, { label: value === null || value === void 0 ? void 0 : value.event.name, onDelete: handleDeleteEvent, icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "CalendarIcon" }), onClick: handleClickEvent, disabled: !((_c = value === null || value === void 0 ? void 0 : value.event) === null || _c === void 0 ? void 0 : _c.subscription_status) }, value === null || value === void 0 ? void 0 : value.event.id)), ((_d = value === null || value === void 0 ? void 0 : value.addressing) === null || _d === void 0 ? void 0 : _d.length) > 0 &&
50
56
  (value === null || value === void 0 ? void 0 : value.addressing.map((t) => ((0, jsx_runtime_1.jsx)(TagChip_1.default, { tag: t, onDelete: handleDeleteTag(t.id), icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "label" }), onClick: handleClickTag }, t.id)))), (value === null || value === void 0 ? void 0 : value.location) && ((0, jsx_runtime_1.jsx)(material_1.Chip, { icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "add_location_alt" }), label: value === null || value === void 0 ? void 0 : value.location.location, onDelete: handleDeleteLocation, onClick: handleClickLocation }))] })));
51
57
  };
@@ -1,5 +1,5 @@
1
1
  import { SyntheticEvent } from 'react';
2
- import { SCCategoryType, SCContributionType, SCFeedDiscussionType, SCFeedPostType, SCFeedStatusType, SCFeedTypologyType, SCGroupType, SCMediaType, SCPollType, SCTagType } from '@selfcommunity/types';
2
+ import { SCCategoryType, SCContributionType, SCEventType, SCFeedDiscussionType, SCFeedPostType, SCFeedStatusType, SCFeedTypologyType, SCGroupType, SCMediaType, SCPollType, SCTagType } from '@selfcommunity/types';
3
3
  import { DialogProps } from '@mui/material';
4
4
  import { EditorProps } from '../Editor';
5
5
  import { SCMediaObjectType } from '../../types/media';
@@ -27,6 +27,7 @@ export interface ComposerProps extends Omit<DialogProps, 'defaultValue' | 'scrol
27
27
  title?: string;
28
28
  text?: string;
29
29
  categories?: SCCategoryType[];
30
+ event?: SCEventType;
30
31
  group?: SCGroupType;
31
32
  audience?: string;
32
33
  addressing?: SCTagType[];
@@ -53,7 +54,7 @@ export interface ComposerProps extends Omit<DialogProps, 'defaultValue' | 'scrol
53
54
  * Callback triggered on close click
54
55
  * @default null
55
56
  */
56
- onClose?: (event: SyntheticEvent) => void;
57
+ onClose?: (e: SyntheticEvent) => void;
57
58
  /**
58
59
  * The feed where the component is rendered
59
60
  * @default SCFeedTypologyType.HOME
@@ -61,6 +61,7 @@ const COMPOSER_INITIAL_STATE = {
61
61
  htmlError: null,
62
62
  categories: [],
63
63
  group: null,
64
+ event: null,
64
65
  categoriesError: null,
65
66
  groupsError: null,
66
67
  addressing: null,
@@ -74,6 +75,8 @@ const reducer = (state, action) => {
74
75
  switch (action.type) {
75
76
  case 'reset':
76
77
  return Object.assign(Object.assign({}, COMPOSER_INITIAL_STATE), { key: (0, utils_1.random)() });
78
+ case 'resetEventFeed':
79
+ return Object.assign(Object.assign({}, COMPOSER_INITIAL_STATE), { event: state.event, key: (0, utils_1.random)() });
77
80
  case 'resetGroupFeed':
78
81
  return Object.assign(Object.assign({}, COMPOSER_INITIAL_STATE), { group: state.group, key: (0, utils_1.random)() });
79
82
  case 'resetCategoryFeed':
@@ -140,7 +143,7 @@ function Composer(inProps) {
140
143
  const [isSubmitting, setIsSubmitting] = (0, react_1.useState)(false);
141
144
  const [layer, setLayer] = (0, react_1.useState)();
142
145
  const [state, dispatch] = (0, react_1.useReducer)(reducer, Object.assign(Object.assign(Object.assign({}, COMPOSER_INITIAL_STATE), defaultValue), { key: (0, utils_1.random)() }));
143
- const { key, id, type, title, titleError, html, categories, group, addressing, audience, medias, poll, pollError, location, error } = state;
146
+ const { key, id, type, title, titleError, html, categories, event, group, addressing, audience, medias, poll, pollError, location, error } = state;
144
147
  const destructureFeedObject = (_feedObject) => {
145
148
  if (_feedObject.type === types_1.SCContributionType.POST) {
146
149
  _feedObject = _feedObject;
@@ -160,6 +163,7 @@ function Composer(inProps) {
160
163
  title: _feedObject.title,
161
164
  html: _feedObject.html,
162
165
  categories: _feedObject.categories,
166
+ event: _feedObject.event,
163
167
  group: _feedObject.group,
164
168
  addressing: _feedObject.addressing,
165
169
  medias: _feedObject.medias,
@@ -222,8 +226,8 @@ function Composer(inProps) {
222
226
  (0, react_1.useEffect)(() => {
223
227
  if (!unloadRef.current && canSubmit) {
224
228
  unloadRef.current = true;
225
- const onUnload = (event) => {
226
- event.preventDefault();
229
+ const onUnload = (e) => {
230
+ e.preventDefault();
227
231
  return '';
228
232
  };
229
233
  window.onbeforeunload = onUnload;
@@ -244,17 +248,17 @@ function Composer(inProps) {
244
248
  }
245
249
  /**
246
250
  * On touchStart event save the initial Y
247
- * @param event
251
+ * @param e
248
252
  */
249
- const handleTouchStart = (event) => {
250
- pointerStartY.current = event.touches[0].clientY;
253
+ const handleTouchStart = (e) => {
254
+ pointerStartY.current = e.touches[0].clientY;
251
255
  };
252
256
  /**
253
257
  * Perform blur only if gesture is a pan (bottom direction)
254
- * @param event
258
+ * @param e
255
259
  */
256
- const handleTouchmove = (event) => {
257
- const currentY = event.touches[0].clientY;
260
+ const handleTouchmove = (e) => {
261
+ const currentY = e.touches[0].clientY;
258
262
  const deltaY = currentY - pointerStartY.current;
259
263
  pointerStartY.current = currentY;
260
264
  if (deltaY > 0) {
@@ -312,9 +316,12 @@ function Composer(inProps) {
312
316
  }
313
317
  }), [handleAddLayer, handleRemoveLayer, handleChangeCategories, categories]);
314
318
  const handleChangeAudience = (0, react_1.useCallback)((value) => {
315
- if (group || (value && Object.prototype.hasOwnProperty.call(value, 'managed_by'))) {
319
+ if (group || (value && Object.prototype.hasOwnProperty.call(value, 'emotional_image_position'))) {
316
320
  dispatch({ type: 'group', value });
317
321
  }
322
+ else if (event || (value && Object.prototype.hasOwnProperty.call(value, 'recurring'))) {
323
+ dispatch({ type: 'event', value });
324
+ }
318
325
  else {
319
326
  dispatch({ type: 'addressing', value });
320
327
  }
@@ -326,9 +333,13 @@ function Composer(inProps) {
326
333
  ComponentProps: {
327
334
  onClose: handleRemoveLayer,
328
335
  onSave: handleChangeAudience,
329
- defaultValue: group || (addressing && Object.prototype.hasOwnProperty.call(addressing, 'managed_by')) ? group : addressing
336
+ defaultValue: group || (addressing && Object.prototype.hasOwnProperty.call(addressing, 'emotional_image_position'))
337
+ ? group
338
+ : event || (addressing && Object.prototype.hasOwnProperty.call(addressing, 'recurring'))
339
+ ? event
340
+ : addressing
330
341
  }
331
- }), [handleAddLayer, handleRemoveLayer, handleChangeAudience, addressing, group]);
342
+ }), [handleAddLayer, handleRemoveLayer, handleChangeAudience, addressing, event, group]);
332
343
  const handleChangeLocation = (0, react_1.useCallback)((value) => {
333
344
  dispatch({ type: 'location', value });
334
345
  setLayer(null);
@@ -359,7 +370,7 @@ function Composer(inProps) {
359
370
  });
360
371
  mediasRef.current.medias = _medias;
361
372
  }, []);
362
- const handleMediaTriggerClick = (0, react_1.useCallback)((mediaObjectType) => (event) => {
373
+ const handleMediaTriggerClick = (0, react_1.useCallback)((mediaObjectType) => (e) => {
363
374
  if (mediaObjectType.layerComponent) {
364
375
  handleAddLayer({
365
376
  name: mediaObjectType.name,
@@ -391,9 +402,9 @@ function Composer(inProps) {
391
402
  break;
392
403
  }
393
404
  }, [handleAddCategoryLayer, handleAddAudienceLayer, handleAddLocationLayer]);
394
- const handleSubmit = (0, react_1.useCallback)((event) => {
395
- event.preventDefault();
396
- event.stopPropagation();
405
+ const handleSubmit = (0, react_1.useCallback)((e) => {
406
+ e.preventDefault();
407
+ e.stopPropagation();
397
408
  if (react_core_1.UserUtils.isBlocked(scUserContext.user)) {
398
409
  // deny submit action if authenticated user is blocked
399
410
  enqueueSnackbar((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.common.userBlocked", defaultMessage: "ui.common.userBlocked" }), {
@@ -422,6 +433,9 @@ function Composer(inProps) {
422
433
  if (features.includes(types_1.SCFeatureName.GROUPING) && group !== null) {
423
434
  data.group = group.id;
424
435
  }
436
+ if (features.includes(types_1.SCFeatureName.EVENT) && event !== null) {
437
+ data.event = event.id;
438
+ }
425
439
  setIsSubmitting(true);
426
440
  // Finding right url
427
441
  const _type = type === Composer_1.COMPOSER_TYPE_POLL ? types_1.SCContributionType.POST : type;
@@ -445,17 +459,19 @@ function Composer(inProps) {
445
459
  }
446
460
  feedType && feedType === types_1.SCFeedTypologyType.CATEGORY
447
461
  ? dispatch({ type: 'resetCategoryFeed' })
448
- : feedType === types_1.SCFeedTypologyType.GROUP
449
- ? dispatch({ type: 'resetGroupFeed' })
450
- : dispatch({ type: 'reset' });
462
+ : feedType === types_1.SCFeedTypologyType.EVENT
463
+ ? dispatch({ type: 'resetEventFeed' })
464
+ : feedType === types_1.SCFeedTypologyType.GROUP
465
+ ? dispatch({ type: 'resetGroupFeed' })
466
+ : dispatch({ type: 'reset' });
451
467
  })
452
468
  .catch((error) => {
453
469
  dispatch({ type: 'multiple', value: (0, api_services_1.formatHttpErrorCode)(error) });
454
470
  })
455
471
  .then(() => setIsSubmitting(false));
456
- }, [scUserContext.user, feedObjectType, id, type, title, html, categories, group, addressing, audience, medias, poll, location, hasPoll]);
472
+ }, [scUserContext.user, feedObjectType, id, type, title, html, categories, event, group, addressing, audience, medias, poll, location, hasPoll]);
457
473
  //edited here
458
- const handleClose = (0, react_1.useCallback)((event, reason) => {
474
+ const handleClose = (0, react_1.useCallback)((e, reason) => {
459
475
  if (unloadRef.current) {
460
476
  window.onbeforeunload = null;
461
477
  }
@@ -466,21 +482,21 @@ function Composer(inProps) {
466
482
  ComponentProps: {
467
483
  onClose: handleRemoveLayer,
468
484
  onSave: () => {
469
- onClose && onClose(event);
485
+ onClose && onClose(e);
470
486
  setLayer(null);
471
487
  feedType && feedType === types_1.SCFeedTypologyType.CATEGORY
472
488
  ? dispatch({ type: 'resetCategoryFeed' })
473
- : feedType === types_1.SCFeedTypologyType.GROUP
474
- ? dispatch({ type: 'resetGroupFeed' })
475
- : dispatch({ type: 'reset' });
489
+ : feedType === types_1.SCFeedTypologyType.EVENT
490
+ ? dispatch({ type: 'resetEventFeed' })
491
+ : feedType === types_1.SCFeedTypologyType.GROUP
492
+ ? dispatch({ type: 'resetGroupFeed' })
493
+ : dispatch({ type: 'reset' });
476
494
  }
477
495
  }
478
496
  });
479
497
  }
480
498
  else {
481
- console.log('qui');
482
- onClose && onClose(event);
483
- console.log('qui2');
499
+ onClose && onClose(e);
484
500
  /*setLayer(null);
485
501
  feedType && feedType === SCFeedTypologyType.CATEGORY
486
502
  ? dispatch({type: 'resetCategoryFeed'})
@@ -489,7 +505,7 @@ function Composer(inProps) {
489
505
  : dispatch({type: 'reset'}); */
490
506
  }
491
507
  }, [onClose, canSubmit, handleRemoveLayer]);
492
- const handleClosePrompt = (0, react_1.useCallback)((event) => {
508
+ const handleClosePrompt = (0, react_1.useCallback)((e) => {
493
509
  if (canSubmit) {
494
510
  handleAddLayer({
495
511
  name: 'close',
@@ -501,7 +517,7 @@ function Composer(inProps) {
501
517
  });
502
518
  }
503
519
  else {
504
- handleClose(event);
520
+ handleClose(e);
505
521
  }
506
522
  }, [canSubmit, handleAddLayer, handleRemoveLayer, handleClose]);
507
523
  // RENDER
@@ -515,11 +531,11 @@ function Composer(inProps) {
515
531
  }
516
532
  switch (type) {
517
533
  case Composer_1.COMPOSER_TYPE_POLL:
518
- return ((0, jsx_runtime_1.jsx)(ContentPoll_1.default, { onChange: handleChangePoll, value: { html, group, addressing, medias, poll, location }, error: pollError, disabled: isSubmitting }, key));
534
+ return ((0, jsx_runtime_1.jsx)(ContentPoll_1.default, { onChange: handleChangePoll, value: { html, event, group, addressing, medias, poll, location }, error: pollError, disabled: isSubmitting }, key));
519
535
  case types_1.SCContributionType.DISCUSSION:
520
- return ((0, jsx_runtime_1.jsx)(ContentDiscussion_1.default, { value: { title, html, categories, group, addressing, medias, poll, location }, error: { titleError, error }, onChange: handleChangeDiscussion, disabled: isSubmitting, EditorProps: Object.assign({ toolbar: true, uploadImage: true }, EditorProps) }, key));
536
+ return ((0, jsx_runtime_1.jsx)(ContentDiscussion_1.default, { value: { title, html, categories, event, group, addressing, medias, poll, location }, error: { titleError, error }, onChange: handleChangeDiscussion, disabled: isSubmitting, EditorProps: Object.assign({ toolbar: true, uploadImage: true }, EditorProps) }, key));
521
537
  default:
522
- return ((0, jsx_runtime_1.jsx)(ContentPost_1.default, { value: { html, categories, group, addressing, medias, poll, location }, error: { error }, onChange: handleChangePost, disabled: isSubmitting, EditorProps: Object.assign({ toolbar: false, uploadImage: false }, EditorProps) }, key));
538
+ return ((0, jsx_runtime_1.jsx)(ContentPost_1.default, { value: { html, categories, event, group, addressing, medias, poll, location }, error: { error }, onChange: handleChangePost, disabled: isSubmitting, EditorProps: Object.assign({ toolbar: false, uploadImage: false }, EditorProps) }, key));
523
539
  }
524
540
  }, [
525
541
  key,
@@ -527,6 +543,7 @@ function Composer(inProps) {
527
543
  title,
528
544
  html,
529
545
  categories,
546
+ event,
530
547
  group,
531
548
  addressing,
532
549
  medias,
@@ -541,7 +558,7 @@ function Composer(inProps) {
541
558
  if (!scUserContext.user && !(scUserContext.loading && open)) {
542
559
  return null;
543
560
  }
544
- return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ ref: dialogRef, TransitionComponent: DialogTransition, keepMounted: true, onClose: handleClose }, rest, { className: (0, classnames_1.default)(classes.root, { [classes.ios]: isIOS }), scroll: "body", fullScreen: fullScreen, tabIndex: -1 }, { children: [(0, jsx_runtime_1.jsxs)("form", Object.assign({ onSubmit: handleSubmit, method: "post" }, { children: [(0, jsx_runtime_1.jsxs)(material_1.DialogTitle, Object.assign({ className: classes.title }, { children: [(0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: handleClosePrompt }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "close" }) })), (0, jsx_runtime_1.jsx)(LoadingButton_1.default, Object.assign({ size: "small", type: "submit", color: "secondary", variant: "contained", disabled: !canSubmit, loading: isSubmitting }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.submit", defaultMessage: "ui.composer.submit" }) }))] })), (0, jsx_runtime_1.jsxs)(material_1.DialogContent, Object.assign({ className: classes.content }, { children: [(0, jsx_runtime_1.jsx)(Attributes_1.default, { value: { categories, group, addressing, location }, className: classes.attributes, onChange: handleChangeAttributes, onClick: handleClickAttributes }), content, medias && medias.length > 0 && ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.medias }, { children: mediaObjectTypes.map((mediaObjectType) => {
561
+ return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ ref: dialogRef, TransitionComponent: DialogTransition, keepMounted: true, onClose: handleClose }, rest, { className: (0, classnames_1.default)(classes.root, { [classes.ios]: isIOS }), scroll: "body", fullScreen: fullScreen, tabIndex: -1 }, { children: [(0, jsx_runtime_1.jsxs)("form", Object.assign({ onSubmit: handleSubmit, method: "post" }, { children: [(0, jsx_runtime_1.jsxs)(material_1.DialogTitle, Object.assign({ className: classes.title }, { children: [(0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: handleClosePrompt }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "close" }) })), (0, jsx_runtime_1.jsx)(LoadingButton_1.default, Object.assign({ size: "small", type: "submit", color: "secondary", variant: "contained", disabled: !canSubmit, loading: isSubmitting }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.submit", defaultMessage: "ui.composer.submit" }) }))] })), (0, jsx_runtime_1.jsxs)(material_1.DialogContent, Object.assign({ className: classes.content }, { children: [(0, jsx_runtime_1.jsx)(Attributes_1.default, { value: { categories, event, group, addressing, location }, className: classes.attributes, onChange: handleChangeAttributes, onClick: handleClickAttributes }), content, medias && medias.length > 0 && ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.medias }, { children: mediaObjectTypes.map((mediaObjectType) => {
545
562
  if (mediaObjectType.previewComponent) {
546
563
  return (0, jsx_runtime_1.jsx)(mediaObjectType.previewComponent, { value: medias, onChange: handleChangeMedias }, mediaObjectType.name);
547
564
  }
@@ -553,6 +570,6 @@ function Composer(inProps) {
553
570
  .map((mediaObjectType) => {
554
571
  const props = mediaObjectType.layerComponent ? { onClick: handleMediaTriggerClick(mediaObjectType) } : { onAdd: handleAddMedia };
555
572
  return ((0, jsx_runtime_1.jsx)(mediaObjectType.triggerButton, Object.assign({ disabled: isSubmitting || hasMediaShare, color: medias.filter(mediaObjectType.filter).length > 0 ? 'primary' : 'default' }, props), mediaObjectType.name));
556
- }), (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ disabled: isSubmitting, onClick: handleAddCategoryLayer }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "category" }) })), (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ disabled: isSubmitting || !features.includes(types_1.SCFeatureName.TAGGING) || Boolean(feedObject === null || feedObject === void 0 ? void 0 : feedObject.group), onClick: handleAddAudienceLayer }, { children: (!group && addressing === null) || (addressing === null || addressing === void 0 ? void 0 : addressing.length) === 0 ? (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "public" }) : group ? (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "groups" }) : (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "label" }) })), preferences[react_core_1.SCPreferences.ADDONS_POST_GEOLOCATION_ENABLED].value && ((0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ disabled: isSubmitting, onClick: handleAddLocationLayer, color: location !== null ? 'primary' : 'default' }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "add_location_alt" }) })))] }))] })), layer && ((0, jsx_runtime_1.jsx)(LayerTransitionRoot, Object.assign({ className: classes.layerTransitionRoot, in: true, container: dialogRef.current, direction: "left" }, { children: (0, jsx_runtime_1.jsx)(layer.Component, Object.assign({}, layer.ComponentProps)) })))] })));
573
+ }), (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ disabled: isSubmitting, onClick: handleAddCategoryLayer }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "category" }) })), (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ disabled: isSubmitting || !features.includes(types_1.SCFeatureName.TAGGING) || Boolean(feedObject === null || feedObject === void 0 ? void 0 : feedObject.group) || Boolean(feedObject === null || feedObject === void 0 ? void 0 : feedObject.event), onClick: handleAddAudienceLayer }, { children: (!group && addressing === null) || (!event && addressing === null) || (addressing === null || addressing === void 0 ? void 0 : addressing.length) === 0 ? ((0, jsx_runtime_1.jsx)(Icon_1.default, { children: "public" })) : group ? ((0, jsx_runtime_1.jsx)(Icon_1.default, { children: "groups" })) : event ? ((0, jsx_runtime_1.jsx)(Icon_1.default, { children: "CalendarIcon" })) : ((0, jsx_runtime_1.jsx)(Icon_1.default, { children: "label" })) })), preferences[react_core_1.SCPreferences.ADDONS_POST_GEOLOCATION_ENABLED].value && ((0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ disabled: isSubmitting, onClick: handleAddLocationLayer, color: location !== null ? 'primary' : 'default' }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "add_location_alt" }) })))] }))] })), layer && ((0, jsx_runtime_1.jsx)(LayerTransitionRoot, Object.assign({ className: classes.layerTransitionRoot, in: true, container: dialogRef.current, direction: "left" }, { children: (0, jsx_runtime_1.jsx)(layer.Component, Object.assign({}, layer.ComponentProps)) })))] })));
557
574
  }
558
575
  exports.default = Composer;
@@ -28,6 +28,7 @@ const DEFAULT_DISCUSSION = {
28
28
  title: '',
29
29
  categories: [],
30
30
  group: null,
31
+ event: null,
31
32
  medias: [],
32
33
  html: '',
33
34
  addressing: []
@@ -27,6 +27,7 @@ const DEFAULT_POST = {
27
27
  medias: [],
28
28
  html: '',
29
29
  addressing: [],
30
+ event: null,
30
31
  group: null
31
32
  };
32
33
  exports.default = (props) => {
@@ -7,7 +7,8 @@ import { SCGroupType } from '@selfcommunity/types';
7
7
  export declare enum AudienceTypes {
8
8
  AUDIENCE_ALL = "all",
9
9
  AUDIENCE_TAG = "tag",
10
- AUDIENCE_GROUP = "group"
10
+ AUDIENCE_GROUP = "group",
11
+ AUDIENCE_EVENT = "event"
11
12
  }
12
13
  export interface AudienceLayerProps extends Omit<BoxProps, 'defaultValue'>, ComposerLayerProps {
13
14
  defaultValue: SCTagType[] | SCGroupType | any;
@@ -18,11 +18,13 @@ const react_core_1 = require("@selfcommunity/react-core");
18
18
  const constants_1 = require("../../constants");
19
19
  const GroupAutocomplete_1 = tslib_1.__importDefault(require("../../../GroupAutocomplete"));
20
20
  const types_1 = require("@selfcommunity/types");
21
+ const EventAutocomplete_1 = tslib_1.__importDefault(require("../../../EventAutocomplete"));
21
22
  var AudienceTypes;
22
23
  (function (AudienceTypes) {
23
24
  AudienceTypes["AUDIENCE_ALL"] = "all";
24
25
  AudienceTypes["AUDIENCE_TAG"] = "tag";
25
26
  AudienceTypes["AUDIENCE_GROUP"] = "group";
27
+ AudienceTypes["AUDIENCE_EVENT"] = "event";
26
28
  })(AudienceTypes = exports.AudienceTypes || (exports.AudienceTypes = {}));
27
29
  const classes = {
28
30
  root: `${constants_1.PREFIX}-layer-audience-root`,
@@ -48,9 +50,11 @@ const AudienceLayer = react_1.default.forwardRef((props, ref) => {
48
50
  // @ts-ignore
49
51
  defaultValue === null || defaultValue.length === 0
50
52
  ? AudienceTypes.AUDIENCE_ALL
51
- : defaultValue && Object.prototype.hasOwnProperty.call(defaultValue, 'managed_by')
52
- ? AudienceTypes.AUDIENCE_GROUP
53
- : AudienceTypes.AUDIENCE_TAG);
53
+ : defaultValue && Object.prototype.hasOwnProperty.call(defaultValue, 'recurring')
54
+ ? AudienceTypes.AUDIENCE_EVENT
55
+ : defaultValue && Object.prototype.hasOwnProperty.call(defaultValue, 'managed_by')
56
+ ? AudienceTypes.AUDIENCE_GROUP
57
+ : AudienceTypes.AUDIENCE_TAG);
54
58
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
55
59
  // @ts-ignore
56
60
  const [value, setValue] = (0, react_1.useState)(defaultValue || undefined);
@@ -58,19 +62,25 @@ const AudienceLayer = react_1.default.forwardRef((props, ref) => {
58
62
  const { scAddressingTags } = (0, react_core_1.useSCFetchAddressingTagList)({ fetch: autocompleteOpen });
59
63
  const { features } = (0, react_core_1.useSCPreferences)();
60
64
  // MEMO
65
+ const eventsEnabled = (0, react_1.useMemo)(() => features && features.includes(types_1.SCFeatureName.EVENT) && features.includes(types_1.SCFeatureName.TAGGING), [features]);
61
66
  const groupsEnabled = (0, react_1.useMemo)(() => features && features.includes(types_1.SCFeatureName.GROUPING) && features.includes(types_1.SCFeatureName.TAGGING), [features]);
62
67
  // HANDLERS
63
68
  const handleSave = (0, react_1.useCallback)(() => {
64
- audience === AudienceTypes.AUDIENCE_GROUP ? onSave(value) : onSave((value === null || value === void 0 ? void 0 : value.length) && (value === null || value === void 0 ? void 0 : value.length) > 0 ? value : null);
69
+ audience === AudienceTypes.AUDIENCE_GROUP || audience === AudienceTypes.AUDIENCE_EVENT
70
+ ? onSave(value)
71
+ : onSave((value === null || value === void 0 ? void 0 : value.length) && (value === null || value === void 0 ? void 0 : value.length) > 0 ? value : null);
65
72
  }, [value, onSave, audience]);
66
73
  const handleChange = (0, react_1.useCallback)((event, tags) => setValue(tags), []);
74
+ const handleEventChange = (0, react_1.useCallback)((event) => setValue(event), []);
67
75
  const handleGroupChange = (0, react_1.useCallback)((group) => setValue(group), []);
68
76
  const handleChangeAudience = (0, react_1.useCallback)((event, data) => setAudience(data), []);
69
77
  const handleAutocompleteOpen = (0, react_1.useCallback)(() => setAutocompleteOpen(true), []);
70
78
  const handleAutocompleteClose = (0, react_1.useCallback)(() => setAutocompleteOpen(false), []);
71
- return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ ref: ref, className: (0, classnames_1.default)(className, classes.root) }, rest, { children: [(0, jsx_runtime_1.jsxs)(material_1.DialogTitle, Object.assign({ className: classes.title }, { children: [(0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: onClose }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "arrow_back" }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.title", defaultMessage: "ui.composer.layer.audience.title" }) }), (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ size: "small", color: "secondary", variant: "contained", onClick: handleSave }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.save", defaultMessage: "ui.composer.layer.save" }) }))] })), (0, jsx_runtime_1.jsxs)(DialogContent_1.default, Object.assign({ className: classes.content }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Tabs, Object.assign({ value: audience, onChange: handleChangeAudience, "aria-label": "audience type" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Tab, { value: AudienceTypes.AUDIENCE_ALL, icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "public" }), label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.all", defaultMessage: "ui.composer.layer.audience.all" }) }), groupsEnabled && ((0, jsx_runtime_1.jsx)(material_1.Tab, { disabled: (Boolean(value === null || value === void 0 ? void 0 : value.length) && !Object.prototype.hasOwnProperty.call(value, 'managed_by')) ||
79
+ return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ ref: ref, className: (0, classnames_1.default)(className, classes.root) }, rest, { children: [(0, jsx_runtime_1.jsxs)(material_1.DialogTitle, Object.assign({ className: classes.title }, { children: [(0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: onClose }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "arrow_back" }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.title", defaultMessage: "ui.composer.layer.audience.title" }) }), (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ size: "small", color: "secondary", variant: "contained", onClick: handleSave }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.save", defaultMessage: "ui.composer.layer.save" }) }))] })), (0, jsx_runtime_1.jsxs)(DialogContent_1.default, Object.assign({ className: classes.content }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Tabs, Object.assign({ value: audience, onChange: handleChangeAudience, "aria-label": "audience type" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Tab, { value: AudienceTypes.AUDIENCE_ALL, icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "public" }), label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.all", defaultMessage: "ui.composer.layer.audience.all" }) }), eventsEnabled && ((0, jsx_runtime_1.jsx)(material_1.Tab, { disabled: (Boolean(value === null || value === void 0 ? void 0 : value.length) && !Object.prototype.hasOwnProperty.call(value, 'recurring')) ||
72
80
  (value !== undefined && Boolean(!(value === null || value === void 0 ? void 0 : value.length)) && audience !== AudienceTypes.AUDIENCE_ALL) ||
73
- (Boolean((value === null || value === void 0 ? void 0 : value.length) === 0) && audience === AudienceTypes.AUDIENCE_ALL && Boolean((defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length) !== 0)), value: AudienceTypes.AUDIENCE_GROUP, icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "groups" }), label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.group", defaultMessage: "ui.composer.layer.audience.group" }) })), (0, jsx_runtime_1.jsx)(material_1.Tab, { disabled: value && Object.prototype.hasOwnProperty.call(value, 'managed_by'), value: AudienceTypes.AUDIENCE_TAG, icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "label" }), label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.tag", defaultMessage: "ui.composer.layer.audience.tag" }) })] })), (0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ className: classes.message }, { children: [audience === AudienceTypes.AUDIENCE_ALL && ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.all.message", defaultMessage: "ui.composer.audience.layer.all.message" })), audience === AudienceTypes.AUDIENCE_GROUP && ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.group.message", defaultMessage: "ui.composer.audience.layer.group.message" })), audience === AudienceTypes.AUDIENCE_TAG && ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.tag.message", defaultMessage: "ui.composer.audience.layer.tag.message" }))] })), audience === AudienceTypes.AUDIENCE_TAG && ((0, jsx_runtime_1.jsx)(material_1.Autocomplete, { className: classes.autocomplete, open: autocompleteOpen, onOpen: handleAutocompleteOpen, onClose: handleAutocompleteClose, multiple: true, options: scAddressingTags || [], getOptionLabel: (option) => option.name || '', value: value, selectOnFocus: true, clearOnBlur: true, handleHomeEndKeys: true, clearIcon: null, noOptionsText: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.tags.empty", defaultMessage: "ui.composer.layer.audience.tags.empty" }), onChange: handleChange, isOptionEqualToValue: (option, value) => value.id === option.id, renderTags: (value, getTagProps) => {
81
+ (Boolean((value === null || value === void 0 ? void 0 : value.length) === 0) && audience === AudienceTypes.AUDIENCE_ALL && Boolean((defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length) !== 0)), value: AudienceTypes.AUDIENCE_EVENT, icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "CalendarIcon" }), label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.event", defaultMessage: "ui.composer.layer.audience.event" }) })), groupsEnabled && ((0, jsx_runtime_1.jsx)(material_1.Tab, { disabled: (Boolean(value === null || value === void 0 ? void 0 : value.length) && !Object.prototype.hasOwnProperty.call(value, 'managed_by')) ||
82
+ (value !== undefined && Boolean(!(value === null || value === void 0 ? void 0 : value.length)) && audience !== AudienceTypes.AUDIENCE_ALL) ||
83
+ (Boolean((value === null || value === void 0 ? void 0 : value.length) === 0) && audience === AudienceTypes.AUDIENCE_ALL && Boolean((defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length) !== 0)), value: AudienceTypes.AUDIENCE_GROUP, icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "groups" }), label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.group", defaultMessage: "ui.composer.layer.audience.group" }) })), (0, jsx_runtime_1.jsx)(material_1.Tab, { disabled: value && Object.prototype.hasOwnProperty.call(value, 'managed_by'), value: AudienceTypes.AUDIENCE_TAG, icon: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "label" }), label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.tag", defaultMessage: "ui.composer.layer.audience.tag" }) })] })), (0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ className: classes.message }, { children: [audience === AudienceTypes.AUDIENCE_ALL && ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.all.message", defaultMessage: "ui.composer.audience.layer.all.message" })), audience === AudienceTypes.AUDIENCE_EVENT && ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.event.message", defaultMessage: "ui.composer.audience.layer.event.message" })), audience === AudienceTypes.AUDIENCE_GROUP && ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.group.message", defaultMessage: "ui.composer.audience.layer.group.message" })), audience === AudienceTypes.AUDIENCE_TAG && ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.tag.message", defaultMessage: "ui.composer.audience.layer.tag.message" }))] })), audience === AudienceTypes.AUDIENCE_TAG && ((0, jsx_runtime_1.jsx)(material_1.Autocomplete, { className: classes.autocomplete, open: autocompleteOpen, onOpen: handleAutocompleteOpen, onClose: handleAutocompleteClose, multiple: true, options: scAddressingTags || [], getOptionLabel: (option) => option.name || '', value: value, selectOnFocus: true, clearOnBlur: true, handleHomeEndKeys: true, clearIcon: null, noOptionsText: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.tags.empty", defaultMessage: "ui.composer.layer.audience.tags.empty" }), onChange: handleChange, isOptionEqualToValue: (option, value) => value.id === option.id, renderTags: (value, getTagProps) => {
74
84
  return value.map((option, index) => (0, jsx_runtime_1.jsx)(TagChip_1.default, Object.assign({ tag: option }, getTagProps({ index })), option.id));
75
85
  }, renderOption: (props, option, { selected, inputValue }) => {
76
86
  const matches = (0, match_1.default)(option.name, inputValue);
@@ -78,6 +88,6 @@ const AudienceLayer = react_1.default.forwardRef((props, ref) => {
78
88
  return ((0, jsx_runtime_1.jsx)("li", Object.assign({}, props, { children: (0, jsx_runtime_1.jsx)(TagChip_1.default, { tag: option, label: (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: parts.map((part, index) => ((0, jsx_runtime_1.jsx)("span", Object.assign({ style: { fontWeight: part.highlight ? 700 : 400 } }, { children: part.text }), index))) }) }, option.id) })));
79
89
  }, renderInput: (params) => {
80
90
  return ((0, jsx_runtime_1.jsx)(TextField_1.default, Object.assign({}, params, TextFieldProps, { InputProps: Object.assign(Object.assign({}, params.InputProps), { autoComplete: 'addressing', endAdornment: (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: params.InputProps.endAdornment }) }) })));
81
- } })), audience === AudienceTypes.AUDIENCE_GROUP && (0, jsx_runtime_1.jsx)(GroupAutocomplete_1.default, { onChange: handleGroupChange, defaultValue: defaultValue })] }))] })));
91
+ } })), audience === AudienceTypes.AUDIENCE_GROUP && (0, jsx_runtime_1.jsx)(GroupAutocomplete_1.default, { onChange: handleGroupChange, defaultValue: defaultValue }), audience === AudienceTypes.AUDIENCE_EVENT && (0, jsx_runtime_1.jsx)(EventAutocomplete_1.default, { onChange: handleEventChange, defaultValue: defaultValue })] }))] })));
82
92
  });
83
93
  exports.default = AudienceLayer;
@@ -119,13 +119,13 @@ function Event(inProps) {
119
119
  */
120
120
  let contentObj;
121
121
  if (template === event_1.SCEventTemplateType.DETAIL) {
122
- contentObj = ((0, jsx_runtime_1.jsxs)(DetailRoot, Object.assign({ className: classes.detailRoot }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: classes.detailImageWrapper }, { children: [(0, jsx_runtime_1.jsx)(material_1.CardMedia, { component: "img", image: scEvent.image_medium, alt: scEvent.name, className: classes.detailImage }), (0, jsx_runtime_1.jsx)(Calendar_1.default, { day: new Date(scEvent.start_date).getDate() })] })), (0, jsx_runtime_1.jsxs)(material_1.CardContent, Object.assign({ className: classes.detailContent }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes.EVENT_ROUTE_NAME, scEvent), className: classes.detailNameWrapper }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "h3", className: classes.detailName }, { children: scEvent.name })) })), (0, jsx_runtime_1.jsx)(EventInfoDetails_1.default, { event: scEvent }), !hideEventPlanner && ((0, jsx_runtime_1.jsx)(User_1.default, { user: scEvent.managed_by, elevation: 0, secondary: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "caption" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.myEventsWidget.planner", defaultMessage: "ui.myEventsWidget.planner" }) })), actions: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}), className: classes.detailUser })), !hideEventParticipants && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Divider, { className: classes.detailFirstDivider }), (0, jsx_runtime_1.jsx)(EventPartecipantsButton_1.default, { event: scEvent, eventId: scEvent.id })] })), (0, jsx_runtime_1.jsx)(material_1.Divider, { className: classes.detailSecondDivider })] })), actions !== null && actions !== void 0 ? actions : ((0, jsx_runtime_1.jsx)(material_1.CardActions, Object.assign({ className: classes.detailActions }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ size: "small", variant: "outlined", component: react_core_1.Link, to: scRoutingContext.url(react_core_1.SCRoutes.EVENT_ROUTE_NAME, scEvent) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { defaultMessage: "ui.event.see", id: "ui.event.see" }) })) })))] })));
122
+ contentObj = ((0, jsx_runtime_1.jsxs)(DetailRoot, Object.assign({ className: classes.detailRoot }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: classes.detailImageWrapper }, { children: [(0, jsx_runtime_1.jsx)(material_1.CardMedia, { component: "img", image: scEvent.image_big, alt: scEvent.name, className: classes.detailImage }), (0, jsx_runtime_1.jsx)(Calendar_1.default, { day: new Date(scEvent.start_date).getDate() })] })), (0, jsx_runtime_1.jsxs)(material_1.CardContent, Object.assign({ className: classes.detailContent }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes.EVENT_ROUTE_NAME, scEvent), className: classes.detailNameWrapper }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "h3", className: classes.detailName }, { children: scEvent.name })) })), (0, jsx_runtime_1.jsx)(EventInfoDetails_1.default, { event: scEvent }), !hideEventPlanner && ((0, jsx_runtime_1.jsx)(User_1.default, { user: scEvent.managed_by, elevation: 0, secondary: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "caption" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.myEventsWidget.planner", defaultMessage: "ui.myEventsWidget.planner" }) })), actions: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}), className: classes.detailUser })), !hideEventParticipants && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Divider, { className: classes.detailFirstDivider }), (0, jsx_runtime_1.jsx)(EventPartecipantsButton_1.default, { event: scEvent, eventId: scEvent.id })] })), (0, jsx_runtime_1.jsx)(material_1.Divider, { className: classes.detailSecondDivider })] })), actions !== null && actions !== void 0 ? actions : ((0, jsx_runtime_1.jsx)(material_1.CardActions, Object.assign({ className: classes.detailActions }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ size: "small", variant: "outlined", component: react_core_1.Link, to: scRoutingContext.url(react_core_1.SCRoutes.EVENT_ROUTE_NAME, scEvent) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { defaultMessage: "ui.event.see", id: "ui.event.see" }) })) })))] })));
123
123
  }
124
124
  else if (template === event_1.SCEventTemplateType.PREVIEW) {
125
125
  contentObj = ((0, jsx_runtime_1.jsxs)(PreviewRoot, Object.assign({ className: classes.previewRoot }, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ position: "relative", className: classes.previewImageWrapper }, { children: (0, jsx_runtime_1.jsx)(material_1.CardMedia, { component: "img", height: "100px", image: scEvent.image_medium, alt: scEvent.name, className: classes.previewImage }) })), (0, jsx_runtime_1.jsxs)(material_1.CardContent, Object.assign({ className: classes.previewContent }, { children: [(0, jsx_runtime_1.jsx)(EventInfoDetails_1.default, { event: scEvent, hidePrivacyIcon: true, hasLocationInfo: false, beforePrivacyInfo: (0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes.EVENT_ROUTE_NAME, scEvent), className: classes.previewNameWrapper }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "h5", className: classes.previewName }, { children: scEvent.name })) })) }), !hideEventParticipants && (0, jsx_runtime_1.jsx)(EventPartecipantsButton_1.default, { event: scEvent })] })), actions !== null && actions !== void 0 ? actions : ((0, jsx_runtime_1.jsx)(material_1.CardActions, Object.assign({ className: classes.previewActions }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ size: "small", variant: "outlined", component: react_core_1.Link, to: scRoutingContext.url(react_core_1.SCRoutes.EVENT_ROUTE_NAME, scEvent) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { defaultMessage: "ui.event.see", id: "ui.event.see" }) })) })))] })));
126
126
  }
127
127
  else {
128
- contentObj = ((0, jsx_runtime_1.jsx)(SnippetRoot, { elevation: 0, square: true, disableTypography: true, className: classes.snippetRoot, image: (0, jsx_runtime_1.jsx)(material_1.Avatar, { variant: "square", alt: scEvent.name, src: scEvent.image_medium, className: classes.snippetAvatar }), primary: (0, jsx_runtime_1.jsxs)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes.EVENT_ROUTE_NAME, scEvent), className: classes.snippetPrimary }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ component: "span" }, { children: `${intl.formatDate(scEvent.start_date, {
128
+ contentObj = ((0, jsx_runtime_1.jsx)(SnippetRoot, { elevation: 0, square: true, disableTypography: true, className: classes.snippetRoot, image: (0, jsx_runtime_1.jsx)(material_1.Avatar, { variant: "square", alt: scEvent.name, src: scEvent.image_small, className: classes.snippetAvatar }), primary: (0, jsx_runtime_1.jsxs)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes.EVENT_ROUTE_NAME, scEvent), className: classes.snippetPrimary }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ component: "span" }, { children: `${intl.formatDate(scEvent.start_date, {
129
129
  weekday: 'long',
130
130
  month: 'long',
131
131
  day: 'numeric'
@@ -0,0 +1,48 @@
1
+ import { TextFieldProps } from '@mui/material/TextField';
2
+ import { AutocompleteProps } from '@mui/material';
3
+ import { SCEventType } from '@selfcommunity/types/src/index';
4
+ export interface EventAutocompleteProps extends Pick<AutocompleteProps<SCEventType | null, any, any, any>, Exclude<keyof AutocompleteProps<SCEventType | 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 events that will be visible when not focused.
7
+ * @default 0
8
+ */
9
+ limitCountEvents?: 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: events_label}
18
+ */
19
+ TextFieldProps?: TextFieldProps;
20
+ /**
21
+ * Callback for change event on event object
22
+ * @param value
23
+ */
24
+ onChange?: (value: any) => void;
25
+ }
26
+ /**
27
+ * > API documentation for the Community-JS Event 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 events available in the application.
31
+ *
32
+ * #### Import
33
+ * ```jsx
34
+ * import {EventAutocomplete} from '@selfcommunity/react-ui';
35
+ * ```
36
+ * #### Component Name
37
+ * The name `SCEventAutocomplete` can be used when providing style overrides in the theme.
38
+ *
39
+ * #### CSS
40
+ *
41
+ * |Rule Name|Global class|Description|
42
+ * |---|---|---|
43
+ * |root|.SCEventAutocomplete-root|Styles applied to the root element.|
44
+ *
45
+ * @param inProps
46
+ */
47
+ declare const EventAutocomplete: (inProps: EventAutocompleteProps) => JSX.Element;
48
+ export default EventAutocomplete;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = tslib_1.__importStar(require("react"));
6
+ const react_intl_1 = require("react-intl");
7
+ const Autocomplete_1 = tslib_1.__importDefault(require("@mui/material/Autocomplete"));
8
+ const TextField_1 = tslib_1.__importDefault(require("@mui/material/TextField"));
9
+ const CircularProgress_1 = tslib_1.__importDefault(require("@mui/material/CircularProgress"));
10
+ const parse_1 = tslib_1.__importDefault(require("autosuggest-highlight/parse"));
11
+ const match_1 = tslib_1.__importDefault(require("autosuggest-highlight/match"));
12
+ const material_1 = require("@mui/material");
13
+ const react_core_1 = require("@selfcommunity/react-core");
14
+ const styles_1 = require("@mui/material/styles");
15
+ const system_1 = require("@mui/system");
16
+ const PREFIX = 'SCEventAutocomplete';
17
+ const classes = {
18
+ root: `${PREFIX}-root`
19
+ };
20
+ const Root = (0, styles_1.styled)(Autocomplete_1.default, {
21
+ name: PREFIX,
22
+ slot: 'Root',
23
+ overridesResolver: (props, styles) => styles.root
24
+ })(() => ({}));
25
+ /**
26
+ * > API documentation for the Community-JS Event Autocomplete component. Learn about the available props and the CSS API.
27
+ *
28
+ *
29
+ * This component renders a bar that allows users to search (with autocomplete) for all the events available in the application.
30
+ *
31
+ * #### Import
32
+ * ```jsx
33
+ * import {EventAutocomplete} from '@selfcommunity/react-ui';
34
+ * ```
35
+ * #### Component Name
36
+ * The name `SCEventAutocomplete` can be used when providing style overrides in the theme.
37
+ *
38
+ * #### CSS
39
+ *
40
+ * |Rule Name|Global class|Description|
41
+ * |---|---|---|
42
+ * |root|.SCEventAutocomplete-root|Styles applied to the root element.|
43
+ *
44
+ * @param inProps
45
+ */
46
+ const EventAutocomplete = (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: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventAutocomplete.label", defaultMessage: "ui.eventAutocomplete.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 { events, isLoading } = (0, react_core_1.useSCFetchEvents)();
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(events.find((e) => e.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 = (e, value) => {
80
+ setValue(value);
81
+ };
82
+ // Render
83
+ return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ className: classes.root, open: open, onOpen: handleOpen, onClose: handleClose, options: events || [], getOptionLabel: (option) => option.name || '', value: value, selectOnFocus: true, clearOnBlur: true, blurOnSelect: true, handleHomeEndKeys: true, clearIcon: null, disabled: disabled || isLoading, noOptionsText: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.eventAutocomplete.empty", defaultMessage: "ui.eventAutocomplete.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 ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ component: "li" }, props, { children: [(0, jsx_runtime_1.jsx)(material_1.Avatar, { alt: option.name, src: option.image_small, sx: { marginRight: 1 } }), (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: parts.map((part, index) => ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ sx: { fontWeight: part.highlight ? 700 : 400, marginRight: 0.2 } }, { children: part.text }), index))) })] })));
93
+ }, renderInput: (params) => {
94
+ return ((0, jsx_runtime_1.jsx)(TextField_1.default, Object.assign({}, params, TextFieldProps, { margin: "dense", InputProps: Object.assign(Object.assign({}, params.InputProps), { autoComplete: 'events', endAdornment: ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [isLoading ? (0, jsx_runtime_1.jsx)(CircularProgress_1.default, { color: "inherit", size: 20 }) : null, params.InputProps.endAdornment] })) }) })));
95
+ } }, rest)));
96
+ };
97
+ exports.default = EventAutocomplete;
@@ -0,0 +1,3 @@
1
+ import EventAutocomplete, { EventAutocompleteProps } from './EventAutocomplete';
2
+ export default EventAutocomplete;
3
+ export { EventAutocompleteProps };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const EventAutocomplete_1 = tslib_1.__importDefault(require("./EventAutocomplete"));
5
+ exports.default = EventAutocomplete_1.default;