Sha256: 3481ada9912f8a2104dff05e032eb7800b636f8f07cb2b247cf45f9d4845cf87

Contents?: true

Size: 1.26 KB

Versions: 9

Compression:

Stored size: 1.26 KB

Contents

import React from 'react';
import API from 'foremanReact/API';
import { addToast } from 'foremanReact/redux/actions/toasts';
import { inventoryUrl } from '../../../../ForemanInventoryHelpers';
import Toast from './components/Toast';
import {
  INVENTORY_SYNC_REQUEST,
  INVENTORY_SYNC_SUCCESS,
  INVENTORY_SYNC_FAILURE,
} from './SyncButtonConstants';

export const handleSync = () => async dispatch => {
  dispatch({
    type: INVENTORY_SYNC_REQUEST,
    payload: {},
  });
  try {
    const {
      data: { syncHosts, disconnectHosts },
    } = await API.post(inventoryUrl('tasks'));
    dispatch({
      type: INVENTORY_SYNC_SUCCESS,
      payload: {
        syncHosts,
        disconnectHosts,
      },
    });

    dispatch(
      addToast({
        sticky: true,
        type: 'success',
        message: (
          <Toast syncHosts={syncHosts} disconnectHosts={disconnectHosts} />
        ),
      })
    );
  } catch ({
    message,
    response: { data: { message: toastMessage } = {} } = {},
  }) {
    dispatch({
      type: INVENTORY_SYNC_FAILURE,
      payload: {
        error: message,
      },
    });

    if (toastMessage) {
      dispatch(
        addToast({
          sticky: true,
          type: 'error',
          message: toastMessage,
        })
      );
    }
  }
};

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
foreman_rh_cloud-0.9.12 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-1.0.12 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-2.0.12 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-0.9.11 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-1.0.11 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-2.0.11 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-0.9.10 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-1.0.10 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-2.0.10 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js