mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03:00
2453f6afbd
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>
98 lines
3.3 KiB
JavaScript
98 lines
3.3 KiB
JavaScript
import Component from '@ember/component';
|
|
import moment from 'moment';
|
|
import {action} from '@ember/object';
|
|
import {computed} from '@ember/object';
|
|
import {gt} from '@ember/object/computed';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default Component.extend({
|
|
membersUtils: service(),
|
|
feature: service(),
|
|
config: service(),
|
|
mediaQueries: service(),
|
|
ghostPaths: service(),
|
|
ajax: service(),
|
|
store: service(),
|
|
|
|
stripeDetailsType: 'subscription',
|
|
|
|
// Allowed actions
|
|
setProperty: () => {},
|
|
|
|
hasMultipleSubscriptions: gt('member.stripe', 1),
|
|
|
|
canShowStripeInfo: computed('member.isNew', 'membersUtils.isStripeEnabled', function () {
|
|
let stripeEnabled = this.membersUtils.isStripeEnabled;
|
|
|
|
if (this.member.get('isNew') || !stripeEnabled) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}),
|
|
|
|
subscriptions: computed('member.stripe', function () {
|
|
let subscriptions = this.member.get('stripe');
|
|
if (subscriptions && subscriptions.length > 0) {
|
|
return subscriptions.map((subscription) => {
|
|
const statusLabel = subscription.status ? subscription.status.replace('_', ' ') : '';
|
|
return {
|
|
id: subscription.id,
|
|
customer: subscription.customer,
|
|
name: subscription.name || '',
|
|
email: subscription.email || '',
|
|
status: subscription.status,
|
|
statusLabel: statusLabel,
|
|
startDate: subscription.start_date ? moment(subscription.start_date).format('D MMM YYYY') : '-',
|
|
plan: subscription.plan,
|
|
amount: parseInt(subscription.plan.amount) ? (subscription.plan.amount / 100) : 0,
|
|
cancelAtPeriodEnd: subscription.cancel_at_period_end,
|
|
cancellationReason: subscription.cancellation_reason,
|
|
validUntil: subscription.current_period_end ? moment(subscription.current_period_end).format('D MMM YYYY') : '-'
|
|
};
|
|
}).reverse();
|
|
}
|
|
return null;
|
|
}),
|
|
|
|
actions: {
|
|
setProperty(property, value) {
|
|
this.setProperty(property, value);
|
|
},
|
|
setLabels(labels) {
|
|
this.member.set('labels', labels);
|
|
}
|
|
},
|
|
|
|
changeStripeDetailsType: action(function (type) {
|
|
this.set('stripeDetailsType', type);
|
|
}),
|
|
|
|
cancelSubscription: task(function* (subscriptionId) {
|
|
let url = this.get('ghostPaths.url').api('members', this.member.get('id'), 'subscriptions', subscriptionId);
|
|
|
|
let response = yield this.ajax.put(url, {
|
|
data: {
|
|
cancel_at_period_end: true
|
|
}
|
|
});
|
|
|
|
this.store.pushPayload('member', response);
|
|
return response;
|
|
}).drop(),
|
|
|
|
continueSubscription: task(function* (subscriptionId) {
|
|
let url = this.get('ghostPaths.url').api('members', this.member.get('id'), 'subscriptions', subscriptionId);
|
|
|
|
let response = yield this.ajax.put(url, {
|
|
data: {
|
|
cancel_at_period_end: false
|
|
}
|
|
});
|
|
|
|
this.store.pushPayload('member', response);
|
|
return response;
|
|
}).drop()
|
|
});
|