dataBucketObservers.js
3.67 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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) => {
console.log("dataBucket profilation Update successfully");
})
.catch((err) => {
console.error(err);
}
);
}
)
// 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);
}
);
}
)
// Observer sulla proprietà dataBucketContact dello store
export const dataBucketContactObserver = observer(
state => state.ProfilationSelectReducer.dataBucketContact,
(dispatch, current, previous) => {
// current is undefined on first call
if(!current) return;
console.log('Databucket contact aggiornato');
console.log('Previous', previous);
console.log('Current', current);
let email =
(/^[A-Za-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/.test(current.Email)) ?
current.Email : "";
let phone = (/^\+?\d+$/.test(current.PhoneNumber)) ?
current.PhoneNumber : "";
let request = {
Description: current.Description || "",
Email: email || "",
PhoneNumber: phone || "",
PrivacyAck: current.PrivacyAck || false,
AllowContact: current.AllowContact || false,
ContactReason: JSON.parse(localStorage.getItem("ContactsModel"))
};
const lemaApi = new LemaApi();
lemaApi.saveContactData(request)
.then(response => {
console.log("Contact saved successfully");
})
.catch(err => {
console.error(err);
}
);
}
)