diff --git a/src/app/form/form-view/form-view.component.ts b/src/app/form/form-view/form-view.component.ts index d5776889a607e8a2a6bb47fc3bc9fe4b423f7ad1..5a0f0df018ecf2ac819a2c4bbb249b02c5463d38 100644 --- a/src/app/form/form-view/form-view.component.ts +++ b/src/app/form/form-view/form-view.component.ts @@ -138,6 +138,10 @@ export class FormViewComponent implements OnInit { } private initPage(): void { + const profileFormSteps: number = Object.keys(profileFormStep).length / 2; + const personnalOfferFormSteps: number = Object.keys(personalOfferFormStep).length / 2 - 1; + const structureFormSteps: number = Object.keys(structureFormStep).length / 2; + const totalFormSteps: number = profileFormSteps + personnalOfferFormSteps + structureFormSteps; if (formType[this.routeParam] === formType.account) { this.nbSteps = 3; this.currentPage = accountFormStep.accountInfo; @@ -146,14 +150,14 @@ export class FormViewComponent implements OnInit { this.currentForm = this.accountForm; } if (formType[this.routeParam] === formType.profile) { - this.nbSteps = Object.keys(profileFormStep).length / 2; + this.nbSteps = totalFormSteps; this.currentPage = profileFormStep.profileBeginningInfo; this.currentFormType = formType.profile; this.createProfileForm(); this.currentForm = this.profileForm; } if (formType[this.routeParam] === formType.structure) { - this.nbSteps = 24; + this.nbSteps = totalFormSteps; this.currentPage = structureFormStep.structureChoice; this.currentFormType = formType.structure; this.structure = new Structure(); @@ -176,7 +180,7 @@ export class FormViewComponent implements OnInit { }); } if (formType[this.routeParam] === formType.personaloffer) { - this.nbSteps = 3; + this.nbSteps = totalFormSteps; this.currentPage = personalOfferFormStep.personalOfferAccompaniment; this.currentFormType = formType.personaloffer; const newPersonalOffer: PersonalOffer = new PersonalOffer(); @@ -362,7 +366,6 @@ export class FormViewComponent implements OnInit { public linkStructureToUser(): void { this.structureService.joinStructure(this.structureForm.value._id, this.profile.email).subscribe((data) => { this.currentPage = structureFormStep.mailSentInfo; - this.nbSteps = structureFormStep.mailSentInfo; this.structure._id = this.structureForm.value._id; this.structure.structureName = this.structureForm.value.structureName; }); diff --git a/src/app/form/form-view/global-components/progress-bar/progress-bar.component.ts b/src/app/form/form-view/global-components/progress-bar/progress-bar.component.ts index a6c49470c41a7a8cc9c3f458f85cf28e4493e23d..0f67bb3c7ca420aca74f61215bd4f9edd35025de 100644 --- a/src/app/form/form-view/global-components/progress-bar/progress-bar.component.ts +++ b/src/app/form/form-view/global-components/progress-bar/progress-bar.component.ts @@ -1,5 +1,8 @@ import { Component, Input, OnChanges, SimpleChanges } from '@angular/core'; import { formType } from '../../formType.enum'; +import { personalOfferFormStep } from '../../personal-offer-form/personalOfferFormStep.enum'; +import { profileFormStep } from '../../profile-form/profileFormStep.enum'; +import { structureFormStep } from '../../structure-form/structureFormStep.enum'; @Component({ selector: 'app-progress-bar', @@ -13,8 +16,28 @@ export class ProgressBarComponent implements OnChanges { @Input() nbSteps: number; public progressStatus: number; public formTypeEnum = formType; + public profileFormSteps: number = Object.keys(profileFormStep).length / 2; + public personnalOfferFormSteps: number = Object.keys(personalOfferFormStep).length / 2; + public structureFormSteps: number = Object.keys(structureFormStep).length / 2; ngOnChanges(changes: SimpleChanges): void { - if (changes.currentPage) this.progressStatus = ((this.currentPage + 1) / this.nbSteps) * 100; + if (changes.currentPage) { + switch (this.formType) { + case formType.profile: { + this.progressStatus = ((this.currentPage + 1) / this.nbSteps) * 100; + break; + } + case formType.structure: { + this.progressStatus = ((this.currentPage + this.profileFormSteps + 1) / this.nbSteps) * 100; + break; + } + case formType.personaloffer: + this.progressStatus = + ((this.currentPage + this.structureFormSteps + this.profileFormSteps + 1) / this.nbSteps) * 100; + break; + default: + this.progressStatus = ((this.currentPage + 1) / this.nbSteps) * 100; + } + } } }