cozy-sharing 12.2.0 → 13.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/.storybook/preview.jsx +1 -0
- package/CHANGELOG.md +40 -0
- package/dist/components/Avatar/AvatarList.js +13 -2
- package/dist/components/Avatar/AvatarList.spec.js +11 -6
- package/dist/components/Avatar/AvatarList.stories.js +13 -1
- package/dist/components/Avatar/GroupAvatar.js +4 -2
- package/dist/components/ContactSuggestion.js +7 -3
- package/dist/components/ContactSuggestion.spec.js +7 -1
- package/dist/components/Recipient/GroupRecipient.js +14 -7
- package/dist/components/Recipient/GroupRecipientDetail.js +4 -2
- package/dist/components/Recipient/GroupRecipientDetailWithAccess.js +9 -11
- package/dist/components/Recipient/GroupRecipientDetailWithoutAccess.js +8 -4
- package/dist/components/Recipient/GroupRecipientPermissions.js +3 -6
- package/dist/components/Recipient/MemberRecipient.js +1 -2
- package/dist/components/Recipient/MemberRecipientPermissions.js +1 -1
- package/dist/components/ShareAutosuggest.js +16 -9
- package/dist/components/ShareAutosuggest.spec.js +38 -13
- package/dist/components/ShareAutosuggest.stories.js +61 -0
- package/dist/components/ShareByEmail.js +15 -15
- package/dist/components/ShareByEmail.spec.js +0 -6
- package/dist/components/ShareDialogCozyToCozy.js +1 -5
- package/dist/components/ShareDialogCozyToCozy.spec.js +0 -61
- package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +1 -5
- package/dist/components/ShareDialogTwoStepsConfirmationContainer.spec.js +0 -61
- package/dist/components/ShareModal/EditableSharingModal.js +3 -10
- package/dist/components/ShareModal/EditableSharingModal.spec.js +0 -6
- package/dist/components/ShareModal.js +1 -8
- package/dist/components/ShareRecipientsInput.js +46 -49
- package/dist/components/ShareRecipientsInput.spec.js +120 -144
- package/dist/helpers/contacts.js +12 -1
- package/dist/helpers/recipients.js +16 -9
- package/dist/helpers/successMessage.js +58 -16
- package/dist/helpers/successMessage.spec.js +122 -57
- package/dist/queries/queries.js +37 -5
- package/dist/styles/autosuggest.styl +2 -1
- package/dist/stylesheet.css +2 -1
- package/locales/en.json +23 -10
- package/locales/fr.json +23 -8
- package/package.json +4 -4
- package/src/components/Avatar/AvatarList.jsx +33 -14
- package/src/components/Avatar/AvatarList.spec.jsx +11 -6
- package/src/components/Avatar/AvatarList.stories.jsx +19 -1
- package/src/components/Avatar/GroupAvatar.jsx +2 -2
- package/src/components/ContactSuggestion.jsx +9 -3
- package/src/components/ContactSuggestion.spec.jsx +10 -1
- package/src/components/Recipient/GroupRecipient.jsx +17 -10
- package/src/components/Recipient/GroupRecipientDetail.jsx +5 -2
- package/src/components/Recipient/GroupRecipientDetailWithAccess.jsx +9 -14
- package/src/components/Recipient/GroupRecipientDetailWithoutAccess.jsx +8 -3
- package/src/components/Recipient/GroupRecipientPermissions.jsx +3 -8
- package/src/components/Recipient/MemberRecipient.jsx +4 -3
- package/src/components/Recipient/MemberRecipientPermissions.jsx +1 -1
- package/src/components/ShareAutosuggest.jsx +16 -11
- package/src/components/ShareAutosuggest.spec.jsx +31 -10
- package/src/components/ShareAutosuggest.stories.jsx +63 -0
- package/src/components/ShareByEmail.jsx +11 -11
- package/src/components/ShareByEmail.spec.jsx +0 -4
- package/src/components/ShareDialogCozyToCozy.jsx +0 -4
- package/src/components/ShareDialogCozyToCozy.spec.jsx +0 -67
- package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +0 -4
- package/src/components/ShareDialogTwoStepsConfirmationContainer.spec.jsx +0 -67
- package/src/components/ShareModal/EditableSharingModal.jsx +3 -21
- package/src/components/ShareModal/EditableSharingModal.spec.jsx +0 -2
- package/src/components/ShareModal.jsx +1 -7
- package/src/components/ShareRecipientsInput.jsx +84 -52
- package/src/components/ShareRecipientsInput.spec.jsx +140 -145
- package/src/helpers/contacts.js +8 -0
- package/src/helpers/recipients.js +24 -15
- package/src/helpers/successMessage.js +71 -21
- package/src/helpers/successMessage.spec.js +129 -69
- package/src/queries/queries.js +36 -5
- package/src/styles/autosuggest.styl +2 -1
- package/test/AppLike.jsx +6 -3
|
@@ -2,7 +2,16 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
3
|
import { render, screen } from '@testing-library/react';
|
|
4
4
|
import React from 'react';
|
|
5
|
+
import { createMockClient } from 'cozy-client';
|
|
6
|
+
import flag from 'cozy-flags';
|
|
5
7
|
import ShareRecipientsInput from './ShareRecipientsInput';
|
|
8
|
+
import AppLike from './SharingBanner/test/AppLike';
|
|
9
|
+
jest.mock('cozy-flags', function () {
|
|
10
|
+
return {
|
|
11
|
+
__esModule: true,
|
|
12
|
+
default: jest.fn()
|
|
13
|
+
};
|
|
14
|
+
});
|
|
6
15
|
jest.mock('./ShareAutosuggest', function () {
|
|
7
16
|
return {
|
|
8
17
|
__esModule: true,
|
|
@@ -16,7 +25,7 @@ jest.mock('./ShareAutosuggest', function () {
|
|
|
16
25
|
} else {
|
|
17
26
|
return /*#__PURE__*/React.createElement("li", {
|
|
18
27
|
key: contactOrGroup.id
|
|
19
|
-
}, contactOrGroup.name);
|
|
28
|
+
}, contactOrGroup.name, " - ", contactOrGroup.members.length, " members");
|
|
20
29
|
}
|
|
21
30
|
}));
|
|
22
31
|
}
|
|
@@ -25,14 +34,31 @@ jest.mock('./ShareAutosuggest', function () {
|
|
|
25
34
|
describe('ShareRecipientsInput component', function () {
|
|
26
35
|
var setup = function setup(_ref2) {
|
|
27
36
|
var contacts = _ref2.contacts,
|
|
28
|
-
contactGroups = _ref2.contactGroups
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
contactGroups = _ref2.contactGroups,
|
|
38
|
+
unreachableContact = _ref2.unreachableContact;
|
|
39
|
+
var mockClient = createMockClient({
|
|
40
|
+
queries: {
|
|
41
|
+
'io.cozy.contacts/reachable': {
|
|
42
|
+
doctype: 'io.cozy.contacts',
|
|
43
|
+
data: contacts
|
|
44
|
+
},
|
|
45
|
+
'io.cozy.contacts.groups/by-ids/fe86af20-c6c5': {
|
|
46
|
+
doctype: 'io.cozy.contacts.groups',
|
|
47
|
+
data: contactGroups
|
|
48
|
+
},
|
|
49
|
+
'io.cozy.contacts/unreachable-with-groups': {
|
|
50
|
+
doctype: 'io.cozy.contacts',
|
|
51
|
+
data: unreachableContact
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
render( /*#__PURE__*/React.createElement(AppLike, {
|
|
56
|
+
client: mockClient
|
|
57
|
+
}, /*#__PURE__*/React.createElement(ShareRecipientsInput, {
|
|
32
58
|
onPick: function onPick() {},
|
|
33
59
|
onRemove: function onRemove() {},
|
|
34
60
|
placeholder: "Enter recipients here"
|
|
35
|
-
}));
|
|
61
|
+
})));
|
|
36
62
|
};
|
|
37
63
|
|
|
38
64
|
it('should include groups and contacts when are loaded', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
@@ -40,54 +66,44 @@ describe('ShareRecipientsInput component', function () {
|
|
|
40
66
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
41
67
|
while (1) switch (_context.prev = _context.next) {
|
|
42
68
|
case 0:
|
|
43
|
-
contacts = {
|
|
44
|
-
id: '
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
data: [{
|
|
66
|
-
_id: 'fe86af20-c6c5',
|
|
67
|
-
_type: 'io.cozy.contacts.groups'
|
|
68
|
-
}]
|
|
69
|
-
}
|
|
69
|
+
contacts = [{
|
|
70
|
+
id: 'df563cc4-6440',
|
|
71
|
+
_id: 'df563cc4-6440',
|
|
72
|
+
_type: 'io.cozy.contacts',
|
|
73
|
+
name: {
|
|
74
|
+
givenName: 'Michale',
|
|
75
|
+
familyName: 'Russel'
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
id: '5a3b4ccf-c257',
|
|
79
|
+
_id: '5a3b4ccf-c257',
|
|
80
|
+
_type: 'io.cozy.contacts',
|
|
81
|
+
name: {
|
|
82
|
+
givenName: 'Teagan',
|
|
83
|
+
familyName: 'Wolf'
|
|
84
|
+
},
|
|
85
|
+
relationships: {
|
|
86
|
+
groups: {
|
|
87
|
+
data: [{
|
|
88
|
+
_id: 'fe86af20-c6c5',
|
|
89
|
+
_type: 'io.cozy.contacts.groups'
|
|
90
|
+
}]
|
|
70
91
|
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
contactGroups = {
|
|
74
|
-
id: '
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
name: "The Night's Watch",
|
|
80
|
-
_id: 'fe86af20-c6c5',
|
|
81
|
-
_type: 'io.cozy.contacts.groups'
|
|
82
|
-
}]
|
|
83
|
-
};
|
|
92
|
+
}
|
|
93
|
+
}];
|
|
94
|
+
contactGroups = [{
|
|
95
|
+
id: 'fe86af20-c6c5',
|
|
96
|
+
name: "The Night's Watch",
|
|
97
|
+
_id: 'fe86af20-c6c5',
|
|
98
|
+
_type: 'io.cozy.contacts.groups'
|
|
99
|
+
}];
|
|
84
100
|
setup({
|
|
85
101
|
contacts: contacts,
|
|
86
102
|
contactGroups: contactGroups
|
|
87
103
|
});
|
|
88
104
|
expect(screen.getByText('Michale Russel')).toBeInTheDocument();
|
|
89
105
|
expect(screen.getByText('Teagan Wolf')).toBeInTheDocument();
|
|
90
|
-
expect(screen.getByText("The Night's Watch")).toBeInTheDocument();
|
|
106
|
+
expect(screen.getByText("The Night's Watch - 1 members")).toBeInTheDocument();
|
|
91
107
|
|
|
92
108
|
case 6:
|
|
93
109
|
case "end":
|
|
@@ -95,116 +111,76 @@ describe('ShareRecipientsInput component', function () {
|
|
|
95
111
|
}
|
|
96
112
|
}, _callee);
|
|
97
113
|
})));
|
|
98
|
-
it('should include
|
|
99
|
-
var contacts, contactGroups;
|
|
114
|
+
it('should include unreachable members when flag sharing.show-recipient-groups is activated', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
115
|
+
var contacts, contactGroups, unreachableContact;
|
|
100
116
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
101
117
|
while (1) switch (_context2.prev = _context2.next) {
|
|
102
118
|
case 0:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
119
|
+
flag.mockReturnValue(true);
|
|
120
|
+
contacts = [{
|
|
121
|
+
id: 'df563cc4-6440',
|
|
122
|
+
_id: 'df563cc4-6440',
|
|
123
|
+
_type: 'io.cozy.contacts',
|
|
124
|
+
name: {
|
|
125
|
+
givenName: 'Michale',
|
|
126
|
+
familyName: 'Russel'
|
|
127
|
+
}
|
|
128
|
+
}, {
|
|
129
|
+
id: '5a3b4ccf-c257',
|
|
130
|
+
_id: '5a3b4ccf-c257',
|
|
131
|
+
_type: 'io.cozy.contacts',
|
|
132
|
+
name: {
|
|
133
|
+
givenName: 'Teagan',
|
|
134
|
+
familyName: 'Wolf'
|
|
135
|
+
},
|
|
136
|
+
relationships: {
|
|
137
|
+
groups: {
|
|
138
|
+
data: [{
|
|
139
|
+
_id: 'fe86af20-c6c5',
|
|
140
|
+
_type: 'io.cozy.contacts.groups'
|
|
141
|
+
}]
|
|
114
142
|
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
143
|
+
}
|
|
144
|
+
}];
|
|
145
|
+
contactGroups = [{
|
|
146
|
+
id: 'fe86af20-c6c5',
|
|
147
|
+
name: "The Night's Watch",
|
|
148
|
+
_id: 'fe86af20-c6c5',
|
|
149
|
+
_type: 'io.cozy.contacts.groups'
|
|
150
|
+
}];
|
|
151
|
+
unreachableContact = [{
|
|
152
|
+
id: 'df532cc4-6560',
|
|
153
|
+
_id: 'df532cc4-6560',
|
|
154
|
+
_type: 'io.cozy.contacts',
|
|
155
|
+
name: {
|
|
156
|
+
givenName: 'Tony',
|
|
157
|
+
familyName: 'Stark'
|
|
158
|
+
},
|
|
159
|
+
relationships: {
|
|
160
|
+
groups: {
|
|
161
|
+
data: [{
|
|
162
|
+
_id: 'fe86af20-c6c5',
|
|
163
|
+
_type: 'io.cozy.contacts.groups'
|
|
164
|
+
}]
|
|
130
165
|
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
contactGroups = {
|
|
134
|
-
id: 'groups',
|
|
135
|
-
fetchStatus: 'loaded',
|
|
136
|
-
hasMore: false,
|
|
137
|
-
data: [{
|
|
138
|
-
id: 'fe86af20-c6c5',
|
|
139
|
-
name: "The Night's Watch",
|
|
140
|
-
_id: 'fe86af20-c6c5',
|
|
141
|
-
_type: 'io.cozy.contacts.groups'
|
|
142
|
-
}]
|
|
143
|
-
};
|
|
166
|
+
}
|
|
167
|
+
}];
|
|
144
168
|
setup({
|
|
145
169
|
contacts: contacts,
|
|
146
|
-
contactGroups: contactGroups
|
|
170
|
+
contactGroups: contactGroups,
|
|
171
|
+
unreachableContact: unreachableContact
|
|
147
172
|
});
|
|
148
173
|
expect(screen.getByText('Michale Russel')).toBeInTheDocument();
|
|
149
|
-
expect(screen.getByText('Teagan Wolf')).toBeInTheDocument();
|
|
150
|
-
|
|
174
|
+
expect(screen.getByText('Teagan Wolf')).toBeInTheDocument(); // 3 members because cozy-client replay the query with the new data
|
|
175
|
+
// so the unreachableContact is added to the reachable contact query
|
|
176
|
+
// TODO: improve createMockClient to handle this case
|
|
151
177
|
|
|
152
|
-
|
|
178
|
+
expect(screen.getByText("The Night's Watch - 3 members")).toBeInTheDocument();
|
|
179
|
+
|
|
180
|
+
case 8:
|
|
153
181
|
case "end":
|
|
154
182
|
return _context2.stop();
|
|
155
183
|
}
|
|
156
184
|
}, _callee2);
|
|
157
185
|
})));
|
|
158
|
-
it('should include groups only if they have more than one member', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
159
|
-
var contacts, contactGroups;
|
|
160
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
161
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
162
|
-
case 0:
|
|
163
|
-
contacts = {
|
|
164
|
-
id: 'contacts',
|
|
165
|
-
fetchStatus: 'loaded',
|
|
166
|
-
hasMore: false,
|
|
167
|
-
data: [{
|
|
168
|
-
id: 'df563cc4-6440',
|
|
169
|
-
_id: 'df563cc4-6440',
|
|
170
|
-
_type: 'io.cozy.contacts',
|
|
171
|
-
name: {
|
|
172
|
-
givenName: 'Michale',
|
|
173
|
-
familyName: 'Russel'
|
|
174
|
-
}
|
|
175
|
-
}, {
|
|
176
|
-
id: '5a3b4ccf-c257',
|
|
177
|
-
_id: '5a3b4ccf-c257',
|
|
178
|
-
_type: 'io.cozy.contacts',
|
|
179
|
-
name: {
|
|
180
|
-
givenName: 'Teagan',
|
|
181
|
-
familyName: 'Wolf'
|
|
182
|
-
}
|
|
183
|
-
}]
|
|
184
|
-
};
|
|
185
|
-
contactGroups = {
|
|
186
|
-
id: 'groups',
|
|
187
|
-
fetchStatus: 'loaded',
|
|
188
|
-
hasMore: false,
|
|
189
|
-
data: [{
|
|
190
|
-
id: 'fe86af20-c6c5',
|
|
191
|
-
name: "The Night's Watch",
|
|
192
|
-
_id: 'fe86af20-c6c5',
|
|
193
|
-
_type: 'io.cozy.contacts.groups'
|
|
194
|
-
}]
|
|
195
|
-
};
|
|
196
|
-
setup({
|
|
197
|
-
contacts: contacts,
|
|
198
|
-
contactGroups: contactGroups
|
|
199
|
-
});
|
|
200
|
-
expect(screen.getByText('Michale Russel')).toBeInTheDocument();
|
|
201
|
-
expect(screen.getByText('Teagan Wolf')).toBeInTheDocument();
|
|
202
|
-
expect(screen.queryByText("The Night's Watch")).toBeNull();
|
|
203
|
-
|
|
204
|
-
case 6:
|
|
205
|
-
case "end":
|
|
206
|
-
return _context3.stop();
|
|
207
|
-
}
|
|
208
|
-
}, _callee3);
|
|
209
|
-
})));
|
|
210
186
|
});
|
package/dist/helpers/contacts.js
CHANGED
|
@@ -91,4 +91,15 @@ export var getOrCreateFromArray = /*#__PURE__*/function () {
|
|
|
91
91
|
return function getOrCreateFromArray(_x, _x2, _x3) {
|
|
92
92
|
return _ref.apply(this, arguments);
|
|
93
93
|
};
|
|
94
|
-
}();
|
|
94
|
+
}();
|
|
95
|
+
export var getContactsFromGroupId = function getContactsFromGroupId() {
|
|
96
|
+
var contacts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
97
|
+
var groupId = arguments.length > 1 ? arguments[1] : undefined;
|
|
98
|
+
return contacts.filter(function (contact) {
|
|
99
|
+
var _contact$relationship;
|
|
100
|
+
|
|
101
|
+
return (_contact$relationship = contact.relationships) === null || _contact$relationship === void 0 || (_contact$relationship = _contact$relationship.groups) === null || _contact$relationship === void 0 || (_contact$relationship = _contact$relationship.data) === null || _contact$relationship === void 0 ? void 0 : _contact$relationship.some(function (group) {
|
|
102
|
+
return group._id === groupId;
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
};
|
|
@@ -5,9 +5,9 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
5
5
|
|
|
6
6
|
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; }
|
|
7
7
|
|
|
8
|
-
import get from 'lodash/get';
|
|
9
8
|
import flag from 'cozy-flags';
|
|
10
9
|
import { Group } from '../models';
|
|
10
|
+
export var DEFAULT_DISPLAY_NAME = 'Share.contacts.defaultDisplayName';
|
|
11
11
|
export var filterAndReworkRecipients = function filterAndReworkRecipients(recipients, previousRecipients) {
|
|
12
12
|
return recipients.filter(function (recipient) {
|
|
13
13
|
return recipient.status !== 'owner';
|
|
@@ -56,23 +56,18 @@ export var hasReachRecipientsLimit = function hasReachRecipientsLimit(current, n
|
|
|
56
56
|
};
|
|
57
57
|
/**
|
|
58
58
|
* Merges the recipients list with a new recipient and their associated contacts.
|
|
59
|
+
* Only used when flag sharing.show-recipient-groups is not enabled.
|
|
59
60
|
* @param {object[]} recipients - The list of recipients.
|
|
60
61
|
* @param {object} recipient - The new recipient.
|
|
61
62
|
* @param {object[]} contacts - The list of contacts.
|
|
62
63
|
* @returns {object[]} - The merged recipients list.
|
|
63
64
|
*/
|
|
64
65
|
|
|
65
|
-
export var spreadGroupAndMergeRecipients = function spreadGroupAndMergeRecipients(recipients, newRecipient
|
|
66
|
+
export var spreadGroupAndMergeRecipients = function spreadGroupAndMergeRecipients(recipients, newRecipient) {
|
|
66
67
|
var contactsToAdd;
|
|
67
68
|
|
|
68
69
|
if (newRecipient._type === Group.doctype) {
|
|
69
|
-
|
|
70
|
-
contactsToAdd = contacts.data.filter(function (contact) {
|
|
71
|
-
var contactGroupIds = get(contact, 'relationships.groups.data', []).map(function (group) {
|
|
72
|
-
return group._id;
|
|
73
|
-
});
|
|
74
|
-
return contactGroupIds.includes(groupId);
|
|
75
|
-
});
|
|
70
|
+
contactsToAdd = newRecipient.members;
|
|
76
71
|
} else {
|
|
77
72
|
contactsToAdd = [newRecipient];
|
|
78
73
|
}
|
|
@@ -88,4 +83,16 @@ export var spreadGroupAndMergeRecipients = function spreadGroupAndMergeRecipient
|
|
|
88
83
|
};
|
|
89
84
|
export var mergeRecipients = function mergeRecipients(recipients, newRecipient) {
|
|
90
85
|
return [].concat(_toConsumableArray(recipients), [newRecipient]);
|
|
86
|
+
};
|
|
87
|
+
export var getGroupRecipientSecondaryText = function getGroupRecipientSecondaryText(_ref) {
|
|
88
|
+
var nbMember = _ref.nbMember,
|
|
89
|
+
nbMemberReady = _ref.nbMemberReady,
|
|
90
|
+
t = _ref.t,
|
|
91
|
+
isUserInsideMembers = _ref.isUserInsideMembers;
|
|
92
|
+
var memberCount = nbMember === nbMemberReady ? nbMember : [nbMemberReady, nbMember].join('/');
|
|
93
|
+
var secondary = t('GroupRecipient.secondary', {
|
|
94
|
+
memberCount: memberCount,
|
|
95
|
+
smart_count: nbMember
|
|
96
|
+
});
|
|
97
|
+
return secondary + (isUserInsideMembers ? " (".concat(t('GroupRecipient.secondary_you'), ")") : '');
|
|
91
98
|
};
|
|
@@ -1,36 +1,78 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
|
|
3
|
+
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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
1
7
|
import { models } from 'cozy-client';
|
|
2
|
-
import { Contact } from '../models';
|
|
8
|
+
import { Contact, Group } from '../models';
|
|
3
9
|
export var countNewRecipients = function countNewRecipients(currentRecipients, newRecipients) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
var newRecipientsNotAlreadyIncluded = newRecipients.filter(function (recipient) {
|
|
11
|
+
if (Contact.isContact(recipient)) {
|
|
12
|
+
var email = models.contact.getPrimaryEmail(recipient);
|
|
13
|
+
var cozyUrl = models.contact.getPrimaryCozy(recipient);
|
|
14
|
+
return !currentRecipients.find(function (r) {
|
|
15
|
+
return email && r.email && r.email === email || cozyUrl && r.instance && r.instance === cozyUrl;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return true;
|
|
20
|
+
});
|
|
21
|
+
return newRecipientsNotAlreadyIncluded.reduce(function (acc, recipient) {
|
|
22
|
+
if (recipient._type === Group.doctype) {
|
|
23
|
+
return _objectSpread(_objectSpread({}, acc), {}, {
|
|
24
|
+
group: acc.group + 1
|
|
25
|
+
});
|
|
26
|
+
} else {
|
|
27
|
+
return _objectSpread(_objectSpread({}, acc), {}, {
|
|
28
|
+
contact: acc.contact + 1
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}, {
|
|
32
|
+
group: 0,
|
|
33
|
+
contact: 0
|
|
34
|
+
});
|
|
11
35
|
};
|
|
12
36
|
export var getSuccessMessage = function getSuccessMessage(recipientsBefore, recipientsAfter, documentType) {
|
|
13
37
|
if (recipientsAfter.length === 1) {
|
|
14
38
|
var recipient = recipientsAfter[0];
|
|
15
39
|
var email = Contact.isContact(recipient) ? models.contact.getPrimaryEmail(recipient) : recipient.email;
|
|
16
40
|
var cozyUrl = models.contact.getPrimaryCozy(recipient);
|
|
41
|
+
var isContactGroup = recipient._type === Group.doctype;
|
|
17
42
|
|
|
18
|
-
if (
|
|
19
|
-
return ["".concat(documentType, ".share.shareByEmail.
|
|
43
|
+
if (isContactGroup) {
|
|
44
|
+
return ["".concat(documentType, ".share.shareByEmail.singleGroupSuccess"), {
|
|
45
|
+
groupName: recipient.name
|
|
46
|
+
}];
|
|
47
|
+
} else if (email) {
|
|
48
|
+
return ["".concat(documentType, ".share.shareByEmail.singleContactSuccess"), {
|
|
20
49
|
email: email
|
|
21
50
|
}];
|
|
22
51
|
} else if (cozyUrl) {
|
|
23
|
-
return ["".concat(documentType, ".share.shareByEmail.
|
|
52
|
+
return ["".concat(documentType, ".share.shareByEmail.singleContactSuccess"), {
|
|
24
53
|
email: cozyUrl
|
|
25
54
|
}];
|
|
26
55
|
} else {
|
|
27
|
-
return ["".concat(documentType, ".share.shareByEmail.
|
|
28
|
-
|
|
56
|
+
return ["".concat(documentType, ".share.shareByEmail.contactSuccess"), {
|
|
57
|
+
smart_count: 1
|
|
29
58
|
}];
|
|
30
59
|
}
|
|
31
60
|
} else {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
61
|
+
var count = countNewRecipients(recipientsBefore, recipientsAfter);
|
|
62
|
+
|
|
63
|
+
if (count.contact > 0 && count.group > 0) {
|
|
64
|
+
return ["".concat(documentType, ".share.shareByEmail.contactAndGroupSuccess"), {
|
|
65
|
+
nbContact: count.contact,
|
|
66
|
+
nbGroup: count.group
|
|
67
|
+
}];
|
|
68
|
+
} else if (count.group > 0) {
|
|
69
|
+
return ["".concat(documentType, ".share.shareByEmail.groupSuccess"), {
|
|
70
|
+
smart_count: count.group
|
|
71
|
+
}];
|
|
72
|
+
} else {
|
|
73
|
+
return ["".concat(documentType, ".share.shareByEmail.contactSuccess"), {
|
|
74
|
+
smart_count: count.contact
|
|
75
|
+
}];
|
|
76
|
+
}
|
|
35
77
|
}
|
|
36
78
|
};
|