From c177ddb659dc1d4248e3627de8957f2b36a89e76 Mon Sep 17 00:00:00 2001
From: Guilhem CARRON <gcarron@grandlyon.com>
Date: Wed, 21 Dec 2022 15:56:44 +0000
Subject: [PATCH] fix: several bugs on recette

---
 src/app/admin/admin-pannel.scss               |  3 +-
 .../claim-structure.component.html            |  1 +
 .../manage-lockdown-info.component.html       |  2 +-
 .../manage-employers.component.html           |  4 +-
 .../manage-jobs/manage-jobs.component.html    |  4 +-
 .../admin-structures-list.component.html      |  1 +
 .../information-step.component.html           |  2 +-
 .../structure-contact.component.html          |  9 +--
 .../structure-form.component.ts               |  2 +-
 src/app/profile/edit/edit.component.ts        | 57 +++++++++++--------
 .../profile-structure.component.html          |  2 +-
 .../profile-structure.component.scss          |  2 +-
 .../profile-structure.component.ts            |  4 +-
 src/app/profile/profile.component.html        |  4 +-
 .../structure-edition-summary.component.html  |  6 +-
 src/app/utils/CustomRegExp.ts                 |  2 +-
 src/app/utils/formUtils.ts                    | 11 +++-
 17 files changed, 64 insertions(+), 52 deletions(-)

diff --git a/src/app/admin/admin-pannel.scss b/src/app/admin/admin-pannel.scss
index 1b7c40a19..1de269d3a 100644
--- a/src/app/admin/admin-pannel.scss
+++ b/src/app/admin/admin-pannel.scss
@@ -12,7 +12,8 @@
 }
 
 .results-column {
-  width: 30%;
+  width: 100%;
+  max-width: 600px;
 }
 
 .incomplete {
diff --git a/src/app/admin/components/claim-structure/claim-structure.component.html b/src/app/admin/components/claim-structure/claim-structure.component.html
index 8dae1d010..677c6657e 100644
--- a/src/app/admin/components/claim-structure/claim-structure.component.html
+++ b/src/app/admin/components/claim-structure/claim-structure.component.html
@@ -1,4 +1,5 @@
 <div fxLayout="column" fxLayoutAlign="center center">
+  <h2>Revendication structure</h2>
   <table *ngIf="isClaimedStructure" aria-describedby="demands attachment results" class="results-tab">
     <thead>
       <th scope="col">Utilisateur</th>
diff --git a/src/app/admin/components/lockdown-info/manage-lockdown-info.component.html b/src/app/admin/components/lockdown-info/manage-lockdown-info.component.html
index d2879e51c..e4e78daa9 100644
--- a/src/app/admin/components/lockdown-info/manage-lockdown-info.component.html
+++ b/src/app/admin/components/lockdown-info/manage-lockdown-info.component.html
@@ -2,7 +2,7 @@
   <img class="loader-gif" src="/assets/gif/loader_circle_grey.gif" alt />
 </div>
 <div *ngIf="!isLoading" fxLayout="column" fxLayoutAlign="center center">
-  <H2>Gestion de l'affichage des infos Covid</H2>
+  <h2>Gestion de l'affichage des infos Covid</h2>
   <div *ngIf="lockdownInfoDisplay">Les infos covid sont actuellement affichées dans les fiches structure.</div>
   <div *ngIf="!lockdownInfoDisplay">Les infos covid ne sont actuellement pas affichées dans les fiches structure.</div>
   <div *ngIf="!error" class="singleCheckbox" [ngClass]="{ checked: lockdownInfoDisplay }">
diff --git a/src/app/admin/components/manage-employers/manage-employers.component.html b/src/app/admin/components/manage-employers/manage-employers.component.html
index 8a55a3a57..8727f210c 100644
--- a/src/app/admin/components/manage-employers/manage-employers.component.html
+++ b/src/app/admin/components/manage-employers/manage-employers.component.html
@@ -1,10 +1,10 @@
 <div fxLayout="column" fxLayoutGap="5px" fxLayoutAlign="center center" class="userBlock">
-  <h3>
+  <h2>
     Gestion des employeurs
     <span *ngIf="unvalidatedEmployers && validatedEmployers">
       ({{ unvalidatedEmployers.length + validatedEmployers.length }})
     </span>
-  </h3>
+  </h2>
 </div>
 
 <div class="tables-list">
diff --git a/src/app/admin/components/manage-jobs/manage-jobs.component.html b/src/app/admin/components/manage-jobs/manage-jobs.component.html
index 5bec9d716..b35f3cceb 100644
--- a/src/app/admin/components/manage-jobs/manage-jobs.component.html
+++ b/src/app/admin/components/manage-jobs/manage-jobs.component.html
@@ -1,8 +1,8 @@
 <div fxLayout="column" fxLayoutGap="5px" fxLayoutAlign="center center" class="userBlock">
-  <h3>
+  <h2>
     Gestion des fonctions
     <span *ngIf="unvalidatedJobs && validatedJobs"> ({{ unvalidatedJobs.length + validatedJobs.length }}) </span>
-  </h3>
+  </h2>
 </div>
 
 <div class="tables-list">
diff --git a/src/app/admin/components/structures-list/admin-structures-list.component.html b/src/app/admin/components/structures-list/admin-structures-list.component.html
index e71fd4da0..c2a25e3ee 100644
--- a/src/app/admin/components/structures-list/admin-structures-list.component.html
+++ b/src/app/admin/components/structures-list/admin-structures-list.component.html
@@ -2,6 +2,7 @@
   <img class="loader-gif" src="/assets/gif/loader_circle_grey.gif" alt />
 </div>
 <div *ngIf="!isLoading" fxLayout="column" fxLayoutAlign="center center">
+  <h2>Liste structures</h2>
   <table aria-describedby="demands attachment results" class="results-tab results-column">
     <thead>
       <th colspan="2" scope="colgroup">
diff --git a/src/app/form/form-view/global-components/information-step/information-step.component.html b/src/app/form/form-view/global-components/information-step/information-step.component.html
index e24e9cb9e..ba9aeecea 100644
--- a/src/app/form/form-view/global-components/information-step/information-step.component.html
+++ b/src/app/form/form-view/global-components/information-step/information-step.component.html
@@ -16,7 +16,7 @@
     <img src="../../assets/form/profileSkip.svg" alt="Image profil" />
     <div class="footerForm" fxLayout="row" fxLayoutGap="10px" fxLayoutAlign="center center">
       <app-button (action)="goToHome()" [text]="'Plus tard'"></app-button>
-      <app-button (action)="goToNextPage()" [text]="'C`est parti !'" [style]="buttonTypeEnum.Primary"></app-button>
+      <app-button (action)="goToNextPage()" [text]="'C\'est parti !'" [style]="buttonTypeEnum.Primary"></app-button>
     </div>
   </div>
 </ng-container>
diff --git a/src/app/form/form-view/structure-form/structure-contact/structure-contact.component.html b/src/app/form/form-view/structure-form/structure-contact/structure-contact.component.html
index 088362abb..17f79d2fc 100644
--- a/src/app/form/form-view/structure-form/structure-contact/structure-contact.component.html
+++ b/src/app/form/form-view/structure-form/structure-contact/structure-contact.component.html
@@ -9,15 +9,9 @@
     ></app-svg-icon>
     <div class="titleContent">
       <h3>Comment joindre votre structure&nbsp;?</h3>
+      <label class="label-optional">Veuillez renseigner au moins un des 2 champs</label>
     </div>
   </div>
-  <p
-    class="missing-information"
-    *ngIf="isEditMode && (!structureForm.get('contactPhone').valid || !structureForm.get('contactMail').valid)"
-  >
-    <app-svg-icon [iconClass]="'icon-26'" [type]="'form'" [icon]="'notValidate'" class="validationIcon"></app-svg-icon>
-    <span>Il faut renseigner tous les champs</span>
-  </p>
   <div class="form-group" fxLayout="column">
     <label for="structureName">Email de la structure</label>
     <div fxLayout="row" fxLayoutGap="13px">
@@ -39,7 +33,6 @@
   <div class="form-group" fxLayout="column">
     <div fxLayout="row" fxLayoutGap="8px">
       <label for="contactPhone">Téléphone de la structure</label>
-      <label class="label-optional">(Facultatif)</label>
     </div>
     <div fxLayout="row" fxLayoutGap="13px">
       <input
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 5cdc8cba6..f5b0c3964 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
@@ -157,7 +157,7 @@ export class StructureFormComponent implements OnChanges, OnInit {
         valid: this.structureForm.get('structureName').valid && this.structureForm.get('address').valid,
       };
       this.pagesValidation[structureFormStep.structureContact] = {
-        valid: this.structureForm.get('contactMail').valid && this.structureForm.get('contactPhone').valid,
+        valid: this.structureForm.get('contactMail').valid || this.structureForm.get('contactPhone').valid,
       };
       this.pagesValidation[structureFormStep.structureAccompanimentChoice] = {
         valid: this.structureForm.get('placeOfReception').valid,
diff --git a/src/app/profile/edit/edit.component.ts b/src/app/profile/edit/edit.component.ts
index 3f243acba..feece6abe 100644
--- a/src/app/profile/edit/edit.component.ts
+++ b/src/app/profile/edit/edit.component.ts
@@ -2,8 +2,7 @@ import { HttpErrorResponse } from '@angular/common/http';
 import { ChangeDetectorRef, Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
 import { Router } from '@angular/router';
 import * as _ from 'lodash';
-import { forkJoin, of } from 'rxjs';
-import { catchError, first, map } from 'rxjs/operators';
+import { catchError, first } from 'rxjs/operators';
 import { Employer } from '../../models/employer.model';
 import { Job } from '../../models/job.model';
 import { User } from '../../models/user.model';
@@ -58,6 +57,7 @@ export class EditComponent implements OnInit {
   private selectedEmployer: Employer;
   private isAlreadySearching = false;
   public isNewUser = false;
+  public isNewEmployer: boolean;
   @ViewChild('searchEmployer') searchEmployer: ElementRef;
   @ViewChild('newJobInput') newJobInput: ElementRef;
 
@@ -207,7 +207,7 @@ export class EditComponent implements OnInit {
       })
       .subscribe((user: User) => {
         this.notificationService.showSuccess('Vos informations ont bien été enregistrées');
-        //Update localstorage
+        // Update localStorage
         const updatedUser = {
           ...this.authService.userSubject.value,
           name: user.name,
@@ -222,26 +222,26 @@ export class EditComponent implements OnInit {
   }
 
   public confirmEmployer(): void {
-    if (this.newJob) this.selectedJob = this.newJob;
-    forkJoin({
-      employer: this.profileService.createEmployer(this.selectedEmployer).pipe(
-        map((res) => res),
-        catchError(() => of(this.selectedEmployer))
-      ),
-      job: this.profileService.createJob(this.selectedJob).pipe(
-        map((res) => res),
-        catchError(() => of(this.selectJob))
-      ),
-    }).subscribe(() => {
-      this.profileService.updateProfile(this.selectedEmployer.name, this.selectedJob.name).subscribe(
-        () => {
-          this.router.navigate(['/profile']);
-          this.notificationService.showSuccess('Vos informations ont bien été enregistrées');
-        },
-        () => {
-          this.notificationService.showError("Vos informations n'ont pas été enregistrées", 'Une erreur est survenue');
-        }
-      );
+    if (this.newJob) {
+      this.selectedJob = this.newJob;
+      this.profileService.createJob(this.selectedJob).subscribe((res) => {
+        console.log(res);
+      });
+    }
+    if (this.isNewEmployer) {
+      this.profileService.createEmployer(this.selectedEmployer).subscribe((res) => {
+        console.log(res);
+      });
+    }
+
+    this.profileService.updateProfile(this.selectedEmployer.name, this.selectedJob.name).subscribe({
+      next: () => {
+        this.router.navigate(['/profile']);
+        this.notificationService.showSuccess('Vos informations ont bien été enregistrées');
+      },
+      error: () => {
+        this.notificationService.showError("Vos informations n'ont pas été enregistrées", 'Une erreur est survenue');
+      },
     });
   }
 
@@ -306,9 +306,10 @@ export class EditComponent implements OnInit {
       );
   }
 
-  //Jobs
+  // Jobs
   public selectJob(job: Job): void {
     this.selectedJob = job;
+    this.newJob = null;
   }
   public isSelectedJob(job: Job): boolean {
     return this.selectedJob && this.selectedJob.name === job.name;
@@ -320,17 +321,23 @@ export class EditComponent implements OnInit {
     this.newJob = new Job({ name: value, validated: false, hasPersonalOffer: true });
   }
 
-  //Structures
+  // Structures
   public onSearchChange(searchString: string): void {
     if (searchString.length <= 2) this.getEmployers();
     this.getEmployers(searchString);
     this.selectedEmployer = new Employer({ name: searchString, validated: false });
+    if (!this.employers.map((employer) => employer.name).includes(this.selectedEmployer?.name)) {
+      this.isNewEmployer = true;
+    } else {
+      this.isNewEmployer = false;
+    }
   }
 
   public selectEmployer(employer: Employer): void {
     if (employer) this.searchEmployer.nativeElement.value = employer.name;
     this.selectedEmployer = employer;
     this.employers = [];
+    this.isNewEmployer = false;
   }
 
   private getEmployers(searchString: string = '') {
diff --git a/src/app/profile/profile-structure/profile-structure.component.html b/src/app/profile/profile-structure/profile-structure.component.html
index af083fd2e..69546f06c 100644
--- a/src/app/profile/profile-structure/profile-structure.component.html
+++ b/src/app/profile/profile-structure/profile-structure.component.html
@@ -23,7 +23,7 @@
         </p>
       </div>
       <app-button
-        *ngIf="isPending"
+        *ngIf="isPending && !isPublic"
         class="hide-on-mobile"
         [type]="'button'"
         [iconType]="'form'"
diff --git a/src/app/profile/profile-structure/profile-structure.component.scss b/src/app/profile/profile-structure/profile-structure.component.scss
index 9ec224513..449103997 100644
--- a/src/app/profile/profile-structure/profile-structure.component.scss
+++ b/src/app/profile/profile-structure/profile-structure.component.scss
@@ -35,7 +35,7 @@
       display: flex;
       align-items: center;
       ::ng-deep button {
-        margin-right: 1rem;
+        margin-right: 0.7rem;
         margin-top: 0.25rem;
       }
       .showDetails {
diff --git a/src/app/profile/profile-structure/profile-structure.component.ts b/src/app/profile/profile-structure/profile-structure.component.ts
index ddeddf874..50031c9c6 100644
--- a/src/app/profile/profile-structure/profile-structure.component.ts
+++ b/src/app/profile/profile-structure/profile-structure.component.ts
@@ -136,7 +136,9 @@ export class ProfileStructureComponent implements OnInit {
     }
   }
   public getFormattedDate(): string {
-    if (this.joinRequestDate) return DateTime.fromISO(this.joinRequestDate, { zone: 'Europe/Paris' }).toISODate();
+    if (this.joinRequestDate) {
+      return DateTime.fromISO(this.joinRequestDate, { zone: 'Europe/Paris' }).toFormat('dd-MM-yyyy');
+    }
   }
 
   public handleCancelJoin(idStructure: string): void {
diff --git a/src/app/profile/profile.component.html b/src/app/profile/profile.component.html
index 1a1f46f2f..983c85ebf 100644
--- a/src/app/profile/profile.component.html
+++ b/src/app/profile/profile.component.html
@@ -60,7 +60,7 @@
     </div>
   </section>
 
-  <section *ngIf="userProfile.structuresLink.length">
+  <section>
     <div class="header">
       <h1 [ngPlural]="userProfile.structuresLink.length">
         <ng-template ngPluralCase="1">Structure</ng-template>
@@ -110,7 +110,7 @@
     </div>
     <app-button
       class="addStructure"
-      *ngIf="!isPublic && userProfile.structuresLink.length == 0"
+      *ngIf="!isPublic"
       [style]="buttonTypeEnum.SecondaryUltraWide"
       [iconBtn]="'add'"
       [text]="'Ajouter une structure'"
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 7e9c6f5db..79d354b62 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
@@ -55,12 +55,12 @@
         ></app-button>
       </div>
       <div class="content">
-        <app-missing-information *ngIf="!isFieldValid('contactPhone')"></app-missing-information>
+        <app-missing-information
+          *ngIf="!isFieldValid('contactPhone') && !isFieldValid('contactMail')"
+        ></app-missing-information>
         <p *ngIf="isFieldValid('contactPhone')">
           {{ structure.contactPhone }}
         </p>
-
-        <app-missing-information *ngIf="!isFieldValid('contactMail')"></app-missing-information>
         <p *ngIf="isFieldValid('contactMail')">
           <a [href]="mailHref">
             {{ structure.contactMail }}
diff --git a/src/app/utils/CustomRegExp.ts b/src/app/utils/CustomRegExp.ts
index 74d77eba7..7582ce5fa 100644
--- a/src/app/utils/CustomRegExp.ts
+++ b/src/app/utils/CustomRegExp.ts
@@ -18,7 +18,7 @@ export class CustomRegExp {
    * Validate an email
    */
   public static readonly EMAIL: RegExp = /^[A-Za-z0-9.\-_]+@[A-Za-z0-9.-]+[.][a-z]{2,3}$/; //NOSONAR
-  public static readonly TEXT_WITHOUT_NUMBER: RegExp = /^[A-Za-zÀ-ÖØ-öø-ÿ- ]{1,}$/; //NOSONAR
+  public static readonly TEXT_WITHOUT_NUMBER: RegExp = /^[A-Za-zÀ-ÖØ-öø-ÿ-\' ]{1,}$/; //NOSONAR
   /**
    * Validate a phone number (4 or 10 digits, allowing spaces, dashes and dots as spacers)
    */
diff --git a/src/app/utils/formUtils.ts b/src/app/utils/formUtils.ts
index d98605a92..9efa1ed23 100644
--- a/src/app/utils/formUtils.ts
+++ b/src/app/utils/formUtils.ts
@@ -88,9 +88,16 @@ export class formUtils {
       }),
       contactMail: new UntypedFormControl(
         structure.contactMail === 'unknown@unknown.com' ? null : structure.contactMail,
-        [Validators.required, Validators.pattern(CustomRegExp.EMAIL)]
+        !isEditMode
+          ? [Validators.required, Validators.pattern(CustomRegExp.EMAIL)]
+          : [Validators.pattern(CustomRegExp.EMAIL)]
+      ),
+      contactPhone: new UntypedFormControl(
+        structure.contactPhone,
+        !isEditMode
+          ? [Validators.required, Validators.pattern(CustomRegExp.PHONE)]
+          : [Validators.pattern(CustomRegExp.PHONE)]
       ),
-      contactPhone: new UntypedFormControl(structure.contactPhone, [Validators.pattern(CustomRegExp.PHONE)]),
       contactPersonFirstname: new UntypedFormControl(
         structure.contactPersonLastName,
         !isEditMode && Validators.required
-- 
GitLab