diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 9b9e30d8dfb4bd5da2cb07181a97530b66c25292..13fba3cf1c27833e321c5e9802f1cd6bcfe30c5c 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,6 +1,7 @@ import { Component } from '@angular/core'; import { ProfileService } from './profile/services/profile.service'; import { AuthService } from './services/auth.service'; +import { RouterListenerService } from './services/routerListener.service'; import { PrintService } from './shared/service/print.service'; @Component({ @@ -14,7 +15,8 @@ export class AppComponent { constructor( public printService: PrintService, private authService: AuthService, - private profilService: ProfileService + private profilService: ProfileService, + private routerListenerService: RouterListenerService ) { if (this.authService.isLoggedIn()) { this.profilService.getProfile(); diff --git a/src/app/form/footer-form/footer-form.component.html b/src/app/form/footer-form/footer-form.component.html index a2d4f21ff57b20eb0bfb39750e17cda3c6b32263..6157b4a2cf76c62bb6919885cc21aba3e5aa80b0 100644 --- a/src/app/form/footer-form/footer-form.component.html +++ b/src/app/form/footer-form/footer-form.component.html @@ -4,7 +4,7 @@ <svg class="chevronLeft" aria-hidden="true"> <use [attr.xlink:href]="'assets/form/sprite.svg#chevronLeft'"></use> </svg> - Précédent + {{ btnName[0] }} </div> </button> <button @@ -15,7 +15,8 @@ [ngClass]="{ invalid: !isValid }" > <div class="rowBtn" fxLayout="row" fxLayoutAlign="center center"> - Suivant<svg class="chevronRight" aria-hidden="true"> + {{ btnName[1] + }}<svg class="chevronRight" aria-hidden="true"> <use [attr.xlink:href]="'assets/form/sprite.svg#chevronRight'"></use> </svg> </div> diff --git a/src/app/form/footer-form/footer-form.component.ts b/src/app/form/footer-form/footer-form.component.ts index e5e6fbfaf35d2973f089b6f00a40703ae59952c3..15a5456ff32156d608f712a4c9cf4ae4a9cefd42 100644 --- a/src/app/form/footer-form/footer-form.component.ts +++ b/src/app/form/footer-form/footer-form.component.ts @@ -7,6 +7,7 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; }) export class FooterFormComponent implements OnInit { @Input() isValid: boolean; + @Input() btnName: string[]; @Output() nextPage = new EventEmitter<any>(); @Output() previousPage = new EventEmitter<any>(); constructor() {} diff --git a/src/app/form/form.component.html b/src/app/form/form.component.html index 7378f6c9c4ed6863a41d3757cc4cf8145be303d7..2bea200b728d9f6bc64473137bb2b9704fc71ef5 100644 --- a/src/app/form/form.component.html +++ b/src/app/form/form.component.html @@ -47,9 +47,13 @@ <p class="titleDesc">Cela va prendre une quinzaine de minutes</p> <p>Une fois réalisé cela vous permettra d'être référencé sur la platefome</p> </div> - <div class="btnStart"> - <button class="btn-primary start" (click)="nextPage()">C'est parti</button> - </div> + <app-footer-form + class="btnStart" + [btnName]="['Précédent', 'C\'est parti']" + (previousPage)="previousUrl()" + (nextPage)="nextPage()" + [isValid]="isPageValid" + ></app-footer-form> </div> <div *ngIf="displayClaimStructure()" @@ -64,9 +68,13 @@ <div> <p>Une fois réalisé cela vous permettra de devenir propriétaire de cette structure</p> </div> - <div class="btnStart"> - <button class="btn-primary start" (click)="nextPage()">C'est parti</button> - </div> + <app-footer-form + class="btnStart" + [btnName]="['Précédent', 'C\'est parti']" + (previousPage)="previousUrl()" + (nextPage)="nextPage()" + [isValid]="isPageValid" + ></app-footer-form> </div> <div *ngIf="currentPage == pageTypeEnum.summary && isEditMode" @@ -1115,6 +1123,7 @@ <div *ngIf="currentPage != 0" class="footer desktop"> <div fxLayout="row" fxLayoutAlign="center center" *ngIf="currentPage != nbPagesForm && !isEditMode"> <app-footer-form + [btnName]="['Précédent', 'Suivant']" (previousPage)="previousPage()" (nextPage)="nextPage()" [isValid]="isPageValid" @@ -1156,6 +1165,7 @@ <div *ngIf="currentPage != 0" class="footer phone"> <div fxLayout="row" fxLayoutAlign="center center" *ngIf="currentPage != nbPagesForm && !isEditMode"> <app-footer-form + [btnName]="['Précédent', 'Suivant']" (previousPage)="previousPage()" (nextPage)="nextPage()" [isValid]="isPageValid" diff --git a/src/app/form/form.component.scss b/src/app/form/form.component.scss index aef1dad977e5d18604c602a35463173e436b492a..d32ba5a2cc79f9c57c473f12142886501002b6e7 100644 --- a/src/app/form/form.component.scss +++ b/src/app/form/form.component.scss @@ -140,6 +140,7 @@ h3 { height: 100%; .btnStart { margin-top: 90px; + margin-bottom: 10px; text-align: center; } } diff --git a/src/app/form/form.component.ts b/src/app/form/form.component.ts index 1acd268a7d580617c62d2238923c115c1a769d5c..692a0a761ba6101bdaaf36744fc784c6e1f1df1c 100644 --- a/src/app/form/form.component.ts +++ b/src/app/form/form.component.ts @@ -19,6 +19,7 @@ import { first } from 'rxjs/operators'; import { PageTypeEnum } from './pageType.enum'; import { CustomRegExp } from '../utils/CustomRegExp'; import { StructureWithOwners } from '../models/structureWithOwners.model'; +import { RouterListenerService } from '../services/routerListener.service'; const { DateTime } = require('luxon'); @Component({ selector: 'app-structureForm', @@ -80,7 +81,8 @@ export class FormComponent implements OnInit { private profileService: ProfileService, private authService: AuthService, private router: Router, - private route: ActivatedRoute + private route: ActivatedRoute, + private routerListener: RouterListenerService ) {} async ngOnInit(): Promise<void> { @@ -123,6 +125,16 @@ export class FormComponent implements OnInit { }); } + public previousUrl(): void { + if (this.claimStructure) { + this.routerListener.goToPreviousUrl(this.claimStructure); + } else if (this.editForm) { + this.routerListener.goToPreviousUrl(this.editForm.value); + } else { + this.routerListener.goToPreviousUrl(); + } + } + async setCategories(): Promise<void> { this.searchService.getCategoriesAccompaniment().subscribe((categories: Category[]) => { this.proceduresAccompaniment = categories[0]; @@ -166,7 +178,9 @@ export class FormComponent implements OnInit { // Init form this.structureForm = this.createStructureForm(structure); - this.editForm = this.createStructureForm(structure); + if (this.isEditMode) { + this.editForm = this.createStructureForm(structure); + } // Init hours form this.hoursForm = new FormGroup({ diff --git a/src/app/services/routerListener.service.ts b/src/app/services/routerListener.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..ff42af6857078fbf75e37c0c3e612188f8937583 --- /dev/null +++ b/src/app/services/routerListener.service.ts @@ -0,0 +1,28 @@ +import { Injectable } from '@angular/core'; +import { Router, RoutesRecognized } from '@angular/router'; +import { filter, pairwise } from 'rxjs/operators'; + +@Injectable({ + providedIn: 'root', +}) +export class RouterListenerService { + private previousUrl: string; + constructor(private router: Router) { + this.router.events + .pipe( + filter((evt: any) => evt instanceof RoutesRecognized), + pairwise() + ) + .subscribe((events: RoutesRecognized[]) => { + this.previousUrl = events[0].urlAfterRedirects; + }); + } + + public goToPreviousUrl(data?: any): void { + if (data) { + this.router.navigateByUrl(this.previousUrl, { state: { data: data } }); + } else { + this.router.navigateByUrl(this.previousUrl); + } + } +}