Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/Humans.Infrastructure/Services/ShiftSignupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ await _notificationService.SendAsync(
$"Coverage gap: {shift.Rota.Name} day {shift.DayOffset}",
coordinatorIds,
body: $"Only {confirmedCount}/{shift.MinVolunteers} volunteers confirmed.",
actionUrl: $"/Shifts?departmentId={teamId}",
actionUrl: $"/Shifts/Dashboard?departmentId={teamId}",
actionLabel: "Find cover \u2192");
}
catch (Exception ex)
Expand Down Expand Up @@ -1037,7 +1037,7 @@ await _notificationService.SendAsync(
$"Shift signup change: {rotaName}",
coordinatorIds,
body: enrichedDescription,
actionUrl: $"/Shifts?departmentId={teamId}",
actionUrl: $"/Shifts/Dashboard?departmentId={teamId}",
actionLabel: "View \u2192");
}
catch (Exception ex)
Expand Down
25 changes: 19 additions & 6 deletions src/Humans.Web/Controllers/ShiftsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public async Task<IActionResult> Index(Guid? departmentId, string? fromDate, str

[HttpPost("SignUp")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> SignUp(Guid shiftId)
public async Task<IActionResult> SignUp(Guid shiftId, Guid? departmentId, string? fromDate, string? toDate, string? period, [FromForm(Name = "tags")] List<Guid>? tagIds)
{
var (currentUserNotFound, user) = await ResolveCurrentUserOrChallengeAsync();
if (currentUserNotFound is not null)
Expand All @@ -202,19 +202,19 @@ public async Task<IActionResult> SignUp(Guid shiftId)
if (!result.Success)
{
SetError(result.Error ?? "Shift signup failed.");
return RedirectToAction(nameof(Index));
return RedirectToAction(nameof(Index), BuildFilterRouteValues(departmentId, fromDate, toDate, period, tagIds));
}

SetSuccess(result.Warning is not null
? $"Signed up successfully. Note: {result.Warning}"
: "Signed up successfully!");

return RedirectToAction(nameof(Index));
return RedirectToAction(nameof(Index), BuildFilterRouteValues(departmentId, fromDate, toDate, period, tagIds));
}

[HttpPost("SignUpRange")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> SignUpRange(Guid rotaId, int startDayOffset, int endDayOffset)
public async Task<IActionResult> SignUpRange(Guid rotaId, int startDayOffset, int endDayOffset, Guid? departmentId, string? fromDate, string? toDate, string? period, [FromForm(Name = "tags")] List<Guid>? tagIds)
{
var (currentUserNotFound, user) = await ResolveCurrentUserOrChallengeAsync();
if (currentUserNotFound is not null)
Expand All @@ -228,14 +228,27 @@ public async Task<IActionResult> SignUpRange(Guid rotaId, int startDayOffset, in
if (!result.Success)
{
SetError(result.Error ?? "Shift range signup failed.");
return RedirectToAction(nameof(Index));
return RedirectToAction(nameof(Index), BuildFilterRouteValues(departmentId, fromDate, toDate, period, tagIds));
}

SetSuccess(result.Warning is not null
? $"Signed up for date range. Note: {result.Warning}"
: "Signed up for date range!");

return RedirectToAction(nameof(Index));
return RedirectToAction(nameof(Index), BuildFilterRouteValues(departmentId, fromDate, toDate, period, tagIds));
}

private static RouteValueDictionary BuildFilterRouteValues(Guid? departmentId, string? fromDate, string? toDate, string? period, List<Guid>? tagIds)
{
var rv = new RouteValueDictionary();
if (departmentId.HasValue) rv["departmentId"] = departmentId.Value;
if (!string.IsNullOrEmpty(fromDate)) rv["fromDate"] = fromDate;
if (!string.IsNullOrEmpty(toDate)) rv["toDate"] = toDate;
if (!string.IsNullOrEmpty(period)) rv["period"] = period;
if (tagIds is { Count: > 0 })
for (var i = 0; i < tagIds.Count; i++)
rv[$"tags[{i}]"] = tagIds[i];
return rv;
}

[HttpPost("BailRange")]
Expand Down
10 changes: 10 additions & 0 deletions src/Humans.Web/Views/Shifts/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@
<form asp-action="SignUpRange" method="post" class="row g-2 align-items-end mb-3">
@Html.AntiForgeryToken()
<input type="hidden" name="rotaId" value="@rotaGroup.Rota.Id" />
@if (Model.FilterDepartmentId.HasValue) { <input type="hidden" name="departmentId" value="@Model.FilterDepartmentId" /> }
@if (!string.IsNullOrEmpty(Model.FilterFromDate)) { <input type="hidden" name="fromDate" value="@Model.FilterFromDate" /> }
@if (!string.IsNullOrEmpty(Model.FilterToDate)) { <input type="hidden" name="toDate" value="@Model.FilterToDate" /> }
@if (!string.IsNullOrEmpty(Model.FilterPeriod)) { <input type="hidden" name="period" value="@Model.FilterPeriod" /> }
@foreach (var tagId in Model.FilterTagIds) { <input type="hidden" name="tags" value="@tagId" /> }
<div class="col-auto">
<label class="form-label form-label-sm">Start</label>
<select name="startDayOffset" class="form-select form-select-sm">
Expand Down Expand Up @@ -544,6 +549,11 @@
<form asp-action="SignUp" method="post" class="d-inline">
@Html.AntiForgeryToken()
<input type="hidden" name="shiftId" value="@shift.Id" />
@if (Model.FilterDepartmentId.HasValue) { <input type="hidden" name="departmentId" value="@Model.FilterDepartmentId" /> }
@if (!string.IsNullOrEmpty(Model.FilterFromDate)) { <input type="hidden" name="fromDate" value="@Model.FilterFromDate" /> }
@if (!string.IsNullOrEmpty(Model.FilterToDate)) { <input type="hidden" name="toDate" value="@Model.FilterToDate" /> }
@if (!string.IsNullOrEmpty(Model.FilterPeriod)) { <input type="hidden" name="period" value="@Model.FilterPeriod" /> }
@foreach (var tagId in Model.FilterTagIds) { <input type="hidden" name="tags" value="@tagId" /> }
<button type="submit" class="btn btn-sm btn-success">Sign Up</button>
</form>
}
Expand Down