Skip to content

Commit

Permalink
footer update
Browse files Browse the repository at this point in the history
  • Loading branch information
TetiZ committed Feb 1, 2024
1 parent 79100b1 commit 2c5ba83
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 51 deletions.
1 change: 1 addition & 0 deletions src/favorites.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ <h2 class="fav-title">110 min</h2>
<load src="./partials/favorites.html" />
<load src="./partials/exersises-filters.html" />
<load src="./partials/favorite-modal.html" />
<load src="./partials/footer.html" />

<!-- SCROLL -->
<load src="./partials/scroll-btn.html" />
Expand Down
101 changes: 51 additions & 50 deletions src/js/submit-email-footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,62 @@ import 'izitoast/dist/css/iziToast.min.css';
const form = document.querySelector('.subs-form');
const localStorageKey = 'user-email';

if (form) {
const savedEmail = localStorage.getItem(localStorageKey);
const savedEmail = localStorage.getItem(localStorageKey);

function saveToLocalStorage(evt) {
localStorage.setItem(localStorageKey, evt.target.value);
}
form.addEventListener('input', saveToLocalStorage);
if (savedEmail) {
form.elements.email.value = savedEmail;
} else {
form.elements.email.value = '';
}

form.elements.email.value = savedEmail ? savedEmail : '';
form.addEventListener('input', saveToLocalStorage);

async function postEmail(userEmail) {
try {
const response = await fetch(
'https://energyflow.b.goit.study/api/subscription',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email: userEmail }),
}
);
if (!response.ok) {
console.error('Код помилки:', response.status);
throw new Error('Мережевий запит не був успішним');
}
const data = await response.json();
console.log('Дані успішно відправлені', data);
function saveToLocalStorage(evt) {
localStorage.setItem(localStorageKey, evt.target.value);
}

iziToast.success({
title: 'We are excited to have you on board!',
message:
'Thank you for subscribing to new exercises on Energy Flow. You have just taken a significant step towards improving your fitness and well-being.',
position: 'center',
});
} catch (error) {
console.error('Помилка при відправленні даних', error);
async function postEmail(userEmail) {
try {
const response = await fetch(
'https://energyflow.b.goit.study/api/subscription',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email: userEmail }),
}
);
if (!response.ok) {
console.error('Код помилки:', response.status);
throw new Error('Мережевий запит не був успішним');
}
const data = await response.json();
console.log('Дані успішно відправлені', data);

iziToast.success({
title: 'We are excited to have you on board!',
message:
'Thank you for subscribing to new exercises on Energy Flow. You have just taken a significant step towards improving your fitness and well-being.',
position: 'center',
});
} catch (error) {
console.error('Помилка при відправленні даних', error);
}
}

form.addEventListener('submit', async e => {
e.preventDefault();
const userEmail = savedEmail;
if (userEmail) {
try {
await postEmail(userEmail);
localStorage.removeItem(localStorageKey);
form.reset();
} catch (error) {
console.error('Помилка при відправленні електронної пошти.', error);
}
} else {
console.log('Електронна пошта не введена.');
form.addEventListener('submit', async e => {
e.preventDefault();
const userEmail = localStorage.getItem(localStorageKey);
if (userEmail) {
try {
await postEmail(userEmail);
localStorage.removeItem(localStorageKey);
form.reset();
} catch (error) {
console.log('Помилка при відправленні електронної пошти.');
}
});
} else {
console.error('Форма не знайдена.');
}
} else {
console.log('Електронна пошта не введена.');
}
});
2 changes: 1 addition & 1 deletion src/partials/footer.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<footer class="footer-section section">
<footer class="footer-section section visually-hidden">
<div class="footer-container">
<div class="footer-main-wrapper">
<div class="footer-first-half-wrapper">
Expand Down

0 comments on commit 2c5ba83

Please sign in to comment.