From 23f1ad8b5927879dcdab41446036512f8dc63efb Mon Sep 17 00:00:00 2001
From: Augustin LECONTE <["ext.sopra.aleconte@grandlyon.com"]>
Date: Wed, 15 Dec 2021 10:52:11 +0000
Subject: [PATCH] feat: add admin remove from structure

---
 package.json                                          |  1 +
 src/app/profile/profile.component.html                |  6 +++++-
 .../structure-options-modal.component.ts              | 11 ++++++++++-
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/package.json b/package.json
index d9282d159..da8e72a2c 100644
--- a/package.json
+++ b/package.json
@@ -35,6 +35,7 @@
     "leaflet.locatecontrol": "^0.72.0",
     "lodash": "^4.17.20",
     "luxon": "^1.25.0",
+    "npx": "^10.2.2",
     "rxjs": "~6.6.0",
     "tslib": "^2.0.0",
     "zone.js": "~0.10.2"
diff --git a/src/app/profile/profile.component.html b/src/app/profile/profile.component.html
index 5dbf5d216..43c5a29af 100644
--- a/src/app/profile/profile.component.html
+++ b/src/app/profile/profile.component.html
@@ -31,7 +31,11 @@
               <a class="structureName" routerLink="/acteurs" [state]="{ data: s.structure }">{{
                 s.structure.structureName
               }}</a>
-              <app-structure-options-modal [structure]="s" (closed)="ngOnInit()"></app-structure-options-modal>
+              <app-structure-options-modal
+                [structure]="s"
+                (closed)="ngOnInit()"
+                (closedWithRefresh)="ngOnInit()"
+              ></app-structure-options-modal>
             </div>
             <div fxLayout="column" fxLayoutGap="14px" class="ownersBlock">
               <p class="ownerName" *ngFor="let owner of s.owners">{{ owner.email }}</p>
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 dccf978c4..7f3ea1a62 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
@@ -23,6 +23,7 @@ export class StructureOptionsModalComponent implements OnInit {
   @Input() public userProfile?: User;
   @Input() public isEditFormView? = false;
   @Output() closed = new EventEmitter();
+  @Output() closedWithRefresh = new EventEmitter();
   public active: boolean;
 
   // Password profile
@@ -135,10 +136,17 @@ export class StructureOptionsModalComponent implements OnInit {
 
   // Profile Section
   public closeModalOptsProfile(): void {
+    this.editModal = null;
+    this.formEmail.reset();
+    this.formPassword.reset();
+  }
+
+  public closeModalOptsProfileAndRefresh(): void {
     this.editModal = null;
     //this.formAddAccount.reset();
     this.formEmail.reset();
     this.formPassword.reset();
+    this.closedWithRefresh.emit();
   }
 
   private toggleDeleteAccountModal(): void {
@@ -196,6 +204,7 @@ export class StructureOptionsModalComponent implements OnInit {
     user.email = this.fAddAccount.email.value;
     this.structureService.addOwnerToStructure(user, this.structure.structure._id).subscribe(
       () => {
+        this.closedWithRefresh.emit('');
         this.closeModalOptsProfile();
         this.formAddAccount.reset();
       },
@@ -209,7 +218,7 @@ export class StructureOptionsModalComponent implements OnInit {
     this.structureService.removeOwnerFromStructure(owner, this.structure.structure._id).subscribe(() => {
       this.structure.owners = this.structure.owners.filter((o) => o.id !== owner);
       if (this.structure.owners.length == 0) {
-        this.closeModalOptsProfile();
+        this.closeModalOptsProfileAndRefresh();
       }
     });
   }
-- 
GitLab