@@ -20,10 +20,7 @@ import {
2020 deleteResource as deleteResourceAPI
2121} from '../services/challenges'
2222import {
23- LOAD_CHALLENGE_DETAILS_PENDING ,
24- LOAD_CHALLENGE_DETAILS_SUCCESS ,
25- LOAD_CHALLENGE_DETAILS_FAILURE ,
26- LOAD_CHALLENGE_MEMBERS_SUCCESS ,
23+ LOAD_CHALLENGE_DETAILS ,
2724 LOAD_CHALLENGE_METADATA_SUCCESS ,
2825 LOAD_CHALLENGES_FAILURE ,
2926 LOAD_CHALLENGES_PENDING ,
@@ -45,7 +42,6 @@ import {
4542 CREATE_CHALLENGE_SUCCESS ,
4643 CREATE_CHALLENGE_FAILURE
4744} from '../config/constants'
48- import { fetchProjectById } from '../services/projects'
4945import { loadProject } from './projects'
5046
5147/**
@@ -171,41 +167,19 @@ export function loadChallenges (projectId, status, filterChallengeName = null) {
171167 * Loads Challenge details
172168 */
173169export function loadChallengeDetails ( projectId , challengeId ) {
174- return async ( dispatch , getState ) => {
175- dispatch ( {
176- type : LOAD_CHALLENGE_DETAILS_PENDING ,
177- challengeDetails : { }
178- } )
179-
170+ return ( dispatch , getState ) => {
180171 if ( challengeId ) {
181- fetchChallenge ( challengeId ) . then ( ( challenge ) => {
182- dispatch ( {
183- type : LOAD_CHALLENGE_DETAILS_SUCCESS ,
184- challengeDetails : challenge
185- } )
186- loadProject ( challenge . projectId ) ( dispatch , getState )
187- } ) . catch ( ( ) => {
188- dispatch ( {
189- type : LOAD_CHALLENGE_DETAILS_FAILURE
172+ return dispatch ( {
173+ type : LOAD_CHALLENGE_DETAILS ,
174+ payload : fetchChallenge ( challengeId ) . then ( ( challenge ) => {
175+ // TODO remove this unncessary check, or better utilize the the case when given project id
176+ // does not match with challenge's project id
177+ if ( challenge . projectId === projectId ) {
178+ dispatch ( loadProject ( projectId ) )
179+ }
180+ return challenge
190181 } )
191182 } )
192- } else {
193- dispatch ( {
194- type : LOAD_CHALLENGE_DETAILS_SUCCESS ,
195- challengeDetails : null
196- } )
197-
198- if ( projectId ) {
199- fetchProjectById ( projectId ) . then ( ( selectedProject ) => {
200- if ( ! selectedProject ) return
201- const members = selectedProject . members
202- . filter ( m => m . role === 'manager' || m . role === 'copilot' )
203- dispatch ( {
204- type : LOAD_CHALLENGE_MEMBERS_SUCCESS ,
205- members
206- } )
207- } )
208- }
209183 }
210184 }
211185}
@@ -427,7 +401,7 @@ export function loadResources (challengeId) {
427401 } )
428402
429403 if ( challengeId ) {
430- fetchResources ( challengeId ) . then ( ( resources ) => {
404+ return fetchResources ( challengeId ) . then ( ( resources ) => {
431405 dispatch ( {
432406 type : LOAD_CHALLENGE_RESOURCES_SUCCESS ,
433407 challengeResources : resources
@@ -457,6 +431,12 @@ export function loadResourceRoles () {
457431 }
458432}
459433
434+ /**
435+ * Deletes a resource for the given challenge in given role
436+ * @param {UUID } challengeId id of the challenge for which resource is to be deleted
437+ * @param {UUID } roleId id of the role, the resource is in
438+ * @param {String } memberHandle handle of the resource
439+ */
460440export function deleteResource ( challengeId , roleId , memberHandle ) {
461441 const resource = {
462442 challengeId,
@@ -471,6 +451,12 @@ export function deleteResource (challengeId, roleId, memberHandle) {
471451 }
472452}
473453
454+ /**
455+ * Creates a resource for the given challenge in given role
456+ * @param {UUID } challengeId id of the challenge for which resource is to be created
457+ * @param {UUID } roleId id of the role, the resource should be in
458+ * @param {String } memberHandle handle of the resource
459+ */
474460export function createResource ( challengeId , roleId , memberHandle ) {
475461 const resource = {
476462 challengeId,
@@ -485,6 +471,13 @@ export function createResource (challengeId, roleId, memberHandle) {
485471 }
486472}
487473
474+ /**
475+ * Replaces the given resource in given role with new resource for the provided challenge
476+ * @param {UUID } challengeId id of the challenge for which resource is to be replaced
477+ * @param {UUID } roleId id of the role, the resource is in
478+ * @param {String } newMember handle of the new resource
479+ * @param {String } oldMember handle of the existing resource
480+ */
488481export function replaceResourceInRole ( challengeId , roleId , newMember , oldMember ) {
489482 return async ( dispatch ) => {
490483 if ( newMember === oldMember ) {
0 commit comments