dataBucketObservers.js
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import LemaApi from "./service.js";
import { observer } 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) => {
// current is undefined on first call
if(!current) return;
console.log('Databucket profilazione 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 || 0,
Gas: current.gas || 0,
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});
}
);
}
)
// Observer sulla proprietà dataBucketPrivacy dello store
export const dataBucketPrivacyObserver = observer(
state => state.ProfilationSelectReducer.dataBucketPrivacy,
(dispatch, current, previous) => {
// current is undefined on first call
if(!current) return;
console.log('Databucket privacy aggiornato');
console.log('Previous', previous);
console.log('Current', current);
let request = {
contractAccepted: current.ContractAccepted || false,
activationAdAccepted: current.ActivationAdAccepted || false,
commercialAccepted: current.CommercialAccepted || false
};
const lemaApi = new LemaApi();
lemaApi.savePrivacyInfo(request)
.then(response => {
console.log("Privacy Info saved successfully");
})
.catch(err => {
console.error(err);
}
);
}
)