1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-21 03:43:41 +00:00
Files
browser/apps/web/src/app/billing/organizations/billing-sync-key.component.ts
Oscar Hinton ac49e594c1 Add standalone false to all non migrated (#14797)
Adds standalone: false to all components since Angular is changing the default to true and we'd rather not have the angular PR change 300+ files.
2025-05-15 10:44:07 -04:00

89 lines
3.3 KiB
TypeScript

// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Component, Inject } from "@angular/core";
import { FormControl, FormGroup, Validators } from "@angular/forms";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { OrganizationConnectionType } from "@bitwarden/common/admin-console/enums";
import { OrganizationConnectionRequest } from "@bitwarden/common/admin-console/models/request/organization-connection.request";
import { OrganizationConnectionResponse } from "@bitwarden/common/admin-console/models/response/organization-connection.response";
import { BillingSyncConfigApi } from "@bitwarden/common/billing/models/api/billing-sync-config.api";
import { BillingSyncConfigRequest } from "@bitwarden/common/billing/models/request/billing-sync-config.request";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { DIALOG_DATA, DialogRef, DialogService } from "@bitwarden/components";
export interface BillingSyncKeyModalData {
entityId: string;
existingConnectionId: string;
billingSyncKey: string;
setParentConnection: (connection: OrganizationConnectionResponse<BillingSyncConfigApi>) => void;
}
@Component({
templateUrl: "billing-sync-key.component.html",
standalone: false,
})
export class BillingSyncKeyComponent {
protected entityId: string;
protected existingConnectionId: string;
protected billingSyncKey: string;
protected setParentConnection: (
connection: OrganizationConnectionResponse<BillingSyncConfigApi>,
) => void;
protected formGroup: FormGroup;
constructor(
private dialogRef: DialogRef,
@Inject(DIALOG_DATA) protected data: BillingSyncKeyModalData,
private apiService: ApiService,
private logService: LogService,
) {
this.entityId = data.entityId;
this.existingConnectionId = data.existingConnectionId;
this.billingSyncKey = data.billingSyncKey;
this.setParentConnection = data.setParentConnection;
this.formGroup = new FormGroup({
billingSyncKey: new FormControl<string>(this.billingSyncKey, Validators.required),
});
}
submit = async () => {
try {
const request = new OrganizationConnectionRequest(
this.entityId,
OrganizationConnectionType.CloudBillingSync,
true,
new BillingSyncConfigRequest(this.formGroup.value.billingSyncKey),
);
const response =
this.existingConnectionId == null
? await this.apiService.createOrganizationConnection(request, BillingSyncConfigApi)
: await this.apiService.updateOrganizationConnection(
request,
BillingSyncConfigApi,
this.existingConnectionId,
);
this.existingConnectionId = response?.id;
this.billingSyncKey = response?.config?.billingSyncKey;
this.setParentConnection(response);
this.dialogRef.close();
} catch (e) {
this.logService.error(e);
}
};
deleteConnection = async () => {
await this.apiService.deleteOrganizationConnection(this.existingConnectionId);
this.setParentConnection(null);
this.dialogRef.close();
};
static open(dialogService: DialogService, data: BillingSyncKeyModalData) {
return dialogService.open(BillingSyncKeyComponent, { data });
}
}