cozy-sharing 5.0.0 → 6.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 (115) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/SharedRecipients.js +1 -1
  3. package/dist/SharedStatus.js +1 -1
  4. package/dist/SharingBanner/hooks/useSharingInfos.js +1 -1
  5. package/dist/SharingDetailsModal.js +1 -1
  6. package/dist/SharingOwnerAvatar.js +1 -1
  7. package/dist/SharingProvider.js +21 -8
  8. package/dist/components/ContactSuggestion.js +15 -27
  9. package/dist/components/EditLinkPermissionDialog.js +72 -0
  10. package/dist/components/EditLinkPermissionDialog.spec.js +48 -0
  11. package/dist/components/EditableSharingModal.js +15 -62
  12. package/dist/components/{AvatarPlusX.js → Recipient/AvatarPlusX.js} +1 -1
  13. package/dist/components/{Identity.js → Recipient/Identity.js} +17 -16
  14. package/dist/components/Recipient/LinkRecipient.js +72 -0
  15. package/dist/components/Recipient/LinkRecipientPermissions.js +159 -0
  16. package/dist/components/Recipient/OwnerIdentity.js +44 -0
  17. package/dist/components/Recipient/Recipient.js +72 -0
  18. package/dist/components/{Recipient.spec.js → Recipient/Recipient.spec.js} +4 -45
  19. package/dist/components/Recipient/RecipientAvatar.js +33 -0
  20. package/dist/components/Recipient/RecipientConfirm.js +63 -0
  21. package/dist/components/Recipient/RecipientPermissions.js +126 -0
  22. package/dist/components/Recipient/RecipientPlusX.js +45 -0
  23. package/dist/components/Recipient/RecipientStatus.js +64 -0
  24. package/dist/components/Recipient/RecipientWithoutStatus.js +45 -0
  25. package/dist/components/Recipient/RecipientsAvatars.js +100 -0
  26. package/dist/components/{RecipientsAvatars.spec.js → Recipient/RecipientsAvatars.spec.js} +43 -2
  27. package/dist/components/{recipient.styl → Recipient/recipient.styl} +6 -2
  28. package/dist/components/ShareAutosuggest.js +176 -252
  29. package/dist/components/ShareAutosuggest.spec.js +3 -2
  30. package/dist/components/ShareByEmail.js +142 -193
  31. package/dist/components/ShareByEmail.spec.js +42 -23
  32. package/dist/components/ShareByLink.js +251 -357
  33. package/dist/components/ShareDialogCozyToCozy.js +16 -4
  34. package/dist/components/ShareDialogCozyToCozy.spec.js +12 -1
  35. package/dist/components/ShareDialogOnlyByLink.js +23 -10
  36. package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +7 -7
  37. package/dist/components/ShareModal.js +5 -1
  38. package/dist/components/ShareRecipientsInput.js +44 -128
  39. package/dist/components/WhoHasAccess.js +43 -5
  40. package/dist/components/WhoHasAccessLight.js +3 -19
  41. package/dist/components/autosuggest.styl +21 -36
  42. package/dist/helpers/documentType.js +6 -0
  43. package/dist/helpers/hooks.js +8 -1
  44. package/dist/helpers/link.js +5 -0
  45. package/dist/helpers/permissions.js +8 -0
  46. package/dist/helpers/recipients.js +24 -0
  47. package/dist/helpers/sharings.js +72 -53
  48. package/dist/helpers/synchronousJobQueue.js +67 -0
  49. package/dist/helpers/synchronousJobQueue.spec.js +97 -0
  50. package/dist/index.js +2 -1
  51. package/dist/queries/queries.js +72 -0
  52. package/dist/share.styl +0 -15
  53. package/dist/stylesheet.css +67 -92
  54. package/locales/en.json +29 -41
  55. package/locales/fr.json +26 -39
  56. package/package.json +10 -10
  57. package/src/SharedRecipients.jsx +1 -1
  58. package/src/SharedStatus.jsx +1 -1
  59. package/src/SharingBanner/hooks/useSharingInfos.jsx +1 -1
  60. package/src/SharingDetailsModal.jsx +1 -1
  61. package/src/SharingOwnerAvatar.jsx +1 -1
  62. package/src/SharingProvider.jsx +17 -4
  63. package/src/components/ContactSuggestion.jsx +25 -10
  64. package/src/components/EditLinkPermissionDialog.jsx +89 -0
  65. package/src/components/EditLinkPermissionDialog.spec.jsx +52 -0
  66. package/src/components/EditableSharingModal.jsx +58 -100
  67. package/src/components/{AvatarPlusX.jsx → Recipient/AvatarPlusX.jsx} +1 -1
  68. package/src/components/{Identity.jsx → Recipient/Identity.jsx} +0 -0
  69. package/src/components/Recipient/LinkRecipient.jsx +59 -0
  70. package/src/components/Recipient/LinkRecipientPermissions.jsx +157 -0
  71. package/src/components/Recipient/OwnerIdentity.jsx +20 -0
  72. package/src/components/Recipient/Recipient.jsx +79 -0
  73. package/src/components/{Recipient.spec.jsx → Recipient/Recipient.spec.jsx} +4 -42
  74. package/src/components/Recipient/RecipientAvatar.jsx +38 -0
  75. package/src/components/Recipient/RecipientConfirm.jsx +37 -0
  76. package/src/components/Recipient/RecipientPermissions.jsx +114 -0
  77. package/src/components/Recipient/RecipientPlusX.jsx +28 -0
  78. package/src/components/Recipient/RecipientStatus.jsx +48 -0
  79. package/src/components/Recipient/RecipientWithoutStatus.jsx +21 -0
  80. package/src/components/Recipient/RecipientsAvatars.jsx +108 -0
  81. package/src/components/{RecipientsAvatars.spec.jsx → Recipient/RecipientsAvatars.spec.jsx} +43 -2
  82. package/src/components/{recipient.styl → Recipient/recipient.styl} +6 -2
  83. package/src/components/ShareAutosuggest.jsx +136 -127
  84. package/src/components/ShareAutosuggest.spec.jsx +12 -8
  85. package/src/components/ShareByEmail.jsx +65 -90
  86. package/src/components/ShareByEmail.spec.jsx +39 -11
  87. package/src/components/ShareByLink.jsx +146 -238
  88. package/src/components/ShareDialogCozyToCozy.jsx +14 -2
  89. package/src/components/ShareDialogCozyToCozy.spec.jsx +8 -1
  90. package/src/components/ShareDialogOnlyByLink.jsx +30 -13
  91. package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +5 -5
  92. package/src/components/ShareModal.jsx +5 -1
  93. package/src/components/ShareRecipientsInput.jsx +30 -44
  94. package/src/components/WhoHasAccess.jsx +85 -27
  95. package/src/components/WhoHasAccessLight.jsx +2 -1
  96. package/src/components/__snapshots__/ContactSuggestion.spec.jsx.snap +915 -132
  97. package/src/components/__snapshots__/ShareRecipientsInput.spec.jsx.snap +86 -102
  98. package/src/components/autosuggest.styl +21 -36
  99. package/src/helpers/documentType.js +6 -0
  100. package/src/helpers/hooks.js +11 -1
  101. package/src/helpers/link.js +4 -0
  102. package/src/helpers/permissions.js +15 -0
  103. package/src/helpers/recipients.js +21 -0
  104. package/src/helpers/sharings.js +15 -12
  105. package/src/helpers/synchronousJobQueue.js +22 -0
  106. package/src/helpers/synchronousJobQueue.spec.js +75 -0
  107. package/src/index.jsx +1 -0
  108. package/src/queries/queries.js +75 -0
  109. package/src/share.styl +0 -15
  110. package/dist/SharingBanner/helpers/queries.js +0 -12
  111. package/dist/components/ContactsAndGroupsDataLoader.js +0 -50
  112. package/dist/components/Recipient.js +0 -450
  113. package/src/SharingBanner/helpers/queries.js +0 -14
  114. package/src/components/ContactsAndGroupsDataLoader.jsx +0 -30
  115. package/src/components/Recipient.jsx +0 -415
@@ -1,28 +1,13 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
- import _createClass from "@babel/runtime/helpers/createClass";
5
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
6
- import _inherits from "@babel/runtime/helpers/inherits";
7
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
8
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
9
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
10
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
11
-
12
- 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; }
13
-
14
- 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; }
15
-
16
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
17
-
18
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
19
-
20
- import React, { Component } from 'react';
5
+ import React, { useState } from 'react';
21
6
  import PropTypes from 'prop-types';
22
7
  import get from 'lodash/get';
23
- import { withClient } from 'cozy-client';
8
+ import { useClient } from 'cozy-client';
9
+ import { useI18n } from 'cozy-ui/transpiled/react/I18n';
24
10
  import Alerter from 'cozy-ui/transpiled/react/Alerter';
25
- import { translate } from 'cozy-ui/transpiled/react/I18n';
26
11
  import ShareSubmit from './Sharesubmit';
27
12
  import ShareTypeSelect from './Sharetypeselect';
28
13
  import { Group } from '../models';
@@ -58,122 +43,113 @@ var styles = {
58
43
  import { getSuccessMessage } from '../helpers/successMessage';
59
44
  import { getOrCreateFromArray } from '../helpers/contacts';
60
45
  import { isReadOnlySharing } from '../state';
61
- export var ShareByEmail = /*#__PURE__*/function (_Component) {
62
- _inherits(ShareByEmail, _Component);
63
-
64
- var _super = _createSuper(ShareByEmail);
65
-
66
- function ShareByEmail(props) {
67
- var _this;
68
-
69
- _classCallCheck(this, ShareByEmail);
70
-
71
- _this = _super.call(this, props);
72
-
73
- _defineProperty(_assertThisInitialized(_this), "state", _objectSpread({}, _this.initialState));
74
-
75
- _defineProperty(_assertThisInitialized(_this), "reset", function () {
76
- _this.setState(_objectSpread({}, _this.initialState));
77
- });
78
-
79
- _defineProperty(_assertThisInitialized(_this), "onChange", function (value) {
80
- _this.setState(function (state) {
81
- return _objectSpread(_objectSpread({}, state), {}, {
82
- selectedOption: value
46
+ export var ShareByEmail = function ShareByEmail(_ref) {
47
+ var contacts = _ref.contacts,
48
+ groups = _ref.groups,
49
+ document = _ref.document,
50
+ sharingDesc = _ref.sharingDesc,
51
+ onShare = _ref.onShare,
52
+ createContact = _ref.createContact,
53
+ documentType = _ref.documentType,
54
+ currentRecipients = _ref.currentRecipients,
55
+ sharing = _ref.sharing;
56
+ var client = useClient();
57
+
58
+ var _useI18n = useI18n(),
59
+ t = _useI18n.t;
60
+
61
+ var _useState = useState([]),
62
+ _useState2 = _slicedToArray(_useState, 2),
63
+ recipients = _useState2[0],
64
+ setRecipients = _useState2[1];
65
+
66
+ var _useState3 = useState(false),
67
+ _useState4 = _slicedToArray(_useState3, 2),
68
+ loading = _useState4[0],
69
+ setLoading = _useState4[1];
70
+
71
+ var _useState5 = useState(),
72
+ _useState6 = _slicedToArray(_useState5, 2),
73
+ selectedOption = _useState6[0],
74
+ setSelectedOption = _useState6[1];
75
+
76
+ var reset = function reset() {
77
+ setRecipients([]);
78
+ setLoading(false);
79
+ };
80
+
81
+ var onChange = function onChange(value) {
82
+ setSelectedOption(value);
83
+ };
84
+
85
+ var onRecipientPick = function onRecipientPick(recipient) {
86
+ var contactsToAdd;
87
+
88
+ if (recipient._type === Group.doctype) {
89
+ var groupId = recipient.id;
90
+ contactsToAdd = contacts.data.filter(function (contact) {
91
+ var contactGroupIds = get(contact, 'relationships.groups.data', []).map(function (group) {
92
+ return group._id;
83
93
  });
94
+ return contactGroupIds.includes(groupId);
84
95
  });
85
- });
86
-
87
- _defineProperty(_assertThisInitialized(_this), "onSubmit", function () {
88
- _this.sendSharingLink();
89
- });
90
-
91
- _defineProperty(_assertThisInitialized(_this), "onRecipientPick", function (recipient) {
92
- var contactsToAdd;
93
-
94
- if (recipient._type === Group.doctype) {
95
- var groupId = recipient.id;
96
- contactsToAdd = _this.props.contacts.data.filter(function (contact) {
97
- var contactGroupIds = get(contact, 'relationships.groups.data', []).map(function (group) {
98
- return group._id;
99
- });
100
- return contactGroupIds.includes(groupId);
101
- });
102
- } else {
103
- contactsToAdd = [recipient];
104
- }
96
+ } else {
97
+ contactsToAdd = [recipient];
98
+ }
105
99
 
106
- var filtered = contactsToAdd.filter(function (contact) {
107
- return contact.email && contact.email.length > 0 || contact.cozy && contact.cozy.length > 0;
108
- }).filter(function (contact) {
109
- return !_this.state.recipients.find(function (r) {
110
- return r === contact;
111
- });
112
- });
113
-
114
- _this.setState(function (state) {
115
- return _objectSpread(_objectSpread({}, state), {}, {
116
- recipients: [].concat(_toConsumableArray(state.recipients), _toConsumableArray(filtered))
117
- });
100
+ var filtered = contactsToAdd.filter(function (contact) {
101
+ return contact.email && contact.email.length > 0 || contact.cozy && contact.cozy.length > 0;
102
+ }).filter(function (contact) {
103
+ return !recipients.find(function (r) {
104
+ return r === contact;
118
105
  });
119
106
  });
107
+ setRecipients([].concat(_toConsumableArray(recipients), _toConsumableArray(filtered)));
108
+ };
120
109
 
121
- _defineProperty(_assertThisInitialized(_this), "onRecipientRemove", function (recipient) {
122
- var idx = _this.state.recipients.findIndex(function (r) {
123
- return r === recipient;
124
- });
125
-
126
- _this.setState(function (state) {
127
- return _objectSpread(_objectSpread({}, state), {}, {
128
- recipients: [].concat(_toConsumableArray(state.recipients.slice(0, idx)), _toConsumableArray(state.recipients.slice(idx + 1)))
129
- });
130
- });
110
+ var onRecipientRemove = function onRecipientRemove(recipient) {
111
+ var idx = recipients.findIndex(function (r) {
112
+ return r === recipient;
131
113
  });
114
+ setRecipients([].concat(_toConsumableArray(recipients.slice(0, idx)), _toConsumableArray(recipients.slice(idx + 1))));
115
+ };
132
116
 
133
- _defineProperty(_assertThisInitialized(_this), "share", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
134
- var _this$props, document, sharingDesc, onShare, createContact, documentType, client, t, _this$state, recipients, selectedOption, recipientsBefore, contacts, readWriteRecipients, readOnlyRecipients;
117
+ var share = /*#__PURE__*/function () {
118
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
119
+ var recipientsBefore, _contacts, readWriteRecipients, readOnlyRecipients;
135
120
 
136
121
  return _regeneratorRuntime.wrap(function _callee$(_context) {
137
122
  while (1) {
138
123
  switch (_context.prev = _context.next) {
139
124
  case 0:
140
- _this$props = _this.props, document = _this$props.document, sharingDesc = _this$props.sharingDesc, onShare = _this$props.onShare, createContact = _this$props.createContact, documentType = _this$props.documentType, client = _this$props.client, t = _this$props.t;
141
- _this$state = _this.state, recipients = _this$state.recipients, selectedOption = _this$state.selectedOption;
142
-
143
125
  if (!(recipients.length === 0)) {
144
- _context.next = 4;
126
+ _context.next = 2;
145
127
  break;
146
128
  }
147
129
 
148
130
  return _context.abrupt("return");
149
131
 
150
- case 4:
132
+ case 2:
151
133
  // we can't use currentRecipients prop in getSuccessMessage because it may use
152
134
  // the updated prop to count the new recipients
153
- recipientsBefore = _this.props.currentRecipients;
154
-
155
- _this.setState(function (state) {
156
- return _objectSpread(_objectSpread({}, state), {}, {
157
- loading: true
158
- });
159
- });
160
-
161
- _context.prev = 6;
162
- _context.next = 9;
135
+ recipientsBefore = currentRecipients;
136
+ setLoading(true);
137
+ _context.prev = 4;
138
+ _context.next = 7;
163
139
  return getOrCreateFromArray(client, recipients, createContact);
164
140
 
165
- case 9:
166
- contacts = _context.sent;
141
+ case 7:
142
+ _contacts = _context.sent;
167
143
  readWriteRecipients = [];
168
144
  readOnlyRecipients = [];
169
145
 
170
146
  if (selectedOption === 'readOnly') {
171
- readOnlyRecipients = contacts;
147
+ readOnlyRecipients = _contacts;
172
148
  } else {
173
- readWriteRecipients = contacts;
149
+ readWriteRecipients = _contacts;
174
150
  }
175
151
 
176
- _context.next = 15;
152
+ _context.next = 13;
177
153
  return onShare({
178
154
  document: document,
179
155
  recipients: readWriteRecipients,
@@ -182,104 +158,77 @@ export var ShareByEmail = /*#__PURE__*/function (_Component) {
182
158
  openSharing: readWriteRecipients.length > 0
183
159
  });
184
160
 
185
- case 15:
186
- Alerter.success(t.apply(void 0, _toConsumableArray(getSuccessMessage(recipientsBefore, contacts, documentType))));
187
-
188
- _this.reset();
189
-
190
- _context.next = 24;
161
+ case 13:
162
+ Alerter.success(t.apply(void 0, _toConsumableArray(getSuccessMessage(recipientsBefore, _contacts, documentType))));
163
+ reset();
164
+ _context.next = 22;
191
165
  break;
192
166
 
193
- case 19:
194
- _context.prev = 19;
195
- _context.t0 = _context["catch"](6);
167
+ case 17:
168
+ _context.prev = 17;
169
+ _context.t0 = _context["catch"](4);
196
170
  Alerter.error('Error.generic');
197
-
198
- _this.reset();
199
-
171
+ reset();
200
172
  throw _context.t0;
201
173
 
202
- case 24:
174
+ case 22:
203
175
  case "end":
204
176
  return _context.stop();
205
177
  }
206
178
  }
207
- }, _callee, null, [[6, 19]]);
208
- })));
209
-
210
- _defineProperty(_assertThisInitialized(_this), "getSharingOptions", function () {
211
- var _this$props2 = _this.props,
212
- t = _this$props2.t,
213
- sharing = _this$props2.sharing,
214
- document = _this$props2.document;
215
- var isSharingReadOnly = sharing ? isReadOnlySharing(sharing, document._id) : false;
216
- var readWrite = {
217
- value: 'readWrite',
218
- label: t('Share.type.two-way'),
219
- desc: t('Share.type.desc.two-way'),
220
- disabled: false
221
- };
222
- var readOnly = {
223
- value: 'readOnly',
224
- label: t('Share.type.one-way'),
225
- desc: t('Share.type.desc.one-way'),
226
- disabled: false
227
- };
228
- return isSharingReadOnly ? [readOnly] : [readWrite, readOnly];
229
- });
179
+ }, _callee, null, [[4, 17]]);
180
+ }));
230
181
 
231
- _this.initialState = {
232
- recipients: [],
233
- loading: false
182
+ return function share() {
183
+ return _ref2.apply(this, arguments);
234
184
  };
235
- _this.state = _objectSpread({}, _this.initialState);
236
- return _this;
237
- }
238
-
239
- _createClass(ShareByEmail, [{
240
- key: "render",
241
- value: function render() {
242
- var _this2 = this;
243
-
244
- var _this$props3 = this.props,
245
- contacts = _this$props3.contacts,
246
- documentType = _this$props3.documentType,
247
- groups = _this$props3.groups,
248
- t = _this$props3.t;
249
- var recipients = this.state.recipients;
250
- return /*#__PURE__*/React.createElement("div", {
251
- className: styles['coz-form-group']
252
- }, /*#__PURE__*/React.createElement("div", {
253
- className: styles['coz-form']
254
- }, /*#__PURE__*/React.createElement(ShareRecipientsInput, {
255
- label: t("".concat(documentType, ".share.shareByEmail.email")),
256
- placeholder: recipients.length === 0 ? t("".concat(documentType, ".share.shareByEmail.emailPlaceholder")) : '',
257
- onFocus: this.onInputFocus,
258
- onPick: function onPick(recipient) {
259
- return _this2.onRecipientPick(recipient);
260
- },
261
- onRemove: function onRemove(recipient) {
262
- return _this2.onRecipientRemove(recipient);
263
- },
264
- contacts: contacts,
265
- groups: groups,
266
- recipients: recipients
267
- })), /*#__PURE__*/React.createElement("div", {
268
- className: styles['share-type-control']
269
- }, /*#__PURE__*/React.createElement(ShareTypeSelect, {
270
- options: this.getSharingOptions(),
271
- onChange: this.onChange
272
- }), /*#__PURE__*/React.createElement(ShareSubmit, {
273
- label: t("".concat(documentType, ".share.shareByEmail.send")),
274
- onSubmit: this.share,
275
- loading: this.state.loading,
276
- disabled: recipients.length === 0
277
- })));
278
- }
279
- }]);
280
-
281
- return ShareByEmail;
282
- }(Component);
185
+ }();
186
+
187
+ var getSharingOptions = function getSharingOptions() {
188
+ var isSharingReadOnly = sharing ? isReadOnlySharing(sharing, document._id) : false;
189
+ var readWrite = {
190
+ value: 'readWrite',
191
+ label: t('Share.type.two-way'),
192
+ desc: t('Share.type.desc.two-way'),
193
+ disabled: false
194
+ };
195
+ var readOnly = {
196
+ value: 'readOnly',
197
+ label: t('Share.type.one-way'),
198
+ desc: t('Share.type.desc.one-way'),
199
+ disabled: false
200
+ };
201
+ return isSharingReadOnly ? [readOnly] : [readWrite, readOnly];
202
+ };
203
+
204
+ var showShareControl = recipients.length > 0;
205
+ return /*#__PURE__*/React.createElement("div", {
206
+ className: styles['coz-form-group']
207
+ }, /*#__PURE__*/React.createElement("div", {
208
+ className: styles['coz-form']
209
+ }, /*#__PURE__*/React.createElement(ShareRecipientsInput, {
210
+ placeholder: recipients.length === 0 ? t("".concat(documentType, ".share.shareByEmail.emailPlaceholder")) : '',
211
+ onPick: function onPick(recipient) {
212
+ return onRecipientPick(recipient);
213
+ },
214
+ onRemove: function onRemove(recipient) {
215
+ return onRecipientRemove(recipient);
216
+ },
217
+ contacts: contacts,
218
+ groups: groups,
219
+ recipients: recipients
220
+ })), showShareControl && /*#__PURE__*/React.createElement("div", {
221
+ className: styles['share-type-control']
222
+ }, /*#__PURE__*/React.createElement(ShareTypeSelect, {
223
+ options: getSharingOptions(),
224
+ onChange: onChange
225
+ }), /*#__PURE__*/React.createElement(ShareSubmit, {
226
+ label: t("".concat(documentType, ".share.shareByEmail.send")),
227
+ onSubmit: share,
228
+ loading: loading,
229
+ disabled: recipients.length === 0
230
+ })));
231
+ };
283
232
  ShareByEmail.propTypes = {
284
233
  currentRecipients: PropTypes.arrayOf(PropTypes.object),
285
234
  contacts: contactsResponseType.isRequired,
@@ -292,4 +241,4 @@ ShareByEmail.propTypes = {
292
241
  // We can display this component without having created the sharing yet
293
242
  sharing: PropTypes.object
294
243
  };
295
- export default translate()(withClient(ShareByEmail));
244
+ export default ShareByEmail;
@@ -1,11 +1,20 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
3
  import React from 'react';
4
- import { mount } from 'enzyme';
4
+ import { render, fireEvent, waitFor } from '@testing-library/react';
5
5
  import { ShareByEmail } from './ShareByEmail';
6
+ import AppLike from '../../test/AppLike';
7
+ import { act } from 'react-dom/test-utils';
8
+ jest.mock('../helpers/contacts', function () {
9
+ return {
10
+ getOrCreateFromArray: function getOrCreateFromArray(client, recipients) {
11
+ return recipients;
12
+ }
13
+ };
14
+ });
6
15
  describe('ShareByEmailComponent', function () {
7
16
  it('shoud call share if submited', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
8
- var onShare, props, comp;
17
+ var onShare, props, root;
9
18
  return _regeneratorRuntime.wrap(function _callee$(_context) {
10
19
  while (1) {
11
20
  switch (_context.prev = _context.next) {
@@ -15,9 +24,6 @@ describe('ShareByEmailComponent', function () {
15
24
  contacts: {
16
25
  data: []
17
26
  },
18
- t: function t(x) {
19
- return x;
20
- },
21
27
  groups: {
22
28
  data: []
23
29
  },
@@ -29,27 +35,40 @@ describe('ShareByEmailComponent', function () {
29
35
  sharingDesc: 'test',
30
36
  createContact: jest.fn()
31
37
  };
32
- comp = mount( /*#__PURE__*/React.createElement(ShareByEmail, props));
33
- comp.instance().onRecipientPick({
34
- id: 1,
35
- email: 'quentin@cozycloud.cc'
38
+ root = render( /*#__PURE__*/React.createElement(AppLike, null, /*#__PURE__*/React.createElement(ShareByEmail, props)));
39
+ act(function () {
40
+ fireEvent.change(root.getByPlaceholderText('Add contacts or groups'), {
41
+ target: {
42
+ value: 'quentin@cozycloud.cc'
43
+ }
44
+ });
36
45
  });
37
- _context.next = 6;
38
- return comp.instance().share();
39
-
40
- case 6:
41
- expect(onShare).toHaveBeenCalledWith({
42
- description: props.sharingDesc,
43
- document: props.document,
44
- openSharing: true,
45
- readOnlyRecipients: [],
46
- recipients: [{
47
- id: 1,
48
- email: 'quentin@cozycloud.cc'
49
- }]
46
+ act(function () {
47
+ fireEvent.keyPress(root.getByPlaceholderText('Add contacts or groups'), {
48
+ key: 'Enter',
49
+ code: 'Enter',
50
+ charCode: 13
51
+ });
52
+ });
53
+ act(function () {
54
+ fireEvent.click(root.getByRole('button', {
55
+ name: 'Send'
56
+ }));
57
+ });
58
+ _context.next = 8;
59
+ return waitFor(function () {
60
+ expect(onShare).toHaveBeenCalledWith({
61
+ description: props.sharingDesc,
62
+ document: props.document,
63
+ openSharing: true,
64
+ readOnlyRecipients: [],
65
+ recipients: [{
66
+ email: 'quentin@cozycloud.cc'
67
+ }]
68
+ });
50
69
  });
51
70
 
52
- case 7:
71
+ case 8:
53
72
  case "end":
54
73
  return _context.stop();
55
74
  }