Skip to content

Commit d08de83

Browse files
committed
Created separate variable in redux store to have count of all projects for customers
1 parent 15fc022 commit d08de83

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

src/projects/actions/loadProjects.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,23 @@ const getProjectsWithMembers = (dispatch, getState, criteria, pageNum) => {
2525
return dispatch({
2626
type: GET_PROJECTS,
2727
payload: getProjects(criteria, pageNum)
28-
.then((data) => {
28+
.then((originalData) => {
2929
const retryForCustomer = criteria.status === PROJECT_STATUS_ACTIVE && state.loadUser.user.roles && state.loadUser.user.roles.length === 1
3030
&& state.loadUser.user.roles[0] === ROLE_TOPCODER_USER
31-
if(data.totalCount === 0 && retryForCustomer) {
31+
if(originalData.totalCount === 0 && retryForCustomer) {
3232
//retrying for customer if active projects are 0 but there are some projects with other status
3333
//This is to bypass the walkthrough page which we ideally show for customer with zero projects
3434
const newCriteria = {
3535
sort: 'updatedAt desc'
3636
}
3737
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-
}
38+
.then((allProjectsData) => {
39+
//add allprojects count to be updated to redux store
40+
originalData.allProjectsCount = allProjectsData.totalCount
41+
return originalData
4642
})
4743
} else {
48-
return data
44+
return originalData
4945
}
5046
}),
5147
meta: {

src/projects/list/components/Projects/Projects.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,11 @@ class Projects extends Component {
189189
}
190190

191191
render() {
192-
const { isPowerUser, isCustomer, isLoading, totalCount, criteria, projectsListView, setProjectsListView, setInfiniteAutoload, loadProjects, history, orgConfig } = this.props
192+
const { isPowerUser, isCustomer, isLoading, totalCount, criteria, projectsListView, setProjectsListView, setInfiniteAutoload, loadProjects, history, orgConfig, allProjectsCount } = this.props
193193
// show walk through if user is customer and no projects were returned
194194
// for default filters
195-
const showWalkThrough = !isLoading && totalCount === 0 &&
196-
_.isEqual(criteria, PROJECT_LIST_DEFAULT_CRITERIA) &&
197-
!isPowerUser
195+
const showWalkThrough = !isLoading && !isPowerUser && totalCount === 0 && allProjectsCount === 0 &&
196+
_.isEqual(criteria, PROJECT_LIST_DEFAULT_CRITERIA)
198197
const getStatusCriteriaText = (criteria) => {
199198
return (_.find(PROJECT_STATUS, { value: criteria.status }) || { name: ''}).name
200199
}
@@ -287,6 +286,7 @@ const mapStateToProps = ({ projectSearch, members, loadUser, projectState, templ
287286
projects : projectSearch.projects,
288287
members : members.members,
289288
totalCount : projectSearch.totalCount,
289+
allProjectsCount: projectSearch.allProjectsCount,
290290
pageNum : projectSearch.pageNum,
291291
criteria : projectSearch.criteria,
292292
infiniteAutoload: projectSearch.infiniteAutoload,

src/projects/reducers/projectSearch.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const initialState = {
1515
projects: [],
1616
error: false,
1717
totalCount: 0,
18+
allProjectsCount: 0,
1819
pageNum: 1,
1920
// make a copy of constant to avoid unintentional modifications
2021
criteria: {...PROJECT_LIST_DEFAULT_CRITERIA},
@@ -53,8 +54,8 @@ export default function(state = initialState, action) {
5354
})
5455
case GET_PROJECTS_SUCCESS: {
5556
const updatedProjects = action.meta.keepPrevious
56-
? { projects : { $push : action.payload.projects }, totalCount: { $set : action.payload.totalCount} }
57-
: { projects : { $set : action.payload.projects }, totalCount: { $set : action.payload.totalCount} }
57+
? { projects : { $push : action.payload.projects }, totalCount: { $set : action.payload.totalCount}, allProjectsCount: { $set : action.payload.allProjectsCount} }
58+
: { projects : { $set : action.payload.projects }, totalCount: { $set : action.payload.totalCount}, allProjectsCount: { $set : action.payload.allProjectsCount} }
5859
return update(state, updatedProjects)
5960
}
6061

0 commit comments

Comments
 (0)