dataBucketObservers.js 1.32 KB
import LemaApi from "./service.js";
import { observer, observe } from 'redux-observers'
import {toast} from 'react-toastify';


// Observer sulla proprietà dataBucketProfilation dello store  
export const dataBucketsProfilationObserver = observer(
    state => state.ProfilationSelectReducer.dataBucketProfilation,

    (dispatch, current, previous) => {
        console.clear();
        console.log('Databucket aggiornato');
        console.log('Previous', previous);
        console.log('Current', current);       
                
        let request = {
            Job: current.job,
            Service: current.service,
            Expend: current.expend,
            Period: current.period,
            Light: current.light.length == 0 ? 0 : current.light,
            Gas: current.gas.length == 0 ? 0 : current.gas,
            Environment: current.environment,
            Flexibility: current.flexibility,
            Customizable: current.customizable
          };
      
          const lemaApi = new LemaApi();
          lemaApi.saveProfilationData(request)
            .then((response) => {
                toast.success("Update OK", {position: toast.POSITION.BOTTOM_CENTER});
            })
            .catch((err) => {
                toast.error("Update Error", {position: toast.POSITION.BOTTOM_CENTER});
            }
        );
    }
)