2022-09-13 11:38:14 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
2022-09-26 20:59:30 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
2022-09-13 11:38:14 +03:00
|
|
|
|
2022-09-28 13:57:44 +03:00
|
|
|
const DISPLAY_OPTIONS = [{
|
2022-09-28 14:44:24 +03:00
|
|
|
name: 'Free signups',
|
2022-09-28 13:57:44 +03:00
|
|
|
value: 'signups'
|
2022-09-28 14:44:24 +03:00
|
|
|
}, {
|
|
|
|
name: 'Paid conversions',
|
|
|
|
value: 'paid'
|
2022-09-28 13:57:44 +03:00
|
|
|
}];
|
|
|
|
|
2022-09-13 11:38:14 +03:00
|
|
|
export default class Recents extends Component {
|
|
|
|
@service dashboardStats;
|
2022-09-26 20:59:30 +03:00
|
|
|
@tracked sortColumn = 'signups';
|
2022-09-28 13:57:44 +03:00
|
|
|
displayOptions = DISPLAY_OPTIONS;
|
|
|
|
|
|
|
|
@action
|
|
|
|
onDisplayChange(selected) {
|
|
|
|
this.sortColumn = selected.value;
|
|
|
|
}
|
2022-09-26 20:59:30 +03:00
|
|
|
|
|
|
|
@action
|
|
|
|
setSortColumn(column) {
|
|
|
|
this.sortColumn = column;
|
|
|
|
}
|
2022-09-13 11:38:14 +03:00
|
|
|
|
|
|
|
@action
|
|
|
|
loadData() {
|
|
|
|
this.dashboardStats.loadMemberAttributionStats();
|
|
|
|
}
|
|
|
|
|
2022-09-29 08:33:07 +03:00
|
|
|
get allowedDisplayOptions() {
|
|
|
|
if (!this.hasPaidConversionData) {
|
|
|
|
return this.displayOptions.filter(d => d.value === 'signups');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.hasFreeSignups) {
|
|
|
|
return this.displayOptions.filter(d => d.value === 'paid');
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.displayOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
get isDropdownDisabled() {
|
|
|
|
if (!this.hasPaidConversionData || !this.hasFreeSignups) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-28 13:57:44 +03:00
|
|
|
get selectedDisplayOption() {
|
2022-09-29 08:33:07 +03:00
|
|
|
if (!this.hasPaidConversionData) {
|
|
|
|
return this.displayOptions.find(d => d.value === 'signups');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.hasFreeSignups) {
|
|
|
|
return this.displayOptions.find(d => d.value === 'paid');
|
|
|
|
}
|
|
|
|
|
2022-09-28 13:57:44 +03:00
|
|
|
return this.displayOptions.find(d => d.value === this.sortColumn) ?? this.displayOptions[0];
|
|
|
|
}
|
|
|
|
|
2022-09-29 08:33:07 +03:00
|
|
|
get selectedSortColumn() {
|
|
|
|
if (!this.hasPaidConversionData) {
|
|
|
|
return 'signups';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.hasFreeSignups) {
|
|
|
|
return 'paid';
|
|
|
|
}
|
|
|
|
return this.sortColumn;
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasPaidConversionData() {
|
|
|
|
return this.sources.some(sourceData => sourceData.paidConversions > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasFreeSignups() {
|
|
|
|
return this.sources.some(sourceData => sourceData.signups > 0);
|
|
|
|
}
|
|
|
|
|
2022-09-13 11:38:14 +03:00
|
|
|
get sources() {
|
2022-09-19 11:48:24 +03:00
|
|
|
return this.dashboardStats?.memberSourceAttributionCounts || [];
|
2022-09-13 11:38:14 +03:00
|
|
|
}
|
|
|
|
|
2022-09-29 07:35:24 +03:00
|
|
|
// chartDays value for more than 7 days has an extra day to show all ticks
|
|
|
|
get chartPeriod() {
|
|
|
|
if (this.dashboardStats.chartDays > 7) {
|
|
|
|
return this.dashboardStats.chartDays - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.dashboardStats.chartDays;
|
|
|
|
}
|
|
|
|
|
2022-09-22 18:34:46 +03:00
|
|
|
get chartSources() {
|
|
|
|
const counts = this.dashboardStats?.memberSourceAttributionCounts || [];
|
|
|
|
// filter null source from the list
|
|
|
|
return counts.filter(source => source.source);
|
|
|
|
}
|
|
|
|
|
2022-09-13 11:38:14 +03:00
|
|
|
get areMembersEnabled() {
|
|
|
|
return this.dashboardStats.siteStatus?.membersEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
get areNewslettersEnabled() {
|
|
|
|
return this.dashboardStats.siteStatus?.newslettersEnabled;
|
|
|
|
}
|
|
|
|
}
|