Skip to content

Commit

Permalink
Aligned delete alert journey with designs (#1631)
Browse files Browse the repository at this point in the history
  • Loading branch information
hortha authored Oct 29, 2024
1 parent 2b42a46 commit 57dcfa8
Show file tree
Hide file tree
Showing 13 changed files with 798 additions and 753 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
@page "/alerts/{alertId}/delete/check-answers/{handler?}"
@model TeachingRecordSystem.SupportUi.Pages.Alerts.DeleteAlert.CheckAnswersModel
@{
ViewBag.Title = "Check details and delete alert";
}

@section BeforeContent {
<govuk-back-link href="@LinkGenerator.AlertDelete(Model.AlertId, Model.JourneyInstance!.InstanceId)">Back</govuk-back-link>
}

<div class="govuk-grid-row">
<div class="govuk-grid-column-full-from-desktop">
<form action="@LinkGenerator.AlertDeleteCheckAnswers(Model.AlertId, Model.JourneyInstance!.InstanceId)" method="post">
<span class="govuk-caption-l">Delete an alert - @Model.PersonName</span>
<h1 class="govuk-heading-l" data-testid="title">@ViewBag.Title</h1>

<govuk-summary-list>
<govuk-summary-list-row>
<govuk-summary-list-row-key>Alert type</govuk-summary-list-row-key>
<govuk-summary-list-row-value data-testid="alert-type">@Model.AlertTypeName</govuk-summary-list-row-value>
</govuk-summary-list-row>
<govuk-summary-list-row>
<govuk-summary-list-row-key>Details</govuk-summary-list-row-key>
<govuk-summary-list-row-value><multi-line-text text="@Model.Details" data-testid="details" /></govuk-summary-list-row-value>
</govuk-summary-list-row>
<govuk-summary-list-row>
<govuk-summary-list-row-key>Link</govuk-summary-list-row-key>
<govuk-summary-list-row-value>
@if (Model.Link is not null)
{
<a href="@Model.Link" class="govuk-link" rel="noreferrer noopener" target="_blank" data-testid="link">@($"{Model.Link} (opens in new tab)")</a>
}
else
{
<span data-testid="link" use-empty-fallback></span>
}
</govuk-summary-list-row-value>
</govuk-summary-list-row>
<govuk-summary-list-row>
<govuk-summary-list-row-key>Start date</govuk-summary-list-row-key>
<govuk-summary-list-row-value data-testid="start-date">@Model.StartDate?.ToString("d MMMM yyyy")</govuk-summary-list-row-value>
</govuk-summary-list-row>
<govuk-summary-list-row>
<govuk-summary-list-row-key>End date</govuk-summary-list-row-key>
<govuk-summary-list-row-value data-testid="end-date" use-empty-fallback>@Model.EndDate?.ToString("d MMMM yyyy")</govuk-summary-list-row-value>
</govuk-summary-list-row>
<govuk-summary-list-row>
<govuk-summary-list-row-key>Reason for deleting alert</govuk-summary-list-row-key>
<govuk-summary-list-row-value>
@if (Model.DeleteReasonDetail is not null)
{
<multi-line-text text="@Model.DeleteReasonDetail" />
}
else
{
<span use-empty-fallback></span>
}
</govuk-summary-list-row-value>
<govuk-summary-list-row-actions>
<govuk-summary-list-row-action href="@LinkGenerator.AlertDelete(Model.AlertId, Model.JourneyInstance!.InstanceId, fromCheckAnswers: true)" visually-hidden-text="reason details">Change</govuk-summary-list-row-action>
</govuk-summary-list-row-actions>
</govuk-summary-list-row>
<govuk-summary-list-row>
<govuk-summary-list-row-key>Evidence</govuk-summary-list-row-key>
<govuk-summary-list-row-value>
@if (Model.UploadedEvidenceFileUrl is not null)
{
<a href="@Model.UploadedEvidenceFileUrl" class="govuk-link" rel="noreferrer noopener" target="_blank" data-testid="uploaded-evidence-link">@($"{Model.EvidenceFileName} (opens in new tab)")</a>
}
else
{
<span data-testid="uploaded-evidence-link" use-empty-fallback></span>
}
</govuk-summary-list-row-value>
<govuk-summary-list-row-actions>
<govuk-summary-list-row-action href="@LinkGenerator.AlertDelete(Model.AlertId, Model.JourneyInstance!.InstanceId, fromCheckAnswers: true)" visually-hidden-text="evidence">Change</govuk-summary-list-row-action>
</govuk-summary-list-row-actions>
</govuk-summary-list-row>
</govuk-summary-list>

<h2 class="govuk-heading-m">Are you sure you want to delete this alert?</h2>
<div class="govuk-body">
<span class="govuk-caption-m">Deleting this alert will permanently remove it from the database</span>
</div>
<div class="govuk-button-group">
<govuk-button class="govuk-button--warning" type="submit">Delete alert</govuk-button>
<govuk-button formaction="@LinkGenerator.AlertDeleteCheckAnswersCancel(Model.AlertId, Model.JourneyInstance!.InstanceId)" class="govuk-button--secondary" type="submit">Cancel and return to record</govuk-button>
</div>
</form>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using TeachingRecordSystem.Core.DataStore.Postgres;
using TeachingRecordSystem.Core.Services.Files;
using TeachingRecordSystem.SupportUi.Infrastructure.DataAnnotations;

namespace TeachingRecordSystem.SupportUi.Pages.Alerts.DeleteAlert;

[Journey(JourneyNames.DeleteAlert), RequireJourneyInstance]
public class ConfirmModel(
public class CheckAnswersModel(
TrsDbContext dbContext,
TrsLinkGenerator linkGenerator,
IFileService fileService,
Expand Down Expand Up @@ -38,49 +36,17 @@ public class ConfirmModel(

public DateOnly? EndDate { get; set; }

[BindProperty]
[Display(Name = "Do you want to add additional detail?")]
[Required(ErrorMessage = "Select yes if you want to add additional detail")]
public bool? HasAdditionalDetail { get; set; }
public string? DeleteReasonDetail { get; set; }

[BindProperty]
[Display(Name = "Add additional detail")]
public string? AdditionalDetail { get; set; }
public string? EvidenceFileName { get; set; }

[BindProperty]
[Display(Name = "Upload evidence")]
[Required(ErrorMessage = "Select yes if you want to upload evidence")]
public bool? UploadEvidence { get; set; }
public string? EvidenceFileSizeDescription { get; set; }

[BindProperty]
[EvidenceFile]
[FileSize(MaxFileSizeMb * 1024 * 1024, ErrorMessage = "The selected file must be smaller than 50MB")]
public IFormFile? EvidenceFile { get; set; }
public string? UploadedEvidenceFileUrl { get; set; }

public async Task<IActionResult> OnPost()
{
if (HasAdditionalDetail == true && AdditionalDetail is null)
{
ModelState.AddModelError(nameof(AdditionalDetail), "Add additional detail");
}

if (UploadEvidence == true && EvidenceFile is null)
{
ModelState.AddModelError(nameof(EvidenceFile), "Select a file");
}

if (!ModelState.IsValid)
{
return this.PageWithErrors();
}

var now = clock.UtcNow;
Guid? evidenceFileId = null;
if (UploadEvidence == true)
{
using var stream = EvidenceFile!.OpenReadStream();
evidenceFileId = await fileService.UploadFile(stream, EvidenceFile.ContentType);
}

var alert = await dbContext.Alerts
.SingleAsync(a => a.AlertId == AlertId);
Expand All @@ -95,15 +61,15 @@ public async Task<IActionResult> OnPost()
CreatedUtc = now,
RaisedBy = User.GetUserId(),
PersonId = PersonId,
Alert = EventModels.Alert.FromModel(alert),
DeletionReasonDetail = HasAdditionalDetail == true ? AdditionalDetail : null,
EvidenceFile = evidenceFileId is Guid fileId ?
Alert = oldAlertEventModel,
DeletionReasonDetail = DeleteReasonDetail,
EvidenceFile = JourneyInstance!.State.EvidenceFileId is Guid fileId ?
new EventModels.File()
{
FileId = fileId,
Name = EvidenceFile!.FileName
Name = JourneyInstance.State.EvidenceFileName!
} :
null
null,
};

dbContext.AddEvent(deletedEvent);
Expand All @@ -124,7 +90,7 @@ public async Task<IActionResult> OnPostCancel()

public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
if (JourneyInstance!.State.ConfirmDelete is null)
if (!JourneyInstance!.State.IsComplete)
{
context.Result = Redirect(linkGenerator.AlertDelete(AlertId, JourneyInstance.InstanceId));
return;
Expand All @@ -140,6 +106,11 @@ public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingConte
Link = alertInfo.Alert.ExternalLink;
StartDate = alertInfo.Alert.StartDate;
EndDate = alertInfo.Alert.EndDate;
DeleteReasonDetail = JourneyInstance.State.DeleteReasonDetail;
EvidenceFileName = JourneyInstance.State.EvidenceFileName;
UploadedEvidenceFileUrl = JourneyInstance!.State.EvidenceFileId is not null ?
await fileService.GetFileUrl(JourneyInstance!.State.EvidenceFileId!.Value, _fileUrlExpiresAfter) :
null;

await next();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;

namespace TeachingRecordSystem.SupportUi.Pages.Alerts.DeleteAlert;

public class DeleteAlertState : IRegisterJourney
Expand All @@ -8,5 +11,24 @@ public class DeleteAlertState : IRegisterJourney
requestDataKeys: ["alertId"],
appendUniqueKey: true);

public bool? ConfirmDelete { get; set; }
public bool? HasAdditionalReasonDetail { get; set; }

public string? DeleteReasonDetail { get; set; }

public bool? UploadEvidence { get; set; }

public Guid? EvidenceFileId { get; set; }

public string? EvidenceFileName { get; set; }

public string? EvidenceFileSizeDescription { get; set; }

[JsonIgnore]
[MemberNotNullWhen(true, nameof(HasAdditionalReasonDetail), nameof(UploadEvidence), nameof(EvidenceFileId))]
public bool IsComplete =>
HasAdditionalReasonDetail.HasValue &&
(!HasAdditionalReasonDetail.Value || (HasAdditionalReasonDetail.Value && !string.IsNullOrWhiteSpace(DeleteReasonDetail))) &&
UploadEvidence.HasValue &&
(!UploadEvidence.Value || (UploadEvidence.Value && EvidenceFileId.HasValue));

}
Loading

0 comments on commit 57dcfa8

Please sign in to comment.