Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin) : change the mulitple radio buttons to a partial view #255

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions DVSAdmin/Controllers/RegisterManagementController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using DVSAdmin.Models.RegManagement;
using DVSRegister.Extensions;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;

namespace DVSAdmin.Controllers
{
Expand Down Expand Up @@ -167,29 +166,54 @@ public async Task<IActionResult> DownloadCertificate(string key, string filename
public async Task<IActionResult> ReasonForRemoval(int providerId)
{
ProviderProfileDto providerDto = await regManagementService.GetProviderDetails(providerId);
return View(providerDto);
var model = new MultipleRadiosViewModel
{
ProviderId = providerDto.Id,
RemovalReasons = Enum.GetValues(typeof(RemovalReasonsEnum))
.Cast<RemovalReasonsEnum>()
.Skip(1)
.Select(reason => new RemovalReasonViewModel
{
Id = (int)reason,
Description = reason.GetDescription(),
RequiresAdditionalInfo = reason.RequiresAdditionalInfo()
}).ToList()
};
return View(model);
}

[HttpPost("proceed-with-removal")]
public async Task<IActionResult> ProceedWithRemoval(int providerId, RemovalReasonsEnum? removalReason)
public async Task<IActionResult> ProceedWithRemoval(MultipleRadiosViewModel model)
{
ProviderProfileDto providerProfileDto = await regManagementService.GetProviderDetails(providerId);
ProviderProfileDto providerProfileDto = await regManagementService.GetProviderDetails(model.ProviderId);
var userEmails = await userService.GetUserEmailsExcludingLoggedIn(userEmail, userprofile);
if (removalReason == null)

if (model.SelectedRemovalReason == null)
{
ModelState.AddModelError("RemovalReason", "Select a reason for removal");
ModelState.AddModelError("SelectedRemovalReason", "Select a reason for removal");
}

if (!ModelState.IsValid)
{
return View("ReasonForRemoval", providerProfileDto);
model.RemovalReasons = Enum.GetValues(typeof(RemovalReasonsEnum))
.Cast<RemovalReasonsEnum>()
.Skip(1)
.Select(reason => new RemovalReasonViewModel
{
Id = (int)reason,
Description = reason.GetDescription(),
RequiresAdditionalInfo = reason.RequiresAdditionalInfo()
}).ToList();

return View("ReasonForRemoval", model);
}

providerProfileDto.DSITUserEmails = userEmails;
providerProfileDto.RemovalReason = removalReason.Value;
providerProfileDto.RemovalReason = model.SelectedRemovalReason.Value;

return View("ProceedRemoval", providerProfileDto);
}



[HttpPost("publish-removal-reason")]
public async Task<IActionResult> RequestProviderRemoval(ProviderProfileDto providerDetailsViewModel, RemovalReasonsEnum removalReason)
{
Expand Down
18 changes: 18 additions & 0 deletions DVSAdmin/Models/RegManagement/MultipleRadioViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using DVSAdmin.CommonUtility.Models.Enums;

namespace DVSAdmin.Models.RegManagement
{
public class MultipleRadiosViewModel
{
public int ProviderId { get; set; }
public RemovalReasonsEnum? SelectedRemovalReason { get; set; }
public List<RemovalReasonViewModel>? RemovalReasons { get; set; }
}

public class RemovalReasonViewModel
{
public int Id { get; set; }
public string Description { get; set; }
public bool RequiresAdditionalInfo { get; set; }
}
}
57 changes: 57 additions & 0 deletions DVSAdmin/Views/PartialViews/_MultipleRadioButtonGroupView.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@model DVSAdmin.Models.RegManagement.MultipleRadiosViewModel

<div class="govuk-form-group @(ViewData.ModelState["SelectedRemovalReason"] != null && ViewData.ModelState["SelectedRemovalReason"].Errors.Count > 0 ? "govuk-form-group--error" : "")">
<fieldset class="govuk-fieldset" aria-describedby="removal-reason-description @(ViewData.ModelState["SelectedRemovalReason"] != null && ViewData.ModelState["SelectedRemovalReason"].Errors.Count > 0 ? "removal-reason-error" : "")">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--s">Select reason for removal</legend>
<div class="govuk-hint" id="removal-reason-description">You should proceed with removal if any of the reasons below apply.</div>

@if (ViewData.ModelState["SelectedRemovalReason"] != null && ViewData.ModelState["SelectedRemovalReason"].Errors.Count > 0)
{
<span id="removal-reason-error" class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span>
@ViewData.ModelState["SelectedRemovalReason"].Errors[0].ErrorMessage
</span>
}

<div class="govuk-radios" data-module="govuk-radios">
@foreach (var reason in Model.RemovalReasons)
{
var radioId = "radio" + reason.Id;
var ariaControls = "conditional-reason" + reason.Id;
var furtherExplanationId = "further-explanation" + reason.Id;
var furtherExplanationErrorId = "further-explanation-error" + reason.Id;

if (!reason.RequiresAdditionalInfo)
{
<div class="govuk-radios__item">
@Html.RadioButtonFor(m => m.SelectedRemovalReason, reason.Id, new { @id = radioId, @class = "govuk-radios__input" })
<label class="govuk-label govuk-radios__label" for="@radioId">@reason.Description</label>
</div>
}
else
{
<div class="govuk-radios__item">
@Html.RadioButtonFor(m => m.SelectedRemovalReason, reason.Id, new { @id = radioId, @class = "govuk-radios__input", @data_aria_controls = ariaControls })
<label class="govuk-label govuk-radios__label" for="@radioId">@reason.Description</label>
</div>
<div class="govuk-radios__conditional govuk-radios__conditional--hidden" id="@ariaControls">
<div class="govuk-form-group @(ViewData.ModelState["FurtherExplanation"]?.Errors.Count > 0 ? "govuk-form-group--error" : "")">
<label class="govuk-label" for="@furtherExplanationId">
Give further details on the reason selected:
</label>
@if (ViewData.ModelState["FurtherExplanation"]?.Errors.Count > 0)
{
<p id="@furtherExplanationErrorId" class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span> @ViewData.ModelState["FurtherExplanation"].Errors[0].ErrorMessage
</p>
}
<textarea class="govuk-textarea @(ViewData.ModelState["FurtherExplanation"]?.Errors.Count > 0 ? "govuk-input--error" : "")" rows="5" id="@furtherExplanationId" name="FurtherExplanation" aria-describedby="@furtherExplanationErrorId"></textarea>
</div>
</div>
}
}
</div>
</fieldset>
</div>


6 changes: 1 addition & 5 deletions DVSAdmin/Views/RegisterManagement/ProceedRemoval.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,7 @@
data-module="govuk-button">
Request provider removal
</button>

<a class="govuk-button govuk-button--secondary"
href="[email protected]">
Cancel
</a>
@Html.ActionLink("Cancel", "ReasonForRemoval", "RegisterManagement", new { providerId = Model.Id }, new { @class = "govuk-button govuk-button--secondary" })
</div>
}
</div>
Expand Down
91 changes: 10 additions & 81 deletions DVSAdmin/Views/RegisterManagement/ReasonForRemoval.cshtml
Original file line number Diff line number Diff line change
@@ -1,109 +1,38 @@
@using DVSAdmin.BusinessLogic.Models;
@using DVSAdmin.CommonUtility.Models.Enums;
@using DVSAdmin.Extensions
@using System.Diagnostics
@using System.Reflection
@using System.Reflection
@using System.ComponentModel
@model ProviderProfileDto;
@model DVSAdmin.Models.RegManagement.MultipleRadiosViewModel

@{
ViewData["Title"] = "Removal Reason";
Layout = "~/Views/Shared/_LayoutLoggedIn.cshtml";
}

<div class="govuk-width-container">
@Html.ActionLink("Back", "ProviderDetails", "RegisterManagement", new { providerId = Model.Id }, new { @class = "govuk-back-link" })
@Html.ActionLink("Back", "ProviderDetails", "RegisterManagement", new { providerId = Model.ProviderId }, new { @class = "govuk-back-link" })
<main id="main-content" class="govuk-main-wrapper" role="main">
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl">Select a reason for removing this provider</h1>
@using (Html.BeginForm("ProceedWithRemoval", "RegisterManagement", FormMethod.Post))
{
<input type="hidden" name="providerId" value="@Model.Id" />
<input type="hidden" name="ProviderId" value="@Model.ProviderId" />

@if (ViewData.ModelState["RemovalReason"] != null && ViewData.ModelState["RemovalReason"].Errors.Count > 0)
@if (ViewData.ModelState["SelectedRemovalReason"] != null && ViewData.ModelState["SelectedRemovalReason"].Errors.Count > 0)
{
<div class="govuk-error-summary" data-module="govuk-error-summary">
<div role="alert">
<h2 class="govuk-error-summary__title">
There is a problem
</h2>
<div class="govuk-error-summary__body">
<ul class="govuk-list govuk-error-summary__list">
<li>
<a href="#">@ViewData.ModelState["RemovalReason"].Errors[0].ErrorMessage</a>
</li>
</ul>
</div>
</div>
</div>
@await Html.PartialAsync("~/Views/PartialViews/_ErrorSummaryView.cshtml", Model)
}

<div class="govuk-form-group @(ViewData.ModelState["RemovalReason"] != null && ViewData.ModelState["RemovalReason"].Errors.Count > 0 ? "govuk-form-group--error" : "")">
<fieldset class="govuk-fieldset" aria-describedby="removal-reason-description">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--s">Select reason for removal</legend>
<div class="govuk-hint" id="removal-reason-description">You should proceed with removal if any of the reasons below apply.</div>
@if (ViewData.ModelState["RemovalReason"] != null && ViewData.ModelState["RemovalReason"].Errors.Count > 0)
{
<span class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span>
@ViewData.ModelState["RemovalReason"].Errors[0].ErrorMessage
</span>
}
@await Html.PartialAsync("~/Views/PartialViews/_MultipleRadioButtonGroupView.cshtml", Model)

<div class="govuk-radios" data-module="govuk-radios">
@{
var reasons = Enum.GetValues(typeof(RemovalReasonsEnum)).Cast<RemovalReasonsEnum>().ToList();
for (int i = 1; i < reasons.Count; i++)
{
var reason = reasons[i];
var radioId = "radio" + +(int)reason;
var ariaControls = "conditional-reason" + +(int)reason;
var furtherExpalanationId = "further-explanation" + +(int)reason;
var furtherExpalanationErrorId = "further-explanation-error" + +(int)reason;
var description = reason.GetDescription();

if (!reason.RequiresAdditionalInfo())
{
<div class="govuk-radios__item">
@Html.RadioButton("RemovalReason", (int)reason, false, new { @id = radioId, @class = "govuk-radios__input" })
<label class="govuk-label govuk-radios__label" for="@radioId">@description</label>
</div>
}
else
{
<div class="govuk-radios__item">
@Html.RadioButton("RemovalReason", (int)reason, false, new { @id = radioId, @class = "govuk-radios__input", @data_aria_controls = ariaControls })
<label class="govuk-label govuk-radios__label" for="@radioId">@description</label>
</div>
<div class="govuk-radios__conditional govuk-radios__conditional--hidden" id="@ariaControls">
<div class="govuk-form-group @(ViewData.ModelState["FurtherExplanation"]?.Errors.Count > 0 ? "govuk-form-group--error" : "")">
<label class="govuk-label" for="@furtherExpalanationId">
Give further details on the reason selected:
</label>
@if (ViewData.ModelState["FurtherExplanation"]?.Errors.Count > 0)
{
<p id="@furtherExpalanationErrorId" class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span> @ViewData.ModelState["FurtherExplanation"].Errors[0].ErrorMessage
</p>
}
<textarea class="govuk-textarea @(ViewData.ModelState["FurtherExplanation"]?.Errors.Count > 0 ? "govuk-input--error" : "")" rows="5" id="@furtherExpalanationId" name="FurtherExplanation" aria-describedby="@furtherExpalanationId"></textarea>
</div>
</div>
}
}
}

</div>
</fieldset>
</div>
<div class="govuk-button-group">
<button type="submit" class="govuk-button">Continue</button>
<a href="provider-details?providerId=@Model.Id" class="govuk-button govuk-button--secondary">Cancel</a>
<a href="provider-details?providerId=@Model.ProviderId" class="govuk-button govuk-button--secondary">Cancel</a>
</div>
}
</div>
</div>
</main>
</div>