Skip to content

Commit

Permalink
airtable and modal ok, added required attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ail3ngrimaldi authored and olanod committed Jun 19, 2024
1 parent 346bbcf commit 34200f0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
22 changes: 8 additions & 14 deletions _layouts/index.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<meta name="description" content="{{ site.description }}">
<title>{{ page.title }}</title>

<!-- change color -->
<meta name="theme-color" content="#54c95e">
<meta name="theme-color" content="#10353B">
<link rel="stylesheet" href="/css/index.css">
<link rel="stylesheet" href="/css/layout.css">
<link rel="stylesheet" href="/css/variables.css">
Expand All @@ -30,7 +29,7 @@

{% assign env = site.data.env %}

<script>
<script>
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.intersectionRatio > 0) {
Expand Down Expand Up @@ -86,7 +85,7 @@ mailForm.addEventListener('submit', async (event) => {
}
};
const response = await fetch(`https://api.airtable.com/${baseId}/${table}`, {
const response = await fetch(`https://api.airtable.com/v0/${baseId}/${table}`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKeyAirtable}`,
Expand All @@ -95,24 +94,19 @@ mailForm.addEventListener('submit', async (event) => {
body: JSON.stringify(data)
});
console.log(response.json())
if (!response.ok) {
throw new Error(`Airtable API error: ${response.status}`);
}
const result = await response.json();
openModal(`<img src="/img/success.svg" alt="success" /><h2>¡Gracias!</h2><h3>Su mail ha sido registrado exitosamente.</h3>`);
console.log('Datos enviados exitosamente a Airtable:', result);
} catch (error) {
openModal('<img src="/img/error.svg" alt="error" /><h2>Error</h2><h3>Hubo un problema al registrar su mail.</h3><h3 class="bolder">Por favor, intente nuevamente.</h3>');
console.error("Error al enviar datos a Airtable:", error);
} catch (error) {
console.error('Error:', error); // Log the error for debugging
openModal('<img src="/img/error.svg" alt="error" /><h2>Error</h2><h3>Hubo un problema al registrar su mail.</h3><h3 class="bolder">Por favor, intente nuevamente.</h3>');
}
});
</script>
</script>
</body>

</html>
</html>
2 changes: 1 addition & 1 deletion index.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ data:
<form id="mail-form">
<input type="text" name="contactName" placeholder="{{ home_section.placeholder_name }}">
<input type="text" name="contactLastName" placeholder="{{ home_section.placeholder_last_name }}">
<input type="email" name="contactEmail" placeholder="{{ home_section.placeholder_email }}">
<input type="email" name="contactEmail" placeholder="{{ home_section.placeholder_email }}" required>
<button type="submit" id="mail-button" class="bolder">{{ home_section.cta }}</button>
</form>
</article>
Expand Down
2 changes: 1 addition & 1 deletion services.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ section {
<form id="mail-form">
<input type="text" name="contactName" placeholder="{{ service.placeholder_name }}">
<input type="text" name="contactLastName" placeholder="{{ service.placeholder_last_name }}">
<input type="email" name="contactEmail" placeholder="{{ service.placeholder_email }}">
<input type="email" name="contactEmail" placeholder="{{ service.placeholder_email }}" required>
<button type="submit" id="mail-button" class="bolder dark-green-bg">{{ service.cta }}</button>
</form>
</div>
Expand Down

0 comments on commit 34200f0

Please sign in to comment.