Moved parse-member-event helper to class syntax

no issue

- Added feature service in it
This commit is contained in:
Simon Backx 2022-08-25 16:42:19 +02:00
parent 4ac1a2c21e
commit 6e2579ec9d

View File

@ -1,15 +1,20 @@
import Helper from '@ember/component/helper';
import moment from 'moment';
import {getNonDecimal, getSymbol} from 'ghost-admin/utils/currency';
import {inject as service} from '@ember/service';
export default function parseMemberEvent(event, hasMultipleNewsletters) {
export default class ParseMemberEventHelper extends Helper {
@service feature;
compute([event, hasMultipleNewsletters]) {
const subject = event.data.member.name || event.data.member.email;
const icon = getIcon(event);
const action = getAction(event, hasMultipleNewsletters);
const info = getInfo(event);
const icon = this.getIcon(event);
const action = this.getAction(event, hasMultipleNewsletters);
const info = this.getInfo(event);
const join = getJoin(event);
const object = getObject(event);
const url = getURL(event);
const join = this.getJoin(event);
const object = this.getObject(event);
const url = this.getURL(event);
const timestamp = moment(event.data.created_at);
return {
@ -26,11 +31,10 @@ export default function parseMemberEvent(event, hasMultipleNewsletters) {
url,
timestamp
};
}
}
/* internal helper functions */
function getIcon(event) {
/* internal helper functions */
getIcon(event) {
let icon;
if (event.type === 'signup_event') {
@ -78,9 +82,9 @@ function getIcon(event) {
}
return 'event-' + icon;
}
}
function getAction(event, hasMultipleNewsletters) {
getAction(event, hasMultipleNewsletters) {
if (event.type === 'signup_event') {
return 'signed up';
}
@ -144,9 +148,9 @@ function getAction(event, hasMultipleNewsletters) {
}
return 'commented';
}
}
}
/**
/**
* When we need to append the action and object in one sentence, you can add extra words here.
* E.g.,
* action: 'Signed up'.
@ -155,7 +159,7 @@ function getAction(event, hasMultipleNewsletters) {
* -> do this by returning 'on' in getJoin()
* This string is not added when action and object are in a separete table column, or when the getObject/getURL is empty
*/
function getJoin(event) {
getJoin(event) {
if (event.type === 'signup_event' || event.type === 'subscription_event') {
if (event.data.attribution?.title) {
return 'on';
@ -169,12 +173,12 @@ function getJoin(event) {
}
return '';
}
}
/**
/**
* Clickable object, shown between action and info, or in a separate column in some views
*/
function getObject(event) {
getObject(event) {
if (event.type === 'signup_event' || event.type === 'subscription_event') {
if (event.data.attribution?.title) {
return event.data.attribution.title;
@ -188,9 +192,9 @@ function getObject(event) {
}
return '';
}
}
function getInfo(event) {
getInfo(event) {
if (event.type === 'subscription_event') {
let mrrDelta = getNonDecimal(event.data.mrr_delta, event.data.currency);
if (mrrDelta === 0) {
@ -201,12 +205,12 @@ function getInfo(event) {
return `(MRR ${sign}${symbol}${Math.abs(mrrDelta)})`;
}
return;
}
}
/**
/**
* Make the object clickable
*/
function getURL(event) {
getURL(event) {
if (event.type === 'comment_event') {
if (event.data.post) {
return event.data.post.url;
@ -219,4 +223,6 @@ function getURL(event) {
}
}
return;
}
}