From d66d67c957c26f207bb956ff345bacbe53275d06 Mon Sep 17 00:00:00 2001
From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com>
Date: Thu, 24 Nov 2022 10:45:00 +0000
Subject: [PATCH] feat(onboarding): split public in two steps

---
 src/app/form/form-view/form-view.component.ts |   5 +
 .../structure-form.component.html             |  10 ++
 .../structure-form.component.ts               |   4 +
 .../structure-public-target.component.html    | 126 ++++++++++--------
 .../structure-public-target.component.ts      |   1 +
 .../structure-form/structureFormStep.enum.ts  |   1 +
 .../structure-edition-summary.component.html  |  30 +++++
 src/app/utils/formUtils.ts                    |   2 +-
 8 files changed, 120 insertions(+), 59 deletions(-)

diff --git a/src/app/form/form-view/form-view.component.ts b/src/app/form/form-view/form-view.component.ts
index 49cecd5ea..41b2ad9ac 100644
--- a/src/app/form/form-view/form-view.component.ts
+++ b/src/app/form/form-view/form-view.component.ts
@@ -447,6 +447,11 @@ export class FormViewComponent implements OnInit, AfterViewInit {
         return {
           categories: {
             age: this.structureForm.get('categories').get('age').value,
+          },
+        };
+      case structureFormStep.structurePublicTargetOptional:
+        return {
+          categories: {
             languageAndIlliteracy: this.structureForm.get('categories').get('languageAndIlliteracy').value,
             handicaps: this.structureForm.get('categories').get('handicaps').value,
             publicOthers: this.structureForm.get('categories').get('publicOthers').value,
diff --git a/src/app/form/form-view/structure-form/structure-form.component.html b/src/app/form/form-view/structure-form/structure-form.component.html
index aba2c1cf6..6fbba87db 100644
--- a/src/app/form/form-view/structure-form/structure-form.component.html
+++ b/src/app/form/form-view/structure-form/structure-form.component.html
@@ -113,9 +113,19 @@
       [isEditMode]="isEditMode"
       [structureForm]="structureForm"
       [age]="age"
+      (validateForm)="setValidationsForm()"
+      (updateChoice)="updateChoice($event)"
+    >
+    </app-structure-public-target>
+  </div>
+  <div *ngIf="currentStep == structureFormStep.structurePublicTargetOptional">
+    <app-structure-public-target
+      [isEditMode]="isEditMode"
+      [structureForm]="structureForm"
       [handicaps]="handicaps"
       [publicOthers]="publicOthers"
       [languageAndIlliteracy]="languageAndIlliteracy"
+      [isMandatoryFields]="false"
       (validateForm)="setValidationsForm()"
       (updateChoice)="updateChoice($event)"
     >
diff --git a/src/app/form/form-view/structure-form/structure-form.component.ts b/src/app/form/form-view/structure-form/structure-form.component.ts
index 3079d5194..5cdc8cba6 100644
--- a/src/app/form/form-view/structure-form/structure-form.component.ts
+++ b/src/app/form/form-view/structure-form/structure-form.component.ts
@@ -68,6 +68,7 @@ export class StructureFormComponent implements OnChanges, OnInit {
         this.currentStep === structureFormStep.structureCreationFinishedInfo ||
         this.currentStep === structureFormStep.structureHours ||
         this.currentStep === structureFormStep.structureTrainingType ||
+        this.currentStep === structureFormStep.structurePublicTargetOptional ||
         this.currentStep === structureFormStep.structureEquipments ||
         this.currentStep === structureFormStep.structureLabels ||
         this.currentStep === structureFormStep.structureSolidarityMaterial ||
@@ -194,6 +195,9 @@ export class StructureFormComponent implements OnChanges, OnInit {
       this.pagesValidation[structureFormStep.structurePublicTarget] = {
         valid: this.structureForm.get('categories').get('age').valid,
       };
+      this.pagesValidation[structureFormStep.structurePublicTargetOptional] = {
+        valid: true,
+      };
       this.pagesValidation[structureFormStep.structureDigitalHelpingAccompanimentOther] = {
         valid: this.structureForm.get('otherDescription').valid,
       };
diff --git a/src/app/form/form-view/structure-form/structure-public-target/structure-public-target.component.html b/src/app/form/form-view/structure-form/structure-public-target/structure-public-target.component.html
index 838a9d05a..beaaccd14 100644
--- a/src/app/form/form-view/structure-form/structure-public-target/structure-public-target.component.html
+++ b/src/app/form/form-view/structure-form/structure-public-target/structure-public-target.component.html
@@ -8,74 +8,84 @@
       [icon]="'arrowBack'"
     ></app-svg-icon>
     <div class="titleContent">
-      <h3>Quel public peut être accueilli dans cette structure&nbsp;?</h3>
-      <p>Plusieurs choix possibles</p>
+      <h3>
+        {{
+          isMandatoryFields
+            ? 'Quel public peut être accueilli dans cette structure&nbsp;?'
+            : 'Quels publics spécifiques peuvent être accueillis dans cette structure&nbsp;?'
+        }}
+      </h3>
+      <p>{{ isMandatoryFields ? '' : 'Facultatif - ' }}Plusieurs choix possibles</p>
     </div>
   </div>
   <p class="missing-information" *ngIf="isEditMode && !structureForm.get('categories').get('age').valid">
     <app-svg-icon [iconClass]="'icon-26'" [type]="'form'" [icon]="'notValidate'" class="validationIcon"></app-svg-icon>
     <span>Il faut renseigner au moins un champ</span>
   </p>
-  <div *ngIf="publicOthers">
-    <div class="btn-grid">
-      <app-button
-        *ngFor="let choice of publicOthers.modules"
-        [ngClass]="{ selectedChoice: true }"
-        [extraClass]="isInArray(choice.id, 'publicOthers') ? 'selected' : ''"
-        [style]="buttonTypeEnum.CheckButton"
-        [text]="choice.name"
-        (action)="updateChoicePublic(choice.id, 'publicOthers')"
-      ></app-button>
+  <ng-container *ngIf="!isMandatoryFields">
+    <div *ngIf="languageAndIlliteracy">
+      <div class="title">
+        <h4>Langue et illettrisme</h4>
+      </div>
+      <div class="btn-grid">
+        <app-button
+          *ngFor="let choice of languageAndIlliteracy.modules"
+          [ngClass]="{ selectedChoice: true }"
+          [extraClass]="isInArray(choice.id, 'languageAndIlliteracy') ? 'selected' : ''"
+          [style]="buttonTypeEnum.CheckButton"
+          [text]="choice.name"
+          (action)="updateChoicePublic(choice.id, 'languageAndIlliteracy')"
+        ></app-button>
+      </div>
     </div>
-  </div>
-  <div *ngIf="age">
-    <div class="title">
-      <h4>Âge</h4>
-    </div>
-    <div class="btn-grid">
-      <app-button
-        *ngFor="let choice of age.modules"
-        [ngClass]="{ selectedChoice: true }"
-        [extraClass]="isInArray(choice.id, 'age') ? 'selected' : ''"
-        [style]="buttonTypeEnum.CheckButton"
-        [text]="choice.name"
-        (action)="updateChoicePublic(choice.id, 'age')"
-      ></app-button>
-    </div>
-  </div>
+    <div *ngIf="handicaps">
+      <div class="title">
+        <h4>Handicaps</h4>
+      </div>
 
-  <div *ngIf="languageAndIlliteracy">
-    <div class="title">
-      <h4>Langue et illettrisme</h4>
-      <p>Facultatif</p>
+      <div class="btn-grid">
+        <app-button
+          *ngFor="let choice of handicaps.modules"
+          [ngClass]="{ selectedChoice: true }"
+          [extraClass]="isInArray(choice.id, 'handicaps') ? 'selected' : ''"
+          [style]="buttonTypeEnum.CheckButton"
+          [text]="choice.name"
+          (action)="updateChoicePublic(choice.id, 'handicaps')"
+        ></app-button>
+      </div>
     </div>
-    <div class="btn-grid">
-      <app-button
-        *ngFor="let choice of languageAndIlliteracy.modules"
-        [ngClass]="{ selectedChoice: true }"
-        [extraClass]="isInArray(choice.id, 'languageAndIlliteracy') ? 'selected' : ''"
-        [style]="buttonTypeEnum.CheckButton"
-        [text]="choice.name"
-        (action)="updateChoicePublic(choice.id, 'languageAndIlliteracy')"
-      ></app-button>
-    </div>
-  </div>
-
-  <div *ngIf="handicaps">
-    <div class="title">
-      <h4>Handicaps</h4>
-      <p>Facultatif</p>
+    <div *ngIf="publicOthers">
+      <div class="title">
+        <h4>Autre</h4>
+      </div>
+      <div class="btn-grid">
+        <app-button
+          *ngFor="let choice of publicOthers.modules"
+          [ngClass]="{ selectedChoice: true }"
+          [extraClass]="isInArray(choice.id, 'publicOthers') ? 'selected' : ''"
+          [style]="buttonTypeEnum.CheckButton"
+          [text]="choice.name"
+          (action)="updateChoicePublic(choice.id, 'publicOthers')"
+        ></app-button>
+      </div>
     </div>
+  </ng-container>
 
-    <div class="btn-grid">
-      <app-button
-        *ngFor="let choice of handicaps.modules"
-        [ngClass]="{ selectedChoice: true }"
-        [extraClass]="isInArray(choice.id, 'handicaps') ? 'selected' : ''"
-        [style]="buttonTypeEnum.CheckButton"
-        [text]="choice.name"
-        (action)="updateChoicePublic(choice.id, 'handicaps')"
-      ></app-button>
+  <ng-container *ngIf="isMandatoryFields">
+    <div *ngIf="age">
+      <div class="title">
+        <h4>Âge</h4>
+      </div>
+      <div class="btn-grid">
+        <app-button
+          *ngFor="let choice of age.modules"
+          [ngClass]="{ selectedChoice: true }"
+          [extraClass]="isInArray(choice.id, 'age') ? 'selected' : ''"
+          [style]="buttonTypeEnum.CheckButton"
+          [text]="choice.name"
+          (action)="updateChoicePublic(choice.id, 'age')"
+        ></app-button>
+      </div>
     </div>
-  </div>
+  </ng-container>
 </form>
diff --git a/src/app/form/form-view/structure-form/structure-public-target/structure-public-target.component.ts b/src/app/form/form-view/structure-form/structure-public-target/structure-public-target.component.ts
index def473a16..6471b6372 100644
--- a/src/app/form/form-view/structure-form/structure-public-target/structure-public-target.component.ts
+++ b/src/app/form/form-view/structure-form/structure-public-target/structure-public-target.component.ts
@@ -14,6 +14,7 @@ export class StructurePublicTargetComponent implements OnInit {
   @Input() handicaps: Category;
   @Input() publicOthers: Category;
   @Input() isEditMode: boolean;
+  @Input() isMandatoryFields = true;
   @Output() updateChoice = new EventEmitter<any>();
   @Output() validateForm = new EventEmitter<any>();
 
diff --git a/src/app/form/form-view/structure-form/structureFormStep.enum.ts b/src/app/form/form-view/structure-form/structureFormStep.enum.ts
index 84e846544..5e1ce4ffb 100644
--- a/src/app/form/form-view/structure-form/structureFormStep.enum.ts
+++ b/src/app/form/form-view/structure-form/structureFormStep.enum.ts
@@ -12,6 +12,7 @@ export enum structureFormStep {
   structurePmr,
   structureWebAndSocialNetwork,
   structurePublicTarget,
+  structurePublicTargetOptional,
   structureDigitalHelpingAccompaniment,
   structureDigitalHelpingAccompanimentOther,
   structureTrainingType,
diff --git a/src/app/profile/structure-edition-summary/structure-edition-summary.component.html b/src/app/profile/structure-edition-summary/structure-edition-summary.component.html
index 039edaef5..84bd07da6 100644
--- a/src/app/profile/structure-edition-summary/structure-edition-summary.component.html
+++ b/src/app/profile/structure-edition-summary/structure-edition-summary.component.html
@@ -300,6 +300,25 @@
           <app-missing-information></app-missing-information>
         </ng-container>
       </div>
+    </div>
+
+    <div class="section publics">
+      <div class="sectionHeader">
+        <p>Public spécifique admis</p>
+        <app-button
+          class="hide-on-mobile"
+          [text]="'Modifier'"
+          [style]="buttonTypeEnum.Secondary"
+          [extraClass]="'editButton'"
+          (action)="goToEdit(structureFormStep.structurePublicTargetOptional)"
+        ></app-button>
+        <app-button
+          class="hide-on-desktop"
+          [iconBtn]="'edit'"
+          [style]="buttonTypeEnum.SecondaryOnlyIcon"
+          (action)="goToEdit(structureFormStep.structurePublicTargetOptional)"
+        ></app-button>
+      </div>
       <div class="content">
         <ng-container
           *ngIf="
@@ -339,6 +358,17 @@
           </div>
         </ng-container>
       </div>
+      <div class="content">
+        <ng-container
+          *ngIf="
+            structure.categoriesDisplay.languageAndIlliteracy.length === 0 &&
+            structure.categoriesDisplay.publicOthers.length === 0 &&
+            structure.categoriesDisplay.handicaps.length === 0
+          "
+        >
+          <app-no-information></app-no-information>
+        </ng-container>
+      </div>
     </div>
 
     <div class="section proceduresAccompaniment">
diff --git a/src/app/utils/formUtils.ts b/src/app/utils/formUtils.ts
index 8ce4f2a2c..97cb7c613 100644
--- a/src/app/utils/formUtils.ts
+++ b/src/app/utils/formUtils.ts
@@ -30,7 +30,7 @@ export class formUtils {
       inputs: ['website', 'facebook', 'twitter', 'instagram'],
     },
     { step: structureFormStep.structurePublicTarget, name: 'Public admis', inputs: ['publics'] },
-
+    { step: structureFormStep.structurePublicTarget, name: 'Public admis - Optionnel', inputs: ['publics'] },
     {
       step: structureFormStep.structureDigitalHelpingAccompaniment,
       name: 'Aides au numérique',
-- 
GitLab