mirror of
https://github.com/bitwarden/browser
synced 2025-12-21 18:53:29 +00:00
* Ensure business plan is selected for providers * Show add organization button on if user has valid orgs to add * Correct client owner description * No drop down options if you can't manage organizations
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
import {
|
|
Component,
|
|
EventEmitter,
|
|
Input,
|
|
OnInit,
|
|
Output
|
|
} from '@angular/core';
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
import { ApiService } from 'jslib-common/abstractions/api.service';
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
|
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
|
|
import { UserService } from 'jslib-common/abstractions/user.service';
|
|
|
|
import { ValidationService } from 'jslib-angular/services/validation.service';
|
|
|
|
import { ProviderService } from '../services/provider.service';
|
|
|
|
import { Organization } from 'jslib-common/models/domain/organization';
|
|
import { Provider } from 'jslib-common/models/domain/provider';
|
|
|
|
import { PlanType } from 'jslib-common/enums/planType';
|
|
|
|
@Component({
|
|
selector: 'provider-add-organization',
|
|
templateUrl: 'add-organization.component.html',
|
|
})
|
|
export class AddOrganizationComponent implements OnInit {
|
|
|
|
@Input() providerId: string;
|
|
@Input() organizations: Organization[];
|
|
@Output() onAddedOrganization = new EventEmitter();
|
|
|
|
provider: Provider;
|
|
formPromise: Promise<any>;
|
|
loading = true;
|
|
|
|
constructor(private userService: UserService, private providerService: ProviderService,
|
|
private toasterService: ToasterService, private i18nService: I18nService,
|
|
private platformUtilsService: PlatformUtilsService, private validationService: ValidationService,
|
|
private apiService: ApiService) { }
|
|
|
|
async ngOnInit() {
|
|
await this.load();
|
|
}
|
|
|
|
async load() {
|
|
if (this.providerId == null) {
|
|
return;
|
|
}
|
|
|
|
this.provider = await this.userService.getProvider(this.providerId);
|
|
|
|
this.loading = false;
|
|
}
|
|
|
|
async add(organization: Organization) {
|
|
if (this.formPromise) {
|
|
return;
|
|
}
|
|
|
|
const confirmed = await this.platformUtilsService.showDialog(
|
|
this.i18nService.t('addOrganizationConfirmation', organization.name, this.provider.name), organization.name,
|
|
this.i18nService.t('yes'), this.i18nService.t('no'), 'warning');
|
|
|
|
if (!confirmed) {
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
this.formPromise = this.providerService.addOrganizationToProvider(this.providerId, organization.id);
|
|
await this.formPromise;
|
|
} catch (e) {
|
|
this.validationService.showError(e);
|
|
return;
|
|
} finally {
|
|
this.formPromise = null;
|
|
}
|
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('organizationJoinedProvider'));
|
|
this.onAddedOrganization.emit();
|
|
}
|
|
}
|