Skip to content

Commit 5491201

Browse files
authored
Merge pull request #245 from ioet/242-remove-message-on-entry-updated
fix: 242 remove message on entry updated. closes #244
2 parents 1327db7 + a637d55 commit 5491201

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

src/app/modules/shared/messages.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const INFO_SAVED_SUCCESSFULLY = 'The data has been saved successfully';
2+
export const INFO_DELETE_SUCCESSFULLY = 'The data has been deleted successfully';
3+
export const UNEXPECTED_ERROR = 'An unexpected error happened, please try again later';

src/app/modules/time-clock/pages/time-clock.component.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Store, select } from '@ngrx/store';
55
import { Component, OnInit } from '@angular/core';
66
import { AzureAdB2CService } from '../../login/services/azure.ad.b2c.service';
77
import { Subscription } from 'rxjs';
8-
import { ToastrService } from 'ngx-toastr';
98

109
@Component({
1110
selector: 'app-time-clock',
@@ -18,8 +17,7 @@ export class TimeClockComponent implements OnInit {
1817
activeTimeEntry: Entry;
1918
actionsSubscription: Subscription;
2019

21-
constructor(private azureAdB2CService: AzureAdB2CService, private store: Store<Entry>,
22-
private toastr: ToastrService) {
20+
constructor(private azureAdB2CService: AzureAdB2CService, private store: Store<Entry>) {
2321
}
2422

2523
ngOnInit() {
@@ -37,6 +35,5 @@ export class TimeClockComponent implements OnInit {
3735
clockOut() {
3836
this.store.dispatch(new StopTimeEntryRunning(this.activeTimeEntry.id));
3937
this.areFieldsVisible = false;
40-
this.toastr.success('You clocked-out successfully');
4138
}
4239
}

src/app/modules/time-clock/store/entry.effects.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { INFO_SAVED_SUCCESSFULLY, INFO_DELETE_SUCCESSFULLY, UNEXPECTED_ERROR } from './../../shared/messages';
12
import { Injectable } from '@angular/core';
23
import { ofType, Actions, Effect } from '@ngrx/effects';
34
import { Action } from '@ngrx/store';
@@ -55,11 +56,14 @@ export class EntryEffects {
5556
mergeMap((entry) =>
5657
this.entryService.createEntry(entry).pipe(
5758
map((entryData) => {
58-
this.toastrService.success('Entry was saved successfully');
59+
if (entryData.end_date !== null) {
60+
this.toastrService.success(INFO_SAVED_SUCCESSFULLY);
61+
}
5962
return new actions.CreateEntrySuccess(entryData);
6063
}),
6164
catchError((error) => {
62-
this.toastrService.error(error.error.message);
65+
console.error(error);
66+
this.toastrService.success(UNEXPECTED_ERROR);
6367
return of(new actions.CreateEntryFail(error.error.message));
6468
})
6569
)
@@ -72,8 +76,15 @@ export class EntryEffects {
7276
map((action: actions.DeleteEntry) => action.entryId),
7377
mergeMap((entryId) =>
7478
this.entryService.deleteEntry(entryId).pipe(
75-
map(() => new actions.DeleteEntrySuccess(entryId)),
76-
catchError((error) => of(new actions.DeleteEntryFail(error)))
79+
map(() => {
80+
this.toastrService.success(INFO_DELETE_SUCCESSFULLY);
81+
return new actions.DeleteEntrySuccess(entryId);
82+
}),
83+
catchError((error) => {
84+
console.log(error);
85+
this.toastrService.success(UNEXPECTED_ERROR);
86+
return of(new actions.DeleteEntryFail(error));
87+
})
7788
)
7889
)
7990
);
@@ -85,11 +96,11 @@ export class EntryEffects {
8596
mergeMap((project) =>
8697
this.entryService.updateActiveEntry(project).pipe(
8798
map((projectData) => {
88-
this.toastrService.success('Entry was updated successfully');
8999
return new actions.UpdateActiveEntrySuccess(projectData);
90100
}),
91101
catchError((error) => {
92-
this.toastrService.error(error.error.message);
102+
console.log(error);
103+
this.toastrService.success(UNEXPECTED_ERROR);
93104
return of(new actions.UpdateActiveEntryFail(error));
94105
})
95106
)
@@ -103,6 +114,7 @@ export class EntryEffects {
103114
mergeMap((timeEntryId) =>
104115
this.entryService.stopEntryRunning(timeEntryId).pipe(
105116
map(() => {
117+
this.toastrService.success('You clocked-out successfully');
106118
return new actions.StopTimeEntryRunningSuccess(timeEntryId);
107119
}),
108120
catchError((error) => of(new actions.StopTimeEntryRunningFail(error.error.message)))

0 commit comments

Comments
 (0)