Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
#67 remove imports and added delete activity failed
  • Loading branch information
daros10 committed Apr 7, 2020
commit 001a70d52b8cb836470205a6c21f9063f9a54a30
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum ActivityManagementActionTypes {
CREATE_ACTIVITY_FAIL = '[ActivityManagement] CREATE_ACTIVITY_FAIL',
DELETE_ACTIVITY = '[ActivityManagement] Delete Activity',
DELETE_ACTIVITY_SUCCESS = '[ActivityManagement] Delete Activity Success',
DELETE_ACTIVITY_FAIL = '[ActivityManagement] Delete Activity Fail',
}

export class LoadActivities implements Action {
Expand Down Expand Up @@ -59,6 +60,12 @@ export class DeleteActivitySuccess implements Action {
constructor(public activityId: string) {}
}

export class DeleteActivityFail implements Action {
public readonly type = ActivityManagementActionTypes.DELETE_ACTIVITY_FAIL;

constructor(public error: string) {}
}

export type ActivityManagementActions =
| LoadActivities
| LoadActivitiesSuccess
Expand All @@ -67,4 +74,5 @@ export type ActivityManagementActions =
| CreateActivitySuccess
| CreateActivityFail
| DeleteActivity
| DeleteActivitySuccess;
| DeleteActivitySuccess
| DeleteActivityFail;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { catchError, map, mergeMap } from 'rxjs/operators';
import * as actions from './activity-management.actions';
import { Activity } from './../../shared/models/activity.model';
import { ActivityService } from './../services/activity.service';
import { ActivityManagementActionTypes, DeleteActivitySuccess } from './activity-management.actions';

@Injectable()
export class ActivityEffects {
Expand Down Expand Up @@ -42,13 +41,14 @@ export class ActivityEffects {

@Effect()
deleteActivity$: Observable<Action> = this.actions$.pipe(
ofType(ActivityManagementActionTypes.DELETE_ACTIVITY),
ofType(actions.ActivityManagementActionTypes.DELETE_ACTIVITY),
map((action: actions.DeleteActivity) => action.activityId),
mergeMap((activityId) =>
this.activityService.deleteActivity(activityId).pipe(
map(() => {
return new DeleteActivitySuccess(activityId);
})
return new actions.DeleteActivitySuccess(activityId);
}),
catchError((error) => of(new actions.DeleteActivityFail(error)))
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function activityManagementReducer(state: ActivityState = initialState, a
case ActivityManagementActionTypes.DELETE_ACTIVITY: {
return {
...state,
isLoading: true,
message: 'Activity removed successfully!',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to set the loading variable to true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daros10 you don't need to add "message: 'Activity removed successfully!'," that is only in DELETE_ACTIVITY_SUCCESS

};
}
Expand All @@ -71,6 +72,14 @@ export function activityManagementReducer(state: ActivityState = initialState, a
message: 'Activity removed successfully!',
};
}

case ActivityManagementActionTypes.DELETE_ACTIVITY_FAIL: {
return {
data: [],
isLoading: false,
message: 'Something went wrong creating activities!',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the message is wrong "Something went wrong creating activities!" change for deleting

};
}
default:
return state;
}
Expand Down