Ghost/ghost/admin/app/components/gh-membership-products-alpha.js
Rishabh 498efd00cb Refined tiers list to switch to active list on unarchive
refs https://github.com/TryGhost/Team/issues/1252

- on unarchiving a tier, we switch back to active tier list instead of staying back on archived list
2022-02-02 16:24:20 +05:30

81 lines
1.7 KiB
JavaScript

import Component from '@glimmer/component';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
import {tracked} from '@glimmer/tracking';
const TYPES = [{
name: 'Active',
value: 'active'
},{
name: 'Archived',
value: 'archived'
}];
export default class extends Component {
@service membersUtils;
@service ghostPaths;
@service ajax;
@service store;
@service config;
@tracked showProductModal = false;
@tracked productModel = null;
@tracked type = 'active';
get products() {
return this.args.products.filter((product) => {
if (this.type === 'active') {
return !!product.active;
} else if (this.type === 'archived') {
return !product.active;
}
});
}
get availableTypes() {
return TYPES;
}
get selectedType() {
return this.type ? TYPES.find((d) => {
return this.type === d.value;
}) : TYPES[0];
}
get isEmptyList() {
return this.products.length === 0;
}
@action
onTypeChange(type) {
this.type = type.value;
}
@action
async openEditProduct(product) {
this.productModel = product;
this.showProductModal = true;
}
@action
async onUnarchive() {
this.type = 'active';
}
@action
async openNewProduct() {
this.productModel = this.store.createRecord('product');
this.showProductModal = true;
}
@action
closeProductModal() {
this.showProductModal = false;
}
@action
confirmProductSave() {
this.args.confirmProductSave();
}
}