Skip to content

Commit

Permalink
Add success message for notification settings update
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisreimann committed Nov 28, 2024
1 parent d9ed601 commit 091e383
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion BTCPayApp.UI/Pages/Settings/NotificationsPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@inherits Fluxor.Blazor.Web.Components.FluxorComponent
@inject IState<NotificationState> NotificationState
@inject IDispatcher Dispatcher
@inject IActionSubscriber ActionSubscriber

<PageTitle>Notifications</PageTitle>

Expand All @@ -30,7 +31,7 @@
}
else if (Model.Notifications is not null)
{
<ValidationEditContext @ref="_validationEditContext" Model="Model" OnValidSubmit="HandleValidSubmit" ErrorMessage="@Error">
<ValidationEditContext @ref="_validationEditContext" Model="Model" OnValidSubmit="HandleValidSubmit" SuccessMessage="@_successMessage" ErrorMessage="@Error">
<DataAnnotationsValidator/>
@foreach (var item in Model.Notifications)
{
Expand Down Expand Up @@ -58,18 +59,36 @@
@code {
[Parameter, EditorRequired]
public string? AppId { get; set; }
private string? _successMessage;

private ValidationEditContext? _validationEditContext;

protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();

ActionSubscriber.SubscribeToAction<NotificationState.UpdatedSettings>(this, action =>
{
if (action.Settings == null || action.Error != null) return;
_successMessage = "Settings successfully updated";
InvokeAsync(StateHasChanged);
});

Dispatcher.Dispatch(new NotificationState.FetchSettings());
}

protected override ValueTask DisposeAsyncCore(bool disposing)
{
base.DisposeAsyncCore(disposing);

ActionSubscriber.UnsubscribeFromAllActions(this);

return ValueTask.CompletedTask;
}

private void HandleValidSubmit()
{
_successMessage = null;
var disabled = Model.Notifications!
.Where(n => !n.Enabled)
.Select(n => n.Identifier)
Expand Down

0 comments on commit 091e383

Please sign in to comment.