Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated: wording for email received toast + intl #401

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 54 additions & 34 deletions addon/services/activity-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,76 +48,95 @@ 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 <b>${data.influencer_name}</b>
<a href="${data.entity_url}" target="_blank">Reply</a>`,
'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 <b>${data.influencer_name}</b>
<a href="${data.entity_url}" target="_blank">Reply</a>`,
'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 <b>${data.influencer_name}</b>
<a href="${data.entity_url}" target="_blank">Reply</a>`,
'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 <b>${data.influencer_name}</b> in <b>${data.campaign_name}</b>
<a href="${data.url}" target="_blank">See application</a>`,
'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 <b>${data.influencer_name}</b> in <b>${data.campaign_name}</b>
<a href="${data.url}" target="_blank">Review</a>`,
'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 <b>${data.count}</b> new recommendations for your <b>${data.list_name}</b> list
<a href="${data.url}" target="_blank">View</a>`,
'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(
`<b>Mailing error.</b> We ran into a problem with one of your Mailings.
<a href="${data.mailing_url}" target="_blank">View my mailing</a>`,
'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(
`<b>Your ${data.integration_name} has been disconnected.</b> Please check your integration.
settings and reconnect it to avoid any issues. <a href="${data.integration_url}" target="_blank">Reconnect</a>`,
'Integration disconnected'
intl.t('notifications.credential_disconnected.description', {
integration_name: data.integration_name,
integration_url: data.integration_url
}),
intl.t('notifications.credential_disconnected.title')
);
}
};

export default class ActivityWatcher extends Service {
@service declare eventsService: EventsService;
@service declare toast: ToastService;
@service declare intl: IntlService;

private declare _observer: Observable<ResourceEvent> | null;

Expand Down Expand Up @@ -169,7 +189,7 @@ export default class ActivityWatcher extends Service {
return null;
}

return renderer(evt.payload.data || {});
return renderer(evt.payload.data, this.intl || {});
}
}

Expand Down
14 changes: 7 additions & 7 deletions tests/unit/services/activity-watcher-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module('Unit | Service | activity-watcher', function (hooks) {
}
},
wantInfoTitle: 'New email',
wantInfoMessage: `Email from <b>bozito</b>
wantInfoMessage: `You have a new email from bozito!<br>
<a href="https://entity.url.com" target="_blank">Reply</a>`
},
{
Expand All @@ -57,8 +57,8 @@ module('Unit | Service | activity-watcher', function (hooks) {
}
},
wantInfoTitle: 'New email',
wantInfoMessage: `Email from <b>bozito</b>
<a href="https://entity.url.com" target="_blank">Reply</a>`
wantInfoMessage: `You have a new email from bozito!<br>
<a href="https://entity.url.com" target="_blank">Reply</a>`
},
{
notification: {
Expand Down Expand Up @@ -140,8 +140,8 @@ module('Unit | Service | activity-watcher', function (hooks) {
}
},
wantErrorTitle: 'Integration disconnected',
wantErrorMessage: `<b>Your woop has been disconnected.</b> Please check your integration.
settings and reconnect it to avoid any issues. <a href="https://inte-gration.com" target="_blank">Reconnect</a>`
wantErrorMessage: `<b>Your woop has been disconnected.</b> Please check your integration settings and reconnect it to avoid any issues.
<a href="https://inte-gration.com" target="_blank">Reconnect</a>`
}
];

Expand All @@ -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);
});

Expand Down
41 changes: 41 additions & 0 deletions translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}!<br>
<a href="{entity_url}" target="_blank">Reply</a>
conversation_email_received:
title: New email
description: |
You have a new email from {influencer_name}!<br>
<a href="{entity_url}" target="_blank">Reply</a>
direct_message_received:
title: New message
description: |
Message from <b>{influencer_name}</b>
Copy link
Contributor

@aprentout aprentout Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a <br/> here too for consistency ?

<a href="{entity_url}" target="_blank">Reply</a>
publishr_application_received:
title: New application
description: |
Application from <b>{influencer_name}</b> in <b>{campaign_name}</b>
<a href="{url}" target="_blank">See application</a>
publishr_draft_created:
title: New draft
description: |
Draft by <b>{influencer_name}</b> in <b>{campaign_name}</b>
<a href="{url}" target="_blank">Review</a>
list_recommendation:
title: New recommendations
description: |
You have <b>{count}</b> new recommendations for your <b>{list_name}</b> list
<a href="{url}" target="_blank">View</a>
thread_failure_summary:
title: Thread failure
description: |
<b>Mailing error.</b> We ran into a problem with one of your Mailings.
<a href="{mailing_url}" target="_blank">View my mailing</a>
credential_disconnected:
title: Integration disconnected
description: |
<b>Your {integration_name} has been disconnected.</b> Please check your integration settings and reconnect it to avoid any issues.
<a href="{integration_url}" target="_blank">Reconnect</a>
Loading