Skip to content

Commit 15fc022

Browse files
committed
- bypassed 'Walkthrough' page when customer non-zero count of non-active projects
1 parent acaa6e1 commit 15fc022

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/projects/actions/loadProjects.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ import {
44
SET_SEARCH_TERM, SET_PROJECTS_SEARCH_CRITERIA,
55
CLEAR_PROJECT_SUGGESTIONS_SEARCH, PROJECT_SUGGESTIONS_SEARCH_SUCCESS,
66
SET_PROJECTS_INFINITE_AUTOLOAD,
7-
SET_PROJECTS_LIST_VIEW
7+
SET_PROJECTS_LIST_VIEW,
8+
PROJECT_STATUS_ACTIVE,
9+
ROLE_TOPCODER_USER
810
} from '../../config/constants'
911
import { getProjects } from '../../api/projects'
1012
import { loadMembers } from '../../actions/members'
1113

1214
// ignore action
1315
/*eslint-disable no-unused-vars */
1416
const getProjectsWithMembers = (dispatch, getState, criteria, pageNum) => {
17+
const state = getState()
1518
return new Promise((resolve, reject) => {
1619
dispatch({
1720
type: SET_PROJECTS_SEARCH_CRITERIA,
@@ -21,7 +24,30 @@ const getProjectsWithMembers = (dispatch, getState, criteria, pageNum) => {
2124

2225
return dispatch({
2326
type: GET_PROJECTS,
24-
payload: getProjects(criteria, pageNum),
27+
payload: getProjects(criteria, pageNum)
28+
.then((data) => {
29+
const retryForCustomer = criteria.status === PROJECT_STATUS_ACTIVE && state.loadUser.user.roles && state.loadUser.user.roles.length === 1
30+
&& state.loadUser.user.roles[0] === ROLE_TOPCODER_USER
31+
if(data.totalCount === 0 && retryForCustomer) {
32+
//retrying for customer if active projects are 0 but there are some projects with other status
33+
//This is to bypass the walkthrough page which we ideally show for customer with zero projects
34+
const newCriteria = {
35+
sort: 'updatedAt desc'
36+
}
37+
return getProjects(newCriteria, pageNum)
38+
.then((data2) => {
39+
//if there no project in any status return original result
40+
if(data2.totalCount === 0) {
41+
return data
42+
} else {
43+
data2.projects.length = 0
44+
return data2
45+
}
46+
})
47+
} else {
48+
return data
49+
}
50+
}),
2551
meta: {
2652
// keep previous to enable the loading without paginator (infinite scroll)
2753
keepPrevious : pageNum !== 1

0 commit comments

Comments
 (0)