diff --git a/jslib b/jslib
index de9bcac0..4f876fc2 160000
--- a/jslib
+++ b/jslib
@@ -1 +1 @@
-Subproject commit de9bcac0ec9f4429c17af4b952f58a2054aad02e
+Subproject commit 4f876fc222a0b6b5156139f43a4623f6fa083465
diff --git a/src/app/organizations/settings/adjust-seats.component.html b/src/app/organizations/settings/adjust-seats.component.html
index e07179be..c41e4d0f 100644
--- a/src/app/organizations/settings/adjust-seats.component.html
+++ b/src/app/organizations/settings/adjust-seats.component.html
@@ -26,3 +26,4 @@
+
diff --git a/src/app/organizations/settings/adjust-seats.component.ts b/src/app/organizations/settings/adjust-seats.component.ts
index ef61f309..2ca0a5fb 100644
--- a/src/app/organizations/settings/adjust-seats.component.ts
+++ b/src/app/organizations/settings/adjust-seats.component.ts
@@ -3,6 +3,7 @@ import {
EventEmitter,
Input,
Output,
+ ViewChild,
} from '@angular/core';
import { ToasterService } from 'angular2-toaster';
@@ -13,6 +14,8 @@ import { I18nService } from 'jslib/abstractions/i18n.service';
import { SeatRequest } from 'jslib/models/request/seatRequest';
+import { PaymentComponent } from '../../settings/payment.component';
+
@Component({
selector: 'app-adjust-seats',
templateUrl: 'adjust-seats.component.html',
@@ -25,6 +28,8 @@ export class AdjustSeatsComponent {
@Output() onAdjusted = new EventEmitter();
@Output() onCanceled = new EventEmitter();
+ @ViewChild(PaymentComponent) paymentComponent: PaymentComponent;
+
seatAdjustment = 0;
formPromise: Promise;
@@ -39,12 +44,27 @@ export class AdjustSeatsComponent {
request.seatAdjustment *= -1;
}
- this.formPromise = this.apiService.postOrganizationSeat(this.organizationId, request);
+ let paymentFailed = false;
+ const action = async () => {
+ const result = await this.apiService.postOrganizationSeat(this.organizationId, request);
+ if (result != null && result.paymentIntentClientSecret != null) {
+ try {
+ await this.paymentComponent.handleStripeCardPayment(result.paymentIntentClientSecret, null);
+ } catch {
+ paymentFailed = true;
+ }
+ }
+ };
+ this.formPromise = action();
await this.formPromise;
this.analytics.eventTrack.next({ action: this.add ? 'Added Seats' : 'Removed Seats' });
- this.toasterService.popAsync('success', null,
- this.i18nService.t('adjustedSeats', request.seatAdjustment.toString()));
this.onAdjusted.emit(this.seatAdjustment);
+ if (paymentFailed) {
+ // TODO: Go to billing page
+ } else {
+ this.toasterService.popAsync('success', null,
+ this.i18nService.t('adjustedSeats', request.seatAdjustment.toString()));
+ }
} catch { }
}
diff --git a/src/app/settings/adjust-storage.component.ts b/src/app/settings/adjust-storage.component.ts
index dde64552..49f1e6ab 100644
--- a/src/app/settings/adjust-storage.component.ts
+++ b/src/app/settings/adjust-storage.component.ts
@@ -33,7 +33,7 @@ export class AdjustStorageComponent {
@ViewChild(PaymentComponent) paymentComponent: PaymentComponent;
storageAdjustment = 0;
- formPromise: Promise;
+ formPromise: Promise;
constructor(private apiService: ApiService, private i18nService: I18nService,
private analytics: Angulartics2, private toasterService: ToasterService) { }
@@ -46,19 +46,33 @@ export class AdjustStorageComponent {
request.storageGbAdjustment *= -1;
}
- if (this.organizationId == null) {
- this.formPromise = this.apiService.postAccountStorage(request);
- } else {
- this.formPromise = this.apiService.postOrganizationStorage(this.organizationId, request);
- }
- const result = await this.formPromise;
- if (result != null && result.paymentIntentClientSecret != null) {
- await this.paymentComponent.handleStripeCardPayment(result.paymentIntentClientSecret, null);
- }
+ let paymentFailed = false;
+ const action = async () => {
+ let response: Promise;
+ if (this.organizationId == null) {
+ response = this.formPromise = this.apiService.postAccountStorage(request);
+ } else {
+ response = this.formPromise = this.apiService.postOrganizationStorage(this.organizationId, request);
+ }
+ const result = await response;
+ if (result != null && result.paymentIntentClientSecret != null) {
+ try {
+ await this.paymentComponent.handleStripeCardPayment(result.paymentIntentClientSecret, null);
+ } catch {
+ paymentFailed = true;
+ }
+ }
+ };
+ this.formPromise = action();
+ await this.formPromise;
this.analytics.eventTrack.next({ action: this.add ? 'Added Storage' : 'Removed Storage' });
- this.toasterService.popAsync('success', null,
- this.i18nService.t('adjustedStorage', request.storageGbAdjustment.toString()));
this.onAdjusted.emit(this.storageAdjustment);
+ if (paymentFailed) {
+ // TOOD: go to billing page
+ } else {
+ this.toasterService.popAsync('success', null,
+ this.i18nService.t('adjustedStorage', request.storageGbAdjustment.toString()));
+ }
} catch { }
}