2023-09-04 15:55:51 +02:00
|
|
|
import { action, set } from "@ember/object";
|
|
|
|
import { inject as service } from "@ember/service";
|
|
|
|
import Component from "@glimmer/component";
|
|
|
|
import { tracked } from "@glimmer/tracking";
|
2023-09-08 11:54:41 +02:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2023-09-22 09:17:52 +02:00
|
|
|
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-22 09:17:52 +02:00
|
|
|
basePath = "/admin/plugins/subscription-client/suppliers";
|
|
|
|
|
2023-09-04 15:55:51 +02:00
|
|
|
@service siteSettings;
|
2023-09-22 09:17:52 +02:00
|
|
|
|
2023-09-08 11:54:41 +02:00
|
|
|
@tracked supplierId = null;
|
2023-09-08 20:14:36 +02:00
|
|
|
@tracked authorized = false;
|
2023-09-22 09:17:52 +02:00
|
|
|
@tracked unauthorizing = false;
|
2023-09-04 15:55:51 +02:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
2023-09-22 09:17:52 +02:00
|
|
|
ajax("/admin/plugins/subscription-client/suppliers?final_landing_path%3D%2Fadmin%2Fwizards%2Fwizard").then((result) => {
|
2023-09-08 20:14:36 +02:00
|
|
|
this.supplierId = result.suppliers[0].id;
|
|
|
|
this.authorized = result.suppliers[0].authorized;
|
|
|
|
})
|
2023-09-04 15:55:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
authorize() {
|
2023-09-22 09:17:52 +02:00
|
|
|
window.location.href = `${this.basePath}/authorize?supplier_id=${this.supplierId}`;
|
2023-09-04 15:55:51 +02:00
|
|
|
}
|
2023-09-22 09:17:52 +02:00
|
|
|
|
|
|
|
@action
|
|
|
|
deauthorize() {
|
|
|
|
this.unauthorizing = true;
|
|
|
|
|
|
|
|
ajax(`${this.basePath}/authorize`, {
|
|
|
|
type: "DELETE",
|
|
|
|
data: {
|
|
|
|
supplier_id: this.supplierId,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then((result) => {
|
2023-09-22 11:20:22 +02:00
|
|
|
console.log(result);
|
2023-09-22 09:17:52 +02:00
|
|
|
this.supplierId = result.suppliers[0].id;
|
|
|
|
this.authorized = result.suppliers[0].authorized;
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.unauthorizing = false;
|
2023-09-22 15:05:05 +02:00
|
|
|
window.location.reload();
|
2023-09-22 09:17:52 +02:00
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
};
|
2023-09-04 15:55:51 +02:00
|
|
|
}
|