Skip to content

Commit

Permalink
feat: Add mobile notifications to the expiration service
Browse files Browse the repository at this point in the history
  • Loading branch information
Merkur39 committed May 22, 2024
1 parent cbf59e0 commit 83ea8d5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
14 changes: 10 additions & 4 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
"button": "See",
"content": {
"hello": "Hello 👋,",
"info": "Documents saved in your My Papers application will soon expire:",
"view": "Click on the name of the document to view it in your My Papers application.",
"info": "Documents saved in your Mes Papiers application will soon expire:",
"view": "Click on the name of the document to view it in your Mes Papiers application.",
"seeyou": "See you soon!"
}
},
"mobile": {
"content": {
"info": "The document %{filename} in your Mes Papiers application is about to expire.",
"multiple": "Documents saved in your Mes Papiers application will soon expire."
}
}
}
},
Expand All @@ -19,8 +25,8 @@
"content": {
"paragraph01": "You can get help directly by phone: <a href=\"tel://0483439040\">04 83 43 90 40</a>",
"paragraph02": "Free call Monday to Friday from 3pm to 5pm, Thursday until 7pm, and Saturday from 10am to 12pm.",
"paragraph03": "You can also find help, report a problem, or suggest a good idea on <a href=\"%{url}\" target=\"_blank\" rel=\"noopener\">the user support site</a> My Papers.",
"paragraph04": "Do not hesitate to write to us, the My Papers team will answer you with pleasure."
"paragraph03": "You can also find help, report a problem, or suggest a good idea on <a href=\"%{url}\" target=\"_blank\" rel=\"noopener\">the user support site</a> Mes Papiers.",
"paragraph04": "Do not hesitate to write to us, the Mes Papiers team will answer you with pleasure."
},
"actions": {
"later": "Close",
Expand Down
6 changes: 6 additions & 0 deletions src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"view": "Cliquez sur le nom du document pour le consulter dans votre application Mes Papiers.",
"seeyou": "À très bientôt !"
}
},
"mobile": {
"content": {
"info": "Le document %{filename} dans votre application Mes Papiers va bientôt expirer",
"multiple": "Des documents enregistrés dans votre application Mes Papiers vont bientôt arriver à expiration."
}
}
}
},
Expand Down
43 changes: 36 additions & 7 deletions src/notifications/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import format from 'date-fns/format'

import { generateWebLink, models } from 'cozy-client'
import { generateWebLink } from 'cozy-client'
import { splitFilename } from 'cozy-client/dist/models/file'
import { NotificationView } from 'cozy-notifications'

import template from 'raw-loader!./template.hbs'
import { APP_SLUG } from 'src/constants'

const {
file: { splitFilename }
} = models

/**
* @typedef {object} FilesInfo
* @property {string} name - Filename
Expand All @@ -30,10 +27,13 @@ const {
* Manages the notification sent for expiration files
*/
class ExpirationNotification extends NotificationView {
#hasMultipleExpiredFiles

constructor(options) {
super(options)
this.currentDate = options.currentDate
this.filesInfo = options.filesInfo
this.#hasMultipleExpiredFiles = options.filesInfo.length > 1
}

/**
Expand All @@ -50,7 +50,18 @@ class ExpirationNotification extends NotificationView {
* @returns {string}
*/
getPushContent() {
return ' '
if (!this.#hasMultipleExpiredFiles) {
const file = this.filesInfo[0].file

if (file) {
const { filename } = splitFilename(file)
return this.t('notifications.expiration.mobile.content.info', {
filename
})
}
}

return this.t('notifications.expiration.mobile.content.multiple')
}
/**
* Subject of mail
Expand All @@ -60,6 +71,24 @@ class ExpirationNotification extends NotificationView {
return this.t('notifications.expiration.email.title')
}

getExtraAttributes() {
let paperLink = 'paper'

if (!this.#hasMultipleExpiredFiles) {
const file = this.filesInfo[0].file
if (file) {
paperLink = `paper/files/${file.metadata.qualification.label}/${file._id}`
}
}

return {
data: {
appName: '', // Overwrite the appName in the notification
redirectLink: `mespapiers/#/${paperLink}`
}
}
}

/**
* Building data passed to the template
* @returns {BuildDataReturns}
Expand Down Expand Up @@ -104,6 +133,6 @@ class ExpirationNotification extends NotificationView {

ExpirationNotification.template = template
ExpirationNotification.category = 'expiration'
ExpirationNotification.preferredChannels = ['mail']
ExpirationNotification.preferredChannels = ['mobile', 'mail']

export default ExpirationNotification

0 comments on commit 83ea8d5

Please sign in to comment.