Sha256: 8ad4daab7ab60fd6c9206eb7041649a8b7e8e5eea14352b36ed436377ca6f44c

Contents?: true

Size: 1.02 KB

Versions: 24

Compression:

Stored size: 1.02 KB

Contents

import api from 'foremanReact/API';
import { deepPropsToCamelCase } from 'foremanReact/common/helpers';

import {
  SYNC_SETTINGS_REQUEST,
  SYNC_SETTINGS_SUCCESS,
  SYNC_SETTINGS_FAILURE,
  SYNC_RESULT_PAGINATION_CHANGE,
} from '../../consts';

import { initialState } from '../TemplateSyncResult/TemplateSyncResultReducer';

export const getSyncSettings = url => async dispatch => {
  dispatch({ type: SYNC_SETTINGS_REQUEST });

  try {
    const { data } = await api.get(url);
    dispatch({
      type: SYNC_RESULT_PAGINATION_CHANGE,
      payload: { pagination: initialState.pagination },
    });
    return dispatch({
      type: SYNC_SETTINGS_SUCCESS,
      payload: {
        ...deepPropsToCamelCase(data),
      },
    });
  } catch (error) {
    return dispatch(errorHandler(SYNC_SETTINGS_FAILURE, error));
  }
};

const errorHandler = (msg, err) => {
  const error = {
    errorMsg: 'Failed to fetch Settings for template sync from server.',
    statusText: err.response.statusText,
  };
  return { type: msg, payload: { error } };
};

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
foreman_templates-10.0.4 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-10.0.3 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-10.0.2 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-10.0.1 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-10.0.0 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-9.5.1 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-9.5.0 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-9.3.3 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-9.3.2 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-9.3.1 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-9.4.0 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-9.3.0 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-9.2.0 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-9.1.0 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-9.0.2 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-9.0.1 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-9.0.0 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-7.0.7 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-8.0.0 webpack/components/NewTemplateSync/NewTemplateSyncActions.js
foreman_templates-7.0.6 webpack/components/NewTemplateSync/NewTemplateSyncActions.js