Fix self-serve toggle error handling by reverting to current status on failure

This commit is contained in:
Jeppe Bundgaard
2026-03-02 13:14:34 +01:00
parent d37465a0c0
commit 95e9283236
@@ -101,15 +101,15 @@ const modules = computed(() => [
onToggle: async (newValue) => {
const departmentId = getDepartmentId();
if (!departmentId) return;
// Get the current self-serve status, and set it to the opposite of the new value
const currentStatus = selfServeEnabled.value;
try {
await authenticatedRequest(`/departments/self-serve/enabled?id=${departmentId}&enabled=${newValue}`, 'PUT');
selfServeEnabled.value = newValue;
toast.success(newValue ? t('admin.department_modules.self_wash.enabled') : t('admin.department_modules.self_wash.disabled'));
} catch (error) {
console.error("Failed to update self-serve status", error);
// Revert switch value on error
selfServeEnabled.value = !newValue;
selfServeEnabled.value = currentStatus;
toast.error(t('admin.department_modules.self_wash.update_error'));
}
}