cozy-sharing 18.0.0 → 19.0.0

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 (42) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/components/Recipient/LinkRecipientPermissions.js +18 -129
  3. package/dist/components/Recipient/actions/editPermissionLink.js +71 -0
  4. package/dist/components/Recipient/actions/readOnlyPermissionLink.js +63 -0
  5. package/dist/components/ShareByLink.js +45 -185
  6. package/dist/components/ShareDialogCozyToCozy.js +2 -6
  7. package/dist/components/ShareDialogOnlyByLink.js +2 -8
  8. package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +1 -3
  9. package/dist/components/ShareModal/EditableSharingModal.js +1 -7
  10. package/dist/components/ShareModal.js +0 -12
  11. package/dist/components/ShareRestrictionModal/BoxDate.js +77 -0
  12. package/dist/components/ShareRestrictionModal/BoxEditingRights.js +83 -0
  13. package/dist/components/ShareRestrictionModal/BoxPassword.js +138 -0
  14. package/dist/components/ShareRestrictionModal/ShareRestrictionContentModal.js +94 -0
  15. package/dist/components/ShareRestrictionModal/ShareRestrictionModal.js +260 -0
  16. package/dist/components/ShareRestrictionModal/helpers.js +275 -0
  17. package/dist/components/ShareRestrictionModal/helpers.spec.js +110 -0
  18. package/dist/components/WhoHasAccess.js +1 -5
  19. package/locales/en.json +28 -0
  20. package/locales/fr.json +29 -0
  21. package/package.json +11 -7
  22. package/src/components/Recipient/LinkRecipientPermissions.jsx +28 -137
  23. package/src/components/Recipient/actions/editPermissionLink.js +63 -0
  24. package/src/components/Recipient/actions/readOnlyPermissionLink.js +59 -0
  25. package/src/components/ShareByLink.jsx +20 -96
  26. package/src/components/ShareDialogCozyToCozy.jsx +1 -5
  27. package/src/components/ShareDialogOnlyByLink.jsx +0 -6
  28. package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +0 -2
  29. package/src/components/ShareModal/EditableSharingModal.jsx +1 -7
  30. package/src/components/ShareModal.jsx +0 -12
  31. package/src/components/ShareRestrictionModal/BoxDate.jsx +76 -0
  32. package/src/components/ShareRestrictionModal/BoxEditingRights.jsx +91 -0
  33. package/src/components/ShareRestrictionModal/BoxPassword.jsx +112 -0
  34. package/src/components/ShareRestrictionModal/ShareRestrictionContentModal.jsx +102 -0
  35. package/src/components/ShareRestrictionModal/ShareRestrictionModal.jsx +177 -0
  36. package/src/components/ShareRestrictionModal/helpers.js +193 -0
  37. package/src/components/ShareRestrictionModal/helpers.spec.js +78 -0
  38. package/src/components/WhoHasAccess.jsx +1 -5
  39. package/dist/components/EditLinkPermissionDialog.js +0 -72
  40. package/dist/components/EditLinkPermissionDialog.spec.js +0 -48
  41. package/src/components/EditLinkPermissionDialog.jsx +0 -89
  42. package/src/components/EditLinkPermissionDialog.spec.jsx +0 -53
package/CHANGELOG.md CHANGED
@@ -3,6 +3,37 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [19.0.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@18.0.0...cozy-sharing@19.0.0) (2025-01-08)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **sharing:** Update propTypes ([0474d9c](https://github.com/cozy/cozy-libs/commit/0474d9c46344b1f7abf65fc6e419a25aef33d2ed))
12
+
13
+
14
+ ### Features
15
+
16
+ * **sharing:** Add 3 actions to use the new action menu ([1af8fa7](https://github.com/cozy/cozy-libs/commit/1af8fa7dbffad63d117149d14e09399e9d71a8a6))
17
+ * **sharing:** Add missing devDeps ([5221b40](https://github.com/cozy/cozy-libs/commit/5221b40397935538e95dcec82c939fb22196c991))
18
+ * **sharing:** Add needed packages ([36a2b67](https://github.com/cozy/cozy-libs/commit/36a2b6771275a35b3ab484b22a18b6d9c7b61496))
19
+ * **sharing:** Add ShareRestrictionModal component ([df5ed28](https://github.com/cozy/cozy-libs/commit/df5ed28c7c7f5dbb339bf26d563e8ffd825a686f))
20
+ * **sharing:** Add the 3 boxes of the new link-sharing modal ([a297d20](https://github.com/cozy/cozy-libs/commit/a297d20c46966c82447491a6fefe2d96509c45a9))
21
+ * **sharing:** Move revoke action to a secondary button ([83d3738](https://github.com/cozy/cozy-libs/commit/83d3738220e2c02ed749a08a47f92ca08ce9feb7))
22
+ * **sharing:** Remove EditLinkPermissionDialog ([1b8bd56](https://github.com/cozy/cozy-libs/commit/1b8bd560f4e72b885817f1f17a83156b6c1a7d58))
23
+ * **sharing:** Remove useless props ([cc3f816](https://github.com/cozy/cozy-libs/commit/cc3f816b6d35deb619488495bb767e1d76b557de))
24
+ * **sharing:** Replace old sharing link menu with the new modal ([de1a1c2](https://github.com/cozy/cozy-libs/commit/de1a1c27a5747c0b8bf091ed1856994f65cdcdb2))
25
+ * **sharing:** Upgrade packages ([9a1312d](https://github.com/cozy/cozy-libs/commit/9a1312d43cba1dcd521e8d6502865ac2071535cf))
26
+ * **sharing:** Use ShareRestrictionModal when creating share link ([248c3b4](https://github.com/cozy/cozy-libs/commit/248c3b4904649e17e935afdef1bd2a0b87082dc7))
27
+
28
+
29
+ ### BREAKING CHANGES
30
+
31
+ * **sharing:** You muse have `cozy-client >= 52.1.0` and `cozy-ui >= 116.0.0`
32
+
33
+
34
+
35
+
36
+
6
37
  # [18.0.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@17.0.0...cozy-sharing@18.0.0) (2024-12-23)
7
38
 
8
39
 
@@ -1,26 +1,15 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
+ import PropTypes from 'prop-types';
4
3
  import React, { useState, useRef } from 'react';
5
4
  import DropdownButton from 'cozy-ui/transpiled/react/DropdownButton';
6
- import Icon from 'cozy-ui/transpiled/react/Icon';
7
- import TrashIcon from 'cozy-ui/transpiled/react/Icons/Trash';
8
- import Spinner from 'cozy-ui/transpiled/react/Spinner';
9
- import Typography from 'cozy-ui/transpiled/react/Typography';
10
- import ActionMenu, { ActionMenuItem, ActionMenuRadio } from 'cozy-ui/transpiled/react/deprecated/ActionMenu';
11
- import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter';
12
5
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
13
- import { isOnlyReadOnlyLinkAllowed } from '../../helpers/link';
14
6
  import { checkIsReadOnlyPermissions } from '../../helpers/permissions';
15
- import logger from '../../logger';
7
+ import { ShareRestrictionModal } from '../ShareRestrictionModal/ShareRestrictionModal';
16
8
 
17
9
  var LinkRecipientPermissions = function LinkRecipientPermissions(_ref) {
18
10
  var className = _ref.className,
19
11
  document = _ref.document,
20
- documentType = _ref.documentType,
21
- permissions = _ref.permissions,
22
- onChangePermissions = _ref.onChangePermissions,
23
- onDisable = _ref.onDisable;
12
+ permissions = _ref.permissions;
24
13
 
25
14
  var _useI18n = useI18n(),
26
15
  t = _useI18n.t;
@@ -29,129 +18,29 @@ var LinkRecipientPermissions = function LinkRecipientPermissions(_ref) {
29
18
 
30
19
  var _useState = useState(false),
31
20
  _useState2 = _slicedToArray(_useState, 2),
32
- menuIsOpen = _useState2[0],
33
- setMenuIsOpen = _useState2[1];
34
-
35
- var _useState3 = useState(false),
36
- _useState4 = _slicedToArray(_useState3, 2),
37
- loading = _useState4[0],
38
- setLoading = _useState4[1];
21
+ openShareRestrictionModal = _useState2[0],
22
+ setOpenShareRestrictionModal = _useState2[1];
39
23
 
40
24
  var isReadOnlyPermissions = checkIsReadOnlyPermissions(permissions);
41
-
42
- var toggleMenu = function toggleMenu() {
43
- setMenuIsOpen(!menuIsOpen);
44
- };
45
-
46
- var deleteShareLink = /*#__PURE__*/function () {
47
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
48
- return _regeneratorRuntime.wrap(function _callee$(_context) {
49
- while (1) switch (_context.prev = _context.next) {
50
- case 0:
51
- _context.prev = 0;
52
- setLoading(true);
53
- _context.next = 4;
54
- return onDisable(document);
55
-
56
- case 4:
57
- _context.next = 10;
58
- break;
59
-
60
- case 6:
61
- _context.prev = 6;
62
- _context.t0 = _context["catch"](0);
63
- Alerter.error(t("".concat(documentType, ".share.error.revoke")));
64
- logger.log(_context.t0);
65
-
66
- case 10:
67
- _context.prev = 10;
68
- setLoading(false);
69
- return _context.finish(10);
70
-
71
- case 13:
72
- case "end":
73
- return _context.stop();
74
- }
75
- }, _callee, null, [[0, 6, 10, 13]]);
76
- }));
77
-
78
- return function deleteShareLink() {
79
- return _ref2.apply(this, arguments);
80
- };
81
- }();
82
-
83
- var updateLinkPermissions = function updateLinkPermissions(_ref3) {
84
- var isReadOnly = _ref3.isReadOnly;
85
- var verbs = isReadOnly ? ['GET'] : ['GET', 'POST', 'PUT', 'PATCH'];
86
-
87
- try {
88
- onChangePermissions(document, verbs);
89
- } catch (err) {
90
- Alerter.error(t("".concat(documentType, ".share.shareByLink.permserror")));
91
- logger.log(err);
92
- }
93
- };
94
-
95
25
  return /*#__PURE__*/React.createElement("div", {
96
26
  className: className
97
- }, loading && /*#__PURE__*/React.createElement(Spinner, null), !loading && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DropdownButton, {
98
- onClick: toggleMenu,
27
+ }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DropdownButton, {
99
28
  ref: buttonRef,
100
- textVariant: "body2"
101
- }, t("Share.type.".concat(isReadOnlyPermissions ? 'one-way' : 'two-way')).toLowerCase()), menuIsOpen && /*#__PURE__*/React.createElement(ActionMenu, {
102
- onClose: toggleMenu,
103
- popperOptions: {
104
- placement: 'bottom-end',
105
- strategy: 'fixed'
106
- },
107
- anchorElRef: buttonRef
108
- }, /*#__PURE__*/React.createElement(ActionMenuItem, {
109
- left: /*#__PURE__*/React.createElement(ActionMenuRadio, {
110
- name: "permissionLinkMenu",
111
- value: "true",
112
- checked: isReadOnlyPermissions
113
- }),
29
+ textVariant: "body2",
114
30
  onClick: function onClick() {
115
- toggleMenu();
116
- updateLinkPermissions({
117
- isReadOnly: true
118
- });
31
+ return setOpenShareRestrictionModal(true);
119
32
  }
120
- }, /*#__PURE__*/React.createElement(React.Fragment, null, (document === null || document === void 0 ? void 0 : document.type) === 'directory' ? t("Share.permissionLink.seeFolder") : t("Share.permissionLink.seeFile"), /*#__PURE__*/React.createElement(Typography, {
121
- className: "u-mt-half",
122
- variant: "caption",
123
- color: "textSecondary"
124
- }, t('Share.permissionLink.readDescription')))), !isOnlyReadOnlyLinkAllowed({
125
- documentType: documentType
126
- }) && /*#__PURE__*/React.createElement(ActionMenuItem, {
127
- left: /*#__PURE__*/React.createElement(ActionMenuRadio, {
128
- name: "permissionLinkMenu",
129
- value: "false",
130
- checked: !isReadOnlyPermissions
131
- }),
132
- onClick: function onClick() {
133
- toggleMenu();
134
- updateLinkPermissions({
135
- isReadOnly: false
136
- });
137
- }
138
- }, /*#__PURE__*/React.createElement(React.Fragment, null, (document === null || document === void 0 ? void 0 : document.type) === 'directory' ? t("Share.permissionLink.modifyFolder") : t("Share.permissionLink.modifyFile"), /*#__PURE__*/React.createElement(Typography, {
139
- className: "u-mt-half",
140
- variant: "caption",
141
- color: "textSecondary"
142
- }, t('Share.permissionLink.writeDescription')))), /*#__PURE__*/React.createElement("hr", null), /*#__PURE__*/React.createElement(ActionMenuItem, {
143
- left: /*#__PURE__*/React.createElement(Icon, {
144
- icon: TrashIcon,
145
- color: "var(--errorColor)"
146
- }),
147
- onClick: function onClick() {
148
- toggleMenu();
149
- deleteShareLink();
33
+ }, t("Share.type.".concat(isReadOnlyPermissions ? 'one-way' : 'two-way')).toLowerCase()), openShareRestrictionModal && /*#__PURE__*/React.createElement(ShareRestrictionModal, {
34
+ file: document,
35
+ onClose: function onClose() {
36
+ return setOpenShareRestrictionModal(false);
150
37
  }
151
- }, /*#__PURE__*/React.createElement(Typography, {
152
- className: "u-error",
153
- variant: "body1"
154
- }, t('Share.permissionLink.deactivate'))))));
38
+ })));
155
39
  };
156
40
 
41
+ LinkRecipientPermissions.propTypes = {
42
+ className: PropTypes.string,
43
+ document: PropTypes.object.isRequired,
44
+ permissions: PropTypes.arrayOf(PropTypes.object).isRequired
45
+ };
157
46
  export default LinkRecipientPermissions;
@@ -0,0 +1,71 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React, { forwardRef } from 'react';
3
+ import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem';
4
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
5
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
6
+ import Radios from 'cozy-ui/transpiled/react/Radios';
7
+ import { isOnlyReadOnlyLinkAllowed } from '../../../helpers/link';
8
+ import { useSharingContext } from '../../../hooks/useSharingContext';
9
+
10
+ var makeComponent = function makeComponent(_ref) {
11
+ var label = _ref.label,
12
+ desc = _ref.desc,
13
+ editingRights = _ref.editingRights;
14
+ var Component = /*#__PURE__*/forwardRef(function (props, ref) {
15
+ var _useSharingContext = useSharingContext(),
16
+ updateDocumentPermissions = _useSharingContext.updateDocumentPermissions;
17
+
18
+ return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
19
+ ref: ref,
20
+ button: false,
21
+ onClick: function onClick() {
22
+ return props.onClick({
23
+ updateDocumentPermissions: updateDocumentPermissions
24
+ });
25
+ }
26
+ }), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Radios, {
27
+ checked: editingRights === 'write'
28
+ })), /*#__PURE__*/React.createElement(ListItemText, {
29
+ primary: label,
30
+ secondary: desc
31
+ }));
32
+ });
33
+ Component.displayName = 'EditPermissionLink';
34
+ return Component;
35
+ };
36
+ /**
37
+ * @param {boolean} isDirectory - true if the document is a directory
38
+ * @param {function} t - translation function
39
+ * @param {string} editingRights - current editing rights
40
+ * @param {function} setEditingRights - function to set editing rights
41
+ * @param {string} documentType - type of the document
42
+ */
43
+
44
+
45
+ export var editPermissionLink = function editPermissionLink(_ref2) {
46
+ var isDirectory = _ref2.isDirectory,
47
+ t = _ref2.t,
48
+ editingRights = _ref2.editingRights,
49
+ setEditingRights = _ref2.setEditingRights,
50
+ documentType = _ref2.documentType;
51
+ var label = isDirectory ? t('Share.permissionLink.modifyFolder') : t('Share.permissionLink.modifyFile');
52
+ var desc = t('Share.permissionLink.writeDescription');
53
+ return {
54
+ name: 'editPermissionLink',
55
+ label: label,
56
+ icon: null,
57
+ displayCondition: function displayCondition() {
58
+ return !isOnlyReadOnlyLinkAllowed({
59
+ documentType: documentType
60
+ });
61
+ },
62
+ action: function action() {
63
+ setEditingRights('write');
64
+ },
65
+ Component: makeComponent({
66
+ label: label,
67
+ desc: desc,
68
+ editingRights: editingRights
69
+ })
70
+ };
71
+ };
@@ -0,0 +1,63 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React, { forwardRef } from 'react';
3
+ import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem';
4
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
5
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
6
+ import Radios from 'cozy-ui/transpiled/react/Radios';
7
+ import { useSharingContext } from '../../../hooks/useSharingContext';
8
+
9
+ var makeComponent = function makeComponent(_ref) {
10
+ var label = _ref.label,
11
+ desc = _ref.desc,
12
+ editingRights = _ref.editingRights;
13
+ var Component = /*#__PURE__*/forwardRef(function (props, ref) {
14
+ var _useSharingContext = useSharingContext(),
15
+ updateDocumentPermissions = _useSharingContext.updateDocumentPermissions;
16
+
17
+ return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
18
+ ref: ref,
19
+ button: false,
20
+ onClick: function onClick() {
21
+ return props.onClick({
22
+ updateDocumentPermissions: updateDocumentPermissions
23
+ });
24
+ }
25
+ }), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Radios, {
26
+ checked: editingRights === 'readOnly'
27
+ })), /*#__PURE__*/React.createElement(ListItemText, {
28
+ primary: label,
29
+ secondary: desc
30
+ }));
31
+ });
32
+ Component.displayName = 'ReadOnlyPermissionLink';
33
+ return Component;
34
+ };
35
+ /**
36
+ * @param {boolean} isDirectory - true if the document is a directory
37
+ * @param {function} t - translation function
38
+ * @param {string} editingRights - current editing rights
39
+ * @param {function} setEditingRights - function to set editing rights
40
+ */
41
+
42
+
43
+ export var readOnlyPermissionLink = function readOnlyPermissionLink(_ref2) {
44
+ var isDirectory = _ref2.isDirectory,
45
+ t = _ref2.t,
46
+ editingRights = _ref2.editingRights,
47
+ setEditingRights = _ref2.setEditingRights;
48
+ var label = isDirectory ? t('Share.permissionLink.seeFolder') : t('Share.permissionLink.seeFile');
49
+ var desc = t('Share.permissionLink.readDescription');
50
+ return {
51
+ name: 'readOnlyPermissionLink',
52
+ label: label,
53
+ icon: null,
54
+ action: function action() {
55
+ setEditingRights('readOnly');
56
+ },
57
+ Component: makeComponent({
58
+ label: label,
59
+ desc: desc,
60
+ editingRights: editingRights
61
+ })
62
+ };
63
+ };
@@ -1,31 +1,22 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
-
5
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
-
7
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8
-
9
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
10
4
  import PropTypes from 'prop-types';
11
- import React, { useState, useEffect, useCallback } from 'react';
12
- import Alert from 'cozy-ui/transpiled/react/Alert';
5
+ import React, { useReducer } from 'react';
13
6
  import Button from 'cozy-ui/transpiled/react/Buttons';
14
7
  import Icon from 'cozy-ui/transpiled/react/Icon';
15
8
  import CopyIcon from 'cozy-ui/transpiled/react/Icons/Copy';
16
9
  import LinkIcon from 'cozy-ui/transpiled/react/Icons/Link';
17
- import Snackbar from 'cozy-ui/transpiled/react/Snackbar';
10
+ import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert';
18
11
  import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints';
19
12
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
20
- import EditLinkPermissionDialog from './EditLinkPermissionDialog';
21
- import { isOnlyReadOnlyLinkAllowed } from '../helpers/link';
22
- import logger from '../logger';
13
+ import { ShareRestrictionModal } from './ShareRestrictionModal/ShareRestrictionModal';
14
+ import { copyToClipboard } from './ShareRestrictionModal/helpers';
23
15
 
24
16
  var ShareByLink = function ShareByLink(_ref) {
25
17
  var link = _ref.link,
26
18
  document = _ref.document,
27
- documentType = _ref.documentType,
28
- onEnable = _ref.onEnable;
19
+ documentType = _ref.documentType;
29
20
 
30
21
  var _useI18n = useI18n(),
31
22
  t = _useI18n.t;
@@ -33,200 +24,80 @@ var ShareByLink = function ShareByLink(_ref) {
33
24
  var _useBreakpoints = useBreakpoints(),
34
25
  isMobile = _useBreakpoints.isMobile;
35
26
 
36
- var _useState = useState(false),
37
- _useState2 = _slicedToArray(_useState, 2),
38
- loading = _useState2[0],
39
- setLoading = _useState2[1];
40
-
41
- var _useState3 = useState(false),
42
- _useState4 = _slicedToArray(_useState3, 2),
43
- shouldCopyToClipboard = _useState4[0],
44
- setShouldCopyToClipboard = _useState4[1];
27
+ var _useAlert = useAlert(),
28
+ showAlert = _useAlert.showAlert;
45
29
 
46
- var _useState5 = useState(false),
47
- _useState6 = _slicedToArray(_useState5, 2),
48
- alert = _useState6[0],
49
- setAlert = _useState6[1];
30
+ var showCopyAndSendButtons = link && isMobile && navigator.share;
31
+ var showOnlyCopyButton = link && !isMobile || link && isMobile && !navigator.share;
50
32
 
51
- var _useState7 = useState(false),
52
- _useState8 = _slicedToArray(_useState7, 2),
53
- isEditDialogOpen = _useState8[0],
54
- setIsEditDialogOpen = _useState8[1];
33
+ var _useReducer = useReducer(function (state) {
34
+ return !state;
35
+ }, false),
36
+ _useReducer2 = _slicedToArray(_useReducer, 2),
37
+ isEditDialogOpen = _useReducer2[0],
38
+ toggleEditDialogOpen = _useReducer2[1];
55
39
 
56
- var copyLinkToClipboard = useCallback( /*#__PURE__*/function () {
57
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2) {
58
- var isAutomaticCopy;
40
+ var copyLinkToClipboard = /*#__PURE__*/function () {
41
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
59
42
  return _regeneratorRuntime.wrap(function _callee$(_context) {
60
43
  while (1) switch (_context.prev = _context.next) {
61
44
  case 0:
62
- isAutomaticCopy = _ref2.isAutomaticCopy;
63
- _context.prev = 1;
64
- _context.next = 4;
65
- return navigator.clipboard.writeText(link);
66
-
67
- case 4:
68
- setAlert({
69
- open: true,
70
- severity: 'success',
71
- message: t("".concat(documentType, ".share.shareByLink.copied"))
45
+ _context.next = 2;
46
+ return copyToClipboard(link, {
47
+ t: t,
48
+ showAlert: showAlert
72
49
  });
73
- _context.next = 10;
74
- break;
75
-
76
- case 7:
77
- _context.prev = 7;
78
- _context.t0 = _context["catch"](1);
79
50
 
80
- if (!isAutomaticCopy) {
81
- // In case of automatic copy, the browser can block the copy request. This is not shown to the user since it is expected and can be circumvented by clicking directly on the copy link
82
- setAlert({
83
- open: true,
84
- severity: 'error',
85
- message: t("".concat(documentType, ".share.shareByLink.failed"))
86
- });
87
- }
88
-
89
- case 10:
51
+ case 2:
90
52
  case "end":
91
53
  return _context.stop();
92
54
  }
93
- }, _callee, null, [[1, 7]]);
55
+ }, _callee);
94
56
  }));
95
57
 
96
- return function (_x) {
97
- return _ref3.apply(this, arguments);
98
- };
99
- }(), [documentType, link, t]);
100
-
101
- var onPermissionsSelected = /*#__PURE__*/function () {
102
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(options) {
103
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
104
- while (1) switch (_context2.prev = _context2.next) {
105
- case 0:
106
- _context2.prev = 0;
107
- setLoading(true);
108
- _context2.next = 4;
109
- return onEnable(document, options);
110
-
111
- case 4:
112
- _context2.next = 10;
113
- break;
114
-
115
- case 6:
116
- _context2.prev = 6;
117
- _context2.t0 = _context2["catch"](0);
118
- setAlert({
119
- open: true,
120
- severity: 'error',
121
- message: t("".concat(documentType, ".share.error.generic"))
122
- });
123
- logger.log(_context2.t0);
124
-
125
- case 10:
126
- _context2.prev = 10;
127
- setLoading(false);
128
- setShouldCopyToClipboard(true);
129
- return _context2.finish(10);
130
-
131
- case 14:
132
- case "end":
133
- return _context2.stop();
134
- }
135
- }, _callee2, null, [[0, 6, 10, 14]]);
136
- }));
137
-
138
- return function onPermissionsSelected(_x2) {
139
- return _ref4.apply(this, arguments);
58
+ return function copyLinkToClipboard() {
59
+ return _ref2.apply(this, arguments);
140
60
  };
141
61
  }();
142
62
 
143
- var onCreate = /*#__PURE__*/function () {
144
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
145
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
146
- while (1) switch (_context3.prev = _context3.next) {
147
- case 0:
148
- if (isOnlyReadOnlyLinkAllowed({
149
- documentType: documentType
150
- })) {
151
- onPermissionsSelected({
152
- verbs: ['GET']
153
- });
154
- } else {
155
- setIsEditDialogOpen(true);
156
- }
157
-
158
- case 1:
159
- case "end":
160
- return _context3.stop();
161
- }
162
- }, _callee3);
163
- }));
164
-
165
- return function onCreate() {
166
- return _ref5.apply(this, arguments);
167
- };
168
- }();
169
-
170
- useEffect(function () {
171
- if (link && shouldCopyToClipboard) {
172
- copyLinkToClipboard({
173
- isAutomaticCopy: true
174
- });
175
- setShouldCopyToClipboard(false);
176
- }
177
- }, [link, shouldCopyToClipboard, copyLinkToClipboard]);
178
-
179
- var onClose = function onClose() {
180
- setIsEditDialogOpen(false);
181
- };
182
-
183
- var onCloseAlert = function onCloseAlert() {
184
- setAlert(_objectSpread(_objectSpread({}, alert), {}, {
185
- open: false
186
- }));
187
- };
188
-
189
- var showCopyAndSendButtons = link && isMobile && navigator.share;
190
- var showOnlyCopyButton = link && !isMobile || link && isMobile && !navigator.share;
191
-
192
63
  var shareLink = /*#__PURE__*/function () {
193
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
64
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
194
65
  var shareData;
195
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
196
- while (1) switch (_context4.prev = _context4.next) {
66
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
67
+ while (1) switch (_context2.prev = _context2.next) {
197
68
  case 0:
198
- _context4.prev = 0;
69
+ _context2.prev = 0;
199
70
  shareData = {
200
71
  text: t("".concat(documentType, ".share.shareByLink.shareDescription"), {
201
72
  name: document.name || ''
202
73
  }),
203
74
  url: link
204
75
  };
205
- _context4.next = 4;
76
+ _context2.next = 4;
206
77
  return navigator.share(shareData);
207
78
 
208
79
  case 4:
209
- _context4.next = 9;
80
+ _context2.next = 9;
210
81
  break;
211
82
 
212
83
  case 6:
213
- _context4.prev = 6;
214
- _context4.t0 = _context4["catch"](0);
215
- setAlert({
216
- open: true,
84
+ _context2.prev = 6;
85
+ _context2.t0 = _context2["catch"](0);
86
+ showAlert({
87
+ message: t("".concat(documentType, ".share.error.generic")),
217
88
  severity: 'error',
218
- message: t("".concat(documentType, ".share.error.generic"))
89
+ variant: 'filled'
219
90
  });
220
91
 
221
92
  case 9:
222
93
  case "end":
223
- return _context4.stop();
94
+ return _context2.stop();
224
95
  }
225
- }, _callee4, null, [[0, 6]]);
96
+ }, _callee2, null, [[0, 6]]);
226
97
  }));
227
98
 
228
99
  return function shareLink() {
229
- return _ref6.apply(this, arguments);
100
+ return _ref3.apply(this, arguments);
230
101
  };
231
102
  }();
232
103
 
@@ -240,12 +111,11 @@ var ShareByLink = function ShareByLink(_ref) {
240
111
  icon: LinkIcon
241
112
  }),
242
113
  className: "u-flex-auto",
243
- busy: loading,
244
114
  style: {
245
115
  position: 'initial'
246
116
  } // fix z-index bug on iOS when under a BottomDrawer due to relative position
247
117
  ,
248
- onClick: onCreate
118
+ onClick: toggleEditDialogOpen
249
119
  }), showCopyAndSendButtons && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
250
120
  label: t("".concat(documentType, ".share.shareByLink.send")),
251
121
  variant: "secondary",
@@ -271,25 +141,15 @@ var ShareByLink = function ShareByLink(_ref) {
271
141
  }),
272
142
  className: "u-flex-auto u-mr-half",
273
143
  onClick: copyLinkToClipboard
274
- }), isEditDialogOpen && /*#__PURE__*/React.createElement(EditLinkPermissionDialog, {
275
- open: true,
276
- onClose: onClose,
277
- document: document,
278
- onPermissionsSelected: onPermissionsSelected
279
- }), /*#__PURE__*/React.createElement(Snackbar, {
280
- open: alert.open,
281
- onClose: onCloseAlert
282
- }, /*#__PURE__*/React.createElement(Alert, {
283
- variant: "filled",
284
- severity: alert.severity,
285
- onClose: onCloseAlert
286
- }, alert.message)));
144
+ }), isEditDialogOpen && /*#__PURE__*/React.createElement(ShareRestrictionModal, {
145
+ file: document,
146
+ onClose: toggleEditDialogOpen
147
+ }));
287
148
  };
288
149
 
289
150
  ShareByLink.propTypes = {
290
151
  link: PropTypes.string,
291
152
  document: PropTypes.object.isRequired,
292
- documentType: PropTypes.string.isRequired,
293
- onEnable: PropTypes.func.isRequired
153
+ documentType: PropTypes.string.isRequired
294
154
  };
295
155
  export default ShareByLink;