diff --git a/addon/services/activity-watcher.ts b/addon/services/activity-watcher.ts
index 08802d7b..891cf7c9 100644
--- a/addon/services/activity-watcher.ts
+++ b/addon/services/activity-watcher.ts
@@ -4,6 +4,7 @@ import { inject as service } from '@ember/service';
import { Observable } from '@upfluence/hyperevents/helpers/observable';
import EventsService, { ResourceEvent, prefixPath } from '@upfluence/hyperevents/services/events-service';
import ToastService, { ToastOptions } from '@upfluence/oss-components/services/toast';
+import { IntlService } from 'ember-intl';
type NotificationEvent = {
resource: string;
@@ -47,69 +48,87 @@ function renderNotificationMessageWithAvatar(message: string, title: string, ava
}
type NotificationRendererMap = {
- [key: string]: (data: any) => RenderedNotification;
+ [key: string]: (data: any, intl?: IntlService) => RenderedNotification;
};
const renderersByNotificationType: NotificationRendererMap = {
- mailing_email_received: (data: any) => {
+ mailing_email_received: (data: any, intl: IntlService) => {
return renderNotificationMessageWithAvatar(
- `Email from ${data.influencer_name}
- Reply`,
- 'New email',
+ intl.t('notifications.mailing_email_received.description', {
+ influencer_name: data.influencer_name,
+ entity_url: data.entity_url
+ }),
+ intl.t('notifications.mailing_email_received.title'),
data.influencer_avatar
);
},
- conversation_email_received: (data: any) => {
+ conversation_email_received: (data: any, intl: IntlService) => {
return renderNotificationMessageWithAvatar(
- `Email from ${data.influencer_name}
- Reply`,
- 'New email',
+ intl.t('notifications.conversation_email_received.description', {
+ influencer_name: data.influencer_name,
+ entity_url: data.entity_url
+ }),
+ intl.t('notifications.conversation_email_received.title'),
data.influencer_avatar
);
},
- direct_message_received: (data: any) => {
+ direct_message_received: (data: any, intl: IntlService) => {
return renderNotificationMessageWithAvatar(
- `Message from ${data.influencer_name}
- Reply`,
- 'New message',
+ intl.t('notifications.direct_message_received.description', {
+ influencer_name: data.influencer_name,
+ entity_url: data.entity_url
+ }),
+ intl.t('notifications.direct_message_received.title'),
data.influencer_avatar
);
},
- publishr_application_received: (data: any) => {
+ publishr_application_received: (data: any, intl: IntlService) => {
return renderNotificationMessageWithAvatar(
- `Application from ${data.influencer_name} in ${data.campaign_name}
- See application`,
- 'New application',
+ intl.t('notifications.publishr_application_received.description', {
+ influencer_name: data.influencer_name,
+ campaign_name: data.campaign_name,
+ url: data.url
+ }),
+ intl.t('notifications.publishr_application_received.title'),
data.influencer_avatar
);
},
- publishr_draft_created: (data: any) => {
+ publishr_draft_created: (data: any, intl: IntlService) => {
return renderNotificationMessageWithAvatar(
- `Draft by ${data.influencer_name} in ${data.campaign_name}
- Review`,
- 'New draft',
+ intl.t('notifications.publishr_draft_created.description', {
+ influencer_name: data.influencer_name,
+ campaign_name: data.campaign_name,
+ url: data.url
+ }),
+ intl.t('notifications.publishr_draft_created.title'),
data.influencer_avatar
);
},
- list_recommendation: (data: any) => {
+ list_recommendation: (data: any, intl: IntlService) => {
return renderNotificationMessage(
- `You have ${data.count} new recommendations for your ${data.list_name} list
- View`,
- 'New recommendations'
+ intl.t('notifications.list_recommendation.description', {
+ count: data.count,
+ list_name: data.list_name,
+ url: data.url
+ }),
+ intl.t('notifications.list_recommendation.title')
);
},
- thread_failure_summary: (data: any) => {
+ thread_failure_summary: (data: any, intl: IntlService) => {
return renderNotificationErrorMessage(
- `Mailing error. We ran into a problem with one of your Mailings.
- View my mailing`,
- 'Thread failure'
+ intl.t('notifications.thread_failure_summary.description', {
+ mailing_url: data.mailing_url
+ }),
+ intl.t('notifications.thread_failure_summary.title')
);
},
- credential_disconnected: (data: any) => {
+ credential_disconnected: (data: any, intl: IntlService) => {
return renderNotificationErrorMessage(
- `Your ${data.integration_name} has been disconnected. Please check your integration.
- settings and reconnect it to avoid any issues. Reconnect`,
- 'Integration disconnected'
+ intl.t('notifications.credential_disconnected.description', {
+ integration_name: data.integration_name,
+ integration_url: data.integration_url
+ }),
+ intl.t('notifications.credential_disconnected.title')
);
}
};
@@ -117,6 +136,7 @@ const renderersByNotificationType: NotificationRendererMap = {
export default class ActivityWatcher extends Service {
@service declare eventsService: EventsService;
@service declare toast: ToastService;
+ @service declare intl: IntlService;
private declare _observer: Observable | null;
@@ -169,7 +189,7 @@ export default class ActivityWatcher extends Service {
return null;
}
- return renderer(evt.payload.data || {});
+ return renderer(evt.payload.data, this.intl || {});
}
}
diff --git a/tests/unit/services/activity-watcher-test.ts b/tests/unit/services/activity-watcher-test.ts
index 899084ea..608cf6fe 100644
--- a/tests/unit/services/activity-watcher-test.ts
+++ b/tests/unit/services/activity-watcher-test.ts
@@ -43,7 +43,7 @@ module('Unit | Service | activity-watcher', function (hooks) {
}
},
wantInfoTitle: 'New email',
- wantInfoMessage: `Email from bozito
+ wantInfoMessage: `You have a new email from bozito!
Reply`
},
{
@@ -57,8 +57,8 @@ module('Unit | Service | activity-watcher', function (hooks) {
}
},
wantInfoTitle: 'New email',
- wantInfoMessage: `Email from bozito
- Reply`
+ wantInfoMessage: `You have a new email from bozito!
+ Reply`
},
{
notification: {
@@ -140,8 +140,8 @@ module('Unit | Service | activity-watcher', function (hooks) {
}
},
wantErrorTitle: 'Integration disconnected',
- wantErrorMessage: `Your woop has been disconnected. Please check your integration.
- settings and reconnect it to avoid any issues. Reconnect`
+ wantErrorMessage: `Your woop has been disconnected. Please check your integration settings and reconnect it to avoid any issues.
+ Reconnect`
}
];
@@ -152,13 +152,13 @@ module('Unit | Service | activity-watcher', function (hooks) {
const infoStub = sinon
.stub(this.owner.lookup('service:toast'), 'info')
.callsFake((message: string, title: string) => {
- assert.equal(trimAll(message), trimAll(testCase.wantInfoMessage));
+ assert.true(trimAll(message).includes(trimAll(testCase.wantInfoMessage)));
assert.equal(title, testCase.wantInfoTitle);
});
const errorStub = sinon
.stub(this.owner.lookup('service:toast'), 'error')
.callsFake((message: string, title: string) => {
- assert.equal(trimAll(message), trimAll(testCase.wantErrorMessage));
+ assert.true(trimAll(message).includes(trimAll(testCase.wantErrorMessage)));
assert.equal(title, testCase.wantErrorTitle);
});
diff --git a/translations/en-us.yaml b/translations/en-us.yaml
index ad57f278..ec724434 100644
--- a/translations/en-us.yaml
+++ b/translations/en-us.yaml
@@ -155,3 +155,44 @@ utms:
campaign: UTM campaign*
campaign_placeholder: e.g. product launch winter 2022
preview: Preview of your tracking URL
+notifications:
+ mailing_email_received:
+ title: New email
+ description: |
+ You have a new email from {influencer_name}!
+ Reply
+ conversation_email_received:
+ title: New email
+ description: |
+ You have a new email from {influencer_name}!
+ Reply
+ direct_message_received:
+ title: New message
+ description: |
+ Message from {influencer_name}
+ Reply
+ publishr_application_received:
+ title: New application
+ description: |
+ Application from {influencer_name} in {campaign_name}
+ See application
+ publishr_draft_created:
+ title: New draft
+ description: |
+ Draft by {influencer_name} in {campaign_name}
+ Review
+ list_recommendation:
+ title: New recommendations
+ description: |
+ You have {count} new recommendations for your {list_name} list
+ View
+ thread_failure_summary:
+ title: Thread failure
+ description: |
+ Mailing error. We ran into a problem with one of your Mailings.
+ View my mailing
+ credential_disconnected:
+ title: Integration disconnected
+ description: |
+ Your {integration_name} has been disconnected. Please check your integration settings and reconnect it to avoid any issues.
+ Reconnect
\ No newline at end of file