Replaced usage of older MRR stats endpoint with new endpoint

refs https://github.com/TryGhost/Team/issues/1470

- Correctly uses the highest value currency in the MRR graph
This commit is contained in:
Simon Backx 2022-04-08 09:51:30 +02:00
parent 738dbba82a
commit 0d7ada66b3

View File

@ -325,13 +325,26 @@ export default class DashboardStatsService extends Service {
return;
}
let statsUrl = this.ghostPaths.url.api('members/stats/mrr');
let statsUrl = this.ghostPaths.url.api('stats/mrr');
let stats = yield this.ajax.request(statsUrl);
// @todo: add proper support for all different currencies that are returned
this.mrrStats = stats.data[0].data.map((d) => {
return {date: d.date, mrr: d.value};
});
// Only show the highest value currency and filter the other ones out
const totals = stats.meta.totals;
let currentMax = totals[0];
if (!currentMax) {
// No valid data
this.mrrStats = [];
return;
}
for (const total of totals) {
if (total.mrr > currentMax.mrr) {
currentMax = total;
}
}
const useCurrency = currentMax.currency;
this.mrrStats = stats.stats.filter(d => d.currency === useCurrency);
}
loadLastSeen() {