feat: 11.0 - Frontend - Create habit from form

This commit is contained in:
Echo
2026-02-10 12:39:28 +00:00
parent d4f1526989
commit 4933847f72
3 changed files with 229 additions and 3 deletions

View File

@@ -516,6 +516,7 @@
// Create habit
async function createHabit() {
const nameInput = document.getElementById('habitName');
const createBtn = document.getElementById('habitCreateBtn');
const name = nameInput.value.trim();
const frequency = document.querySelector('input[name="frequency"]:checked').value;
@@ -524,6 +525,11 @@
return;
}
// Disable button during submission (loading state)
createBtn.disabled = true;
const originalText = createBtn.textContent;
createBtn.textContent = 'Se creează...';
try {
const response = await fetch('/api/habits', {
method: 'POST',
@@ -532,16 +538,27 @@
});
if (response.ok) {
// Clear input field after successful creation
nameInput.value = '';
hideHabitModal();
showToast('Obișnuință creată cu succes!');
loadHabits();
} else {
const error = await response.text();
showToast('Eroare la crearea obișnuinței: ' + error);
// Re-enable button on error (modal stays open)
createBtn.disabled = false;
createBtn.textContent = originalText;
}
} catch (error) {
showToast('Eroare la conectarea cu serverul');
console.error(error);
// Re-enable button on error (modal stays open)
createBtn.disabled = false;
createBtn.textContent = originalText;
}
}