ContactsModalStructure.js
2 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
import _ from 'lodash';
import LemaApi from '../../service/service.js';
class ContactModals {
AddContactRequest = (cntSin, modalName) => {
let contactsStructure = JSON.parse(localStorage.getItem("ContactsModel"));
if (contactsStructure.Contacts.length != 0)
{
_.remove(contactsStructure.Contacts, function(obj){
return obj.ContactFormName === modalName;
} )
}
contactsStructure.Contacts.push(cntSin);
localStorage.setItem("ContactsModel", JSON.stringify(contactsStructure));
/*contactsStructure = {
"Contacts" : [
ContactStructure = {
ContactFormName: "",
BusinessName: "",
Email: "",
PhoneNumber: "",
PrivacyAck: false,
AllowContact: false
}
]
}*/
//localStorage.setItem("ContactsModel", JSON.stringify(response.data));
}
GetAndSaveModalInfo = (contactModalName, name, contactValue, modalPrivacy, adAccepted) => {
let email =
(/^[A-Za-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/.test(contactValue)) ?
contactValue : "";
let phone =
(/^\+?\d+$/.test(contactValue)) ?
contactValue : "";
let contactsStruct =
{
ContactFormName: contactModalName,
BusinessName: name,
Email: email,
PhoneNumber: phone,
PrivacyAck: modalPrivacy,
AllowContact: adAccepted
};
this.AddContactRequest(contactsStruct, contactModalName);
const lemaApi = new LemaApi();
lemaApi.saveContactData(JSON.parse(localStorage.getItem("ContactsModel")));
return null;
}
}
export {ContactModals}