From e6ded6a0718ffb121f30dc7e0117a9337c38b5d1 Mon Sep 17 00:00:00 2001
From: Pierre Ecarlat <pecarlat@grandlyon.com>
Date: Thu, 28 Mar 2024 09:14:00 +0000
Subject: [PATCH] fix: Some fixes

---
 .../hour-picker/hour-picker.component.html          |  4 ++--
 .../components/hour-picker/hour-picker.component.ts |  4 ++--
 .../structure-details.component.html                | 13 ++++++++++---
 .../structure-details.component.ts                  |  6 ++++++
 4 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/app/shared/components/hour-picker/hour-picker.component.html b/src/app/shared/components/hour-picker/hour-picker.component.html
index b52deadd1..4cf6b42b8 100644
--- a/src/app/shared/components/hour-picker/hour-picker.component.html
+++ b/src/app/shared/components/hour-picker/hour-picker.component.html
@@ -19,7 +19,7 @@
           [label]="'De :'"
           [size]="'large'"
           [status]="getStatus(hour.start)"
-          [statusText]="getStatusText(hour)"
+          [statusText]="getStatusText(hour.start)"
           [(value)]="hour.start"
           (valueChange)="submitForm()"
         />
@@ -31,7 +31,7 @@
           [label]="'Jusqu’à :'"
           [size]="'large'"
           [status]="getStatus(hour.start, hour.end)"
-          [statusText]="getStatusText(hour)"
+          [statusText]="getStatusText(hour.start, hour.end)"
           [(value)]="hour.end"
           (valueChange)="submitForm()"
         />
diff --git a/src/app/shared/components/hour-picker/hour-picker.component.ts b/src/app/shared/components/hour-picker/hour-picker.component.ts
index 88616a331..217fd8a14 100644
--- a/src/app/shared/components/hour-picker/hour-picker.component.ts
+++ b/src/app/shared/components/hour-picker/hour-picker.component.ts
@@ -174,7 +174,7 @@ export class HourPickerComponent implements OnInit {
     return end && end > start ? 'success' : 'error';
   }
 
-  getStatusText(hour: { start: string; end: string }): string {
-    return 'Horaire ' + (this.getStatus(hour.start, hour.end) === 'error' ? 'invalide' : 'valide');
+  getStatusText(start: string, end?: string): string {
+    return 'Horaire ' + (this.getStatus(start, end) === 'error' ? 'invalide' : 'valide');
   }
 }
diff --git a/src/app/structure-list/components/structure-details/structure-details.component.html b/src/app/structure-list/components/structure-details/structure-details.component.html
index e6ba1b6cc..cdc28cb54 100644
--- a/src/app/structure-list/components/structure-details/structure-details.component.html
+++ b/src/app/structure-list/components/structure-details/structure-details.component.html
@@ -21,7 +21,14 @@
           [clickable]="false"
         />
       </div>
-      <app-svg-icon tabindex="0" [folder]="'ico'" [icon]="'cross'" [iconColor]="'grey-1'" (click)="close()" (keyup.enter)="close()" />
+      <app-svg-icon
+        tabindex="0"
+        [folder]="'ico'"
+        [icon]="'cross'"
+        [iconColor]="'grey-1'"
+        (click)="close()"
+        (keyup.enter)="close()"
+      />
     </section>
 
     <section *ngIf="showButtons" class="actions hide-on-print">
@@ -66,7 +73,7 @@
       </div>
       <!-- Je travaille ici -->
       <div
-        *ngIf="!profileService.isLinkedToStructure(structure._id)"
+        *ngIf="!isInStructure"
         class="clickableDiv"
         role="button"
         tabindex="0"
@@ -78,7 +85,7 @@
       </div>
       <!-- Modifier la structure -->
       <div
-        *ngIf="profileService.isLinkedToStructure(structure._id) || profileService.isAdmin()"
+        *ngIf="isInStructure || profileService.isAdmin()"
         class="clickableDiv"
         role="button"
         tabindex="0"
diff --git a/src/app/structure-list/components/structure-details/structure-details.component.ts b/src/app/structure-list/components/structure-details/structure-details.component.ts
index bf023d609..973eba153 100644
--- a/src/app/structure-list/components/structure-details/structure-details.component.ts
+++ b/src/app/structure-list/components/structure-details/structure-details.component.ts
@@ -56,6 +56,7 @@ export class StructureDetailsComponent implements OnInit {
   public showButtons = true;
   public Equipment = Equipment;
   public FreeWorkshop = FreeWorkshop;
+  public isInStructure = false;
 
   constructor(
     private searchService: SearchService,
@@ -74,6 +75,7 @@ export class StructureDetailsComponent implements OnInit {
       if (queryParams.id) {
         this.structureService.getStructure(queryParams.id).subscribe((structure) => {
           this.structure = new Structure(structure);
+          this.profileIsLinkedToStructure(this.structure._id);
           this.isLoading = true;
           this.initForm();
         });
@@ -107,6 +109,10 @@ export class StructureDetailsComponent implements OnInit {
     });
   }
 
+  public async profileIsLinkedToStructure(id: string): Promise<void> {
+    this.isInStructure = await this.profileService.isLinkedToStructure(id);
+  }
+
   public userIsLoggedIn(): boolean {
     return this.authService.isLoggedIn();
   }
-- 
GitLab