diff --git a/src/app/form/orientation-form-view/base-skills/base-skills-choice/base-skills-choice.component.html b/src/app/form/orientation-form-view/base-skills/base-skills-choice/base-skills-choice.component.html deleted file mode 100644 index cef06288d6662bacdad3ec521d6c8848216f6128..0000000000000000000000000000000000000000 --- a/src/app/form/orientation-form-view/base-skills/base-skills-choice/base-skills-choice.component.html +++ /dev/null @@ -1,15 +0,0 @@ -<div class="orientationForm"> - <h2>Quel est le besoin numérique de la personne ?</h2> - - <div class="tagList"> - <app-tag-item - *ngFor="let module of baseSkills" - [label]="module.name" - [disabled]="module.disabled" - [color]="isSelectedModule(module.id) ? 'green' : 'white'" - [iconName]="isSelectedModule(module.id) ? 'tag-checked' : 'tag-unchecked'" - [clickable]="true" - (action)="handleClick(module)" - /> - </div> -</div> diff --git a/src/app/form/orientation-form-view/base-skills/base-skills-choice/base-skills-choice.component.ts b/src/app/form/orientation-form-view/base-skills/base-skills-choice/base-skills-choice.component.ts deleted file mode 100644 index 6e61f7c6e2b5e55d69a9b411c135204a4911301b..0000000000000000000000000000000000000000 --- a/src/app/form/orientation-form-view/base-skills/base-skills-choice/base-skills-choice.component.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { Component, Input, OnInit } from '@angular/core'; -import { FormGroup } from '@angular/forms'; -import { OrientationService } from '../../../../services/orientation.service'; -import { PersonalOfferService } from '../../../../services/personal-offer.service'; -import { CategoryEnum } from '../../../../shared/enum/category.enum'; -import { Category } from '../../../../structure-list/models/category.model'; -import { Module } from '../../../../structure-list/models/module.model'; -import { SearchService } from '../../../../structure-list/services/search.service'; -import { OrientationUtils } from '../../../../utils/orientationUtils'; -import { SelectComponent } from '../../global-components/select/select.component'; -import { FiltersForm } from '../../interfaces/filtersForm.interface'; - -@Component({ - selector: 'app-base-skills-choice', - templateUrl: './base-skills-choice.component.html', -}) -export class BaseSkillsChoiceComponent extends SelectComponent implements OnInit { - @Input() form: FormGroup<FiltersForm>; - public orientationUtils = new OrientationUtils(); - public baseSkills: Module[] = []; - - constructor( - private searchService: SearchService, - public orientationService: OrientationService, - public personalOfferService: PersonalOfferService, - ) { - super(); - } - - ngOnInit(): void { - this.selectedModules = this.form.get('filters').value; - this.searchService.getCategories().subscribe(async (categories: Category[]) => { - this.baseSkills = categories.find((el) => el.id === CategoryEnum.baseSkills).modules; - - // For rdv from structure or annuaire, disable items which are not offered - if (this.orientationService.rdvUser || this.orientationService.rdvStructure) { - await this.orientationUtils.rdvDisableItemsNotOffered(this.baseSkills, this.orientationService, 'baseSkills'); - } - }); - - this.checkValidation.emit(); - } -} diff --git a/src/app/form/orientation-form-view/base-skills/base-skills.component.html b/src/app/form/orientation-form-view/base-skills/base-skills.component.html index 9c96ac4df53267797901304e49d8a5b1c76ba363..497d1e252a0532eae95363294ff453e06868c498 100644 --- a/src/app/form/orientation-form-view/base-skills/base-skills.component.html +++ b/src/app/form/orientation-form-view/base-skills/base-skills.component.html @@ -1,5 +1,15 @@ -<app-base-skills-choice - *ngIf="currentType === GenericOrientationSteps.common" - [form]="form" - (checkValidation)="checkValidation()" -/> +<div class="orientationForm"> + <h2>Quel est le besoin numérique de la personne ?</h2> + + <div class="tagList"> + <app-tag-item + *ngFor="let module of baseSkills" + [label]="module.name" + [disabled]="module.disabled" + [color]="isSelectedModule(module.id) ? 'green' : 'white'" + [iconName]="isSelectedModule(module.id) ? 'tag-checked' : 'tag-unchecked'" + [clickable]="!module.disabled" + (action)="handleClick(module)" + /> + </div> +</div> diff --git a/src/app/form/orientation-form-view/base-skills/base-skills.component.ts b/src/app/form/orientation-form-view/base-skills/base-skills.component.ts index 2322cee8bfc14657cd9260da4cedc6c4c74a2680..4a07054138276575b225e79771c5f7bfe287217e 100644 --- a/src/app/form/orientation-form-view/base-skills/base-skills.component.ts +++ b/src/app/form/orientation-form-view/base-skills/base-skills.component.ts @@ -1,41 +1,42 @@ -import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; import { FormGroup } from '@angular/forms'; +import { OrientationService } from '../../../services/orientation.service'; +import { CategoryEnum } from '../../../shared/enum/category.enum'; +import { Category } from '../../../structure-list/models/category.model'; +import { Module } from '../../../structure-list/models/module.model'; +import { SearchService } from '../../../structure-list/services/search.service'; import { OrientationUtils } from '../../../utils/orientationUtils'; -import { FiltersSteps, GenericOrientationSteps, RecapsType, StructuresListSteps } from '../enums/orientation.enums'; +import { SelectComponent } from '../global-components/select/select.component'; import { FiltersForm } from '../interfaces/filtersForm.interface'; -import { MediationStepType, MediationType } from '../types/orientation.types'; @Component({ selector: 'app-base-skills', templateUrl: './base-skills.component.html', }) -export class BaseSkillsComponent { - @Input() currentStep: FiltersSteps | MediationStepType; - @Input() currentType: GenericOrientationSteps | MediationType; - @Input() form: FormGroup<FiltersForm>; - @Output() validatePage = new EventEmitter<any>(); +export class BaseSkillsComponent extends SelectComponent implements OnInit { + @Input() filtersForm: FormGroup<FiltersForm>; public orientationUtils = new OrientationUtils(); - public pagesValidation: any[] = []; + public baseSkills: Module[] = []; - // Enums - public StructuresListSteps = StructuresListSteps; - public FiltersSteps = FiltersSteps; - public RecapsType = RecapsType; - public GenericOrientationSteps = GenericOrientationSteps; + constructor( + private searchService: SearchService, + public orientationService: OrientationService, + ) { + super(); + } + + ngOnInit(): void { + this.selectedModules = this.filtersForm.get('filters').value; + this.searchService.getCategories().subscribe(async (categories: Category[]) => { + this.baseSkills = categories.find((el) => el.id === CategoryEnum.baseSkills).modules; + + // For rdv from structure or annuaire, disable items which are not offered + if (this.orientationService.rdvUser || this.orientationService.rdvStructure) { + await this.orientationUtils.rdvDisableItemsNotOffered(this.baseSkills, this.orientationService, 'baseSkills'); + } + }); - public checkValidation(): void { - switch (this.currentType) { - case GenericOrientationSteps.common: - this.orientationUtils.setValidationsEquipmentForm( - this.pagesValidation, - this.form, - (isValid) => this.validatePage.emit(isValid), - this.currentStep as FiltersSteps, - ); - break; - default: - throw new Error('Not implemented tunnel type in BaseSkillsComponent'); - } + this.checkValidation.emit(); } } diff --git a/src/app/form/orientation-form-view/enums/orientation.enums.ts b/src/app/form/orientation-form-view/enums/orientation.enums.ts index f6f0eced397966efe071fecb1f78757bf458bf6b..e2579eb76254e7dee56f113c65aa58a026e7239d 100644 --- a/src/app/form/orientation-form-view/enums/orientation.enums.ts +++ b/src/app/form/orientation-form-view/enums/orientation.enums.ts @@ -1,3 +1,54 @@ +/** + * Names of needs, leading to one of the three orientations + */ +export enum NeedsTypes { + equipmentAccess = 'selfServiceMaterial', + equipmentBuy = 'solidarityMaterial', + onlineDemarch = 'onlineProcedures', + baseSkills = 'baseSkills', +} + +/** + * Names of different orientations + */ +export enum AccompanimentTypes { + structuresList = 'Trouver une structure', + appointment = 'RDV Conseiller Numérique', + onlineMediation = 'Médiation Numérique à distance', +} + +/** + * We are either in the common first steps (filtersChoice, accompanimentChoice), + * or in the accompaniment tunnel (either a structuresList, an appointment, or + * an online Mediation) + */ +export enum GenericOrientationSteps { + common, + accompanimentTunnel, +} + +/** + * To prepare each need, a set of filters must be chosen. In Online procedures + * (onlineDemarch or baseSkills), there is also a choice of the accompaniment + * type. + */ +export enum CommonSteps { + filtersChoice, + accompanimentType, +} + +/** + * Steps of different orientations + */ +export enum StructuresListSteps { + pmrAccess, + address, + structureChoice, + mediationBeneficiaryInfo, + comments, + structureOrientator, + orientationRecap, +} export enum AppointmentSteps { infoScreen, pmrAccess, @@ -10,17 +61,7 @@ export enum AppointmentSteps { rdvEnd, orientationPrint, } - -export enum FiltersSteps { - filterChoice, -} - -export enum GenericOrientationSteps { - common = 'Common', - structureList = 'Trouver une structure', -} - -export enum HotlineMediationSteps { +export enum OnlineMediationSteps { infoScreen, mediationBeneficiaryInfo, mediationHoursSelection, @@ -31,42 +72,3 @@ export enum HotlineMediationSteps { rdvEnd, orientationPrint, } - -export enum OnlineDemarche { - structureList = 'Trouver une structure', - appointment = 'RDV Conseiller Numérique', - onlineMediation = 'Médiation Numérique à distance', - common = 'Common', -} - -export enum OnlineDemarchesCommonSteps { - onlineDemarche, - accompanimentType, -} - -export enum NeedsType { - equipmentAccess = 'equipmentAccess', - equipmentBuy = 'equipmentBuy', - onlineDemarch = 'onlineDemarch', - learnSkills = 'learnSkills', -} -export enum PreferredLanguages { - french = 'Français', - english = 'Anglais', - arabic = 'Arabe', -} -export enum RecapsType { - appointment, - onlineMediation, - structure, -} - -export enum StructuresListSteps { - pmrAccess, - address, - structureChoice, - mediationBeneficiaryInfo, - comments, - structureOrientator, - orientationRecap, -} diff --git a/src/app/form/orientation-form-view/equipment-access/equipment-access-choice/equipment-access-choice.component.ts b/src/app/form/orientation-form-view/equipment-access/equipment-access-choice/equipment-access-choice.component.ts index ebd54d299906ba4373fce237c2a6af955ff2a6fc..e688af66e63bec9549dfae60a3c698aa0952f678 100644 --- a/src/app/form/orientation-form-view/equipment-access/equipment-access-choice/equipment-access-choice.component.ts +++ b/src/app/form/orientation-form-view/equipment-access/equipment-access-choice/equipment-access-choice.component.ts @@ -1,6 +1,5 @@ import { Component, Input, OnInit } from '@angular/core'; import { FormGroup } from '@angular/forms'; - import { CategoryEnum } from '../../../../shared/enum/category.enum'; import { Category } from '../../../../structure-list/models/category.model'; import { Module } from '../../../../structure-list/models/module.model'; @@ -13,7 +12,7 @@ import { FiltersForm } from '../../interfaces/filtersForm.interface'; templateUrl: './equipment-access-choice.component.html', }) export class EquipmentAccessChoiceComponent extends SelectComponent implements OnInit { - @Input() form: FormGroup<FiltersForm>; + @Input() filtersForm: FormGroup<FiltersForm>; public equipmentType: Module[] = []; constructor(private searchService: SearchService) { @@ -21,7 +20,7 @@ export class EquipmentAccessChoiceComponent extends SelectComponent implements O } ngOnInit(): void { - this.selectedModules = this.form.get('filters').value; + this.selectedModules = this.filtersForm.get('filters').value; this.searchService.getCategories().subscribe((categories: Category[]) => { this.equipmentType = categories.find((el) => el.id === CategoryEnum.selfServiceMaterial).modules; }); diff --git a/src/app/form/orientation-form-view/equipment-access/equipment-access.component.html b/src/app/form/orientation-form-view/equipment-access/equipment-access.component.html index e091cd974bd0fd0e2067002c887624a2db58a647..51673974545d459600608cafa25d292b7b66ec66 100644 --- a/src/app/form/orientation-form-view/equipment-access/equipment-access.component.html +++ b/src/app/form/orientation-form-view/equipment-access/equipment-access.component.html @@ -1,12 +1,12 @@ <app-equipment-access-choice - *ngIf="currentType === GenericOrientationSteps.common" - [form]="form" + *ngIf="genericStep === GenericOrientationSteps.common" + [filtersForm]="filtersForm" (checkValidation)="checkValidation()" /> <app-orientation-structure-list - *ngIf="currentType === GenericOrientationSteps.structureList" - [form]="orientationForm" + *ngIf="genericStep === GenericOrientationSteps.accompanimentTunnel" [currentStep]="currentStep" + [form]="orientationForm" [filters]="filters" [profile]="profile" (validatePage)="checkValidation()" diff --git a/src/app/form/orientation-form-view/equipment-access/equipment-access.component.ts b/src/app/form/orientation-form-view/equipment-access/equipment-access.component.ts index 14da13579f09c8ab4403777a4fee04760804d538..f538bbdad1e2daf96065fe102381a4557e704c4d 100644 --- a/src/app/form/orientation-form-view/equipment-access/equipment-access.component.ts +++ b/src/app/form/orientation-form-view/equipment-access/equipment-access.component.ts @@ -3,19 +3,19 @@ import { FormGroup } from '@angular/forms'; import { User } from '../../../models/user.model'; import { Filter } from '../../../structure-list/models/filter.model'; import { OrientationUtils } from '../../../utils/orientationUtils'; -import { FiltersSteps, GenericOrientationSteps, RecapsType, StructuresListSteps } from '../enums/orientation.enums'; +import { CommonSteps, GenericOrientationSteps, StructuresListSteps } from '../enums/orientation.enums'; import { FiltersForm } from '../interfaces/filtersForm.interface'; import { StructureOrientationForm } from '../interfaces/structureOrientationForm.interface'; -import { MediationStepType, MediationType } from '../types/orientation.types'; +import { AllOrientationSteps } from '../types/orientation.types'; @Component({ selector: 'app-equipment-access', templateUrl: './equipment-access.component.html', }) export class EquipmentAccessComponent { - @Input() currentStep: FiltersSteps | StructuresListSteps | MediationStepType; - @Input() currentType: GenericOrientationSteps | MediationType; - @Input() form: FormGroup<FiltersForm>; + @Input() currentStep: AllOrientationSteps; + @Input() genericStep: GenericOrientationSteps; + @Input() filtersForm: FormGroup<FiltersForm>; @Input() orientationForm: FormGroup<StructureOrientationForm>; @Input() filters: Filter[] = []; @Input() profile: User; @@ -25,21 +25,19 @@ export class EquipmentAccessComponent { public pagesValidation: any[] = []; // Enums - public FiltersSteps = FiltersSteps; - public RecapsType = RecapsType; public GenericOrientationSteps = GenericOrientationSteps; public checkValidation(): void { - switch (this.currentType) { + switch (this.genericStep) { case GenericOrientationSteps.common: this.orientationUtils.setValidationsEquipmentForm( this.pagesValidation, - this.form, + this.filtersForm, (isValid) => this.validatePage.emit(isValid), - this.currentStep as FiltersSteps, + this.currentStep as CommonSteps, ); break; - case GenericOrientationSteps.structureList: + case GenericOrientationSteps.accompanimentTunnel: this.orientationUtils.setValidationsStructuresForm( this.pagesValidation, this.orientationForm, diff --git a/src/app/form/orientation-form-view/equipment-buy/equipment-buy-type/equipment-buy-type.component.ts b/src/app/form/orientation-form-view/equipment-buy/equipment-buy-type/equipment-buy-type.component.ts index c1a617264f5a2960309e484c7d1c94bfd6dd5f28..c09791d08b4826c36647a88be3b981ef545d0d60 100644 --- a/src/app/form/orientation-form-view/equipment-buy/equipment-buy-type/equipment-buy-type.component.ts +++ b/src/app/form/orientation-form-view/equipment-buy/equipment-buy-type/equipment-buy-type.component.ts @@ -12,14 +12,14 @@ import { FiltersForm } from '../../interfaces/filtersForm.interface'; templateUrl: './equipment-buy-type.component.html', }) export class EquipmentBuyTypeComponent extends SelectComponent implements OnInit { - @Input() form: FormGroup<FiltersForm>; + @Input() filtersForm: FormGroup<FiltersForm>; public equipmentType: Module[] = []; constructor(private searchService: SearchService) { super(); } ngOnInit(): void { - this.selectedModules = this.form.get('filters').value; + this.selectedModules = this.filtersForm.get('filters').value; this.searchService.getCategories().subscribe((categories: Category[]) => { this.equipmentType = categories.find((el) => el.id === CategoryEnum.solidarityMaterial).modules; }); diff --git a/src/app/form/orientation-form-view/equipment-buy/equipment-buy.component.html b/src/app/form/orientation-form-view/equipment-buy/equipment-buy.component.html index 92e7d8724fc2f03632e3246daf8a4b88b3f3e346..e5e8a9aaaf812f0688333305bc591cd17d261685 100644 --- a/src/app/form/orientation-form-view/equipment-buy/equipment-buy.component.html +++ b/src/app/form/orientation-form-view/equipment-buy/equipment-buy.component.html @@ -1,10 +1,10 @@ <app-equipment-buy-type - *ngIf="currentType === GenericOrientationSteps.common" - [form]="form" + *ngIf="genericStep === GenericOrientationSteps.common" + [filtersForm]="filtersForm" (checkValidation)="checkValidation()" /> <app-orientation-structure-list - *ngIf="currentType === GenericOrientationSteps.structureList" + *ngIf="genericStep === GenericOrientationSteps.accompanimentTunnel" [form]="orientationForm" [currentStep]="currentStep" [filters]="filters" diff --git a/src/app/form/orientation-form-view/equipment-buy/equipment-buy.component.ts b/src/app/form/orientation-form-view/equipment-buy/equipment-buy.component.ts index d34dd5dcd0b774c4f472b4e1d4dedabfead5b686..2e1a7c8ec224284bc750d075543cd4d1e8300fef 100644 --- a/src/app/form/orientation-form-view/equipment-buy/equipment-buy.component.ts +++ b/src/app/form/orientation-form-view/equipment-buy/equipment-buy.component.ts @@ -3,19 +3,19 @@ import { FormGroup } from '@angular/forms'; import { User } from '../../../models/user.model'; import { Filter } from '../../../structure-list/models/filter.model'; import { OrientationUtils } from '../../../utils/orientationUtils'; -import { FiltersSteps, GenericOrientationSteps, RecapsType, StructuresListSteps } from '../enums/orientation.enums'; +import { CommonSteps, GenericOrientationSteps, StructuresListSteps } from '../enums/orientation.enums'; import { FiltersForm } from '../interfaces/filtersForm.interface'; import { StructureOrientationForm } from '../interfaces/structureOrientationForm.interface'; -import { MediationStepType, MediationType } from '../types/orientation.types'; +import { AllOrientationSteps } from '../types/orientation.types'; @Component({ selector: 'app-equipment-buy', templateUrl: './equipment-buy.component.html', }) export class EquipmentBuyComponent { - @Input() currentStep: FiltersSteps | StructuresListSteps | MediationStepType; - @Input() currentType: GenericOrientationSteps | MediationType; - @Input() form: FormGroup<FiltersForm>; + @Input() currentStep: AllOrientationSteps; + @Input() genericStep: GenericOrientationSteps; + @Input() filtersForm: FormGroup<FiltersForm>; @Input() orientationForm: FormGroup<StructureOrientationForm>; @Input() filters: Filter[] = []; @Input() profile: User; @@ -25,21 +25,19 @@ export class EquipmentBuyComponent { public pagesValidation: any[] = []; // Enums - public FiltersSteps = FiltersSteps; - public RecapsType = RecapsType; public GenericOrientationSteps = GenericOrientationSteps; public checkValidation(): void { - switch (this.currentType) { + switch (this.genericStep) { case GenericOrientationSteps.common: this.orientationUtils.setValidationsEquipmentForm( this.pagesValidation, - this.form, + this.filtersForm, (isValid) => this.validatePage.emit(isValid), - this.currentStep as FiltersSteps, + this.currentStep as CommonSteps, ); break; - case GenericOrientationSteps.structureList: + case GenericOrientationSteps.accompanimentTunnel: this.orientationUtils.setValidationsStructuresForm( this.pagesValidation, this.orientationForm, diff --git a/src/app/form/orientation-form-view/global-components/information-screen/information-screen.component.html b/src/app/form/orientation-form-view/global-components/information-screen/information-screen.component.html index 6d9cd7560388925507db04307b5eaef4dbc1ceae..3050064bdd38b9dea051240d512dd736a7a89523 100644 --- a/src/app/form/orientation-form-view/global-components/information-screen/information-screen.component.html +++ b/src/app/form/orientation-form-view/global-components/information-screen/information-screen.component.html @@ -1,6 +1,6 @@ <div class="container"> <img src="../../../../../assets/img/orientationBeginning.svg" alt="" /> - <ng-container *ngIf="currentType === currentTypeEnum.appointment"> + <ng-container *ngIf="accompanimentType === AccompanimentTypes.appointment"> <h2>Vous vous apprêtez à demander un rendez-vous auprès d'un·e accompagnant·e numérique</h2> <p> Ces professionnel·les peuvent aider à la prise en main des services administratifs en ligne, mais ne sont pas @@ -8,7 +8,7 @@ de l’orienter vers un lieu du type “Maison France Serviceâ€. </p> </ng-container> - <ng-container *ngIf="currentType === currentTypeEnum.onlineMediation"> + <ng-container *ngIf="accompanimentType === AccompanimentTypes.onlineMediation"> <h2>Vous vous apprêtez à choisir un créneau de médiation numérique à distance</h2> <p> Ce service d’accompagnement permettra à la personne d'être assistée depuis son domicile dans ses usages diff --git a/src/app/form/orientation-form-view/global-components/information-screen/information-screen.component.ts b/src/app/form/orientation-form-view/global-components/information-screen/information-screen.component.ts index 0c27c30d048f46d90e442a1730f61a1d4b9175f9..ccb5a6b2a362c43e1c6df4d6a9a3ad89daca228d 100644 --- a/src/app/form/orientation-form-view/global-components/information-screen/information-screen.component.ts +++ b/src/app/form/orientation-form-view/global-components/information-screen/information-screen.component.ts @@ -1,5 +1,5 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { OnlineDemarche } from '../../enums/orientation.enums'; +import { AccompanimentTypes } from '../../enums/orientation.enums'; @Component({ selector: 'app-information-screen', @@ -7,10 +7,10 @@ import { OnlineDemarche } from '../../enums/orientation.enums'; styleUrls: ['./information-screen.component.scss'], }) export class InformationScreenComponent implements OnInit { - @Input() currentType: OnlineDemarche; + @Input() accompanimentType: AccompanimentTypes; @Output() checkValidation = new EventEmitter<boolean>(); - public currentTypeEnum = OnlineDemarche; + public AccompanimentTypes = AccompanimentTypes; ngOnInit(): void { this.checkValidation.emit(); diff --git a/src/app/form/orientation-form-view/global-components/navigation/navigation.component.ts b/src/app/form/orientation-form-view/global-components/navigation/navigation.component.ts index 232206597084f24a768c1cb051f9c253d5758b4e..05758e934c966ed7afea4f5fbafc49d7df1981bb 100644 --- a/src/app/form/orientation-form-view/global-components/navigation/navigation.component.ts +++ b/src/app/form/orientation-form-view/global-components/navigation/navigation.component.ts @@ -1,8 +1,8 @@ import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core'; import { Router } from '@angular/router'; import { ButtonComponent } from '../../../../shared/components'; -import { NeedsType, OnlineDemarche } from '../../enums/orientation.enums'; -import { MediationStepType, MediationType } from '../../types/orientation.types'; +import { NeedsTypes } from '../../enums/orientation.enums'; +import { AllOrientationSteps } from '../../types/orientation.types'; @Component({ selector: 'app-navigation', @@ -10,13 +10,12 @@ import { MediationStepType, MediationType } from '../../types/orientation.types' styleUrls: ['./navigation.component.scss'], }) export class NavigationComponent { - @Input() currentStep: MediationStepType; - @Input() currentType: OnlineDemarche | MediationType; + @Input() currentStep: AllOrientationSteps; @Input() isPageValid: boolean; - @Input() needType: NeedsType; + @Input() needType: NeedsTypes; @Input() isPrevHidden = false; + @Input() isNextHidden = false; @Input() isLastStep = false; - @Input() hideNavButtons = false; @Input() failedOrientation = false; @Output() goNext = new EventEmitter<boolean>(); @@ -26,7 +25,7 @@ export class NavigationComponent { @ViewChild('prevButton', { read: ButtonComponent }) prevButton: ButtonComponent; @ViewChild('nextButton', { read: ButtonComponent }) nextButton: ButtonComponent; - public NeedsTypeEnum = NeedsType; + public NeedsTypeEnum = NeedsTypes; constructor(private router: Router) {} @@ -34,7 +33,7 @@ export class NavigationComponent { return this.currentStep !== null && !(this.isPrevHidden || this.isLastStep); } public showNextButton(): boolean { - return !this.hideNavButtons; + return !this.isNextHidden; } public nextPage(isPrint?: boolean): void { diff --git a/src/app/form/orientation-form-view/global-components/needs-selection/needs-selection.component.html b/src/app/form/orientation-form-view/global-components/needs-selection/needs-selection.component.html index 1b01c221341cbc85505dd1d61fe8ba644e9b7b40..3139ed09a838fe2baf1a849314e17e9149846b7b 100644 --- a/src/app/form/orientation-form-view/global-components/needs-selection/needs-selection.component.html +++ b/src/app/form/orientation-form-view/global-components/needs-selection/needs-selection.component.html @@ -10,7 +10,7 @@ [label]="option.title" [description]="option.hint" [iconName]="option.icon" - [selected]="currentNeed === option.key" + [selected]="needType === option.key" (click)="selectNeed(option.key)" /> </div> diff --git a/src/app/form/orientation-form-view/global-components/needs-selection/needs-selection.component.ts b/src/app/form/orientation-form-view/global-components/needs-selection/needs-selection.component.ts index d3ac80aeb370214ee9ecf9645fd78063f51ce257..722098182a42b0934439329006864f01642922ef 100644 --- a/src/app/form/orientation-form-view/global-components/needs-selection/needs-selection.component.ts +++ b/src/app/form/orientation-form-view/global-components/needs-selection/needs-selection.component.ts @@ -4,40 +4,40 @@ import { PersonalOffer } from '../../../../models/personalOffer.model'; import { OrientationService } from '../../../../services/orientation.service'; import { PersonalOfferService } from '../../../../services/personal-offer.service'; import { INeedItem } from '../../../../utils/orientationUtils'; -import { NeedsType } from '../../enums/orientation.enums'; +import { NeedsTypes } from '../../enums/orientation.enums'; @Component({ selector: 'app-needs-selection', templateUrl: './needs-selection.component.html', }) export class NeedsSelectionComponent implements OnInit { - @Input() currentNeed: NeedsType; - @Output() setNeedType = new EventEmitter<any>(); + @Input() needType: NeedsTypes; + @Output() needTypeChange = new EventEmitter<NeedsTypes>(); @Output() validate = new EventEmitter<any>(); public needsList: INeedItem[] = [ { title: 'Accéder à du matériel numérique en libre service', hint: '(Wifi, ordinateur, imprimante, scanner…)', - key: NeedsType.equipmentAccess, + key: NeedsTypes.equipmentAccess, icon: 'orientationIndex0', }, { title: 'Acheter du matériel numérique à tarif solidaire', hint: '(Ordinateur, smartphone, clé 4G, forfait internet…)', - key: NeedsType.equipmentBuy, + key: NeedsTypes.equipmentBuy, icon: 'orientationIndex1', }, { title: 'Réaliser une démarche en ligne', hint: '(Démarche Caf, CPAM, France Travail…)', - key: NeedsType.onlineDemarch, + key: NeedsTypes.onlineDemarch, icon: 'orientationIndex2', }, { title: 'Acquérir les compétences numériques de base', hint: '(Ordinateur et smartphone, mails, réseaux sociaux et bureautique...)', - key: NeedsType.learnSkills, + key: NeedsTypes.baseSkills, icon: 'orientationIndex3', }, ]; @@ -50,7 +50,7 @@ export class NeedsSelectionComponent implements OnInit { ngOnInit(): void { if (this.orientationService.rdvUser || this.orientationService.rdvStructure) { this.needsList = this.needsList.filter( - (item) => item.key === NeedsType.onlineDemarch || item.key === NeedsType.learnSkills, + (item) => item.key === NeedsTypes.onlineDemarch || item.key === NeedsTypes.baseSkills, ); } @@ -73,7 +73,7 @@ export class NeedsSelectionComponent implements OnInit { } public selectNeed(event: string): void { - this.setNeedType.emit(event); + this.needTypeChange.emit(event as NeedsTypes); this.validate.emit(); } } diff --git a/src/app/form/orientation-form-view/global-components/orientation-recap/orientation-recap.component.ts b/src/app/form/orientation-form-view/global-components/orientation-recap/orientation-recap.component.ts index b361d3e160ad8ddd33fc38586443a882ded4dcdd..0cc17567dd361d14e9d0ea9144508ea75b9ca4bb 100644 --- a/src/app/form/orientation-form-view/global-components/orientation-recap/orientation-recap.component.ts +++ b/src/app/form/orientation-form-view/global-components/orientation-recap/orientation-recap.component.ts @@ -5,7 +5,7 @@ import { Owner } from '../../../../models/owner.model'; import { Structure } from '../../../../models/structure.model'; import { Module } from '../../../../structure-list/models/module.model'; import { Utils } from '../../../../utils/utils'; -import { RecapsType } from '../../enums/orientation.enums'; +import { AccompanimentTypes } from '../../enums/orientation.enums'; @Component({ selector: 'app-orientation-recap', @@ -14,7 +14,7 @@ import { RecapsType } from '../../enums/orientation.enums'; }) export class OrientationRecapComponent implements OnInit { @Input() form: UntypedFormGroup; - @Input() recapType: RecapsType; + @Input() accompanimentType: AccompanimentTypes; @Input() socialWorker?: Owner; @Input() structureRDV?: Structure; @Input() isToPrint = true; @@ -34,7 +34,7 @@ export class OrientationRecapComponent implements OnInit { this.checkValidation.emit(); // When requesting for an appointments, we save Filters within the form 'onlineDemarcheType', // instead of Modules within the form 'filters'. This harmonizes it. - if (this.recapType === RecapsType.appointment) { + if (this.accompanimentType === AccompanimentTypes.appointment) { this.needs = this.utils.convertFiltersToModule(this.form.get('onlineDemarcheType').value); } else { this.needs = this.form.get('filters').value; @@ -43,28 +43,23 @@ export class OrientationRecapComponent implements OnInit { name: this.form.get('name').value, surname: this.form.get('surname').value, }; - switch (this.recapType) { - case RecapsType.onlineMediation: - this.handleOnlineOrientationRecap(); + switch (this.accompanimentType) { + case AccompanimentTypes.structuresList: + this.handleStructureRecap(); break; - case RecapsType.appointment: + case AccompanimentTypes.appointment: this.handleAppointmentRecap(); break; - case RecapsType.structure: - this.handleStructureRecap(); + case AccompanimentTypes.onlineMediation: + this.handleOnlineOrientationRecap(); break; default: - throw new Error(`Not implemented recap type ${this.recapType}`); + throw new Error(`Not implemented recap type ${this.accompanimentType}`); } } public shouldDisplayAppointmentRecap(): boolean { - return this.recapType === RecapsType.appointment; - } - - public handleAppointmentRecap(): void { - this.comment = this.form.get('details').value; - this.orientator = this.form.get('structureOrientator').value; + return this.accompanimentType === AccompanimentTypes.appointment; } public handleStructureRecap(): void { @@ -72,11 +67,10 @@ export class OrientationRecapComponent implements OnInit { this.structuresToPrint = this.form.get('structureChoice').value; this.orientator = this.form.get('structureOrientator').value; } - - public isOrientator(): boolean { - return Boolean(this.orientator?.structureName); + public handleAppointmentRecap(): void { + this.comment = this.form.get('details').value; + this.orientator = this.form.get('structureOrientator').value; } - public handleOnlineOrientationRecap(): void { this.comment = this.form.get('comments').value; this.orientator = this.form.get('structureOrientator').value; @@ -91,29 +85,33 @@ export class OrientationRecapComponent implements OnInit { }; } + public isOrientator(): boolean { + return Boolean(this.orientator?.structureName); + } + public getRecapTitle(): string { - switch (this.recapType) { - case RecapsType.structure: + switch (this.accompanimentType) { + case AccompanimentTypes.structuresList: return 'Orientation vers un lieu de médiation numérique'; - case RecapsType.appointment: + case AccompanimentTypes.appointment: return 'Demande de rendez-vous d’aide numérique'; - case RecapsType.onlineMediation: + case AccompanimentTypes.onlineMediation: return 'Rappel téléphonique'; default: - throw new Error(`Not implemented recap type ${this.recapType}`); + throw new Error(`Not implemented recap type ${this.accompanimentType}`); } } public getRecapInfo(): string | null { - switch (this.recapType) { - case RecapsType.structure: + switch (this.accompanimentType) { + case AccompanimentTypes.structuresList: return null; - case RecapsType.appointment: + case AccompanimentTypes.appointment: return 'Votre demande de rendez-vous d’aide numérique a bien été envoyée.<br>Un·e professionnel·le vous rappellera pour fixer une date.'; - case RecapsType.onlineMediation: + case AccompanimentTypes.onlineMediation: return 'Vous avez effectué une demande de rappel téléphonique.<br>Vous serez contacté(e) par un·e professionnel·le pour le créneau sélectionné.'; default: - throw new Error(`Not implemented recap type ${this.recapType}`); + throw new Error(`Not implemented recap type ${this.accompanimentType}`); } } diff --git a/src/app/form/orientation-form-view/global-components/select/select.component.ts b/src/app/form/orientation-form-view/global-components/select/select.component.ts index aa11c141e66df456f12ddc1c445d91936b29352d..0e47cfdb0a1099c95b40bc5fbd2bfb528b2cbe31 100644 --- a/src/app/form/orientation-form-view/global-components/select/select.component.ts +++ b/src/app/form/orientation-form-view/global-components/select/select.component.ts @@ -4,8 +4,8 @@ import { Module } from '../../../../structure-list/models/module.model'; @Component({ template: `` }) export class SelectComponent { - @Input() form: FormGroup; - @Output() checkValidation = new EventEmitter<any>(); + @Input() filtersForm: FormGroup; + @Output() checkValidation = new EventEmitter<void>(); public equipmentType: Module[] = []; public selectedModules: Module[] = []; @@ -16,7 +16,7 @@ export class SelectComponent { } else { this.selectedModules.push(module); } - this.form.get('filters').patchValue(this.selectedModules); + this.filtersForm.get('filters').patchValue(this.selectedModules); this.checkValidation.emit(); } diff --git a/src/app/form/orientation-form-view/global-components/structure-orientator/structure-orientator.component.ts b/src/app/form/orientation-form-view/global-components/structure-orientator/structure-orientator.component.ts index c9bce5bad753de59ce8fca43dbfb8df1a035c9f4..55e12b573752ba443b3e06a8eb753dd7441d0dca 100644 --- a/src/app/form/orientation-form-view/global-components/structure-orientator/structure-orientator.component.ts +++ b/src/app/form/orientation-form-view/global-components/structure-orientator/structure-orientator.component.ts @@ -37,6 +37,7 @@ export class StructureOrientatorComponent implements OnInit { } else { this.hasStructures = false; } + this.validatePage.emit(this.form.valid); } public select(structure: Structure): void { diff --git a/src/app/form/orientation-form-view/online-demarch/appointment/make-appointment/make-appointment.component.html b/src/app/form/orientation-form-view/online-demarch/appointment/make-appointment/make-appointment.component.html index bb1cb5d3aefe0e43238ef551feee7c12969ec3ca..7037b196717488290359d9de3f1e50a57c47f431 100644 --- a/src/app/form/orientation-form-view/online-demarch/appointment/make-appointment/make-appointment.component.html +++ b/src/app/form/orientation-form-view/online-demarch/appointment/make-appointment/make-appointment.component.html @@ -8,7 +8,7 @@ </div> <!-- If need to select a social worker --> - <section *ngIf="owners?.length > 0"> + <section *ngIf="!comingFromRegistry"> <div class="header-card"> <app-card [structure]="structureRDV" [redirectToStructure]="false" /> </div> @@ -31,7 +31,7 @@ </section> <!-- If need to select a structure --> - <section *ngIf="structures?.length > 0"> + <section *ngIf="comingFromRegistry"> <div class="header-card"> <app-member-card [member]="orientationService.rdvUser" @@ -50,7 +50,7 @@ [structure]="structure" [redirectToStructure]="false" [showRadioButton]="true" - [isChecked]="selectedOption === structure._id" + [isChecked]="this.form.get('structureRDV')?.value === structure._id" (selectedStructure)="onStructureRadioChange(structure)" /> </div> diff --git a/src/app/form/orientation-form-view/online-demarch/appointment/make-appointment/make-appointment.component.ts b/src/app/form/orientation-form-view/online-demarch/appointment/make-appointment/make-appointment.component.ts index eebc5c9b6685dbd7bd1abd2fab4cf86ae8c290c7..0eeb9ea3fd8b057305befa09860ecccc5217b9a7 100644 --- a/src/app/form/orientation-form-view/online-demarch/appointment/make-appointment/make-appointment.component.ts +++ b/src/app/form/orientation-form-view/online-demarch/appointment/make-appointment/make-appointment.component.ts @@ -22,10 +22,8 @@ export class MakeAppointmentComponent implements OnInit { public owners: Owner[]; public structures: Structure[] = []; - public isBaseskills = false; - public isOnlineProcedures = false; - public selectedOption: string; public structuresListReady: boolean; + public comingFromRegistry: boolean; private onlineDemarcheType; private filtersOnOffers; @@ -37,25 +35,24 @@ export class MakeAppointmentComponent implements OnInit { ngOnInit(): void { this.checkValidation.emit(); + this.comingFromRegistry = this.orientationService.rdvUser !== null; - // build arrays containing the needs the user selected in the form + // When no appointment available, we need to know the name of the filters requested to display them if (this.structureRDV?._id || this.orientationService.rdvUser) { this.onlineDemarcheType = this.form.get('onlineDemarcheType').value; this.filtersOnOffers = { onlineProcedures: [], baseSkills: [] }; this.onlineDemarcheType.forEach((filter) => { if (filter.name === 'onlineProcedures') { this.filtersOnOffers.onlineProcedures.push(filter.value); - this.isOnlineProcedures = true; } if (filter.name === 'baseSkills') { this.filtersOnOffers.baseSkills.push(filter.value); - this.isBaseskills = true; } }); } // Filters owners that accept appointments, have personal offers in the selected structure and match the needs previously selected - if (this.structureRDV?._id) { + if (!this.comingFromRegistry) { this.findOwners(this.structureRDV._id).subscribe((owners) => { const filteredOwners = []; this.owners = owners.filter((owner) => owner.withAppointment && owner.job?.hasPersonalOffer); @@ -88,9 +85,8 @@ export class MakeAppointmentComponent implements OnInit { this.failedOrientation.emit(); } }); - } else if (this.orientationService.rdvUser) { - // else if we come from the registry, list the registry's user's structures - this.selectedOption = this.form.get('structureRDV').value; + } else { + // If we come from the registry, list the registry's user's structures const structures$: Observable<any>[] = []; this.structures = []; this.orientationService.rdvUser.structuresLink.forEach((structureId) => { @@ -136,19 +132,23 @@ export class MakeAppointmentComponent implements OnInit { } public onSocialWorkerRadioChange(socialWorker: Owner): void { - this.form.patchValue({ - socialWorkerId: socialWorker._id, - }); + const structure = this.structureRDV ?? this.orientationService.rdvStructure; + if (this.structureRDV) + this.form.patchValue({ + structureRDV: structure._id, + socialWorkerId: socialWorker._id, + }); this.socialWorker.emit(socialWorker); this.checkValidation.emit(); } public onStructureRadioChange(structure: Structure): void { - this.selectedOption = structure._id; - this.form.get('structureRDV').setValue(structure._id); - this.form.get('socialWorkerId').setValue(this.orientationService.rdvUser._id); + this.form.patchValue({ + structureRDV: structure._id, + socialWorkerId: this.orientationService.rdvUser._id, + }); this.selectedStructureRDV.emit(structure); - this.checkValidation.emit(structure); + this.checkValidation.emit(); } public getFormattedNeeds(): string { diff --git a/src/app/form/orientation-form-view/online-demarch/mediation-language-selection/mediation-language-selection.component.ts b/src/app/form/orientation-form-view/online-demarch/mediation-language-selection/mediation-language-selection.component.ts index 73b426d075f61c76081b7735eff7e1ecc738f035..a02e553d6f709a832fa3d09c5415f9b428b1e2e7 100644 --- a/src/app/form/orientation-form-view/online-demarch/mediation-language-selection/mediation-language-selection.component.ts +++ b/src/app/form/orientation-form-view/online-demarch/mediation-language-selection/mediation-language-selection.component.ts @@ -1,6 +1,15 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { UntypedFormGroup } from '@angular/forms'; -import { PreferredLanguages } from '../../enums/orientation.enums'; + +export enum PreferredLanguages { + french = 'Français', + english = 'Anglais', + arabic = 'Arabe', +} +interface LanguageOption { + title: PreferredLanguages; + key: PreferredLanguages; +} @Component({ selector: 'app-mediation-language-selection', @@ -8,22 +17,13 @@ import { PreferredLanguages } from '../../enums/orientation.enums'; }) export class MediationLanguageSelectionComponent implements OnInit { @Input() form: UntypedFormGroup; - @Output() checkValidation = new EventEmitter<any>(); + @Output() checkValidation = new EventEmitter<void>(); public selected: string; - public languages: any[] = [ - { - title: 'Français', - key: PreferredLanguages.french, - }, - { - title: 'Anglais', - key: PreferredLanguages.english, - }, - { - title: 'Arabe', - key: PreferredLanguages.arabic, - }, - ]; + public languages: LanguageOption[] = Object.values(PreferredLanguages).map((language) => ({ + title: language, + key: language, + })); + ngOnInit(): void { this.selected = this.form.get('preferredLanguage').value; this.checkValidation.emit(); diff --git a/src/app/form/orientation-form-view/online-demarch/online-demarch-common/accompaniment-type/accompaniment-type.component.ts b/src/app/form/orientation-form-view/online-demarch/online-demarch-common/accompaniment-type/accompaniment-type.component.ts index 1108e53efeb882db6216798a2b6456773c5d3c7e..690297db98a1eeef703fd0b487626d6684e627f9 100644 --- a/src/app/form/orientation-form-view/online-demarch/online-demarch-common/accompaniment-type/accompaniment-type.component.ts +++ b/src/app/form/orientation-form-view/online-demarch/online-demarch-common/accompaniment-type/accompaniment-type.component.ts @@ -1,7 +1,7 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { UntypedFormGroup } from '@angular/forms'; import { INeedItem } from '../../../../../utils/orientationUtils'; -import { OnlineDemarche } from '../../../enums/orientation.enums'; +import { AccompanimentTypes } from '../../../enums/orientation.enums'; @Component({ selector: 'app-accompaniment-type', @@ -9,24 +9,24 @@ import { OnlineDemarche } from '../../../enums/orientation.enums'; }) export class AccompanimentTypeComponent implements OnInit { @Input() form: UntypedFormGroup; - @Output() checkValidation = new EventEmitter<any>(); + @Output() checkValidation = new EventEmitter<void>(); public selected: string; public accompanimentTypes: INeedItem[] = [ { title: "Trouver une structure proposant l'accompagnement adapté", hint: 'La personne pourra prendre contact avec la structure ou s’y rendre directement', - key: OnlineDemarche.structureList, + key: AccompanimentTypes.structuresList, }, { title: 'Demander un rendez-vous auprès d’un·e accompagnant·e numérique', hint: 'Les coordonnées de la personne seront transmises à l’accompagnant·e', - key: OnlineDemarche.appointment, + key: AccompanimentTypes.appointment, }, { title: 'Choisir un créneau de médiation numérique à distance', hint: 'La personne sera recontactée par téléphone sur le créneau de son choix', - key: OnlineDemarche.onlineMediation, + key: AccompanimentTypes.onlineMediation, }, ]; ngOnInit(): void { diff --git a/src/app/form/orientation-form-view/online-demarch/online-demarch-common/online-demarch.component.ts b/src/app/form/orientation-form-view/online-demarch/online-demarch-common/online-demarch.component.ts index 3434236940aa5a085064fa13fa5f6413122ab248..f4e8fb3f536d95d036760b600228818efb9f9600 100644 --- a/src/app/form/orientation-form-view/online-demarch/online-demarch-common/online-demarch.component.ts +++ b/src/app/form/orientation-form-view/online-demarch/online-demarch-common/online-demarch.component.ts @@ -1,5 +1,5 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { UntypedFormGroup } from '@angular/forms'; +import { FormGroup, UntypedFormGroup } from '@angular/forms'; import { CategoryEnum } from 'src/app/shared/enum/category.enum'; import { OrientationService } from '../../../../services/orientation.service'; import { PersonalOfferService } from '../../../../services/personal-offer.service'; @@ -8,29 +8,34 @@ import { Category } from '../../../../structure-list/models/category.model'; import { Module } from '../../../../structure-list/models/module.model'; import { SearchService } from '../../../../structure-list/services/search.service'; import { OrientationUtils } from '../../../../utils/orientationUtils'; +import { SelectComponent } from '../../global-components/select/select.component'; +import { FiltersForm } from '../../interfaces/filtersForm.interface'; @Component({ selector: 'app-online-demarch', templateUrl: './online-demarch.component.html', }) -export class OnlineDemarchComponent implements OnInit { +export class OnlineDemarchComponent extends SelectComponent implements OnInit { @Input() form: UntypedFormGroup; - @Output() checkValidation = new EventEmitter<any>(); + @Input() filtersForm: FormGroup<FiltersForm>; + @Output() checkValidation = new EventEmitter<void>(); + + public orientationUtils = new OrientationUtils(); + public accompanimentType: Module[]; + public selectedModules: Module[] = []; + public showStrangersModal = false; constructor( private searchService: SearchService, public structureService: StructureService, public orientationService: OrientationService, public personalOfferService: PersonalOfferService, - ) {} - public orientationUtils = new OrientationUtils(); - public accompanimentType: Module[]; - public selectedModules: Module[] = []; - public showStrangersModal = false; + ) { + super(); + } ngOnInit(): void { - this.selectedModules = this.form.get('onlineDemarcheType').value; - // TODO move this in form init categories + this.selectedModules = this.filtersForm.get('filters').value; this.searchService.getCategories().subscribe(async (categories: Category[]) => { this.accompanimentType = categories.find((el) => el.id === CategoryEnum.onlineProcedures).modules; @@ -48,23 +53,12 @@ export class OnlineDemarchComponent implements OnInit { } public handleClick(module: Module): void { - if (module.id === 'foreigners' && !this.isSelectedModule(module.id)) { + if (module.id === 'foreigners' && !super.isSelectedModule(module.id)) { this.showStrangersModal = true; } - if (this.isSelectedModule(module.id)) { - const index = this.selectedModules.findIndex((_module) => _module.id === module.id); - this.selectedModules.splice(index, 1); - } else { - this.selectedModules.push(module); - } - this.form.get('onlineDemarcheType').patchValue(this.selectedModules); - this.checkValidation.emit(); + super.handleClick(module); } - public isSelectedModule(moduleId: string): boolean { - if (this.selectedModules?.map((module) => module.id).includes(moduleId)) return true; - return false; - } public handleClose(): void { this.showStrangersModal = false; } diff --git a/src/app/form/orientation-form-view/online-demarch/onlineDemarch-form.component.html b/src/app/form/orientation-form-view/online-demarch/onlineDemarch-form.component.html index 3dd7e4bf194a9d06a75efd4daa28b44e68a0c213..06caabc759410b67278da984cc702165682f7194 100644 --- a/src/app/form/orientation-form-view/online-demarch/onlineDemarch-form.component.html +++ b/src/app/form/orientation-form-view/online-demarch/onlineDemarch-form.component.html @@ -1,156 +1,160 @@ <!-- COMMON FORM --> -<ng-container *ngIf="currentType === OnlineDemarche.common"> +<ng-container *ngIf="genericStep === GenericOrientationSteps.common"> <app-online-demarch - *ngIf="needType === NeedsType.onlineDemarch && currentStep === OnlineDemarchesCommonSteps.onlineDemarche" - [form]="form" - (checkValidation)="checkValidation()" - /> - <app-accompaniment-type - *ngIf="currentStep === OnlineDemarchesCommonSteps.accompanimentType" + *ngIf="needType === NeedsTypes.onlineDemarch && currentStep === CommonSteps.filtersChoice" [form]="form" + [filtersForm]="filtersForm" (checkValidation)="checkValidation()" /> <app-base-skills - *ngIf="needType === NeedsType.learnSkills && currentStep === OnlineDemarchesCommonSteps.onlineDemarche" - [currentStep]="currentStep" - [currentType]="currentType" - [form]="filtersForm" - (validatePage)="checkValidation()" - /> -</ng-container> -<!-- APPOINTMENT FORM --> -<ng-container *ngIf="currentType === OnlineDemarche.appointment"> - <app-information-screen - *ngIf="currentStep === OnlineDemarchesAppointmentSteps.infoScreen" - [currentType]="currentType" - (checkValidation)="checkValidation()" - /> - <app-structure-pmr - *ngIf="currentStep === OnlineDemarchesAppointmentSteps.pmrAccess" - [structureForm]="form" - (validateForm)="checkValidation()" - (radioChange)="onRadioChange($event)" - /> - <app-orientation-structure-address - *ngIf="currentStep === OnlineDemarchesAppointmentSteps.location" - [form]="form" - (addressStructure)="checkValidation()" - /> - <app-carto - *ngIf="currentStep === OnlineDemarchesAppointmentSteps.carto" - [isOrientationForm]="true" - [isOrientationRdv]="true" - [filters]="filters" - [userLongitude]="form.get('address').value?.coordinates[0]" - [userLatitude]="form.get('address').value?.coordinates[1]" - (structureSelectionRDV)="checkValidation($event)" - /> - <app-make-appointment - *ngIf="currentStep === OnlineDemarchesAppointmentSteps.makeAppointment" - [form]="form" - [structureRDV]="structureRDV" - (checkValidation)="checkValidation()" - (socialWorker)="getSocialWorker($event)" - (selectedStructureRDV)="getSelectedStructureRDV($event)" - (failedOrientation)="setFailedOrientation()" - /> - <app-mediation-beneficiary-info - *ngIf="currentStep === OnlineDemarchesAppointmentSteps.mediationBeneficiaryInfo" - [form]="form" - [isOrientationRdv]="true" - (checkValidation)="checkValidation()" - /> - <app-structure-orientator - *ngIf="currentStep === OnlineDemarchesAppointmentSteps.structureOrientator" - [profile]="profile" - [form]="form" - (validatePage)="checkValidation()" - /> - <app-orientation-recap - *ngIf="currentStep === OnlineDemarchesAppointmentSteps.orientationRecap" - [form]="form" - [recapType]="RecapsType.appointment" - [socialWorker]="socialWorker" - [structureRDV]="structureRDV" - [isToPrint]="false" + *ngIf="needType === NeedsTypes.baseSkills && currentStep === CommonSteps.filtersChoice" + [filtersForm]="filtersForm" (checkValidation)="checkValidation()" /> - <app-appointment-end - *ngIf="currentStep === OnlineDemarchesAppointmentSteps.rdvEnd" - [form]="form" - [structureRDV]="structureRDV" - [selectedStructureRDV]="selectedStructureRDV" - [socialWorker]="socialWorker" - (checkValidation)="checkValidation()" - /> - <app-orientation-recap - *ngIf="currentStep === OnlineDemarchesAppointmentSteps.orientationPrint" + <app-accompaniment-type + *ngIf="currentStep === CommonSteps.accompanimentType" [form]="form" - [recapType]="RecapsType.appointment" - [socialWorker]="socialWorker" - [structureRDV]="structureRDV" (checkValidation)="checkValidation()" /> </ng-container> -<!-- ONLINE MEDIATION FORM --> -<ng-container *ngIf="currentType === OnlineDemarche.onlineMediation"> - <app-information-screen - *ngIf="currentStep === HotlineMediationSteps.infoScreen" - [currentType]="currentType" - (checkValidation)="checkValidation()" - /> - <app-mediation-beneficiary-info - *ngIf="currentStep === HotlineMediationSteps.mediationBeneficiaryInfo" - [form]="form" - (checkValidation)="checkValidation()" - /> - <app-mediation-hours-selection - *ngIf="currentStep === HotlineMediationSteps.mediationHoursSelection" + +<ng-container *ngIf="genericStep === GenericOrientationSteps.accompanimentTunnel"> + <!-- STRUCTURE LIST FORM --> + <app-orientation-structure-list + *ngIf="accompanimentType === AccompanimentTypes.structuresList" [form]="form" - (checkValidation)="checkValidation()" - /> - <app-mediation-language-selection - *ngIf="currentStep === HotlineMediationSteps.mediationLanguageSelection" - [form]="form" - (checkValidation)="checkValidation()" - /> - <app-orientation-comments - *ngIf="currentStep === HotlineMediationSteps.comments" - [form]="form" - (checkValidation)="checkValidation()" - /> - <app-structure-orientator - *ngIf="currentStep === HotlineMediationSteps.structureOrientator" + [currentStep]="currentStep" + [filters]="filters" [profile]="profile" - [form]="form" (validatePage)="checkValidation()" /> - <app-orientation-recap - *ngIf="currentStep === HotlineMediationSteps.orientationRecap" - [form]="form" - [recapType]="RecapsType.onlineMediation" - [isToPrint]="false" - (checkValidation)="checkValidation()" - /> - <app-appointment-end - *ngIf="currentStep === HotlineMediationSteps.rdvEnd" - [form]="form" - [isOnlineMediation]="true" - (checkValidation)="checkValidation()" - /> - <app-orientation-recap - *ngIf="currentStep === HotlineMediationSteps.orientationPrint" - [form]="form" - [recapType]="RecapsType.onlineMediation" - (checkValidation)="checkValidation()" - /> + + <!-- APPOINTMENT FORM --> + <ng-container *ngIf="accompanimentType === AccompanimentTypes.appointment"> + <app-information-screen + *ngIf="currentStep === OnlineDemarchesAppointmentSteps.infoScreen" + [accompanimentType]="accompanimentType" + (checkValidation)="checkValidation()" + /> + <app-structure-pmr + *ngIf="currentStep === OnlineDemarchesAppointmentSteps.pmrAccess" + [structureForm]="form" + (validateForm)="checkValidation()" + (radioChange)="onRadioChange($event)" + /> + <app-orientation-structure-address + *ngIf="currentStep === OnlineDemarchesAppointmentSteps.location" + [form]="form" + (addressStructure)="checkValidation()" + /> + <app-carto + *ngIf="currentStep === OnlineDemarchesAppointmentSteps.carto" + [isOrientationForm]="true" + [isOrientationRdv]="true" + [filters]="filters" + [userLongitude]="form.get('address').value?.coordinates[0]" + [userLatitude]="form.get('address').value?.coordinates[1]" + (structureSelectionRDV)="checkValidation($event)" + /> + <app-make-appointment + *ngIf="currentStep === OnlineDemarchesAppointmentSteps.makeAppointment" + [form]="form" + [structureRDV]="structureRDV" + (checkValidation)="checkValidation()" + (socialWorker)="setSocialWorker($event)" + (selectedStructureRDV)="setStructureRDV($event)" + (failedOrientation)="setFailedOrientation()" + /> + <app-mediation-beneficiary-info + *ngIf="currentStep === OnlineDemarchesAppointmentSteps.mediationBeneficiaryInfo" + [form]="form" + [isOrientationRdv]="true" + (checkValidation)="checkValidation()" + /> + <app-structure-orientator + *ngIf="currentStep === OnlineDemarchesAppointmentSteps.structureOrientator" + [profile]="profile" + [form]="form" + (validatePage)="checkValidation()" + /> + <app-orientation-recap + *ngIf="currentStep === OnlineDemarchesAppointmentSteps.orientationRecap" + [form]="form" + [accompanimentType]="AccompanimentTypes.appointment" + [socialWorker]="socialWorker" + [structureRDV]="structureRDV" + [isToPrint]="false" + (checkValidation)="checkValidation()" + /> + <app-appointment-end + *ngIf="currentStep === OnlineDemarchesAppointmentSteps.rdvEnd" + [form]="form" + [structureRDV]="structureRDV" + [selectedStructureRDV]="structureRDV" + [socialWorker]="socialWorker" + (checkValidation)="checkValidation()" + /> + <app-orientation-recap + *ngIf="currentStep === OnlineDemarchesAppointmentSteps.orientationPrint" + [form]="form" + [accompanimentType]="AccompanimentTypes.appointment" + [socialWorker]="socialWorker" + [structureRDV]="structureRDV" + (checkValidation)="checkValidation()" + /> + </ng-container> + + <!-- ONLINE MEDIATION FORM --> + <ng-container *ngIf="accompanimentType === AccompanimentTypes.onlineMediation"> + <app-information-screen + *ngIf="currentStep === OnlineMediationSteps.infoScreen" + [accompanimentType]="accompanimentType" + (checkValidation)="checkValidation()" + /> + <app-mediation-beneficiary-info + *ngIf="currentStep === OnlineMediationSteps.mediationBeneficiaryInfo" + [form]="form" + (checkValidation)="checkValidation()" + /> + <app-mediation-hours-selection + *ngIf="currentStep === OnlineMediationSteps.mediationHoursSelection" + [form]="form" + (checkValidation)="checkValidation()" + /> + <app-mediation-language-selection + *ngIf="currentStep === OnlineMediationSteps.mediationLanguageSelection" + [form]="form" + (checkValidation)="checkValidation()" + /> + <app-orientation-comments + *ngIf="currentStep === OnlineMediationSteps.comments" + [form]="form" + (checkValidation)="checkValidation()" + /> + <app-structure-orientator + *ngIf="currentStep === OnlineMediationSteps.structureOrientator" + [profile]="profile" + [form]="form" + (validatePage)="checkValidation()" + /> + <app-orientation-recap + *ngIf="currentStep === OnlineMediationSteps.orientationRecap" + [form]="form" + [accompanimentType]="AccompanimentTypes.onlineMediation" + [isToPrint]="false" + (checkValidation)="checkValidation()" + /> + <app-appointment-end + *ngIf="currentStep === OnlineMediationSteps.rdvEnd" + [form]="form" + [isOnlineMediation]="true" + (checkValidation)="checkValidation()" + /> + <app-orientation-recap + *ngIf="currentStep === OnlineMediationSteps.orientationPrint" + [form]="form" + [accompanimentType]="AccompanimentTypes.onlineMediation" + (checkValidation)="checkValidation()" + /> + </ng-container> </ng-container> -<!-- STRUCTURE LIST FORM --> -<app-orientation-structure-list - *ngIf="currentType === OnlineDemarche.structureList" - [form]="form" - [currentStep]="currentStep" - [filters]="filters" - [profile]="profile" - (validatePage)="checkValidation()" -/> diff --git a/src/app/form/orientation-form-view/online-demarch/onlineDemarch-form.component.ts b/src/app/form/orientation-form-view/online-demarch/onlineDemarch-form.component.ts index 14f70798852caf80e287f5019381e832e40c9127..f0d87444d436bacb5f182683c59c674eace2bb0a 100644 --- a/src/app/form/orientation-form-view/online-demarch/onlineDemarch-form.component.ts +++ b/src/app/form/orientation-form-view/online-demarch/onlineDemarch-form.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { FormGroup, UntypedFormArray, UntypedFormControl, UntypedFormGroup } from '@angular/forms'; import { Owner } from '../../../models/owner.model'; import { Structure } from '../../../models/structure.model'; @@ -8,62 +8,77 @@ import { Category } from '../../../structure-list/models/category.model'; import { Filter } from '../../../structure-list/models/filter.model'; import { OrientationUtils } from '../../../utils/orientationUtils'; import { + AccompanimentTypes, AppointmentSteps, - HotlineMediationSteps, - NeedsType, - OnlineDemarche, - OnlineDemarchesCommonSteps, - RecapsType, + CommonSteps, + GenericOrientationSteps, + NeedsTypes, + OnlineMediationSteps, StructuresListSteps, } from '../enums/orientation.enums'; import { FiltersForm } from '../interfaces/filtersForm.interface'; -import { MediationStepType, MediationType, OnlineMediationSteps } from '../types/orientation.types'; +import { AllOrientationSteps } from '../types/orientation.types'; @Component({ selector: 'app-online-demarch-form', templateUrl: './onlineDemarch-form.component.html', }) -export class OnlineDemarchFormComponent { - @Input() needType: NeedsType; - @Input() currentStep: OnlineMediationSteps | StructuresListSteps | AppointmentSteps | MediationStepType; - @Input() currentType: OnlineDemarche | MediationType; +export class OnlineDemarchFormComponent implements OnInit { + @Input() needType: NeedsTypes; + @Input() currentStep: AllOrientationSteps; + @Input() genericStep: GenericOrientationSteps; + @Input() accompanimentType: AccompanimentTypes; @Input() form: UntypedFormGroup; @Input() filters: Filter[] = []; @Input() filtersForm: FormGroup<FiltersForm>; @Input() profile: User; @Input() categories: Record<string, Category>; - @Input() structureRDV: Structure; - @Input() selectedStructureRDV: Structure; @Output() validatePage = new EventEmitter<any>(); @Output() validateStructureRDV = new EventEmitter<Structure>(); @Output() failedOrientation = new EventEmitter<any>(); public orientationUtils = new OrientationUtils(); public pagesValidation: any[] = []; + public structureRDV: Structure; public socialWorker: Owner; // Enums - public HotlineMediationSteps = HotlineMediationSteps; - public OnlineDemarchesCommonSteps = OnlineDemarchesCommonSteps; + public GenericOrientationSteps = GenericOrientationSteps; + public NeedsTypes = NeedsTypes; + public AccompanimentTypes = AccompanimentTypes; + public CommonSteps = CommonSteps; public StructuresListSteps = StructuresListSteps; - public OnlineDemarche = OnlineDemarche; public OnlineDemarchesAppointmentSteps = AppointmentSteps; - public NeedsType = NeedsType; - public RecapsType = RecapsType; + public OnlineMediationSteps = OnlineMediationSteps; constructor(public orientationService: OrientationService) {} + ngOnInit(): void { + // If coming from registry + if (this.orientationService.rdvUser) { + this.setSocialWorker(this.orientationService.rdvUser as unknown as Owner); + } + + // If coming from carto + if (this.orientationService.rdvStructure) { + this.setStructureRDV(this.orientationService.rdvStructure); + } + } + public checkValidation(event?: any): void { - switch (this.currentType) { - case OnlineDemarche.onlineMediation: - this.orientationUtils.setValidationsOnlineMediationForm( - this.pagesValidation, - this.form, - (isValid) => this.validatePage.emit(isValid), - this.currentStep as HotlineMediationSteps, - ); - break; - case OnlineDemarche.structureList: + if (this.genericStep === GenericOrientationSteps.common) { + this.orientationUtils.setValidationsOnlineDemarchesForm( + this.pagesValidation, + this.filtersForm, + this.form, + (isValid) => this.validatePage.emit(isValid), + this.currentStep as CommonSteps, + ); + return; + } + + switch (this.accompanimentType) { + case AccompanimentTypes.structuresList: this.orientationUtils.setValidationsStructuresForm( this.pagesValidation, this.form, @@ -71,25 +86,7 @@ export class OnlineDemarchFormComponent { this.currentStep as StructuresListSteps, ); break; - case OnlineDemarche.common: - if (this.needType === NeedsType.learnSkills) { - this.orientationUtils.setValidationsLearnSkillsForm( - this.pagesValidation, - this.filtersForm, - this.form, - (isValid) => this.validatePage.emit(isValid), - this.currentStep as OnlineDemarchesCommonSteps, - ); - } else { - this.orientationUtils.setValidationsOnlineDemarchesForm( - this.pagesValidation, - this.form, - (isValid) => this.validatePage.emit(isValid), - this.currentStep as OnlineDemarchesCommonSteps, - ); - } - break; - case OnlineDemarche.appointment: + case AccompanimentTypes.appointment: if (this.currentStep === AppointmentSteps.carto - 1) { // if rdv from structure details, don't reinit the structureRDV variable if (!this.orientationService.rdvStructure) this.structureRDV = null; @@ -106,16 +103,24 @@ export class OnlineDemarchFormComponent { this.currentStep as AppointmentSteps, ); break; + case AccompanimentTypes.onlineMediation: + this.orientationUtils.setValidationsOnlineMediationForm( + this.pagesValidation, + this.form, + (isValid) => this.validatePage.emit(isValid), + this.currentStep as OnlineMediationSteps, + ); + break; default: throw new Error('Not implemented tunnel type in OnlineDemarchFormComponent'); } } - public getSocialWorker(item: Owner): void { + public setSocialWorker(item: Owner): void { this.socialWorker = item; } - public getSelectedStructureRDV(structure: Structure): void { - this.selectedStructureRDV = structure; + public setStructureRDV(structure: Structure): void { + this.structureRDV = structure; } public updatePublicChoice({ formControlName, choice }: { formControlName: string; choice: string }): void { diff --git a/src/app/form/orientation-form-view/orientation-form-view.component.html b/src/app/form/orientation-form-view/orientation-form-view.component.html index 0f8dff1e189fc1b05d8eb76afbe3141fc0680751..275900e98d502574a30a2c62b4231d259c911bed 100644 --- a/src/app/form/orientation-form-view/orientation-form-view.component.html +++ b/src/app/form/orientation-form-view/orientation-form-view.component.html @@ -5,44 +5,39 @@ </div> <app-progress-bar [currentPage]="currentStep" [nbSteps]="nbSteps" [formType]="formType.orientation" /> <div class="container" [ngClass]="{ 'no-max-width': fullScreen }"> - <app-needs-selection - *ngIf="currentStep === null" - [currentNeed]="needType" - (setNeedType)="setCurrentNeedType($event)" - (validate)="validatePage(true)" - /> + <app-needs-selection *ngIf="currentStep === null" [(needType)]="needType" (validate)="validatePage(true)" /> <ng-container *ngIf="currentStep !== null"> <app-equipment-access - *ngIf="needType === needEnum.equipmentAccess" + *ngIf="needType === NeedsTypes.equipmentAccess" [currentStep]="currentStep" - [currentType]="currentType" - [form]="filtersForm" + [genericStep]="genericStep" + [filtersForm]="filtersForm" [orientationForm]="structureOrientationForm" [filters]="filters" [profile]="profile" (validatePage)="validatePage($event)" /> <app-equipment-buy - *ngIf="needType === needEnum.equipmentBuy" + *ngIf="needType === NeedsTypes.equipmentBuy" [currentStep]="currentStep" - [currentType]="currentType" - [form]="filtersForm" + [genericStep]="genericStep" + [filtersForm]="filtersForm" [orientationForm]="structureOrientationForm" [filters]="filters" [profile]="profile" (validatePage)="validatePage($event)" /> <app-online-demarch-form - *ngIf="needType === needEnum.onlineDemarch || needType === needEnum.learnSkills" + *ngIf="isOnlineDemarchOrBaseSkills()" [needType]="needType" [currentStep]="currentStep" - [currentType]="currentType" + [genericStep]="genericStep" + [accompanimentType]="accompanimentType" [form]="onlineDemarcheForm" [filters]="filters" [filtersForm]="filtersForm" [profile]="profile" [categories]="categories" - [structureRDV]="orientationService.rdvStructure" (validatePage)="validatePage($event)" (validateStructureRDV)="validateStructureRDV($event)" (failedOrientation)="setFailedOrientation()" @@ -52,11 +47,10 @@ <app-navigation [currentStep]="currentStep" [isPrevHidden]="isPrevHidden" + [isNextHidden]="isNextHidden" [isLastStep]="isLastStep" [needType]="needType" - [currentType]="currentType" [isPageValid]="isPageValid" - [hideNavButtons]="hideNavButtons" [failedOrientation]="failedOrientation" (goNext)="nextPage()" (goPrev)="prevPage()" diff --git a/src/app/form/orientation-form-view/orientation-form-view.component.ts b/src/app/form/orientation-form-view/orientation-form-view.component.ts index f100feab80206a17de4e73c43e0ee6e3eebace2d..6bf919f90d846fae20ddeef2e415831ded28a22f 100644 --- a/src/app/form/orientation-form-view/orientation-form-view.component.ts +++ b/src/app/form/orientation-form-view/orientation-form-view.component.ts @@ -19,19 +19,16 @@ import { OrientationUtils } from '../../utils/orientationUtils'; import { CanExitResolver, Utils } from '../../utils/utils'; import { formType } from '../form-view/formType.enum'; import { + AccompanimentTypes, AppointmentSteps, - FiltersSteps, + CommonSteps, GenericOrientationSteps, - HotlineMediationSteps, - NeedsType, - OnlineDemarche, - OnlineDemarchesCommonSteps, + NeedsTypes, + OnlineMediationSteps, StructuresListSteps, } from './enums/orientation.enums'; import { NavigationComponent } from './global-components/navigation/navigation.component'; -import { IAppointment } from './interfaces/appointment.interface'; import { FiltersForm } from './interfaces/filtersForm.interface'; -import { IOnlineMediation } from './interfaces/onlineMediation.interface'; import { IOrientationIndicator, OrientationIndicatorStructure, @@ -39,7 +36,7 @@ import { } from './interfaces/orientationIndicator.interface'; import { StructureOrientationForm } from './interfaces/structureOrientationForm.interface'; import { StructureOrientator } from './interfaces/structureOrientator.interface'; -import { MediationStepType, MediationType } from './types/orientation.types'; +import { AllOrientationSteps } from './types/orientation.types'; @Component({ selector: 'app-orientation-form-view', @@ -49,34 +46,32 @@ import { MediationStepType, MediationType } from './types/orientation.types'; export class OrientationFormViewComponent implements OnInit, AfterContentChecked { public static readonly MAX_STEP = (Math.max( - Object.keys(HotlineMediationSteps).length, - Object.keys(AppointmentSteps).length, Object.keys(StructuresListSteps).length, + Object.keys(AppointmentSteps).length, + Object.keys(OnlineMediationSteps).length, ) + - Object.keys(OnlineDemarchesCommonSteps).length) / + Object.keys(CommonSteps).length) / 2; public orientationUtils = new OrientationUtils(); public utils = new Utils(); // OnlineDemarches public onlineDemarcheForm: UntypedFormGroup; - public onlineDemarcheType: OnlineDemarche; // Equipments public filtersForm: FormGroup<FiltersForm>; public structureOrientationForm: FormGroup<StructureOrientationForm>; // Orientator public orientator: FormGroup<StructureOrientator>; // Enum - public needEnum = NeedsType; + public NeedsTypes = NeedsTypes; public formType = formType; // Global - public needType: NeedsType; - public indicatorNeedType: NeedsType; - public previousNeedType: NeedsType; - public currentType: MediationType = OnlineDemarche.common; - public currentStep: MediationStepType = null; + public needType: NeedsTypes; + public genericStep: GenericOrientationSteps = GenericOrientationSteps.common; + public accompanimentType: AccompanimentTypes; + public currentStep: AllOrientationSteps = null; public isPrevHidden = false; + public isNextHidden = false; public isLastStep = false; - public hideNavButtons = false; public nbSteps = OrientationFormViewComponent.MAX_STEP; public isPageValid = false; public filters: Filter[] = []; @@ -170,31 +165,26 @@ export class OrientationFormViewComponent implements OnInit, AfterContentChecked this.orientationService.rdvStructure = null; if (history.state.rdvStructure) { - // Create new Structure object to call Structure functions (getTypeStructureIcon,...) + // Create new Structure object to call Structure functions (getTypeStructureIcon, ...) this.orientationService.rdvStructure = new Structure(history.state.rdvStructure); } if (!this.authService.isLoggedIn()) { this.showLoginModal = true; - } else { - this.profile = await this.profileService.getProfile(); - - if (this.profile?.structuresLink?.length === 1) { - this.structureService.getStructure(this.profile.structuresLink[0]).subscribe( - (_structure) => - (this.orientator = this.orientationUtils.createStructureOrientatorForm({ - structureName: _structure.structureName, - structureMail: _structure.contactMail, - structurePhone: _structure.contactPhone, - })), - ); - } + return; } - if (history.state.mediationNumerique) { - this.currentStep = 0; - this.needType = this.needEnum.learnSkills; - this.setCurrentNeedType(NeedsType.learnSkills); + this.profile = await this.profileService.getProfile(); + + if (this.profile?.structuresLink?.length === 1) { + this.structureService.getStructure(this.profile.structuresLink[0]).subscribe( + (_structure) => + (this.orientator = this.orientationUtils.createStructureOrientatorForm({ + structureName: _structure.structureName, + structureMail: _structure.contactMail, + structurePhone: _structure.contactPhone, + })), + ); } } @@ -206,496 +196,262 @@ export class OrientationFormViewComponent implements OnInit, AfterContentChecked this.isPageValid = event; } + public setFailedOrientation(): void { + this.failedOrientation = true; + } + public validateStructureRDV(event: Structure): void { this.onlineDemarcheForm.get('structureRDV').patchValue(event._id); this.nextPage(); } - public setStepNumber(enumLength: number): void { - this.nbSteps = enumLength / 2; - } - - public setCurrentNeedType(needType: NeedsType): void { - this.needType = needType; - this.validatePage(true); - // Init form according to needType - switch (needType) { - case NeedsType.onlineDemarch: - this.onlineDemarcheForm = this.orientationUtils.createOnlineDemarchesForm(); - break; - case NeedsType.equipmentAccess: - case NeedsType.equipmentBuy: - this.filtersForm = this.orientationUtils.createFiltersForm(); + private async handleAppointment(): Promise<void> { + switch (this.accompanimentType) { + case AccompanimentTypes.appointment: + await lastValueFrom( + this.orientationService.createAppointment({ + ...this.onlineDemarcheForm.value, + onlineDemarcheType: this.onlineDemarcheForm.value.onlineDemarcheType.filter( + (item) => item.name !== 'pmrAccess', + ), + }), + ); break; - case NeedsType.learnSkills: - this.filtersForm = this.orientationUtils.createFiltersForm(); - this.onlineDemarcheForm = this.orientationUtils.createOnlineDemarchesForm(); + case AccompanimentTypes.onlineMediation: + await lastValueFrom( + this.orientationService.createOnlineMediation({ + ...this.onlineDemarcheForm.value, + onlineDemarcheType: this.onlineDemarcheForm.value.filters.map((module: Module) => module.displayText), + }), + ); break; - default: - throw new Error(`Not implemented NeedsType in OrientationFormViewComponent ${needType}`); } } - private currentStepIs(orientationType: MediationType, orientationStep: MediationStepType): boolean { - return this.currentType === orientationType && this.currentStep === orientationStep; - } - - private isOnlineDemarcheOrLearnSkills(): boolean { - return this.needType === NeedsType.onlineDemarch || this.needType === NeedsType.learnSkills; - } - - /** - * In online procedures (online mediation and appointment), a request is sent to the server before the orientation - * summary. isPrevHidden flag prevents from going back in the form after validation. - */ - public checkPrevHidden(): void { - const isOnlineMediationSuccess = this.currentStepIs(OnlineDemarche.onlineMediation, HotlineMediationSteps.rdvEnd); - const isAppointmentSuccess = this.currentStepIs(OnlineDemarche.appointment, AppointmentSteps.rdvEnd); - this.isPrevHidden = this.isOnlineDemarcheOrLearnSkills() && (isOnlineMediationSuccess || isAppointmentSuccess); - } - - public checkLastStep(): void { - const isStructureListOrientationRecap = this.currentStepIs( - OnlineDemarche.structureList, - StructuresListSteps.orientationRecap, - ); - const isAppointmentOrientationRecap = this.currentStepIs( - OnlineDemarche.appointment, - AppointmentSteps.orientationPrint, - ); - const isOnlineMediationOrientationRecap = this.currentStepIs( - OnlineDemarche.onlineMediation, - HotlineMediationSteps.orientationPrint, - ); - this.isLastStep = - isStructureListOrientationRecap || - (this.isOnlineDemarcheOrLearnSkills() && (isAppointmentOrientationRecap || isOnlineMediationOrientationRecap)); - } - - /** - * Handle appointment, send to server - */ - public async handleAppointment(): Promise<void> { - const appointment: IAppointment = { - ...this.onlineDemarcheForm.value, - onlineDemarcheType: this.onlineDemarcheForm.value.onlineDemarcheType.filter((item) => item.name !== 'pmrAccess'), - }; - - await lastValueFrom(this.orientationService.createAppointment(appointment)); - this.canDeactivate = true; - } - - /** - * Handle online mediation, send to server then print - */ - public async handleOnlineAppointment(): Promise<void> { - const toCreate: IOnlineMediation = { - ...this.onlineDemarcheForm.value, - onlineDemarcheType: this.onlineDemarcheForm.value.filters.map((module: Module) => module.displayText), - }; - await lastValueFrom(this.orientationService.createOnlineMediation(toCreate)) - .then(() => { - this.notificationService.showSuccess('Votre démarche en ligne a bien été enregistrée'); - }) - .catch(() => { - this.notificationService.showErrorPleaseRetry('Échec de la création de votre démarche en ligne'); - }); - } - - public async printForm(): Promise<void> { + private async printForm(): Promise<void> { await this.sendOrientationIndicator(this.structureOrientationForm ?? this.onlineDemarcheForm); window.print(); setTimeout(() => { - this.canDeactivate = true; history.pushState({ rdvStructure: null, rdvUser: null }, '', '/orientation'); window.location.reload(); }, 100); } - public setOnlineEquipmentsForm(): void { - this.currentType = OnlineDemarche.structureList; - this.currentStep = StructuresListSteps.pmrAccess; - // first filter screen + regular StructureList form - this.setStepNumber(Object.keys(StructuresListSteps).length); - this.structureOrientationForm = this.orientationUtils.createStructureOrientationForm( - this.filtersForm.value.filters, - this.orientator, - ); - } - - public setOnlineProceduresForm(): void { - switch (this.onlineDemarcheForm.get('accompanimentType').value) { - case OnlineDemarche.structureList: - this.currentType = OnlineDemarche.structureList; - this.currentStep = StructuresListSteps.pmrAccess; - this.setStepNumber(Object.keys(StructuresListSteps).length); - this.onlineDemarcheForm = this.orientationUtils.createStructureOrientationForm( - this.utils.convertFiltersToModule(this.filters), - ); - break; - case OnlineDemarche.appointment: - this.currentType = OnlineDemarche.appointment; - // Skip first screen appointment info for learnSkills - if (this.indicatorNeedType === NeedsType.learnSkills) { - this.currentStep = AppointmentSteps.infoScreen + 1; - this.skipStructureOrientator(true); - } else { - this.currentStep = AppointmentSteps.infoScreen; - } - this.setStepNumber(Object.keys(AppointmentSteps).length); - this.onlineDemarcheForm = this.orientationUtils.createAppointmentForm(this.filters, this.orientator); - break; - case OnlineDemarche.onlineMediation: - this.currentType = OnlineDemarche.onlineMediation; - this.currentStep = HotlineMediationSteps.infoScreen; - this.setStepNumber(Object.keys(HotlineMediationSteps).length); - this.onlineDemarcheForm = this.orientationUtils.createOnlineMediationForm( - this.utils.convertFiltersToModule(this.filters), - this.orientator, - ); - break; - default: - throw new Error('Not implemented value in nextPage()'); - } - } - private async setCategories(): Promise<void> { const categories = await this.searchService.getCategories().toPromise(); - categories.forEach((categ) => { - switch (categ.id) { + categories.forEach((category) => { + switch (category.id) { case CategoryEnum.age: { - this.categories.age = categ; + this.categories.age = category; break; } case CategoryEnum.languageAndIlliteracy: { - this.categories.languageAndIlliteracy = categ; + this.categories.languageAndIlliteracy = category; break; } case CategoryEnum.genre: { - this.categories.genre = categ; + this.categories.genre = category; break; } case CategoryEnum.handicaps: { - this.categories.handicaps = categ; + this.categories.handicaps = category; break; } } }); } - private skipStructureOrientator(isNextPage: boolean): void { - if (this.profile?.structuresLink?.length === 1) { - // skip structureOrientator if user with only one structure - if (isNextPage) { - this.currentStep++; - } else { - this.currentStep--; - } - } - } - - public setOnlineProcedureFilters(): void { - // Handle online procedures - const onlineProcedures: Filter[] = this.onlineDemarcheForm.value.onlineDemarcheType.map((module: Module) => { - return new Filter('onlineProcedures', module.id, module.displayText); - }); - if (onlineProcedures.length > 0) this.filters = [...onlineProcedures, ...this.filters]; - } - - public setFilters(category: string): void { - // Handle online procedures - this.filters = this.filtersForm.value.filters.map((module: Module) => { - return new Filter(category, module.id, module.displayText); - }); - } - public async nextPage(): Promise<void> { this.isPageValid = false; - this.hideNavButtons = false; - // Handle filters form - if (this.isFilterForm() && this.currentStepIs(GenericOrientationSteps.common, FiltersSteps.filterChoice)) { - this.indicatorNeedType = this.needType; - switch (this.needType) { - case NeedsType.equipmentAccess: - this.previousNeedType = NeedsType.equipmentAccess; - this.setFilters('selfServiceMaterial'); - // Switch to structure list form - this.setOnlineEquipmentsForm(); - return; - case NeedsType.equipmentBuy: - this.previousNeedType = NeedsType.equipmentBuy; - this.setFilters('solidarityMaterial'); - // Switch to structure list form - this.setOnlineEquipmentsForm(); - return; - case NeedsType.learnSkills: - this.previousNeedType = NeedsType.learnSkills; - this.setFilters('baseSkills'); - this.needType = NeedsType.onlineDemarch; - this.indicatorNeedType = NeedsType.learnSkills; // ugly but would need a big refacto to stop changing needtype to fit onlinedemarch form - if (this.orientationService.rdvStructure || this.orientationService.rdvUser) { - // if rdv from structure details or user, continue function below to skip accompanimentType and init onlineDemarcheForm - this.currentStep = OnlineDemarchesCommonSteps.accompanimentType - 1; - } else { - this.currentStep = OnlineDemarchesCommonSteps.accompanimentType; - return; - } - break; - } - } - // Online demarches or learn skills - if (this.needType === NeedsType.onlineDemarch || this.needType === NeedsType.learnSkills) { - if ( - this.currentStepIs(OnlineDemarche.common, OnlineDemarchesCommonSteps.accompanimentType - 1) && - (this.orientationService.rdvStructure || this.orientationService.rdvUser) - ) { - this.onlineDemarcheForm.get('accompanimentType').patchValue(OnlineDemarche.appointment); - this.currentStep++; - } - - if (this.currentStepIs(OnlineDemarche.common, OnlineDemarchesCommonSteps.accompanimentType)) { - this.setOnlineProcedureFilters(); - this.setOnlineProceduresForm(); - this.previousNeedType = this.needType; - return; - } - // If no multiple structures, skip orientator - if (this.currentStepIs(OnlineDemarche.onlineMediation, HotlineMediationSteps.structureOrientator - 1)) { - this.skipStructureOrientator(true); - } - // Handle Online appointment - if (this.currentStepIs(OnlineDemarche.onlineMediation, HotlineMediationSteps.rdvEnd - 1)) { - await this.handleOnlineAppointment(); - } - // Handle last screen Online appointment and print - if (this.currentStepIs(OnlineDemarche.onlineMediation, HotlineMediationSteps.orientationPrint)) { - this.printForm(); - return; - } - // Handle last screen appointment - if (this.currentStepIs(OnlineDemarche.appointment, AppointmentSteps.rdvEnd - 1)) { - try { - await this.handleAppointment(); - } catch (e) { - console.log(e); - this.notificationService.showErrorPleaseRetry("Échec de l'envoi de votre demande de RDV"); - // If appointment fails, don't go to next page - return; - } - } + this.isNextHidden = false; + + // Go next routine + this.goToNextStep(); + + // Check if the new screen must be skipped + this.checkSkipInfoScreen(true); + this.checkHasEligibleStructures(); + this.checkSkipCartoScreens('next'); + this.checkSkipStructureOrientator(true); + + // Handle appointments + if (this.shouldHandleAppointment()) { + await this.handleAppointment() + .then(() => { + this.notificationService.showSuccess('Votre demande a bien été enregistrée'); + this.canDeactivate = true; + }) + .catch(() => { + this.notificationService.showErrorPleaseRetry('Échec de la création de votre rendez-vous'); + this.goToPreviousStep(); + }); } - // Structure list handling - if (this.currentType === OnlineDemarche.structureList) { - // If no multiple structures, skip orientator - if (this.currentStep === StructuresListSteps.structureOrientator - 1) { - this.skipStructureOrientator(true); - } - // Print last screen - if (this.currentStep === StructuresListSteps.orientationRecap) { - this.printForm(); - return; - } - // Carto display case for full screen - // Set to full screen - if (this.currentStep === StructuresListSteps.address) { - this.fullScreen = true; - } - // Unset fullscreen - if (this.currentStep === StructuresListSteps.structureChoice) { - this.fullScreen = false; - } - } + // Additional params (fullScreen, Nav buttons, ..) + this.updateHiddenNavButtons(); + this.updateFullScreen(); + this.updateLastStep(); + } - // Appointment handling - if (this.currentType === OnlineDemarche.appointment) { - if (this.currentStep === AppointmentSteps.structureOrientator - 1) { - this.skipStructureOrientator(true); - } + public prevPage(): void { + // Go back routine + this.goToPreviousStep(); - // If no structure found, go to the end - if (this.currentStep === AppointmentSteps.pmrAccess) { - if ( - // For orientation rdv, structure categories must be ignored: we filter only on personalOffers with appointment of the structure - (await lastValueFrom(this.structureService.getStructures(this.filters, 'search', true))).filter( - (structure) => structure.hasUserWithAppointmentDN, - ).length === 0 - ) { - this.sendOrientationIndicator(this.structureOrientationForm ?? this.onlineDemarcheForm); - this.failedOrientation = true; - this.currentStep = AppointmentSteps.rdvEnd - 1; - } - } + // Check if the new screen must be skipped + this.checkSkipStructureOrientator(false); + this.checkSkipCartoScreens('prev'); + this.checkSkipInfoScreen(false); - // Carto display case for full screen - // Set to full screen - if (this.currentStep === AppointmentSteps.location) { - this.fullScreen = true; - } - // Unset fullscreen - if (this.currentStep === AppointmentSteps.carto) { - this.fullScreen = false; - } + // Additional params (fullScreen, Nav buttons, ..) + this.updateHiddenNavButtons(); + this.updateFullScreen(); + this.updateLastStep(); + } - // After last page, print and go to new orientation - if (this.currentStep === AppointmentSteps.orientationPrint) { - this.printForm(); - return; + private goToNextStep(): void { + // Form starts + if (this.currentStep === null) { + this.currentStep = 0; + this.filtersForm = this.orientationUtils.createFiltersForm(); + if (this.isOnlineDemarchOrBaseSkills()) { + this.onlineDemarcheForm = this.orientationUtils.createOnlineDemarchesForm(); } + return; } + // Deals with last steps if ( - this.currentStepIs(OnlineDemarche.appointment, AppointmentSteps.pmrAccess - 1) && - (this.orientationService.rdvStructure || this.orientationService.rdvUser) + this.tunnelingStepIs(AccompanimentTypes.structuresList, StructuresListSteps.orientationRecap) || + this.tunnelingStepIs(AccompanimentTypes.appointment, AppointmentSteps.orientationPrint) || + this.tunnelingStepIs(AccompanimentTypes.onlineMediation, OnlineMediationSteps.orientationPrint) ) { - if (this.orientationService.rdvStructure) { - this.onlineDemarcheForm.get('structureRDV').patchValue(this.orientationService.rdvStructure._id); - } - // skip pmrAccess, location and carto - this.currentStep += 3; + this.printForm(); + return; } - // Default case - if (this.currentStep === null) { - // handle the form start - this.currentStep = 0; + // End of common steps, need to enter the accompaniment tunnels + const commonEquipmentFinished = !this.isOnlineDemarchOrBaseSkills() && this.commonStepIs(CommonSteps.filtersChoice); + const commonOnlineFinished = this.isOnlineDemarchOrBaseSkills() && this.commonStepIs(CommonSteps.accompanimentType); + const commonAppointmentFinished = + this.isComingFromCartoOrRegistry() && this.commonStepIs(CommonSteps.filtersChoice); + + if (commonEquipmentFinished || commonOnlineFinished || commonAppointmentFinished) { + this.filters = this.filtersForm.value.filters.map((module: Module) => { + return new Filter(this.needType, module.id, module.displayText); + }); + this.startsAccompanimentTunnel(); return; } - if (this.currentStep < this.nbSteps) { - this.currentStep++; - this.checkPrevHidden(); - this.checkLastStep(); - this.checkHideNavButtons(); - } + + this.currentStep++; } - public prevPage(): void { - this.hideNavButtons = false; - // Structure list previous page - if (this.currentType === OnlineDemarche.structureList) { - if (this.currentStep === StructuresListSteps.structureChoice) { - this.fullScreen = false; - } - if (this.currentStep === StructuresListSteps.structureOrientator + 1) { - this.skipStructureOrientator(false); - } - if (this.currentStep === StructuresListSteps.structureChoice + 1) { - this.fullScreen = true; + private goToPreviousStep(): void { + if (this.currentStep === 0) { + switch (this.genericStep) { + // If back to beginning of the form, reset + case GenericOrientationSteps.common: + this.reset(); + break; + + // Else, we are in middle of form, going back to choice of accompaniment type + case GenericOrientationSteps.accompanimentTunnel: + this.genericStep = GenericOrientationSteps.common; + this.currentStep = CommonSteps.filtersChoice; + if (this.isOnlineDemarchOrBaseSkills()) { + this.onlineDemarcheForm = this.orientationUtils.createOnlineDemarchesForm(); + if (!this.isComingFromCartoOrRegistry()) { + this.currentStep = CommonSteps.accompanimentType; + } + } + break; } + return; } - // Appointment previous page - if (this.currentType === OnlineDemarche.appointment) { - if ( - this.currentStep === AppointmentSteps.pmrAccess + 1 && - (this.orientationService.rdvStructure || this.orientationService.rdvUser) - ) { - this.currentStep--; - } - if (this.indicatorNeedType === NeedsType.learnSkills && this.currentStep === AppointmentSteps.infoScreen + 1) { - this.currentStep--; - } - if (this.currentStep === AppointmentSteps.carto) { - this.fullScreen = false; - } - if (this.currentStep === AppointmentSteps.makeAppointment) { - this.fullScreen = true; - } - if ( - this.currentStep === AppointmentSteps.makeAppointment && - (this.orientationService.rdvStructure || this.orientationService.rdvUser) - ) { - this.fullScreen = false; - this.currentStep -= 3; - this.skipStructureOrientator(false); - } - if (this.currentStep === AppointmentSteps.structureOrientator + 1) { - this.skipStructureOrientator(false); - } + this.currentStep--; + } + + private startsAccompanimentTunnel(): void { + this.genericStep = GenericOrientationSteps.accompanimentTunnel; + if (this.isComingFromCartoOrRegistry()) { + this.accompanimentType = AccompanimentTypes.appointment; + this.onlineDemarcheForm.get('accompanimentType').patchValue(AccompanimentTypes.appointment); + } else if (!this.isOnlineDemarchOrBaseSkills()) { + this.accompanimentType = AccompanimentTypes.structuresList; + } else { + const onlineProcedures: Filter[] = this.onlineDemarcheForm.value.onlineDemarcheType.map((module: Module) => { + return new Filter('onlineProcedures', module.id, module.displayText); + }); + if (onlineProcedures.length > 0) this.filters = [...onlineProcedures, ...this.filters]; + this.accompanimentType = this.onlineDemarcheForm.get('accompanimentType').value; } - // Default case for first form step. If there was a previous form (like filterForm) we go back to this form - if (this.currentStep === 0) { - switch (this.previousNeedType) { - case NeedsType.learnSkills: - case NeedsType.onlineDemarch: - this.currentType = OnlineDemarche.common; - this.currentStep = OnlineDemarchesCommonSteps.accompanimentType; - this.onlineDemarcheForm = this.orientationUtils.createOnlineDemarchesForm(); - this.previousNeedType = null; - if (this.orientationService.rdvStructure || this.orientationService.rdvUser) { - this.currentStep--; - } - return; - case NeedsType.equipmentAccess: - case NeedsType.equipmentBuy: - this.needType = this.previousNeedType; - this.currentType = OnlineDemarche.common; - this.currentStep = OnlineDemarchesCommonSteps.accompanimentType; - this.previousNeedType = null; - break; - default: - // Last step, reset all - this.reset(); - return; - } - // return; - // handle the form start + switch (this.accompanimentType) { + case AccompanimentTypes.structuresList: + this.currentStep = StructuresListSteps.pmrAccess; + this.setStepNumber(Object.keys(StructuresListSteps).length); + if (this.isOnlineDemarchOrBaseSkills()) { + this.onlineDemarcheForm = this.orientationUtils.createStructuresListForm( + this.utils.convertFiltersToModule(this.filters), + ); + } else { + this.structureOrientationForm = this.orientationUtils.createStructuresListForm( + this.filtersForm.value.filters, + this.orientator, + ); + } + break; + case AccompanimentTypes.appointment: + this.currentStep = AppointmentSteps.infoScreen; + this.setStepNumber(Object.keys(AppointmentSteps).length); + this.onlineDemarcheForm = this.orientationUtils.createAppointmentForm(this.filters, this.orientator); + break; + case AccompanimentTypes.onlineMediation: + this.currentStep = OnlineMediationSteps.infoScreen; + this.setStepNumber(Object.keys(OnlineMediationSteps).length); + this.onlineDemarcheForm = this.orientationUtils.createOnlineMediationForm( + this.utils.convertFiltersToModule(this.filters), + this.orientator, + ); + break; + default: + throw new Error('Unknown tunnel routine'); } - if (this.currentStep > 0) { - this.currentStep--; - this.checkPrevHidden(); - this.checkLastStep(); - this.checkHideNavButtons(); + } + + private async checkHasEligibleStructures(): Promise<void> { + if (this.tunnelingStepIs(AccompanimentTypes.appointment, AppointmentSteps.location)) { + const eligibleStructures = ( + await lastValueFrom(this.structureService.getStructures(this.filters, 'search', true)) + ).filter((structure) => structure.hasUserWithAppointmentDN); + if (eligibleStructures.length === 0) { + this.sendOrientationIndicator(this.structureOrientationForm ?? this.onlineDemarcheForm); + this.failedOrientation = true; + this.currentStep = AppointmentSteps.rdvEnd; + } } } public reset(): void { this.onlineDemarcheForm = undefined; - this.onlineDemarcheType = undefined; - this.filtersForm = undefined; + this.filtersForm = this.orientationUtils.createFiltersForm(); this.currentStep = null; - this.currentType = OnlineDemarche.common; + this.genericStep = GenericOrientationSteps.common; + this.needType = undefined; + this.accompanimentType = undefined; + this.isPrevHidden = false; + this.isNextHidden = false; this.isLastStep = false; this.failedOrientation = false; this.nbSteps = OrientationFormViewComponent.MAX_STEP; this.isPageValid = false; - this.needType = undefined; this.filters = []; } /** - * Return if it's a filter form + * Indicators */ - private isFilterForm(): boolean { - return ( - this.needType === NeedsType.equipmentAccess || - this.needType === NeedsType.equipmentBuy || - this.needType === NeedsType.learnSkills - ); - } - - public canExit(): Promise<boolean> { - // Avoid confirmation when user submit form and leave. - if (this.canDeactivate || this.currentStep === null) { - return Promise.resolve(true); - } else { - return new Promise((resolve) => this.showModal(resolve)); - } - } - private showModal(resolve: CanExitResolver): void { - this.showConfirmationModal = true; - this.resolve = resolve; - } - - public hasRedirectionAccepted(hasAccept: boolean): void { - this.resolve(hasAccept); - if (hasAccept) { - this.sendOrientationIndicator(this.structureOrientationForm ?? this.onlineDemarcheForm); - } - this.showConfirmationModal = false; - } - private targetStructures(structureChoice: AbstractControl): OrientationIndicatorStructure[] { const targetStructures: OrientationIndicatorStructure[] = []; if (structureChoice?.value) { @@ -711,41 +467,37 @@ export class OrientationFormViewComponent implements OnInit, AfterContentChecked } return targetStructures; } - - private displayTextNeedType(needType: NeedsType): string { + private displayTextNeedType(needType: NeedsTypes): string { switch (needType) { - case NeedsType.equipmentAccess: + case NeedsTypes.equipmentAccess: return 'accès matériel'; - case NeedsType.equipmentBuy: + case NeedsTypes.equipmentBuy: return 'achat matériel'; - case NeedsType.learnSkills: - return 'compétences'; - case NeedsType.onlineDemarch: + case NeedsTypes.onlineDemarch: return 'démarche en ligne'; + case NeedsTypes.baseSkills: + return 'compétences'; default: return ''; } } - private orientationType(filters: Filter[]): OrientationIndicatorType { const orientationType: OrientationIndicatorType = { - typeOrientation: this.displayTextNeedType(this.indicatorNeedType ?? this.needType), + typeOrientation: this.displayTextNeedType(this.needType), filtres: [], - typeAccompagnement: this.currentType, + typeAccompagnement: this.accompanimentType, }; filters.forEach((filter) => { orientationType.filtres.push(filter.text); }); return orientationType; } - private getProgress(): number { if (this.isLastStep) { return 100; } return Math.round((this.currentStep / this.nbSteps) * 100); } - private async sendOrientationIndicator(orientationForm: FormGroup): Promise<void> { let isConnected = false; let profile: User = null; @@ -770,25 +522,146 @@ export class OrientationFormViewComponent implements OnInit, AfterContentChecked this.indicatorService.createOrientationIndicator(orientationIndicator).subscribe(); } - public checkHideNavButtons(): void { - if ( - (this.needType === NeedsType.onlineDemarch || this.needType === NeedsType.learnSkills) && - this.currentStepIs(OnlineDemarche.appointment, AppointmentSteps.carto) - ) { - this.hideNavButtons = true; + + /** + * Confirmation modal + */ + public canExit(): Promise<boolean> { + // Avoid confirmation when user submit form and leave. + if (this.canDeactivate || this.currentStep === null) { + return Promise.resolve(true); + } else { + return new Promise((resolve) => this.showModal(resolve)); } } - public setFailedOrientation(): void { - this.failedOrientation = true; + private showModal(resolve: CanExitResolver): void { + this.showConfirmationModal = true; + this.resolve = resolve; + } + public hasRedirectionAccepted(hasAccept: boolean): void { + this.resolve(hasAccept); + if (hasAccept) { + this.sendOrientationIndicator(this.structureOrientationForm ?? this.onlineDemarcheForm); + } + this.showConfirmationModal = false; } - public handleClose(value: boolean): void { - if (value) { + + /** + * Login modal + */ + public goLogin(): void { + this.router.navigate(['/connexion'], { queryParams: { returnUrl: '/orientation' } }); + } + public handleClose(hasAccept: boolean): void { + if (hasAccept) { this.goLogin(); } else { this.showLoginModal = false; } } - public goLogin(): void { - this.router.navigate(['/connexion'], { queryParams: { returnUrl: '/orientation' } }); + + /** + * Shortcuts + */ + private checkSkipInfoScreen(goNext: boolean): void { + // Info screen should be skipped for appointment, if coming from baseSkills + if (this.tunnelingStepIs(AccompanimentTypes.appointment, AppointmentSteps.infoScreen)) { + if (this.needType === NeedsTypes.baseSkills) { + goNext ? this.goToNextStep() : this.goToPreviousStep(); + } + } + } + private checkSkipCartoScreens(dir: 'prev' | 'next'): void { + // When coming from carto or registry, we need to skip the carto steps + if (this.isComingFromCartoOrRegistry()) { + if (dir === 'prev' && this.tunnelingStepIs(AccompanimentTypes.appointment, AppointmentSteps.carto)) { + this.currentStep = AppointmentSteps.infoScreen; + } else if (dir === 'next' && this.tunnelingStepIs(AccompanimentTypes.appointment, AppointmentSteps.pmrAccess)) { + this.currentStep = AppointmentSteps.makeAppointment; + } + } + } + private checkSkipStructureOrientator(goNext: boolean): void { + // When only one structure, no need to set orientator + if ( + this.tunnelingStepIs(AccompanimentTypes.structuresList, StructuresListSteps.structureOrientator) || + this.tunnelingStepIs(AccompanimentTypes.appointment, AppointmentSteps.structureOrientator) || + this.tunnelingStepIs(AccompanimentTypes.onlineMediation, OnlineMediationSteps.structureOrientator) + ) { + if (this.profile?.structuresLink?.length === 1) { + goNext ? this.goToNextStep() : this.goToPreviousStep(); + } + } + } + + /** + * Update states + */ + private updateHiddenNavButtons(): void { + // Only needs to hide in appointment / online mediation + if (!this.isOnlineDemarchOrBaseSkills()) return; + + const isCartoStep = this.tunnelingStepIs(AccompanimentTypes.appointment, AppointmentSteps.carto); + const isAppointmentSuccess = this.tunnelingStepIs(AccompanimentTypes.appointment, AppointmentSteps.rdvEnd); + const isOnlineMediationSuccess = this.tunnelingStepIs( + AccompanimentTypes.onlineMediation, + OnlineMediationSteps.rdvEnd, + ); + this.isPrevHidden = isAppointmentSuccess || isOnlineMediationSuccess; + this.isNextHidden = isCartoStep; + } + private updateFullScreen(): void { + this.fullScreen = + this.tunnelingStepIs(AccompanimentTypes.structuresList, StructuresListSteps.structureChoice) || + this.tunnelingStepIs(AccompanimentTypes.appointment, AppointmentSteps.carto); + } + public updateLastStep(): void { + const isStructureListOrientationRecap = this.tunnelingStepIs( + AccompanimentTypes.structuresList, + StructuresListSteps.orientationRecap, + ); + const isAppointmentOrientationRecap = this.tunnelingStepIs( + AccompanimentTypes.appointment, + AppointmentSteps.orientationPrint, + ); + const isOnlineMediationOrientationRecap = this.tunnelingStepIs( + AccompanimentTypes.onlineMediation, + OnlineMediationSteps.orientationPrint, + ); + this.isLastStep = + isStructureListOrientationRecap || + (this.isOnlineDemarchOrBaseSkills() && (isAppointmentOrientationRecap || isOnlineMediationOrientationRecap)); + } + + /** + * Helpers + */ + private commonStepIs(step: CommonSteps): boolean { + return this.genericStep === GenericOrientationSteps.common && this.currentStep === step; + } + private tunnelingStepIs( + accompanimentType: AccompanimentTypes, + step: StructuresListSteps | AppointmentSteps | OnlineMediationSteps, + ): boolean { + return ( + this.genericStep === GenericOrientationSteps.accompanimentTunnel && + this.accompanimentType === accompanimentType && + this.currentStep === step + ); + } + public isOnlineDemarchOrBaseSkills(): boolean { + return this.needType === NeedsTypes.onlineDemarch || this.needType === NeedsTypes.baseSkills; + } + private isComingFromCartoOrRegistry(): boolean { + return Boolean(this.orientationService.rdvStructure || this.orientationService.rdvUser); + } + private shouldHandleAppointment(): boolean { + return ( + this.tunnelingStepIs(AccompanimentTypes.appointment, AppointmentSteps.rdvEnd) || + this.tunnelingStepIs(AccompanimentTypes.onlineMediation, OnlineMediationSteps.rdvEnd) + ); + } + private setStepNumber(enumLength: number): void { + this.nbSteps = enumLength / 2; } } diff --git a/src/app/form/orientation-form-view/orientation-structure-list/orientation-structure-list.component.html b/src/app/form/orientation-form-view/orientation-structure-list/orientation-structure-list.component.html index e62fa71128b1687ed3c5308c51c65fe382eba2ee..175cb0c0e120f700feea6ce719113a20b0a6de89 100644 --- a/src/app/form/orientation-form-view/orientation-structure-list/orientation-structure-list.component.html +++ b/src/app/form/orientation-form-view/orientation-structure-list/orientation-structure-list.component.html @@ -40,7 +40,7 @@ <app-orientation-recap *ngIf="currentStep === StructuresListSteps.orientationRecap" [form]="form" - [recapType]="RecapsType.structure" + [accompanimentType]="AccompanimentTypes.structuresList" (checkValidation)="checkValidation()" /> </ng-container> diff --git a/src/app/form/orientation-form-view/orientation-structure-list/orientation-structure-list.component.ts b/src/app/form/orientation-form-view/orientation-structure-list/orientation-structure-list.component.ts index f2a34f123df0c959a2fa3902ea854fc663c333c4..be95e999d79a990b6448609ab75c81c0e4cf6d4d 100644 --- a/src/app/form/orientation-form-view/orientation-structure-list/orientation-structure-list.component.ts +++ b/src/app/form/orientation-form-view/orientation-structure-list/orientation-structure-list.component.ts @@ -4,15 +4,15 @@ import { Structure } from '../../../models/structure.model'; import { User } from '../../../models/user.model'; import { Filter } from '../../../structure-list/models/filter.model'; import { OrientationUtils } from '../../../utils/orientationUtils'; -import { FiltersSteps, NeedsType, RecapsType, StructuresListSteps } from '../enums/orientation.enums'; -import { MediationStepType } from '../types/orientation.types'; +import { AccompanimentTypes, StructuresListSteps } from '../enums/orientation.enums'; +import { AllOrientationSteps } from '../types/orientation.types'; @Component({ selector: 'app-orientation-structure-list', templateUrl: './orientation-structure-list.component.html', }) export class OrientationStructureListComponent implements OnChanges { - @Input() currentStep: StructuresListSteps | FiltersSteps | MediationStepType | NeedsType; + @Input() currentStep: AllOrientationSteps; @Input() profile: User; @Input() form: UntypedFormGroup; @Input() filters: Filter[] = []; @@ -22,7 +22,8 @@ export class OrientationStructureListComponent implements OnChanges { // Enum public StructuresListSteps = StructuresListSteps; - public RecapsType = RecapsType; + public AccompanimentTypes = AccompanimentTypes; + // Init data for form public selectedStructures: Structure[] = []; @@ -38,10 +39,6 @@ export class OrientationStructureListComponent implements OnChanges { } public checkValidation(event?: any): void { - // Reset value of selected structure in case of multiple previous - if (this.currentStep === StructuresListSteps.address) { - this.selectedStructures = []; - } if (this.currentStep === StructuresListSteps.structureChoice) { this.selectedStructures = event; this.form.get('structureChoice').setValue(event); diff --git a/src/app/form/orientation-form-view/orientation.module.ts b/src/app/form/orientation-form-view/orientation.module.ts index 3057ae8695865ddcdbfe3c81b932d1d6b768ea53..3323a1760b028f3ddd331aaf8f159678c57baa2a 100644 --- a/src/app/form/orientation-form-view/orientation.module.ts +++ b/src/app/form/orientation-form-view/orientation.module.ts @@ -2,7 +2,6 @@ import { A11yModule } from '@angular/cdk/a11y'; import { NgModule } from '@angular/core'; import { CartoModule } from '../../carto/carto.module'; import { SharedModule } from '../../shared/shared.module'; -import { BaseSkillsChoiceComponent } from './base-skills/base-skills-choice/base-skills-choice.component'; import { BaseSkillsComponent } from './base-skills/base-skills.component'; import { EquipmentAccessChoiceComponent } from './equipment-access/equipment-access-choice/equipment-access-choice.component'; import { EquipmentAccessComponent } from './equipment-access/equipment-access.component'; @@ -50,7 +49,6 @@ import { OrientationStructureListComponent } from './orientation-structure-list/ DetailledStructureCardComponent, OrientationCommentsComponent, EquipmentAccessComponent, - BaseSkillsChoiceComponent, MediationLanguageSelectionComponent, SelectComponent, MakeAppointmentComponent, diff --git a/src/app/form/orientation-form-view/types/orientation.types.ts b/src/app/form/orientation-form-view/types/orientation.types.ts index 2a9694d2aee8f938f425902a4478f1f31b802024..9c91f7f1cf41bb0fb16091853ce2f396f4f4e906 100644 --- a/src/app/form/orientation-form-view/types/orientation.types.ts +++ b/src/app/form/orientation-form-view/types/orientation.types.ts @@ -1,19 +1,12 @@ import { + AccompanimentTypes, AppointmentSteps, - FiltersSteps, + CommonSteps, GenericOrientationSteps, - HotlineMediationSteps, - OnlineDemarche, - OnlineDemarchesCommonSteps, + OnlineMediationSteps, StructuresListSteps, } from '../enums/orientation.enums'; -export type MediationType = OnlineDemarche | GenericOrientationSteps; +export type MediationType = GenericOrientationSteps | AccompanimentTypes; -export type OnlineMediationSteps = - | HotlineMediationSteps - | StructuresListSteps - | OnlineDemarchesCommonSteps - | AppointmentSteps; - -export type MediationStepType = OnlineMediationSteps | FiltersSteps; +export type AllOrientationSteps = CommonSteps | StructuresListSteps | AppointmentSteps | OnlineMediationSteps; diff --git a/src/app/services/structure.service.ts b/src/app/services/structure.service.ts index 848b1e654532a3c3ab2d215a4ab635bc032f1026..acd3e5a6dc211fe33b6363915ab5ff7f6a7ac2da 100644 --- a/src/app/services/structure.service.ts +++ b/src/app/services/structure.service.ts @@ -84,10 +84,10 @@ export class StructureService { const filterPMR = filters.find((filter) => filter.text === 'Accessible PMR'); if (filterPMR) filterPMR.name = 'pmrAccess'; - const andFormatedFilters = this.formatFilters(filters.filter((e) => !e.orOperator)); - const orFormatedFilters = this.formatFilters(filters.filter((e) => e.orOperator)); + const andFormattedFilters = this.formatFilters(filters.filter((e) => !e.orOperator)); + const orFormattedFilters = this.formatFilters(filters.filter((e) => e.orOperator)); requestFilters = { - filters: [andFormatedFilters, orFormatedFilters], + filters: [andFormattedFilters, orFormattedFilters], onlyOffersWithAppointment, limit, }; diff --git a/src/app/utils/orientationUtils.ts b/src/app/utils/orientationUtils.ts index 5e4b435c0697331e5c9202de75e7bbecdd031c70..f7180922fb7437d84071f22c80aa5bb9a5297bc6 100644 --- a/src/app/utils/orientationUtils.ts +++ b/src/app/utils/orientationUtils.ts @@ -1,13 +1,11 @@ import { FormControl, FormGroup, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; import { structureFormStep } from '../form/form-view/structure-form/structureFormStep.enum'; import { + AccompanimentTypes, AppointmentSteps, - FiltersSteps, - HotlineMediationSteps, - NeedsType, - OnlineDemarche, - OnlineDemarchesCommonSteps, - PreferredLanguages, + CommonSteps, + NeedsTypes, + OnlineMediationSteps, StructuresListSteps, } from '../form/orientation-form-view/enums/orientation.enums'; import { AppointmentForm } from '../form/orientation-form-view/interfaces/appointmentForm.interface'; @@ -15,6 +13,7 @@ import { FiltersForm } from '../form/orientation-form-view/interfaces/filtersFor import { OnlineDemarchesForm } from '../form/orientation-form-view/interfaces/onlineDemarchesForm.interface'; import { StructureOrientationForm } from '../form/orientation-form-view/interfaces/structureOrientationForm.interface'; import { StructureOrientator } from '../form/orientation-form-view/interfaces/structureOrientator.interface'; +import { PreferredLanguages } from '../form/orientation-form-view/online-demarch/mediation-language-selection/mediation-language-selection.component'; import { PersonalOffer } from '../models/personalOffer.model'; import { OrientationService } from '../services/orientation.service'; import { Filter } from '../structure-list/models/filter.model'; @@ -30,7 +29,7 @@ export interface IStructureSummary { export interface INeedItem { title: string; hint: string; - key: NeedsType | OnlineDemarche; + key: NeedsTypes | AccompanimentTypes; icon?: string; } export class OrientationUtils { @@ -63,7 +62,7 @@ export class OrientationUtils { }); } - public createStructureOrientationForm( + public createStructuresListForm( filters: Module[] = [], orientatorForm?: FormGroup<StructureOrientator>, ): FormGroup<StructureOrientationForm> { @@ -126,32 +125,18 @@ export class OrientationUtils { }); } - public setValidationsLearnSkillsForm( - pagesValidation: any[], - filterForm: FormGroup<FiltersForm>, - form: UntypedFormGroup, - updatePageValid: (isValid: boolean) => void, - step: OnlineDemarchesCommonSteps, - ): void { - pagesValidation[OnlineDemarchesCommonSteps.onlineDemarche] = { - valid: filterForm.get('filters').value.length > 0, - }; - pagesValidation[OnlineDemarchesCommonSteps.accompanimentType] = { - valid: form.get('accompanimentType')?.value !== null, - }; - updatePageValid(pagesValidation[step].valid); - } public setValidationsOnlineDemarchesForm( pagesValidation: any[], + filtersForm: FormGroup<FiltersForm>, form: UntypedFormGroup, updatePageValid: (isValid: boolean) => void, - step: OnlineDemarchesCommonSteps, + step: CommonSteps, ): void { - pagesValidation[OnlineDemarchesCommonSteps.onlineDemarche] = { - valid: form.get('onlineDemarcheType').value.length > 0, + pagesValidation[CommonSteps.filtersChoice] = { + valid: filtersForm.get('filters').value.length > 0, }; - pagesValidation[OnlineDemarchesCommonSteps.accompanimentType] = { - valid: form.get('accompanimentType').value !== null, + pagesValidation[CommonSteps.accompanimentType] = { + valid: form.get('accompanimentType')?.value !== null, }; updatePageValid(pagesValidation[step].valid); } @@ -160,23 +145,23 @@ export class OrientationUtils { pagesValidation: any[], form: UntypedFormGroup, updatePageValid: (isValid: boolean) => void, - step: HotlineMediationSteps, + step: OnlineMediationSteps, ): void { - pagesValidation[HotlineMediationSteps.infoScreen] = { valid: true }; - pagesValidation[HotlineMediationSteps.mediationBeneficiaryInfo] = { + pagesValidation[OnlineMediationSteps.infoScreen] = { valid: true }; + pagesValidation[OnlineMediationSteps.mediationBeneficiaryInfo] = { valid: form.get('name').valid && form.get('surname').valid && form.get('phone').valid, }; - pagesValidation[HotlineMediationSteps.mediationHoursSelection] = { + pagesValidation[OnlineMediationSteps.mediationHoursSelection] = { valid: form.get('dateSlot').value !== null, }; - pagesValidation[HotlineMediationSteps.mediationLanguageSelection] = { valid: true }; - pagesValidation[HotlineMediationSteps.comments] = { valid: true }; - pagesValidation[HotlineMediationSteps.structureOrientator] = { + pagesValidation[OnlineMediationSteps.mediationLanguageSelection] = { valid: true }; + pagesValidation[OnlineMediationSteps.comments] = { valid: true }; + pagesValidation[OnlineMediationSteps.structureOrientator] = { valid: this.isStructureOrientatorFormValid(form.get('structureOrientator') as FormGroup), }; - pagesValidation[HotlineMediationSteps.orientationRecap] = { valid: true }; - pagesValidation[HotlineMediationSteps.rdvEnd] = { valid: true }; - pagesValidation[HotlineMediationSteps.orientationPrint] = { valid: true }; + pagesValidation[OnlineMediationSteps.orientationRecap] = { valid: true }; + pagesValidation[OnlineMediationSteps.rdvEnd] = { valid: true }; + pagesValidation[OnlineMediationSteps.orientationPrint] = { valid: true }; updatePageValid(pagesValidation[step].valid); } @@ -239,12 +224,12 @@ export class OrientationUtils { public setValidationsEquipmentForm( pagesValidation: any[], - form: FormGroup<FiltersForm>, + filtersForm: FormGroup<FiltersForm>, updatePageValid: (isValid: boolean) => void, - step: FiltersSteps, + step: CommonSteps, ): void { - pagesValidation[FiltersSteps.filterChoice] = { - valid: form.get('filters').valid, + pagesValidation[CommonSteps.filtersChoice] = { + valid: filtersForm.get('filters').value.length > 0, }; updatePageValid(pagesValidation[step].valid); }