-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (46 loc) · 1.96 KB
/
index.js
File metadata and controls
57 lines (46 loc) · 1.96 KB
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
import { sweetAlert3 } from "./Data/data.js";
import { cardLogic } from "./range.js";
import { currentUser, signOutUser } from "./firebase.js";
currentUser()
// Account Name Functionality
const accountName = () => {
let accountP = document.getElementsByClassName("account-p")[1];
let dropDownDiv = document.getElementsByClassName("sn-navbar__dropdown-menu")[0];
let loggedInUserEmail = JSON.parse(localStorage.getItem("loggedInUser"));
let usersData = JSON.parse(localStorage.getItem("Data")) || [];
let firstChar = (sUName) => {
return sUName.charAt(0).toUpperCase();
}
if (loggedInUserEmail && typeof loggedInUserEmail === 'string') {
let loggedInUser = usersData.find(user => user.email === loggedInUserEmail);
if (loggedInUser) {
accountP.innerText = `${loggedInUser.fName} ${firstChar(loggedInUser.sName)}.`;
}
dropDownDiv.innerHTML = `<li><a id="logOut" href="../forms/login.html">Log Out</a></li>`;
let logOut = document.getElementById("logOut")
logOut.addEventListener("click", () => {
signOutUser()
localStorage.setItem("loggedInUser", JSON.stringify(false))
localStorage.setItem("User", JSON.stringify(false))
})
}
}
accountName();
// Add To Cart Functionality
const addToCart = (cartBtn) => {
const cartArray = JSON.parse(localStorage.getItem("Cart")) || []
let userValue = JSON.parse(localStorage.getItem("User"))
let cartNum = document.getElementsByClassName("cart-number")[0]
cartNum.style.display = "block"
if (!userValue) {
sweetAlert3("error", "Login Required!!!", "Please Log In First to Add Products in the Cart")
return
}
let productId = cartBtn.dataset.productId
// console.log(productId)
}
document.addEventListener("click", (event) => {
if (event.target.classList.contains("cartBtn")) {
addToCart(event.target)
}
})