/* global config */
import 'isomorphic-fetch';

/**
 * CONSTANTS
*/
const GET_PARTNER_SUCCESS = 'explore/GET_PARTNER_SUCCESS';
const GET_PARTNER_ERROR = 'explore/GET_PARTNER_ERROR';
const GET_PARTNER_LOADING = 'explore/GET_PARTNER_LOADING';

/**
 * REDUCER
*/
const initialState = {
  data: {}
};

export default function (state = initialState, action) {
  switch (action.type) {
    case GET_PARTNER_SUCCESS: {
      return Object.assign({}, state, {
        data: action.payload,
        loading: false,
        error: false
      });
    }

    case GET_PARTNER_ERROR: {
      return Object.assign({}, state, {
        loading: false,
        error: true
      });
    }

    case GET_PARTNER_LOADING: {
      return Object.assign({}, state, {
        loading: true,
        error: false
      });
    }

    default:
      return state;
  }
}

/**
 * ACTIONS
 * - getPartnerData
*/
export function getPartnerData(id) {
  return (dispatch) => {
    // Waiting for fetch from server -> Dispatch loading
    dispatch({ type: GET_PARTNER_LOADING });
    // TODO: remove the date now
    fetch(new Request(`${process.env.API_URL}/partners/${id}`))
      .then((response) => {
        if (response.ok) return response.json();
        throw new Error(response.statusText);
      })
      .then((response) => {
        dispatch({
          type: GET_PARTNER_SUCCESS,
          payload: response.data.attributes
        });
      })
      .catch((err) => {
        // Fetch from server ko -> Dispatch error
        dispatch({
          type: GET_PARTNER_ERROR,
          payload: err.message
        });
      });
  };
}

@@ -86,31 +86,37 @@
 _SUCCESS = '
-explore
+partnerDetail
 /GET_PARTNER
@@ -149,31 +149,37 @@
 ER_ERROR = '
-explore
+partnerDetail
 /GET_PARTNER
@@ -220,89 +220,361 @@
  = '
-explore/GET_PARTNER_LOADING';%0A%0A/**%0A * REDUCER%0A*/%0Aconst initialState = %7B%0A  data: %7B
+partnerDetail/GET_PARTNER_LOADING';%0Aconst GET_DATASETS_SUCCESS = 'partnerDetail/GET_DATASETS_SUCCESS';%0Aconst GET_DATASETS_ERROR = 'partnerDetail/GET_DATASETS_ERROR';%0Aconst GET_DATASETS_LOADING = 'partnerDetail/GET_DATASETS_LOADING';%0A%0A/**%0A * REDUCER%0A*/%0Aconst initialState = %7B%0A  data: %7B%7D,%0A  datasets: %7B%0A    loading: false,%0A    error: null,%0A    list: %5B%5D%0A  
 %7D%0A%7D;
@@ -1016,32 +1016,605 @@
 gn(%7B%7D, state, %7B%0A
+        datasets: %7B%0A          list: %5B%5D,%0A          loading: true,%0A          error: null%0A        %7D%0A      %7D);%0A    %7D%0A%0A    case GET_DATASETS_SUCCESS: %7B%0A      return Object.assign(%7B%7D, state, %7B%0A        datasets: %7B%0A          list: action.payload,%0A          loading: false,%0A          error: null%0A        %7D%0A      %7D);%0A    %7D%0A%0A    case GET_DATASETS_ERROR: %7B%0A      return Object.assign(%7B%7D, state, %7B%0A        datasets: %7B%0A          list: %5B%5D,%0A          loading: false,%0A          error: true%0A        %7D%0A      %7D);%0A    %7D%0A%0A    case GET_DATASETS_LOADING: %7B%0A      return Object.assign(%7B%7D, state, %7B%0A
         loading:

prepare actions to load datasets