1
+ import { INFO_SAVED_SUCCESSFULLY , INFO_DELETE_SUCCESSFULLY , UNEXPECTED_ERROR } from './../../shared/messages' ;
1
2
import { Injectable } from '@angular/core' ;
2
3
import { ofType , Actions , Effect } from '@ngrx/effects' ;
3
4
import { Action } from '@ngrx/store' ;
@@ -55,11 +56,14 @@ export class EntryEffects {
55
56
mergeMap ( ( entry ) =>
56
57
this . entryService . createEntry ( entry ) . pipe (
57
58
map ( ( entryData ) => {
58
- this . toastrService . success ( 'Entry was saved successfully' ) ;
59
+ if ( entryData . end_date !== null ) {
60
+ this . toastrService . success ( INFO_SAVED_SUCCESSFULLY ) ;
61
+ }
59
62
return new actions . CreateEntrySuccess ( entryData ) ;
60
63
} ) ,
61
64
catchError ( ( error ) => {
62
- this . toastrService . error ( error . error . message ) ;
65
+ console . error ( error ) ;
66
+ this . toastrService . success ( UNEXPECTED_ERROR ) ;
63
67
return of ( new actions . CreateEntryFail ( error . error . message ) ) ;
64
68
} )
65
69
)
@@ -72,8 +76,15 @@ export class EntryEffects {
72
76
map ( ( action : actions . DeleteEntry ) => action . entryId ) ,
73
77
mergeMap ( ( entryId ) =>
74
78
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
+ } )
77
88
)
78
89
)
79
90
) ;
@@ -85,11 +96,11 @@ export class EntryEffects {
85
96
mergeMap ( ( project ) =>
86
97
this . entryService . updateActiveEntry ( project ) . pipe (
87
98
map ( ( projectData ) => {
88
- this . toastrService . success ( 'Entry was updated successfully' ) ;
89
99
return new actions . UpdateActiveEntrySuccess ( projectData ) ;
90
100
} ) ,
91
101
catchError ( ( error ) => {
92
- this . toastrService . error ( error . error . message ) ;
102
+ console . log ( error ) ;
103
+ this . toastrService . success ( UNEXPECTED_ERROR ) ;
93
104
return of ( new actions . UpdateActiveEntryFail ( error ) ) ;
94
105
} )
95
106
)
@@ -103,6 +114,7 @@ export class EntryEffects {
103
114
mergeMap ( ( timeEntryId ) =>
104
115
this . entryService . stopEntryRunning ( timeEntryId ) . pipe (
105
116
map ( ( ) => {
117
+ this . toastrService . success ( 'You clocked-out successfully' ) ;
106
118
return new actions . StopTimeEntryRunningSuccess ( timeEntryId ) ;
107
119
} ) ,
108
120
catchError ( ( error ) => of ( new actions . StopTimeEntryRunningFail ( error . error . message ) ) )
0 commit comments