Skip to content

Commit

Permalink
feat: Improve the message of success to integrate the notion of groups
Browse files Browse the repository at this point in the history
  • Loading branch information
cballevre committed Apr 8, 2024
1 parent e1b21f8 commit f0945b7
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 98 deletions.
28 changes: 20 additions & 8 deletions packages/cozy-sharing/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,11 @@
"subtitle": "By email",
"emailPlaceholder": "Add contacts or groups",
"send": "Send",
"genericSuccess": "You sent an invite to %{count} contacts.",
"success": "You sent an invite to %{email}.",
"singleContactSuccess": "You sent an invite to %{email}.",
"contactSuccess": "You sent an invite to %{smart_count} contact. |||| You sent an invite to %{smart_count} contacts.",
"singleGroupSuccess": "You sent an invite to the members of the %{groupName} group.",
"groupSuccess": "You sent an invite to the members of %{smart_count} group. |||| You sent an invite to the members of %{smart_count} groups.",
"contactAndGroupSuccess": "You sent an invite to %{nbContact} contacts and the members of %{nbGroup} groups.",
"comingsoon": "Coming soon! You will be able to share documents and photos in a single click with your family, your friends, and even your coworkers. Don't worry, we'll let you know when it's ready!",
"onlyByLink": "This %{type} can only be shared by link, because",
"type": {
Expand Down Expand Up @@ -180,8 +183,11 @@
"email": "To:",
"emailPlaceholder": "Enter the email address or name of the recipient",
"send": "Send",
"genericSuccess": "You sent an invite to %{count} contacts.",
"success": "You sent an invite to %{email}.",
"singleContactSuccess": "You sent an invite to %{email}.",
"contactSuccess": "You sent an invite to %{smart_count} contact. |||| You sent an invite to %{smart_count} contacts.",
"singleGroupSuccess": "You sent an invite to the members of the %{groupName} group.",
"groupSuccess": "You sent an invite to the members of %{smart_count} group. |||| You sent an invite to the members of %{smart_count} groups.",
"contactAndGroupSuccess": "You sent an invite to %{nbContact} contacts and the members of %{nbGroup} groups.",
"comingsoon": "Coming soon! You will be able to share documents and photos in a single click with your family, your friends, and even your coworkers. Don't worry, we'll let you know when it's ready!",
"onlyByLink": "This %{type} can only be shared by link, because",
"type": {
Expand Down Expand Up @@ -246,8 +252,11 @@
"email": "email",
"emailPlaceholder": "Enter the email address or name of the recipient",
"send": "Send",
"genericSuccess": "You sent an invite to %{count} contacts.",
"success": "You sent an invite to %{email}.",
"singleContactSuccess": "You sent an invite to %{email}.",
"contactSuccess": "You sent an invite to %{smart_count} contact. |||| You sent an invite to %{smart_count} contacts.",
"singleGroupSuccess": "You sent an invite to the members of the %{groupName} group.",
"groupSuccess": "You sent an invite to the members of %{smart_count} group. |||| You sent an invite to the members of %{smart_count} groups.",
"contactAndGroupSuccess": "You sent an invite to %{nbContact} contacts and the members of %{nbGroup} groups.",
"comingsoon": "Coming soon! You will be able to share documents and photos in a single click with your family, your friends, and even your coworkers. Don't worry, we'll let you know when it's ready!"
},
"unshare": {
Expand Down Expand Up @@ -307,8 +316,11 @@
"email": "Send to:",
"emailPlaceholder": "Enter the email address or name of the recipient",
"send": "Send",
"genericSuccess": "You sent an invite to %{count} contacts.",
"success": "You sent an invite to %{email}.",
"singleContactSuccess": "You sent an invite to %{email}.",
"contactSuccess": "You sent an invite to %{smart_count} contact. |||| You sent an invite to %{smart_count} contacts.",
"singleGroupSuccess": "You sent an invite to the members of the %{groupName} group.",
"groupSuccess": "You sent an invite to the members of %{smart_count} group. |||| You sent an invite to the members of %{smart_count} groups.",
"contactAndGroupSuccess": "You sent an invite to %{nbContact} contacts and the members of %{nbGroup} groups.",
"comingsoon": "Coming soon! You will be able to share documents and photos in a single click with your family, your friends, and even your coworkers. Don't worry, we'll let you know when it's ready!",
"onlyByLink": "This %{type} can only be shared by link, because",
"type": {
Expand Down
26 changes: 20 additions & 6 deletions packages/cozy-sharing/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@
"subtitle": "Par email",
"emailPlaceholder": "Ajouter des contacts ou des groupes",
"send": "Envoyer",
"genericSuccess": "Vous avez invité %{count} contacts.",
"success": "Vous avez envoyé une invitation à %{email}.",
"singleContactSuccess": "Vous avez envoyé une invitation à %{email}.",
"contactSuccess": "Vous avez invité %{smart_count} contact. |||| Vous avez invité %{smart_count} contacts.",
"singleGroupSuccess": "Vous avez invité les membres du groupe %{groupName}.",
"groupSuccess": "Vous avez invité les membres de %{smart_count} groupe. |||| Vous avez invité les membres de %{smart_count} groupes.",
"contactAndGroupSuccess": "Vous avez invité %{nbContact} contacts et les membres de %{nbGroup} groupes.",
"comingsoon": "Bientôt disponible ! Vous pourrez partager un document et vos photos en un seul clic avec votre famille, vos amis, et même vos collaborateurs. Ne vous inquiétez pas, on vous prévient quand ce sera prêt !",
"onlyByLink": "Ce %{type} ne peut être partagé que sous la forme d'un lien, car il",
"type": {
Expand Down Expand Up @@ -179,7 +182,11 @@
"email": "À :",
"emailPlaceholder": "Saisissez le courriel ou le nom du destinataire.",
"send": "Envoyer",
"genericSuccess": "Vous avez invité %{count} contacts.",
"singleContactSuccess": "Vous avez envoyé une invitation à %{email}.",
"contactSuccess": "Vous avez invité %{smart_count} contact. |||| Vous avez invité %{smart_count} contacts.",
"singleGroupSuccess": "Vous avez invité les membres du groupe %{groupName}.",
"groupSuccess": "Vous avez invité les membres de %{smart_count} groupe. |||| Vous avez invité les membres de %{smart_count} groupes.",
"contactAndGroupSuccess": "Vous avez invité %{nbContact} contacts et les membres de %{nbGroup} groupes.",
"success": "Vous avez envoyé une invitation à %{email}.",
"comingsoon": "Bientôt disponible ! Vous pourrez partager un document et vos photos en un seul clic avec votre famille, vos amis, et même vos collaborateurs. Ne vous inquiétez pas, on vous prévient quand ce sera prêt !",
"onlyByLink": "Ce %{type} ne peut être partagé que sous la forme d'un lien, car il",
Expand Down Expand Up @@ -245,7 +252,11 @@
"email": "e-mail",
"emailPlaceholder": "Saisissez l'email ou le nom du destinataire.",
"send": "Envoyer",
"genericSuccess": "Vous avez envoyé une invitation à %{count} contacts.",
"singleContactSuccess": "Vous avez envoyé une invitation à %{email}.",
"contactSuccess": "Vous avez invité %{smart_count} contact. |||| Vous avez invité %{smart_count} contacts.",
"singleGroupSuccess": "Vous avez invité les membres du groupe %{groupName}.",
"groupSuccess": "Vous avez invité les membres de %{smart_count} groupe. |||| Vous avez invité les membres de %{smart_count} groupes.",
"contactAndGroupSuccess": "Vous avez invité %{nbContact} contacts et les membres de %{nbGroup} groupes.",
"success": "Vous avez envoyé une invitation à %{email}.",
"comingsoon": "Bientôt disponible ! Vous pourrez partager vos documents et vos photos en un seul clic avec votre famille, vos amis et même vos collaborateurs. Ne vous inquiétez pas, on vous préviendra quand ce sera prêt !\n"
},
Expand Down Expand Up @@ -305,8 +316,11 @@
"email": "Envoyer à :",
"emailPlaceholder": "Saisissez le courriel ou le nom du destinataire.",
"send": "Envoyer",
"genericSuccess": "Vous avez invité %{count} contacts.",
"success": "Vous avez envoyé une invitation à %{email}.",
"singleContactSuccess": "Vous avez envoyé une invitation à %{email}.",
"contactSuccess": "Vous avez invité %{smart_count} contact. |||| Vous avez invité %{smart_count} contacts.",
"singleGroupSuccess": "Vous avez invité les membres du groupe %{groupName}.",
"groupSuccess": "Vous avez invité les membres de %{smart_count} groupe. |||| Vous avez invité les membres de %{smart_count} groupes.",
"contactAndGroupSuccess": "Vous avez invité %{nbContact} contacts et les membres de %{nbGroup} groupes.",
"comingsoon": "Bientôt disponible ! Vous pourrez partager un document et vos photos en un seul clic avec votre famille, vos amis, et même vos collaborateurs. Ne vous inquiétez pas, on vous prévient quand ce sera prêt !",
"onlyByLink": "Ce %{type} ne peut être partagé que sous la forme d'un lien, car il",
"type": {
Expand Down
13 changes: 10 additions & 3 deletions packages/cozy-sharing/src/components/ShareByEmail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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'

import ShareRecipientsInput from './ShareRecipientsInput'
Expand Down Expand Up @@ -34,6 +35,8 @@ export const ShareByEmail = ({
}) => {
const client = useClient()
const { t } = useI18n()
const { showAlert } = useAlert()

const [recipients, setRecipients] = useState([])
const [loading, setLoading] = useState(false)
const [selectedOption, setSelectedOption] = useState()
Expand Down Expand Up @@ -96,9 +99,13 @@ export const ShareByEmail = ({
openSharing: readWriteRecipients.length > 0
})

Alerter.success(
t(...getSuccessMessage(recipientsBefore, contacts, documentType))
)
showAlert({
message: t(
...getSuccessMessage(recipientsBefore, contacts, documentType)
),
severity: 'success',
variant: 'filled'
})
reset()
} catch (err) {
Alerter.error('Error.generic')
Expand Down
92 changes: 71 additions & 21 deletions packages/cozy-sharing/src/helpers/successMessage.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
import { models } from 'cozy-client'

import { Contact } from '../models'
import { Contact, Group } from '../models'

export const countNewRecipients = (currentRecipients, newRecipients) => {
return newRecipients.filter(contact => {
const email = models.contact.getPrimaryEmail(contact)
const cozyUrl = models.contact.getPrimaryCozy(contact)
return !currentRecipients.find(
r =>
(email && r.email && r.email === email) ||
(cozyUrl && r.instance && r.instance === cozyUrl)
)
}).length
const newRecipientsNotAlreadyIncluded = newRecipients.filter(recipient => {
if (Contact.isContact(recipient)) {
const email = models.contact.getPrimaryEmail(recipient)
const cozyUrl = models.contact.getPrimaryCozy(recipient)
return !currentRecipients.find(
r =>
(email && r.email && r.email === email) ||
(cozyUrl && r.instance && r.instance === cozyUrl)
)
}
return true
})

return newRecipientsNotAlreadyIncluded.reduce(
(acc, recipient) => {
if (recipient._type === Group.doctype) {
return {
...acc,
group: acc.group + 1
}
} else {
return {
...acc,
contact: acc.contact + 1
}
}
},
{
group: 0,
contact: 0
}
)
}

export const getSuccessMessage = (
Expand All @@ -24,35 +48,61 @@ export const getSuccessMessage = (
? models.contact.getPrimaryEmail(recipient)
: recipient.email
const cozyUrl = models.contact.getPrimaryCozy(recipient)
const isContactGroup = recipient._type === Group.doctype

if (email) {
if (isContactGroup) {
return [
`${documentType}.share.shareByEmail.success`,
`${documentType}.share.shareByEmail.singleGroupSuccess`,
{
groupName: recipient.name
}
]
} else if (email) {
return [
`${documentType}.share.shareByEmail.singleContactSuccess`,
{
email
}
]
} else if (cozyUrl) {
return [
`${documentType}.share.shareByEmail.success`,
`${documentType}.share.shareByEmail.singleContactSuccess`,
{
email: cozyUrl
}
]
} else {
return [
`${documentType}.share.shareByEmail.genericSuccess`,
`${documentType}.share.shareByEmail.contactSuccess`,
{
count: 1
smart_count: 1
}
]
}
} else {
return [
`${documentType}.share.shareByEmail.genericSuccess`,
{
count: countNewRecipients(recipientsBefore, recipientsAfter)
}
]
const count = countNewRecipients(recipientsBefore, recipientsAfter)
if (count.contact > 0 && count.group > 0) {
return [
`${documentType}.share.shareByEmail.contactAndGroupSuccess`,
{
nbContact: count.contact,
nbGroup: count.group
}
]
} else if (count.group > 0) {
return [
`${documentType}.share.shareByEmail.groupSuccess`,
{
smart_count: count.group
}
]
} else {
return [
`${documentType}.share.shareByEmail.contactSuccess`,
{
smart_count: count.contact
}
]
}
}
}

0 comments on commit f0945b7

Please sign in to comment.