diff --git a/src/app/shared/components/delete-user-dialog-confirmation-action/delete-user-dialog-confirmation-action.component.html b/src/app/shared/components/delete-user-dialog-confirmation-action/delete-user-dialog-confirmation-action.component.html index 6d7855c75085eda98037d1b057ea38b6bdb73a58..de2757cd2b6a10a83742a2e3e192c7cc43e6216e 100644 --- a/src/app/shared/components/delete-user-dialog-confirmation-action/delete-user-dialog-confirmation-action.component.html +++ b/src/app/shared/components/delete-user-dialog-confirmation-action/delete-user-dialog-confirmation-action.component.html @@ -1,6 +1,6 @@ <mat-toolbar class="dialog-header"> <div style="display: flex; align-items: center; padding: 0; flex: 1 1 auto"> - <h2>Delete Shared Member</h2> + <h2>{{ title }}</h2> </div> <button type="button" @@ -15,8 +15,7 @@ <mat-dialog-content> <div class="star-rating-container"> <p> - Would you like to delete '{{ user.firstName }} {{ user.lastName }}' from - the shared list? + {{ content }} </p> </div></mat-dialog-content > diff --git a/src/app/shared/components/delete-user-dialog-confirmation-action/delete-user-dialog-confirmation-action.component.ts b/src/app/shared/components/delete-user-dialog-confirmation-action/delete-user-dialog-confirmation-action.component.ts index 64dcefb259fcb47873718893ec6a718d72587c21..fbfaa3af718d861ffb25f27fb703fa7dcbcc482a 100644 --- a/src/app/shared/components/delete-user-dialog-confirmation-action/delete-user-dialog-confirmation-action.component.ts +++ b/src/app/shared/components/delete-user-dialog-confirmation-action/delete-user-dialog-confirmation-action.component.ts @@ -27,34 +27,38 @@ import { AlertService } from 'src/app/core/services/alert.service'; styleUrl: './delete-user-dialog-confirmation-action.component.scss', }) export class DeleteUserDialogConfirmationActionComponent implements OnInit { - user!: UserDetails; + title!: string; + content!: string; + alertMessage!: string; constructor( public dialogRef: MatDialogRef<DeleteUserDialogConfirmationActionComponent>, - private privateCatalogsService: PrivateCatalogsService, @Inject(MAT_DIALOG_DATA) public data: any, private alertService: AlertService, ) {} ngOnInit(): void { - this.user = this.data.dataKey.user; + this.title = this.data.dataKey.title; + this.content = this.data.dataKey.content; + this.alertMessage = this.data.dataKey.alertMessage; } confirm() { - this.privateCatalogsService - .deleteShareWithTeam(this.user.userId ?? '', this.data.dataKey.solutionId) - .subscribe((res) => { - const alert: Alert = { - message: '', - type: AlertType.Success, - }; - - if (res.error_code === '100') { - alert.message = 'Deleted successfully. '; - } - - this.alertService.notify(alert, 3000); - this.dialogRef.close(); - }); + this.data.dataKey.action().subscribe({ + next: (res: any) => { + this.alertService.notify( + { message: this.alertMessage, type: AlertType.Success }, + 3000, + ); + this.dialogRef.close(true); + }, + error: (err: any) => { + this.alertService.notify( + { message: 'Operation failed', type: AlertType.Error }, + 3000, + ); + this.dialogRef.close(false); + }, + }); } } diff --git a/src/app/shared/components/share-with-team-page/share-with-team-page.component.ts b/src/app/shared/components/share-with-team-page/share-with-team-page.component.ts index ebb19a4ecdbc1dce3cfc65c04f6bab2a2b62ea47..c55ad3a922b5d8552b5074d75bf7290e4916cd34 100644 --- a/src/app/shared/components/share-with-team-page/share-with-team-page.component.ts +++ b/src/app/shared/components/share-with-team-page/share-with-team-page.component.ts @@ -256,8 +256,11 @@ export class ShareWithTeamPageComponent implements OnInit { this.dialog.open(DeleteUserDialogConfirmationActionComponent, { data: { dataKey: { - solutionId: this.solutionId, - user: user, + title: 'Delete Shared Member', + content: `Would you like to delete '${user.firstName} ${user.lastName}' from + the shared list?`, + alertMessage: 'Deleted successfully. ', + action: () => this.deleteUser(user), }, }, autoFocus: false, @@ -267,4 +270,11 @@ export class ShareWithTeamPageComponent implements OnInit { this.getShareWithTeam(this.solutionId); }); } + + deleteUser(user: UserDetails): Observable<any> { + return this.privateCatalogsService.deleteShareWithTeam( + user.userId ?? '', + this.solutionId, + ); + } }