Guest User

Untitled

a guest
Jun 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. const campaignRouteIsCorrect = ({ campaign }, location) => {
  2. const [campaign_type, type] = [campaign, location];
  3. const routerActions = {
  4. [DYNAMIC]: DYNAMIC_ROUTE_ACTION_TYPE,
  5. [RELATIVE]: RELATIVE_ROUTE_ACTION_TYPE
  6. };
  7.  
  8. return routerActions[campaign_type] === type;
  9. };
  10.  
  11. const fetchInitialCampaignData = state => dispatch => {
  12. const { location, requestedCampaignData } = state;
  13. if (!requestedCampaignData && location.payload.campaignId) {
  14. dispatch(requestCampaignData());
  15.  
  16. return fetchData({
  17. url: getEnterpriseAPIURL(ORG_CAMPAIGN_DATA_ROUTE, location.payload.campaignId, {
  18. page_size: CAMPAIGN_CONTENT_PAGE_SIZE
  19. }),
  20. options: createGetRequestOptions(),
  21. success(responseBody) {
  22. if (!campaignRouteIsCorrect(responseBody, location)) {
  23. const { campaign_type, campaign_id, status } = responseBody.campaign;
  24. const editStep = findEditStep(status);
  25. const isRelative = campaign_type === RELATIVE;
  26.  
  27. dispatch(goToEditStep(editStep, campaign_id, isRelative));
  28. }
  29.  
  30. // districts handled separately by district widget
  31. dispatch(addDistricts(responseBody.districts));
  32. dispatch(initializeData(getPayloadForInitAction(responseBody)));
  33. },
  34. fail() {
  35. dispatch(alertGeneralError(resetAllCampaignState()));
  36. // fail to load campaign go to create dynamic step
  37. setTimeout(() => dispatch(goToCreateStep(FIRST_STEP, false)), 1000);
  38. }
  39. });
  40. }
  41.  
  42. return Promise.resolve();
  43. };
Add Comment
Please, Sign In to add comment