handle seats and storage adjustment for sca
This commit is contained in:
parent
80c5dff5ad
commit
8bafbbd2ff
2
jslib
2
jslib
|
@ -1 +1 @@
|
|||
Subproject commit de9bcac0ec9f4429c17af4b952f58a2054aad02e
|
||||
Subproject commit 4f876fc222a0b6b5156139f43a4623f6fa083465
|
|
@ -26,3 +26,4 @@
|
|||
</small>
|
||||
</div>
|
||||
</form>
|
||||
<app-payment [showMethods]="false"></app-payment>
|
||||
|
|
|
@ -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<number>();
|
||||
@Output() onCanceled = new EventEmitter();
|
||||
|
||||
@ViewChild(PaymentComponent) paymentComponent: PaymentComponent;
|
||||
|
||||
seatAdjustment = 0;
|
||||
formPromise: Promise<any>;
|
||||
|
||||
|
@ -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.onAdjusted.emit(this.seatAdjustment);
|
||||
if (paymentFailed) {
|
||||
// TODO: Go to billing page
|
||||
} else {
|
||||
this.toasterService.popAsync('success', null,
|
||||
this.i18nService.t('adjustedSeats', request.seatAdjustment.toString()));
|
||||
this.onAdjusted.emit(this.seatAdjustment);
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ export class AdjustStorageComponent {
|
|||
@ViewChild(PaymentComponent) paymentComponent: PaymentComponent;
|
||||
|
||||
storageAdjustment = 0;
|
||||
formPromise: Promise<PaymentResponse>;
|
||||
formPromise: Promise<any>;
|
||||
|
||||
constructor(private apiService: ApiService, private i18nService: I18nService,
|
||||
private analytics: Angulartics2, private toasterService: ToasterService) { }
|
||||
|
@ -46,19 +46,33 @@ export class AdjustStorageComponent {
|
|||
request.storageGbAdjustment *= -1;
|
||||
}
|
||||
|
||||
let paymentFailed = false;
|
||||
const action = async () => {
|
||||
let response: Promise<PaymentResponse>;
|
||||
if (this.organizationId == null) {
|
||||
this.formPromise = this.apiService.postAccountStorage(request);
|
||||
response = this.formPromise = this.apiService.postAccountStorage(request);
|
||||
} else {
|
||||
this.formPromise = this.apiService.postOrganizationStorage(this.organizationId, request);
|
||||
response = this.formPromise = this.apiService.postOrganizationStorage(this.organizationId, request);
|
||||
}
|
||||
const result = await this.formPromise;
|
||||
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.onAdjusted.emit(this.storageAdjustment);
|
||||
if (paymentFailed) {
|
||||
// TOOD: go to billing page
|
||||
} else {
|
||||
this.toasterService.popAsync('success', null,
|
||||
this.i18nService.t('adjustedStorage', request.storageGbAdjustment.toString()));
|
||||
this.onAdjusted.emit(this.storageAdjustment);
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue