Skip to content

Commit 311f93c

Browse files
committed
Update Add Alert journey to use JourneySteps
1 parent 829ae7f commit 311f93c

27 files changed

+305
-274
lines changed

TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/LinkGeneratorExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static string GetRequiredPathByPage(this LinkGenerator linkGenerator, str
1010

1111
if (journeyInstanceId?.UniqueKey is string journeyInstanceUniqueKey)
1212
{
13-
url = QueryHelpers.AddQueryString(url, WebCommon.FormFlow.Constants.UniqueKeyQueryParameterName, journeyInstanceUniqueKey);
13+
url = QueryHelpers.AddQueryString(url, Constants.UniqueKeyQueryParameterName, journeyInstanceUniqueKey);
1414
}
1515

1616
return url;

TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/AddAlertLinkGenerator.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,32 @@ public class AddAlertLinkGenerator(LinkGenerator linkGenerator)
55
public string Index(Guid personId, JourneyInstanceId? journeyInstanceId) =>
66
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Index", routeValues: new { personId }, journeyInstanceId: journeyInstanceId);
77

8-
public string Type(Guid personId, JourneyInstanceId journeyInstanceId, bool? fromCheckAnswers = null) =>
9-
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Type", routeValues: new { personId, fromCheckAnswers }, journeyInstanceId: journeyInstanceId);
8+
public string Type(Guid personId, JourneyInstanceId journeyInstanceId, string? returnUrl = null) =>
9+
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Type", routeValues: new { personId, returnUrl }, journeyInstanceId: journeyInstanceId);
1010

1111
public string TypeCancel(Guid personId, JourneyInstanceId journeyInstanceId) =>
1212
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Type", "cancel", routeValues: new { personId }, journeyInstanceId: journeyInstanceId);
1313

14-
public string Details(Guid personId, JourneyInstanceId journeyInstanceId, bool? fromCheckAnswers = null) =>
15-
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Details", routeValues: new { personId, fromCheckAnswers }, journeyInstanceId: journeyInstanceId);
14+
public string Details(Guid personId, JourneyInstanceId journeyInstanceId, string? returnUrl = null) =>
15+
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Details", routeValues: new { personId, returnUrl }, journeyInstanceId: journeyInstanceId);
1616

1717
public string DetailsCancel(Guid personId, JourneyInstanceId journeyInstanceId) =>
1818
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Details", "cancel", routeValues: new { personId }, journeyInstanceId: journeyInstanceId);
1919

20-
public string Link(Guid personId, JourneyInstanceId journeyInstanceId, bool? fromCheckAnswers = null) =>
21-
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Link", routeValues: new { personId, fromCheckAnswers }, journeyInstanceId: journeyInstanceId);
20+
public string Link(Guid personId, JourneyInstanceId journeyInstanceId, string? returnUrl = null) =>
21+
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Link", routeValues: new { personId, returnUrl }, journeyInstanceId: journeyInstanceId);
2222

2323
public string LinkCancel(Guid personId, JourneyInstanceId journeyInstanceId) =>
2424
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Link", "cancel", routeValues: new { personId }, journeyInstanceId: journeyInstanceId);
2525

26-
public string StartDate(Guid personId, JourneyInstanceId journeyInstanceId, bool? fromCheckAnswers = null) =>
27-
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/StartDate", routeValues: new { personId, fromCheckAnswers }, journeyInstanceId: journeyInstanceId);
26+
public string StartDate(Guid personId, JourneyInstanceId journeyInstanceId, string? returnUrl = null) =>
27+
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/StartDate", routeValues: new { personId, returnUrl }, journeyInstanceId: journeyInstanceId);
2828

2929
public string StartDateCancel(Guid personId, JourneyInstanceId journeyInstanceId) =>
3030
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/StartDate", "cancel", routeValues: new { personId }, journeyInstanceId: journeyInstanceId);
3131

32-
public string Reason(Guid personId, JourneyInstanceId journeyInstanceId, bool? fromCheckAnswers = null) =>
33-
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Reason", routeValues: new { personId, fromCheckAnswers }, journeyInstanceId: journeyInstanceId);
32+
public string Reason(Guid personId, JourneyInstanceId journeyInstanceId, string? returnUrl = null) =>
33+
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Reason", routeValues: new { personId, returnUrl }, journeyInstanceId: journeyInstanceId);
3434

3535
public string ReasonCancel(Guid personId, JourneyInstanceId journeyInstanceId) =>
3636
linkGenerator.GetRequiredPathByPage("/Alerts/AddAlert/Reason", "cancel", routeValues: new { personId }, journeyInstanceId: journeyInstanceId);
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
using System.Diagnostics.CodeAnalysis;
2-
using System.Text.Json.Serialization;
31
using TeachingRecordSystem.SupportUi.Pages.Shared.Evidence;
4-
52
namespace TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert;
63

7-
public class AddAlertState : IRegisterJourney
4+
public class AddAlertState : IRegisterJourney, IJourneyWithSteps
85
{
96
public static JourneyDescriptor Journey => new(
107
JourneyNames.AddAlert,
118
typeof(AddAlertState),
129
requestDataKeys: ["personId"],
1310
appendUniqueKey: true);
1411

12+
public required JourneySteps Steps { get; init; }
13+
1514
public Guid? AlertTypeId { get; set; }
1615

1716
public string? AlertTypeName { get; set; }
@@ -32,14 +31,14 @@ public class AddAlertState : IRegisterJourney
3231

3332
public EvidenceUploadModel Evidence { get; set; } = new();
3433

35-
[JsonIgnore]
36-
[MemberNotNullWhen(true, nameof(AlertTypeId), nameof(Details), nameof(StartDate))]
37-
public bool IsComplete =>
38-
AlertTypeId.HasValue &&
39-
AddLink.HasValue &&
40-
StartDate.HasValue &&
41-
AddReason.HasValue &&
42-
HasAdditionalReasonDetail is bool hasDetail &&
43-
(!hasDetail || AddReasonDetail is not null) &&
44-
Evidence.IsComplete;
34+
}
35+
public class AddAlertStateJourneyStateFactory(SupportUiLinkGenerator linkGenerator) : IJourneyStateFactory<AddAlertState>
36+
{
37+
public Task<AddAlertState> CreateAsync(CreateJourneyStateContext context)
38+
{
39+
var personId = context.HttpContext.GetCurrentPersonFeature().PersonId;
40+
var firstStep = new JourneyStep(linkGenerator.Alerts.AddAlert.Index(personId, context.InstanceId));
41+
var state = new AddAlertState { Steps = JourneySteps.Create(firstStep) };
42+
return Task.FromResult(state);
43+
}
4544
}

TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/CheckAnswers.cshtml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
@page "/alerts/add/check-answers/{handler?}"
1+
@page "/alerts/add/check-answers"
22
@model TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert.CheckAnswersModel
33
@{
44
ViewBag.Title = "Check details before adding alert";
5+
6+
var returnUrl = Request.GetEncodedPathAndQuery();
57
}
68

79
@section BeforeContent {
8-
<govuk-back-link href="@LinkGenerator.Alerts.AddAlert.Reason(Model.PersonId, Model.JourneyInstance!.InstanceId)">Back</govuk-back-link>
10+
<govuk-back-link href="@Model.JourneyInstance!.GetPreviousStepUrl()">Back</govuk-back-link>
911
}
1012

1113
<div class="govuk-grid-row">
@@ -19,14 +21,14 @@
1921
<govuk-summary-list-row-key>Alert type</govuk-summary-list-row-key>
2022
<govuk-summary-list-row-value>@Model.AlertTypeName</govuk-summary-list-row-value>
2123
<govuk-summary-list-row-actions>
22-
<govuk-summary-list-row-action href="@LinkGenerator.Alerts.AddAlert.Type(Model.PersonId, Model.JourneyInstance!.InstanceId, fromCheckAnswers: true)" visually-hidden-text="alert type">Change</govuk-summary-list-row-action>
24+
<govuk-summary-list-row-action href="@LinkGenerator.Alerts.AddAlert.Type(Model.PersonId, Model.JourneyInstance!.InstanceId, returnUrl)" visually-hidden-text="alert type">Change</govuk-summary-list-row-action>
2325
</govuk-summary-list-row-actions>
2426
</govuk-summary-list-row>
2527
<govuk-summary-list-row>
2628
<govuk-summary-list-row-key>Details</govuk-summary-list-row-key>
2729
<govuk-summary-list-row-value use-empty-fallback>@Html.ConvertNewlinesToLineBreaks(Model.Details)</govuk-summary-list-row-value>
2830
<govuk-summary-list-row-actions>
29-
<govuk-summary-list-row-action href="@LinkGenerator.Alerts.AddAlert.Details(Model.PersonId, Model.JourneyInstance!.InstanceId, fromCheckAnswers: true)" visually-hidden-text="details">Change</govuk-summary-list-row-action>
31+
<govuk-summary-list-row-action href="@LinkGenerator.Alerts.AddAlert.Details(Model.PersonId, Model.JourneyInstance!.InstanceId, returnUrl)" visually-hidden-text="details">Change</govuk-summary-list-row-action>
3032
</govuk-summary-list-row-actions>
3133
</govuk-summary-list-row>
3234
<govuk-summary-list-row>
@@ -42,14 +44,14 @@
4244
}
4345
</govuk-summary-list-row-value>
4446
<govuk-summary-list-row-actions>
45-
<govuk-summary-list-row-action href="@LinkGenerator.Alerts.AddAlert.Link(Model.PersonId, Model.JourneyInstance!.InstanceId, fromCheckAnswers: true)" visually-hidden-text="link">Change</govuk-summary-list-row-action>
47+
<govuk-summary-list-row-action href="@LinkGenerator.Alerts.AddAlert.Link(Model.PersonId, Model.JourneyInstance!.InstanceId, returnUrl)" visually-hidden-text="link">Change</govuk-summary-list-row-action>
4648
</govuk-summary-list-row-actions>
4749
</govuk-summary-list-row>
4850
<govuk-summary-list-row>
4951
<govuk-summary-list-row-key>Start date</govuk-summary-list-row-key>
5052
<govuk-summary-list-row-value>@Model.StartDate.ToString(UiDefaults.DateOnlyDisplayFormat)</govuk-summary-list-row-value>
5153
<govuk-summary-list-row-actions>
52-
<govuk-summary-list-row-action href="@LinkGenerator.Alerts.AddAlert.StartDate(Model.PersonId, Model.JourneyInstance!.InstanceId, fromCheckAnswers: true)" visually-hidden-text="start date">Change</govuk-summary-list-row-action>
54+
<govuk-summary-list-row-action href="@LinkGenerator.Alerts.AddAlert.StartDate(Model.PersonId, Model.JourneyInstance!.InstanceId, returnUrl)" visually-hidden-text="start date">Change</govuk-summary-list-row-action>
5355
</govuk-summary-list-row-actions>
5456
</govuk-summary-list-row>
5557
</govuk-summary-list>
@@ -61,7 +63,7 @@
6163
<govuk-summary-list-row-key>Reason</govuk-summary-list-row-key>
6264
<govuk-summary-list-row-value>@Model.AddReason.GetDisplayName()</govuk-summary-list-row-value>
6365
<govuk-summary-list-row-actions>
64-
<govuk-summary-list-row-action href="@LinkGenerator.Alerts.AddAlert.Reason(Model.PersonId, Model.JourneyInstance!.InstanceId, fromCheckAnswers: true)" visually-hidden-text="reason for adding">Change</govuk-summary-list-row-action>
66+
<govuk-summary-list-row-action href="@LinkGenerator.Alerts.AddAlert.Reason(Model.PersonId, Model.JourneyInstance!.InstanceId, returnUrl)" visually-hidden-text="reason for adding">Change</govuk-summary-list-row-action>
6567
</govuk-summary-list-row-actions>
6668
</govuk-summary-list-row>
6769
<govuk-summary-list-row>
@@ -77,7 +79,7 @@
7779
}
7880
</govuk-summary-list-row-value>
7981
<govuk-summary-list-row-actions>
80-
<govuk-summary-list-row-action href="@LinkGenerator.Alerts.AddAlert.Reason(Model.PersonId, Model.JourneyInstance!.InstanceId, fromCheckAnswers: true)" visually-hidden-text="reason details">Change</govuk-summary-list-row-action>
82+
<govuk-summary-list-row-action href="@LinkGenerator.Alerts.AddAlert.Reason(Model.PersonId, Model.JourneyInstance!.InstanceId, returnUrl)" visually-hidden-text="reason details">Change</govuk-summary-list-row-action>
8183
</govuk-summary-list-row-actions>
8284
</govuk-summary-list-row>
8385

@@ -87,7 +89,7 @@
8789
<vc:evidence-file-link evidence-file="@Model.EvidenceFile" />
8890
</govuk-summary-list-row-value>
8991
<govuk-summary-list-row-actions>
90-
<govuk-summary-list-row-action href="@LinkGenerator.Alerts.AddAlert.Reason(Model.PersonId, Model.JourneyInstance!.InstanceId, fromCheckAnswers: true)" visually-hidden-text="evidence">Change</govuk-summary-list-row-action>
92+
<govuk-summary-list-row-action href="@LinkGenerator.Alerts.AddAlert.Reason(Model.PersonId, Model.JourneyInstance!.InstanceId, returnUrl)" visually-hidden-text="evidence">Change</govuk-summary-list-row-action>
9193
</govuk-summary-list-row-actions>
9294
</govuk-summary-list-row>
9395
</govuk-summary-list>

TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/CheckAnswers.cshtml.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ public class CheckAnswersModel(
1919
[FromQuery]
2020
public Guid PersonId { get; set; }
2121

22-
[FromQuery]
23-
public bool FromCheckAnswers { get; set; }
24-
2522
public string? PersonName { get; set; }
2623

2724
public Guid AlertTypeId { get; set; }
@@ -45,16 +42,10 @@ public class CheckAnswersModel(
4542

4643
public override void OnPageHandlerExecuting(PageHandlerExecutingContext context)
4744
{
48-
if (!JourneyInstance!.State.IsComplete)
49-
{
50-
context.Result = Redirect(linkGenerator.Alerts.AddAlert.Reason(PersonId, JourneyInstance.InstanceId));
51-
return;
52-
}
53-
5445
var personInfo = context.HttpContext.GetCurrentPersonFeature();
5546

5647
PersonName = personInfo.Name;
57-
AlertTypeId = JourneyInstance.State.AlertTypeId!.Value;
48+
AlertTypeId = JourneyInstance!.State.AlertTypeId!.Value;
5849
AlertTypeName = JourneyInstance.State.AlertTypeName;
5950
Details = JourneyInstance.State.Details;
6051
Link = JourneyInstance.State.Link;

TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Details.cshtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
@page "/alerts/add/details/{handler?}"
1+
@page "/alerts/add/details"
22
@model TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert.DetailsModel
33
@{
44
ViewBag.Title = "Enter details about this alert (optional)";
55
}
66

77
@section BeforeContent {
8-
<govuk-back-link href="@(Model.FromCheckAnswers ? LinkGenerator.Alerts.AddAlert.CheckAnswers(Model.PersonId, Model.JourneyInstance!.InstanceId) : LinkGenerator.Alerts.AddAlert.Type(Model.PersonId, Model.JourneyInstance!.InstanceId))" />
8+
<govuk-back-link href="@Model.JourneyInstance!.GetPreviousStepUrl()" />
99
}
1010

1111
<div class="govuk-grid-row">
1212
<div class="govuk-grid-column-two-thirds-from-desktop">
13-
<form action="@LinkGenerator.Alerts.AddAlert.Details(Model.PersonId, Model.JourneyInstance!.InstanceId, Model.FromCheckAnswers)" method="post">
13+
<form method="post">
1414
<span class="govuk-caption-l">Add an alert - @Model.PersonName</span>
1515
<h1 class="govuk-heading-l">@ViewBag.Title</h1>
1616
<h2 class="govuk-heading-m">@Model.AlertTypeName</h2>

TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Details.cshtml.cs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ public class DetailsModel(SupportUiLinkGenerator linkGenerator, EvidenceUploadMa
1414
[FromQuery]
1515
public Guid PersonId { get; set; }
1616

17-
[FromQuery]
18-
public bool FromCheckAnswers { get; set; }
19-
2017
public string? PersonName { get; set; }
2118

2219
public string? AlertTypeName { get; set; }
@@ -37,14 +34,11 @@ public async Task<IActionResult> OnPostAsync()
3734
return this.PageWithErrors();
3835
}
3936

40-
await JourneyInstance!.UpdateStateAsync(state =>
41-
{
42-
state.Details = Details;
43-
});
37+
var nextStep = linkGenerator.Alerts.AddAlert.Link(PersonId, JourneyInstance!.InstanceId);
4438

45-
return Redirect(FromCheckAnswers
46-
? linkGenerator.Alerts.AddAlert.CheckAnswers(PersonId, JourneyInstance.InstanceId)
47-
: linkGenerator.Alerts.AddAlert.Link(PersonId, JourneyInstance.InstanceId));
39+
return await JourneyInstance.UpdateStateAndRedirectToNextStepAsync(
40+
state => state.Details = Details,
41+
nextStep);
4842
}
4943

5044
public async Task<IActionResult> OnPostCancelAsync()
@@ -56,15 +50,9 @@ public async Task<IActionResult> OnPostCancelAsync()
5650

5751
public override void OnPageHandlerExecuting(PageHandlerExecutingContext context)
5852
{
59-
if (JourneyInstance!.State.AlertTypeId is null)
60-
{
61-
context.Result = Redirect(linkGenerator.Alerts.AddAlert.Type(PersonId, JourneyInstance.InstanceId));
62-
return;
63-
}
64-
6553
var personInfo = context.HttpContext.GetCurrentPersonFeature();
6654

6755
PersonName = personInfo.Name;
68-
AlertTypeName = JourneyInstance.State.AlertTypeName;
56+
AlertTypeName = JourneyInstance!.State.AlertTypeName;
6957
}
7058
}

TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Index.cshtml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ public class IndexModel(SupportUiLinkGenerator linkGenerator) : PageModel
1111
[FromQuery]
1212
public Guid PersonId { get; set; }
1313

14-
public IActionResult OnGet() => Redirect(linkGenerator.Alerts.AddAlert.Type(PersonId, JourneyInstance!.InstanceId));
14+
public Task<IActionResult> OnGetAsync() =>
15+
JourneyInstance!.UpdateStateAndRedirectToNextStepAsync(_ => { }, linkGenerator.Alerts.AddAlert.Type(PersonId, JourneyInstance!.InstanceId));
1516
}

TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Link.cshtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
@page "/alerts/add/link/{handler?}"
1+
@page "/alerts/add/link"
22
@model TeachingRecordSystem.SupportUi.Pages.Alerts.AddAlert.LinkModel
33
@{
44
ViewBag.Title = Html.DisplayNameFor(m => m.AddLink);
55
}
66

77
@section BeforeContent {
8-
<govuk-back-link href="@(Model.FromCheckAnswers == true ? LinkGenerator.Alerts.AddAlert.CheckAnswers(Model.PersonId, Model.JourneyInstance!.InstanceId) : LinkGenerator.Alerts.AddAlert.Details(Model.PersonId, Model.JourneyInstance!.InstanceId))" />
8+
<govuk-back-link href="@Model.JourneyInstance!.GetBackLinkUrl()" />
99
}
1010

1111
<div class="govuk-grid-row">
1212
<div class="govuk-grid-column-two-thirds-from-desktop">
13-
<form action="@LinkGenerator.Alerts.AddAlert.Link(Model.PersonId, Model.JourneyInstance!.InstanceId, Model.FromCheckAnswers)" method="post">
13+
<form method="post">
1414
<span class="govuk-caption-l">Add an alert - @Model.PersonName</span>
1515

1616
<govuk-radios for="AddLink">

TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/Link.cshtml.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ public class LinkModel(SupportUiLinkGenerator linkGenerator, EvidenceUploadManag
1414
[FromQuery]
1515
public Guid PersonId { get; set; }
1616

17-
[FromQuery]
18-
public bool FromCheckAnswers { get; set; }
19-
2017
public string? PersonName { get; set; }
2118

2219
[BindProperty]
@@ -44,15 +41,15 @@ public async Task<IActionResult> OnPostAsync()
4441
return this.PageWithErrors();
4542
}
4643

47-
await JourneyInstance!.UpdateStateAsync(state =>
48-
{
49-
state.AddLink = AddLink;
50-
state.Link = AddLink == true ? Link : null;
51-
});
44+
var nextStep = linkGenerator.Alerts.AddAlert.StartDate(PersonId, JourneyInstance!.InstanceId);
5245

53-
return Redirect(FromCheckAnswers
54-
? linkGenerator.Alerts.AddAlert.CheckAnswers(PersonId, JourneyInstance.InstanceId)
55-
: linkGenerator.Alerts.AddAlert.StartDate(PersonId, JourneyInstance.InstanceId));
46+
return await JourneyInstance.UpdateStateAndRedirectToNextStepAsync(
47+
state =>
48+
{
49+
state.AddLink = AddLink;
50+
state.Link = AddLink == true ? Link : null;
51+
},
52+
nextStep);
5653
}
5754

5855
public async Task<IActionResult> OnPostCancelAsync()

0 commit comments

Comments
 (0)