-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathapp.js
93 lines (70 loc) · 2.11 KB
/
app.js
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
$("[data-toggle=popover]").popover();
// Crear proyecto de node
// npm init -> agregar la configuración
// npm i sass -> instalar dependencia de sass desde https://www.npmjs.com/package/sass
// crear .gitignore y agregar texto de la pagina -> https://www.toptal.com/developers/gitignore/api/node
// ejecutar comando -> ./node_modules/sass/sass.js --watch ./scss/main.scss output.css
// Si es desde windows -> node ./node_modules/sass/sass.js --watch ./scss/main.scss output.css
// Variables -----------------------------------------------------------
// const x = 5
// let y = 5
// console.log(y);
// y = 6
// var z = 6
// z = 8
// console.log(z);
// ------------------------------------------------------------
const forms = document.querySelectorAll(".signup-form")
// console.log(forms);
// function suma(a, b) {
// return a + b
// }
const getTemplate = () => {
return fetch("./template.html")
.then((response) => response.text())
}
const sendEmailToApi = (address, template) => {
fetch(`https://bedu-email-sender-api.herokuapp.com/send?id`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
address: address,
template: template,
}),
})
.then((results) => {
console.log(results.status);
if(results.status == 200){
alert("E-mail send!!!")
} else {
alert("Send failed")
}
document.getElementById("email").value = ""
})
.catch((error) => {
console.error(error);
document.getElementById("email").value = ""
alert("Send failed")
});
};
function sendEmail(miVariable) {
miVariable.preventDefault()
const email = miVariable.target.querySelector("input").value
getTemplate()
.then((template) => {
sendEmailToApi(email, template)
})
.catch((error) => {
console.log(error, "error al obtener el template");
})
}
// const sendEmail = (miVariable) => {
// miVariable.preventDefault()
// console.log(miVariable);
// }
for(let i = 0; i < forms.length; i++){
// console.log(forms[i]);
forms[i].addEventListener("submit", sendEmail)
}