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.
- package/CHANGELOG.md +69 -0
- package/dist/SharedRecipients.js +1 -1
- package/dist/SharedStatus.js +1 -1
- package/dist/SharingBanner/hooks/useSharingInfos.js +1 -1
- package/dist/SharingDetailsModal.js +1 -1
- package/dist/SharingOwnerAvatar.js +1 -1
- package/dist/SharingProvider.js +21 -8
- package/dist/components/ContactSuggestion.js +15 -27
- package/dist/components/EditLinkPermissionDialog.js +72 -0
- package/dist/components/EditLinkPermissionDialog.spec.js +48 -0
- package/dist/components/EditableSharingModal.js +15 -62
- package/dist/components/{AvatarPlusX.js → Recipient/AvatarPlusX.js} +1 -1
- package/dist/components/{Identity.js → Recipient/Identity.js} +17 -16
- package/dist/components/Recipient/LinkRecipient.js +72 -0
- package/dist/components/Recipient/LinkRecipientPermissions.js +159 -0
- package/dist/components/Recipient/OwnerIdentity.js +44 -0
- package/dist/components/Recipient/Recipient.js +72 -0
- package/dist/components/{Recipient.spec.js → Recipient/Recipient.spec.js} +4 -45
- package/dist/components/Recipient/RecipientAvatar.js +33 -0
- package/dist/components/Recipient/RecipientConfirm.js +63 -0
- package/dist/components/Recipient/RecipientPermissions.js +126 -0
- package/dist/components/Recipient/RecipientPlusX.js +45 -0
- package/dist/components/Recipient/RecipientStatus.js +64 -0
- package/dist/components/Recipient/RecipientWithoutStatus.js +45 -0
- package/dist/components/Recipient/RecipientsAvatars.js +100 -0
- package/dist/components/{RecipientsAvatars.spec.js → Recipient/RecipientsAvatars.spec.js} +43 -2
- package/dist/components/{recipient.styl → Recipient/recipient.styl} +6 -2
- package/dist/components/ShareAutosuggest.js +176 -252
- package/dist/components/ShareAutosuggest.spec.js +3 -2
- package/dist/components/ShareByEmail.js +142 -193
- package/dist/components/ShareByEmail.spec.js +42 -23
- package/dist/components/ShareByLink.js +251 -357
- package/dist/components/ShareDialogCozyToCozy.js +16 -4
- package/dist/components/ShareDialogCozyToCozy.spec.js +12 -1
- package/dist/components/ShareDialogOnlyByLink.js +23 -10
- package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +7 -7
- package/dist/components/ShareModal.js +5 -1
- package/dist/components/ShareRecipientsInput.js +44 -128
- package/dist/components/WhoHasAccess.js +43 -5
- package/dist/components/WhoHasAccessLight.js +3 -19
- package/dist/components/autosuggest.styl +21 -36
- package/dist/helpers/documentType.js +6 -0
- package/dist/helpers/hooks.js +8 -1
- package/dist/helpers/link.js +5 -0
- package/dist/helpers/permissions.js +8 -0
- package/dist/helpers/recipients.js +24 -0
- package/dist/helpers/sharings.js +72 -53
- package/dist/helpers/synchronousJobQueue.js +67 -0
- package/dist/helpers/synchronousJobQueue.spec.js +97 -0
- package/dist/index.js +2 -1
- package/dist/queries/queries.js +72 -0
- package/dist/share.styl +0 -15
- package/dist/stylesheet.css +67 -92
- package/locales/en.json +29 -41
- package/locales/fr.json +26 -39
- package/package.json +10 -10
- package/src/SharedRecipients.jsx +1 -1
- package/src/SharedStatus.jsx +1 -1
- package/src/SharingBanner/hooks/useSharingInfos.jsx +1 -1
- package/src/SharingDetailsModal.jsx +1 -1
- package/src/SharingOwnerAvatar.jsx +1 -1
- package/src/SharingProvider.jsx +17 -4
- package/src/components/ContactSuggestion.jsx +25 -10
- package/src/components/EditLinkPermissionDialog.jsx +89 -0
- package/src/components/EditLinkPermissionDialog.spec.jsx +52 -0
- package/src/components/EditableSharingModal.jsx +58 -100
- package/src/components/{AvatarPlusX.jsx → Recipient/AvatarPlusX.jsx} +1 -1
- package/src/components/{Identity.jsx → Recipient/Identity.jsx} +0 -0
- package/src/components/Recipient/LinkRecipient.jsx +59 -0
- package/src/components/Recipient/LinkRecipientPermissions.jsx +157 -0
- package/src/components/Recipient/OwnerIdentity.jsx +20 -0
- package/src/components/Recipient/Recipient.jsx +79 -0
- package/src/components/{Recipient.spec.jsx → Recipient/Recipient.spec.jsx} +4 -42
- package/src/components/Recipient/RecipientAvatar.jsx +38 -0
- package/src/components/Recipient/RecipientConfirm.jsx +37 -0
- package/src/components/Recipient/RecipientPermissions.jsx +114 -0
- package/src/components/Recipient/RecipientPlusX.jsx +28 -0
- package/src/components/Recipient/RecipientStatus.jsx +48 -0
- package/src/components/Recipient/RecipientWithoutStatus.jsx +21 -0
- package/src/components/Recipient/RecipientsAvatars.jsx +108 -0
- package/src/components/{RecipientsAvatars.spec.jsx → Recipient/RecipientsAvatars.spec.jsx} +43 -2
- package/src/components/{recipient.styl → Recipient/recipient.styl} +6 -2
- package/src/components/ShareAutosuggest.jsx +136 -127
- package/src/components/ShareAutosuggest.spec.jsx +12 -8
- package/src/components/ShareByEmail.jsx +65 -90
- package/src/components/ShareByEmail.spec.jsx +39 -11
- package/src/components/ShareByLink.jsx +146 -238
- package/src/components/ShareDialogCozyToCozy.jsx +14 -2
- package/src/components/ShareDialogCozyToCozy.spec.jsx +8 -1
- package/src/components/ShareDialogOnlyByLink.jsx +30 -13
- package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +5 -5
- package/src/components/ShareModal.jsx +5 -1
- package/src/components/ShareRecipientsInput.jsx +30 -44
- package/src/components/WhoHasAccess.jsx +85 -27
- package/src/components/WhoHasAccessLight.jsx +2 -1
- package/src/components/__snapshots__/ContactSuggestion.spec.jsx.snap +915 -132
- package/src/components/__snapshots__/ShareRecipientsInput.spec.jsx.snap +86 -102
- package/src/components/autosuggest.styl +21 -36
- package/src/helpers/documentType.js +6 -0
- package/src/helpers/hooks.js +11 -1
- package/src/helpers/link.js +4 -0
- package/src/helpers/permissions.js +15 -0
- package/src/helpers/recipients.js +21 -0
- package/src/helpers/sharings.js +15 -12
- package/src/helpers/synchronousJobQueue.js +22 -0
- package/src/helpers/synchronousJobQueue.spec.js +75 -0
- package/src/index.jsx +1 -0
- package/src/queries/queries.js +75 -0
- package/src/share.styl +0 -15
- package/dist/SharingBanner/helpers/queries.js +0 -12
- package/dist/components/ContactsAndGroupsDataLoader.js +0 -50
- package/dist/components/Recipient.js +0 -450
- package/src/SharingBanner/helpers/queries.js +0 -14
- package/src/components/ContactsAndGroupsDataLoader.jsx +0 -30
- 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
|
|
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 {
|
|
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 =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
134
|
-
|
|
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 =
|
|
126
|
+
_context.next = 2;
|
|
145
127
|
break;
|
|
146
128
|
}
|
|
147
129
|
|
|
148
130
|
return _context.abrupt("return");
|
|
149
131
|
|
|
150
|
-
case
|
|
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 =
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
|
166
|
-
|
|
141
|
+
case 7:
|
|
142
|
+
_contacts = _context.sent;
|
|
167
143
|
readWriteRecipients = [];
|
|
168
144
|
readOnlyRecipients = [];
|
|
169
145
|
|
|
170
146
|
if (selectedOption === 'readOnly') {
|
|
171
|
-
readOnlyRecipients =
|
|
147
|
+
readOnlyRecipients = _contacts;
|
|
172
148
|
} else {
|
|
173
|
-
readWriteRecipients =
|
|
149
|
+
readWriteRecipients = _contacts;
|
|
174
150
|
}
|
|
175
151
|
|
|
176
|
-
_context.next =
|
|
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
|
|
186
|
-
Alerter.success(t.apply(void 0, _toConsumableArray(getSuccessMessage(recipientsBefore,
|
|
187
|
-
|
|
188
|
-
|
|
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
|
|
194
|
-
_context.prev =
|
|
195
|
-
_context.t0 = _context["catch"](
|
|
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
|
|
174
|
+
case 22:
|
|
203
175
|
case "end":
|
|
204
176
|
return _context.stop();
|
|
205
177
|
}
|
|
206
178
|
}
|
|
207
|
-
}, _callee, null, [[
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
loading: false
|
|
182
|
+
return function share() {
|
|
183
|
+
return _ref2.apply(this, arguments);
|
|
234
184
|
};
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
|
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 {
|
|
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,
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
|
71
|
+
case 8:
|
|
53
72
|
case "end":
|
|
54
73
|
return _context.stop();
|
|
55
74
|
}
|