cozy-sharing 13.1.2 → 13.3.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/locales/en.json CHANGED
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "create-cozy": "Create my cozy",
32
32
  "members": {
33
- "count": "1 member |||| %{smart_count} members",
33
+ "count": "%{smart_count} member |||| %{smart_count} members",
34
34
  "others": "and 1 other… |||| and %{smart_count} others…",
35
35
  "otherContacts": "other contact |||| other contacts"
36
36
  },
@@ -79,6 +79,7 @@
79
79
  "errors": {
80
80
  "errors": {
81
81
  "groupMemberAlreadyInSharing": "%{groupName} members have already been invited with %{sharingRights} rights. It is not possible to invite the same contact twice with different rights. |||| Contacts have already been invited with %{sharingRights} rights. It is not possible to invite the same contact twice with different rights.",
82
+ "contactAlreadyInSharing": "%{contactName} has already been invited in a group with %{sharingRights} rights. It is not possible to invite the same contact twice with different rights. |||| Contacts have already been invited with %{sharingRights} rights. It is not possible to invite the same contact twice with different rights.",
82
83
  "sharingRights": {
83
84
  "readOnly": "read",
84
85
  "readWrite": "write"
@@ -400,6 +401,10 @@
400
401
  },
401
402
  "GroupRecipientDetail": {
402
403
  "subtitle": "Managed by %{ownerName}",
404
+ "empty": {
405
+ "content": "Your contact group is empty! Quickly add members to start sharing your valuable documents with them!",
406
+ "action": "Open Contacts"
407
+ },
403
408
  "withAccess": {
404
409
  "title": "Access to item"
405
410
  },
package/locales/fr.json CHANGED
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "create-cozy": "Créer mon Cozy",
32
32
  "members": {
33
- "count": "1 membre |||| %{smart_count} membres",
33
+ "count": "%{smart_count} membre |||| %{smart_count} membres",
34
34
  "others": "et 1 autre… |||| et %{smart_count} autres…",
35
35
  "otherContacts": "autre contact |||| autres contacts"
36
36
  },
@@ -78,6 +78,7 @@
78
78
  },
79
79
  "errors": {
80
80
  "groupMemberAlreadyInSharing": "Des membres de %{groupName} ont déjà été invités avec des droits de %{sharingRights}. Impossible d’inviter 2 fois le même contact avec des droits différents. |||| Des contacts ont déjà été invités avec des droits de %{sharingRights}. Impossible d’inviter 2 fois le même contact avec des droits différents.",
81
+ "contactAlreadyInSharing": "%{contactName} a déjà été invité dans un groupe avec des droits de %{sharingRights}. Impossible d’inviter 2 fois le même contact avec des droits différents. |||| Des contacts ont déjà été invités avec des droits de %{sharingRights}. Impossible d’inviter 2 fois le même contact avec des droits différents.",
81
82
  "sharingRights": {
82
83
  "readOnly": "lecture",
83
84
  "readWrite": "modification"
@@ -398,6 +399,10 @@
398
399
  },
399
400
  "GroupRecipientDetail": {
400
401
  "subtitle": "Géré par %{ownerName}",
402
+ "empty": {
403
+ "content": "Votre groupe de contacts est vide ! Ajoutez rapidement des membres pour commencer à leur partager vos précieux documents !",
404
+ "action": "Ouvrir Contacts"
405
+ },
401
406
  "withAccess": {
402
407
  "title": "Accès à l’élément"
403
408
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-sharing",
3
- "version": "13.1.2",
3
+ "version": "13.3.0",
4
4
  "description": "Provides sharing login for React applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -71,5 +71,5 @@
71
71
  "sideEffects": [
72
72
  "*.css"
73
73
  ],
74
- "gitHead": "9fc3693859a59637e1bfb34d8a69f67e168a3811"
74
+ "gitHead": "ffc77c3e7df6b4c206a3532359aead2722c54487"
75
75
  }
@@ -1,6 +1,9 @@
1
1
  import React from 'react'
2
2
 
3
+ import { useClient, generateWebLink } from 'cozy-client'
4
+ import Buttons from 'cozy-ui/transpiled/react/Buttons'
3
5
  import { Dialog } from 'cozy-ui/transpiled/react/CozyDialogs'
6
+ import Empty from 'cozy-ui/transpiled/react/Empty'
4
7
  import Typography from 'cozy-ui/transpiled/react/Typography'
5
8
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
6
9
 
@@ -8,6 +11,7 @@ import { GroupRecipientDetailWithAccess } from './GroupRecipientDetailWithAccess
8
11
  import { GroupRecipientDetailWithoutAccess } from './GroupRecipientDetailWithoutAccess'
9
12
 
10
13
  const GroupRecipientDetail = ({ name, owner, members, onClose, isOwner }) => {
14
+ const client = useClient()
11
15
  const { t } = useI18n()
12
16
  const withAccess = members.filter(
13
17
  member => !['revoked', 'mail-not-sent'].includes(member.status)
@@ -17,6 +21,12 @@ const GroupRecipientDetail = ({ name, owner, members, onClose, isOwner }) => {
17
21
  )
18
22
 
19
23
  const ownerName = owner.public_name
24
+ const contactsLink = generateWebLink({
25
+ cozyUrl: client.getStackClient().uri,
26
+ slug: 'contacts',
27
+ pathname: '/',
28
+ subDomainType: client.getInstanceOptions().subdomain
29
+ })
20
30
 
21
31
  return (
22
32
  <Dialog
@@ -35,6 +45,18 @@ const GroupRecipientDetail = ({ name, owner, members, onClose, isOwner }) => {
35
45
  }
36
46
  content={
37
47
  <div className="u-flex u-stack-xs u-flex-column">
48
+ {members.length === 0 ? (
49
+ <Empty text={t('GroupRecipientDetail.empty.content')}>
50
+ <Buttons
51
+ component="a"
52
+ className="u-mt-1"
53
+ href={contactsLink}
54
+ target="_blank"
55
+ rel="noopener noreferrer"
56
+ label={t('GroupRecipientDetail.empty.action')}
57
+ />
58
+ </Empty>
59
+ ) : null}
38
60
  {withAccess.length > 0 ? (
39
61
  <GroupRecipientDetailWithAccess withAccess={withAccess} />
40
62
  ) : null}
@@ -48,7 +48,7 @@ const GroupRecipientDetailWithoutAccess = ({ withoutAccess, isOwner }) => {
48
48
  {t(
49
49
  `GroupRecipientDetail.withoutAccess.status.${recipient.status}`
50
50
  )}
51
- {isOwner
51
+ {isOwner && recipient.status === 'mail-not-sent'
52
52
  ? ` - ${t('GroupRecipientDetail.withoutAccess.addEmail')}`
53
53
  : null}
54
54
  </div>
@@ -16,7 +16,7 @@ import {
16
16
  spreadGroupAndMergeRecipients,
17
17
  hasReachRecipientsLimit
18
18
  } from '../helpers/recipients'
19
- import { getSuccessMessage } from '../helpers/successMessage'
19
+ import { getSuccessMessage, getErrorMessage } from '../helpers/share'
20
20
  import { isReadOnlySharing } from '../state'
21
21
  import styles from '../styles/share.styl'
22
22
 
@@ -104,40 +104,19 @@ export const ShareByEmail = ({
104
104
  variant: 'filled'
105
105
  })
106
106
  } catch (err) {
107
- let showGenericAlert = true
108
- if (err.name === 'FetchError' && err.status === 400) {
109
- const detail = JSON.parse(err.message).errors[0].detail
110
- if (
111
- detail.startsWith(
112
- 'A group member cannot be added as they are already in'
113
- )
114
- ) {
115
- // To know the sharing rights of the other group
116
- const sharingRights =
117
- selectedOption === 'readOnly' ? 'readWrite' : 'readOnly'
118
- showAlert({
119
- message: t('Share.errors.groupMemberAlreadyInSharing', {
120
- smart_count: recipients.length,
121
- groupName: recipients[0].name,
122
- sharingRights: t(`Share.errors.sharingRights.${sharingRights}`),
123
- icon: false
124
- }),
125
- severity: 'error',
126
- variant: 'filled'
107
+ showAlert({
108
+ message: t(
109
+ ...getErrorMessage({
110
+ t,
111
+ err,
112
+ documentType,
113
+ recipients,
114
+ selectedOption
127
115
  })
128
- showGenericAlert = false
129
- }
130
- }
131
-
132
- if (showGenericAlert) {
133
- showAlert({
134
- message: t(`${documentType}.share.error.generic`),
135
- severity: 'error',
136
- variant: 'filled'
137
- })
138
- }
139
-
140
- throw err
116
+ ),
117
+ severity: 'error',
118
+ variant: 'filled'
119
+ })
141
120
  } finally {
142
121
  reset()
143
122
  }
@@ -8,7 +8,7 @@ import ShareAutosuggest from './ShareAutosuggest'
8
8
  import { getContactsFromGroupId } from '../helpers/contacts'
9
9
  import {
10
10
  buildReachableContactsQuery,
11
- buildContactGroupsByIdsQuery,
11
+ buildContactGroupsQuery,
12
12
  buildUnreachableContactsWithGroupsQuery
13
13
  } from '../queries/queries'
14
14
 
@@ -40,25 +40,17 @@ const ShareRecipientsInput = ({
40
40
  }
41
41
  )
42
42
 
43
- const contactGroupsByIdsQuery = buildContactGroupsByIdsQuery([
44
- ...new Set(
45
- (reachableContactsResult.data || []).flatMap(contact => {
46
- return (contact.relationships?.groups?.data || []).map(
47
- group => group._id
48
- )
49
- })
50
- )
51
- ])
52
- const contactGroupsByIdsResult = useQueryAll(
53
- contactGroupsByIdsQuery.definition,
54
- contactGroupsByIdsQuery.options
43
+ const contactGroupsQuery = buildContactGroupsQuery()
44
+ const contactGroupsResult = useQueryAll(
45
+ contactGroupsQuery.definition,
46
+ contactGroupsQuery.options
55
47
  )
56
48
 
57
49
  const isLoading =
58
50
  isQueryLoading(reachableContactsResult) ||
59
51
  reachableContactsResult.hasMore ||
60
- isQueryLoading(contactGroupsByIdsResult) ||
61
- contactGroupsByIdsResult.hasMore ||
52
+ isQueryLoading(contactGroupsResult) ||
53
+ contactGroupsResult.hasMore ||
62
54
  (flag('sharing.show-recipient-groups') &&
63
55
  (isQueryLoading(unreachableContactsWithGroupsResult) ||
64
56
  unreachableContactsWithGroupsResult.hasMore))
@@ -66,7 +58,7 @@ const ShareRecipientsInput = ({
66
58
  const currentRecipientGroups = currentRecipients
67
59
  .map(({ id }) => id)
68
60
  .filter(Boolean)
69
- const contactGroups = (contactGroupsByIdsResult.data || [])
61
+ const contactGroups = (contactGroupsResult.data || [])
70
62
  .filter(
71
63
  ({ _id }) =>
72
64
  !flag('sharing.show-recipient-groups') ||
@@ -45,7 +45,7 @@ describe('ShareRecipientsInput component', () => {
45
45
  doctype: 'io.cozy.contacts',
46
46
  data: contacts
47
47
  },
48
- 'io.cozy.contacts.groups/by-ids/fe86af20-c6c5': {
48
+ 'io.cozy.contacts.groups': {
49
49
  doctype: 'io.cozy.contacts.groups',
50
50
  data: contactGroups
51
51
  },
@@ -1,6 +1,6 @@
1
1
  import { models } from 'cozy-client'
2
2
 
3
- import { Contact, Group } from '../models'
3
+ import { Contact, Group, getDisplayName } from '../models'
4
4
 
5
5
  export const countNewRecipients = (currentRecipients, newRecipients) => {
6
6
  const newRecipientsNotAlreadyIncluded = newRecipients.filter(recipient => {
@@ -106,3 +106,48 @@ export const getSuccessMessage = (
106
106
  }
107
107
  }
108
108
  }
109
+
110
+ export const getErrorMessage = ({
111
+ t,
112
+ err,
113
+ documentType,
114
+ recipients,
115
+ selectedOption
116
+ }) => {
117
+ if (err.name === 'FetchError' && err.status === 400) {
118
+ const detail = JSON.parse(err.message).errors[0].detail
119
+ if (
120
+ detail.startsWith('A group member cannot be added as they are already in')
121
+ ) {
122
+ const sharingRights = t(
123
+ `Share.errors.sharingRights.${
124
+ selectedOption === 'readOnly' ? 'readWrite' : 'readOnly'
125
+ }`
126
+ )
127
+
128
+ if (recipients.length === 1 && recipients[0]._type === Contact.doctype) {
129
+ return [
130
+ 'Share.errors.contactAlreadyInSharing',
131
+ {
132
+ smart_count: recipients.length,
133
+ contactName: getDisplayName(recipients[0]),
134
+ sharingRights,
135
+ icon: false
136
+ }
137
+ ]
138
+ }
139
+
140
+ return [
141
+ 'Share.errors.groupMemberAlreadyInSharing',
142
+ {
143
+ smart_count: recipients.length,
144
+ groupName: recipients[0].name,
145
+ sharingRights,
146
+ icon: false
147
+ }
148
+ ]
149
+ }
150
+ }
151
+
152
+ return [`${documentType}.share.error.generic`]
153
+ }