136 lines
6.4 KiB
Plaintext
136 lines
6.4 KiB
Plaintext
@using Indotalent.Features.Leave.LeaveRequest
|
|
@using Indotalent.Features.Leave.LeaveRequest.Cqrs
|
|
@using Indotalent.Features.Leave.LeaveCategory
|
|
@using Indotalent.Features.Leave.LeaveCategory.Cqrs
|
|
@using Indotalent.Shared.Utils
|
|
@using MudBlazor
|
|
@inject LeaveRequestService LeaveRequestService
|
|
@inject LeaveCategoryService LeaveCategoryService
|
|
@inject ISnackbar Snackbar
|
|
|
|
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
|
|
<div class="d-flex align-center gap-4">
|
|
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
|
|
<div>
|
|
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">Apply for Leave</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #64748b;">Submit a new leave application for approval.</MudText>
|
|
</div>
|
|
</div>
|
|
</MudPaper>
|
|
|
|
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
|
<MudForm @ref="_form" Model="_model">
|
|
<MudGrid Spacing="3">
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Select Employee</MudText>
|
|
<MudSelect T="string" @bind-Value="_model.EmployeeId"
|
|
For="@(() => _model.EmployeeId)"
|
|
Validation="@(_validator.ValidateValue())"
|
|
Variant="Variant.Outlined" Margin="Margin.Dense"
|
|
AnchorOrigin="Origin.BottomLeft" TransformOrigin="Origin.TopLeft">
|
|
@foreach (var emp in _employees)
|
|
{
|
|
<MudSelectItem Value="@emp.Id">@emp.FullName (@emp.Code)</MudSelectItem>
|
|
}
|
|
</MudSelect>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Leave Type</MudText>
|
|
<MudSelect T="string" @bind-Value="_model.LeaveCategoryId"
|
|
For="@(() => _model.LeaveCategoryId)"
|
|
Validation="@(_validator.ValidateValue())"
|
|
Variant="Variant.Outlined" Margin="Margin.Dense"
|
|
AnchorOrigin="Origin.BottomLeft" TransformOrigin="Origin.TopLeft">
|
|
@foreach (var cat in _categories)
|
|
{
|
|
<MudSelectItem Value="@cat.Id">@cat.Name</MudSelectItem>
|
|
}
|
|
</MudSelect>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="3">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Date</MudText>
|
|
<MudDatePicker @bind-Date="_startDate" Variant="Variant.Outlined" Margin="Margin.Dense" Editable="true" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="3">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">End Date</MudText>
|
|
<MudDatePicker @bind-Date="_endDate" Variant="Variant.Outlined" Margin="Margin.Dense" Editable="true" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Total Days</MudText>
|
|
<MudNumericField @bind-Value="_model.Days" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" ReadOnly="true" />
|
|
</MudItem>
|
|
<MudItem xs="12">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Reason</MudText>
|
|
<MudTextField @bind-Value="_model.Reason"
|
|
For="@(() => _model.Reason)"
|
|
Validation="@(_validator.ValidateValue())"
|
|
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Lines="3" />
|
|
</MudItem>
|
|
</MudGrid>
|
|
|
|
<div class="d-flex justify-end gap-2 mt-8">
|
|
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Disabled="_processing" Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">Cancel</MudButton>
|
|
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700;">
|
|
@if (_processing)
|
|
{
|
|
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
|
|
<MudText Class="ms-2">Submitting...</MudText>
|
|
}
|
|
else
|
|
{
|
|
<MudText>Submit Application</MudText>
|
|
}
|
|
</MudButton>
|
|
</div>
|
|
</MudForm>
|
|
</MudPaper>
|
|
|
|
@code {
|
|
[Parameter] public EventCallback OnCancel { get; set; }
|
|
[Parameter] public EventCallback OnSuccess { get; set; }
|
|
|
|
private MudForm _form = default!;
|
|
private CreateLeaveRequestValidator _validator = new();
|
|
private CreateLeaveRequestRequest _model = new() { StartDate = DateTime.Today, EndDate = DateTime.Today };
|
|
private List<GetLeaveCategoryListResponse> _categories = new();
|
|
private List<EmployeeLeaveReferenceResponse> _employees = new();
|
|
private bool _processing = false;
|
|
|
|
private DateTime? _startDate { get => _model.StartDate; set { _model.StartDate = value ?? DateTime.Today; CalculateDays(); } }
|
|
private DateTime? _endDate { get => _model.EndDate; set { _model.EndDate = value ?? DateTime.Today; CalculateDays(); } }
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
var catRes = await LeaveCategoryService.GetLeaveCategoryListAsync();
|
|
if (catRes != null && catRes.IsSuccess) _categories = catRes.Value ?? new();
|
|
|
|
var empRes = await LeaveRequestService.GetEmployeeReferenceAsync();
|
|
if (empRes != null && empRes.IsSuccess) _employees = empRes.Value ?? new();
|
|
|
|
CalculateDays();
|
|
}
|
|
|
|
private void CalculateDays()
|
|
{
|
|
_model.Days = (_model.EndDate - _model.StartDate).TotalDays + 1;
|
|
if (_model.Days < 0) _model.Days = 0;
|
|
}
|
|
|
|
private async Task Submit()
|
|
{
|
|
await _form.Validate();
|
|
if (!_form.IsValid) return;
|
|
_processing = true;
|
|
try
|
|
{
|
|
var response = await LeaveRequestService.CreateLeaveRequestAsync(_model);
|
|
await Task.Delay(500);
|
|
if (response != null && response.IsSuccess)
|
|
{
|
|
Snackbar.Add("Leave request submitted", Severity.Success);
|
|
await OnSuccess.InvokeAsync();
|
|
}
|
|
}
|
|
finally { _processing = false; }
|
|
}
|
|
} |