@selfcommunity/react-ui 0.7.0-alpha.360 → 0.7.0-alpha.362

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.
@@ -90,7 +90,7 @@ function AccountDataPortability(inProps) {
90
90
  */
91
91
  const handleDownloadDataPortabilityFile = () => {
92
92
  setDownloadingDataPortability(true);
93
- api_services_1.DataPortabilityService.downloadDataPortability()
93
+ api_services_1.DataPortabilityService.downloadDataPortability({ timeout: 30 * 60 * 1000 })
94
94
  .then((res) => {
95
95
  const url = window.URL.createObjectURL(new Blob([res], { type: 'application/zip' }));
96
96
  const link = document.createElement('a');
@@ -180,9 +180,10 @@ function Composer(inProps) {
180
180
  return poll && poll.title.length > 0 && poll.title.length < Composer_1.COMPOSER_TITLE_MAX_LENGTH && poll.choices.length >= Composer_1.COMPOSER_POLL_MIN_CHOICES;
181
181
  }, [poll]);
182
182
  const canSubmit = (0, react_1.useMemo)(() => {
183
- return !isLoading && ((type === types_1.SCContributionType.DISCUSSION && title.length > 0 && title.length < Composer_1.COMPOSER_TITLE_MAX_LENGTH) ||
184
- (type === types_1.SCContributionType.POST && ((0, utils_1.stripHtml)(html).length > 0 || medias.length > 0 || hasPoll)) ||
185
- (type === Composer_1.COMPOSER_TYPE_POLL && hasPoll));
183
+ return (!isLoading &&
184
+ ((type === types_1.SCContributionType.DISCUSSION && title.length > 0 && title.length < Composer_1.COMPOSER_TITLE_MAX_LENGTH) ||
185
+ (type === types_1.SCContributionType.POST && ((0, utils_1.stripHtml)(html).length > 0 || medias.length > 0 || hasPoll)) ||
186
+ (type === Composer_1.COMPOSER_TYPE_POLL && hasPoll)));
186
187
  }, [isLoading, type, title, html, medias, hasPoll]);
187
188
  const isIOS = (0, react_1.useMemo)(() => (0, utils_1.iOS)(), []);
188
189
  // Load feed object
@@ -230,8 +231,8 @@ function Composer(inProps) {
230
231
  const handleBlur = () => {
231
232
  dialogRef.current.focus();
232
233
  };
233
- dialogRef.current.addEventListener("touchstart", handleBlur);
234
- return () => { var _a; return (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener("touchstart", handleBlur); };
234
+ dialogRef.current.addEventListener('touchstart', handleBlur);
235
+ return () => { var _a; return (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('touchstart', handleBlur); };
235
236
  }, [dialogRef.current, isIOS]);
236
237
  /* Handlers */
237
238
  const handleAddLayer = (0, react_1.useCallback)((layer) => setLayer(layer), []);
@@ -403,14 +404,31 @@ function Composer(inProps) {
403
404
  })
404
405
  .then(() => setIsSubmitting(false));
405
406
  }, [scUserContext.user, feedObjectType, id, type, title, html, categories, addressing, audience, medias, poll, location, hasPoll]);
406
- const handleClose = (0, react_1.useCallback)((event) => {
407
+ //edited here
408
+ const handleClose = (0, react_1.useCallback)((event, reason) => {
407
409
  if (unloadRef.current) {
408
410
  window.onbeforeunload = null;
409
411
  }
410
- onClose && onClose(event);
411
- setLayer(null);
412
- dispatch({ type: 'reset' });
413
- }, [onClose]);
412
+ if (reason && canSubmit) {
413
+ handleAddLayer({
414
+ name: 'close',
415
+ Component: CloseLayer_1.default,
416
+ ComponentProps: {
417
+ onClose: handleRemoveLayer,
418
+ onSave: () => {
419
+ onClose && onClose(event);
420
+ setLayer(null);
421
+ dispatch({ type: 'reset' });
422
+ }
423
+ }
424
+ });
425
+ }
426
+ else {
427
+ onClose && onClose(event);
428
+ setLayer(null);
429
+ dispatch({ type: 'reset' });
430
+ }
431
+ }, [onClose, canSubmit, handleRemoveLayer]);
414
432
  const handleClosePrompt = (0, react_1.useCallback)((event) => {
415
433
  if (canSubmit) {
416
434
  handleAddLayer({
@@ -440,11 +458,11 @@ function Composer(inProps) {
440
458
  }
441
459
  switch (type) {
442
460
  case Composer_1.COMPOSER_TYPE_POLL:
443
- return react_1.default.createElement(ContentPoll_1.default, { key: key, onChange: handleChangePoll, value: { html, categories, addressing, medias, poll, location }, error: pollError, disabled: isSubmitting });
461
+ return (react_1.default.createElement(ContentPoll_1.default, { key: key, onChange: handleChangePoll, value: { html, categories, addressing, medias, poll, location }, error: pollError, disabled: isSubmitting }));
444
462
  case types_1.SCContributionType.DISCUSSION:
445
- return react_1.default.createElement(ContentDiscussion_1.default, { key: key, value: { title, html, categories, addressing, medias, poll, location }, error: { titleError, error }, onChange: handleChangeDiscussion, disabled: isSubmitting, EditorProps: Object.assign({ toolbar: true, uploadImage: true }, EditorProps) });
463
+ return (react_1.default.createElement(ContentDiscussion_1.default, { key: key, value: { title, html, categories, addressing, medias, poll, location }, error: { titleError, error }, onChange: handleChangeDiscussion, disabled: isSubmitting, EditorProps: Object.assign({ toolbar: true, uploadImage: true }, EditorProps) }));
446
464
  default:
447
- return react_1.default.createElement(ContentPost_1.default, { key: key, value: { html, categories, addressing, medias, poll, location }, error: { error }, onChange: handleChangePost, disabled: isSubmitting, EditorProps: Object.assign({ toolbar: false, uploadImage: false }, EditorProps) });
465
+ return (react_1.default.createElement(ContentPost_1.default, { key: key, value: { html, categories, addressing, medias, poll, location }, error: { error }, onChange: handleChangePost, disabled: isSubmitting, EditorProps: Object.assign({ toolbar: false, uploadImage: false }, EditorProps) }));
448
466
  }
449
467
  }, [key, type, title, html, categories, addressing, medias, poll, pollError, location, error, handleChangePoll, handleChangePost, isSubmitting]);
450
468
  if (!scUserContext.user && !(scUserContext.loading && open)) {
@@ -460,14 +478,14 @@ function Composer(inProps) {
460
478
  react_1.default.createElement(material_1.DialogContent, { className: classes.content },
461
479
  react_1.default.createElement(Attributes_1.default, { value: { categories, addressing, location }, className: classes.attributes, onChange: handleChangeAttributes, onClick: handleClickAttributes }),
462
480
  content,
463
- medias && medias.length > 0 && react_1.default.createElement(material_1.Box, { className: classes.medias }, mediaObjectTypes.map((mediaObjectType) => {
481
+ medias && medias.length > 0 && (react_1.default.createElement(material_1.Box, { className: classes.medias }, mediaObjectTypes.map((mediaObjectType) => {
464
482
  if (mediaObjectType.previewComponent) {
465
483
  return react_1.default.createElement(mediaObjectType.previewComponent, { key: mediaObjectType.name, value: medias, onChange: handleChangeMedias });
466
484
  }
467
485
  else if (mediaObjectType.displayComponent) {
468
486
  return react_1.default.createElement(mediaObjectType.displayComponent, { key: mediaObjectType.name, medias: medias });
469
487
  }
470
- }))),
488
+ })))),
471
489
  !canSubmit && !editMode && react_1.default.createElement(TypeSwitchButtonGroup_1.default, { className: classes.types, onChange: handleChangeType, size: "small", value: type }),
472
490
  react_1.default.createElement(material_1.DialogActions, { className: classes.actions },
473
491
  mediaObjectTypes
@@ -481,7 +499,7 @@ function Composer(inProps) {
481
499
  react_1.default.createElement(material_1.IconButton, { disabled: isSubmitting || !features.includes(types_1.SCFeatureName.TAGGING), onClick: handleAddAudienceLayer }, addressing === null || addressing.length === 0 ? react_1.default.createElement(Icon_1.default, null, "public") : react_1.default.createElement(Icon_1.default, null, "label")),
482
500
  preferences[react_core_1.SCPreferences.ADDONS_POST_GEOLOCATION_ENABLED].value && (react_1.default.createElement(material_1.IconButton, { disabled: isSubmitting, onClick: handleAddLocationLayer, color: location !== null ? 'primary' : 'default' },
483
501
  react_1.default.createElement(Icon_1.default, null, "add_location_alt"))))),
484
- layer && react_1.default.createElement(LayerTransitionRoot, { className: classes.layerTransitionRoot, in: true, container: dialogRef.current, direction: "left" },
485
- react_1.default.createElement(layer.Component, Object.assign({}, layer.ComponentProps)))));
502
+ layer && (react_1.default.createElement(LayerTransitionRoot, { className: classes.layerTransitionRoot, in: true, container: dialogRef.current, direction: "left" },
503
+ react_1.default.createElement(layer.Component, Object.assign({}, layer.ComponentProps))))));
486
504
  }
487
505
  exports.default = Composer;
@@ -88,7 +88,7 @@ export default function AccountDataPortability(inProps) {
88
88
  */
89
89
  const handleDownloadDataPortabilityFile = () => {
90
90
  setDownloadingDataPortability(true);
91
- DataPortabilityService.downloadDataPortability()
91
+ DataPortabilityService.downloadDataPortability({ timeout: 30 * 60 * 1000 })
92
92
  .then((res) => {
93
93
  const url = window.URL.createObjectURL(new Blob([res], { type: 'application/zip' }));
94
94
  const link = document.createElement('a');
@@ -1,11 +1,11 @@
1
1
  import { __rest } from "tslib";
2
- import React, { forwardRef, useCallback, useEffect, useMemo, useReducer, useRef, useState, } from 'react';
3
- import { SCContributionType, SCFeatureName, } from '@selfcommunity/types';
2
+ import React, { forwardRef, useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react';
3
+ import { SCContributionType, SCFeatureName } from '@selfcommunity/types';
4
4
  import { Endpoints, formatHttpErrorCode, http } from '@selfcommunity/api-services';
5
- import { SCPreferences, UserUtils, useSCPreferences, useSCUser, } from '@selfcommunity/react-core';
5
+ import { SCPreferences, UserUtils, useSCPreferences, useSCUser } from '@selfcommunity/react-core';
6
6
  import { FormattedMessage } from 'react-intl';
7
7
  import Icon from '@mui/material/Icon';
8
- import { Alert, AlertTitle, Box, Dialog, DialogActions, DialogContent, DialogTitle, Fade, IconButton, Slide, useMediaQuery, } from '@mui/material';
8
+ import { Alert, AlertTitle, Box, Dialog, DialogActions, DialogContent, DialogTitle, Fade, IconButton, Slide, useMediaQuery } from '@mui/material';
9
9
  import { styled, useTheme } from '@mui/material/styles';
10
10
  import { COMPOSER_POLL_MIN_CHOICES, COMPOSER_TITLE_MAX_LENGTH, COMPOSER_TYPE_POLL } from '../../constants/Composer';
11
11
  import { MEDIA_TYPE_SHARE } from '../../constants/Media';
@@ -178,9 +178,10 @@ export default function Composer(inProps) {
178
178
  return poll && poll.title.length > 0 && poll.title.length < COMPOSER_TITLE_MAX_LENGTH && poll.choices.length >= COMPOSER_POLL_MIN_CHOICES;
179
179
  }, [poll]);
180
180
  const canSubmit = useMemo(() => {
181
- return !isLoading && ((type === SCContributionType.DISCUSSION && title.length > 0 && title.length < COMPOSER_TITLE_MAX_LENGTH) ||
182
- (type === SCContributionType.POST && (stripHtml(html).length > 0 || medias.length > 0 || hasPoll)) ||
183
- (type === COMPOSER_TYPE_POLL && hasPoll));
181
+ return (!isLoading &&
182
+ ((type === SCContributionType.DISCUSSION && title.length > 0 && title.length < COMPOSER_TITLE_MAX_LENGTH) ||
183
+ (type === SCContributionType.POST && (stripHtml(html).length > 0 || medias.length > 0 || hasPoll)) ||
184
+ (type === COMPOSER_TYPE_POLL && hasPoll)));
184
185
  }, [isLoading, type, title, html, medias, hasPoll]);
185
186
  const isIOS = useMemo(() => iOS(), []);
186
187
  // Load feed object
@@ -228,8 +229,8 @@ export default function Composer(inProps) {
228
229
  const handleBlur = () => {
229
230
  dialogRef.current.focus();
230
231
  };
231
- dialogRef.current.addEventListener("touchstart", handleBlur);
232
- return () => { var _a; return (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener("touchstart", handleBlur); };
232
+ dialogRef.current.addEventListener('touchstart', handleBlur);
233
+ return () => { var _a; return (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('touchstart', handleBlur); };
233
234
  }, [dialogRef.current, isIOS]);
234
235
  /* Handlers */
235
236
  const handleAddLayer = useCallback((layer) => setLayer(layer), []);
@@ -401,14 +402,31 @@ export default function Composer(inProps) {
401
402
  })
402
403
  .then(() => setIsSubmitting(false));
403
404
  }, [scUserContext.user, feedObjectType, id, type, title, html, categories, addressing, audience, medias, poll, location, hasPoll]);
404
- const handleClose = useCallback((event) => {
405
+ //edited here
406
+ const handleClose = useCallback((event, reason) => {
405
407
  if (unloadRef.current) {
406
408
  window.onbeforeunload = null;
407
409
  }
408
- onClose && onClose(event);
409
- setLayer(null);
410
- dispatch({ type: 'reset' });
411
- }, [onClose]);
410
+ if (reason && canSubmit) {
411
+ handleAddLayer({
412
+ name: 'close',
413
+ Component: CloseLayer,
414
+ ComponentProps: {
415
+ onClose: handleRemoveLayer,
416
+ onSave: () => {
417
+ onClose && onClose(event);
418
+ setLayer(null);
419
+ dispatch({ type: 'reset' });
420
+ }
421
+ }
422
+ });
423
+ }
424
+ else {
425
+ onClose && onClose(event);
426
+ setLayer(null);
427
+ dispatch({ type: 'reset' });
428
+ }
429
+ }, [onClose, canSubmit, handleRemoveLayer]);
412
430
  const handleClosePrompt = useCallback((event) => {
413
431
  if (canSubmit) {
414
432
  handleAddLayer({
@@ -438,11 +456,11 @@ export default function Composer(inProps) {
438
456
  }
439
457
  switch (type) {
440
458
  case COMPOSER_TYPE_POLL:
441
- return React.createElement(ContentPoll, { key: key, onChange: handleChangePoll, value: { html, categories, addressing, medias, poll, location }, error: pollError, disabled: isSubmitting });
459
+ return (React.createElement(ContentPoll, { key: key, onChange: handleChangePoll, value: { html, categories, addressing, medias, poll, location }, error: pollError, disabled: isSubmitting }));
442
460
  case SCContributionType.DISCUSSION:
443
- return React.createElement(ContentDiscussion, { key: key, value: { title, html, categories, addressing, medias, poll, location }, error: { titleError, error }, onChange: handleChangeDiscussion, disabled: isSubmitting, EditorProps: Object.assign({ toolbar: true, uploadImage: true }, EditorProps) });
461
+ return (React.createElement(ContentDiscussion, { key: key, value: { title, html, categories, addressing, medias, poll, location }, error: { titleError, error }, onChange: handleChangeDiscussion, disabled: isSubmitting, EditorProps: Object.assign({ toolbar: true, uploadImage: true }, EditorProps) }));
444
462
  default:
445
- return React.createElement(ContentPost, { key: key, value: { html, categories, addressing, medias, poll, location }, error: { error }, onChange: handleChangePost, disabled: isSubmitting, EditorProps: Object.assign({ toolbar: false, uploadImage: false }, EditorProps) });
463
+ return (React.createElement(ContentPost, { key: key, value: { html, categories, addressing, medias, poll, location }, error: { error }, onChange: handleChangePost, disabled: isSubmitting, EditorProps: Object.assign({ toolbar: false, uploadImage: false }, EditorProps) }));
446
464
  }
447
465
  }, [key, type, title, html, categories, addressing, medias, poll, pollError, location, error, handleChangePoll, handleChangePost, isSubmitting]);
448
466
  if (!scUserContext.user && !(scUserContext.loading && open)) {
@@ -458,14 +476,14 @@ export default function Composer(inProps) {
458
476
  React.createElement(DialogContent, { className: classes.content },
459
477
  React.createElement(Attributes, { value: { categories, addressing, location }, className: classes.attributes, onChange: handleChangeAttributes, onClick: handleClickAttributes }),
460
478
  content,
461
- medias && medias.length > 0 && React.createElement(Box, { className: classes.medias }, mediaObjectTypes.map((mediaObjectType) => {
479
+ medias && medias.length > 0 && (React.createElement(Box, { className: classes.medias }, mediaObjectTypes.map((mediaObjectType) => {
462
480
  if (mediaObjectType.previewComponent) {
463
481
  return React.createElement(mediaObjectType.previewComponent, { key: mediaObjectType.name, value: medias, onChange: handleChangeMedias });
464
482
  }
465
483
  else if (mediaObjectType.displayComponent) {
466
484
  return React.createElement(mediaObjectType.displayComponent, { key: mediaObjectType.name, medias: medias });
467
485
  }
468
- }))),
486
+ })))),
469
487
  !canSubmit && !editMode && React.createElement(TypeSwitchButtonGroup, { className: classes.types, onChange: handleChangeType, size: "small", value: type }),
470
488
  React.createElement(DialogActions, { className: classes.actions },
471
489
  mediaObjectTypes
@@ -479,6 +497,6 @@ export default function Composer(inProps) {
479
497
  React.createElement(IconButton, { disabled: isSubmitting || !features.includes(SCFeatureName.TAGGING), onClick: handleAddAudienceLayer }, addressing === null || addressing.length === 0 ? React.createElement(Icon, null, "public") : React.createElement(Icon, null, "label")),
480
498
  preferences[SCPreferences.ADDONS_POST_GEOLOCATION_ENABLED].value && (React.createElement(IconButton, { disabled: isSubmitting, onClick: handleAddLocationLayer, color: location !== null ? 'primary' : 'default' },
481
499
  React.createElement(Icon, null, "add_location_alt"))))),
482
- layer && React.createElement(LayerTransitionRoot, { className: classes.layerTransitionRoot, in: true, container: dialogRef.current, direction: "left" },
483
- React.createElement(layer.Component, Object.assign({}, layer.ComponentProps)))));
500
+ layer && (React.createElement(LayerTransitionRoot, { className: classes.layerTransitionRoot, in: true, container: dialogRef.current, direction: "left" },
501
+ React.createElement(layer.Component, Object.assign({}, layer.ComponentProps))))));
484
502
  }