RED-6713: update tenant selection

This commit is contained in:
Dan Percic 2023-06-16 18:26:48 +03:00
parent 1522d08a32
commit 39b4ff1f97
2 changed files with 11 additions and 8 deletions

View File

@ -16,6 +16,8 @@ export const ifLoggedIn: CanActivateFn = async (route: ActivatedRouteSnapshot) =
const keycloakInstance = keycloakService.getKeycloakInstance(); const keycloakInstance = keycloakService.getKeycloakInstance();
const tenant = route.paramMap.get('tenant'); const tenant = route.paramMap.get('tenant');
const queryParams = new URLSearchParams(window.location.search);
const username = queryParams.get('username');
if (!keycloakInstance) { if (!keycloakInstance) {
if (!tenant) { if (!tenant) {
@ -37,6 +39,6 @@ export const ifLoggedIn: CanActivateFn = async (route: ActivatedRouteSnapshot) =
} }
logger.warn('[ROUTES] Redirect to login'); logger.warn('[ROUTES] Redirect to login');
await keycloakStatusService.createLoginUrlAndExecute(route.queryParamMap.get('username')); keycloakStatusService.createLoginUrlAndExecute(username);
return false; return false;
}; };

View File

@ -1,4 +1,4 @@
import { Component, inject, Input } from '@angular/core'; import { ChangeDetectionStrategy, Component, inject, Input } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { FormBuilder, Validators } from '@angular/forms'; import { FormBuilder, Validators } from '@angular/forms';
import { TenantsService } from '../services'; import { TenantsService } from '../services';
@ -10,6 +10,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
@Component({ @Component({
templateUrl: './tenant-select.component.html', templateUrl: './tenant-select.component.html',
styleUrls: ['./tenant-select.component.scss'], styleUrls: ['./tenant-select.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
}) })
export class TenantSelectComponent { export class TenantSelectComponent {
@Input() isLoggedOut = false; @Input() isLoggedOut = false;
@ -19,8 +20,8 @@ export class TenantSelectComponent {
// eslint-disable-next-line @typescript-eslint/unbound-method // eslint-disable-next-line @typescript-eslint/unbound-method
tenantId: ['', Validators.required], tenantId: ['', Validators.required],
}); });
protected readonly _tenantsService = inject(TenantsService); protected readonly tenantsService = inject(TenantsService);
protected readonly storedTenants = this._tenantsService protected readonly storedTenants = this.tenantsService
.getStoredTenants() .getStoredTenants()
.sort((a, b) => a.tenant.displayName.localeCompare(b.tenant.displayName)); .sort((a, b) => a.tenant.displayName.localeCompare(b.tenant.displayName));
protected readonly titleService = inject(Title); protected readonly titleService = inject(Title);
@ -33,7 +34,7 @@ export class TenantSelectComponent {
throw new Error('No tenant selected!'); throw new Error('No tenant selected!');
} }
if (!this._tenantsService.has(tenantId)) { if (!this.tenantsService.has(tenantId)) {
this.toaster.error(_('tenant-resolve.tenant-does-not-exist')); this.toaster.error(_('tenant-resolve.tenant-does-not-exist'));
return; return;
} }
@ -45,9 +46,9 @@ export class TenantSelectComponent {
} }
#getQueryParams(tenantId: string) { #getQueryParams(tenantId: string) {
const existingStored = this.storedTenants.find(s => s.tenant.tenantId === tenantId); const existingStored = this.storedTenants.filter(s => s.tenant.tenantId === tenantId);
if (existingStored) { if (existingStored.length === 1) {
return { username: existingStored.email }; return { username: existingStored[0].email };
} }
return {}; return {};