From a2b45c3d2081714e733c5d5d4d89ac4f451ecc72 Mon Sep 17 00:00:00 2001 From: Bastien DUMONT <bdumont@grandlyon.com> Date: Tue, 8 Nov 2022 13:58:14 +0100 Subject: [PATCH 1/2] add member without refreshing --- .../profile-structure.component.scss | 5 +++-- .../profile-structure/profile-structure.component.ts | 12 ++++++++++++ .../structure-add-member-modal.component.html | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/app/profile/profile-structure/profile-structure.component.scss b/src/app/profile/profile-structure/profile-structure.component.scss index 83aa6b653..d68ea7797 100644 --- a/src/app/profile/profile-structure/profile-structure.component.scss +++ b/src/app/profile/profile-structure/profile-structure.component.scss @@ -4,7 +4,7 @@ @import '../../../assets/scss/shapes'; .structureCard { - padding: 8px 16px 8px 8px; + padding: 8px 0; border: 1px solid $grey-5; border-radius: 4px; overflow: hidden; @@ -15,6 +15,7 @@ } .collapseHeader { + padding: 0 0.5rem; cursor: pointer; p { margin: 0 !important; @@ -35,7 +36,7 @@ } .collapseContent { - padding: 0 10px; + padding: 0 1rem; .infoSection { @include lato-regular-14; diff --git a/src/app/profile/profile-structure/profile-structure.component.ts b/src/app/profile/profile-structure/profile-structure.component.ts index a036f6366..520784842 100644 --- a/src/app/profile/profile-structure/profile-structure.component.ts +++ b/src/app/profile/profile-structure/profile-structure.component.ts @@ -6,6 +6,7 @@ import { structureFormStep } from '../../form/form-view/structure-form/structure import { Structure } from '../../models/structure.model'; import { StructureWithOwners } from '../../models/structureWithOwners.model'; import { NotificationService } from '../../services/notification.service'; +import { StructureService } from '../../services/structure.service'; import { ButtonType } from '../../shared/components/button/buttonType.enum'; import { SearchService } from '../../structure-list/services/search.service'; import { formUtils } from '../../utils/formUtils'; @@ -44,6 +45,7 @@ export class ProfileStructureComponent implements OnInit { private userService: UserService, private notificationService: NotificationService, private searchService: SearchService, + private structureService: StructureService, public utils: Utils ) {} @@ -108,6 +110,16 @@ export class ProfileStructureComponent implements OnInit { this.addMemberModalOpenned = false; if (memberAddRequested) { this.ngOnInit(); + this.structureService + .getStructureWithOwners(this.structureWithOwners.structure._id, this.userProfile) + .subscribe((result) => { + this.structureWithOwners = result; + result.owners.forEach((owner) => { + this.userService.getUser(owner._id).subscribe((res) => { + this.members.push(res); + }); + }); + }); this.notificationService.showSuccess(`La demande d'ajout a bien été effectuée`, ''); } } diff --git a/src/app/profile/structure-add-member-modal/structure-add-member-modal.component.html b/src/app/profile/structure-add-member-modal/structure-add-member-modal.component.html index b8aea48a5..4277ed621 100644 --- a/src/app/profile/structure-add-member-modal/structure-add-member-modal.component.html +++ b/src/app/profile/structure-add-member-modal/structure-add-member-modal.component.html @@ -20,7 +20,7 @@ <div class="buttons" fxLayout="row" fxLayoutAlign="space-between center"> <app-button [text]="'Annuler'" (action)="closeModal(false)"></app-button> <app-button - [text]="'Valider'" + [text]="'Ajouter'" [disabled]="formAddAccount.invalid" (action)="addOwner()" [style]="buttonTypeEnum.Primary" -- GitLab From 888d4195a103a1afdf44fe5457b9b472bf5c6888 Mon Sep 17 00:00:00 2001 From: Bastien DUMONT <bdumont@grandlyon.com> Date: Tue, 8 Nov 2022 14:20:07 +0100 Subject: [PATCH 2/2] show correct notification --- .../profile-structure.component.ts | 1 - .../structure-add-member-modal.component.html | 3 +-- .../structure-add-member-modal.component.ts | 14 ++++++++++++-- src/app/services/structure.service.ts | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/app/profile/profile-structure/profile-structure.component.ts b/src/app/profile/profile-structure/profile-structure.component.ts index 520784842..758518d79 100644 --- a/src/app/profile/profile-structure/profile-structure.component.ts +++ b/src/app/profile/profile-structure/profile-structure.component.ts @@ -120,7 +120,6 @@ export class ProfileStructureComponent implements OnInit { }); }); }); - this.notificationService.showSuccess(`La demande d'ajout a bien été effectuée`, ''); } } } diff --git a/src/app/profile/structure-add-member-modal/structure-add-member-modal.component.html b/src/app/profile/structure-add-member-modal/structure-add-member-modal.component.html index 4277ed621..1096cda71 100644 --- a/src/app/profile/structure-add-member-modal/structure-add-member-modal.component.html +++ b/src/app/profile/structure-add-member-modal/structure-add-member-modal.component.html @@ -24,8 +24,7 @@ [disabled]="formAddAccount.invalid" (action)="addOwner()" [style]="buttonTypeEnum.Primary" - > - </app-button> + ></app-button> </div> </form> </div> diff --git a/src/app/profile/structure-add-member-modal/structure-add-member-modal.component.ts b/src/app/profile/structure-add-member-modal/structure-add-member-modal.component.ts index 66f7e5d3f..26f8329f6 100644 --- a/src/app/profile/structure-add-member-modal/structure-add-member-modal.component.ts +++ b/src/app/profile/structure-add-member-modal/structure-add-member-modal.component.ts @@ -2,6 +2,7 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; import { StructureWithOwners } from '../../models/structureWithOwners.model'; import { TempUser } from '../../models/temp-user.model'; +import { NotificationService } from '../../services/notification.service'; import { StructureService } from '../../services/structure.service'; import { ButtonType } from '../../shared/components/button/buttonType.enum'; import { CustomRegExp } from '../../utils/CustomRegExp'; @@ -18,7 +19,11 @@ export class StructureAddMemberModalComponent implements OnInit { public formAddAccount: FormGroup; public ownerAlreadyLinked = false; - constructor(private formBuilder: FormBuilder, private structureService: StructureService) {} + constructor( + private formBuilder: FormBuilder, + private structureService: StructureService, + private notificationService: NotificationService + ) {} ngOnInit(): void { this.formAddAccount = this.formBuilder.group({ @@ -43,7 +48,12 @@ export class StructureAddMemberModalComponent implements OnInit { const user = new TempUser(); user.email = this.fAddAccount.email.value; this.structureService.addOwnerToStructure(user, this.structure.structure._id).subscribe( - () => { + (res) => { + if ((res as TempUser).email) { + this.notificationService.showSuccess("La demande d'ajout a bien été effectuée"); + } else { + this.notificationService.showSuccess('Le membre a bien été ajouté'); + } this.closed.emit(true); }, (err) => { diff --git a/src/app/services/structure.service.ts b/src/app/services/structure.service.ts index 0224f445a..2c75cb375 100644 --- a/src/app/services/structure.service.ts +++ b/src/app/services/structure.service.ts @@ -72,7 +72,7 @@ export class StructureService { public removeOwnerFromStructure(idOwner: string, idStructure: string): Observable<any> { return this.http.delete<any>(`${this.baseUrl}/${idStructure}/owner/${idOwner}`); } - public addOwnerToStructure(user: TempUser, idStructure: string): Observable<any> { + public addOwnerToStructure(user: TempUser, idStructure: string): Observable<string[] | TempUser> { return this.http.post<any>(`${this.baseUrl}/${idStructure}/addOwner`, user); } -- GitLab