From a72cc2710b328a1fa9e57c6f63fd0db60d71573b Mon Sep 17 00:00:00 2001
From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com>
Date: Tue, 23 Feb 2021 16:24:28 +0100
Subject: [PATCH] fix(form) : add optionFormBtn to form

---
 src/app/form/form.component.html                     |  7 ++++++-
 src/app/form/form.component.ts                       | 12 +++++++++++-
 .../modal-options/modal-options.component.html       |  8 +++++++-
 .../modal-options/modal-options.component.ts         |  1 +
 .../structure-options-modal.component.html           |  1 +
 .../structure-options-modal.component.ts             |  1 +
 6 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/app/form/form.component.html b/src/app/form/form.component.html
index 517892876..dbfe52fe2 100644
--- a/src/app/form/form.component.html
+++ b/src/app/form/form.component.html
@@ -5,8 +5,13 @@
     (closed)="hasRedirectionAccepted($event)"
   ></app-modal-confirmation>
   <div class="content" *ngIf="!isLoading" [ngClass]="{ editMode: isEditMode }">
-    <div class="headerEditMode" *ngIf="isEditMode">
+    <div class="headerEditMode" *ngIf="isEditMode" fxLayout="row" fxLayoutAlign="space-between center">
       <h2>Modification de {{ editForm.get('structureName').value }}</h2>
+      <app-structure-options-modal
+        [structure]="structureWithOwners"
+        [isEditFormView]="true"
+        (closed)="structureDeleted()"
+      ></app-structure-options-modal>
     </div>
     <div class="returnBtnSection" *ngIf="isEditMode && currentPage != 0">
       <button class="btn-primary previous" (click)="goToSpecificPage(0, false)">
diff --git a/src/app/form/form.component.ts b/src/app/form/form.component.ts
index 2b9b3f25a..dcc151211 100644
--- a/src/app/form/form.component.ts
+++ b/src/app/form/form.component.ts
@@ -18,6 +18,7 @@ import { AuthService } from '../services/auth.service';
 import { first } from 'rxjs/operators';
 import { PageTypeEnum } from './pageType.enum';
 import { CustomRegExp } from '../utils/CustomRegExp';
+import { StructureWithOwners } from '../models/structureWithOwners.model';
 const { DateTime } = require('luxon');
 @Component({
   selector: 'app-structureForm',
@@ -71,6 +72,7 @@ export class FormComponent implements OnInit {
   public isJoinMode = false;
   public isLoading = false;
   public isWifiChoosen = false;
+  public structureWithOwners: StructureWithOwners;
 
   constructor(
     private structureService: StructureService,
@@ -92,7 +94,11 @@ export class FormComponent implements OnInit {
     if (history.state.data) {
       this.isEditMode = true;
       this.isWifiChoosen = true;
-      this.initForm(new Structure(history.state.data));
+      const editStructure = new Structure(history.state.data);
+      this.initForm(editStructure);
+      this.structureService.getStructureWithOwners(editStructure._id, this.profile).subscribe((s) => {
+        this.structureWithOwners = s;
+      });
     } else if (history.state.newUser) {
       this.isClaimMode = true;
       // Handle join strucutre, the case is very similar to claim
@@ -903,4 +909,8 @@ export class FormComponent implements OnInit {
   public displayClaimStructure(): boolean {
     return this.currentPage == this.pageTypeEnum.summary && !this.isEditMode && this.isClaimMode;
   }
+
+  public structureDeleted(): void {
+    this.router.navigateByUrl('home');
+  }
 }
diff --git a/src/app/shared/components/modal-options/modal-options.component.html b/src/app/shared/components/modal-options/modal-options.component.html
index 6d8a62025..0e45ca7cc 100644
--- a/src/app/shared/components/modal-options/modal-options.component.html
+++ b/src/app/shared/components/modal-options/modal-options.component.html
@@ -28,7 +28,13 @@
       <app-svg-icon [type]="'ico'" [iconColor]="'inherit'" [icon]="'remove'"></app-svg-icon>
       <p>Supprimer un compte</p>
     </div>
-    <div (click)="closeModal(functionType.editStructure)" fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="9px">
+    <div
+      *ngIf="!isEditFormView"
+      (click)="closeModal(functionType.editStructure)"
+      fxLayout="row"
+      fxLayoutAlign="start center"
+      fxLayoutGap="9px"
+    >
       <app-svg-icon [type]="'ico'" [iconColor]="'inherit'" [icon]="'edit'"></app-svg-icon>
       <p>Modifier la structure</p>
     </div>
diff --git a/src/app/shared/components/modal-options/modal-options.component.ts b/src/app/shared/components/modal-options/modal-options.component.ts
index 1fa03b1ed..4de502a5c 100644
--- a/src/app/shared/components/modal-options/modal-options.component.ts
+++ b/src/app/shared/components/modal-options/modal-options.component.ts
@@ -12,6 +12,7 @@ export class ModalOptionsComponent implements OnInit {
   constructor() {}
   @Input() isModalProfileOpts = false;
   @Input() hasOwners = true;
+  @Input() public isEditFormView? = false;
   @Output() closed = new EventEmitter<number>();
   ngOnInit(): void {}
 
diff --git a/src/app/shared/components/structure-options-modal/structure-options-modal.component.html b/src/app/shared/components/structure-options-modal/structure-options-modal.component.html
index 1857d0baa..a5f68cc4d 100644
--- a/src/app/shared/components/structure-options-modal/structure-options-modal.component.html
+++ b/src/app/shared/components/structure-options-modal/structure-options-modal.component.html
@@ -7,6 +7,7 @@
       <ul *ngIf="showModalOption" class="dropdown">
         <app-modal-options
           [isModalProfileOpts]="!structure"
+          [isEditFormView]="structure && isEditFormView"
           [hasOwners]="structure && structure.owners.length > 0"
           (closed)="closeModalOpts($event)"
         ></app-modal-options>
diff --git a/src/app/shared/components/structure-options-modal/structure-options-modal.component.ts b/src/app/shared/components/structure-options-modal/structure-options-modal.component.ts
index 2ae893c84..dccf978c4 100644
--- a/src/app/shared/components/structure-options-modal/structure-options-modal.component.ts
+++ b/src/app/shared/components/structure-options-modal/structure-options-modal.component.ts
@@ -21,6 +21,7 @@ export class StructureOptionsModalComponent implements OnInit {
   // Global var
   @Input() public structure?: StructureWithOwners;
   @Input() public userProfile?: User;
+  @Input() public isEditFormView? = false;
   @Output() closed = new EventEmitter();
   public active: boolean;
 
-- 
GitLab