2019-02-18 21:28:23 +01:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
import { Organization } from 'jslib-common/models/domain/organization';
|
2021-06-07 20:13:58 +02:00
|
|
|
import { OrganizationSubscriptionResponse } from 'jslib-common/models/response/organizationSubscriptionResponse';
|
2019-02-18 21:28:23 +01:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiService } from 'jslib-common/abstractions/api.service';
|
|
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
|
|
|
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
|
|
|
|
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
|
2019-02-18 21:28:23 +01:00
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
import { UserService } from 'jslib-common/abstractions';
|
2021-06-07 20:13:58 +02:00
|
|
|
import { PlanType } from 'jslib-common/enums/planType';
|
2019-02-18 21:28:23 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-org-subscription',
|
|
|
|
templateUrl: 'organization-subscription.component.html',
|
|
|
|
})
|
|
|
|
export class OrganizationSubscriptionComponent implements OnInit {
|
|
|
|
loading = false;
|
|
|
|
firstLoaded = false;
|
|
|
|
organizationId: string;
|
|
|
|
adjustSeatsAdd = true;
|
|
|
|
showAdjustSeats = false;
|
|
|
|
adjustStorageAdd = true;
|
|
|
|
showAdjustStorage = false;
|
|
|
|
showUpdateLicense = false;
|
2019-03-20 14:56:50 +01:00
|
|
|
showDownloadLicense = false;
|
2019-03-20 15:11:51 +01:00
|
|
|
showChangePlan = false;
|
2019-02-18 21:28:23 +01:00
|
|
|
sub: OrganizationSubscriptionResponse;
|
|
|
|
selfHosted = false;
|
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
userOrg: Organization;
|
|
|
|
|
2019-02-18 21:28:23 +01:00
|
|
|
cancelPromise: Promise<any>;
|
|
|
|
reinstatePromise: Promise<any>;
|
|
|
|
|
2020-08-12 23:16:38 +02:00
|
|
|
constructor(private apiService: ApiService, private platformUtilsService: PlatformUtilsService,
|
2021-04-14 23:43:40 +02:00
|
|
|
private i18nService: I18nService, private toasterService: ToasterService,
|
2021-07-21 11:32:27 +02:00
|
|
|
private messagingService: MessagingService, private route: ActivatedRoute,
|
|
|
|
private userService: UserService) {
|
2019-02-18 21:28:23 +01:00
|
|
|
this.selfHosted = platformUtilsService.isSelfHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
async ngOnInit() {
|
2021-02-03 18:41:33 +01:00
|
|
|
this.route.parent.parent.params.subscribe(async params => {
|
2019-02-18 21:28:23 +01:00
|
|
|
this.organizationId = params.organizationId;
|
|
|
|
await this.load();
|
|
|
|
this.firstLoaded = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async load() {
|
|
|
|
if (this.loading) {
|
|
|
|
return;
|
|
|
|
}
|
2021-07-21 11:32:27 +02:00
|
|
|
|
2019-02-18 21:28:23 +01:00
|
|
|
this.loading = true;
|
2021-07-21 11:32:27 +02:00
|
|
|
this.userOrg = await this.userService.getOrganization(this.organizationId);
|
2019-02-18 21:28:23 +01:00
|
|
|
this.sub = await this.apiService.getOrganizationSubscription(this.organizationId);
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
async reinstate() {
|
|
|
|
if (this.loading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const confirmed = await this.platformUtilsService.showDialog(this.i18nService.t('reinstateConfirmation'),
|
|
|
|
this.i18nService.t('reinstateSubscription'), this.i18nService.t('yes'), this.i18nService.t('cancel'));
|
|
|
|
if (!confirmed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.reinstatePromise = this.apiService.postOrganizationReinstate(this.organizationId);
|
|
|
|
await this.reinstatePromise;
|
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('reinstated'));
|
|
|
|
this.load();
|
|
|
|
} catch { }
|
|
|
|
}
|
|
|
|
|
|
|
|
async cancel() {
|
|
|
|
if (this.loading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const confirmed = await this.platformUtilsService.showDialog(this.i18nService.t('cancelConfirmation'),
|
|
|
|
this.i18nService.t('cancelSubscription'), this.i18nService.t('yes'), this.i18nService.t('no'), 'warning');
|
|
|
|
if (!confirmed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.cancelPromise = this.apiService.postOrganizationCancel(this.organizationId);
|
|
|
|
await this.cancelPromise;
|
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('canceledSubscription'));
|
|
|
|
this.load();
|
|
|
|
} catch { }
|
|
|
|
}
|
|
|
|
|
|
|
|
async changePlan() {
|
2019-04-17 17:06:21 +02:00
|
|
|
if (this.subscription == null && this.sub.planType === PlanType.Free) {
|
2019-03-20 15:11:51 +01:00
|
|
|
this.showChangePlan = !this.showChangePlan;
|
|
|
|
return;
|
|
|
|
}
|
2019-02-18 21:28:23 +01:00
|
|
|
const contactSupport = await this.platformUtilsService.showDialog(this.i18nService.t('changeBillingPlanDesc'),
|
|
|
|
this.i18nService.t('changeBillingPlan'), this.i18nService.t('contactSupport'), this.i18nService.t('close'));
|
|
|
|
if (contactSupport) {
|
|
|
|
this.platformUtilsService.launchUri('https://bitwarden.com/contact');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-20 15:11:51 +01:00
|
|
|
closeChangePlan(changed: boolean) {
|
|
|
|
this.showChangePlan = false;
|
|
|
|
}
|
|
|
|
|
2019-03-20 14:56:50 +01:00
|
|
|
downloadLicense() {
|
|
|
|
this.showDownloadLicense = !this.showDownloadLicense;
|
|
|
|
}
|
2019-02-18 21:28:23 +01:00
|
|
|
|
2019-03-20 14:56:50 +01:00
|
|
|
closeDownloadLicense() {
|
|
|
|
this.showDownloadLicense = false;
|
2019-02-18 21:28:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
updateLicense() {
|
|
|
|
if (this.loading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.showUpdateLicense = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
closeUpdateLicense(updated: boolean) {
|
|
|
|
this.showUpdateLicense = false;
|
|
|
|
if (updated) {
|
|
|
|
this.load();
|
|
|
|
this.messagingService.send('updatedOrgLicense');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
adjustSeats(add: boolean) {
|
|
|
|
this.adjustSeatsAdd = add;
|
|
|
|
this.showAdjustSeats = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
closeSeats(load: boolean) {
|
|
|
|
this.showAdjustSeats = false;
|
|
|
|
if (load) {
|
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
adjustStorage(add: boolean) {
|
|
|
|
this.adjustStorageAdd = add;
|
|
|
|
this.showAdjustStorage = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
closeStorage(load: boolean) {
|
|
|
|
this.showAdjustStorage = false;
|
|
|
|
if (load) {
|
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get isExpired() {
|
|
|
|
return this.sub != null && this.sub.expiration != null &&
|
|
|
|
new Date(this.sub.expiration) < new Date();
|
|
|
|
}
|
|
|
|
|
|
|
|
get subscriptionMarkedForCancel() {
|
|
|
|
return this.subscription != null && !this.subscription.cancelled && this.subscription.cancelAtEndDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
get subscription() {
|
|
|
|
return this.sub != null ? this.sub.subscription : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
get nextInvoice() {
|
|
|
|
return this.sub != null ? this.sub.upcomingInvoice : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
get storagePercentage() {
|
|
|
|
return this.sub != null && this.sub.maxStorageGb ?
|
|
|
|
+(100 * (this.sub.storageGb / this.sub.maxStorageGb)).toFixed(2) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get storageProgressWidth() {
|
|
|
|
return this.storagePercentage < 5 ? 5 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get billingInterval() {
|
2020-08-12 23:16:38 +02:00
|
|
|
const monthly = !this.sub.plan.isAnnual;
|
2019-02-18 21:28:23 +01:00
|
|
|
return monthly ? 'month' : 'year';
|
|
|
|
}
|
|
|
|
|
|
|
|
get storageGbPrice() {
|
2020-08-12 23:16:38 +02:00
|
|
|
return this.sub.plan.additionalStoragePricePerGb;
|
2019-02-18 21:28:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get seatPrice() {
|
2020-08-12 23:16:38 +02:00
|
|
|
return this.sub.plan.seatPrice;
|
2019-02-18 21:28:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get canAdjustSeats() {
|
2020-08-12 23:16:38 +02:00
|
|
|
return this.sub.plan.hasAdditionalSeatsOption;
|
2019-02-18 21:28:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get canDownloadLicense() {
|
|
|
|
return (this.sub.planType !== PlanType.Free && this.subscription == null) ||
|
|
|
|
(this.subscription != null && !this.subscription.cancelled);
|
|
|
|
}
|
|
|
|
}
|