mirror of
https://github.com/bitwarden/browser.git
synced 2024-08-26 23:09:46 +02:00
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>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
<app-payment [showMethods]="false"></app-payment>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
EventEmitter,
|
EventEmitter,
|
||||||
Input,
|
Input,
|
||||||
Output,
|
Output,
|
||||||
|
ViewChild,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
|
||||||
import { ToasterService } from 'angular2-toaster';
|
import { ToasterService } from 'angular2-toaster';
|
||||||
|
@ -13,6 +14,8 @@ import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||||
|
|
||||||
import { SeatRequest } from 'jslib/models/request/seatRequest';
|
import { SeatRequest } from 'jslib/models/request/seatRequest';
|
||||||
|
|
||||||
|
import { PaymentComponent } from '../../settings/payment.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-adjust-seats',
|
selector: 'app-adjust-seats',
|
||||||
templateUrl: 'adjust-seats.component.html',
|
templateUrl: 'adjust-seats.component.html',
|
||||||
|
@ -25,6 +28,8 @@ export class AdjustSeatsComponent {
|
||||||
@Output() onAdjusted = new EventEmitter<number>();
|
@Output() onAdjusted = new EventEmitter<number>();
|
||||||
@Output() onCanceled = new EventEmitter();
|
@Output() onCanceled = new EventEmitter();
|
||||||
|
|
||||||
|
@ViewChild(PaymentComponent) paymentComponent: PaymentComponent;
|
||||||
|
|
||||||
seatAdjustment = 0;
|
seatAdjustment = 0;
|
||||||
formPromise: Promise<any>;
|
formPromise: Promise<any>;
|
||||||
|
|
||||||
|
@ -39,12 +44,27 @@ export class AdjustSeatsComponent {
|
||||||
request.seatAdjustment *= -1;
|
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;
|
await this.formPromise;
|
||||||
this.analytics.eventTrack.next({ action: this.add ? 'Added Seats' : 'Removed Seats' });
|
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);
|
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 { }
|
} catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ export class AdjustStorageComponent {
|
||||||
@ViewChild(PaymentComponent) paymentComponent: PaymentComponent;
|
@ViewChild(PaymentComponent) paymentComponent: PaymentComponent;
|
||||||
|
|
||||||
storageAdjustment = 0;
|
storageAdjustment = 0;
|
||||||
formPromise: Promise<PaymentResponse>;
|
formPromise: Promise<any>;
|
||||||
|
|
||||||
constructor(private apiService: ApiService, private i18nService: I18nService,
|
constructor(private apiService: ApiService, private i18nService: I18nService,
|
||||||
private analytics: Angulartics2, private toasterService: ToasterService) { }
|
private analytics: Angulartics2, private toasterService: ToasterService) { }
|
||||||
|
@ -46,19 +46,33 @@ export class AdjustStorageComponent {
|
||||||
request.storageGbAdjustment *= -1;
|
request.storageGbAdjustment *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.organizationId == null) {
|
let paymentFailed = false;
|
||||||
this.formPromise = this.apiService.postAccountStorage(request);
|
const action = async () => {
|
||||||
} else {
|
let response: Promise<PaymentResponse>;
|
||||||
this.formPromise = this.apiService.postOrganizationStorage(this.organizationId, request);
|
if (this.organizationId == null) {
|
||||||
}
|
response = this.formPromise = this.apiService.postAccountStorage(request);
|
||||||
const result = await this.formPromise;
|
} else {
|
||||||
if (result != null && result.paymentIntentClientSecret != null) {
|
response = this.formPromise = this.apiService.postOrganizationStorage(this.organizationId, request);
|
||||||
await this.paymentComponent.handleStripeCardPayment(result.paymentIntentClientSecret, null);
|
}
|
||||||
}
|
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.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);
|
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 { }
|
} catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user