cozy-sharing 19.0.0 → 21.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 (38) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/dist/SharingProvider.js +16 -9
  3. package/dist/actions/{openSharingLink.js → addToCozySharingLink.js} +12 -16
  4. package/dist/actions/createCozySharingLink.js +51 -0
  5. package/dist/actions/syncToCozySharingLink.js +51 -0
  6. package/dist/components/Recipient/LinkRecipient.js +20 -4
  7. package/dist/components/ShareRestrictionModal/BoxPassword.js +21 -4
  8. package/dist/components/ShareRestrictionModal/ShareRestrictionContentModal.js +33 -9
  9. package/dist/components/ShareRestrictionModal/ShareRestrictionModal.js +74 -78
  10. package/dist/components/ShareRestrictionModal/helpers.js +82 -47
  11. package/dist/components/ShareRestrictionModal/helpers.spec.js +142 -20
  12. package/dist/components/SharingBanner/components/PublicBanner.js +3 -3
  13. package/dist/components/SharingBanner/components/PublicBanner.spec.js +1 -1
  14. package/dist/components/SharingBanner/components/SharingBanner.js +3 -3
  15. package/dist/components/SharingBanner/hooks/useSharingInfos.js +37 -25
  16. package/dist/components/SharingBanner/hooks/useSharingInfos.spec.js +9 -9
  17. package/dist/helpers/permissions.js +15 -0
  18. package/dist/index.js +3 -1
  19. package/locales/en.json +2 -0
  20. package/locales/fr.json +2 -0
  21. package/package.json +4 -4
  22. package/src/SharingProvider.jsx +10 -5
  23. package/src/actions/addToCozySharingLink.js +51 -0
  24. package/src/actions/createCozySharingLink.js +47 -0
  25. package/src/actions/{openSharingLink.js → syncToCozySharingLink.js} +10 -12
  26. package/src/components/Recipient/LinkRecipient.jsx +28 -4
  27. package/src/components/ShareRestrictionModal/BoxPassword.jsx +14 -0
  28. package/src/components/ShareRestrictionModal/ShareRestrictionContentModal.jsx +31 -9
  29. package/src/components/ShareRestrictionModal/ShareRestrictionModal.jsx +55 -46
  30. package/src/components/ShareRestrictionModal/helpers.js +65 -31
  31. package/src/components/ShareRestrictionModal/helpers.spec.js +92 -11
  32. package/src/components/SharingBanner/components/PublicBanner.jsx +3 -3
  33. package/src/components/SharingBanner/components/PublicBanner.spec.jsx +1 -1
  34. package/src/components/SharingBanner/components/SharingBanner.jsx +3 -3
  35. package/src/components/SharingBanner/hooks/useSharingInfos.jsx +12 -3
  36. package/src/components/SharingBanner/hooks/useSharingInfos.spec.js +7 -7
  37. package/src/helpers/permissions.js +12 -0
  38. package/src/index.jsx +3 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,74 @@
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
+ # [21.0.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@20.0.0...cozy-sharing@21.0.0) (2025-01-23)
7
+
8
+
9
+ ### Features
10
+
11
+ * **sharing:** Add new links to `useSharingInfos` ([e9e51f7](https://github.com/cozy/cozy-libs/commit/e9e51f773698ea72af5aca218c65b597c4f918c7))
12
+ * **sharing:** Replace `openSharingLink` with 3 new actions ([9150b33](https://github.com/cozy/cozy-libs/commit/9150b33f7ef3cd55b986dffedd768f00408674dd))
13
+ * **sharing:** Update PublicBanner with new addSharingLink ([3be70fe](https://github.com/cozy/cozy-libs/commit/3be70fef1780806584cba1f07daaf0ebcd9596c7))
14
+
15
+
16
+ ### BREAKING CHANGES
17
+
18
+ * **sharing:** We now need 3 separate actions to Cozy to Cozy sharing.
19
+ Replace the `openSharingLink` action with the desired
20
+ action with its link option
21
+
22
+ Example:
23
+ ```
24
+ import {
25
+ addToCozySharingLink,
26
+ syncToCozySharingLink,
27
+ useSharingInfos
28
+ } from 'cozy-sharing'
29
+
30
+ const { addSharingLink, syncSharingLink } = useSharingInfos()
31
+
32
+ const actions = makeActions(
33
+ [
34
+ addToCozySharingLink,
35
+ syncToCozySharingLink
36
+ ],
37
+ {
38
+ addSharingLink,
39
+ syncSharingLink
40
+ }
41
+ )
42
+ ```
43
+
44
+
45
+
46
+
47
+
48
+ # [20.0.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@19.0.0...cozy-sharing@20.0.0) (2025-01-22)
49
+
50
+
51
+ ### Bug Fixes
52
+
53
+ * **sharing:** Dispatch correct value ([4f2d17c](https://github.com/cozy/cozy-libs/commit/4f2d17cec7ce51fae97c825e3bb605c204dff330))
54
+
55
+
56
+ ### Features
57
+
58
+ * **sharing:** Auto focus password input ([614da3c](https://github.com/cozy/cozy-libs/commit/614da3cceae6f207ced87ae0bc81886224c83a24))
59
+ * **sharing:** Change ShareRestrictionModal validity ([00fb730](https://github.com/cozy/cozy-libs/commit/00fb730160e7f80ea57f6ebf7f47afadff9c0945))
60
+ * **sharing:** Improve BoxPassword ([7e39d7f](https://github.com/cozy/cozy-libs/commit/7e39d7fe16c021c9902a905f7dbdba92b2787eaf))
61
+ * **sharing:** Improve ShareDialogOnlyByLink UX ([4287e74](https://github.com/cozy/cozy-libs/commit/4287e74dc32aa7541e861939c4405a20426640e6))
62
+ * **sharing:** Rework logic of ShareRestrictionModal ([e33df9f](https://github.com/cozy/cozy-libs/commit/e33df9f5bb737dab6db738b435d2d0492698c8e9))
63
+ * **sharing:** Upgrade cozy-client to 53.0.0 ([fd6294f](https://github.com/cozy/cozy-libs/commit/fd6294f0870499a928795a73f099f3885e090a0a))
64
+
65
+
66
+ ### BREAKING CHANGES
67
+
68
+ * **sharing:** You must have `cozy-client >= 53.0.0`
69
+
70
+
71
+
72
+
73
+
6
74
  # [19.0.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@18.0.0...cozy-sharing@19.0.0) (2025-01-08)
7
75
 
8
76
 
@@ -465,18 +465,22 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
465
465
  * updateDocumentPermissions - Description
466
466
  *
467
467
  * @param {Object} document A shared document
468
- * @param {Array} newVerbs The new verbs to use for the permission, eg. ['GET']
468
+ * @param {object} options The new verbs to use for the permission, eg. ['GET']
469
+ * @param {string[]} options.verbs The new verbs to use for the permission, eg. ['GET']
470
+ * @param {string} [options.expiresAt] The new expiration date for the permission
471
+ * @param {string} [options.password] The new password for the permission
469
472
  *
470
473
  * @return {Array}
471
474
  */
472
475
  _defineProperty(_this2, "updateDocumentPermissions", /*#__PURE__*/function () {
473
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(document, newVerbs) {
474
- var permissions, responses;
476
+ var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(document, options) {
477
+ var verbs, expiresAt, password, permissions, responses;
475
478
  return _regeneratorRuntime.wrap(function _callee11$(_context11) {
476
479
  while (1) switch (_context11.prev = _context11.next) {
477
480
  case 0:
481
+ verbs = options.verbs, expiresAt = options.expiresAt, password = options.password;
478
482
  permissions = _getDocumentPermissions(_this2.state, document.id);
479
- _context11.next = 3;
483
+ _context11.next = 4;
480
484
  return Promise.all(permissions.map( /*#__PURE__*/function () {
481
485
  var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(permissionDocument) {
482
486
  var updatedPermissions, resp;
@@ -485,15 +489,18 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
485
489
  case 0:
486
490
  updatedPermissions = permissionDocument.attributes.permissions;
487
491
  Object.keys(updatedPermissions).map(function (permType) {
488
- updatedPermissions[permType].verbs = newVerbs;
492
+ updatedPermissions[permType].verbs = verbs;
489
493
  });
490
494
  _context10.next = 4;
491
- return _this2.permissionCol.add(permissionDocument, updatedPermissions);
495
+ return _this2.permissionCol.add(permissionDocument, updatedPermissions, {
496
+ expiresAt: expiresAt,
497
+ password: password
498
+ });
492
499
 
493
500
  case 4:
494
501
  resp = _context10.sent;
495
502
 
496
- _this2.dispatch(updateSharingLink(resp));
503
+ _this2.dispatch(updateSharingLink(resp.data));
497
504
 
498
505
  return _context10.abrupt("return", resp);
499
506
 
@@ -509,11 +516,11 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
509
516
  };
510
517
  }()));
511
518
 
512
- case 3:
519
+ case 4:
513
520
  responses = _context11.sent;
514
521
  return _context11.abrupt("return", responses);
515
522
 
516
- case 5:
523
+ case 6:
517
524
  case "end":
518
525
  return _context11.stop();
519
526
  }
@@ -2,9 +2,10 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import React, { forwardRef } from 'react';
3
3
  import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem';
4
4
  import Icon from 'cozy-ui/transpiled/react/Icon';
5
+ import CloudPlusOutlinedIcon from 'cozy-ui/transpiled/react/Icons/CloudPlusOutlined';
5
6
  import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
6
7
  import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
7
- import { getIconWithlabel, openExternalLink } from '../helpers/sharings';
8
+ import { openExternalLink } from '../helpers/sharings';
8
9
  import { getActionsI18n } from '../hoc/withLocales';
9
10
 
10
11
  var makeComponent = function makeComponent(label, icon) {
@@ -17,39 +18,34 @@ var makeComponent = function makeComponent(label, icon) {
17
18
  primary: label
18
19
  }));
19
20
  });
20
- Component.displayName = 'OpenSharingLink';
21
+ Component.displayName = 'AddToCozySharingLink';
21
22
  return Component;
22
23
  };
23
24
 
24
- export var openSharingLink = function openSharingLink(_ref) {
25
+ export var addToCozySharingLink = function addToCozySharingLink(_ref) {
25
26
  var isSharingShortcutCreated = _ref.isSharingShortcutCreated,
26
27
  _ref$openSharingLinkD = _ref.openSharingLinkDisplayed,
27
28
  openSharingLinkDisplayed = _ref$openSharingLinkD === void 0 ? true : _ref$openSharingLinkD,
28
29
  _ref$isShortLabel = _ref.isShortLabel,
29
30
  isShortLabel = _ref$isShortLabel === void 0 ? false : _ref$isShortLabel,
30
- link = _ref.link;
31
+ addSharingLink = _ref.addSharingLink;
31
32
 
32
33
  var _getActionsI18n = getActionsI18n(),
33
34
  t = _getActionsI18n.t;
34
35
 
35
- var _getIconWithlabel = getIconWithlabel({
36
- link: link,
37
- isSharingShortcutCreated: isSharingShortcutCreated,
38
- isShortLabel: isShortLabel,
39
- t: t
40
- }),
41
- icon = _getIconWithlabel.icon,
42
- label = _getIconWithlabel.label;
43
-
36
+ var label = t('Share.banner.add_to_mine', {
37
+ smart_count: isShortLabel ? 1 : 2
38
+ });
39
+ var icon = CloudPlusOutlinedIcon;
44
40
  return {
45
- name: 'openSharingLink',
41
+ name: 'addToCozySharingLink',
46
42
  label: label,
47
43
  icon: icon,
48
44
  displayCondition: function displayCondition() {
49
- return openSharingLinkDisplayed;
45
+ return openSharingLinkDisplayed && !isSharingShortcutCreated;
50
46
  },
51
47
  action: function action() {
52
- openExternalLink(link);
48
+ openExternalLink(addSharingLink);
53
49
  },
54
50
  Component: makeComponent(label, icon)
55
51
  };
@@ -0,0 +1,51 @@
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 Icon from 'cozy-ui/transpiled/react/Icon';
5
+ import ToTheCloudIcon from 'cozy-ui/transpiled/react/Icons/ToTheCloud';
6
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
7
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
8
+ import { openExternalLink } from '../helpers/sharings';
9
+ import { getActionsI18n } from '../hoc/withLocales';
10
+
11
+ var makeComponent = function makeComponent(label, icon) {
12
+ var Component = /*#__PURE__*/forwardRef(function (props, ref) {
13
+ return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
14
+ ref: ref
15
+ }), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
16
+ icon: icon
17
+ })), /*#__PURE__*/React.createElement(ListItemText, {
18
+ primary: label
19
+ }));
20
+ });
21
+ Component.displayName = 'CreateCozySharingLink';
22
+ return Component;
23
+ };
24
+
25
+ export var createCozySharingLink = function createCozySharingLink(_ref) {
26
+ var _ref$openSharingLinkD = _ref.openSharingLinkDisplayed,
27
+ openSharingLinkDisplayed = _ref$openSharingLinkD === void 0 ? true : _ref$openSharingLinkD,
28
+ _ref$isShortLabel = _ref.isShortLabel,
29
+ isShortLabel = _ref$isShortLabel === void 0 ? false : _ref$isShortLabel,
30
+ createSharingLink = _ref.createSharingLink;
31
+
32
+ var _getActionsI18n = getActionsI18n(),
33
+ t = _getActionsI18n.t;
34
+
35
+ var label = t('Share.create-cozy', {
36
+ smart_count: isShortLabel ? 1 : 2
37
+ });
38
+ var icon = ToTheCloudIcon;
39
+ return {
40
+ name: 'createCozySharingLink',
41
+ label: label,
42
+ icon: icon,
43
+ displayCondition: function displayCondition() {
44
+ return openSharingLinkDisplayed;
45
+ },
46
+ action: function action() {
47
+ openExternalLink(createSharingLink);
48
+ },
49
+ Component: makeComponent(label, icon)
50
+ };
51
+ };
@@ -0,0 +1,51 @@
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 Icon from 'cozy-ui/transpiled/react/Icon';
5
+ import SyncIcon from 'cozy-ui/transpiled/react/Icons/Sync';
6
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
7
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
8
+ import { openExternalLink } from '../helpers/sharings';
9
+ import { getActionsI18n } from '../hoc/withLocales';
10
+
11
+ var makeComponent = function makeComponent(label, icon) {
12
+ var Component = /*#__PURE__*/forwardRef(function (props, ref) {
13
+ return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
14
+ ref: ref
15
+ }), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
16
+ icon: icon
17
+ })), /*#__PURE__*/React.createElement(ListItemText, {
18
+ primary: label
19
+ }));
20
+ });
21
+ Component.displayName = 'SyncToCozySharingLink';
22
+ return Component;
23
+ };
24
+
25
+ export var syncToCozySharingLink = function syncToCozySharingLink(_ref) {
26
+ var _ref$openSharingLinkD = _ref.openSharingLinkDisplayed,
27
+ openSharingLinkDisplayed = _ref$openSharingLinkD === void 0 ? true : _ref$openSharingLinkD,
28
+ _ref$isShortLabel = _ref.isShortLabel,
29
+ isShortLabel = _ref$isShortLabel === void 0 ? false : _ref$isShortLabel,
30
+ syncSharingLink = _ref.syncSharingLink;
31
+
32
+ var _getActionsI18n = getActionsI18n(),
33
+ t = _getActionsI18n.t;
34
+
35
+ var label = t('Share.banner.sync_to_mine', {
36
+ smart_count: isShortLabel ? 1 : 2
37
+ });
38
+ var icon = SyncIcon;
39
+ return {
40
+ name: 'syncToCozySharingLink',
41
+ label: label,
42
+ icon: icon,
43
+ displayCondition: function displayCondition() {
44
+ return openSharingLinkDisplayed;
45
+ },
46
+ action: function action() {
47
+ openExternalLink(syncSharingLink);
48
+ },
49
+ Component: makeComponent(label, icon)
50
+ };
51
+ };
@@ -13,7 +13,9 @@ import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints';
13
13
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
14
14
  import LinkRecipientPermissions from './LinkRecipientPermissions';
15
15
  import RecipientConfirm from './RecipientConfirm';
16
+ import { checkIsPermissionHasPassword, getPermissionExpiresDate } from '../../helpers/permissions';
16
17
  import { FADE_IN_DURATION } from '../../helpers/recipients';
18
+ import { useSharingContext } from '../../hooks/useSharingContext';
17
19
  var styles = {
18
20
  "recipient": "recipient__recipient___2DmZI",
19
21
  "recipients-list-light": "recipient__recipients-list-light___Vq4op",
@@ -34,15 +36,29 @@ var styles = {
34
36
 
35
37
  var LinkRecipient = function LinkRecipient(props) {
36
38
  var _useI18n = useI18n(),
37
- t = _useI18n.t;
39
+ t = _useI18n.t,
40
+ f = _useI18n.f,
41
+ lang = _useI18n.lang;
38
42
 
39
43
  var _useBreakpoints = useBreakpoints(),
40
44
  isMobile = _useBreakpoints.isMobile;
41
45
 
46
+ var _useSharingContext = useSharingContext(),
47
+ getDocumentPermissions = _useSharingContext.getDocumentPermissions;
48
+
42
49
  var recipientConfirmationData = props.recipientConfirmationData,
43
50
  verifyRecipient = props.verifyRecipient,
44
51
  link = props.link,
45
- fadeIn = props.fadeIn;
52
+ fadeIn = props.fadeIn,
53
+ document = props.document;
54
+ var permissions = getDocumentPermissions(document._id);
55
+ var hasPassword = checkIsPermissionHasPassword(permissions);
56
+ var expiresDate = getPermissionExpiresDate(permissions);
57
+ var dateFormatted = expiresDate ? f(expiresDate, lang === 'fr' ? 'dd/LL/yyyy' : 'LL/dd/yyyy') : null;
58
+ var textPrimary = hasPassword ? t('Share.recipients.linkWithPassword') : t('Share.recipients.anyoneWithTheLink');
59
+ var textSecondary = expiresDate ? t('Share.recipients.expires', {
60
+ date: dateFormatted
61
+ }) : link;
46
62
  var RightPart = recipientConfirmationData ? /*#__PURE__*/React.createElement(RecipientConfirm, {
47
63
  recipientConfirmationData: recipientConfirmationData,
48
64
  verifyRecipient: verifyRecipient
@@ -64,8 +80,8 @@ var LinkRecipient = function LinkRecipient(props) {
64
80
  primary: /*#__PURE__*/React.createElement(Typography, {
65
81
  className: "u-ellipsis",
66
82
  variant: "body1"
67
- }, t('Share.recipients.anyoneWithTheLink')),
68
- secondary: link
83
+ }, textPrimary),
84
+ secondary: textSecondary
69
85
  }), RightPart));
70
86
  };
71
87
 
@@ -1,3 +1,4 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
1
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
@@ -16,8 +17,11 @@ import TextField from 'cozy-ui/transpiled/react/TextField';
16
17
  import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert';
17
18
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
18
19
  import { copyToClipboard } from './helpers';
20
+ import { checkIsPermissionHasPassword } from '../../helpers/permissions';
21
+ import { useSharingContext } from '../../hooks/useSharingContext';
19
22
  export var BoxPassword = function BoxPassword(_ref) {
20
- var onChange = _ref.onChange,
23
+ var file = _ref.file,
24
+ onChange = _ref.onChange,
21
25
  password = _ref.password,
22
26
  onToggle = _ref.onToggle,
23
27
  toggle = _ref.toggle,
@@ -37,6 +41,12 @@ export var BoxPassword = function BoxPassword(_ref) {
37
41
 
38
42
  var inputRef = React.useRef();
39
43
 
44
+ var _useSharingContext = useSharingContext(),
45
+ getDocumentPermissions = _useSharingContext.getDocumentPermissions;
46
+
47
+ var permissions = getDocumentPermissions(file._id);
48
+ var hasPassword = checkIsPermissionHasPassword(permissions);
49
+
40
50
  var handlePasswordToggle = function handlePasswordToggle(val) {
41
51
  var _val$target$checked, _val$target;
42
52
 
@@ -106,9 +116,16 @@ export var BoxPassword = function BoxPassword(_ref) {
106
116
  onChange: handlePasswordToggle
107
117
  })))), toggle && /*#__PURE__*/React.createElement("div", {
108
118
  className: "u-pt-half u-ph-1 u-pb-1"
109
- }, /*#__PURE__*/React.createElement(TextField, {
119
+ }, /*#__PURE__*/React.createElement(TextField, _extends({
110
120
  inputRef: inputRef,
111
- label: t('BoxPassword.label'),
121
+ autoFocus: true,
122
+ label: t('BoxPassword.label')
123
+ }, hasPassword && {
124
+ placeholder: '****',
125
+ InputLabelProps: {
126
+ shrink: true
127
+ }
128
+ }, {
112
129
  value: password,
113
130
  error: displayHelper && !!helperText,
114
131
  helperText: displayHelper && helperText,
@@ -126,7 +143,7 @@ export var BoxPassword = function BoxPassword(_ref) {
126
143
  }))
127
144
  },
128
145
  inputProps: inputProps
129
- })));
146
+ }))));
130
147
  };
131
148
  BoxPassword.propTypes = {
132
149
  onChange: PropTypes.func.isRequired,
@@ -1,4 +1,4 @@
1
- import { addDays } from 'date-fns';
1
+ import { addDays, isValid } from 'date-fns';
2
2
  import PropTypes from 'prop-types';
3
3
  import React from 'react';
4
4
  import Box from 'cozy-ui/transpiled/react/Box';
@@ -7,6 +7,8 @@ import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
7
7
  import { BoxDate } from './BoxDate';
8
8
  import { BoxEditingRights } from './BoxEditingRights';
9
9
  import { BoxPassword } from './BoxPassword';
10
+ import { checkIsPermissionHasPassword } from '../../helpers/permissions';
11
+ import { useSharingContext } from '../../hooks/useSharingContext';
10
12
  var PASSWORD_MIN_LENGTH = 4;
11
13
  export var ShareRestrictionContentModal = function ShareRestrictionContentModal(_ref) {
12
14
  var file = _ref.file,
@@ -27,23 +29,44 @@ export var ShareRestrictionContentModal = function ShareRestrictionContentModal(
27
29
  var _useI18n = useI18n(),
28
30
  t = _useI18n.t;
29
31
 
32
+ var _useSharingContext = useSharingContext(),
33
+ getDocumentPermissions = _useSharingContext.getDocumentPermissions;
34
+
35
+ var permissions = getDocumentPermissions(file._id);
36
+ var hasPassword = checkIsPermissionHasPassword(permissions);
37
+
38
+ var handlePassword = function handlePassword(value) {
39
+ setPassword(value);
40
+ setIsValidPassword(hasPassword && value.trim().length === 0 || value.trim().length >= PASSWORD_MIN_LENGTH);
41
+ };
42
+
30
43
  var handlePasswordToggle = function handlePasswordToggle(val) {
31
44
  setPasswordToggle(val);
45
+ setPassword('');
46
+
47
+ if (val && !password) {
48
+ setIsValidPassword(hasPassword);
49
+ } else {
50
+ setIsValidPassword(true);
51
+ }
32
52
  };
33
53
 
34
- var handlePassword = function handlePassword(value) {
35
- setPassword(value);
36
- setIsValidPassword(value.trim().length === 0 || value.trim().length >= PASSWORD_MIN_LENGTH);
54
+ var handleDate = function handleDate(date) {
55
+ setSelectedDate(date);
56
+ setIsValidDate(isValid(date));
37
57
  };
38
58
 
39
59
  var handleDateToggle = function handleDateToggle(val) {
60
+ setDateToggle(val);
61
+
40
62
  if (!val) {
63
+ setSelectedDate(null);
64
+ setIsValidDate(true);
65
+ } else {
66
+ var defaultValue = val ? addDays(new Date(), 30) : null;
67
+ setSelectedDate(defaultValue);
41
68
  setIsValidDate(true);
42
69
  }
43
-
44
- var defaultValue = val ? addDays(new Date(), 30) : null;
45
- setSelectedDate(defaultValue, true);
46
- setDateToggle(val);
47
70
  };
48
71
 
49
72
  return /*#__PURE__*/React.createElement(Box, {
@@ -58,11 +81,12 @@ export var ShareRestrictionContentModal = function ShareRestrictionContentModal(
58
81
  editingRights: editingRights,
59
82
  setEditingRights: setEditingRights
60
83
  }), /*#__PURE__*/React.createElement(BoxDate, {
61
- onChange: setSelectedDate,
84
+ onChange: handleDate,
62
85
  date: selectedDate,
63
86
  onToggle: handleDateToggle,
64
87
  toggle: dateToggle
65
88
  }), /*#__PURE__*/React.createElement(BoxPassword, {
89
+ file: file,
66
90
  onChange: handlePassword,
67
91
  password: password,
68
92
  onToggle: handlePasswordToggle,