Skip to content

Commit b6157bf

Browse files
authored
Update account-dashboard.html
1 parent 0e22cb2 commit b6157bf

File tree

1 file changed

+73
-6
lines changed

1 file changed

+73
-6
lines changed

account-dashboard.html

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,39 @@
9999
display: none;
100100
}
101101
}
102+
103+
.settings-form {
104+
margin-top: 20px;
105+
text-align: center;
106+
}
107+
108+
.settings-form input {
109+
padding: 10px;
110+
margin: 5px;
111+
font-size: 18px;
112+
}
113+
114+
.settings-form button {
115+
padding: 10px 20px;
116+
background-color: #50e3c2;
117+
color: white;
118+
border: none;
119+
cursor: pointer;
120+
}
121+
122+
.settings-form button:hover {
123+
background-color: #4ba99d;
124+
}
102125
</style>
103126
</head>
104127
<body>
105128
<nav class="menu-container">
106-
<!-- Logo -->
107129
<a href="https://scratch-coding-hut.github.io" class="menu-logo">
108130
<img src="Images/Coding-Hut-Logo.png" alt="Coding Hut Logo" width="50" height="50" />
109131
</a>
110132

111-
<!-- Menu for Mobile -->
112133
<span class="hamburger" onclick="toggleMenu()">&#9776;</span>
113134

114-
<!-- Menu Items -->
115135
<div class="menu">
116136
<ul>
117137
<li><a href="https://scratch-coding-hut.github.io">Home</a></li>
@@ -130,8 +150,16 @@ <h1 id="user" style="text-align: center"><b>Coding Hut</b></h1>
130150
<h2 style="text-align: center">Welcome to your dashboard</h2>
131151
<p id="data" style="text-align: center">COMING SOON</p>
132152

153+
<div class="settings-form">
154+
<h3>Update Your Settings</h3>
155+
<form id="settings-form">
156+
<input type="email" id="email" placeholder="Update your email" />
157+
<input type="number" id="points" placeholder="Update your points" />
158+
<button type="submit">Save Settings</button>
159+
</form>
160+
</div>
161+
133162
<script>
134-
// Fetch user data and update UI
135163
async function loadUserData() {
136164
const username = localStorage.getItem("username");
137165

@@ -152,13 +180,52 @@ <h2 style="text-align: center">Welcome to your dashboard</h2>
152180
}
153181
}
154182

155-
// Menu toggle for mobile
183+
async function updateUserSettings(event) {
184+
event.preventDefault();
185+
186+
const username = localStorage.getItem("username");
187+
const email = document.getElementById("email").value;
188+
const points = document.getElementById("points").value;
189+
190+
if (!email && !points) {
191+
alert("Please enter at least one value to update.");
192+
return;
193+
}
194+
195+
const updatedData = {};
196+
if (email) updatedData.email = email;
197+
if (points) updatedData.points = parseInt(points);
198+
199+
try {
200+
const res = await fetch(`https://scratch-coding-hut-data.onrender.com/${username}`, {
201+
method: "PUT",
202+
headers: {
203+
"Content-Type": "application/json",
204+
},
205+
body: JSON.stringify(updatedData),
206+
});
207+
208+
const data = await res.json();
209+
210+
if (data) {
211+
document.getElementById("data").textContent = JSON.stringify(data);
212+
alert("Settings updated successfully!");
213+
} else {
214+
alert("Error updating settings.");
215+
}
216+
} catch (error) {
217+
console.error("Error updating data:", error);
218+
alert("Failed to update settings.");
219+
}
220+
}
221+
222+
document.getElementById("settings-form").addEventListener("submit", updateUserSettings);
223+
156224
function toggleMenu() {
157225
var menu = document.querySelector(".menu");
158226
menu.style.display = menu.style.display === "flex" ? "none" : "flex";
159227
}
160228

161-
// Load user data on page load
162229
document.addEventListener("DOMContentLoaded", loadUserData);
163230
</script>
164231
</body>

0 commit comments

Comments
 (0)