1+ import { INFO_SAVED_SUCCESSFULLY , INFO_DELETE_SUCCESSFULLY , UNEXPECTED_ERROR } from './../../shared/messages' ;
12import { Injectable } from '@angular/core' ;
23import { ofType , Actions , Effect } from '@ngrx/effects' ;
34import { 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