From d719d9a4cf7c5de682bb8c43b406f65b9d15053f Mon Sep 17 00:00:00 2001 From: Karan Takalkar Date: Tue, 23 Jun 2020 17:24:28 +0530 Subject: [PATCH] feat: shares account actions (delete) (#894) Fixes: #893 --- .../shares-account-view.component.ts | 30 ++++++++++++++++++- src/app/shares/shares.service.ts | 8 +++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/app/shares/shares-account-view/shares-account-view.component.ts b/src/app/shares/shares-account-view/shares-account-view.component.ts index 46849f5d7..0f6deaaef 100644 --- a/src/app/shares/shares-account-view/shares-account-view.component.ts +++ b/src/app/shares/shares-account-view/shares-account-view.component.ts @@ -1,6 +1,13 @@ /** Angular Imports */ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; +import { MatDialog } from '@angular/material'; + +/** Custom Dialogs */ +import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component'; + +/** Custom Services */ +import { SharesService } from '../shares.service'; /** Custom Buttons Configuration */ import { SharesButtonsConfiguration } from './shares-buttons.config'; @@ -25,7 +32,9 @@ export class SharesAccountViewComponent implements OnInit { * @param {ActivatedRoute} route Activated Route */ constructor(private route: ActivatedRoute, - private router: Router) { + private router: Router, + private sharesService: SharesService, + public dialog: MatDialog) { this.route.data.subscribe((data: { sharesAccountData: any }) => { this.sharesAccountData = data.sharesAccountData; }); @@ -82,7 +91,26 @@ export class SharesAccountViewComponent implements OnInit { case 'Reject': this.router.navigate(['actions/Reject'], { relativeTo: this.route }); break; + case 'Delete': + this.deleteSharesAccount(); + break; } } + /** + * Deletes Shares Account. + */ + private deleteSharesAccount() { + const deleteCurrencyDialogRef = this.dialog.open(DeleteDialogComponent, { + data: { deleteContext: `shares account with id: ${this.sharesAccountData.id}` } + }); + deleteCurrencyDialogRef.afterClosed().subscribe((response: any) => { + if (response.delete) { + this.sharesService.deleteSharesAccount(this.sharesAccountData.id).subscribe(() => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); + } + }); + } + } diff --git a/src/app/shares/shares.service.ts b/src/app/shares/shares.service.ts index 370298cdb..ddd13e6af 100644 --- a/src/app/shares/shares.service.ts +++ b/src/app/shares/shares.service.ts @@ -50,6 +50,14 @@ export class SharesService { return this.http.put(`/accounts/share/${accountId}`, sharesAccount); } + /** + * @param {string} accountId shares account Id + * @returns {Observable} + */ + deleteSharesAccount(accountId: string): Observable { + return this.http.delete(`/accounts/share/${accountId}`); + } + /** * @param {string} accountId Shares Account Id * @param {string} command Command