Sha256: fc0ef347f714a2ca11d92618093eb2995df602ea3c79382f1161094e92ac0fdf

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

import React from 'react';
import { API } from 'foremanReact/redux/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_ERROR,
} 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_ERROR,
      payload: {
        error: message,
      },
    });

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_rh_cloud-3.0.18.1 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-3.0.18 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-3.0.17 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-3.0.16 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js
foreman_rh_cloud-3.0.15 webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js