From 640e8a7f21c845b8f6d54022abd9a60be0299ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Tr=C3=B8strup?= Date: Thu, 25 Sep 2025 19:36:56 +0200 Subject: [PATCH 1/2] Show pretty alert on login --- Shifty.App/Pages/Login.razor | 58 ++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/Shifty.App/Pages/Login.razor b/Shifty.App/Pages/Login.razor index 44b823d..2cbd7b5 100644 --- a/Shifty.App/Pages/Login.razor +++ b/Shifty.App/Pages/Login.razor @@ -6,22 +6,34 @@ @attribute [AllowAnonymous] - + Please login - + @if (_loggingIn) { - + } else { - if (!_successfulLogin) + if (_showFailureAlert) { - Invalid credentials + An error occurred. Please try + again later. + + } + + if (_showSuccessAlert) + { + A magic link has been sent to + your email address. Please check your inbox to login. + } @code { - bool _loggingIn = false; - bool _successfulLogin = true; - LoginForm _loginForm = new(); + private const string FailureAlertId = "failure"; + private const string SuccessAlertId = "success"; + + readonly LoginForm _loginForm = new(); + + bool _loggingIn; + bool _successfulLogin; + bool _showFailureAlert; + bool _showSuccessAlert; public class LoginForm { - [Required] - [EmailAddress] - public string Email { get; set; } + [Required] [EmailAddress] public string Email { get; set; } } async Task LoginUser() { - _successfulLogin = true; _loggingIn = true; _successfulLogin = await _authenticationService.LoginUser(_loginForm.Email); _loggingIn = false; - if (_successfulLogin) + + _ = _successfulLogin switch { - Navigation.NavigateTo("/"); - } + true => _showSuccessAlert = true, + _ => _showFailureAlert = true + }; } + + private void CloseAlert(string alert) + { + _ = alert switch + { + FailureAlertId => _showFailureAlert = false, + SuccessAlertId => _showSuccessAlert = false, + _ => throw new Exception("roof burning") + }; + } + } \ No newline at end of file From 7049e15a737393c907a81ecd95b3fa05b0165edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Tr=C3=B8strup?= Date: Thu, 25 Sep 2025 20:14:19 +0200 Subject: [PATCH 2/2] Use messagebox instead --- Shifty.App/Pages/Login.razor | 69 +++++++++--------------------------- 1 file changed, 16 insertions(+), 53 deletions(-) diff --git a/Shifty.App/Pages/Login.razor b/Shifty.App/Pages/Login.razor index 2cbd7b5..9aa4920 100644 --- a/Shifty.App/Pages/Login.razor +++ b/Shifty.App/Pages/Login.razor @@ -14,35 +14,12 @@ - @if (_loggingIn) - { - - } - else - { - if (_showFailureAlert) - { - An error occurred. Please try - again later. - - } - - if (_showSuccessAlert) - { - A magic link has been sent to - your email address. Please check your inbox to login. - - } - - - } + @code { - private const string FailureAlertId = "failure"; - private const string SuccessAlertId = "success"; + [Inject] private IDialogService DialogService { get; set; } readonly LoginForm _loginForm = new(); - bool _loggingIn; - bool _successfulLogin; - bool _showFailureAlert; - bool _showSuccessAlert; - public class LoginForm { [Required] [EmailAddress] public string Email { get; set; } @@ -75,24 +46,16 @@ async Task LoginUser() { - _loggingIn = true; - _successfulLogin = await _authenticationService.LoginUser(_loginForm.Email); - _loggingIn = false; - - _ = _successfulLogin switch - { - true => _showSuccessAlert = true, - _ => _showFailureAlert = true - }; - } - - private void CloseAlert(string alert) - { - _ = alert switch + _ = await _authenticationService.LoginUser(_loginForm.Email) switch { - FailureAlertId => _showFailureAlert = false, - SuccessAlertId => _showSuccessAlert = false, - _ => throw new Exception("roof burning") + true => await DialogService.ShowMessageBox( + "Email sent", + "A magic link has been sent to your email address. Please check your inbox to login." + ), + _ => await DialogService.ShowMessageBox( + "Error", + "An error occured. Please wait a few minutes and try again." + ) }; }