From 7e474af4c9616595947272066c48f319c04ba2d9 Mon Sep 17 00:00:00 2001
From: Antonin Coquet <ext.sopra.acoquet@grandlyon.com>
Date: Tue, 6 Apr 2021 14:14:47 +0200
Subject: [PATCH] add content value to modal

---
 src/app/services/structure.service.ts                    | 9 +++++----
 .../text-input-modal/text-input-modal.component.html     | 7 +++----
 .../text-input-modal/text-input-modal.component.ts       | 5 +++--
 .../structure-details/structure-details.component.html   | 1 +
 .../structure-details/structure-details.component.ts     | 9 +++++----
 5 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/app/services/structure.service.ts b/src/app/services/structure.service.ts
index ecaa01eea..507582392 100644
--- a/src/app/services/structure.service.ts
+++ b/src/app/services/structure.service.ts
@@ -194,9 +194,10 @@ export class StructureService {
     return this.http.post<any>(`${this.baseUrl}/${structureId}/withOwners`, { emailUser: profile.email });
   }
 
-  public sendMailOnStructureError(structureId: string, content: string, profile: User): Observable<boolean> {
-    console.log('send:', content, ' to:', structureId);
-    return;
-    //return this.http.post<any>(`${this.baseUrl}/${structureId}/withOwners`, { emailUser: profile.email });
+  public sendMailOnStructureError(structureId: string, content: string, profile: User) {
+    return this.http.post<any>(`${this.baseUrl}/reportStructureError`, {
+      structureId,
+      content: content,
+    });
   }
 }
diff --git a/src/app/shared/components/text-input-modal/text-input-modal.component.html b/src/app/shared/components/text-input-modal/text-input-modal.component.html
index d1835a7f3..15f690ba6 100644
--- a/src/app/shared/components/text-input-modal/text-input-modal.component.html
+++ b/src/app/shared/components/text-input-modal/text-input-modal.component.html
@@ -3,12 +3,11 @@
     <div class="contentModal" fxLayout="column" fxLayoutAlign="space-around center">
       <h3>ATTENTION</h3>
       <p>{{ content }}</p>
-      <textarea ng-model="myContent" id="story" class="textarea" name="story" rows="6">{{ placeholder }}</textarea>
+      <textarea #myText id="story" class="textarea" name="story" rows="6">{{ placeholder }}</textarea>
       <div class="footerModal" fxLayout="row" fxLayoutAlign="space-around center">
-        <button class="btn-primary small leave" (click)="closeModal(true)">Confirmer</button>
-        <button class="btn-primary small" (click)="closeModal(false)">Annuler</button>
+        <button class="btn-primary small leave" (click)="closeModal(true, myText.value)">Confirmer</button>
+        <button class="btn-primary small" (click)="closeModal(false, myText.value)">Annuler</button>
       </div>
-      {{ myContent }}
     </div>
   </div>
 </div>
diff --git a/src/app/shared/components/text-input-modal/text-input-modal.component.ts b/src/app/shared/components/text-input-modal/text-input-modal.component.ts
index 57a132f12..524396cda 100644
--- a/src/app/shared/components/text-input-modal/text-input-modal.component.ts
+++ b/src/app/shared/components/text-input-modal/text-input-modal.component.ts
@@ -10,11 +10,12 @@ export class TextInputModalComponent {
   @Input() public content: string;
   @Input() public placeholder: string;
   @Output() closed = new EventEmitter<boolean>();
+  @Output() newContent = new EventEmitter<{ content: string; shouldSend: boolean }>();
 
   public myContent: string;
   constructor() {}
 
-  public closeModal(value: boolean): void {
-    this.closed.emit(value);
+  public closeModal(shouldSend: boolean, content: string) {
+    this.newContent.emit({ content, shouldSend });
   }
 }
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 5df01d73d..a4e2d0c4f 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
@@ -385,4 +385,5 @@
     'Voulez-vous notifier res\'in d\'une erreur sur la fiche de cet acteur&nbsp;? Votre commentaire sera envoyé aux administrateurs.'
   "
   (closed)="sendErrorEmail($event)"
+  (newContent)="sendErrorEmail($event)"
 ></app-text-input-modal>
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 6203f7c3d..79042b400 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
@@ -295,11 +295,12 @@ export class StructureDetailsComponent implements OnInit {
     this.structureErrorModalOpenned = !this.structureErrorModalOpenned;
   }
 
-  public sendErrorEmail(shouldSend: boolean, content: string): void {
+  public sendErrorEmail(modalValue: any): void {
     this.displayModalError();
-    if (shouldSend) {
-      console.log('conrtent is:', content);
-      this.structureService.sendMailOnStructureError(this.structure._id, '', this.currentProfile);
+    if (modalValue.shouldSend) {
+      this.structureService
+        .sendMailOnStructureError(this.structure._id, modalValue.content, this.currentProfile)
+        .subscribe(() => {});
     }
   }
 }
-- 
GitLab