Ghost/ghost/admin/app/routes/member.js
Sanne de Vries 2453f6afbd Added activity feed to member details screen (#1796)
closes https://github.com/TryGhost/Ghost/issues/12461

Design changes:
- added activity feed to member details page
- rearranged Stripe info to display on the right
- added toggle buttons for Stripe subscription and customer info
- added box to display activity feed for received and opened emails

Functionality changes:
- added `queryRecord()` to member adapter so `queryRecord('member', {id: x})` will hit `/members/:id/?query` instead of `/members/?id=x&query`
- updated member route to query member with `?include=email_recipients`
- added `EmailRecipient` model for access to event timestamps and email relationship setup
- added `<GhMemberActivityFeed>` component that accepts an `EmailRecipient` array and converts that into an activity list
- added support for `@model=emailInstance` to the email preview modal
- fixed a timing issue with email preview that could result in it showing blank content until the mobile/desktop toggle is used
- fixed sometimes blank member location

Co-authored-by: Kevin Ansfield <kevin@lookingsideways.co.uk>
2020-12-10 11:38:38 +00:00

76 lines
2.2 KiB
JavaScript

import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import classic from 'ember-classic-decorator';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
@classic
export default class MembersRoute extends AuthenticatedRoute {
@service router;
_requiresBackgroundRefresh = true;
init() {
super.init(...arguments);
this.router.on('routeWillChange', (transition) => {
this.showUnsavedChangesModal(transition);
});
}
beforeModel() {
super.beforeModel(...arguments);
return this.session.user.then((user) => {
if (!user.isOwnerOrAdmin) {
return this.transitionTo('home');
}
});
}
model(params) {
this._requiresBackgroundRefresh = false;
if (params.member_id) {
return this.store.queryRecord('member', {id: params.member_id, include: 'email_recipients'});
} else {
return this.store.createRecord('member');
}
}
setupController(controller, member) {
super.setupController(...arguments);
if (this._requiresBackgroundRefresh) {
controller.fetchMemberTask.perform(member.get('id'));
}
}
deactivate() {
super.deactivate(...arguments);
// clean up newly created records and revert unsaved changes to existing
this.controller.member.rollbackAttributes();
this._requiresBackgroundRefresh = true;
}
@action
save() {
this.controller.save();
}
titleToken() {
return this.controller.member.name;
}
showUnsavedChangesModal(transition) {
if (transition.from && transition.from.name === this.routeName && transition.targetName) {
let {controller} = this;
// member.changedAttributes is always true for new members but number of changed attrs is reliable
let isChanged = Object.keys(controller.member.changedAttributes()).length > 0;
if (!controller.member.isDeleted && isChanged) {
transition.abort();
controller.toggleUnsavedChangesModal(transition);
return;
}
}
}
}