mirror of
https://github.com/kevin-DL/complete-node-bootcamp.git
synced 2026-01-20 22:55:12 +00:00
Initial commit 🚀
This commit is contained in:
55
4-natours/after-section-12/public/js/index.js
Normal file
55
4-natours/after-section-12/public/js/index.js
Normal file
@@ -0,0 +1,55 @@
|
||||
/* eslint-disable */
|
||||
import '@babel/polyfill';
|
||||
import { displayMap } from './mapbox';
|
||||
import { login, logout } from './login';
|
||||
import { updateSettings } from './updateSettings';
|
||||
|
||||
// DOM ELEMENTS
|
||||
const mapBox = document.getElementById('map');
|
||||
const loginForm = document.querySelector('.form--login');
|
||||
const logOutBtn = document.querySelector('.nav__el--logout');
|
||||
const userDataForm = document.querySelector('.form-user-data');
|
||||
const userPasswordForm = document.querySelector('.form-user-password');
|
||||
|
||||
// DELEGATION
|
||||
if (mapBox) {
|
||||
const locations = JSON.parse(mapBox.dataset.locations);
|
||||
displayMap(locations);
|
||||
}
|
||||
|
||||
if (loginForm)
|
||||
loginForm.addEventListener('submit', e => {
|
||||
e.preventDefault();
|
||||
const email = document.getElementById('email').value;
|
||||
const password = document.getElementById('password').value;
|
||||
login(email, password);
|
||||
});
|
||||
|
||||
if (logOutBtn) logOutBtn.addEventListener('click', logout);
|
||||
|
||||
if (userDataForm)
|
||||
userDataForm.addEventListener('submit', e => {
|
||||
e.preventDefault();
|
||||
const name = document.getElementById('name').value;
|
||||
const email = document.getElementById('email').value;
|
||||
updateSettings({ name, email }, 'data');
|
||||
});
|
||||
|
||||
if (userPasswordForm)
|
||||
userPasswordForm.addEventListener('submit', async e => {
|
||||
e.preventDefault();
|
||||
document.querySelector('.btn--save-password').textContent = 'Updating...';
|
||||
|
||||
const passwordCurrent = document.getElementById('password-current').value;
|
||||
const password = document.getElementById('password').value;
|
||||
const passwordConfirm = document.getElementById('password-confirm').value;
|
||||
await updateSettings(
|
||||
{ passwordCurrent, password, passwordConfirm },
|
||||
'password'
|
||||
);
|
||||
|
||||
document.querySelector('.btn--save-password').textContent = 'Save password';
|
||||
document.getElementById('password-current').value = '';
|
||||
document.getElementById('password').value = '';
|
||||
document.getElementById('password-confirm').value = '';
|
||||
});
|
||||
Reference in New Issue
Block a user