Skip to content

Commit f145647

Browse files
author
Vikas Agarwal
committed
Merge branch 'hotfix/no_permissions_immediately_after_joining_project'
2 parents d92b317 + f63be95 commit f145647

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

src/projects/reducers/project.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ const initialState = {
2121
processingMembers: false,
2222
processingAttachments: false,
2323
error: false,
24-
project: {}
24+
project: {},
25+
projectNonDirty: {}
2526
}
2627

28+
// NOTE: We should always update projectNonDirty state whenever we update the project state
29+
2730
const parseErrorObj = (action) => {
2831
const data = action.payload.response.data.result
2932
return {
@@ -40,7 +43,8 @@ export const projectState = function (state=initialState, action) {
4043
case LOAD_PROJECT_PENDING:
4144
return Object.assign({}, state, {
4245
isLoading: true,
43-
project: null
46+
project: null,
47+
projectNonDirty: null
4448
})
4549

4650
case LOAD_PROJECT_SUCCESS:
@@ -54,7 +58,8 @@ export const projectState = function (state=initialState, action) {
5458
case CLEAR_LOADED_PROJECT:
5559
case GET_PROJECTS_SUCCESS:
5660
return Object.assign({}, state, {
57-
project: {}
61+
project: {},
62+
projectNonDirty: {}
5863
})
5964

6065
case LOAD_DIRECT_PROJECT_SUCCESS:
@@ -70,6 +75,18 @@ export const projectState = function (state=initialState, action) {
7075
plannedDuration: action.payload.plannedDuration,
7176
projectedDuration: action.payload.projectedDuration
7277
}}
78+
},
79+
projectNonDirty: {
80+
budget: { $set: {
81+
actualCost: action.payload.actualCost,
82+
projectedCost: action.payload.projectedCost,
83+
totalBudget: action.payload.totalBudget
84+
}},
85+
duration: { $set: {
86+
actualDuration: action.payload.actualDuration,
87+
plannedDuration: action.payload.plannedDuration,
88+
projectedDuration: action.payload.projectedDuration
89+
}}
7390
}
7491
})
7592

@@ -96,7 +113,8 @@ export const projectState = function (state=initialState, action) {
96113
return Object.assign({}, state, {
97114
processing: false,
98115
error: false,
99-
project: {}
116+
project: {},
117+
projectNonDirty: {}
100118
})
101119

102120
// Project attachments
@@ -110,15 +128,17 @@ export const projectState = function (state=initialState, action) {
110128
case ADD_PROJECT_ATTACHMENT_SUCCESS:
111129
return update(state, {
112130
processingAttachments: { $set : false },
113-
project: { attachments: { $push: [action.payload] } }
131+
project: { attachments: { $push: [action.payload] } },
132+
projectNonDirty: { attachments: { $push: [action.payload] } }
114133
})
115134

116135
case UPDATE_PROJECT_ATTACHMENT_SUCCESS: {
117136
// get index
118137
const idx = _.findIndex(state.project.attachments, a => a.id === action.payload.id)
119138
return update(state, {
120139
processingAttachments: { $set : false },
121-
project: { attachments: { $splice : [[idx, 1, action.payload]] } }
140+
project: { attachments: { $splice : [[idx, 1, action.payload]] } },
141+
projectNonDirty: { attachments: { $splice : [[idx, 1, action.payload]] } }
122142
})
123143
}
124144

@@ -128,7 +148,8 @@ export const projectState = function (state=initialState, action) {
128148
const idx = _.findIndex(state.project.attachments, a => a.id === action.payload)
129149
return update(state, {
130150
processing: { $set : false },
131-
project: { attachments: { $splice: [[idx, 1]] } }
151+
project: { attachments: { $splice: [[idx, 1]] } },
152+
projectNonDirty: { attachments: { $splice: [[idx, 1]] } }
132153
})
133154
}
134155

@@ -142,7 +163,8 @@ export const projectState = function (state=initialState, action) {
142163
case ADD_PROJECT_MEMBER_SUCCESS:
143164
return update (state, {
144165
processingMembers: { $set : false },
145-
project: { members: { $push: [action.payload] } }
166+
project: { members: { $push: [action.payload] } },
167+
projectNonDirty: { members: { $push: [action.payload] } }
146168
})
147169

148170
case UPDATE_PROJECT_MEMBER_SUCCESS: {
@@ -156,7 +178,8 @@ export const projectState = function (state=initialState, action) {
156178
updatedMembers.splice(idx, 1, action.payload)
157179
return update(state, {
158180
processingMembers: { $set : false },
159-
project: { members: { $set: updatedMembers } }
181+
project: { members: { $set: updatedMembers } },
182+
projectNonDirty: { members: { $set: updatedMembers } }
160183
})
161184
}
162185

@@ -165,7 +188,8 @@ export const projectState = function (state=initialState, action) {
165188
const idx = _.findIndex(state.project.members, a => a.id === action.payload)
166189
return update(state, {
167190
processingMembers: { $set : false },
168-
project: { members: { $splice: [[idx, 1]] } }
191+
project: { members: { $splice: [[idx, 1]] } },
192+
projectNonDirty: { members: { $splice: [[idx, 1]] } }
169193
})
170194
}
171195

0 commit comments

Comments
 (0)