Skip to content

Commit

Permalink
Added colors to simple alert
Browse files Browse the repository at this point in the history
  • Loading branch information
goodtocode committed Jul 8, 2023
1 parent 96dd10d commit 4eb6b97
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/Subjects/Presentation.Shared.Rcl/Alert/Alert.razor
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@

var classes = new List<string> { "alert", "alert-dismissable", "mt-4", "container" };

var alertTypeClass = new Dictionary<AlertType, string>();
alertTypeClass[AlertType.Success] = "alert-success";
alertTypeClass[AlertType.Error] = "alert-danger";
alertTypeClass[AlertType.Info] = "alert-info";
alertTypeClass[AlertType.Warning] = "alert-warning";
var alertTypeClass = new Dictionary<AlertTypes, string>();
alertTypeClass[AlertTypes.Success] = "alert-success";
alertTypeClass[AlertTypes.Error] = "alert-danger";
alertTypeClass[AlertTypes.Info] = "alert-info";
alertTypeClass[AlertTypes.Warning] = "alert-warning";

classes.Add(alertTypeClass[alert.Type]);

Expand Down
10 changes: 1 addition & 9 deletions src/Subjects/Presentation.Shared.Rcl/Alert/AlertModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@ namespace Goodtocode.Subjects.Rcl;
public class AlertModel
{
public string Id { get; set; }

Check warning on line 5 in src/Subjects/Presentation.Shared.Rcl/Alert/AlertModel.cs

View workflow job for this annotation

GitHub Actions / Build, Test and Deploy .NET (7.0.x)

Non-nullable property 'Id' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public AlertType Type { get; set; }
public AlertTypes Type { get; set; }
public string Message { get; set; }

Check warning on line 7 in src/Subjects/Presentation.Shared.Rcl/Alert/AlertModel.cs

View workflow job for this annotation

GitHub Actions / Build, Test and Deploy .NET (7.0.x)

Non-nullable property 'Message' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public bool AutoClose { get; set; }
public bool KeepAfterRouteChange { get; set; }
public bool Fade { get; set; }
}

public enum AlertType
{
Success,
Error,
Info,
Warning
}
8 changes: 4 additions & 4 deletions src/Subjects/Presentation.Shared.Rcl/Alert/AlertService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Success(string message, bool keepAfterRouteChange = false, bool auto
{
this.Alert(new AlertModel
{
Type = AlertType.Success,
Type = AlertTypes.Success,
Message = message,
KeepAfterRouteChange = keepAfterRouteChange,
AutoClose = autoClose
Expand All @@ -31,7 +31,7 @@ public void Error(string message, bool keepAfterRouteChange = false, bool autoCl
{
this.Alert(new AlertModel
{
Type = AlertType.Error,
Type = AlertTypes.Error,
Message = message,
KeepAfterRouteChange = keepAfterRouteChange,
AutoClose = autoClose
Expand All @@ -42,7 +42,7 @@ public void Info(string message, bool keepAfterRouteChange = false, bool autoClo
{
this.Alert(new AlertModel
{
Type = AlertType.Info,
Type = AlertTypes.Info,
Message = message,
KeepAfterRouteChange = keepAfterRouteChange,
AutoClose = autoClose
Expand All @@ -53,7 +53,7 @@ public void Warn(string message, bool keepAfterRouteChange = false, bool autoClo
{
this.Alert(new AlertModel
{
Type = AlertType.Warning,
Type = AlertTypes.Warning,
Message = message,
KeepAfterRouteChange = keepAfterRouteChange,
AutoClose = autoClose
Expand Down
9 changes: 9 additions & 0 deletions src/Subjects/Presentation.Shared.Rcl/Alert/AlertTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Goodtocode.Subjects.Rcl;

public enum AlertTypes
{
Success,
Error,
Info,
Warning
}
21 changes: 20 additions & 1 deletion src/Subjects/Presentation.Shared.Rcl/Alert/SimpleAlert.razor
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
@using Goodtocode.Common.Extensions;

<div hidden="@string.IsNullOrEmpty(Message)" class="alert alert-danger m-4" role="alert">@Message</div>
<div hidden="@string.IsNullOrEmpty(Message)" class="alert m-4 @alertClass" role="alert">@Message</div>

@code {
[Parameter]
public string Message { get; set; }

Check warning on line 7 in src/Subjects/Presentation.Shared.Rcl/Alert/SimpleAlert.razor

View workflow job for this annotation

GitHub Actions / Build, Test and Deploy .NET (7.0.x)

Non-nullable property 'Message' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
[Parameter]
public AlertTypes AlertType { get; set; } = AlertTypes.Error;

private string alertClass = "alert-danger";

protected override async Task OnParametersSetAsync()

Check warning on line 13 in src/Subjects/Presentation.Shared.Rcl/Alert/SimpleAlert.razor

View workflow job for this annotation

GitHub Actions / Build, Test and Deploy .NET (7.0.x)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
switch(AlertType)
{
case AlertTypes.Error:
alertClass = "alert-danger";
break;
case AlertTypes.Warning:
alertClass = "alert-warning";
break;
case AlertTypes.Info:
alertClass = "alert-info";
break;
case AlertTypes.Success:
alertClass = "alert-success";
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@using Goodtocode.Subjects.Domain;
@using System.ComponentModel.DataAnnotations;
@using Goodtocode.Subjects.Rcl.Alert
@using Goodtocode.Subjects.Rcl;

@inject BusinessService Service

Expand All @@ -26,12 +27,13 @@
</div>
<button type="submit" class="btn btn-primary" @onclick="CreateBusineses">Create</button>
<ValidationSummary class="mt-3" />
<SimpleAlert Message="@alertMessage" />
<SimpleAlert Message="@alertMessage" AlertType="@alertType" />
</EditForm>

@code {
private BusinessModel business = new BusinessModel();
private string alertMessage = string.Empty;
private AlertTypes alertType = AlertTypes.Error;
private CancellationTokenSource? cts;
private async Task CreateBusineses()
{
Expand All @@ -46,6 +48,7 @@
alertMessage = string.Empty;
await Service.CreateBusinessAsync(business);
alertMessage = $"{business.BusinessName} created";
alertType = AlertTypes.Success;
}
catch (TaskCanceledException)
{
Expand Down

0 comments on commit 4eb6b97

Please sign in to comment.