Skip to content

🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!

Settings page improvement

sassanix8605fbf77665
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e07fec4..6e1effd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,14 @@
# Changelog
+## [0.9.8.5] - 2025-03-29
+
+### Changed
+- **Settings Page Improvements**
+ - Separated email settings into their own section with a dedicated save button
+ - Added independent saving functionality for email preferences
+ - Improved user experience by making email settings management more intuitive
+ - Enhanced feedback when saving email preferences
+
## [0.9.8.4] - 2025-03-26
diff --git a/frontend/settings-new.html b/frontend/settings-new.html
index 84371e2..cac1c1c 100644
--- a/frontend/settings-new.html
+++ b/frontend/settings-new.html
@@ -436,26 +436,38 @@
<div class="form-group">
<div class="preference-item">
<div>
- <label>Email Notifications</label>
- <p class="text-muted">Receive email alerts for warranty expirations</p>
+ <label>Expiring Soon Days</label>
+ <p class="text-muted">Number of days before warranty expiration to mark as "Expiring Soon"</p>
</div>
- <label class="toggle-switch">
- <input type="checkbox" id="emailNotifications">
- <span class="toggle-slider"></span>
- </label>
+ <input type="number" id="expiringSoonDays" class="form-control" min="1" max="365" value="30">
</div>
</div>
-
+
+ <button type="button" id="savePreferencesBtn" class="btn btn-primary">Save Preferences</button>
+ </form>
+ </div>
+ </div>
+
+ <!-- Email Settings -->
+ <div class="card">
+ <div class="card-header">
+ <h3>Email Settings</h3>
+ </div>
+ <div class="card-body">
+ <form id="emailPreferencesForm"> <!-- Consider if a separate form/save button is needed, or if settings.js handles this -->
<div class="form-group">
<div class="preference-item">
<div>
- <label>Expiring Soon Days</label>
- <p class="text-muted">Number of days before warranty expiration to mark as "Expiring Soon"</p>
+ <label>Email Notifications</label>
+ <p class="text-muted">Receive email alerts for warranty expirations</p>
</div>
- <input type="number" id="expiringSoonDays" class="form-control" min="1" max="365" value="30">
+ <label class="toggle-switch">
+ <input type="checkbox" id="emailNotifications">
+ <span class="toggle-slider"></span>
+ </label>
</div>
</div>
-
+
<div class="form-group">
<div class="preference-item">
<div>
@@ -469,7 +481,7 @@
</select>
</div>
</div>
-
+
<div class="form-group">
<div class="preference-item">
<div>
@@ -479,7 +491,7 @@
<input type="time" id="notificationTime" class="form-control" value="09:00">
</div>
</div>
-
+
<div class="form-group">
<div class="preference-item">
<div>
@@ -491,8 +503,7 @@
</select>
</div>
</div>
-
- <button type="button" id="savePreferencesBtn" class="btn btn-primary">Save Preferences</button>
+ <button type="button" id="saveEmailSettingsBtn" class="btn btn-primary">Save Email Settings</button>
</form>
</div>
</div>
@@ -785,4 +796,4 @@
<script src="auth.js"></script>
<script src="settings-new.js"></script>
</body>
-</html>
\ No newline at end of file
+</html>
diff --git a/frontend/settings-new.js b/frontend/settings-new.js
index 6bc959a..b1c2a3a 100644
--- a/frontend/settings-new.js
+++ b/frontend/settings-new.js
@@ -9,6 +9,7 @@ const notificationTimeInput = document.getElementById('notificationTime');
const timezoneSelect = document.getElementById('timezone');
const saveProfileBtn = document.getElementById('saveProfileBtn');
const savePreferencesBtn = document.getElementById('savePreferencesBtn');
+const saveEmailSettingsBtn = document.getElementById('saveEmailSettingsBtn');
const changePasswordBtn = document.getElementById('changePasswordBtn');
const passwordChangeForm = document.getElementById('passwordChangeForm');
const savePasswordBtn = document.getElementById('savePasswordBtn');
@@ -777,6 +778,11 @@ function setupEventListeners() {
});
}
+ // Save email settings button
+ if (saveEmailSettingsBtn) {
+ saveEmailSettingsBtn.addEventListener('click', saveEmailSettings);
+ }
+
console.log('Event listeners setup complete');
}
@@ -2837,4 +2843,78 @@ function loadTimezones() {
reject(error);
});
});
+}
+
+/**
+ * Save email settings
+ */
+function saveEmailSettings() {
+ showLoading();
+
+ try {
+ // Get values
+ const emailNotifications = emailNotificationsToggle.checked;
+ const notificationFrequency = notificationFrequencySelect.value;
+ const notificationTime = notificationTimeInput.value;
+ const timezone = timezoneSelect.value;
+
+ // Validate inputs
+ if (!timezone) {
+ showToast('Please select a timezone', 'error');
+ hideLoading();
+ return;
+ }
+
+ // Create preferences object
+ const preferences = {
+ email_notifications: emailNotifications,
+ notification_frequency: notificationFrequency,
+ notification_time: notificationTime,
+ timezone: timezone
+ };
+
+ // Save to API
+ fetch('/api/auth/preferences', {
+ method: 'PUT',
+ headers: {
+ 'Authorization': 'Bearer ' + localStorage.getItem('auth_token'),
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(preferences)
+ })
+ .then(response => {
+ if (!response.ok) {
+ throw new Error('Failed to save email settings');
+ }
+ return response.json();
+ })
+ .then(data => {
+ // Save to localStorage
+ const prefix = getPreferenceKeyPrefix();
+ localStorage.setItem(`${prefix}emailNotifications`, emailNotifications);
+ localStorage.setItem(`${prefix}notificationFrequency`, notificationFrequency);
+ localStorage.setItem(`${prefix}notificationTime`, notificationTime);
+ localStorage.setItem(`${prefix}timezone`, timezone);
+
+ showToast('Email settings saved successfully', 'success');
+ })
+ .catch(error => {
+ console.error('Error saving email settings:', error);
+ showToast('Error saving email settings', 'error');
+
+ // Save to localStorage as fallback
+ const prefix = getPreferenceKeyPrefix();
+ localStorage.setItem(`${prefix}emailNotifications`, emailNotifications);
+ localStorage.setItem(`${prefix}notificationFrequency`, notificationFrequency);
+ localStorage.setItem(`${prefix}notificationTime`, notificationTime);
+ localStorage.setItem(`${prefix}timezone`, timezone);
+ })
+ .finally(() => {
+ hideLoading();
+ });
+ } catch (error) {
+ console.error('Error in saveEmailSettings:', error);
+ showToast('Error saving email settings', 'error');
+ hideLoading();
+ }
}
\ No newline at end of file