Updated member management data (#1150)

no issue

- Updated hard-coded data in member management to use real values from API
This commit is contained in:
Rishabh Garg 2019-04-16 20:32:43 +05:30 committed by GitHub
parent 7c1ba31781
commit c72e7b6040
6 changed files with 93 additions and 5 deletions

View File

@ -1,14 +1,29 @@
import Controller from '@ember/controller';
import {alias} from '@ember/object/computed';
import {computed} from '@ember/object';
import {inject as controller} from '@ember/controller';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
export default Controller.extend({
members: controller(),
store: service(),
router: service(),
member: alias('model'),
subscription: computed('member.subscriptions', function () {
let subscriptions = this.member.get('subscriptions') || [];
let subscription = subscriptions[0] || {};
return {
amount: subscription.amount ? (subscription.amount / 100) : '-',
status: subscription.status || '-',
plan: subscription.plan || '-'
};
}),
actions: {
finaliseDeletion() {
// decrememnt the total member count manually so there's no flash
@ -18,5 +33,14 @@ export default Controller.extend({
}
this.router.transitionTo('members');
}
}
},
fetchMember: task(function* (memberId) {
yield this.store.findRecord('member', memberId, {
reload: true
}).then((data) => {
this.set('member', data);
});
})
});

View File

@ -0,0 +1,9 @@
import EmberObject from '@ember/object';
export default EmberObject.extend({
adapter: '',
amount: 0,
plan: '',
status: '',
validUntil: 0
});

View File

@ -4,5 +4,6 @@ import attr from 'ember-data/attr';
export default DS.Model.extend({
name: attr('string'),
email: attr('string'),
createdAt: attr('moment-utc')
createdAt: attr('moment-utc'),
subscriptions: attr('member-subscription')
});

View File

@ -1,7 +1,26 @@
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
export default AuthenticatedRoute.extend({
// TODO: add model method to load member if not passed in
model(params) {
this._isMemberUpdated = true;
return this.store.findRecord('member', params.member_id, {
reload: true
});
},
setupController(controller, model) {
this._super(...arguments);
if (!this._isMemberUpdated) {
controller.fetchMember.perform(model.get('id'));
}
},
deactivate() {
this._super(...arguments);
// clear the properties
this._isMemberUpdated = false;
},
titleToken() {
return this.controller.get('member.name');

View File

@ -32,8 +32,8 @@
</div>
<div class="flex flex-column flex-grow-1 pa5">
<span class="db ttu f8 midlightgrey">Current plan</span>
<span class="db f5">Monthly</span>
<span class="db f8 midlightgrey">6 USD/month</span>
<span class="db f5">{{subscription.plan}}</span>
<span class="db f8 midlightgrey">{{subscription.amount}} USD/month</span>
</div>
</div>

View File

@ -0,0 +1,35 @@
import MemberSubscription from 'ghost-admin/models/member-subscription';
import Transform from 'ember-data/transform';
import {A as emberA, isArray as isEmberArray} from '@ember/array';
export default Transform.extend({
deserialize(serialized) {
let subscriptions, subscriptionArray;
subscriptionArray = serialized || [];
subscriptions = subscriptionArray.map(itemDetails => MemberSubscription.create(itemDetails));
return emberA(subscriptions);
},
serialize(deserialized) {
let subscriptionArray;
if (isEmberArray(deserialized)) {
subscriptionArray = deserialized.map((item) => {
let adapter = item.get('adapter').trim();
let amount = item.get('amount');
let plan = item.get('plan').trim();
let status = item.get('status').trim();
let validUntil = item.get('validUntil');
return {adapter, amount, plan, status, validUntil};
}).compact();
} else {
subscriptionArray = [];
}
return subscriptionArray;
}
});