Skip to content

Commit

Permalink
feat: Alert if group shared with members already in it with other rights
Browse files Browse the repository at this point in the history
  • Loading branch information
cballevre committed Apr 9, 2024
1 parent ba86f00 commit 786b1a0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/cozy-sharing/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@
"deactivate": "Deactivate link",
"cancel": "Cancel",
"confirm": "OK"
},
"errors": {
"errors": {
"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.",
"sharingRights": {
"readOnly": "read",
"readWrite": "write"
}
}
}
},
"Sharings": {
Expand Down
7 changes: 7 additions & 0 deletions packages/cozy-sharing/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
"deactivate": "Désactiver le lien",
"cancel": "Annuler",
"confirm": "OK"
},
"errors": {
"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.",
"sharingRights": {
"readOnly": "lecture",
"readWrite": "modification"
}
}
},
"Sharings": {
Expand Down
35 changes: 33 additions & 2 deletions packages/cozy-sharing/src/components/ShareByEmail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { useState } from 'react'

import { useClient } from 'cozy-client'
import flag from 'cozy-flags'
import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter'
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'

Expand Down Expand Up @@ -105,7 +104,39 @@ export const ShareByEmail = ({
})
reset()
} catch (err) {
Alerter.error('Error.generic')
let showGenericAlert = true
if (err.name === 'FetchError' && err.status === 400) {
const detail = JSON.parse(err.message).errors[0].detail
if (
detail.startsWith(
'A group member cannot be added as they are already in'
)
) {
// To know the sharing rights of the other group
const sharingRights =
selectedOption === 'readOnly' ? 'readWrite' : 'readOnly'
showAlert({
message: t('Share.errors.groupMemberAlreadyInSharing', {
smart_count: recipients.length,
groupName: recipients[0].name,
sharingRights: t(`Share.errors.sharingRights.${sharingRights}`),
icon: false
}),
severity: 'error',
variant: 'filled'
})
showGenericAlert = false
}
}

if (showGenericAlert) {
showAlert({
message: t(`${documentType}.share.error.generic`),
severity: 'error',
variant: 'filled'
})
}

reset()
throw err
}
Expand Down

0 comments on commit 786b1a0

Please sign in to comment.