cozy-sharing 38.1.3 → 38.1.5
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 +8 -0
- package/dist/DoctypeContact.js +2 -6
- package/dist/components/ContactSuggestion.js +4 -4
- package/dist/components/ShareAutosuggest.js +3 -3
- package/dist/components/ShareModal/EditableSharingModal.js +2 -2
- package/dist/components/SharedDrive/useSharedDrive.js +2 -2
- package/dist/helpers/recipients.js +2 -2
- package/dist/helpers/share.js +6 -6
- package/dist/models.js +14 -3
- package/dist/queries/queries.js +4 -4
- package/dist/suggestionMatchers.js +2 -2
- package/package.json +3 -4
- package/src/DoctypeContact.js +1 -4
- package/src/components/ContactSuggestion.jsx +10 -5
- package/src/components/ShareAutosuggest.jsx +3 -3
- package/src/components/ShareModal/EditableSharingModal.jsx +2 -2
- package/src/components/SharedDrive/useSharedDrive.js +2 -2
- package/src/helpers/recipients.js +2 -2
- package/src/helpers/share.js +11 -6
- package/src/models.js +18 -8
- package/src/queries/queries.js +4 -4
- package/src/suggestionMatchers.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [38.1.5](https://github.com/cozy/cozy-libs/compare/cozy-sharing@38.1.4...cozy-sharing@38.1.5) (2026-09-30)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package cozy-sharing
|
|
9
|
+
|
|
10
|
+
## [38.1.4](https://github.com/cozy/cozy-libs/compare/cozy-sharing@38.1.3...cozy-sharing@38.1.4) (2026-09-30)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package cozy-sharing
|
|
13
|
+
|
|
6
14
|
## [38.1.3](https://github.com/cozy/cozy-libs/compare/cozy-sharing@38.1.2...cozy-sharing@38.1.3) (2026-09-23)
|
|
7
15
|
|
|
8
16
|
### Bug Fixes
|
package/dist/DoctypeContact.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { getInitials as clientGetInitials, getDisplayName as clientGetDisplayName } from 'cozy-client/dist/models/contact';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var isContact = function isContact(candidate) {
|
|
2
|
+
export var isContact = function isContact(candidate) {
|
|
5
3
|
return candidate._type === 'io.cozy.contacts';
|
|
6
4
|
};
|
|
7
|
-
|
|
8
5
|
export var getInitials = function getInitials(contactOrRecipient) {
|
|
9
6
|
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
10
7
|
|
|
@@ -30,5 +27,4 @@ export var getDisplayName = function getDisplayName(contact) {
|
|
|
30
27
|
// @todo Extract to RecipientModel ?
|
|
31
28
|
return contact.public_name || contact.displayName || contact.name || contact.email || defaultValue;
|
|
32
29
|
}
|
|
33
|
-
};
|
|
34
|
-
export default DoctypeContact;
|
|
30
|
+
};
|
|
@@ -5,7 +5,7 @@ import ListItem from 'cozy-ui/transpiled/react/ListItem';
|
|
|
5
5
|
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
|
|
6
6
|
import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
|
|
7
7
|
import { useI18n } from 'twake-i18n';
|
|
8
|
-
import {
|
|
8
|
+
import { DOCTYPE_GROUPS, contactPropType, groupPropType, getDisplayName } from '../models';
|
|
9
9
|
import { GroupAvatar } from './Avatar/GroupAvatar';
|
|
10
10
|
import { MemberAvatar } from './Avatar/MemberAvatar';
|
|
11
11
|
export var ContactSuggestion = function ContactSuggestion(_ref) {
|
|
@@ -14,7 +14,7 @@ export var ContactSuggestion = function ContactSuggestion(_ref) {
|
|
|
14
14
|
var _useI18n = useI18n(),
|
|
15
15
|
t = _useI18n.t;
|
|
16
16
|
|
|
17
|
-
if (contactOrGroup._type ===
|
|
17
|
+
if (contactOrGroup._type === DOCTYPE_GROUPS) {
|
|
18
18
|
return /*#__PURE__*/React.createElement(ListItem, {
|
|
19
19
|
button: true
|
|
20
20
|
}, /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(GroupAvatar, {
|
|
@@ -45,7 +45,7 @@ var newUnknownContactProptypes = PropTypes.shape({
|
|
|
45
45
|
email: PropTypes.string.isRequired
|
|
46
46
|
});
|
|
47
47
|
ContactSuggestion.propTypes = {
|
|
48
|
-
contactOrGroup: PropTypes.oneOfType([
|
|
49
|
-
contacts: PropTypes.arrayOf(
|
|
48
|
+
contactOrGroup: PropTypes.oneOfType([contactPropType, groupPropType, newUnknownContactProptypes]).isRequired,
|
|
49
|
+
contacts: PropTypes.arrayOf(contactPropType)
|
|
50
50
|
};
|
|
51
51
|
export default ContactSuggestion;
|
|
@@ -10,7 +10,7 @@ import { MemberAvatar } from './Avatar/MemberAvatar';
|
|
|
10
10
|
import ContactSuggestion from './ContactSuggestion';
|
|
11
11
|
import { isContactToBeCreated } from '../helpers/contacts';
|
|
12
12
|
import { extractEmails, validateEmail } from '../helpers/email';
|
|
13
|
-
import { getDisplayName,
|
|
13
|
+
import { getDisplayName, DOCTYPE_CONTACTS, DOCTYPE_GROUPS } from '../models';
|
|
14
14
|
var styles = {
|
|
15
15
|
"container": "autosuggest__container___1Yro7",
|
|
16
16
|
"suggestionsContainer": "autosuggest__suggestionsContainer___3EDuG",
|
|
@@ -76,7 +76,7 @@ var ShareAutosuggest = function ShareAutosuggest(_ref) {
|
|
|
76
76
|
} else if (enableCreateContact && validateEmail(value)) {
|
|
77
77
|
setSuggestions([{
|
|
78
78
|
email: value,
|
|
79
|
-
_type:
|
|
79
|
+
_type: DOCTYPE_CONTACTS
|
|
80
80
|
}]);
|
|
81
81
|
} else {
|
|
82
82
|
setSuggestions([]);
|
|
@@ -181,7 +181,7 @@ var ShareAutosuggest = function ShareAutosuggest(_ref) {
|
|
|
181
181
|
return /*#__PURE__*/React.createElement("div", {
|
|
182
182
|
className: styles['recipientsContainer']
|
|
183
183
|
}, recipients.map(function (recipient, idx) {
|
|
184
|
-
var isContactGroup = recipient._type ===
|
|
184
|
+
var isContactGroup = recipient._type === DOCTYPE_GROUPS;
|
|
185
185
|
var name = getDisplayName(recipient);
|
|
186
186
|
return /*#__PURE__*/React.createElement(Chip, {
|
|
187
187
|
id: "recipient_".concat(idx),
|
|
@@ -9,7 +9,7 @@ import flag from 'cozy-flags';
|
|
|
9
9
|
import minilog from 'cozy-minilog';
|
|
10
10
|
import { useFetchDocumentPath } from '../../hooks/useFetchDocumentPath';
|
|
11
11
|
import { useSharingContext } from '../../hooks/useSharingContext';
|
|
12
|
-
import {
|
|
12
|
+
import { DOCTYPE_CONTACTS } from '../../models';
|
|
13
13
|
import { ShareModal } from '../ShareModal';
|
|
14
14
|
export var EditableSharingModal = function EditableSharingModal(_ref) {
|
|
15
15
|
var document = _ref.document,
|
|
@@ -34,7 +34,7 @@ export var EditableSharingModal = function EditableSharingModal(_ref) {
|
|
|
34
34
|
|
|
35
35
|
return /*#__PURE__*/React.createElement(ShareModal, _extends({
|
|
36
36
|
createContact: function createContact(contact) {
|
|
37
|
-
return client.create(
|
|
37
|
+
return client.create(DOCTYPE_CONTACTS, contact);
|
|
38
38
|
},
|
|
39
39
|
document: document,
|
|
40
40
|
documentType: documentType,
|
|
@@ -5,7 +5,7 @@ import { useState } from 'react';
|
|
|
5
5
|
import { useClient } from 'cozy-client';
|
|
6
6
|
import { getOrCreateFromArray } from '../../helpers/contacts';
|
|
7
7
|
import { usePendingRecipients } from '../../hooks/usePendingRecipients';
|
|
8
|
-
import {
|
|
8
|
+
import { DOCTYPE_CONTACTS } from '../../models';
|
|
9
9
|
export var useSharedDrive = function useSharedDrive() {
|
|
10
10
|
var client = useClient();
|
|
11
11
|
|
|
@@ -25,7 +25,7 @@ export var useSharedDrive = function useSharedDrive() {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
var createContact = function createContact(contact) {
|
|
28
|
-
return client.create(
|
|
28
|
+
return client.create(DOCTYPE_CONTACTS, contact);
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
var onCreate = /*#__PURE__*/function () {
|
|
@@ -6,7 +6,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
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
8
|
import flag from 'cozy-flags';
|
|
9
|
-
import {
|
|
9
|
+
import { DOCTYPE_GROUPS } from '../models';
|
|
10
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) {
|
|
@@ -66,7 +66,7 @@ export var hasReachRecipientsLimit = function hasReachRecipientsLimit(current, n
|
|
|
66
66
|
export var spreadGroupAndMergeRecipients = function spreadGroupAndMergeRecipients(recipients, newRecipient) {
|
|
67
67
|
var contactsToAdd;
|
|
68
68
|
|
|
69
|
-
if (newRecipient._type ===
|
|
69
|
+
if (newRecipient._type === DOCTYPE_GROUPS) {
|
|
70
70
|
contactsToAdd = newRecipient.members;
|
|
71
71
|
} else {
|
|
72
72
|
contactsToAdd = [newRecipient];
|
package/dist/helpers/share.js
CHANGED
|
@@ -5,10 +5,10 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
5
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
6
|
|
|
7
7
|
import { models } from 'cozy-client';
|
|
8
|
-
import {
|
|
8
|
+
import { DOCTYPE_CONTACTS, DOCTYPE_GROUPS, isContact, getDisplayName } from '../models';
|
|
9
9
|
export var countNewRecipients = function countNewRecipients(currentRecipients, newRecipients) {
|
|
10
10
|
var newRecipientsNotAlreadyIncluded = newRecipients.filter(function (recipient) {
|
|
11
|
-
if (
|
|
11
|
+
if (isContact(recipient)) {
|
|
12
12
|
var email = models.contact.getPrimaryEmail(recipient);
|
|
13
13
|
var cozyUrl = models.contact.getPrimaryCozy(recipient);
|
|
14
14
|
return !currentRecipients.find(function (r) {
|
|
@@ -19,7 +19,7 @@ export var countNewRecipients = function countNewRecipients(currentRecipients, n
|
|
|
19
19
|
return true;
|
|
20
20
|
});
|
|
21
21
|
return newRecipientsNotAlreadyIncluded.reduce(function (acc, recipient) {
|
|
22
|
-
if (recipient._type ===
|
|
22
|
+
if (recipient._type === DOCTYPE_GROUPS) {
|
|
23
23
|
return _objectSpread(_objectSpread({}, acc), {}, {
|
|
24
24
|
group: acc.group + 1
|
|
25
25
|
});
|
|
@@ -36,9 +36,9 @@ export var countNewRecipients = function countNewRecipients(currentRecipients, n
|
|
|
36
36
|
export var getSuccessMessage = function getSuccessMessage(recipientsBefore, recipientsAfter, documentType) {
|
|
37
37
|
if (recipientsAfter.length === 1) {
|
|
38
38
|
var recipient = recipientsAfter[0];
|
|
39
|
-
var email =
|
|
39
|
+
var email = isContact(recipient) ? models.contact.getPrimaryEmail(recipient) : recipient.email;
|
|
40
40
|
var cozyUrl = models.contact.getPrimaryCozy(recipient);
|
|
41
|
-
var isContactGroup = recipient._type ===
|
|
41
|
+
var isContactGroup = recipient._type === DOCTYPE_GROUPS;
|
|
42
42
|
|
|
43
43
|
if (isContactGroup) {
|
|
44
44
|
return ["".concat(documentType, ".share.shareByEmail.singleGroupSuccess"), {
|
|
@@ -89,7 +89,7 @@ export var getErrorMessage = function getErrorMessage(_ref) {
|
|
|
89
89
|
if (detail.startsWith('A group member cannot be added as they are already in')) {
|
|
90
90
|
var sharingRights = t("Share.errors.sharingRights.".concat(selectedOption === 'readOnly' ? 'readWrite' : 'readOnly'));
|
|
91
91
|
|
|
92
|
-
if (recipients.length === 1 && recipients[0]._type ===
|
|
92
|
+
if (recipients.length === 1 && recipients[0]._type === DOCTYPE_CONTACTS) {
|
|
93
93
|
return ['Share.errors.contactAlreadyInSharing', {
|
|
94
94
|
smart_count: recipients.length,
|
|
95
95
|
contactName: getDisplayName(recipients[0]),
|
package/dist/models.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
export var DOCTYPE_CONTACTS = 'io.cozy.contacts';
|
|
3
|
+
export var DOCTYPE_GROUPS = 'io.cozy.contacts.groups';
|
|
4
|
+
export var contactPropType = PropTypes.shape({
|
|
5
|
+
_id: PropTypes.string.isRequired,
|
|
6
|
+
_type: PropTypes.string.isRequired
|
|
7
|
+
});
|
|
8
|
+
export var groupPropType = PropTypes.shape({
|
|
9
|
+
_id: PropTypes.string.isRequired,
|
|
10
|
+
_type: PropTypes.string.isRequired,
|
|
11
|
+
name: PropTypes.string.isRequired,
|
|
12
|
+
trashed: PropTypes.bool
|
|
13
|
+
});
|
|
14
|
+
export { isContact, getInitials, getDisplayName } from './DoctypeContact';
|
package/dist/queries/queries.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Q, fetchPolicies } from 'cozy-client';
|
|
2
|
-
import {
|
|
2
|
+
import { DOCTYPE_CONTACTS, DOCTYPE_GROUPS } from '../models';
|
|
3
3
|
var DEFAULT_CACHE_TIMEOUT_QUERIES = 9 * 60 * 1000;
|
|
4
4
|
var defaultFetchPolicy = fetchPolicies.olderThan(DEFAULT_CACHE_TIMEOUT_QUERIES);
|
|
5
5
|
export var buildSharingsByIdQuery = function buildSharingsByIdQuery(sharingId) {
|
|
@@ -13,7 +13,7 @@ export var buildSharingsByIdQuery = function buildSharingsByIdQuery(sharingId) {
|
|
|
13
13
|
};
|
|
14
14
|
export var buildReachableContactsQuery = function buildReachableContactsQuery() {
|
|
15
15
|
return {
|
|
16
|
-
definition: Q(
|
|
16
|
+
definition: Q(DOCTYPE_CONTACTS).where({
|
|
17
17
|
_id: {
|
|
18
18
|
$gt: null
|
|
19
19
|
}
|
|
@@ -46,7 +46,7 @@ export var buildReachableContactsQuery = function buildReachableContactsQuery()
|
|
|
46
46
|
};
|
|
47
47
|
export var buildContactGroupsQuery = function buildContactGroupsQuery() {
|
|
48
48
|
return {
|
|
49
|
-
definition: Q(
|
|
49
|
+
definition: Q(DOCTYPE_GROUPS),
|
|
50
50
|
options: {
|
|
51
51
|
as: "io.cozy.contacts.groups",
|
|
52
52
|
fetchPolicy: defaultFetchPolicy
|
|
@@ -55,7 +55,7 @@ export var buildContactGroupsQuery = function buildContactGroupsQuery() {
|
|
|
55
55
|
};
|
|
56
56
|
export var buildUnreachableContactsWithGroupsQuery = function buildUnreachableContactsWithGroupsQuery() {
|
|
57
57
|
return {
|
|
58
|
-
definition: Q(
|
|
58
|
+
definition: Q(DOCTYPE_CONTACTS).where({
|
|
59
59
|
_id: {
|
|
60
60
|
$gt: null
|
|
61
61
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DOCTYPE_GROUPS } from './models';
|
|
2
2
|
var removeDiacritics;
|
|
3
3
|
|
|
4
4
|
try {
|
|
@@ -50,7 +50,7 @@ var cozyUrlMatch = function cozyUrlMatch(input, contact) {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
var groupNameMatch = function groupNameMatch(input, contactOrGroup) {
|
|
53
|
-
if (contactOrGroup._type !==
|
|
53
|
+
if (contactOrGroup._type !== DOCTYPE_GROUPS) return false;
|
|
54
54
|
var normalizedInput = normalizeLowercase(input);
|
|
55
55
|
return normalizeLowercase(contactOrGroup.name).includes(normalizedInput);
|
|
56
56
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-sharing",
|
|
3
|
-
"version": "38.1.
|
|
3
|
+
"version": "38.1.5",
|
|
4
4
|
"description": "Provides sharing login for React applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Cozy",
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@cozy/minilog": "^1.0.0",
|
|
32
32
|
"classnames": "^2.5.1",
|
|
33
|
-
"cozy-doctypes": "^1.99.1",
|
|
34
33
|
"date-fns": "2.30.0",
|
|
35
34
|
"lodash": "^4.17.21",
|
|
36
35
|
"react-autosuggest": "^10.1.0",
|
|
@@ -59,7 +58,7 @@
|
|
|
59
58
|
"cozy-intent": "^2.31.1",
|
|
60
59
|
"cozy-minilog": "^3.10.1",
|
|
61
60
|
"cozy-ui": "^140.5.0",
|
|
62
|
-
"cozy-ui-plus": "^13.0.
|
|
61
|
+
"cozy-ui-plus": "^13.0.9",
|
|
63
62
|
"jest": "30.3.0",
|
|
64
63
|
"jest-environment-jsdom": "30.3.0",
|
|
65
64
|
"react": "16.12.0",
|
|
@@ -85,5 +84,5 @@
|
|
|
85
84
|
"sideEffects": [
|
|
86
85
|
"*.css"
|
|
87
86
|
],
|
|
88
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "2a289aae5b8bcd1104daeed4855b4aad34473aa8"
|
|
89
88
|
}
|
package/src/DoctypeContact.js
CHANGED
|
@@ -2,9 +2,8 @@ import {
|
|
|
2
2
|
getInitials as clientGetInitials,
|
|
3
3
|
getDisplayName as clientGetDisplayName
|
|
4
4
|
} from 'cozy-client/dist/models/contact'
|
|
5
|
-
import { Contact as DoctypeContact } from 'cozy-doctypes'
|
|
6
5
|
|
|
7
|
-
const isContact = candidate => {
|
|
6
|
+
export const isContact = candidate => {
|
|
8
7
|
return candidate._type === 'io.cozy.contacts'
|
|
9
8
|
}
|
|
10
9
|
export const getInitials = (contactOrRecipient, defaultValue = '') => {
|
|
@@ -43,5 +42,3 @@ export const getDisplayName = (contact, defaultValue = '') => {
|
|
|
43
42
|
)
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
export default DoctypeContact
|
|
@@ -7,14 +7,19 @@ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
|
|
|
7
7
|
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
|
|
8
8
|
import { useI18n } from 'twake-i18n'
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
DOCTYPE_GROUPS,
|
|
12
|
+
contactPropType,
|
|
13
|
+
groupPropType,
|
|
14
|
+
getDisplayName
|
|
15
|
+
} from '../models'
|
|
11
16
|
import { GroupAvatar } from './Avatar/GroupAvatar'
|
|
12
17
|
import { MemberAvatar } from './Avatar/MemberAvatar'
|
|
13
18
|
|
|
14
19
|
export const ContactSuggestion = ({ contactOrGroup }) => {
|
|
15
20
|
const { t } = useI18n()
|
|
16
21
|
|
|
17
|
-
if (contactOrGroup._type ===
|
|
22
|
+
if (contactOrGroup._type === DOCTYPE_GROUPS) {
|
|
18
23
|
return (
|
|
19
24
|
<ListItem button>
|
|
20
25
|
<ListItemIcon>
|
|
@@ -50,11 +55,11 @@ const newUnknownContactProptypes = PropTypes.shape({
|
|
|
50
55
|
|
|
51
56
|
ContactSuggestion.propTypes = {
|
|
52
57
|
contactOrGroup: PropTypes.oneOfType([
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
contactPropType,
|
|
59
|
+
groupPropType,
|
|
55
60
|
newUnknownContactProptypes
|
|
56
61
|
]).isRequired,
|
|
57
|
-
contacts: PropTypes.arrayOf(
|
|
62
|
+
contacts: PropTypes.arrayOf(contactPropType)
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
export default ContactSuggestion
|
|
@@ -10,7 +10,7 @@ import { MemberAvatar } from './Avatar/MemberAvatar'
|
|
|
10
10
|
import ContactSuggestion from './ContactSuggestion'
|
|
11
11
|
import { isContactToBeCreated } from '../helpers/contacts'
|
|
12
12
|
import { extractEmails, validateEmail } from '../helpers/email'
|
|
13
|
-
import { getDisplayName,
|
|
13
|
+
import { getDisplayName, DOCTYPE_CONTACTS, DOCTYPE_GROUPS } from '../models'
|
|
14
14
|
import styles from '../styles/autosuggest.styl'
|
|
15
15
|
import { contactOrGroupMatch } from '../suggestionMatchers'
|
|
16
16
|
|
|
@@ -53,7 +53,7 @@ const ShareAutosuggest = ({
|
|
|
53
53
|
setSuggestions([
|
|
54
54
|
{
|
|
55
55
|
email: value,
|
|
56
|
-
_type:
|
|
56
|
+
_type: DOCTYPE_CONTACTS
|
|
57
57
|
}
|
|
58
58
|
])
|
|
59
59
|
} else {
|
|
@@ -152,7 +152,7 @@ const ShareAutosuggest = ({
|
|
|
152
152
|
const renderInput = inputProps => (
|
|
153
153
|
<div className={styles['recipientsContainer']}>
|
|
154
154
|
{recipients.map((recipient, idx) => {
|
|
155
|
-
const isContactGroup = recipient._type ===
|
|
155
|
+
const isContactGroup = recipient._type === DOCTYPE_GROUPS
|
|
156
156
|
const name = getDisplayName(recipient)
|
|
157
157
|
return (
|
|
158
158
|
<Chip
|
|
@@ -7,7 +7,7 @@ import minilog from 'cozy-minilog'
|
|
|
7
7
|
|
|
8
8
|
import { useFetchDocumentPath } from '../../hooks/useFetchDocumentPath'
|
|
9
9
|
import { useSharingContext } from '../../hooks/useSharingContext'
|
|
10
|
-
import {
|
|
10
|
+
import { DOCTYPE_CONTACTS } from '../../models'
|
|
11
11
|
import { ShareModal } from '../ShareModal'
|
|
12
12
|
|
|
13
13
|
export const EditableSharingModal = ({ document, recipients, ...rest }) => {
|
|
@@ -30,7 +30,7 @@ export const EditableSharingModal = ({ document, recipients, ...rest }) => {
|
|
|
30
30
|
|
|
31
31
|
return (
|
|
32
32
|
<ShareModal
|
|
33
|
-
createContact={contact => client.create(
|
|
33
|
+
createContact={contact => client.create(DOCTYPE_CONTACTS, contact)}
|
|
34
34
|
document={document}
|
|
35
35
|
documentType={documentType}
|
|
36
36
|
hasSharedChild={
|
|
@@ -4,7 +4,7 @@ import { useClient } from 'cozy-client'
|
|
|
4
4
|
|
|
5
5
|
import { getOrCreateFromArray } from '../../helpers/contacts'
|
|
6
6
|
import { usePendingRecipients } from '../../hooks/usePendingRecipients'
|
|
7
|
-
import {
|
|
7
|
+
import { DOCTYPE_CONTACTS } from '../../models'
|
|
8
8
|
|
|
9
9
|
export const useSharedDrive = () => {
|
|
10
10
|
const client = useClient()
|
|
@@ -21,7 +21,7 @@ export const useSharedDrive = () => {
|
|
|
21
21
|
setSharedDriveName(event.target.value)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const createContact = contact => client.create(
|
|
24
|
+
const createContact = contact => client.create(DOCTYPE_CONTACTS, contact)
|
|
25
25
|
|
|
26
26
|
const onCreate = async () => {
|
|
27
27
|
const contacts = await getOrCreateFromArray(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import flag from 'cozy-flags'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { DOCTYPE_GROUPS } from '../models'
|
|
4
4
|
|
|
5
5
|
export const DEFAULT_DISPLAY_NAME = 'Share.contacts.defaultDisplayName'
|
|
6
6
|
|
|
@@ -60,7 +60,7 @@ export const hasReachRecipientsLimit = (current, next) => {
|
|
|
60
60
|
*/
|
|
61
61
|
export const spreadGroupAndMergeRecipients = (recipients, newRecipient) => {
|
|
62
62
|
let contactsToAdd
|
|
63
|
-
if (newRecipient._type ===
|
|
63
|
+
if (newRecipient._type === DOCTYPE_GROUPS) {
|
|
64
64
|
contactsToAdd = newRecipient.members
|
|
65
65
|
} else {
|
|
66
66
|
contactsToAdd = [newRecipient]
|
package/src/helpers/share.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { models } from 'cozy-client'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
DOCTYPE_CONTACTS,
|
|
5
|
+
DOCTYPE_GROUPS,
|
|
6
|
+
isContact,
|
|
7
|
+
getDisplayName
|
|
8
|
+
} from '../models'
|
|
4
9
|
|
|
5
10
|
export const countNewRecipients = (currentRecipients, newRecipients) => {
|
|
6
11
|
const newRecipientsNotAlreadyIncluded = newRecipients.filter(recipient => {
|
|
7
|
-
if (
|
|
12
|
+
if (isContact(recipient)) {
|
|
8
13
|
const email = models.contact.getPrimaryEmail(recipient)
|
|
9
14
|
const cozyUrl = models.contact.getPrimaryCozy(recipient)
|
|
10
15
|
return !currentRecipients.find(
|
|
@@ -18,7 +23,7 @@ export const countNewRecipients = (currentRecipients, newRecipients) => {
|
|
|
18
23
|
|
|
19
24
|
return newRecipientsNotAlreadyIncluded.reduce(
|
|
20
25
|
(acc, recipient) => {
|
|
21
|
-
if (recipient._type ===
|
|
26
|
+
if (recipient._type === DOCTYPE_GROUPS) {
|
|
22
27
|
return {
|
|
23
28
|
...acc,
|
|
24
29
|
group: acc.group + 1
|
|
@@ -44,11 +49,11 @@ export const getSuccessMessage = (
|
|
|
44
49
|
) => {
|
|
45
50
|
if (recipientsAfter.length === 1) {
|
|
46
51
|
const recipient = recipientsAfter[0]
|
|
47
|
-
const email =
|
|
52
|
+
const email = isContact(recipient)
|
|
48
53
|
? models.contact.getPrimaryEmail(recipient)
|
|
49
54
|
: recipient.email
|
|
50
55
|
const cozyUrl = models.contact.getPrimaryCozy(recipient)
|
|
51
|
-
const isContactGroup = recipient._type ===
|
|
56
|
+
const isContactGroup = recipient._type === DOCTYPE_GROUPS
|
|
52
57
|
|
|
53
58
|
if (isContactGroup) {
|
|
54
59
|
return [
|
|
@@ -125,7 +130,7 @@ export const getErrorMessage = ({
|
|
|
125
130
|
}`
|
|
126
131
|
)
|
|
127
132
|
|
|
128
|
-
if (recipients.length === 1 && recipients[0]._type ===
|
|
133
|
+
if (recipients.length === 1 && recipients[0]._type === DOCTYPE_CONTACTS) {
|
|
129
134
|
return [
|
|
130
135
|
'Share.errors.contactAlreadyInSharing',
|
|
131
136
|
{
|
package/src/models.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
|
|
3
|
+
export const DOCTYPE_CONTACTS = 'io.cozy.contacts'
|
|
4
|
+
export const DOCTYPE_GROUPS = 'io.cozy.contacts.groups'
|
|
5
|
+
|
|
6
|
+
export const contactPropType = PropTypes.shape({
|
|
7
|
+
_id: PropTypes.string.isRequired,
|
|
8
|
+
_type: PropTypes.string.isRequired
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export const groupPropType = PropTypes.shape({
|
|
12
|
+
_id: PropTypes.string.isRequired,
|
|
13
|
+
_type: PropTypes.string.isRequired,
|
|
14
|
+
name: PropTypes.string.isRequired,
|
|
15
|
+
trashed: PropTypes.bool
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
export { isContact, getInitials, getDisplayName } from './DoctypeContact'
|
package/src/queries/queries.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Q, fetchPolicies } from 'cozy-client'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { DOCTYPE_CONTACTS, DOCTYPE_GROUPS } from '../models'
|
|
4
4
|
|
|
5
5
|
const DEFAULT_CACHE_TIMEOUT_QUERIES = 9 * 60 * 1000
|
|
6
6
|
|
|
@@ -17,7 +17,7 @@ export const buildSharingsByIdQuery = sharingId => ({
|
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
export const buildReachableContactsQuery = () => ({
|
|
20
|
-
definition: Q(
|
|
20
|
+
definition: Q(DOCTYPE_CONTACTS)
|
|
21
21
|
.where({
|
|
22
22
|
_id: {
|
|
23
23
|
$gt: null
|
|
@@ -52,7 +52,7 @@ export const buildReachableContactsQuery = () => ({
|
|
|
52
52
|
})
|
|
53
53
|
|
|
54
54
|
export const buildContactGroupsQuery = () => ({
|
|
55
|
-
definition: Q(
|
|
55
|
+
definition: Q(DOCTYPE_GROUPS),
|
|
56
56
|
options: {
|
|
57
57
|
as: `io.cozy.contacts.groups`,
|
|
58
58
|
fetchPolicy: defaultFetchPolicy
|
|
@@ -60,7 +60,7 @@ export const buildContactGroupsQuery = () => ({
|
|
|
60
60
|
})
|
|
61
61
|
|
|
62
62
|
export const buildUnreachableContactsWithGroupsQuery = () => ({
|
|
63
|
-
definition: Q(
|
|
63
|
+
definition: Q(DOCTYPE_CONTACTS)
|
|
64
64
|
.where({
|
|
65
65
|
_id: {
|
|
66
66
|
$gt: null
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DOCTYPE_GROUPS } from './models'
|
|
2
2
|
|
|
3
3
|
let removeDiacritics
|
|
4
4
|
try {
|
|
@@ -36,7 +36,7 @@ const cozyUrlMatch = (input, contact) => {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
const groupNameMatch = (input, contactOrGroup) => {
|
|
39
|
-
if (contactOrGroup._type !==
|
|
39
|
+
if (contactOrGroup._type !== DOCTYPE_GROUPS) return false
|
|
40
40
|
const normalizedInput = normalizeLowercase(input)
|
|
41
41
|
return normalizeLowercase(contactOrGroup.name).includes(normalizedInput)
|
|
42
42
|
}
|