2022-01-31 21:26:12 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {inject as service} from '@ember/service';
|
2022-02-09 13:49:38 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2022-01-31 21:26:12 +03:00
|
|
|
|
2022-03-14 13:52:04 +03:00
|
|
|
export default class ArchiveTierModal extends Component {
|
2022-01-31 21:26:12 +03:00
|
|
|
@service notifications;
|
|
|
|
@service router;
|
|
|
|
|
|
|
|
get isActive() {
|
|
|
|
const {product} = this.args.data;
|
|
|
|
return !!product.active;
|
|
|
|
}
|
|
|
|
|
|
|
|
@task({drop: true})
|
|
|
|
*archiveTierTask() {
|
2022-03-09 10:35:07 +03:00
|
|
|
const {product, onArchive} = this.args.data;
|
2022-01-31 21:26:12 +03:00
|
|
|
product.active = false;
|
2022-03-09 10:35:07 +03:00
|
|
|
product.visibility = 'none';
|
2022-01-31 21:26:12 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
yield product.save();
|
2022-03-09 10:35:07 +03:00
|
|
|
onArchive?.();
|
2022-01-31 21:26:12 +03:00
|
|
|
return product;
|
|
|
|
} catch (error) {
|
|
|
|
if (error) {
|
|
|
|
this.notifications.showAPIError(error, {key: 'tier.archive.failed'});
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
this.args.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|