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
@@ -55,14 +55,14 @@ var openExternalLink = function openExternalLink(url) {
55
55
  var SharingBannerCozyToCozy = function SharingBannerCozyToCozy(_ref2) {
56
56
  var sharing = _ref2.sharing,
57
57
  isSharingShortcutCreated = _ref2.isSharingShortcutCreated,
58
- discoveryLink = _ref2.discoveryLink,
58
+ addSharingLink = _ref2.addSharingLink,
59
59
  onClose = _ref2.onClose;
60
60
 
61
61
  var _useI18n2 = useI18n(),
62
62
  t = _useI18n2.t;
63
63
 
64
64
  var action = function action() {
65
- return openExternalLink(discoveryLink);
65
+ return openExternalLink(addSharingLink);
66
66
  };
67
67
 
68
68
  var buttonOne = isSharingShortcutCreated ? {
@@ -146,7 +146,7 @@ var SharingBannerByLink = function SharingBannerByLink(_ref3) {
146
146
  SharingBannerCozyToCozy.propTypes = {
147
147
  sharing: PropTypes.object.isRequired,
148
148
  isSharingShortcutCreated: PropTypes.bool.isRequired,
149
- discoveryLink: PropTypes.string.isRequired,
149
+ addToCozySharingLink: PropTypes.string.isRequired,
150
150
  onClose: PropTypes.func.isRequired
151
151
  };
152
152
  export { SharingBannerCozyToCozy, SharingBannerByLink };
@@ -36,7 +36,7 @@ describe('PublicBanner', function () {
36
36
  var _render = render( /*#__PURE__*/React.createElement(SharingBannerCozyToCozy, {
37
37
  sharing: sharing,
38
38
  isSharingShortcutCreated: true,
39
- discoveryLink: "discoveryLink",
39
+ addSharingLink: "discoveryLink",
40
40
  onClose: function onClose() {}
41
41
  })),
42
42
  container = _render.container; // Then
@@ -14,16 +14,16 @@ export var SharingBanner = function SharingBanner(_ref) {
14
14
  return setIsOpened(false);
15
15
  }, [setIsOpened]);
16
16
  var loading = sharingInfos.loading,
17
- discoveryLink = sharingInfos.discoveryLink,
17
+ addSharingLink = sharingInfos.addSharingLink,
18
18
  sharing = sharingInfos.sharing,
19
19
  isSharingShortcutCreated = sharingInfos.isSharingShortcutCreated;
20
20
  if (loading) return null;
21
- return isOpened && (!discoveryLink ? /*#__PURE__*/React.createElement(SharingBannerByLink, {
21
+ return isOpened && (!addSharingLink ? /*#__PURE__*/React.createElement(SharingBannerByLink, {
22
22
  onClose: onClose
23
23
  }) : /*#__PURE__*/React.createElement(SharingBannerCozyToCozy, {
24
24
  isSharingShortcutCreated: isSharingShortcutCreated,
25
25
  sharing: sharing,
26
- discoveryLink: discoveryLink,
26
+ addSharingLink: addSharingLink,
27
27
  onClose: onClose
28
28
  }));
29
29
  };
@@ -13,34 +13,40 @@ var getSharingId = function getSharingId(permission) {
13
13
  return sharingId;
14
14
  };
15
15
 
16
+ var CREATE_COZY_LINK = 'https://manager.cozycloud.cc/cozy/create';
16
17
  export var useSharingInfos = function useSharingInfos() {
17
18
  var previewPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '/preview';
18
19
  var client = useClient();
19
20
 
20
21
  var _useState = useState(),
21
22
  _useState2 = _slicedToArray(_useState, 2),
22
- discoveryLink = _useState2[0],
23
- setDiscoveryLink = _useState2[1];
23
+ addSharingLink = _useState2[0],
24
+ setAddSharingLink = _useState2[1];
24
25
 
25
- var _useState3 = useState(false),
26
+ var _useState3 = useState(),
26
27
  _useState4 = _slicedToArray(_useState3, 2),
27
- isSharingShortcutCreated = _useState4[0],
28
- setIsSharingSharingcutCreated = _useState4[1];
28
+ syncSharingLink = _useState4[0],
29
+ setSyncSharingLink = _useState4[1];
29
30
 
30
- var _useState5 = useState(),
31
+ var _useState5 = useState(false),
31
32
  _useState6 = _slicedToArray(_useState5, 2),
32
- sharing = _useState6[0],
33
- setSharing = _useState6[1];
33
+ isSharingShortcutCreated = _useState6[0],
34
+ setIsSharingSharingcutCreated = _useState6[1];
34
35
 
35
- var _useState7 = useState(true),
36
+ var _useState7 = useState(),
36
37
  _useState8 = _slicedToArray(_useState7, 2),
37
- loading = _useState8[0],
38
- setLoading = _useState8[1];
38
+ sharing = _useState8[0],
39
+ setSharing = _useState8[1];
40
+
41
+ var _useState9 = useState(true),
42
+ _useState10 = _slicedToArray(_useState9, 2),
43
+ loading = _useState10[0],
44
+ setLoading = _useState10[1];
39
45
 
40
46
  useEffect(function () {
41
47
  var loadSharingDiscoveryLink = /*#__PURE__*/function () {
42
48
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
43
- var response, _isSharingShortcutCreated, sharingId, _getQueryParameter2, sharecode, link, sharingsByIdQuery, _yield$client$query2, _sharing;
49
+ var response, _isSharingShortcutCreated, sharingId, _getQueryParameter2, sharecode, link, linkSync, sharingsByIdQuery, _yield$client$query2, _sharing;
44
50
 
45
51
  return _regeneratorRuntime.wrap(function _callee$(_context) {
46
52
  while (1) switch (_context.prev = _context.next) {
@@ -55,35 +61,39 @@ export var useSharingInfos = function useSharingInfos() {
55
61
  _isSharingShortcutCreated = models.permission.isShortcutCreatedOnTheRecipientCozy(response);
56
62
  sharingId = getSharingId(response);
57
63
  _getQueryParameter2 = getQueryParameter(), sharecode = _getQueryParameter2.sharecode;
58
- link = client.collection('io.cozy.sharings').getDiscoveryLink(sharingId, sharecode);
64
+ link = client.collection('io.cozy.sharings').getDiscoveryLink(sharingId, sharecode, {
65
+ shortcut: true
66
+ });
67
+ linkSync = client.collection('io.cozy.sharings').getDiscoveryLink(sharingId, sharecode);
59
68
  sharingsByIdQuery = buildSharingsByIdQuery(sharingId);
60
- _context.next = 12;
69
+ _context.next = 13;
61
70
  return client.query(sharingsByIdQuery.definition);
62
71
 
63
- case 12:
72
+ case 13:
64
73
  _yield$client$query2 = _context.sent;
65
74
  _sharing = _yield$client$query2.data;
66
- setDiscoveryLink(link);
75
+ setAddSharingLink(link);
76
+ setSyncSharingLink(linkSync);
67
77
  setIsSharingSharingcutCreated(_isSharingShortcutCreated);
68
78
  setSharing(_sharing);
69
- _context.next = 22;
79
+ _context.next = 24;
70
80
  break;
71
81
 
72
- case 19:
73
- _context.prev = 19;
82
+ case 21:
83
+ _context.prev = 21;
74
84
  _context.t0 = _context["catch"](1);
75
85
  logger.warn('Failed to load sharing discovery link', _context.t0);
76
86
 
77
- case 22:
78
- _context.prev = 22;
87
+ case 24:
88
+ _context.prev = 24;
79
89
  setLoading(false);
80
- return _context.finish(22);
90
+ return _context.finish(24);
81
91
 
82
- case 25:
92
+ case 27:
83
93
  case "end":
84
94
  return _context.stop();
85
95
  }
86
- }, _callee, null, [[1, 19, 22, 25]]);
96
+ }, _callee, null, [[1, 21, 24, 27]]);
87
97
  }));
88
98
 
89
99
  return function loadSharingDiscoveryLink() {
@@ -100,7 +110,9 @@ export var useSharingInfos = function useSharingInfos() {
100
110
  return {
101
111
  sharing: sharing,
102
112
  loading: loading,
103
- discoveryLink: discoveryLink,
113
+ addSharingLink: addSharingLink,
114
+ syncSharingLink: syncSharingLink,
115
+ createCozyLink: CREATE_COZY_LINK,
104
116
  isSharingShortcutCreated: isSharingShortcutCreated
105
117
  };
106
118
  };
@@ -86,13 +86,13 @@ describe('useSharingInfos', function () {
86
86
  window.location = location;
87
87
  });
88
88
  it('returns the right infos when using useSharingInfo', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
89
- var discoveryLink, _setup, result, waitForNextUpdate;
89
+ var addSharingLink, _setup, result, waitForNextUpdate;
90
90
 
91
91
  return _regeneratorRuntime.wrap(function _callee$(_context) {
92
92
  while (1) switch (_context.prev = _context.next) {
93
93
  case 0:
94
- discoveryLink = '/link';
95
- getDiscoveryLinkMock.mockReturnValue(discoveryLink);
94
+ addSharingLink = '/addSharingLink';
95
+ getDiscoveryLinkMock.mockReturnValue(addSharingLink);
96
96
  fetchOwnPermissionsMock.mockResolvedValue(mockedPermissionsWithInstance);
97
97
  queryMock.mockResolvedValue(mockSharing);
98
98
  _setup = setup(), result = _setup.result, waitForNextUpdate = _setup.waitForNextUpdate; // default state
@@ -107,7 +107,7 @@ describe('useSharingInfos', function () {
107
107
  expect(result.current.loading).toEqual(false);
108
108
  expect(result.current.isSharingShortcutCreated).toEqual(true);
109
109
  expect(result.current.sharing).toEqual(mockSharing.data);
110
- expect(result.current.discoveryLink).toEqual(discoveryLink);
110
+ expect(result.current.addSharingLink).toEqual(addSharingLink);
111
111
 
112
112
  case 12:
113
113
  case "end":
@@ -115,14 +115,14 @@ describe('useSharingInfos', function () {
115
115
  }
116
116
  }, _callee);
117
117
  })));
118
- it('returns the right infos when using useSharingInfo without discoveryLink', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
119
- var discoveryLink, _setup2, result, waitForNextUpdate;
118
+ it('returns the right infos when using useSharingInfo without addSharingLink', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
119
+ var addSharingLink, _setup2, result, waitForNextUpdate;
120
120
 
121
121
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
122
122
  while (1) switch (_context2.prev = _context2.next) {
123
123
  case 0:
124
- discoveryLink = false;
125
- getDiscoveryLinkMock.mockReturnValue(discoveryLink);
124
+ addSharingLink = undefined;
125
+ getDiscoveryLinkMock.mockReturnValue(addSharingLink);
126
126
  fetchOwnPermissionsMock.mockResolvedValue(mockedPermissionsWithoutInstance);
127
127
  queryMock.mockResolvedValue(mockSharing);
128
128
  _setup2 = setup(), result = _setup2.result, waitForNextUpdate = _setup2.waitForNextUpdate; // default state
@@ -137,7 +137,7 @@ describe('useSharingInfos', function () {
137
137
  expect(result.current.loading).toEqual(false);
138
138
  expect(result.current.isSharingShortcutCreated).toEqual(false);
139
139
  expect(result.current.sharing).toEqual(mockSharing.data);
140
- expect(result.current.discoveryLink).toEqual(discoveryLink);
140
+ expect(result.current.addSharingLink).toEqual(addSharingLink);
141
141
 
142
142
  case 12:
143
143
  case "end":
@@ -5,4 +5,19 @@ export var checkIsReadOnlyPermissions = function checkIsReadOnlyPermissions(perm
5
5
  return Object.values(permissionCategories).filter(function (permissionCategory) {
6
6
  return models.permission.isReadOnly(permissionCategory);
7
7
  }).length > 0;
8
+ };
9
+ export var checkIsPermissionHasExpiresDate = function checkIsPermissionHasExpiresDate(permissions) {
10
+ var _permissions$;
11
+
12
+ return Boolean(permissions === null || permissions === void 0 || (_permissions$ = permissions[0]) === null || _permissions$ === void 0 || (_permissions$ = _permissions$.attributes) === null || _permissions$ === void 0 ? void 0 : _permissions$.expires_at);
13
+ };
14
+ export var getPermissionExpiresDate = function getPermissionExpiresDate(permissions) {
15
+ var _permissions$2;
16
+
17
+ return permissions === null || permissions === void 0 || (_permissions$2 = permissions[0]) === null || _permissions$2 === void 0 || (_permissions$2 = _permissions$2.attributes) === null || _permissions$2 === void 0 ? void 0 : _permissions$2.expires_at;
18
+ };
19
+ export var checkIsPermissionHasPassword = function checkIsPermissionHasPassword(permissions) {
20
+ var _permissions$3;
21
+
22
+ return Boolean(permissions === null || permissions === void 0 || (_permissions$3 = permissions[0]) === null || _permissions$3 === void 0 || (_permissions$3 = _permissions$3.attributes) === null || _permissions$3 === void 0 ? void 0 : _permissions$3.password);
8
23
  };
package/dist/index.js CHANGED
@@ -26,5 +26,7 @@ export { DOCUMENT_TYPE } from './helpers/documentType';
26
26
  export { default as OpenSharingLinkButton } from './OpenSharingLinkButton';
27
27
  export { default as OpenSharingLinkFabButton } from './OpenSharingLinkFabButton';
28
28
  export { NativeFileSharingProvider, useNativeFileSharing } from './providers/NativeFileSharingProvider';
29
- export { openSharingLink } from './actions/openSharingLink';
29
+ export { createCozySharingLink } from './actions/createCozySharingLink';
30
+ export { addToCozySharingLink } from './actions/addToCozySharingLink';
31
+ export { syncToCozySharingLink } from './actions/syncToCozySharingLink';
30
32
  export { shareNative } from './actions/shareNative';
package/locales/en.json CHANGED
@@ -26,6 +26,8 @@
26
26
  "recipients": {
27
27
  "you": "You",
28
28
  "anyoneWithTheLink": "Anyone with the link",
29
+ "linkWithPassword": "Anyone with a password",
30
+ "expires": "Until %{date}",
29
31
  "accessCount": "%{count} people have access"
30
32
  },
31
33
  "create-cozy": "Create |||| Create my cozy",
package/locales/fr.json CHANGED
@@ -26,6 +26,8 @@
26
26
  "recipients": {
27
27
  "you": "Vous",
28
28
  "anyoneWithTheLink": "N'importe qui avec le lien",
29
+ "linkWithPassword": "N'importe qui avec un mot de passe",
30
+ "expires": "Jusqu'au %{date}",
29
31
  "accessCount": "%{count} personnes y ont accès"
30
32
  },
31
33
  "create-cozy": "Créer |||| Créer mon Cozy",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-sharing",
3
- "version": "19.0.0",
3
+ "version": "21.0.0",
4
4
  "description": "Provides sharing login for React applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -53,7 +53,7 @@
53
53
  "babel-jest": "26.6.3",
54
54
  "babel-plugin-css-modules-transform": "1.6.2",
55
55
  "babel-plugin-inline-react-svg": "1.1.2",
56
- "cozy-client": "^52.1.0",
56
+ "cozy-client": "^53.0.0",
57
57
  "cozy-device-helper": "^3.7.1",
58
58
  "cozy-intent": "^2.29.1",
59
59
  "cozy-minilog": "^3.9.1",
@@ -66,7 +66,7 @@
66
66
  "storybook": "7.6.0"
67
67
  },
68
68
  "peerDependencies": {
69
- "cozy-client": ">=52.1.0",
69
+ "cozy-client": ">=53.0.0",
70
70
  "cozy-device-helper": ">=3.7.1",
71
71
  "cozy-intent": ">=2.29.1",
72
72
  "cozy-minilog": ">=3.9.1",
@@ -78,5 +78,5 @@
78
78
  "sideEffects": [
79
79
  "*.css"
80
80
  ],
81
- "gitHead": "74889d160e15166c4aa132e4fc8c77ebe95c62ae"
81
+ "gitHead": "0c51f40c510be568da5c63ae617ec7493801161a"
82
82
  }
@@ -331,25 +331,30 @@ export class SharingProvider extends Component {
331
331
  * updateDocumentPermissions - Description
332
332
  *
333
333
  * @param {Object} document A shared document
334
- * @param {Array} newVerbs The new verbs to use for the permission, eg. ['GET']
334
+ * @param {object} options The new verbs to use for the permission, eg. ['GET']
335
+ * @param {string[]} options.verbs The new verbs to use for the permission, eg. ['GET']
336
+ * @param {string} [options.expiresAt] The new expiration date for the permission
337
+ * @param {string} [options.password] The new password for the permission
335
338
  *
336
339
  * @return {Array}
337
340
  */
338
- updateDocumentPermissions = async (document, newVerbs) => {
341
+ updateDocumentPermissions = async (document, options) => {
342
+ const { verbs, expiresAt, password } = options
339
343
  const permissions = getDocumentPermissions(this.state, document.id)
340
344
 
341
345
  const responses = await Promise.all(
342
346
  permissions.map(async permissionDocument => {
343
347
  const updatedPermissions = permissionDocument.attributes.permissions
344
348
  Object.keys(updatedPermissions).map(permType => {
345
- updatedPermissions[permType].verbs = newVerbs
349
+ updatedPermissions[permType].verbs = verbs
346
350
  })
347
351
 
348
352
  const resp = await this.permissionCol.add(
349
353
  permissionDocument,
350
- updatedPermissions
354
+ updatedPermissions,
355
+ { expiresAt, password }
351
356
  )
352
- this.dispatch(updateSharingLink(resp))
357
+ this.dispatch(updateSharingLink(resp.data))
353
358
  return resp
354
359
  })
355
360
  )
@@ -0,0 +1,51 @@
1
+ import React, { forwardRef } from 'react'
2
+
3
+ import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
4
+ import Icon from 'cozy-ui/transpiled/react/Icon'
5
+ import CloudPlusOutlinedIcon from 'cozy-ui/transpiled/react/Icons/CloudPlusOutlined'
6
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
7
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
8
+
9
+ import { openExternalLink } from '../helpers/sharings'
10
+ import { getActionsI18n } from '../hoc/withLocales'
11
+
12
+ const makeComponent = (label, icon) => {
13
+ const Component = forwardRef((props, ref) => {
14
+ return (
15
+ <ActionsMenuItem {...props} ref={ref}>
16
+ <ListItemIcon>
17
+ <Icon icon={icon} />
18
+ </ListItemIcon>
19
+ <ListItemText primary={label} />
20
+ </ActionsMenuItem>
21
+ )
22
+ })
23
+ Component.displayName = 'AddToCozySharingLink'
24
+
25
+ return Component
26
+ }
27
+
28
+ export const addToCozySharingLink = ({
29
+ isSharingShortcutCreated,
30
+ openSharingLinkDisplayed = true,
31
+ isShortLabel = false,
32
+ addSharingLink
33
+ }) => {
34
+ const { t } = getActionsI18n()
35
+ const label = t('Share.banner.add_to_mine', {
36
+ smart_count: isShortLabel ? 1 : 2
37
+ })
38
+ const icon = CloudPlusOutlinedIcon
39
+
40
+ return {
41
+ name: 'addToCozySharingLink',
42
+ label,
43
+ icon,
44
+ displayCondition: () =>
45
+ openSharingLinkDisplayed && !isSharingShortcutCreated,
46
+ action: () => {
47
+ openExternalLink(addSharingLink)
48
+ },
49
+ Component: makeComponent(label, icon)
50
+ }
51
+ }
@@ -0,0 +1,47 @@
1
+ import React, { forwardRef } from 'react'
2
+
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
+
9
+ import { openExternalLink } from '../helpers/sharings'
10
+ import { getActionsI18n } from '../hoc/withLocales'
11
+
12
+ const makeComponent = (label, icon) => {
13
+ const Component = forwardRef((props, ref) => {
14
+ return (
15
+ <ActionsMenuItem {...props} ref={ref}>
16
+ <ListItemIcon>
17
+ <Icon icon={icon} />
18
+ </ListItemIcon>
19
+ <ListItemText primary={label} />
20
+ </ActionsMenuItem>
21
+ )
22
+ })
23
+ Component.displayName = 'CreateCozySharingLink'
24
+
25
+ return Component
26
+ }
27
+
28
+ export const createCozySharingLink = ({
29
+ openSharingLinkDisplayed = true,
30
+ isShortLabel = false,
31
+ createSharingLink
32
+ }) => {
33
+ const { t } = getActionsI18n()
34
+ const label = t('Share.create-cozy', { smart_count: isShortLabel ? 1 : 2 })
35
+ const icon = ToTheCloudIcon
36
+
37
+ return {
38
+ name: 'createCozySharingLink',
39
+ label,
40
+ icon,
41
+ displayCondition: () => openSharingLinkDisplayed,
42
+ action: () => {
43
+ openExternalLink(createSharingLink)
44
+ },
45
+ Component: makeComponent(label, icon)
46
+ }
47
+ }
@@ -2,10 +2,11 @@ import React, { forwardRef } from 'react'
2
2
 
3
3
  import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
4
4
  import Icon from 'cozy-ui/transpiled/react/Icon'
5
+ import SyncIcon from 'cozy-ui/transpiled/react/Icons/Sync'
5
6
  import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
6
7
  import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
7
8
 
8
- import { getIconWithlabel, openExternalLink } from '../helpers/sharings'
9
+ import { openExternalLink } from '../helpers/sharings'
9
10
  import { getActionsI18n } from '../hoc/withLocales'
10
11
 
11
12
  const makeComponent = (label, icon) => {
@@ -19,32 +20,29 @@ const makeComponent = (label, icon) => {
19
20
  </ActionsMenuItem>
20
21
  )
21
22
  })
22
- Component.displayName = 'OpenSharingLink'
23
+ Component.displayName = 'SyncToCozySharingLink'
23
24
 
24
25
  return Component
25
26
  }
26
27
 
27
- export const openSharingLink = ({
28
- isSharingShortcutCreated,
28
+ export const syncToCozySharingLink = ({
29
29
  openSharingLinkDisplayed = true,
30
30
  isShortLabel = false,
31
- link
31
+ syncSharingLink
32
32
  }) => {
33
33
  const { t } = getActionsI18n()
34
- const { icon, label } = getIconWithlabel({
35
- link,
36
- isSharingShortcutCreated,
37
- isShortLabel,
38
- t
34
+ const label = t('Share.banner.sync_to_mine', {
35
+ smart_count: isShortLabel ? 1 : 2
39
36
  })
37
+ const icon = SyncIcon
40
38
 
41
39
  return {
42
- name: 'openSharingLink',
40
+ name: 'syncToCozySharingLink',
43
41
  label,
44
42
  icon,
45
43
  displayCondition: () => openSharingLinkDisplayed,
46
44
  action: () => {
47
- openExternalLink(link)
45
+ openExternalLink(syncSharingLink)
48
46
  },
49
47
  Component: makeComponent(label, icon)
50
48
  }
@@ -14,14 +14,38 @@ import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
14
14
 
15
15
  import LinkRecipientPermissions from './LinkRecipientPermissions'
16
16
  import RecipientConfirm from './RecipientConfirm'
17
+ import {
18
+ checkIsPermissionHasPassword,
19
+ getPermissionExpiresDate
20
+ } from '../../helpers/permissions'
17
21
  import { FADE_IN_DURATION } from '../../helpers/recipients'
22
+ import { useSharingContext } from '../../hooks/useSharingContext'
18
23
  import styles from '../../styles/recipient.styl'
19
24
 
20
25
  const LinkRecipient = props => {
21
- const { t } = useI18n()
26
+ const { t, f, lang } = useI18n()
22
27
  const { isMobile } = useBreakpoints()
28
+ const { getDocumentPermissions } = useSharingContext()
23
29
 
24
- const { recipientConfirmationData, verifyRecipient, link, fadeIn } = props
30
+ const { recipientConfirmationData, verifyRecipient, link, fadeIn, document } =
31
+ props
32
+
33
+ const permissions = getDocumentPermissions(document._id)
34
+ const hasPassword = checkIsPermissionHasPassword(permissions)
35
+ const expiresDate = getPermissionExpiresDate(permissions)
36
+ const dateFormatted = expiresDate
37
+ ? f(expiresDate, lang === 'fr' ? 'dd/LL/yyyy' : 'LL/dd/yyyy')
38
+ : null
39
+
40
+ const textPrimary = hasPassword
41
+ ? t('Share.recipients.linkWithPassword')
42
+ : t('Share.recipients.anyoneWithTheLink')
43
+
44
+ const textSecondary = expiresDate
45
+ ? t('Share.recipients.expires', {
46
+ date: dateFormatted
47
+ })
48
+ : link
25
49
 
26
50
  const RightPart = recipientConfirmationData ? (
27
51
  <RecipientConfirm
@@ -43,10 +67,10 @@ const LinkRecipient = props => {
43
67
  <ListItemText
44
68
  primary={
45
69
  <Typography className="u-ellipsis" variant="body1">
46
- {t('Share.recipients.anyoneWithTheLink')}
70
+ {textPrimary}
47
71
  </Typography>
48
72
  }
49
- secondary={link}
73
+ secondary={textSecondary}
50
74
  />
51
75
  {RightPart}
52
76
  </ListItem>
@@ -15,8 +15,11 @@ import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert'
15
15
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
16
16
 
17
17
  import { copyToClipboard } from './helpers'
18
+ import { checkIsPermissionHasPassword } from '../../helpers/permissions'
19
+ import { useSharingContext } from '../../hooks/useSharingContext'
18
20
 
19
21
  export const BoxPassword = ({
22
+ file,
20
23
  onChange,
21
24
  password,
22
25
  onToggle,
@@ -28,6 +31,10 @@ export const BoxPassword = ({
28
31
  const { showAlert } = useAlert()
29
32
  const [displayHelper, setDisplayHelper] = useState(false)
30
33
  const inputRef = React.useRef()
34
+ const { getDocumentPermissions } = useSharingContext()
35
+
36
+ const permissions = getDocumentPermissions(file._id)
37
+ const hasPassword = checkIsPermissionHasPassword(permissions)
31
38
 
32
39
  const handlePasswordToggle = val => {
33
40
  const value = val?.target?.checked ?? val
@@ -77,7 +84,14 @@ export const BoxPassword = ({
77
84
  <div className="u-pt-half u-ph-1 u-pb-1">
78
85
  <TextField
79
86
  inputRef={inputRef}
87
+ autoFocus
80
88
  label={t('BoxPassword.label')}
89
+ {...(hasPassword && {
90
+ placeholder: '****',
91
+ InputLabelProps: {
92
+ shrink: true
93
+ }
94
+ })}
81
95
  value={password}
82
96
  error={displayHelper && !!helperText}
83
97
  helperText={displayHelper && helperText}