cozy-sharing 11.0.1 → 12.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 (69) hide show
  1. package/.storybook/preview.jsx +11 -5
  2. package/CHANGELOG.md +31 -0
  3. package/dist/SharingProvider.js +111 -62
  4. package/dist/components/Avatar/GroupAvatar.js +13 -0
  5. package/dist/components/Avatar/GroupAvatar.stories.js +10 -0
  6. package/dist/components/Recipient/GroupRecipient.js +49 -0
  7. package/dist/components/Recipient/GroupRecipient.stories.js +41 -0
  8. package/dist/components/Recipient/GroupRecipientPermissions.js +133 -0
  9. package/dist/components/Recipient/GroupRecipientPermissions.stories.js +37 -0
  10. package/dist/components/Recipient/MemberRecipient.stories.js +11 -1
  11. package/dist/components/Recipient/MemberRecipientPermissions.js +31 -40
  12. package/dist/components/Recipient/MemberRecipientPermissions.stories.js +30 -4
  13. package/dist/components/Recipient/RecipientList.js +16 -1
  14. package/dist/components/Recipient/RecipientList.stories.js +28 -0
  15. package/dist/components/Recipient/actions/permission.js +30 -0
  16. package/dist/components/Recipient/actions/revokeGroup.js +41 -0
  17. package/dist/components/Recipient/actions/revokeMember.js +41 -0
  18. package/dist/components/ShareByEmail.js +8 -29
  19. package/dist/components/ShareByEmail.spec.js +1 -1
  20. package/dist/components/ShareDialogCozyToCozy.js +2 -2
  21. package/dist/components/ShareDialogCozyToCozy.spec.js +1 -1
  22. package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +2 -2
  23. package/dist/components/ShareDialogTwoStepsConfirmationContainer.spec.js +1 -1
  24. package/dist/components/ShareModal/EditableSharingModal.js +43 -42
  25. package/dist/components/ShareModal/EditableSharingModal.spec.js +2 -2
  26. package/dist/components/ShareModal.js +4 -4
  27. package/dist/components/ShareRecipientsInput.js +7 -7
  28. package/dist/components/ShareRecipientsInput.spec.js +2 -2
  29. package/dist/helpers/recipients.js +38 -0
  30. package/dist/helpers/successMessage.spec.js +1 -1
  31. package/dist/propTypes.js +1 -1
  32. package/dist/queries/queries.js +1 -1
  33. package/dist/state.js +85 -2
  34. package/dist/state.spec.js +190 -10
  35. package/locales/en.json +24 -30
  36. package/locales/fr.json +24 -30
  37. package/package.json +5 -5
  38. package/src/SharingProvider.jsx +15 -0
  39. package/src/components/Avatar/GroupAvatar.jsx +10 -0
  40. package/src/components/Avatar/GroupAvatar.stories.jsx +13 -0
  41. package/src/components/Recipient/GroupRecipient.jsx +56 -0
  42. package/src/components/Recipient/GroupRecipient.stories.jsx +38 -0
  43. package/src/components/Recipient/GroupRecipientPermissions.jsx +106 -0
  44. package/src/components/Recipient/GroupRecipientPermissions.stories.jsx +41 -0
  45. package/src/components/Recipient/MemberRecipient.stories.jsx +12 -1
  46. package/src/components/Recipient/MemberRecipientPermissions.jsx +37 -53
  47. package/src/components/Recipient/MemberRecipientPermissions.stories.jsx +31 -4
  48. package/src/components/Recipient/RecipientList.jsx +18 -1
  49. package/src/components/Recipient/RecipientList.stories.jsx +34 -0
  50. package/src/components/Recipient/actions/permission.js +28 -0
  51. package/src/components/Recipient/actions/revokeGroup.js +39 -0
  52. package/src/components/Recipient/actions/revokeMember.js +39 -0
  53. package/src/components/ShareByEmail.jsx +14 -32
  54. package/src/components/ShareByEmail.spec.jsx +1 -1
  55. package/src/components/ShareDialogCozyToCozy.jsx +2 -2
  56. package/src/components/ShareDialogCozyToCozy.spec.jsx +1 -1
  57. package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +2 -2
  58. package/src/components/ShareDialogTwoStepsConfirmationContainer.spec.jsx +1 -1
  59. package/src/components/ShareModal/EditableSharingModal.jsx +48 -46
  60. package/src/components/ShareModal/EditableSharingModal.spec.jsx +1 -1
  61. package/src/components/ShareModal.jsx +4 -4
  62. package/src/components/ShareRecipientsInput.jsx +9 -9
  63. package/src/components/ShareRecipientsInput.spec.jsx +2 -2
  64. package/src/helpers/recipients.js +45 -0
  65. package/src/helpers/successMessage.spec.js +1 -1
  66. package/src/propTypes.js +1 -1
  67. package/src/queries/queries.js +1 -1
  68. package/src/state.js +81 -2
  69. package/src/state.spec.js +230 -9
@@ -0,0 +1,37 @@
1
+ import { GroupRecipientPermissions } from './GroupRecipientPermissions';
2
+ var meta = {
3
+ component: GroupRecipientPermissions,
4
+ args: {
5
+ onRevoke: function onRevoke() {},
6
+ onRevokeSelf: function onRevokeSelf() {},
7
+ type: 'two-way',
8
+ status: 'ready',
9
+ groupIndex: 0
10
+ },
11
+ argTypes: {
12
+ status: {
13
+ control: 'select',
14
+ options: ['ready', 'mail-not-sent', 'pending', 'seen', 'owner'],
15
+ defaultValue: 'ready'
16
+ },
17
+ type: {
18
+ control: 'select',
19
+ options: ['one-way', 'two-way'],
20
+ defaultValue: 'two-way'
21
+ }
22
+ }
23
+ };
24
+ export default meta;
25
+ export var Owner = {
26
+ name: 'Owner',
27
+ args: {
28
+ isOwner: true
29
+ }
30
+ };
31
+ export var Self = {
32
+ name: 'Self',
33
+ args: {
34
+ isOwner: false,
35
+ instance: 'http://alice.cozy.localhost:8080'
36
+ }
37
+ };
@@ -7,7 +7,10 @@ var meta = {
7
7
  status: 'ready',
8
8
  recipientConfirmationData: null,
9
9
  verifyRecipient: function verifyRecipient() {},
10
- fadeIn: true
10
+ fadeIn: true,
11
+ type: 'two-way',
12
+ onRevoke: function onRevoke() {},
13
+ onRevokeSelf: function onRevokeSelf() {}
11
14
  },
12
15
  argTypes: {
13
16
  status: {
@@ -29,6 +32,13 @@ export var Owner = {
29
32
  status: 'owner'
30
33
  }
31
34
  };
35
+ export var SameInstance = {
36
+ name: 'SameInstance',
37
+ args: {
38
+ isOwner: false,
39
+ instance: 'http://alice.cozy.localhost:8080'
40
+ }
41
+ };
32
42
  export var RecipientConfirm = {
33
43
  name: 'RecipientConfirm',
34
44
  args: {
@@ -3,15 +3,14 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  import React, { useState, useRef, useCallback } from 'react';
5
5
  import { useClient } from 'cozy-client';
6
+ import ActionsMenu from 'cozy-ui/transpiled/react/ActionsMenu';
7
+ import { makeActions, divider } from 'cozy-ui/transpiled/react/ActionsMenu/Actions';
6
8
  import DropdownButton from 'cozy-ui/transpiled/react/DropdownButton';
7
- import Icon from 'cozy-ui/transpiled/react/Icon';
8
- import EyeIcon from 'cozy-ui/transpiled/react/Icons/Eye';
9
- import RenameIcon from 'cozy-ui/transpiled/react/Icons/Rename';
10
- import TrashIcon from 'cozy-ui/transpiled/react/Icons/Trash';
11
9
  import Spinner from 'cozy-ui/transpiled/react/Spinner';
12
10
  import Typography from 'cozy-ui/transpiled/react/Typography';
13
- import ActionMenu, { ActionMenuItem } from 'cozy-ui/transpiled/react/deprecated/ActionMenu';
14
11
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
12
+ import { permission } from './actions/permission';
13
+ import { revokeMember } from './actions/revokeMember';
15
14
 
16
15
  var MemberRecipientPermissions = function MemberRecipientPermissions(_ref) {
17
16
  var isOwner = _ref.isOwner,
@@ -19,12 +18,11 @@ var MemberRecipientPermissions = function MemberRecipientPermissions(_ref) {
19
18
  instance = _ref.instance,
20
19
  type = _ref.type,
21
20
  document = _ref.document,
22
- documentType = _ref.documentType,
23
21
  className = _ref.className,
24
22
  onRevoke = _ref.onRevoke,
25
23
  onRevokeSelf = _ref.onRevokeSelf,
26
24
  sharingId = _ref.sharingId,
27
- index = _ref.index;
25
+ memberIndex = _ref.memberIndex;
28
26
 
29
27
  var _useI18n = useI18n(),
30
28
  t = _useI18n.t;
@@ -40,21 +38,21 @@ var MemberRecipientPermissions = function MemberRecipientPermissions(_ref) {
40
38
  var _useState3 = useState(false),
41
39
  _useState4 = _slicedToArray(_useState3, 2),
42
40
  isMenuDisplayed = _useState4[0],
43
- setIsMenuDisplayed = _useState4[1];
41
+ setMenuDisplayed = _useState4[1];
44
42
 
45
43
  var instanceMatchesClient = instance !== undefined && instance === client.options.uri;
46
44
  var contactIsOwner = status === 'owner';
47
45
  var shouldShowMenu = !revoking && !contactIsOwner && (instanceMatchesClient && !isOwner || isOwner);
48
46
 
49
- var showMenu = function showMenu() {
50
- return setIsMenuDisplayed(true);
47
+ var toggleMenu = function toggleMenu() {
48
+ return setMenuDisplayed(!isMenuDisplayed);
51
49
  };
52
50
 
53
51
  var hideMenu = function hideMenu() {
54
- return setIsMenuDisplayed(false);
52
+ return setMenuDisplayed(false);
55
53
  };
56
54
 
57
- var onRevokeClick = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
55
+ var handleRevocation = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
58
56
  return _regeneratorRuntime.wrap(function _callee$(_context) {
59
57
  while (1) switch (_context.prev = _context.next) {
60
58
  case 0:
@@ -66,7 +64,7 @@ var MemberRecipientPermissions = function MemberRecipientPermissions(_ref) {
66
64
  }
67
65
 
68
66
  _context.next = 4;
69
- return onRevoke(document, sharingId, index);
67
+ return onRevoke(document, sharingId, memberIndex);
70
68
 
71
69
  case 4:
72
70
  _context.next = 8;
@@ -84,41 +82,34 @@ var MemberRecipientPermissions = function MemberRecipientPermissions(_ref) {
84
82
  return _context.stop();
85
83
  }
86
84
  }, _callee);
87
- })), [isOwner, onRevoke, onRevokeSelf, document, sharingId, index]);
88
- var PermissionIcon = type === 'two-way' ? RenameIcon : EyeIcon;
85
+ })), [isOwner, onRevoke, onRevokeSelf, document, sharingId, memberIndex]);
86
+ var actions = makeActions([permission, divider, revokeMember], {
87
+ t: t,
88
+ type: type,
89
+ isOwner: isOwner,
90
+ handleRevocation: handleRevocation
91
+ });
89
92
  return /*#__PURE__*/React.createElement("div", {
90
93
  className: className
91
94
  }, revoking && /*#__PURE__*/React.createElement(Spinner, null), !shouldShowMenu && !revoking && /*#__PURE__*/React.createElement(Typography, {
92
95
  variant: "body2"
93
96
  }, t("Share.status.".concat(status)).toLowerCase()), shouldShowMenu && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DropdownButton, {
94
- onClick: showMenu,
95
97
  ref: buttonRef,
98
+ "aria-controls": "simple-menu",
99
+ "aria-haspopup": "true",
100
+ onClick: toggleMenu,
96
101
  textVariant: "body2"
97
- }, t("Share.type.".concat(type)).toLowerCase()), isMenuDisplayed && /*#__PURE__*/React.createElement(ActionMenu, {
98
- onClose: hideMenu,
99
- popperOptions: {
100
- placement: 'bottom-end',
101
- strategy: 'fixed'
102
+ }, t("Share.type.".concat(type)).toLowerCase()), /*#__PURE__*/React.createElement(ActionsMenu, {
103
+ ref: buttonRef,
104
+ open: isMenuDisplayed,
105
+ actions: actions,
106
+ anchorOrigin: {
107
+ vertical: 'bottom',
108
+ horizontal: 'right'
102
109
  },
103
- anchorElRef: buttonRef
104
- }, /*#__PURE__*/React.createElement(ActionMenuItem, {
105
- left: /*#__PURE__*/React.createElement(Icon, {
106
- icon: PermissionIcon,
107
- color: "var(--primaryTextColor)"
108
- })
109
- }, t("Share.type.".concat(type))), /*#__PURE__*/React.createElement("hr", null), /*#__PURE__*/React.createElement(ActionMenuItem, {
110
- onClick: onRevokeClick,
111
- left: /*#__PURE__*/React.createElement(Icon, {
112
- icon: TrashIcon,
113
- color: "var(--errorColor)"
114
- })
115
- }, /*#__PURE__*/React.createElement(Typography, {
116
- className: "u-error",
117
- variant: "body1"
118
- }, isOwner ? t("".concat(documentType, ".share.revoke.title")) : t("".concat(documentType, ".share.revokeSelf.title"))), /*#__PURE__*/React.createElement(Typography, {
119
- variant: "caption",
120
- color: "textSecondary"
121
- }, isOwner ? t("".concat(documentType, ".share.revoke.desc")) : t("".concat(documentType, ".share.revokeSelf.desc")))))));
110
+ autoClose: true,
111
+ onClose: hideMenu
112
+ })));
122
113
  };
123
114
 
124
115
  export default MemberRecipientPermissions;
@@ -1,10 +1,36 @@
1
1
  import MemberRecipientPermissions from './MemberRecipientPermissions';
2
2
  var meta = {
3
3
  component: MemberRecipientPermissions,
4
- args: {}
4
+ args: {
5
+ onRevoke: function onRevoke() {},
6
+ onRevokeSelf: function onRevokeSelf() {},
7
+ type: 'two-way',
8
+ status: 'ready'
9
+ },
10
+ argTypes: {
11
+ status: {
12
+ control: 'select',
13
+ options: ['ready', 'mail-not-sent', 'pending', 'seen', 'owner'],
14
+ defaultValue: 'ready'
15
+ },
16
+ type: {
17
+ control: 'select',
18
+ options: ['one-way', 'two-way'],
19
+ defaultValue: 'two-way'
20
+ }
21
+ }
5
22
  };
6
23
  export default meta;
7
- export var Default = {
8
- name: 'Default',
9
- args: {}
24
+ export var Owner = {
25
+ name: 'Owner',
26
+ args: {
27
+ isOwner: true
28
+ }
29
+ };
30
+ export var Self = {
31
+ name: 'Self',
32
+ args: {
33
+ isOwner: false,
34
+ instance: 'http://alice.cozy.localhost:8080'
35
+ }
10
36
  };
@@ -1,5 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React from 'react';
3
+ import { GroupRecipient } from './GroupRecipient';
3
4
  import MemberRecipient from './MemberRecipient';
4
5
  import { usePrevious } from '../../helpers/hooks';
5
6
  import { filterAndReworkRecipients } from '../../helpers/recipients';
@@ -19,8 +20,22 @@ var RecipientList = function RecipientList(_ref) {
19
20
  var recipientConfirmationData = recipientsToBeConfirmed.find(function (user) {
20
21
  return user.email === recipient.email;
21
22
  });
23
+ var isGroupRecipient = recipient.members;
24
+
25
+ if (isGroupRecipient) {
26
+ return /*#__PURE__*/React.createElement(GroupRecipient, _extends({}, recipient, {
27
+ isOwner: isOwner,
28
+ key: recipient.index,
29
+ document: document,
30
+ documentType: documentType,
31
+ onRevoke: onRevoke,
32
+ onRevokeSelf: onRevokeSelf,
33
+ fadeIn: recipient.hasBeenJustAdded
34
+ }));
35
+ }
36
+
22
37
  return /*#__PURE__*/React.createElement(MemberRecipient, _extends({}, recipient, {
23
- key: "key_r_".concat(recipient.index),
38
+ key: recipient.index,
24
39
  isOwner: isOwner,
25
40
  document: document,
26
41
  documentType: documentType,
@@ -1,3 +1,4 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import { RecipientList } from './RecipientList';
2
3
  import { recipients } from '../../../.storybook/fixtures/recipients';
3
4
  var meta = {
@@ -23,4 +24,31 @@ export var Owner = {
23
24
  args: {
24
25
  isOwner: true
25
26
  }
27
+ };
28
+ export var WithGroup = {
29
+ name: 'With group',
30
+ args: {
31
+ recipients: [].concat(_toConsumableArray(recipients), [{
32
+ id: '2c8d4d5abbec5b4606a1ebe01a021dfd',
33
+ name: 'Famille',
34
+ addedBy: 0,
35
+ read_only: false,
36
+ index: 0,
37
+ members: [{
38
+ status: 'pending',
39
+ email: 'ben@gmail.com',
40
+ only_in_groups: true,
41
+ groups: [0],
42
+ type: 'two-way',
43
+ index: 1
44
+ }, {
45
+ status: 'pending',
46
+ email: 'bob@gmail.com',
47
+ only_in_groups: true,
48
+ groups: [0],
49
+ type: 'two-way',
50
+ index: 2
51
+ }]
52
+ }])
53
+ }
26
54
  };
@@ -0,0 +1,30 @@
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
+
8
+ var permission = function permission(_ref) {
9
+ var t = _ref.t,
10
+ type = _ref.type;
11
+ var title = t("Share.type.".concat(type));
12
+ return {
13
+ name: 'permission',
14
+ label: title,
15
+ icon: null,
16
+ action: null,
17
+ Component: /*#__PURE__*/forwardRef(function RevokeItem(props, ref) {
18
+ return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
19
+ ref: ref,
20
+ button: false
21
+ }), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Radios, {
22
+ checked: true
23
+ })), /*#__PURE__*/React.createElement(ListItemText, {
24
+ primary: title
25
+ }));
26
+ })
27
+ };
28
+ };
29
+
30
+ export { permission };
@@ -0,0 +1,41 @@
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 ForbiddenIcon from 'cozy-ui/transpiled/react/Icons/Forbidden';
6
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
7
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
8
+ import Typography from 'cozy-ui/transpiled/react/Typography';
9
+
10
+ var revokeGroup = function revokeGroup(_ref) {
11
+ var t = _ref.t,
12
+ isOwner = _ref.isOwner,
13
+ handleRevocation = _ref.handleRevocation;
14
+ var revokeType = isOwner ? 'revoke' : 'revokeSelf';
15
+ var title = t("RevokeGroupItem.".concat(revokeType, ".title"));
16
+ var desc = t("RevokeGroupItem.".concat(revokeType, ".desc"));
17
+ var icon = ForbiddenIcon;
18
+ return {
19
+ name: 'revokeMember',
20
+ label: title,
21
+ icon: icon,
22
+ action: function action() {
23
+ handleRevocation();
24
+ },
25
+ Component: /*#__PURE__*/forwardRef(function RevokeMemberItem(props, ref) {
26
+ return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
27
+ ref: ref
28
+ }), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
29
+ icon: icon,
30
+ color: "var(--errorColor)"
31
+ })), /*#__PURE__*/React.createElement(ListItemText, {
32
+ primary: /*#__PURE__*/React.createElement(Typography, {
33
+ color: "error"
34
+ }, title),
35
+ secondary: desc
36
+ }));
37
+ })
38
+ };
39
+ };
40
+
41
+ export { revokeGroup };
@@ -0,0 +1,41 @@
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 TrashIcon from 'cozy-ui/transpiled/react/Icons/Trash';
6
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
7
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
8
+ import Typography from 'cozy-ui/transpiled/react/Typography';
9
+
10
+ var revokeMember = function revokeMember(_ref) {
11
+ var t = _ref.t,
12
+ isOwner = _ref.isOwner,
13
+ handleRevocation = _ref.handleRevocation;
14
+ var revokeType = isOwner ? 'revoke' : 'revokeSelf';
15
+ var title = t("RevokeMemberItem.".concat(revokeType, ".title"));
16
+ var desc = t("RevokeMemberItem.".concat(revokeType, ".desc"));
17
+ var icon = TrashIcon;
18
+ return {
19
+ name: 'revokeMember',
20
+ label: title,
21
+ icon: icon,
22
+ action: function action() {
23
+ handleRevocation();
24
+ },
25
+ Component: /*#__PURE__*/forwardRef(function RevokeMemberItem(props, ref) {
26
+ return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
27
+ ref: ref
28
+ }), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
29
+ icon: icon,
30
+ color: "var(--errorColor)"
31
+ })), /*#__PURE__*/React.createElement(ListItemText, {
32
+ primary: /*#__PURE__*/React.createElement(Typography, {
33
+ color: "error"
34
+ }, title),
35
+ secondary: desc
36
+ }));
37
+ })
38
+ };
39
+ };
40
+
41
+ export { revokeMember };
@@ -2,10 +2,10 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
5
- import get from 'lodash/get';
6
5
  import PropTypes from 'prop-types';
7
6
  import React, { useState } from 'react';
8
7
  import { useClient } from 'cozy-client';
8
+ import flag from 'cozy-flags';
9
9
  import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter';
10
10
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
11
11
  import ShareRecipientsInput from './ShareRecipientsInput';
@@ -13,10 +13,9 @@ import { ShareRecipientsLimitModal } from './ShareRecipientsLimitModal';
13
13
  import ShareSubmit from './Sharesubmit';
14
14
  import ShareTypeSelect from './Sharetypeselect';
15
15
  import { getOrCreateFromArray } from '../helpers/contacts';
16
- import { hasReachRecipientsLimit } from '../helpers/recipients';
16
+ import { mergeRecipients, spreadGroupAndMergeRecipients, hasReachRecipientsLimit } from '../helpers/recipients';
17
17
  import { getSuccessMessage } from '../helpers/successMessage';
18
- import { Group } from '../models';
19
- import { contactsResponseType, groupsResponseType } from '../propTypes';
18
+ import { contactsResponseType, contactGroupsResponseType } from '../propTypes';
20
19
  import { isReadOnlySharing } from '../state';
21
20
  var styles = {
22
21
  "share-modal-content": "share__share-modal-content___1iqEq",
@@ -43,7 +42,7 @@ var styles = {
43
42
  };
44
43
  export var ShareByEmail = function ShareByEmail(_ref) {
45
44
  var contacts = _ref.contacts,
46
- groups = _ref.groups,
45
+ contactGroups = _ref.contactGroups,
47
46
  document = _ref.document,
48
47
  sharingDesc = _ref.sharingDesc,
49
48
  onShare = _ref.onShare,
@@ -86,28 +85,8 @@ export var ShareByEmail = function ShareByEmail(_ref) {
86
85
  };
87
86
 
88
87
  var onRecipientPick = function onRecipientPick(recipient) {
89
- var contactsToAdd;
90
-
91
- if (recipient._type === Group.doctype) {
92
- var groupId = recipient.id;
93
- contactsToAdd = contacts.data.filter(function (contact) {
94
- var contactGroupIds = get(contact, 'relationships.groups.data', []).map(function (group) {
95
- return group._id;
96
- });
97
- return contactGroupIds.includes(groupId);
98
- });
99
- } else {
100
- contactsToAdd = [recipient];
101
- }
102
-
103
- var filtered = contactsToAdd.filter(function (contact) {
104
- return contact.email && contact.email.length > 0 || contact.cozy && contact.cozy.length > 0;
105
- }).filter(function (contact) {
106
- return !recipients.find(function (r) {
107
- return r === contact;
108
- });
109
- });
110
- setRecipients([].concat(_toConsumableArray(recipients), _toConsumableArray(filtered)));
88
+ var mergedRecipients = flag('sharing.show-recipient-groups') ? mergeRecipients(recipients, recipient) : spreadGroupAndMergeRecipients(recipients, recipient, contacts);
89
+ setRecipients(mergedRecipients);
111
90
  };
112
91
 
113
92
  var onRecipientRemove = function onRecipientRemove(recipient) {
@@ -226,7 +205,7 @@ export var ShareByEmail = function ShareByEmail(_ref) {
226
205
  return onRecipientRemove(recipient);
227
206
  },
228
207
  contacts: contacts,
229
- groups: groups,
208
+ contactGroups: contactGroups,
230
209
  recipients: recipients
231
210
  })), showShareControl && /*#__PURE__*/React.createElement("div", {
232
211
  className: styles['share-type-control']
@@ -248,7 +227,7 @@ export var ShareByEmail = function ShareByEmail(_ref) {
248
227
  ShareByEmail.propTypes = {
249
228
  currentRecipients: PropTypes.arrayOf(PropTypes.object),
250
229
  contacts: contactsResponseType.isRequired,
251
- groups: groupsResponseType.isRequired,
230
+ contactGroups: contactGroupsResponseType.isRequired,
252
231
  document: PropTypes.object.isRequired,
253
232
  documentType: PropTypes.string.isRequired,
254
233
  sharingDesc: PropTypes.string.isRequired,
@@ -34,7 +34,7 @@ describe('ShareByEmailComponent', function () {
34
34
  contacts: {
35
35
  data: []
36
36
  },
37
- groups: {
37
+ contactGroups: {
38
38
  data: []
39
39
  },
40
40
  documentType: 'Files',
@@ -38,10 +38,10 @@ var styles = {
38
38
 
39
39
  var SharingContent = function SharingContent(_ref) {
40
40
  var contacts = _ref.contacts,
41
+ contactGroups = _ref.contactGroups,
41
42
  createContact = _ref.createContact,
42
43
  document = _ref.document,
43
44
  documentType = _ref.documentType,
44
- groups = _ref.groups,
45
45
  hasSharedParent = _ref.hasSharedParent,
46
46
  isOwner = _ref.isOwner,
47
47
  needsContactsPermission = _ref.needsContactsPermission,
@@ -75,11 +75,11 @@ var SharingContent = function SharingContent(_ref) {
75
75
  className: "u-mb-1-half"
76
76
  }, t('Share.contacts.whoHasAccess')), showShareByEmail && /*#__PURE__*/React.createElement(DumbShareByEmail, {
77
77
  contacts: contacts,
78
+ contactGroups: contactGroups,
78
79
  createContact: createContact,
79
80
  currentRecipients: recipients,
80
81
  document: document,
81
82
  documentType: documentType,
82
- groups: groups,
83
83
  needsContactsPermission: needsContactsPermission,
84
84
  onShare: onShare,
85
85
  sharing: sharing,
@@ -433,7 +433,7 @@ var getMockProps = function getMockProps() {
433
433
  _id: 'SOME_DOCUMENT_ID'
434
434
  },
435
435
  documentType: 'Organizations',
436
- groups: {
436
+ contactGroups: {
437
437
  id: 'groups',
438
438
  definition: {
439
439
  doctype: 'io.cozy.contacts.groups'
@@ -99,10 +99,10 @@ var RejectRecipientActions = function RejectRecipientActions(_ref3) {
99
99
 
100
100
  var ShareDialogTwoStepsConfirmationContainer = function ShareDialogTwoStepsConfirmationContainer(_ref4) {
101
101
  var contacts = _ref4.contacts,
102
+ contactGroups = _ref4.contactGroups,
102
103
  createContact = _ref4.createContact,
103
104
  document = _ref4.document,
104
105
  documentType = _ref4.documentType,
105
- groups = _ref4.groups,
106
106
  hasSharedParent = _ref4.hasSharedParent,
107
107
  isOwner = _ref4.isOwner,
108
108
  link = _ref4.link,
@@ -241,10 +241,10 @@ var ShareDialogTwoStepsConfirmationContainer = function ShareDialogTwoStepsConfi
241
241
  } else if (status === 'sharing') {
242
242
  dialogContent = /*#__PURE__*/React.createElement(DialogContentOnShare, {
243
243
  contacts: contacts,
244
+ contactGroups: contactGroups,
244
245
  createContact: createContact,
245
246
  document: document,
246
247
  documentType: documentType,
247
- groups: groups,
248
248
  hasSharedParent: hasSharedParent,
249
249
  isOwner: isOwner,
250
250
  needsContactsPermission: needsContactsPermission,
@@ -455,7 +455,7 @@ var getMockProps = function getMockProps() {
455
455
  _id: 'SOME_DOCUMENT_ID'
456
456
  },
457
457
  documentType: 'Organizations',
458
- groups: {
458
+ contactGroups: {
459
459
  id: 'groups',
460
460
  definition: {
461
461
  doctype: 'io.cozy.contacts.groups'