mirror of
https://github.com/marcogll/soul23_placeholder_site_server.git
synced 2026-01-13 13:25:18 +00:00
feat: Update notification form to collect name and phone and submit data via webhook, replacing Firebase email submission.
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
// Initialize Firebase
|
||||
function validateEmail(email) {
|
||||
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
return re.test(String(email).toLowerCase());
|
||||
}
|
||||
|
||||
var config = {
|
||||
apiKey: "<YOUR FIREBASE API KEY>",
|
||||
authDomain: "<FIREBASE AUTH DOMAIN>",
|
||||
databaseURL: "<DB URL>",
|
||||
projectId: "<PROJECT ID>",
|
||||
storageBucket: "<STRORAGE BUKCET>",
|
||||
messagingSenderId: "<MESSAGE SENDER ID>"
|
||||
};
|
||||
firebase.initializeApp(config);
|
||||
var db = firebase.firestore();
|
||||
db.settings({
|
||||
timestampsInSnapshots: true
|
||||
});
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
$('#notifs-form-btn').click(function (e) {
|
||||
var is_present = false;
|
||||
email = $('#notifs-form-input').val();
|
||||
if (validateEmail(email)) {
|
||||
db.collection('Emails').get().then(function (qs) {
|
||||
qs.forEach(function (element) {
|
||||
if (element.data()['ID'] == email) {
|
||||
is_present = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (is_present == false) {
|
||||
db.collection("Emails").add({
|
||||
'ID': email,
|
||||
})
|
||||
.then(function (docRef) {
|
||||
console.log("Document written with ID: ", docRef.id);
|
||||
$("#notifs-form-btn").text("Notified!");
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.error("Error adding document: ", error);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
alert('Invalid Email');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
40
js/form_submission.js
Normal file
40
js/form_submission.js
Normal file
@@ -0,0 +1,40 @@
|
||||
$(document).ready(function () {
|
||||
|
||||
$('#notifs-form-btn').click(function (e) {
|
||||
var name = $('#notifs-form-name').val();
|
||||
var phone = $('#notifs-form-phone').val();
|
||||
|
||||
if (name && phone) {
|
||||
var data = {
|
||||
name: name,
|
||||
phone: phone
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: 'https://flows.soul23.cloud/webhook/Ul6upjlKqQQ79rDgd8XKOm',
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(data),
|
||||
success: function (response) {
|
||||
console.log("Webhook sent successfully", response);
|
||||
$("#notifs-form-btn").text("gracias :)");
|
||||
$("#notifs-form-btn").prop("disabled", true);
|
||||
alert("¡Gracias! Hemos recibido tus datos.");
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error sending webhook", error);
|
||||
var errorMessage = "Hubo un error al enviar tus datos.";
|
||||
if (xhr.responseJSON && xhr.responseJSON.message) {
|
||||
errorMessage += "\n" + xhr.responseJSON.message;
|
||||
} else if (xhr.responseText) {
|
||||
errorMessage += "\n" + xhr.responseText;
|
||||
}
|
||||
alert(errorMessage);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
alert('jejeje, lo haremos mas fácil en el futuro');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user