Ghost/ghost/admin/app/components/dashboard/latest-member-activity.js
Kevin Ansfield 4b3fc52cf0 Extracted dashboard member activity into separate component
refs https://github.com/TryGhost/Team/issues/1277

- first step of further refactoring to make member activity display more generic
- separates component data loading from overall controller logic and allows it to be tested in integration tests as well as acceptance tests
2022-01-18 15:16:22 +00:00

47 lines
1.2 KiB
JavaScript

import Component from '@glimmer/component';
import {inject as service} from '@ember/service';
import {tracked} from '@glimmer/tracking';
export default class DashboardLatestMemberActivityComponent extends Component {
@service membersActivity;
@service session;
@service settings;
@tracked eventsData = null;
@tracked eventsError = null;
@tracked eventsLoading = false;
get shouldDisplay() {
const isOwner = this.session.user?.isOwnerOnly;
const hasCompletedLaunchWizard = this.settings.get('editorIsLaunchComplete');
console.log(this.session.user, {isOwner, hasCompletedLaunchWizard});
if (isOwner && !hasCompletedLaunchWizard) {
return false;
}
return true;
}
constructor() {
super(...arguments);
if (this.shouldDisplay) {
this.loadEvents();
}
}
async loadEvents() {
try {
this.eventsLoading = true;
const {events} = await this.membersActivity.fetchTimeline({limit: 5});
this.eventsData = events;
} catch (error) {
this.eventsError = error;
} finally {
this.eventsLoading = false;
}
}
}