diff --git a/src/Lumina.Presentation.Web/Views/Admin/ManagePermissions.cshtml b/src/Lumina.Presentation.Web/Views/Admin/ManagePermissions.cshtml index a8624e26..eed906a3 100644 --- a/src/Lumina.Presentation.Web/Views/Admin/ManagePermissions.cshtml +++ b/src/Lumina.Presentation.Web/Views/Admin/ManagePermissions.cshtml @@ -121,8 +121,8 @@ .map(checkbox => checkbox.value) }; - const data = await callApiPutAsync('@_urlService.GetAbsoluteUrl("UpdateUserAuthorization", "Admin")', formData); - if (data) + const result = await callApiPutAsync('@_urlService.GetAbsoluteUrl("UpdateUserAuthorization", "Admin")', formData); + if (result.success) notificationService.show('@_localizer["UserAuthorizationUpdated"]', NotificationType.SUCCESS); } diff --git a/src/Lumina.Presentation.Web/Views/Admin/ManageRoles.cshtml b/src/Lumina.Presentation.Web/Views/Admin/ManageRoles.cshtml index 71ee543a..c82b385c 100644 --- a/src/Lumina.Presentation.Web/Views/Admin/ManageRoles.cshtml +++ b/src/Lumina.Presentation.Web/Views/Admin/ManageRoles.cshtml @@ -103,10 +103,10 @@ const isRoleSelected = formData.roleId !== ''; - const data = isRoleSelected ? + const result = isRoleSelected ? await callApiPutAsync('@_urlService.GetAbsoluteUrl("UpdateRole", "Admin")', formData) : - await callApiPostAsync('@_urlService.GetAbsoluteUrl("CreateRole", "Admin")', formData); - if (data) { + { success: (await callApiPostAsync('@_urlService.GetAbsoluteUrl("CreateRole", "Admin")', formData)) !== undefined }; + if (result.success) { await fetchRolesAsync(); notificationService.show(isRoleSelected ? '@_localizer["RoleUpdated"]' : '@_localizer["RoleCreated"]', NotificationType.SUCCESS); } diff --git a/src/Lumina.Presentation.Web/wwwroot/js/site.js b/src/Lumina.Presentation.Web/wwwroot/js/site.js index fd182997..ae4d902a 100644 --- a/src/Lumina.Presentation.Web/wwwroot/js/site.js +++ b/src/Lumina.Presentation.Web/wwwroot/js/site.js @@ -109,7 +109,7 @@ async function callApiPostAsync(url, data, options = {}) { * @param {Object} [options] - Additional options for the request. * @param {boolean} [options.useAntiForgery=true] - Whether to include anti-forgery token. * @param {Object} [options.headers] - Additional headers to include. - * @returns {Promise} The response data if successful, undefined otherwise. + * @returns {Promise<{success: boolean, data: any}>} The result of the request, containing the success flag and the response data. */ async function callApiPutAsync(url, data, options = {}) { const defaultOptions = { @@ -146,7 +146,7 @@ async function callApiPutAsync(url, data, options = {}) { if (jsonResponse.success) { if (jsonResponse.message) notificationService.show(jsonResponse.message, NotificationType.SUCCESS); - return jsonResponse.data; + return { success: jsonResponse.success === true, data: jsonResponse.data }; } else notificationService.show(jsonResponse.errorMessage, NotificationType.ERROR); @@ -155,6 +155,7 @@ async function callApiPutAsync(url, data, options = {}) { console.error('Error:', error); notificationService.show(error, NotificationType.ERROR); } + return { success: false }; } /**