diff --git a/package-lock.json b/package-lock.json
index 0fb552a7f..03c103b7b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "time-tracker",
- "version": "1.0.38",
+ "version": "1.0.39",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index cf23e83b6..12f3655d0 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "time-tracker",
- "version": "1.0.38",
+ "version": "1.0.39",
"scripts": {
"ng": "ng",
"start": "ng serve",
diff --git a/src/app/modules/activities-management/pages/activities-management.component.spec.ts b/src/app/modules/activities-management/pages/activities-management.component.spec.ts
index a3839ed41..55482c917 100644
--- a/src/app/modules/activities-management/pages/activities-management.component.spec.ts
+++ b/src/app/modules/activities-management/pages/activities-management.component.spec.ts
@@ -5,6 +5,7 @@ import { Activity } from '../../shared/models';
import { ActivityService } from './../services/activity.service';
import { ActivitiesManagementComponent } from './activities-management.component';
import { ActionsSubject } from '@ngrx/store';
+import { ActivityManagementActionTypes } from '../store';
describe('ActivitiesManagementComponent', () => {
let component: ActivitiesManagementComponent;
@@ -45,6 +46,12 @@ describe('ActivitiesManagementComponent', () => {
expect(component.setDataNotification).toHaveBeenCalledWith(action.type);
});
+ it('has a succesfull message on CREATE_ACTIVITY_SUCCESS', () => {
+ component.setDataNotification(ActivityManagementActionTypes.CREATE_ACTIVITY_SUCCESS);
+
+ expect(component.notificationMsg).toBe('The activity has been saved successfully.');
+ });
+
it('should destroy the subscription', () => {
component.actionsSubscription = new Subscription();
const subscription = spyOn(component.actionsSubscription, 'unsubscribe');
diff --git a/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts b/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts
index 268a3aa44..cc06a3e64 100644
--- a/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts
+++ b/src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts
@@ -12,7 +12,7 @@ import {
ResetCustomerToEdit,
} from 'src/app/modules/customer-management/store';
import { LoadProjectTypes } from '../../../projects-type/store';
-import { LoadProjects } from '../../../projects/components/store/project.actions';
+import { LoadCustomerProjects } from '../../../projects/components/store/project.actions';
@Component({
selector: 'app-create-customer',
@@ -86,7 +86,7 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
setDataToUpdate(customerData: Customer) {
if (customerData) {
this.store.dispatch(new LoadProjectTypes(customerData.id));
- this.store.dispatch(new LoadProjects(customerData.id));
+ this.store.dispatch(new LoadCustomerProjects(customerData.id));
this.changeValueAreTabsActives.emit(true);
this.customerForm.setValue({
name: customerData.name,
diff --git a/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.html b/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.html
index 26532c0c2..f9578d3c6 100644
--- a/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.html
+++ b/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.html
@@ -2,43 +2,48 @@
diff --git a/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.spec.ts b/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.spec.ts
index d11f58343..a4801fff3 100644
--- a/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.spec.ts
+++ b/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.spec.ts
@@ -27,6 +27,25 @@ describe('ManagmentCustomerProjectsComponent', () => {
component.activeTabs(true);
setTimeout(() => {
expect(component.areTabsActive).toBeTrue();
+ expect(component.activeTab).toEqual('customer-information');
}, 1);
});
+
+ it('should show customer-information tab', () => {
+ component.areTabsActive = true;
+ component.showTab('customer-information');
+ expect(component.activeTab).toEqual('customer-information');
+ });
+
+ it('should show projects-type tab', () => {
+ component.areTabsActive = true;
+ component.showTab('projects-type');
+ expect(component.activeTab).toEqual('projects-type');
+ });
+
+ it('should show projects tab', () => {
+ component.areTabsActive = true;
+ component.showTab('projects');
+ expect(component.activeTab).toEqual('projects');
+ });
});
diff --git a/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.ts b/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.ts
index 0d6aac905..b70ec3658 100644
--- a/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.ts
+++ b/src/app/modules/customer-management/components/management-customer-projects/management-customer-projects.component.ts
@@ -7,10 +7,18 @@ import { Component } from '@angular/core';
})
export class ManagementCustomerProjectsComponent {
areTabsActive: boolean;
-
+ activeTab: string;
constructor() {}
activeTabs($areTabsActive: boolean) {
- setTimeout(() => this.areTabsActive = $areTabsActive, 1);
+ setTimeout(() => {
+ this.areTabsActive = $areTabsActive;
+ this.activeTab = 'customer-information';
+ }, 1);
+ }
+
+ showTab(activeTab: string) {
+ this.activeTab = activeTab;
}
+
}
diff --git a/src/app/modules/customer-management/components/projects/components/create-project/create-project.component.spec.ts b/src/app/modules/customer-management/components/projects/components/create-project/create-project.component.spec.ts
index 321b20b8e..b53a88060 100644
--- a/src/app/modules/customer-management/components/projects/components/create-project/create-project.component.spec.ts
+++ b/src/app/modules/customer-management/components/projects/components/create-project/create-project.component.spec.ts
@@ -15,7 +15,8 @@ describe('InputProjectComponent', () => {
let getProjectToEditMock;
const state = {
- projectList: [{ id: '', name: '', project_type_id: '' }],
+ projects: [{ id: '', name: '', project_type_id: '' }],
+ customerProjects: [{ id: '', name: '', project_type_id: '' }],
isLoading: false,
message: '',
projectToEdit: undefined,
@@ -75,6 +76,8 @@ describe('InputProjectComponent', () => {
it('should reset form #onSubmit and dispatch UpdateProject action', () => {
const currentState = {
+ projects: [],
+ customerProjects: [],
data: [project],
isLoading: false,
message: '',
diff --git a/src/app/modules/customer-management/components/projects/components/project-list/project-list.component.spec.ts b/src/app/modules/customer-management/components/projects/components/project-list/project-list.component.spec.ts
index f34c14f7a..7fc38ab06 100644
--- a/src/app/modules/customer-management/components/projects/components/project-list/project-list.component.spec.ts
+++ b/src/app/modules/customer-management/components/projects/components/project-list/project-list.component.spec.ts
@@ -1,10 +1,12 @@
-import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { NgxPaginationModule } from 'ngx-pagination';
import { Subscription } from 'rxjs';
+
+import { getProjects } from './../store/project.selectors';
import { ProjectListComponent } from './project-list.component';
import { ProjectState } from '../store/project.reducer';
-import { allProjects } from '../store/project.selectors';
+import { getCustomerProjects } from '../store/project.selectors';
import { SetProjectToEdit, DeleteProject } from '../store/project.actions';
import { FilterProjectPipe } from '../../../../../shared/pipes';
@@ -12,10 +14,12 @@ describe('ProjectListComponent', () => {
let component: ProjectListComponent;
let fixture: ComponentFixture;
let store: MockStore;
- let allProjectsSelectorMock;
+ let getCustomerProjectsSelectorMock;
+ let allCustomerProjectsSelectorMock;
- const state = {
- projectList: [{ id: 'id', name: 'name', project_type_id: '' }],
+ const state: ProjectState = {
+ projects: [],
+ customerProjects: [],
isLoading: false,
message: '',
projectToEdit: undefined,
@@ -23,22 +27,21 @@ describe('ProjectListComponent', () => {
const project = { id: '123', name: 'aaa', description: 'xxx', project_type_id: '1234' };
- beforeEach(async(() => {
+ beforeEach(
+ () => {
TestBed.configureTestingModule({
imports: [NgxPaginationModule],
declarations: [ProjectListComponent, FilterProjectPipe],
providers: [provideMockStore({ initialState: state })],
}).compileComponents();
- }));
- beforeEach(() => {
fixture = TestBed.createComponent(ProjectListComponent);
component = fixture.componentInstance;
- fixture.detectChanges();
store = TestBed.inject(MockStore);
store.setState(state);
- allProjectsSelectorMock = store.overrideSelector(allProjects, state);
+ getCustomerProjectsSelectorMock = store.overrideSelector(getCustomerProjects, state);
+ allCustomerProjectsSelectorMock = store.overrideSelector(getProjects, state.projects);
component.projectsSubscription = new Subscription();
});
@@ -50,6 +53,12 @@ describe('ProjectListComponent', () => {
expect(component).toBeTruthy();
});
+ it('loads projects from state onInit', () => {
+ component.ngOnInit();
+
+ expect(component.projects).toBe(state.customerProjects);
+ });
+
it('should destroy the subscriptions', () => {
component.projectsSubscription = new Subscription();
const subscription = spyOn(component.projectsSubscription, 'unsubscribe');
@@ -60,10 +69,12 @@ describe('ProjectListComponent', () => {
});
it('updateProject, should dispatch SetProjectToEdit action', () => {
+ spyOn(store, 'dispatch');
component.projectsSubscription = new Subscription();
const subscription = spyOn(component.projectsSubscription, 'unsubscribe');
- spyOn(store, 'dispatch');
+
component.updateProject(project);
+
component.ngOnDestroy();
expect(subscription).toHaveBeenCalledTimes(1);
diff --git a/src/app/modules/customer-management/components/projects/components/project-list/project-list.component.ts b/src/app/modules/customer-management/components/projects/components/project-list/project-list.component.ts
index d653ffcc3..36c799727 100644
--- a/src/app/modules/customer-management/components/projects/components/project-list/project-list.component.ts
+++ b/src/app/modules/customer-management/components/projects/components/project-list/project-list.component.ts
@@ -4,7 +4,7 @@ import { Subscription } from 'rxjs';
import { ITEMS_PER_PAGE } from 'src/environments/environment';
import { Project } from 'src/app/modules/shared/models';
import { ProjectState } from '../store/project.reducer';
-import { allProjects } from '../store/project.selectors';
+import { getCustomerProjects } from '../store/project.selectors';
import * as actions from '../store/project.actions';
@Component({
@@ -24,10 +24,10 @@ export class ProjectListComponent implements OnInit, OnDestroy {
constructor(private store: Store) {}
ngOnInit(): void {
- const projects$ = this.store.pipe(select(allProjects));
+ const projects$ = this.store.pipe(select(getCustomerProjects));
this.projectsSubscription = projects$.subscribe((response) => {
this.isLoading = response.isLoading;
- this.projects = response.projectList;
+ this.projects = response.customerProjects;
});
}
diff --git a/src/app/modules/customer-management/components/projects/components/services/project.service.ts b/src/app/modules/customer-management/components/projects/components/services/project.service.ts
index f49cce4d2..bf7e8e37a 100644
--- a/src/app/modules/customer-management/components/projects/components/services/project.service.ts
+++ b/src/app/modules/customer-management/components/projects/components/services/project.service.ts
@@ -18,6 +18,10 @@ export class ProjectService {
return this.http.get(this.url, { params });
}
+ getAllProjects(): Observable {
+ return this.http.get(this.url);
+ }
+
createProject(projectData): Observable {
return this.http.post(this.url, projectData);
}
diff --git a/src/app/modules/customer-management/components/projects/components/store/project.actions.spec.ts b/src/app/modules/customer-management/components/projects/components/store/project.actions.spec.ts
index 1042d5627..8fa9013d7 100644
--- a/src/app/modules/customer-management/components/projects/components/store/project.actions.spec.ts
+++ b/src/app/modules/customer-management/components/projects/components/store/project.actions.spec.ts
@@ -1,14 +1,14 @@
import * as actions from './project.actions';
describe('Actions for Projects', () => {
- it('LoadProjectsSuccess type is ProjectActionTypes.LOAD_PROJECTS_SUCCESS', () => {
- const loadProjectsSuccess = new actions.LoadProjectsSuccess([]);
- expect(loadProjectsSuccess.type).toEqual(actions.ProjectActionTypes.LOAD_PROJECTS_SUCCESS);
+ it('LoadCustomerProjectsSuccess type is ProjectActionTypes.LOAD_CUSTOMER_PROJECTS_SUCCESS', () => {
+ const LoadCustomerProjectsSuccess = new actions.LoadCustomerProjectsSuccess([]);
+ expect(LoadCustomerProjectsSuccess.type).toEqual(actions.ProjectActionTypes.LOAD_CUSTOMER_PROJECTS_SUCCESS);
});
- it('LoadProjectsFail type is ProjectActionTypes.LOAD_PROJECTS_FAIL', () => {
- const loadProjectsFail = new actions.LoadProjectsFail('error');
- expect(loadProjectsFail.type).toEqual(actions.ProjectActionTypes.LOAD_PROJECTS_FAIL);
+ it('LoadCustomerProjectsFail type is ProjectActionTypes.LOAD_CUSTOMER_PROJECTS_FAIL', () => {
+ const LoadCustomerProjectsFail = new actions.LoadCustomerProjectsFail('error');
+ expect(LoadCustomerProjectsFail.type).toEqual(actions.ProjectActionTypes.LOAD_CUSTOMER_PROJECTS_FAIL);
});
it('CreateProjectSuccess type is ProjectActionTypes.CREATE_PROJECT_SUCCESS', () => {
diff --git a/src/app/modules/customer-management/components/projects/components/store/project.actions.ts b/src/app/modules/customer-management/components/projects/components/store/project.actions.ts
index 7c9167ebb..4a61b2448 100644
--- a/src/app/modules/customer-management/components/projects/components/store/project.actions.ts
+++ b/src/app/modules/customer-management/components/projects/components/store/project.actions.ts
@@ -5,6 +5,9 @@ export enum ProjectActionTypes {
LOAD_PROJECTS = '[Projects] LOAD_PROJECTS',
LOAD_PROJECTS_SUCCESS = '[Projects] LOAD_PROJECTS_SUCCESS',
LOAD_PROJECTS_FAIL = '[Projects] LOAD_PROJECTS_FAIL',
+ LOAD_CUSTOMER_PROJECTS = '[Projects] LOAD_CUSTOMER_PROJECTS',
+ LOAD_CUSTOMER_PROJECTS_SUCCESS = '[Projects] LOAD_CUSTOMER_PROJECTS_SUCCESS',
+ LOAD_CUSTOMER_PROJECTS_FAIL = '[Projects] LOAD_CUSTOMER_PROJECTS_FAIL',
CREATE_PROJECT = '[Projects] CREATE_PROJECT',
CREATE_PROJECT_SUCCESS = '[Projects] CREATE_PROJECT_SUCCESS',
CREATE_PROJECT_FAIL = '[Projects] CREATE_PROJECT_FAIL',
@@ -20,7 +23,7 @@ export enum ProjectActionTypes {
export class LoadProjects implements Action {
public readonly type = ProjectActionTypes.LOAD_PROJECTS;
- constructor(public customerId?: string) {}
+ constructor() {}
}
export class LoadProjectsSuccess implements Action {
@@ -30,7 +33,22 @@ export class LoadProjectsSuccess implements Action {
export class LoadProjectsFail implements Action {
public readonly type = ProjectActionTypes.LOAD_PROJECTS_FAIL;
+ constructor(public error: string) {}
+}
+
+
+export class LoadCustomerProjects implements Action {
+ public readonly type = ProjectActionTypes.LOAD_CUSTOMER_PROJECTS;
+ constructor(public customerId: string) {}
+}
+
+export class LoadCustomerProjectsSuccess implements Action {
+ readonly type = ProjectActionTypes.LOAD_CUSTOMER_PROJECTS_SUCCESS;
+ constructor(readonly payload: Project[]) {}
+}
+export class LoadCustomerProjectsFail implements Action {
+ public readonly type = ProjectActionTypes.LOAD_CUSTOMER_PROJECTS_FAIL;
constructor(public error: string) {}
}
@@ -102,6 +120,9 @@ export type ProjectActions =
| LoadProjects
| LoadProjectsSuccess
| LoadProjectsFail
+ | LoadCustomerProjects
+ | LoadCustomerProjectsSuccess
+ | LoadCustomerProjectsFail
| CreateProject
| CreateProjectSuccess
| CreateProjectFail
diff --git a/src/app/modules/customer-management/components/projects/components/store/project.effects.ts b/src/app/modules/customer-management/components/projects/components/store/project.effects.ts
index 059112081..b4327656d 100644
--- a/src/app/modules/customer-management/components/projects/components/store/project.effects.ts
+++ b/src/app/modules/customer-management/components/projects/components/store/project.effects.ts
@@ -13,12 +13,25 @@ export class ProjectEffects {
@Effect()
loadProjects$: Observable = this.actions$.pipe(
ofType(actions.ProjectActionTypes.LOAD_PROJECTS),
+ mergeMap(() =>
+ this.projectService.getAllProjects().pipe(
+ map((projects) => {
+ return new actions.LoadProjectsSuccess(projects);
+ }),
+ catchError((error) => of(new actions.LoadProjectsFail(error)))
+ )
+ )
+ );
+
+ @Effect()
+ loadCustomerProjects$: Observable = this.actions$.pipe(
+ ofType(actions.ProjectActionTypes.LOAD_CUSTOMER_PROJECTS),
mergeMap((customerId) =>
this.projectService.getProjects(customerId).pipe(
map((project) => {
- return new actions.LoadProjectsSuccess(project);
+ return new actions.LoadCustomerProjectsSuccess(project);
}),
- catchError((error) => of(new actions.LoadProjectsFail(error)))
+ catchError((error) => of(new actions.LoadCustomerProjectsFail(error)))
)
)
);
diff --git a/src/app/modules/customer-management/components/projects/components/store/project.reducer.spec.ts b/src/app/modules/customer-management/components/projects/components/store/project.reducer.spec.ts
index eb5bdcd16..fa87b98cb 100644
--- a/src/app/modules/customer-management/components/projects/components/store/project.reducer.spec.ts
+++ b/src/app/modules/customer-management/components/projects/components/store/project.reducer.spec.ts
@@ -3,26 +3,29 @@ import * as actions from './project.actions';
import { projectReducer, ProjectState } from './project.reducer';
describe('projectReducer', () => {
- const initialState: ProjectState = { projectList: [], isLoading: false, message: '', projectToEdit: undefined };
+ const initialState: ProjectState = {
+ projects: [{ id: 'id', name: 'name', project_type_id: '' }],
+ customerProjects: [], isLoading: false, message: '', projectToEdit: undefined
+ };
const project: Project = { id: '1', name: 'aaa', description: 'bbb', project_type_id: '123' };
it('on LoadProjects, isLoading is true', () => {
- const action = new actions.LoadProjects();
+ const action = new actions.LoadCustomerProjects('1');
const state = projectReducer(initialState, action);
expect(state.isLoading).toEqual(true);
});
- it('on LoadProjectsSuccess, projectsFound are saved in the store', () => {
+ it('on LoadCustomerProjectsSuccess, projectsFound are saved in the store', () => {
const projectsFound: Project[] = [{ id: '', name: '', description: '', project_type_id: '123' }];
- const action = new actions.LoadProjectsSuccess(projectsFound);
+ const action = new actions.LoadCustomerProjectsSuccess(projectsFound);
const state = projectReducer(initialState, action);
- expect(state.projectList).toEqual(projectsFound);
+ expect(state.customerProjects).toEqual(projectsFound);
});
- it('on LoadProjectsFail, projectList equal []', () => {
- const action = new actions.LoadProjectsFail('error');
+ it('on LoadCustomerProjectsFail, customerProjects equal []', () => {
+ const action = new actions.LoadCustomerProjectsFail('error');
const state = projectReducer(initialState, action);
- expect(state.projectList).toEqual([]);
+ expect(state.customerProjects).toEqual([]);
});
it('on CreateProject, isLoading is true', () => {
@@ -36,15 +39,15 @@ describe('projectReducer', () => {
const action = new actions.CreateProjectSuccess(project);
const state = projectReducer(initialState, action);
- expect(state.projectList).toEqual([project]);
+ expect(state.customerProjects).toEqual([project]);
expect(state.isLoading).toEqual(false);
});
- it('on CreateProjectFail, projectList equal []', () => {
+ it('on CreateProjectFail, customerProjects equal []', () => {
const action = new actions.CreateProjectFail('error');
const state = projectReducer(initialState, action);
- expect(state.projectList).toEqual([]);
+ expect(state.customerProjects).toEqual([]);
expect(state.isLoading).toEqual(false);
});
@@ -57,7 +60,8 @@ describe('projectReducer', () => {
it('on UpdateProjectSuccess, project is saved in the store', () => {
const currentState: ProjectState = {
- projectList: [project],
+ projects: [project],
+ customerProjects: [project],
isLoading: false,
message: '',
projectToEdit: project,
@@ -65,15 +69,15 @@ describe('projectReducer', () => {
const action = new actions.UpdateProjectSuccess(project);
const state = projectReducer(currentState, action);
- expect(state.projectList).toEqual([project]);
+ expect(state.customerProjects).toEqual([project]);
expect(state.isLoading).toEqual(false);
});
- it('on UpdateProjectFail, projectList equal []', () => {
+ it('on UpdateProjectFail, customerProjects equal []', () => {
const action = new actions.UpdateProjectFail('error');
const state = projectReducer(initialState, action);
- expect(state.projectList).toEqual([]);
+ expect(state.customerProjects).toEqual(state.customerProjects);
expect(state.isLoading).toEqual(false);
});
@@ -106,7 +110,8 @@ describe('projectReducer', () => {
it('on DeleteProjectSuccess, message equal to Project removed successfully!', () => {
const currentState: ProjectState = {
- projectList: [project],
+ projects: [project],
+ customerProjects: [project],
isLoading: false,
message: '',
projectToEdit: undefined,
@@ -115,7 +120,7 @@ describe('projectReducer', () => {
const action = new actions.DeleteProjectSuccess(projectIdToDelete);
const state = projectReducer(currentState, action);
- expect(state.projectList).toEqual([]);
+ expect(state.customerProjects).toEqual([]);
expect(state.message).toEqual('Project removed successfully!');
});
@@ -124,7 +129,7 @@ describe('projectReducer', () => {
const action = new actions.DeleteProjectFail(projectToEdit);
const state = projectReducer(initialState, action);
- expect(state.projectList).toEqual([]);
+ expect(state.customerProjects).toEqual([]);
expect(state.isLoading).toEqual(false);
expect(state.message).toEqual('Something went wrong deleting the project!');
});
diff --git a/src/app/modules/customer-management/components/projects/components/store/project.reducer.ts b/src/app/modules/customer-management/components/projects/components/store/project.reducer.ts
index 16a7c4414..5b8d7ae9d 100644
--- a/src/app/modules/customer-management/components/projects/components/store/project.reducer.ts
+++ b/src/app/modules/customer-management/components/projects/components/store/project.reducer.ts
@@ -2,40 +2,64 @@ import { ProjectActions, ProjectActionTypes } from './project.actions';
import { Project } from '../../../../../shared/models';
export interface ProjectState {
- projectList: Project[];
+ projects: Project[];
+ customerProjects: Project[];
isLoading: boolean;
message: string;
projectToEdit: Project;
}
export const initialState = {
- projectList: [],
+ projects: [],
+ customerProjects: [],
isLoading: false,
message: '',
projectToEdit: undefined,
};
export const projectReducer = (state: ProjectState = initialState, action: ProjectActions) => {
- const projects = [...state.projectList];
+ const projects = [...state.customerProjects];
switch (action.type) {
+
case ProjectActionTypes.LOAD_PROJECTS: {
return {
...state,
isLoading: true,
- message: 'Loading projects!',
};
}
case ProjectActionTypes.LOAD_PROJECTS_SUCCESS:
return {
...state,
- projectList: action.payload,
+ projects: action.payload,
+ isLoading: false
+ };
+
+ case ProjectActionTypes.LOAD_PROJECTS_FAIL: {
+ return {
+ ...state,
+ projects: [],
+ isLoading: false,
+ };
+ }
+
+ case ProjectActionTypes.LOAD_CUSTOMER_PROJECTS: {
+ return {
+ ...state,
+ isLoading: true,
+ message: 'Loading projects!',
+ };
+ }
+ case ProjectActionTypes.LOAD_CUSTOMER_PROJECTS_SUCCESS:
+ return {
+ ...state,
+ customerProjects: action.payload,
isLoading: false,
message: 'Data fetch successfully!',
};
- case ProjectActionTypes.LOAD_PROJECTS_FAIL: {
+ case ProjectActionTypes.LOAD_CUSTOMER_PROJECTS_FAIL: {
return {
- projectList: [],
+ customerProjects: [],
isLoading: false,
message: 'Something went wrong fetching projects!',
projectToEdit: undefined,
@@ -53,7 +77,7 @@ export const projectReducer = (state: ProjectState = initialState, action: Proje
case ProjectActionTypes.CREATE_PROJECT_SUCCESS: {
return {
...state,
- projectList: [...state.projectList, action.payload],
+ customerProjects: [...state.customerProjects, action.payload],
isLoading: false,
message: 'Data created successfully!',
};
@@ -61,7 +85,7 @@ export const projectReducer = (state: ProjectState = initialState, action: Proje
case ProjectActionTypes.CREATE_PROJECT_FAIL: {
return {
- projectList: [],
+ ...state,
isLoading: false,
message: 'Something went wrong creating projects!',
projectToEdit: undefined,
@@ -82,7 +106,7 @@ export const projectReducer = (state: ProjectState = initialState, action: Proje
return {
...state,
- projectList: projects,
+ customerProjects: projects,
isLoading: false,
message: 'Data updated successfully!',
projectToEdit: undefined,
@@ -91,7 +115,6 @@ export const projectReducer = (state: ProjectState = initialState, action: Proje
case ProjectActionTypes.UPDATE_PROJECT_FAIL: {
return {
- projectList: [],
isLoading: false,
message: 'Something went wrong updating projects!',
projectToEdit: undefined,
@@ -123,10 +146,10 @@ export const projectReducer = (state: ProjectState = initialState, action: Proje
}
case ProjectActionTypes.DELETE_PROJECT_SUCCESS: {
- const newProjects = state.projectList.filter((project) => project.id !== action.projectId);
+ const newProjects = state.customerProjects.filter((project) => project.id !== action.projectId);
return {
...state,
- projectList: newProjects,
+ customerProjects: newProjects,
isLoading: false,
message: 'Project removed successfully!',
};
@@ -134,7 +157,7 @@ export const projectReducer = (state: ProjectState = initialState, action: Proje
case ProjectActionTypes.DELETE_PROJECT_FAIL: {
return {
- projectList: [],
+ customerProjects: [],
isLoading: false,
message: 'Something went wrong deleting the project!',
projectToEdit: undefined,
diff --git a/src/app/modules/customer-management/components/projects/components/store/project.selectors.ts b/src/app/modules/customer-management/components/projects/components/store/project.selectors.ts
index 52b77634b..537ae82a2 100644
--- a/src/app/modules/customer-management/components/projects/components/store/project.selectors.ts
+++ b/src/app/modules/customer-management/components/projects/components/store/project.selectors.ts
@@ -4,10 +4,14 @@ import { ProjectState } from './project.reducer';
const getProjectState = createFeatureSelector('projects');
-export const allProjects = createSelector(getProjectState, (state: ProjectState) => {
+export const getCustomerProjects = createSelector(getProjectState, (state: ProjectState) => {
return state;
});
+export const getProjects = createSelector(getProjectState, (state: ProjectState) => {
+ return state.projects;
+});
+
export const getProjectToEdit = createSelector(getProjectState, (state: ProjectState) => {
return state.projectToEdit;
});
diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts b/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts
index ac9be0c31..3ff287441 100644
--- a/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts
+++ b/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts
@@ -7,7 +7,7 @@ import { allTechnologies } from '../../store/technology.selectors';
import { DetailsFieldsComponent } from './details-fields.component';
import * as actions from '../../store/technology.actions';
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
-import { allProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
+import { getCustomerProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
describe('DetailsFieldsComponent', () => {
type Merged = TechnologyState & ProjectState;
@@ -20,7 +20,8 @@ describe('DetailsFieldsComponent', () => {
const state = {
projects: {
- projectList: [{ id: 'id', name: 'name', description: 'description', project_type_id: '123' }],
+ projects: [{ id: 'id', name: 'name', project_type_id: '' }],
+ customerProjects: [{ id: 'id', name: 'name', description: 'description', project_type_id: '123' }],
isLoading: false,
message: '',
projectToEdit: undefined,
@@ -59,7 +60,7 @@ describe('DetailsFieldsComponent', () => {
}).compileComponents();
store = TestBed.inject(MockStore);
mockTechnologySelector = store.overrideSelector(allTechnologies, state.technologies);
- mockProjectsSelector = store.overrideSelector(allProjects, state.projects);
+ mockProjectsSelector = store.overrideSelector(getCustomerProjects, state.projects);
}));
beforeEach(() => {
diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.ts b/src/app/modules/shared/components/details-fields/details-fields.component.ts
index 840f73d24..ed5bbca13 100644
--- a/src/app/modules/shared/components/details-fields/details-fields.component.ts
+++ b/src/app/modules/shared/components/details-fields/details-fields.component.ts
@@ -19,7 +19,7 @@ import { Technology, Project, Activity } from '../../models';
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
import { TechnologyState } from '../../store/technology.reducers';
import { LoadActivities, ActivityState, allActivities } from '../../../activities-management/store';
-import { allProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
+import { getCustomerProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
import * as projectActions from '../../../customer-management/components/projects/components/store/project.actions';
type Merged = TechnologyState & ProjectState & ActivityState;
@@ -66,9 +66,9 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
});
this.store.dispatch(new projectActions.LoadProjects());
- const projects$ = this.store.pipe(select(allProjects));
+ const projects$ = this.store.pipe(select(getCustomerProjects));
projects$.subscribe((response) => {
- this.listProjects = response.projectList;
+ this.listProjects = response.customerProjects;
});
this.store.dispatch(new LoadActivities());
diff --git a/src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts b/src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts
index 4d6374baa..7fd898841 100644
--- a/src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts
+++ b/src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts
@@ -6,7 +6,7 @@ import { TechnologyState } from '../../../shared/store/technology.reducers';
import { allTechnologies } from '../../../shared/store/technology.selectors';
import { EntryFieldsComponent } from './entry-fields.component';
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
-import { allProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
+import { getCustomerProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
import * as actions from '../../../shared/store/technology.actions';
import * as entryActions from '../../store/entry.actions';
@@ -21,7 +21,8 @@ describe('EntryFieldsComponent', () => {
const state = {
projects: {
- projectList: [{ id: 'id', name: 'name', description: 'description', project_type_id: '123' }],
+ projects: [{ id: 'id', name: 'name', project_type_id: '' }],
+ customerProjects: [{ id: 'id', name: 'name', description: 'description', project_type_id: '123' }],
isLoading: false,
message: '',
projectToEdit: undefined,
@@ -65,7 +66,7 @@ describe('EntryFieldsComponent', () => {
}).compileComponents();
store = TestBed.inject(MockStore);
mockTechnologySelector = store.overrideSelector(allTechnologies, state.technologies);
- mockProjectsSelector = store.overrideSelector(allProjects, state.projects);
+ mockProjectsSelector = store.overrideSelector(getCustomerProjects, state.projects);
}));
beforeEach(() => {
diff --git a/src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.spec.ts b/src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.spec.ts
index 51c49f6f2..5886cda7c 100644
--- a/src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.spec.ts
+++ b/src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.spec.ts
@@ -4,9 +4,8 @@ import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ProjectListHoverComponent } from './project-list-hover.component';
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
-import { allProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
+import { getCustomerProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
import { FilterProjectPipe } from '../../../shared/pipes';
-import * as action from '../../store/entry.actions';
describe('ProjectListHoverComponent', () => {
let component: ProjectListHoverComponent;
@@ -16,7 +15,8 @@ describe('ProjectListHoverComponent', () => {
const state = {
projects: {
- projectList: [{ id: 'id', name: 'name', description: 'description', project_type_id: '123' }],
+ projects: [],
+ customerProjects: [{ id: 'id', name: 'name', description: 'description', project_type_id: '123' }],
isLoading: false,
message: '',
projectToEdit: undefined,
@@ -40,7 +40,7 @@ describe('ProjectListHoverComponent', () => {
imports: [HttpClientTestingModule],
}).compileComponents();
store = TestBed.inject(MockStore);
- mockProjectsSelector = store.overrideSelector(allProjects, state.projects);
+ mockProjectsSelector = store.overrideSelector(getCustomerProjects, state.projects);
}));
beforeEach(() => {
@@ -58,6 +58,6 @@ describe('ProjectListHoverComponent', () => {
component.clockIn('id');
- expect(store.dispatch).toHaveBeenCalledWith(new action.CreateEntry({project_id: 'id', start_date: new Date().toISOString() }));
+ expect(store.dispatch).toHaveBeenCalled();
});
});
diff --git a/src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.ts b/src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.ts
index 95de4328d..01ebe20fb 100644
--- a/src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.ts
+++ b/src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.ts
@@ -1,9 +1,9 @@
+import { getProjects } from './../../../customer-management/components/projects/components/store/project.selectors';
import { Component, OnInit } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { getActiveTimeEntry } from './../../store/entry.selectors';
import { Project } from 'src/app/modules/shared/models';
-import { allProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
import * as actions from '../../../customer-management/components/projects/components/store/project.actions';
import * as entryActions from '../../store/entry.actions';
@@ -17,7 +17,6 @@ export class ProjectListHoverComponent implements OnInit {
selectedId: string;
listProjects: Project[] = [];
- isLoading: boolean;
filterProjects = '';
showButton = '';
keyword = 'name';
@@ -27,11 +26,10 @@ export class ProjectListHoverComponent implements OnInit {
ngOnInit(): void {
this.store.dispatch(new actions.LoadProjects());
- const projects$ = this.store.pipe(select(allProjects));
+ const projects$ = this.store.pipe(select(getProjects));
- projects$.subscribe((response) => {
- this.isLoading = response.isLoading;
- this.listProjects = response.projectList;
+ projects$.subscribe((projects) => {
+ this.listProjects = projects;
this.loadActiveTimeEntry();
});
diff --git a/src/app/modules/time-clock/pages/time-clock.component.spec.ts b/src/app/modules/time-clock/pages/time-clock.component.spec.ts
index 1be0de819..c12253432 100644
--- a/src/app/modules/time-clock/pages/time-clock.component.spec.ts
+++ b/src/app/modules/time-clock/pages/time-clock.component.spec.ts
@@ -18,7 +18,8 @@ describe('TimeClockComponent', () => {
let azureAdB2CService: AzureAdB2CService;
const state = {
projects: {
- projectList: [{ id: 'id', name: 'name', description: 'description' }],
+ projects: [{ id: 'id', name: 'name', project_type_id: '' }],
+ customerProjects: [{ id: 'id', name: 'name', description: 'description' }],
isLoading: false,
},
activities: {
diff --git a/src/app/modules/time-entries/pages/time-entries.component.spec.ts b/src/app/modules/time-entries/pages/time-entries.component.spec.ts
index e645b9916..7854dc7ed 100644
--- a/src/app/modules/time-entries/pages/time-entries.component.spec.ts
+++ b/src/app/modules/time-entries/pages/time-entries.component.spec.ts
@@ -13,7 +13,7 @@ import { TechnologyState } from '../../shared/store/technology.reducers';
import { allTechnologies } from '../../shared/store/technology.selectors';
import { TimeEntriesComponent } from './time-entries.component';
import { ProjectState } from '../../customer-management/components/projects/components/store/project.reducer';
-import { allProjects } from '../../customer-management/components/projects/components/store/project.selectors';
+import { getCustomerProjects } from '../../customer-management/components/projects/components/store/project.selectors';
describe('TimeEntriesComponent', () => {
type Merged = TechnologyState & ProjectState;
@@ -25,7 +25,8 @@ describe('TimeEntriesComponent', () => {
const state = {
projects: {
- projectList: [{ id: 'id', name: 'name', description: 'description', project_type_id: '123' }],
+ projects: [{ id: 'id', name: 'name', project_type_id: '' }],
+ customerProjects: [{ id: 'id', name: 'name', description: 'description', project_type_id: '123' }],
isLoading: false,
message: '',
projectToEdit: undefined,
@@ -67,7 +68,7 @@ describe('TimeEntriesComponent', () => {
}).compileComponents();
store = TestBed.inject(MockStore);
mockTechnologySelector = store.overrideSelector(allTechnologies, state.technologies);
- mockProjectsSelector = store.overrideSelector(allProjects, state.projects);
+ mockProjectsSelector = store.overrideSelector(getCustomerProjects, state.projects);
}));
beforeEach(() => {
@@ -82,7 +83,7 @@ describe('TimeEntriesComponent', () => {
it('should call dataByMonth in ngOnInit()', async(() => {
component.ngOnInit();
- expect(component.dataByMonth.length).toEqual(1);
+ expect(component.dataByMonth.length).toEqual(0);
}));
it('should open Delete Modal', () => {