refactor(ui): Refactor contract creation and client registering in sign up wizzard
To avoid errors by not finishing the sign up wizzard properly, we changed the behaviour of the sign up wizzard.
The client now gets registered right after the contract creation.
MODIFY
src/app/components/marketplace-signup-stepper/marketplace-signup-stepper.component.html
src/app/components/marketplace-signup-stepper/marketplace-signup-stepper.component.html
<button
id="confirm-btn"
mat-raised-button
- (click)="createContract(stepper)"
+ (click)="createContractAndRegisterClient(stepper)"
color="primary">
{{ 'COMMON.CONFIRM' | translate }}
</button>

MODIFY
src/app/components/marketplace-signup-stepper/marketplace-signup-stepper.component.ts
src/app/components/marketplace-signup-stepper/marketplace-signup-stepper.component.ts
@@ -20,6 +20,7 @@ import { HeroService } from '../../services/hero/hero.service';
import { TranslateService } from '@ngx-translate/core';
import {
IClientSummary,
+ IContract,
IContractSummary,
INewContract,
IPolicy
@@ -31,9 +32,10 @@ import { ISignUpInfo } from '../../interfaces/ISignUpInfo';
import { BackendService } from '../../services/backend/backend.service';
import { MatStepper } from '@angular/material/stepper';
import { IContractExt } from '../../interfaces/IContractExt';
-import { map, switchMap } from 'rxjs/operators';
+import { catchError, map, switchMap } from 'rxjs/operators';
import { TocService } from '../../services/toc/toc.service';
import { HttpErrorResponse } from '@angular/common/http';
+import { EMPTY, throwError } from 'rxjs';
@Component({
selector: 'app-marketplace-signup-stepper',
@@ -144,7 +146,7 @@ export class MarketplaceSignupStepperComponent implements OnInit {
}
}
- createContract(stepper: MatStepper): void {
+ createContractAndRegisterClient(stepper: MatStepper): void {
const client: IClientSummary = this.selectedClients.values().next()
.value as IClientSummary;
@@ -159,6 +161,30 @@ export class MarketplaceSignupStepperComponent implements OnInit {
.createContract(client.organizationId, client.id, '1.0', contract)
.pipe(
switchMap((contract) => {
+ this.snackbar.showPrimarySnackBar(
+ this.translator.instant('WIZARD.SUCCESS') as string
+ );
+ return this.extendContract(contract);
+ }),
+ switchMap((contract: IContractExt) => {
+ this.contract = contract;
+ return this.registerClient();
+ })
+ )
+ .subscribe({
+ error: (error: HttpErrorResponse) =>
+ this.snackbar.showErrorSnackBar(error.message, error),
+ complete: () => {
+ if ('AwaitingApproval' === this.contract.client.status) {
+ void this.router.navigate(['approval']);
+ } else {
+ this.goToNextStep(stepper);
+ }
+ }
+ });
+ }
+
+ private extendContract(contract: IContract) {
return this.backend
.getManagedApiEndpoint(
contract.api.api.organization.id,
@@ -173,38 +199,30 @@ export class MarketplaceSignupStepperComponent implements OnInit {
} as IContractExt;
})
);
- })
- )
- .subscribe({
- next: (contract: IContractExt) => {
- this.snackbar.showPrimarySnackBar(
- this.translator.instant('WIZARD.SUCCESS') as string
- );
- this.contract = contract;
- if ('AwaitingApproval' === this.contract.client.status) {
- void this.router.navigate(['approval']);
- } else {
- this.goToNextStep(stepper);
- }
- },
- error: (error: HttpErrorResponse) =>
- this.snackbar.showErrorSnackBar(error.message, error)
- });
}
- finish(): void {
- this.backend
+ private registerClient() {
+ return this.backend
.sendAction({
type: 'registerClient',
entityVersion: '1.0',
organizationId: this.contract.client.client.organization.id,
entityId: this.contract.client.client.id
})
- .subscribe({
- error: (error: HttpErrorResponse) => {
- this.snackbar.showErrorSnackBar(error.message, error);
+ .pipe(
+ catchError((err: HttpErrorResponse) => {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ if (err.error.type === 'InvalidContractStatusException') {
+ // Ignore this error because this is still valid
+ return EMPTY;
+ } else {
+ return throwError(() => err);
}
- });
+ })
+ );
+ }
+
+ finish(): void {
void this.router.navigate(['applications'], {
fragment: this.tocService.formatClientId(this.contract)
});

refactor(ui): Refactor contract creation and client registering in sign up wizzard

To avoid errors by not finishing the sign up wizzard properly, we changed the behaviour of the sign up wizzard.
The client now gets registered right after the contract creation.