From 070e15593ac018f365c88898f7fe94323c60f41f Mon Sep 17 00:00:00 2001 From: "hualin.zhu" Date: Fri, 13 Dec 2024 20:46:02 +0800 Subject: [PATCH] commit --- .../Account/Profile/AccountSetting.razor | 20 +++++++++---- .../Pages/Account/SignUp.razor | 15 ++++++---- .../Services/ApiClientService.cs | 30 ------------------- .../Services/OfflineModeState.cs | 4 +-- 4 files changed, 25 insertions(+), 44 deletions(-) diff --git a/src/CleanAspire.ClientApp/Pages/Account/Profile/AccountSetting.razor b/src/CleanAspire.ClientApp/Pages/Account/Profile/AccountSetting.razor index e31d2de..10d6a23 100644 --- a/src/CleanAspire.ClientApp/Pages/Account/Profile/AccountSetting.razor +++ b/src/CleanAspire.ClientApp/Pages/Account/Profile/AccountSetting.razor @@ -27,7 +27,7 @@ + Validation="@(new EmailAddressAttribute() {ErrorMessage = L["The email address is invalid"]})"> @@ -56,7 +56,7 @@ + Validation="@(new Func(userNameMatch))"> @@ -78,10 +78,14 @@ { if (success) { - var result = await ApiClientService.ExecuteAsync(() => ApiClient.Account.UpdateEmail.PostAsync(new UpdateEmailRequest() + var result = await ApiClientService.ExecuteAsync(async () => + { + await ApiClient.Account.UpdateEmail.PostAsync(new UpdateEmailRequest() { NewEmail = newEmailAddress - })); + }); + return true; + }); result.Switch( ok => { @@ -102,10 +106,14 @@ { if (deleteSuccess) { - var result = await ApiClientService.ExecuteAsync(() => ApiClient.Account.DeleteOwnerAccount.DeleteAsync(new DeleteUserRequest() + var result = await ApiClientService.ExecuteAsync( async () => + { + await ApiClient.Account.DeleteOwnerAccount.DeleteAsync(new DeleteUserRequest() { Username = confirmUsername - })); + }); + return true; + }); result.Switch( ok => { diff --git a/src/CleanAspire.ClientApp/Pages/Account/SignUp.razor b/src/CleanAspire.ClientApp/Pages/Account/SignUp.razor index 0ee1920..075a045 100644 --- a/src/CleanAspire.ClientApp/Pages/Account/SignUp.razor +++ b/src/CleanAspire.ClientApp/Pages/Account/SignUp.razor @@ -17,11 +17,11 @@
+ Placeholder="@L["Organization"]" + Label="@L["Select Organization"]" + Required="true" + RequiredError="@L["Organization selection is required"]" + @bind-Value="@model.Tenant"> @@ -46,7 +46,10 @@ private async Task OnValidSubmit(EditContext context) { waiting = true; - var result = await ApiClientService.ExecuteAsync(() => ApiClient.Account.Signup.PostAsync(new SignupRequest() { Email = model.Email, Password = model.Password, LanguageCode = model.LanguageCode, Nickname = model.Nickname, Provider = model.Provider, TimeZoneId = model.TimeZoneId, TenantId = model.Tenant?.Id })); + var result = await ApiClientService.ExecuteAsync(async () =>{ + await ApiClient.Account.Signup.PostAsync(new SignupRequest() { Email = model.Email, Password = model.Password, LanguageCode = model.LanguageCode, Nickname = model.Nickname, Provider = model.Provider, TimeZoneId = model.TimeZoneId, TenantId = model.Tenant?.Id }); + return true; + }); result.Switch( ok => { diff --git a/src/CleanAspire.ClientApp/Services/ApiClientService.cs b/src/CleanAspire.ClientApp/Services/ApiClientService.cs index 1e47734..e2c9d1e 100644 --- a/src/CleanAspire.ClientApp/Services/ApiClientService.cs +++ b/src/CleanAspire.ClientApp/Services/ApiClientService.cs @@ -45,36 +45,6 @@ public async Task> Ex return new ApiClientError(ex.Message, ex); } } - - public async Task> ExecuteAsync(Func apiCall) - { - try - { - await apiCall(); - return true; - } - catch (HttpValidationProblemDetails ex) - { - - _logger.LogError(ex, ex.Message); - return new ApiClientValidationError(ex.Detail, ex); - } - catch (ProblemDetails ex) - { - _logger.LogError(ex, ex.Message); - return new ApiClientError(ex.Detail, ex); - } - catch (ApiException ex) - { - _logger.LogError(ex, ex.Message); - return new ApiClientError(ex.Message, ex); - } - catch (Exception ex) - { - _logger.LogError(ex, ex.Message); - return new ApiClientError(ex.Message, ex); - } - } } public class ApiClientError diff --git a/src/CleanAspire.ClientApp/Services/OfflineModeState.cs b/src/CleanAspire.ClientApp/Services/OfflineModeState.cs index 2d75f84..8842768 100644 --- a/src/CleanAspire.ClientApp/Services/OfflineModeState.cs +++ b/src/CleanAspire.ClientApp/Services/OfflineModeState.cs @@ -17,13 +17,13 @@ public OfflineModeState(IStorageService storageService) { _storageService = storageService; // Initialize the OfflineModeEnabled with a default value - Enabled = false; + Enabled = true; } // Initialize the offline mode setting from localStorage public async Task InitializeAsync() { var storedValue = await _storageService.GetItemAsync(OfflineModeKey); - Enabled = storedValue ?? false; + Enabled = storedValue ?? true; } // Update the OfflineModeEnabled and persist it to localStorage public async Task SetOfflineModeAsync(bool isEnabled)