Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/app/modules/shared/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const INFO_SAVED_SUCCESSFULLY = 'The data has been saved successfully';
export const INFO_DELETE_SUCCESSFULLY = 'The data has been deleted successfully';
export const UNEXPECTED_ERROR = 'An unexpected error happened, please try again later';
5 changes: 1 addition & 4 deletions src/app/modules/time-clock/pages/time-clock.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Store, select } from '@ngrx/store';
import { Component, OnInit } from '@angular/core';
import { AzureAdB2CService } from '../../login/services/azure.ad.b2c.service';
import { Subscription } from 'rxjs';
import { ToastrService } from 'ngx-toastr';

@Component({
selector: 'app-time-clock',
Expand All @@ -18,8 +17,7 @@ export class TimeClockComponent implements OnInit {
activeTimeEntry: Entry;
actionsSubscription: Subscription;

constructor(private azureAdB2CService: AzureAdB2CService, private store: Store<Entry>,
private toastr: ToastrService) {
constructor(private azureAdB2CService: AzureAdB2CService, private store: Store<Entry>) {
}

ngOnInit() {
Expand All @@ -37,6 +35,5 @@ export class TimeClockComponent implements OnInit {
clockOut() {
this.store.dispatch(new StopTimeEntryRunning(this.activeTimeEntry.id));
this.areFieldsVisible = false;
this.toastr.success('You clocked-out successfully');
}
}
24 changes: 18 additions & 6 deletions src/app/modules/time-clock/store/entry.effects.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { INFO_SAVED_SUCCESSFULLY, INFO_DELETE_SUCCESSFULLY, UNEXPECTED_ERROR } from './../../shared/messages';
import { Injectable } from '@angular/core';
import { ofType, Actions, Effect } from '@ngrx/effects';
import { Action } from '@ngrx/store';
Expand Down Expand Up @@ -55,11 +56,14 @@ export class EntryEffects {
mergeMap((entry) =>
this.entryService.createEntry(entry).pipe(
map((entryData) => {
this.toastrService.success('Entry was saved successfully');
if (entryData.end_date !== null) {
this.toastrService.success(INFO_SAVED_SUCCESSFULLY);
}
return new actions.CreateEntrySuccess(entryData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
console.error(error);
this.toastrService.success(UNEXPECTED_ERROR);
return of(new actions.CreateEntryFail(error.error.message));
})
)
Expand All @@ -72,8 +76,15 @@ export class EntryEffects {
map((action: actions.DeleteEntry) => action.entryId),
mergeMap((entryId) =>
this.entryService.deleteEntry(entryId).pipe(
map(() => new actions.DeleteEntrySuccess(entryId)),
catchError((error) => of(new actions.DeleteEntryFail(error)))
map(() => {
this.toastrService.success(INFO_DELETE_SUCCESSFULLY);
return new actions.DeleteEntrySuccess(entryId);
}),
catchError((error) => {
console.log(error);
this.toastrService.success(UNEXPECTED_ERROR);
return of(new actions.DeleteEntryFail(error));
})
)
)
);
Expand All @@ -85,11 +96,11 @@ export class EntryEffects {
mergeMap((project) =>
this.entryService.updateActiveEntry(project).pipe(
map((projectData) => {
this.toastrService.success('Entry was updated successfully');
return new actions.UpdateActiveEntrySuccess(projectData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
console.log(error);
this.toastrService.success(UNEXPECTED_ERROR);
return of(new actions.UpdateActiveEntryFail(error));
})
)
Expand All @@ -103,6 +114,7 @@ export class EntryEffects {
mergeMap((timeEntryId) =>
this.entryService.stopEntryRunning(timeEntryId).pipe(
map(() => {
this.toastrService.success('You clocked-out successfully');
return new actions.StopTimeEntryRunningSuccess(timeEntryId);
}),
catchError((error) => of(new actions.StopTimeEntryRunningFail(error.error.message)))
Expand Down