Skip to content
Snippets Groups Projects
Commit ee5aeb63 authored by Kawtar Laariche's avatar Kawtar Laariche
Browse files

#19: make delete dialog generic and reusable

parent 94fef191
No related branches found
No related tags found
No related merge requests found
<mat-toolbar class="dialog-header"> <mat-toolbar class="dialog-header">
<div style="display: flex; align-items: center; padding: 0; flex: 1 1 auto"> <div style="display: flex; align-items: center; padding: 0; flex: 1 1 auto">
<h2>Delete Shared Member</h2> <h2>{{ title }}</h2>
</div> </div>
<button <button
type="button" type="button"
...@@ -15,8 +15,7 @@ ...@@ -15,8 +15,7 @@
<mat-dialog-content> <mat-dialog-content>
<div class="star-rating-container"> <div class="star-rating-container">
<p> <p>
Would you like to delete '{{ user.firstName }} {{ user.lastName }}' from {{ content }}
the shared list?
</p> </p>
</div></mat-dialog-content </div></mat-dialog-content
> >
......
...@@ -27,34 +27,38 @@ import { AlertService } from 'src/app/core/services/alert.service'; ...@@ -27,34 +27,38 @@ import { AlertService } from 'src/app/core/services/alert.service';
styleUrl: './delete-user-dialog-confirmation-action.component.scss', styleUrl: './delete-user-dialog-confirmation-action.component.scss',
}) })
export class DeleteUserDialogConfirmationActionComponent implements OnInit { export class DeleteUserDialogConfirmationActionComponent implements OnInit {
user!: UserDetails; title!: string;
content!: string;
alertMessage!: string;
constructor( constructor(
public dialogRef: MatDialogRef<DeleteUserDialogConfirmationActionComponent>, public dialogRef: MatDialogRef<DeleteUserDialogConfirmationActionComponent>,
private privateCatalogsService: PrivateCatalogsService,
@Inject(MAT_DIALOG_DATA) public data: any, @Inject(MAT_DIALOG_DATA) public data: any,
private alertService: AlertService, private alertService: AlertService,
) {} ) {}
ngOnInit(): void { 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() { confirm() {
this.privateCatalogsService this.data.dataKey.action().subscribe({
.deleteShareWithTeam(this.user.userId ?? '', this.data.dataKey.solutionId) next: (res: any) => {
.subscribe((res) => { this.alertService.notify(
const alert: Alert = { { message: this.alertMessage, type: AlertType.Success },
message: '', 3000,
type: AlertType.Success, );
}; this.dialogRef.close(true);
},
if (res.error_code === '100') { error: (err: any) => {
alert.message = 'Deleted successfully. '; this.alertService.notify(
} { message: 'Operation failed', type: AlertType.Error },
3000,
this.alertService.notify(alert, 3000); );
this.dialogRef.close(); this.dialogRef.close(false);
}); },
});
} }
} }
...@@ -256,8 +256,11 @@ export class ShareWithTeamPageComponent implements OnInit { ...@@ -256,8 +256,11 @@ export class ShareWithTeamPageComponent implements OnInit {
this.dialog.open(DeleteUserDialogConfirmationActionComponent, { this.dialog.open(DeleteUserDialogConfirmationActionComponent, {
data: { data: {
dataKey: { dataKey: {
solutionId: this.solutionId, title: 'Delete Shared Member',
user: user, content: `Would you like to delete '${user.firstName} ${user.lastName}' from
the shared list?`,
alertMessage: 'Deleted successfully. ',
action: () => this.deleteUser(user),
}, },
}, },
autoFocus: false, autoFocus: false,
...@@ -267,4 +270,11 @@ export class ShareWithTeamPageComponent implements OnInit { ...@@ -267,4 +270,11 @@ export class ShareWithTeamPageComponent implements OnInit {
this.getShareWithTeam(this.solutionId); this.getShareWithTeam(this.solutionId);
}); });
} }
deleteUser(user: UserDetails): Observable<any> {
return this.privateCatalogsService.deleteShareWithTeam(
user.userId ?? '',
this.solutionId,
);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment