text: import cogoToast from 'cogo-toast';
  import {
  FIND_DRIVER_START,
  FIND_DRIVER_SUCCESS,
  FIND_DRIVER_ERROR,
  UPDATE_DRIVER_START,
  UPDATE_DRIVER_SUCCESS,
  UPDATE_DRIVER_ERROR
  } from './actionTypes';
  import AuthService from '../../../../../utils/AuthService';
  import API from '../../../../../utils/API';
  import history from '../../../../../utils/history';
  
  const apiStart = () =>({
      type: FIND_DRIVER_START,
  });
  
  const apiSuccess = (payload) =>({
      type: FIND_DRIVER_SUCCESS,
      payload,
  });
  
  const apiError = (error) =>({
      type: FIND_DRIVER_ERROR,
      error,
  });
  
  const updateStart = () =>({
      type: UPDATE_DRIVER_START,
  });
  
  const updateSuccess = (payload) =>({
      type: UPDATE_DRIVER_SUCCESS,
      payload,
  });
  
  const updateError = (error) =>({
      type: UPDATE_DRIVER_ERROR,
      error,
  });
  
  const showSuccessMessage = (message) => {
      cogoToast.success(message, { position: 'top-right' });
    };
  
  const showErrorMessage = (message) => {
      cogoToast.error(message, { position: 'top-right' });
    };
  
    export const findDriverById = () => async (dispatch) =>{
      dispatch(apiStart());
      try {
        const token = AuthService.getToken();
        const { search } = window.location;
        const params = new URLSearchParams(search);
        const id = params.get('id');
        const config = {
          headers: {
              'Content-Type': 'application/json',
              Authorization: `Bearer ${token}`,
          },
        };
          const response = await API.get(`/company/driver/${id}/`, config);
          console.log(response);
          dispatch(apiSuccess(response.data));
      } catch (error) {
          console.log(error);
          showErrorMessage('Driver record not updated, try again!');
          dispatch(apiError(error.response));
      }
  }
  
  export const updateDriver = (driver_name, driver_contact,is_active) => async (dispatch) =>{
     if(driver_name !== '' && driver_contact !== '' ) {
         dispatch(updateStart());
         try {
             const token = AuthService.getToken();
             const { search } = window.location;
             const params = new URLSearchParams(search);
             const id = params.get('id');
             const config = {
               headers: {
                   'Content-Type': 'application/json',
                   Authorization: `Bearer ${token}`,
               },
             };
             const jsonData = 
             {
                 "driver_name": `${driver_name}`,
                 "driver_contact": `${driver_contact}`,
                 "is_active": is_active     
             };
             const response = await API.put(`/company/driver/${id}/`,jsonData, config);
             showSuccessMessage('Record updated successfully!');
             dispatch(updateSuccess(response.data));
             history.push('/viewDriverList');
         } catch (error) {
             console.log(error);
             showErrorMessage('Driver record not updated, try again!');
             dispatch(updateError(error.response));
         }
     } else {
         showErrorMessage('All Fields are required!');
     }
  }