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

Fix when setting the location of an enrolment #24

Merged
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
8 changes: 4 additions & 4 deletions src/Application/Features/Locations/DTOs/LocationDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace Cfo.Cats.Application.Features.Locations.DTOs;

public record LocationDto
{
public int Id { get; init; }
public required string Name { get; init; }
public required GenderProvision GenderProvision { get; init; }
public int Id { get; set; }
public required string Name { get; set; }
public required GenderProvision GenderProvision { get; set; }

public required LocationType LocationType { get; init; }
public required LocationType LocationType { get; set; }

/// <summary>
/// The parent location (currently only supported on community locations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Command(string identifier, LocationDto currentLocation, LocationDto
/// <summary>
/// The location to assign the enrolment to
/// </summary>
[Description("Current Location")]
public LocationDto CurrentLocation { get; set; } = currentLocation;

/// <summary>
Expand All @@ -32,8 +33,10 @@ public class Command(string identifier, LocationDto currentLocation, LocationDto
/// A justification for enrolling a participant in a location
/// other than where we think they are
/// </summary>
[Description("Justification reason for alternative enrolment location")]
public string? JustificationReason { get; set; } = justificationReason;

[Description("Enrol at an alternative location enrolment")]
public bool EnrolFromOtherLocation { get; set; } = enrolmentLocation.Id != currentLocation.Id;

public string CacheKey => ParticipantCacheKey.GetCacheKey($"Id:{this.Identifier}");
Expand Down Expand Up @@ -72,10 +75,18 @@ public Validator()

RuleFor(x => x.EnrolmentLocation)
.NotNull();

When(x => x.EnrolFromOtherLocation, () => {
RuleFor(x => x.EnrolmentLocation)
.Must((model, enrolmentLocation) => model.CurrentLocation != enrolmentLocation)
.WithMessage("Enrolment location must be different when Enrol from another location is selected");
});


When(x => x.CurrentLocation != x.EnrolmentLocation, () => {
RuleFor(x => x.JustificationReason)
.NotNull()
.WithMessage("Justification reason is mandatory when enrolling in a different location")
.NotEmpty()
.WithMessage("Justification reason is mandatory when enrolling in a different location");
});
Expand Down
53 changes: 42 additions & 11 deletions src/Server.UI/Pages/Enrolments/Components/Location.razor
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
@using Cfo.Cats.Application.Features.Locations.DTOs
@using Cfo.Cats.Application.Features.Participants.Commands
@inject IStringLocalizer<Location> L

@if (Model is not null && Locations is not [])
{
<MudForm @ref="_form" Validation="@(Validator.ValidateValue(Model))">
<MudTextField T="string" Label="Location" Value="@Model.CurrentLocation.Name" Disabled/>
<MudForm Model="Model" @ref="_form" Validation="@(Validator.ValidateValue(Model))">

<MudCheckBox T="bool" @bind-Value="Model.EnrolFromOtherLocation" Label="Enrol at alternative location"/>

<MudSelect T="LocationDto" @bind-Value="Model.EnrolmentLocation" Label="Alternative Location" AnchorOrigin="Origin.BottomCenter" Disabled="!Model.EnrolFromOtherLocation">
@foreach (var location in Locations!)
<MudGrid>
<MudItem xs="12">
<MudTextField Label="@L[Model.GetMemberDescription(x => x.CurrentLocation)]"
@bind-Value="Model.CurrentLocation.Name"
ReadOnly="true"
Variant="Variant.Text">
</MudTextField>
</MudItem>
<MudItem xs="12">
<MudCheckBox T="bool" @bind-Value="Model.EnrolFromOtherLocation"
Label="@L[Model.GetMemberDescription(x => x.EnrolFromOtherLocation)]">
</MudCheckBox>
</MudItem>
@if (Model.EnrolFromOtherLocation)
{
<MudSelectItem Value="location">
@location.Name
</MudSelectItem>
<MudItem xs="12">
<MudSelect T="LocationDto"
Label="@L["Alternative Location"]"
Required="true"
@bind-Value="@Model.EnrolmentLocation"
For="@(()=>Model.EnrolmentLocation)">
@foreach (var item in Locations!)
{
<MudSelectItem T="LocationDto" Value="@item">
@item.Name
</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12">
<MudTextField Label="@L[Model.GetMemberDescription(x => x.JustificationReason)]"
@bind-Value="Model.JustificationReason"
For="@(()=>Model.JustificationReason)">
</MudTextField>
</MudItem>
}
</MudSelect>
<MudTextFieldExtended T="string" @bind-Value="Model.JustificationReason" Label="Reason for alternative location enrolment" Disabled="!Model.EnrolFromOtherLocation"/>
</MudGrid>

@*


<MudTextFieldExtended T="string" @bind-Value="Model.JustificationReason" Label="" Disabled="!Model.EnrolFromOtherLocation"/> *@
</MudForm>
}

Expand Down
2 changes: 1 addition & 1 deletion src/Server.UI/Pages/Enrolments/Enrolment.razor
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@

Locations = await Mediator.Send(new GetAllLocationsQuery()
{
UserProfile = this.UserProfile!
UserProfile = UserProfile!
});

}
Expand Down
Loading