diff --git a/src/app/form/form.component.html b/src/app/form/form.component.html index b1f996227e32664caeac2f95db7b1a635732ea5d..46be894612de46b0ed1708fc72c56fa148e108bd 100644 --- a/src/app/form/form.component.html +++ b/src/app/form/form.component.html @@ -62,7 +62,7 @@ </ul> </div> </div> - <form [formGroup]="accountForm" *ngIf="accountForm"> + <form [formGroup]="accountForm" *ngIf="accountForm && !profile"> <div *ngIf="currentPage == 2" class="page"> <div class="title"> <h3>Qui êtes-vous ?</h3> @@ -938,13 +938,13 @@ le site des services et démarches en ligne dans la Métropole de Lyon </p> </div> - <div *ngIf="currentPage == nbPagesForm && !emailConfirmed" class="page" fxLayout="column" fxLayoutGap="69px"> + <div *ngIf="currentPage == nbPagesForm && !profile" class="page" fxLayout="column" fxLayoutGap="69px"> <svg aria-hidden="true"> <use [attr.xlink:href]="'assets/form/sprite.svg#emailVerification'"></use> </svg> <h3>Un courriel vous a été envoyé afin de finaliser votre inscription</h3> </div> - <div *ngIf="emailConfirmed" class="page"> + <div *ngIf="currentPage == nbPagesForm && profile" class="page"> <div class="title"> <h3> Bravo !<br /> @@ -973,10 +973,20 @@ Suivant<span class="chevron right"></span> </button> </div> - <button *ngIf="currentPage == nbPagesForm && !emailConfirmed" class="btn validate unique" (click)="confirmEmail()"> + <button + *ngIf="currentPage == nbPagesForm && !profile" + class="btn validate unique" + routerLink="/home" + [routerLinkActive]="'active'" + > Ok </button> - <button *ngIf="emailConfirmed" class="btn unique" routerLink="/home" [routerLinkActive]="'active'"> + <button + *ngIf="currentPage == nbPagesForm && profile" + class="btn unique" + routerLink="/home" + [routerLinkActive]="'active'" + > Voir ma structure </button> </div> diff --git a/src/app/form/form.component.ts b/src/app/form/form.component.ts index a7428033513206f0994c5e72ee24ff6676f96fcc..ac1c929e873d3914943f80ab6fbb934b9289094f 100644 --- a/src/app/form/form.component.ts +++ b/src/app/form/form.component.ts @@ -24,7 +24,7 @@ import { first } from 'rxjs/operators'; export class FormComponent implements OnInit { @Input() public idStructure?: string; @Input() public isEditMode: boolean = true; - @Input() public profile?: User; + public profile: User; public structureForm: FormGroup; public labelsQualifications: Category; @@ -51,7 +51,6 @@ export class FormComponent implements OnInit { public showMenu = false; public showModalExit: string = null; - public emailConfirmed = false; //collapse var public showWebsite: boolean; public showSocialNetwork: boolean; @@ -67,7 +66,9 @@ export class FormComponent implements OnInit { ) {} ngOnInit(): void { - console.log(this.idStructure); + this.profileService.getProfile().then((user: User) => { + this.profile = user; + }); if (this.idStructure) { this.structureService.getStructure(this.idStructure).subscribe((structure) => { this.initForm(structure); @@ -116,7 +117,6 @@ export class FormComponent implements OnInit { } private initForm(structure: Structure): void { - console.log(structure); // Init account Form this.accountForm = new FormGroup( { @@ -350,6 +350,11 @@ export class FormComponent implements OnInit { this.isPageValid = this.pagesValidation[this.currentPage].valid; } public nextPage(): void { + // Check if user already connected to skip accountForm pages. + if (this.currentPage == 1 && this.profile) { + this.currentPage += 2; // Skip 2 pages from AccountForm + this.progressStatus += 2 * (100 / this.nbPagesForm); + } // Check if "other" isn't check to hide "other description" page if (this.currentPage == 13 && !this.isInArray('autres', 'proceduresAccompaniment')) { this.currentPage++; // page 14 skip and go to page 15 @@ -366,6 +371,12 @@ export class FormComponent implements OnInit { } } public previousPage(): void { + // Check if user already connected to skip accountForm pages. + if (this.currentPage == 4 && this.profile) { + this.currentPage -= 2; // Skip 2 pages from AccountForm + this.progressStatus -= 2 * (100 / this.nbPagesForm); + } + // Check if "other" isn't check to hide "other description" page if (this.currentPage == 15 && !this.isInArray('autres', 'proceduresAccompaniment')) { this.currentPage--; // page 14 skip and go to page 13 @@ -498,41 +509,34 @@ export class FormComponent implements OnInit { } public validateForm(): void { - //this.structureForm.get('hours').setValue(this.hoursForm); - if (this.structureForm.valid && this.accountForm.valid && this.hoursForm.valid) { + if (this.structureForm.valid && this.hoursForm.valid) { let structure: Structure = this.structureForm.value; structure.hours = this.hoursForm.value; - const user = new User(this.accountForm.value); - this.authService - .register(user) - .pipe(first()) - .subscribe( - () => { - this.structureService.createStructure(structure, user).subscribe( - (structure: Structure) => { - this.currentPage++; - }, - (err) => { - console.log('err création structure'); - } - ); - }, - (error) => { - if (error.error.statusCode === 400) { - console.log('Email déjà utilisé'); - } - } - ); - } else { - console.log(this.structureForm); - console.log(this.accountForm); - console.log(this.hoursForm); - console.log('invalid'); + let user: User; + if (this.profile) { + user = this.profile; + this.createStructure(structure, user); + } else { + if (this.accountForm.valid) { + user = new User(this.accountForm.value); + this.authService + .register(user) + .pipe(first()) + .subscribe(() => { + this.createStructure(structure, user); + }); + } + } } } + + private createStructure(structure: Structure, user: User): void { + this.structureService.createStructure(structure, user).subscribe(() => { + this.currentPage++; + }); + } public toggleMenu(): void { this.showMenu = !this.showMenu; - console.log(this.showMenu); } public leaveForm(route: string): void { @@ -550,8 +554,4 @@ export class FormComponent implements OnInit { this.showMenu = false; } } - // TODO : Email verification link - public confirmEmail(): void { - this.emailConfirmed = true; - } } diff --git a/src/app/profile/services/profile.service.ts b/src/app/profile/services/profile.service.ts index ac04735881d4d6f03b4b2c35ef12a7b7ce3c52e2..48ae27f2c929968f34ed88191d57960dbe9cd288 100644 --- a/src/app/profile/services/profile.service.ts +++ b/src/app/profile/services/profile.service.ts @@ -16,7 +16,7 @@ export class ProfileService { public async getProfile(): Promise<User> { // Get profil by API only on first time - if (!this.currentProfile) { + if (this.authService.isLoggedIn()) { const profile = await this.http.get<User>(`${this.baseUrl}/profile`).toPromise(); this.currentProfile = profile; }