Refactor error modal into its own partial (#785)

* Refactor error modal into its own partial

* Fix unresolved error string in TwoFactorPartial

* Use tuple model instead of ViewData for error title and message

* Apply suggestions from code review
This commit is contained in:
koko 2023-06-08 00:01:59 -04:00 committed by GitHub
parent af6fdb457b
commit 77e46a0721
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 94 deletions

View file

@ -12,12 +12,7 @@
@if (!string.IsNullOrWhiteSpace(Model.Error)) @if (!string.IsNullOrWhiteSpace(Model.Error))
{ {
<div class="ui negative message"> @await Html.PartialAsync("Partials/ErrorModalPartial", (Model.Translate(GeneralStrings.Error), Model.Error), ViewData)
<div class="header">
@Model.Translate(GeneralStrings.Error)
</div>
<p style="white-space: pre-line">@Model.Error</p>
</div>
} }
<form class="ui form" onsubmit="return onSubmit(this)" method="post"> <form class="ui form" onsubmit="return onSubmit(this)" method="post">

View file

@ -31,12 +31,7 @@
<form class="ui form" onsubmit="return onSubmit(this)" method="post"> <form class="ui form" onsubmit="return onSubmit(this)" method="post">
@if (!string.IsNullOrWhiteSpace(Model.Error)) @if (!string.IsNullOrWhiteSpace(Model.Error))
{ {
<div class="ui negative message"> @await Html.PartialAsync("Partials/ErrorModalPartial", (Model.Translate(GeneralStrings.Error), Model.Error), ViewData)
<div class="header">
@Model.Translate(GeneralStrings.Error)
</div>
<p style="white-space: pre-line">@Model.Error</p>
</div>
} }
@Html.AntiForgeryToken() @Html.AntiForgeryToken()
<input type="hidden" id="redirect" name="redirect"> <input type="hidden" id="redirect" name="redirect">

View file

@ -1,5 +1,4 @@
@page "/passwordReset" @page "/passwordReset"
@using LBPUnion.ProjectLighthouse.Configuration
@using LBPUnion.ProjectLighthouse.Localization.StringLists @using LBPUnion.ProjectLighthouse.Localization.StringLists
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Login.PasswordResetPage @model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Login.PasswordResetPage
@ -27,16 +26,11 @@
@if (!string.IsNullOrWhiteSpace(Model.Error)) @if (!string.IsNullOrWhiteSpace(Model.Error))
{ {
<div class="ui negative message"> @await Html.PartialAsync("Partials/ErrorModalPartial", (Model.Translate(GeneralStrings.Error), Model.Error), ViewData)
<div class="header">
@Model.Translate(GeneralStrings.Error)
</div>
<p>@Model.Error</p>
</div>
} }
<div class="ui middle aligned center aligned grid"> <div class="ui middle aligned center aligned grid">
<form onsubmit="return onSubmit(this)" method="post"> <form onsubmit="return onSubmit(this)" method="post">
@Html.AntiForgeryToken() @Html.AntiForgeryToken()
<div class="column"> <div class="column">
@ -50,7 +44,7 @@
<div class="ui field"> <div class="ui field">
<label>Password</label> <label>Password</label>
<div class="ui left icon input"> <div class="ui left icon input">
<input type="password" id="password" placeholder="Password" > <input type="password" id="password" placeholder="Password">
<input type="hidden" name="password" id="password-submit"> <input type="hidden" name="password" id="password-submit">
<i class="lock icon"></i> <i class="lock icon"></i>
</div> </div>
@ -68,5 +62,5 @@
<div class="ui divider hidden"></div> <div class="ui divider hidden"></div>
</div> </div>
</div> </div>
</form> </form>
</div> </div>

View file

@ -9,12 +9,7 @@
@if (!string.IsNullOrWhiteSpace(Model.Error)) @if (!string.IsNullOrWhiteSpace(Model.Error))
{ {
<div class="ui negative message"> @await Html.PartialAsync("Partials/ErrorModalPartial", (Model.Translate(GeneralStrings.Error), Model.Error), ViewData)
<div class="header">
@Model.Translate(GeneralStrings.Error)
</div>
<p style="white-space: pre-line">@Model.Error</p>
</div>
} }
@if (!string.IsNullOrWhiteSpace(Model.Status)) @if (!string.IsNullOrWhiteSpace(Model.Status))

View file

@ -25,17 +25,14 @@
@if (!string.IsNullOrWhiteSpace(Model.Error)) @if (!string.IsNullOrWhiteSpace(Model.Error))
{ {
<div class="ui negative message"> @await Html.PartialAsync("Partials/ErrorModalPartial", (Model.Translate(GeneralStrings.Error), Model.Error), ViewData)
<div class="header">
@Model.Translate(GeneralStrings.Error)
</div>
<p>@Model.Error</p>
</div>
} }
@if (Model.Username == null) @if (Model.Username == null)
{ {
<p><b>@Model.Translate(RegisterStrings.UsernameNotice)</b></p> <p>
<b>@Model.Translate(RegisterStrings.UsernameNotice)</b>
</p>
} }
<form class="ui form" onsubmit="return onSubmit(this)" method="post"> <form class="ui form" onsubmit="return onSubmit(this)" method="post">

View file

@ -12,12 +12,7 @@
@if (!string.IsNullOrWhiteSpace(Model.Error)) @if (!string.IsNullOrWhiteSpace(Model.Error))
{ {
<div class="ui negative message"> @await Html.PartialAsync("Partials/ErrorModalPartial", (Model.Translate(GeneralStrings.Error), Model.Error), ViewData)
<div class="header">
@Model.Translate(GeneralStrings.Error)
</div>
<p style="white-space: pre-line">@Model.Error</p>
</div>
} }
<input type="hidden" name="type" value="@((int)Model.Type)"/> <input type="hidden" name="type" value="@((int)Model.Type)"/>

View file

@ -0,0 +1,8 @@
@model (string Title, string Message)
<div class="ui negative message">
<div class="header">
@Model.Title
</div>
<p style="white-space: pre-line">@Model.Message</p>
</div>

View file

@ -11,12 +11,7 @@
<div class="digits" id="2fa"> <div class="digits" id="2fa">
@if (!string.IsNullOrWhiteSpace(error)) @if (!string.IsNullOrWhiteSpace(error))
{ {
<div class="ui negative message"> @await Html.PartialAsync("Partials/ErrorModalPartial", ((string)Model.Translate(GeneralStrings.Error), error), ViewData)
<div class="header">
@Model.Translate(GeneralStrings.Error)
</div>
<p style="white-space: pre-line">@Model.Error</p>
</div>
} }
<input type="text" pattern="\d*" maxlength="1" id="digit1"/> <input type="text" pattern="\d*" maxlength="1" id="digit1"/>
<input type="text" pattern="\d*" maxlength="1" id="digit2"/> <input type="text" pattern="\d*" maxlength="1" id="digit2"/>
@ -45,16 +40,16 @@
@if (allowBackupCodes) @if (allowBackupCodes)
{ {
<text> <text>
document.getElementById("backup-link").addEventListener("click", function (){ document.getElementById("backup-link").addEventListener("click", function (){
let backupInput = document.getElementById("backup"); let backupInput = document.getElementById("backup");
if (backupInput.style.display === "none"){ if (backupInput.style.display === "none"){
backupInput.style.display = ""; backupInput.style.display = "";
} else { } else {
backupInput.style.display = "none"; backupInput.style.display = "none";
} }
}); });
</text> </text>
} }
document.querySelector(".digits").addEventListener("keydown", function(event){ document.querySelector(".digits").addEventListener("keydown", function(event){