Fix self-serve toggle error handling by reverting to current status on failure
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user