-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement Unit of Work - Part II
- Add confirmation service to Angular app (initial implementation) - Extend confirmation service in Angular app (part 2) - Refactor member message component for cleaner structure - Fix bug in reading messages
- Loading branch information
1 parent
90f144d
commit c9a14f5
Showing
8 changed files
with
109 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
Front/FinanceTracker.Client/src/app/_guards/prevent-unsaved-changes.guard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import { CanDeactivateFn } from '@angular/router'; | ||
import { MemberEditComponent } from '../members/member-edit/member-edit.component'; | ||
import { inject } from '@angular/core'; | ||
import { ConfirmService } from '../_services/confirm.service'; | ||
|
||
export const preventUnsavedChangesGuard: CanDeactivateFn<MemberEditComponent> = (component) => { | ||
export const preventUnsavedChangesGuard: CanDeactivateFn< | ||
MemberEditComponent | ||
> = (component) => { | ||
const confirmService = inject(ConfirmService); | ||
if (component.editForm?.dirty) { | ||
return confirm('Are you sure you want to continue? Any unsaved changes will be lost') | ||
return confirmService.confirm() ?? false; | ||
} | ||
return true; | ||
}; |
36 changes: 36 additions & 0 deletions
36
Front/FinanceTracker.Client/src/app/_services/confirm.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { inject, Injectable } from '@angular/core'; | ||
import { BsModalRef, BsModalService, ModalOptions } from 'ngx-bootstrap/modal'; | ||
import { ConfirmDialogComponent } from '../modals/confirm-dialog/confirm-dialog.component'; | ||
import { map } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class ConfirmService { | ||
bsModalRed?: BsModalRef; | ||
private modalService = inject(BsModalService); | ||
|
||
confirm( | ||
title = 'Confirmation', | ||
message = 'Are you sure you want to do this', | ||
btnOkText = 'Ok', | ||
btnCancelText = 'Cancel' | ||
) { | ||
const config: ModalOptions = { | ||
initialState: { | ||
title, | ||
message, | ||
btnOkText, | ||
btnCancelText, | ||
}, | ||
}; | ||
this.bsModalRed = this.modalService.show(ConfirmDialogComponent, config); | ||
return this.bsModalRed.onHidden?.pipe( | ||
map(() => { | ||
if (this.bsModalRed?.content) { | ||
return this.bsModalRed.content.result; | ||
} else return false; | ||
}) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
12 changes: 12 additions & 0 deletions
12
Front/FinanceTracker.Client/src/app/modals/confirm-dialog/confirm-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div class="modal-header"> | ||
<h4 class="modal-title pull-left"> | ||
{{title}} | ||
</h4> | ||
</div> | ||
<div class="modal-body"> | ||
<p>{{message}}</p> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-success" (click)="confirm()">{{btnOkText}}</button> | ||
<button type="button" class="btn btn-danger" (click)="decline()">{{btnCancelText}}</button> | ||
</div> |
27 changes: 27 additions & 0 deletions
27
Front/FinanceTracker.Client/src/app/modals/confirm-dialog/confirm-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { BsModalRef } from 'ngx-bootstrap/modal'; | ||
import { Component, inject, model } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-confim-dialog', | ||
standalone: true, | ||
imports: [], | ||
templateUrl: './confirm-dialog.component.html', | ||
styleUrl: './confirm-dialog.component.css', | ||
}) | ||
export class ConfirmDialogComponent { | ||
bsModalRef = inject(BsModalRef); | ||
title = ''; | ||
message = ''; | ||
btnOkText = ''; | ||
btnCancelText = ''; | ||
result = false; | ||
|
||
confirm() { | ||
this.result = true; | ||
this.bsModalRef.hide(); | ||
} | ||
|
||
decline() { | ||
this.bsModalRef.hide(); | ||
} | ||
} |