2022-03-22 18:37:17 +03:00
|
|
|
import Component from '@glimmer/component';
|
2022-03-24 12:05:08 +03:00
|
|
|
import {action} from '@ember/object';
|
2022-05-17 10:34:34 +03:00
|
|
|
import {formatNumber} from '../../../helpers/format-number';
|
2022-03-23 18:38:16 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2022-03-24 12:05:08 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
|
|
|
|
const STATUS_OPTIONS = [{
|
2022-04-20 15:43:11 +03:00
|
|
|
name: 'All members',
|
2022-03-24 12:05:08 +03:00
|
|
|
value: 'total'
|
|
|
|
}, {
|
2022-04-20 15:43:11 +03:00
|
|
|
name: 'Paid members',
|
2022-03-24 12:05:08 +03:00
|
|
|
value: 'paid'
|
|
|
|
}, {
|
2022-04-20 15:43:11 +03:00
|
|
|
name: 'Free members',
|
2022-03-24 12:05:08 +03:00
|
|
|
value: 'free'
|
|
|
|
}];
|
2022-03-22 18:37:17 +03:00
|
|
|
|
2022-04-12 15:09:00 +03:00
|
|
|
export default class Engagement extends Component {
|
2022-03-23 18:38:16 +03:00
|
|
|
@service dashboardStats;
|
|
|
|
|
2022-03-24 17:32:34 +03:00
|
|
|
@action
|
2022-03-23 18:38:16 +03:00
|
|
|
loadCharts() {
|
2022-03-24 14:04:18 +03:00
|
|
|
this.dashboardStats.lastSeenFilterStatus = this.status;
|
|
|
|
this.dashboardStats.loadLastSeen();
|
2022-04-01 11:48:01 +03:00
|
|
|
this.dashboardStats.loadMemberCountStats();
|
2022-04-20 15:43:11 +03:00
|
|
|
this.dashboardStats.loadNewsletterSubscribers();
|
2022-03-23 18:38:16 +03:00
|
|
|
}
|
|
|
|
|
2022-03-24 12:05:08 +03:00
|
|
|
@tracked status = 'total';
|
|
|
|
statusOptions = STATUS_OPTIONS;
|
|
|
|
|
|
|
|
get selectedStatusOption() {
|
|
|
|
return this.statusOptions.find(option => option.value === this.status);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
onSwitchStatus(selected) {
|
|
|
|
this.status = selected.value;
|
2022-03-24 14:04:18 +03:00
|
|
|
this.dashboardStats.lastSeenFilterStatus = this.status;
|
|
|
|
this.dashboardStats.loadLastSeen();
|
2022-03-23 18:38:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get loading() {
|
|
|
|
return this.dashboardStats.memberCounts === null
|
|
|
|
|| !this.dashboardStats.memberCounts[this.status]
|
|
|
|
|| this.dashboardStats.membersLastSeen30d === null
|
|
|
|
|| this.dashboardStats.membersLastSeen7d === null;
|
|
|
|
}
|
|
|
|
|
2022-03-22 18:37:17 +03:00
|
|
|
get data30Days() {
|
2022-05-06 19:33:19 +03:00
|
|
|
// fake empty data
|
|
|
|
if (this.isTotalMembersZero) {
|
|
|
|
return '30%';
|
|
|
|
}
|
|
|
|
|
2022-03-23 18:38:16 +03:00
|
|
|
if (this.loading) {
|
|
|
|
return '- %';
|
|
|
|
}
|
|
|
|
const total = this.dashboardStats.memberCounts[this.status];
|
|
|
|
const part = this.dashboardStats.membersLastSeen30d;
|
|
|
|
|
|
|
|
if (total <= 0) {
|
|
|
|
return '- %';
|
|
|
|
}
|
|
|
|
|
|
|
|
const percentage = Math.round(part / total * 100);
|
|
|
|
return `${percentage}%`;
|
2022-03-22 18:37:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get data7Days() {
|
2022-05-06 19:33:19 +03:00
|
|
|
// fake empty data
|
|
|
|
if (this.isTotalMembersZero) {
|
|
|
|
return '60%';
|
|
|
|
}
|
|
|
|
|
2022-03-23 18:38:16 +03:00
|
|
|
if (this.loading) {
|
|
|
|
return '- %';
|
|
|
|
}
|
|
|
|
const total = this.dashboardStats.memberCounts[this.status];
|
|
|
|
const part = this.dashboardStats.membersLastSeen7d;
|
|
|
|
|
|
|
|
if (total <= 0) {
|
|
|
|
return '- %';
|
|
|
|
}
|
|
|
|
|
|
|
|
const percentage = Math.round(part / total * 100);
|
|
|
|
return `${percentage}%`;
|
2022-03-22 18:37:17 +03:00
|
|
|
}
|
2022-04-20 15:43:11 +03:00
|
|
|
|
|
|
|
get dataSubscribers() {
|
2022-05-06 19:33:19 +03:00
|
|
|
// fake empty data
|
|
|
|
if (this.isTotalMembersZero) {
|
|
|
|
return '123';
|
|
|
|
}
|
|
|
|
|
2022-04-20 15:43:11 +03:00
|
|
|
if (!this.dashboardStats.newsletterSubscribers) {
|
|
|
|
return '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
return formatNumber(this.dashboardStats.newsletterSubscribers[this.status]);
|
|
|
|
}
|
|
|
|
|
|
|
|
get dataEmailsSent() {
|
|
|
|
return this.dashboardStats.emailsSent30d ?? 0;
|
|
|
|
}
|
2022-04-22 17:46:53 +03:00
|
|
|
|
|
|
|
get hasPaidTiers() {
|
|
|
|
return this.dashboardStats.siteStatus?.hasPaidTiers;
|
|
|
|
}
|
2022-05-06 19:33:19 +03:00
|
|
|
|
|
|
|
get totalMembers() {
|
|
|
|
return this.dashboardStats.memberCounts?.total ?? 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get isTotalMembersZero() {
|
|
|
|
return this.dashboardStats.memberCounts && this.totalMembers === 0;
|
|
|
|
}
|
2022-03-22 18:37:17 +03:00
|
|
|
}
|