Skip to content

Commit

Permalink
added checkbox to record Indefinite RTW, when checked, ValidTo date i…
Browse files Browse the repository at this point in the history
…s disabled and populated as 31/12/9999
  • Loading branch information
vks333 authored and carlsixsmith-moj committed Aug 20, 2024
1 parent dd365af commit 42ef852
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/Server.UI/Pages/Enrolments/Components/RightToWork.razor
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,19 @@
<MudButton Color="Color.Primary" Variant="@(_isRequired ? Variant.Filled : Variant.Outlined)" OnClick="() => _isRequired = true">Yes, Right to Work is required</MudButton>
<MudButton Color="Color.Primary" Variant="@(_isRequired ? Variant.Outlined : Variant.Filled)" OnClick="() => _isRequired = false">No, Right to Work is not required</MudButton>
</MudButtonGroup>

<MudCheckBox @ref="IndefiniteRtw" T="bool" Label="Indefinite Right To Work" ValueChanged="IndefiniteRtwOnValueChanged" />

@if (_isRequired)
{
<MudDatePicker Label="Valid From" Editable="true"
MaxDate="DateTime.Now.Date"
MinDate="DateTime.Now.AddYears(-5).Date"
@bind-Date="Model.ValidFrom" Required/>

<MudDatePicker Label="Valid To" Editable="true"
<MudDatePicker @ref="_dpValidTo" Label="Valid To" Editable="true"
MaxDate="DateTime.MaxValue.Date"
MinDate="DateTime.Now.Date"
@bind-Date="Model.ValidTo" Required/>
@bind-Date="Model.ValidTo" Disabled="_disabled" Required />

<div class="mb-4 mt-8">
<MudFileUpload T="IBrowserFile" FilesChanged="UploadFiles" MaximumFileCount="1" Accept=".pdf">
Expand Down Expand Up @@ -83,14 +84,17 @@

private bool _isRequired = true;
private bool _uploading = false;

private bool _disabled = false;
private MudDatePicker? _dpValidTo;
MudCheckBox<bool> IndefiniteRtw { get; set; } = default!;

[EditorRequired]
[Parameter]
public AddRightToWork.Command? Model { get; set; }

[Parameter]
public RightToWorkDto[]? RightToWorkDtos { get; set; }

private MudForm? Form { get; set; }

public async Task<bool> Validate()
Expand All @@ -99,7 +103,7 @@
{
return true;
}

await Form!.Validate();

if (Form.IsValid)
Expand Down Expand Up @@ -132,11 +136,24 @@
await using var stream = file.OpenReadStream(maxFileSize);
using var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream);

Model!.UploadRequest = new UploadRequest(file.Name, UploadType.Document, memoryStream.ToArray());
_uploading = false;
}
}
}

private void IndefiniteRtwOnValueChanged()
{
if (IndefiniteRtw.Value)
{
_disabled = true;
Model!.ValidTo = new DateTime(9999, 12, 31);
}
else
{
_disabled = false;
Model!.ValidTo = null;
}
}
}

0 comments on commit 42ef852

Please sign in to comment.