Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
neozhu committed Dec 13, 2024
1 parent 9991c89 commit 070e155
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<DialogContent>
<MudForm @bind-IsValid="@success">
<MudTextField T="string" Label="@L["New email address"]" Placeholder="Enter your new email address" @bind-Value="@newEmailAddress" Required="true" RequiredError="@L["Email is required!"]"
Validation="@(new EmailAddressAttribute() {ErrorMessage = L["The email address is invalid"]})"></MudTextField>
Validation="@(new EmailAddressAttribute() {ErrorMessage = L["The email address is invalid"]})"></MudTextField>
</MudForm>
</DialogContent>
<DialogActions>
Expand Down Expand Up @@ -56,7 +56,7 @@

<MudForm @bind-IsValid="@deleteSuccess">
<MudTextField T="string" Label="@L["User name"]" Placeholder="Enter your user name" @bind-Value="@confirmUsername" Required="true" RequiredError="@L["User name is required!"]"
Validation="@(new Func<string, string?>(userNameMatch))"></MudTextField>
Validation="@(new Func<string, string?>(userNameMatch))"></MudTextField>
</MudForm>
</DialogContent>
<DialogActions>
Expand All @@ -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 =>
{
Expand All @@ -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 =>
{
Expand Down
15 changes: 9 additions & 6 deletions src/CleanAspire.ClientApp/Pages/Account/SignUp.razor
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<DataAnnotationsValidator />
<div class="d-flex flex-column gap-2">
<MultiTenantAutocomplete T="TenantDto" For="(()=>model.Tenant)"
Placeholder="@L["Organization"]"
Label="@L["Select Organization"]"
Required="true"
RequiredError="@L["Organization selection is required"]"
@bind-Value="@model.Tenant">
Placeholder="@L["Organization"]"
Label="@L["Select Organization"]"
Required="true"
RequiredError="@L["Organization selection is required"]"
@bind-Value="@model.Tenant">

</MultiTenantAutocomplete>
<MudTextField @bind-Value="model.Email" For="@(() => model.Email)" Label="@L["Email"]" Placeholder="@L["Email"]" Required="true" RequiredError="@L["Email is required"]"></MudTextField>
Expand All @@ -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 =>
{
Expand Down
30 changes: 0 additions & 30 deletions src/CleanAspire.ClientApp/Services/ApiClientService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,6 @@ public async Task<OneOf<TResponse, ApiClientValidationError, ApiClientError>> Ex
return new ApiClientError(ex.Message, ex);
}
}

public async Task<OneOf<bool, ApiClientValidationError, ApiClientError>> ExecuteAsync(Func<Task> 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
Expand Down
4 changes: 2 additions & 2 deletions src/CleanAspire.ClientApp/Services/OfflineModeState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool?>(OfflineModeKey);
Enabled = storedValue ?? false;
Enabled = storedValue ?? true;
}
// Update the OfflineModeEnabled and persist it to localStorage
public async Task SetOfflineModeAsync(bool isEnabled)
Expand Down

0 comments on commit 070e155

Please sign in to comment.