0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-24 02:10:29 +01:00
discourse-custom-wizard/assets/javascripts/discourse/components/wizard-subscription-status.js

58 Zeilen
1,6 KiB
JavaScript

2023-09-04 15:55:51 +02:00
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
2024-11-22 17:11:51 +01:00
import { action } from "@ember/object";
import { service } from "@ember/service";
2023-09-08 11:54:41 +02:00
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
2023-09-04 15:55:51 +02:00
2023-09-22 15:05:05 +02:00
export default class WizardSubscriptionStatus extends Component {
2023-09-04 15:55:51 +02:00
@service siteSettings;
2023-09-23 23:52:46 +02:00
@service subscription;
2023-09-08 11:54:41 +02:00
@tracked supplierId = null;
2023-09-08 20:14:36 +02:00
@tracked authorized = false;
@tracked unauthorizing = false;
2023-09-22 15:38:06 +02:00
basePath = "/admin/plugins/subscription-client/suppliers";
2023-09-04 15:55:51 +02:00
constructor() {
super(...arguments);
ajax(`${this.basePath}?resource=discourse-custom-wizard`)
2023-09-24 12:58:20 +02:00
.then((result) => {
if (result.suppliers && result.suppliers.length) {
this.supplierId = result.suppliers[0].id;
this.authorized = result.suppliers[0].authorized;
}
2023-09-24 12:58:20 +02:00
})
.finally(() => {
this.subscription.retrieveSubscriptionStatus();
});
2023-09-04 15:55:51 +02:00
}
@action
authorize() {
2023-09-22 12:02:44 +02:00
window.location.href = `${this.basePath}/authorize?supplier_id=${this.supplierId}&final_landing_path=/admin/wizards/wizard`;
2023-09-04 15:55:51 +02:00
}
@action
deauthorize() {
this.unauthorizing = true;
ajax(`${this.basePath}/authorize`, {
2023-09-22 15:35:50 +02:00
type: "DELETE",
data: {
supplier_id: this.supplierId,
},
})
.then((result) => {
if (result.success) {
this.supplierId = result.supplier_id;
this.authorized = false;
}
})
.finally(() => {
this.unauthorizing = false;
2023-09-23 23:52:46 +02:00
this.subscription.retrieveSubscriptionStatus();
})
.catch(popupAjaxError);
2023-09-22 15:35:50 +02:00
}
2023-09-04 15:55:51 +02:00
}