[CST-5307] add confirmation modal when deleting the profile

This commit is contained in:
Giuseppe Digilio
2022-05-26 15:47:57 +02:00
parent e6f6bc96f3
commit bc37372f05
3 changed files with 37 additions and 11 deletions

View File

@@ -156,9 +156,15 @@ describe('ProfilePageResearcherFormComponent', () => {
});
describe('deleteProfile', () => {
beforeEach(() => {
const modalService = (component as any).modalService;
spyOn(modalService, 'open').and.returnValue(Object.assign({ componentInstance: Object.assign({ response: observableOf(true) }) }));
component.deleteProfile(profile);
fixture.detectChanges();
});
it('should delete the profile', () => {
component.deleteProfile(profile);
expect(researcherProfileService.delete).toHaveBeenCalledWith(profile);
});

View File

@@ -17,6 +17,7 @@ import { ProfileClaimService } from '../profile-claim/profile-claim.service';
import { RemoteData } from '../../core/data/remote-data';
import { isNotEmpty } from '../../shared/empty.util';
import { followLink } from '../../shared/utils/follow-link-config.model';
import { ConfirmationModalComponent } from '../../shared/confirmation-modal/confirmation-modal.component';
@Component({
selector: 'ds-profile-page-researcher-form',
@@ -113,15 +114,26 @@ export class ProfilePageResearcherFormComponent implements OnInit {
* @param researcherProfile the profile to delete
*/
deleteProfile(researcherProfile: ResearcherProfile): void {
this.processingDelete$.next(true);
this.researcherProfileService.delete(researcherProfile)
.subscribe((deleted) => {
if (deleted) {
this.researcherProfile$.next(null);
this.researcherProfileItemId = null;
}
this.processingDelete$.next(false);
});
const modalRef = this.modalService.open(ConfirmationModalComponent);
modalRef.componentInstance.headerLabel = 'confirmation-modal.delete-profile.header';
modalRef.componentInstance.infoLabel = 'confirmation-modal.delete-profile.info';
modalRef.componentInstance.cancelLabel = 'confirmation-modal.delete-profile.cancel';
modalRef.componentInstance.confirmLabel = 'confirmation-modal.delete-profile.confirm';
modalRef.componentInstance.brandColor = 'danger';
modalRef.componentInstance.confirmIcon = 'fas fa-trash';
modalRef.componentInstance.response.pipe(take(1)).subscribe((confirm: boolean) => {
if (confirm) {
this.processingDelete$.next(true);
this.researcherProfileService.delete(researcherProfile)
.subscribe((deleted) => {
if (deleted) {
this.researcherProfile$.next(null);
this.researcherProfileItemId = null;
}
this.processingDelete$.next(false);
});
}
});
}
/**

View File

@@ -1361,6 +1361,14 @@
"confirmation-modal.delete-eperson.confirm": "Delete",
"confirmation-modal.delete-profile.header": "Delete Profile",
"confirmation-modal.delete-profile.info": "Are you sure you want to delete your profile",
"confirmation-modal.delete-profile.cancel": "Cancel",
"confirmation-modal.delete-profile.confirm": "Delete",
"error.bitstream": "Error fetching bitstream",