cozy-sharing 18.0.0 → 20.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 (48) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/dist/SharingProvider.js +16 -9
  3. package/dist/components/Recipient/LinkRecipient.js +20 -4
  4. package/dist/components/Recipient/LinkRecipientPermissions.js +18 -129
  5. package/dist/components/Recipient/actions/editPermissionLink.js +71 -0
  6. package/dist/components/Recipient/actions/readOnlyPermissionLink.js +63 -0
  7. package/dist/components/ShareByLink.js +45 -185
  8. package/dist/components/ShareDialogCozyToCozy.js +2 -6
  9. package/dist/components/ShareDialogOnlyByLink.js +2 -8
  10. package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +1 -3
  11. package/dist/components/ShareModal/EditableSharingModal.js +1 -7
  12. package/dist/components/ShareModal.js +0 -12
  13. package/dist/components/ShareRestrictionModal/BoxDate.js +77 -0
  14. package/dist/components/ShareRestrictionModal/BoxEditingRights.js +83 -0
  15. package/dist/components/ShareRestrictionModal/BoxPassword.js +155 -0
  16. package/dist/components/ShareRestrictionModal/ShareRestrictionContentModal.js +118 -0
  17. package/dist/components/ShareRestrictionModal/ShareRestrictionModal.js +256 -0
  18. package/dist/components/ShareRestrictionModal/helpers.js +310 -0
  19. package/dist/components/ShareRestrictionModal/helpers.spec.js +232 -0
  20. package/dist/components/WhoHasAccess.js +1 -5
  21. package/dist/helpers/permissions.js +15 -0
  22. package/locales/en.json +30 -0
  23. package/locales/fr.json +31 -0
  24. package/package.json +11 -7
  25. package/src/SharingProvider.jsx +10 -5
  26. package/src/components/Recipient/LinkRecipient.jsx +28 -4
  27. package/src/components/Recipient/LinkRecipientPermissions.jsx +28 -137
  28. package/src/components/Recipient/actions/editPermissionLink.js +63 -0
  29. package/src/components/Recipient/actions/readOnlyPermissionLink.js +59 -0
  30. package/src/components/ShareByLink.jsx +20 -96
  31. package/src/components/ShareDialogCozyToCozy.jsx +1 -5
  32. package/src/components/ShareDialogOnlyByLink.jsx +0 -6
  33. package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +0 -2
  34. package/src/components/ShareModal/EditableSharingModal.jsx +1 -7
  35. package/src/components/ShareModal.jsx +0 -12
  36. package/src/components/ShareRestrictionModal/BoxDate.jsx +76 -0
  37. package/src/components/ShareRestrictionModal/BoxEditingRights.jsx +91 -0
  38. package/src/components/ShareRestrictionModal/BoxPassword.jsx +126 -0
  39. package/src/components/ShareRestrictionModal/ShareRestrictionContentModal.jsx +124 -0
  40. package/src/components/ShareRestrictionModal/ShareRestrictionModal.jsx +186 -0
  41. package/src/components/ShareRestrictionModal/helpers.js +227 -0
  42. package/src/components/ShareRestrictionModal/helpers.spec.js +159 -0
  43. package/src/components/WhoHasAccess.jsx +1 -5
  44. package/src/helpers/permissions.js +12 -0
  45. package/dist/components/EditLinkPermissionDialog.js +0 -72
  46. package/dist/components/EditLinkPermissionDialog.spec.js +0 -48
  47. package/src/components/EditLinkPermissionDialog.jsx +0 -89
  48. package/src/components/EditLinkPermissionDialog.spec.jsx +0 -53
@@ -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;
@@ -56,9 +56,7 @@ var SharingContent = function SharingContent(_ref) {
56
56
  recipientsToBeConfirmed = _ref.recipientsToBeConfirmed,
57
57
  verifyRecipient = _ref.verifyRecipient,
58
58
  link = _ref.link,
59
- permissions = _ref.permissions,
60
- onUpdateShareLinkPermissions = _ref.onUpdateShareLinkPermissions,
61
- onRevokeLink = _ref.onRevokeLink;
59
+ permissions = _ref.permissions;
62
60
 
63
61
  var _useI18n = useI18n(),
64
62
  t = _useI18n.t;
@@ -96,9 +94,7 @@ var SharingContent = function SharingContent(_ref) {
96
94
  recipientsToBeConfirmed: recipientsToBeConfirmed,
97
95
  verifyRecipient: verifyRecipient,
98
96
  link: link,
99
- permissions: permissions,
100
- onUpdateShareLinkPermissions: onUpdateShareLinkPermissions,
101
- onRevokeLink: onRevokeLink
97
+ permissions: permissions
102
98
  }));
103
99
  };
104
100
  /**
@@ -16,9 +16,6 @@ var ShareDialogOnlyByLink = function ShareDialogOnlyByLink(_ref) {
16
16
  documentType = _ref.documentType,
17
17
  link = _ref.link,
18
18
  onClose = _ref.onClose,
19
- onRevokeLink = _ref.onRevokeLink,
20
- onShareByLink = _ref.onShareByLink,
21
- onUpdateShareLinkPermissions = _ref.onUpdateShareLinkPermissions,
22
19
  permissions = _ref.permissions;
23
20
 
24
21
  var _useI18n = useI18n(),
@@ -46,16 +43,13 @@ var ShareDialogOnlyByLink = function ShareDialogOnlyByLink(_ref) {
46
43
  onRevokeSelf: onRevokeSelf,
47
44
  recipients: recipients,
48
45
  link: link,
49
- permissions: permissions,
50
- onUpdateShareLinkPermissions: onUpdateShareLinkPermissions,
51
- onRevokeLink: onRevokeLink
46
+ permissions: permissions
52
47
  }), /*#__PURE__*/React.createElement("div", {
53
48
  className: cx('u-mt-half', isMobile ? 'u-ph-1 u-mb-1' : 'u-ph-2 u-mb-1-half')
54
49
  }, /*#__PURE__*/React.createElement(DumbShareByLink, {
55
50
  link: link,
56
51
  document: document,
57
- documentType: documentType,
58
- onEnable: onShareByLink
52
+ documentType: documentType
59
53
  })))
60
54
  });
61
55
  };
@@ -109,7 +109,6 @@ var ShareDialogTwoStepsConfirmationContainer = function ShareDialogTwoStepsConfi
109
109
  onRevokeLink = _ref4.onRevokeLink,
110
110
  onRevokeSelf = _ref4.onRevokeSelf,
111
111
  onShare = _ref4.onShare,
112
- onShareByLink = _ref4.onShareByLink,
113
112
  onUpdateShareLinkPermissions = _ref4.onUpdateShareLinkPermissions,
114
113
  permissions = _ref4.permissions,
115
114
  recipients = _ref4.recipients,
@@ -262,8 +261,7 @@ var ShareDialogTwoStepsConfirmationContainer = function ShareDialogTwoStepsConfi
262
261
  dialogActions = DialogActionsOnShare ? /*#__PURE__*/React.createElement(DialogActionsOnShare, {
263
262
  link: link,
264
263
  document: document,
265
- documentType: documentType,
266
- onEnable: onShareByLink
264
+ documentType: documentType
267
265
  }) : null;
268
266
  } else if (status === 'confirmingRecipient') {
269
267
  dialogTitle = t("Share.twoStepsConfirmation.title");
@@ -26,10 +26,7 @@ export var EditableSharingModal = function EditableSharingModal(_ref) {
26
26
  isOwner = _useSharingContext.isOwner,
27
27
  revoke = _useSharingContext.revoke,
28
28
  revokeSelf = _useSharingContext.revokeSelf,
29
- revokeSharingLink = _useSharingContext.revokeSharingLink,
30
- share = _useSharingContext.share,
31
- shareByLink = _useSharingContext.shareByLink,
32
- updateDocumentPermissions = _useSharingContext.updateDocumentPermissions;
29
+ share = _useSharingContext.share;
33
30
 
34
31
  return /*#__PURE__*/React.createElement(ShareModal, _extends({
35
32
  createContact: function createContact(contact) {
@@ -42,11 +39,8 @@ export var EditableSharingModal = function EditableSharingModal(_ref) {
42
39
  isOwner: isOwner(document.id),
43
40
  link: getSharingLink(document.id),
44
41
  onRevoke: revoke,
45
- onRevokeLink: revokeSharingLink,
46
42
  onRevokeSelf: revokeSelf,
47
43
  onShare: share,
48
- onShareByLink: shareByLink,
49
- onUpdateShareLinkPermissions: updateDocumentPermissions,
50
44
  permissions: getDocumentPermissions(document.id),
51
45
  recipients: getRecipients(document.id),
52
46
  sharing: getSharingForSelf(document.id)
@@ -14,11 +14,8 @@ export var ShareModal = function ShareModal(_ref) {
14
14
  needsContactsPermission = _ref.needsContactsPermission,
15
15
  onClose = _ref.onClose,
16
16
  onRevoke = _ref.onRevoke,
17
- onRevokeLink = _ref.onRevokeLink,
18
17
  onRevokeSelf = _ref.onRevokeSelf,
19
18
  onShare = _ref.onShare,
20
- onShareByLink = _ref.onShareByLink,
21
- onUpdateShareLinkPermissions = _ref.onUpdateShareLinkPermissions,
22
19
  permissions = _ref.permissions,
23
20
  recipients = _ref.recipients,
24
21
  sharing = _ref.sharing,
@@ -38,9 +35,6 @@ export var ShareModal = function ShareModal(_ref) {
38
35
  documentType: documentType,
39
36
  link: link,
40
37
  onClose: onClose,
41
- onRevokeLink: onRevokeLink,
42
- onShareByLink: onShareByLink,
43
- onUpdateShareLinkPermissions: onUpdateShareLinkPermissions,
44
38
  permissions: permissions
45
39
  }) : /*#__PURE__*/React.createElement(ShareDialogCozyToCozy, {
46
40
  createContact: createContact,
@@ -52,11 +46,8 @@ export var ShareModal = function ShareModal(_ref) {
52
46
  needsContactsPermission: needsContactsPermission,
53
47
  onClose: onClose,
54
48
  onRevoke: onRevoke,
55
- onRevokeLink: onRevokeLink,
56
49
  onRevokeSelf: onRevokeSelf,
57
50
  onShare: onShare,
58
- onShareByLink: onShareByLink,
59
- onUpdateShareLinkPermissions: onUpdateShareLinkPermissions,
60
51
  permissions: permissions,
61
52
  recipients: recipients,
62
53
  sharing: sharing,
@@ -80,10 +71,7 @@ ShareModal.propTypes = {
80
71
  needsContactsPermission: PropTypes.bool,
81
72
  onClose: PropTypes.func.isRequired,
82
73
  onRevoke: PropTypes.func.isRequired,
83
- onRevokeLink: PropTypes.func.isRequired,
84
74
  onShare: PropTypes.func.isRequired,
85
- onShareByLink: PropTypes.func.isRequired,
86
- onUpdateShareLinkPermissions: PropTypes.func.isRequired,
87
75
  permissions: PropTypes.array.isRequired,
88
76
  recipients: PropTypes.array.isRequired,
89
77
  sharingDesc: PropTypes.string,
@@ -0,0 +1,77 @@
1
+ import { format } from 'date-fns';
2
+ import PropTypes from 'prop-types';
3
+ import React from 'react';
4
+ import Box from 'cozy-ui/transpiled/react/Box';
5
+ import DatePicker from 'cozy-ui/transpiled/react/DatePicker';
6
+ import Icon from 'cozy-ui/transpiled/react/Icon';
7
+ import List from 'cozy-ui/transpiled/react/List';
8
+ import ListItem from 'cozy-ui/transpiled/react/ListItem';
9
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
10
+ import ListItemSecondaryAction from 'cozy-ui/transpiled/react/ListItemSecondaryAction';
11
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
12
+ import Switch from 'cozy-ui/transpiled/react/Switch';
13
+ import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
14
+ export var BoxDate = function BoxDate(_ref) {
15
+ var onChange = _ref.onChange,
16
+ date = _ref.date,
17
+ toggle = _ref.toggle,
18
+ onToggle = _ref.onToggle;
19
+
20
+ var _useI18n = useI18n(),
21
+ t = _useI18n.t,
22
+ lang = _useI18n.lang;
23
+
24
+ var formatDate = lang === 'fr' ? 'dd/MM/yyyy' : 'MM/dd/yyyy';
25
+
26
+ var handleDateToggle = function handleDateToggle(val) {
27
+ var _val$target$checked, _val$target;
28
+
29
+ var value = (_val$target$checked = val === null || val === void 0 || (_val$target = val.target) === null || _val$target === void 0 ? void 0 : _val$target.checked) !== null && _val$target$checked !== void 0 ? _val$target$checked : val;
30
+ onToggle(value);
31
+ };
32
+
33
+ return /*#__PURE__*/React.createElement(Box, {
34
+ borderRadius: "0.5rem",
35
+ border: "1px solid var(--borderMainColor)"
36
+ }, /*#__PURE__*/React.createElement(List, {
37
+ className: "u-p-0"
38
+ }, /*#__PURE__*/React.createElement(ListItem, {
39
+ button: true,
40
+ size: "large",
41
+ ellipsis: false,
42
+ onClick: function onClick() {
43
+ return handleDateToggle(!toggle);
44
+ }
45
+ }, /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
46
+ icon: "calendar"
47
+ })), /*#__PURE__*/React.createElement(ListItemText, {
48
+ primary: t('BoxDate.text')
49
+ }), /*#__PURE__*/React.createElement(ListItemSecondaryAction, null, /*#__PURE__*/React.createElement(Switch, {
50
+ edge: "end",
51
+ color: "primary",
52
+ checked: toggle,
53
+ onChange: handleDateToggle
54
+ })))), toggle && /*#__PURE__*/React.createElement("div", {
55
+ className: "u-pt-half u-ph-1 u-pb-1"
56
+ }, /*#__PURE__*/React.createElement(DatePicker, {
57
+ className: "u-w-100",
58
+ enableKeyboard: true,
59
+ label: t('BoxDate.label'),
60
+ placeholder: format(new Date(), formatDate),
61
+ value: date,
62
+ minDate: new Date(),
63
+ onChange: onChange,
64
+ inputProps: {
65
+ inputMode: 'numeric'
66
+ },
67
+ KeyboardButtonProps: {
68
+ 'aria-label': t('BoxDate.label')
69
+ }
70
+ })));
71
+ };
72
+ BoxDate.propTypes = {
73
+ onChange: PropTypes.func.isRequired,
74
+ date: PropTypes.instanceOf(Date),
75
+ toggle: PropTypes.bool.isRequired,
76
+ onToggle: PropTypes.func.isRequired
77
+ };
@@ -0,0 +1,83 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import PropTypes from 'prop-types';
3
+ import React, { useReducer, useRef } from 'react';
4
+ import { isDirectory as isDir } from 'cozy-client/dist/models/file';
5
+ import ActionsMenu from 'cozy-ui/transpiled/react/ActionsMenu';
6
+ import { makeActions } from 'cozy-ui/transpiled/react/ActionsMenu/Actions';
7
+ import Box from 'cozy-ui/transpiled/react/Box';
8
+ import Icon from 'cozy-ui/transpiled/react/Icon';
9
+ import List from 'cozy-ui/transpiled/react/List';
10
+ import ListItem from 'cozy-ui/transpiled/react/ListItem';
11
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
12
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
13
+ import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
14
+ import { useSharingContext } from '../../hooks/useSharingContext';
15
+ import { editPermissionLink } from '../Recipient/actions/editPermissionLink';
16
+ import { readOnlyPermissionLink } from '../Recipient/actions/readOnlyPermissionLink';
17
+ export var BoxEditingRights = function BoxEditingRights(_ref) {
18
+ var file = _ref.file,
19
+ editingRights = _ref.editingRights,
20
+ setEditingRights = _ref.setEditingRights;
21
+
22
+ var _useReducer = useReducer(function (state) {
23
+ return !state;
24
+ }, false),
25
+ _useReducer2 = _slicedToArray(_useReducer, 2),
26
+ isMenuDisplayed = _useReducer2[0],
27
+ toggleMenuDisplayed = _useReducer2[1];
28
+
29
+ var buttonRef = useRef();
30
+
31
+ var _useI18n = useI18n(),
32
+ t = _useI18n.t;
33
+
34
+ var _useSharingContext = useSharingContext(),
35
+ documentType = _useSharingContext.documentType;
36
+
37
+ var isDirectory = isDir(file);
38
+ var actions = makeActions([readOnlyPermissionLink, editPermissionLink], {
39
+ t: t,
40
+ editingRights: editingRights,
41
+ setEditingRights: setEditingRights,
42
+ documentType: documentType,
43
+ isDirectory: isDirectory
44
+ });
45
+ var textSecondary = editingRights === 'readOnly' ? t('Share.permissionLink.readDescription') : t('Share.permissionLink.writeDescription');
46
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Box, {
47
+ borderRadius: "0.5rem",
48
+ border: "1px solid var(--borderMainColor)",
49
+ ref: buttonRef
50
+ }, /*#__PURE__*/React.createElement(List, {
51
+ className: "u-p-0"
52
+ }, /*#__PURE__*/React.createElement(ListItem, {
53
+ button: true,
54
+ size: "large",
55
+ ellipsis: false,
56
+ onClick: toggleMenuDisplayed
57
+ }, /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
58
+ icon: "people"
59
+ })), /*#__PURE__*/React.createElement(ListItemText, {
60
+ primary: t('BoxEditingRights.text'),
61
+ secondary: textSecondary
62
+ }), /*#__PURE__*/React.createElement(ListItemIcon, {
63
+ className: "u-mr-half"
64
+ }, /*#__PURE__*/React.createElement(Icon, {
65
+ icon: "bottom"
66
+ }))))), /*#__PURE__*/React.createElement(ActionsMenu, {
67
+ ref: buttonRef,
68
+ open: isMenuDisplayed,
69
+ docs: [file],
70
+ actions: actions,
71
+ anchorOrigin: {
72
+ vertical: 'bottom',
73
+ horizontal: 'right'
74
+ },
75
+ autoClose: true,
76
+ onClose: toggleMenuDisplayed
77
+ }));
78
+ };
79
+ BoxEditingRights.propTypes = {
80
+ file: PropTypes.object.isRequired,
81
+ editingRights: PropTypes.oneOf(['readOnly', 'write']).isRequired,
82
+ setEditingRights: PropTypes.func.isRequired
83
+ };