initial commit
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
@using Indotalent.Features.Leave.LeaveBalance
|
||||
@using Indotalent.Features.Leave.LeaveBalance.Cqrs
|
||||
@using Indotalent.Features.Leave.LeaveRequest.Cqrs
|
||||
@using Indotalent.Features.Leave.LeaveRequest
|
||||
@using Indotalent.Features.Leave.LeaveCategory
|
||||
@using Indotalent.Features.Leave.LeaveCategory.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject LeaveBalanceService LeaveBalanceService
|
||||
@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;">Create Leave Balance</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Initialize new leave quota for an employee.</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">Employee</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.EmployeeId" For="@(() => _model.EmployeeId)" 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)" 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="4">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Year</MudText>
|
||||
<MudNumericField @bind-Value="_model.Year" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="4">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Entitlement (Quota)</MudText>
|
||||
<MudNumericField @bind-Value="_model.Entitlement" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="4">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Carry Forward</MudText>
|
||||
<MudNumericField @bind-Value="_model.CarryForward" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Valid From</MudText>
|
||||
<MudDatePicker @bind-Date="_validFrom" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Valid To</MudText>
|
||||
<MudDatePicker @bind-Date="_validTo" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</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;">Cancel</MudButton>
|
||||
<MudButton Color="Color.Warning" Variant="Variant.Filled" OnClick="Submit" Disabled="_processing" Style="color:white; font-weight:700;">Create Balance</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
[Parameter] public EventCallback OnSuccess { get; set; }
|
||||
private MudForm _form = default!;
|
||||
private CreateLeaveBalanceValidator _validator = new();
|
||||
private CreateLeaveBalanceRequest _model = new() { Year = DateTime.Today.Year, ValidFrom = new DateTime(DateTime.Today.Year, 1, 1), ValidTo = new DateTime(DateTime.Today.Year, 12, 31) };
|
||||
private List<EmployeeLeaveReferenceResponse> _employees = new();
|
||||
private List<GetLeaveCategoryListResponse> _categories = new();
|
||||
private bool _processing = false;
|
||||
private DateTime? _validFrom { get => _model.ValidFrom; set => _model.ValidFrom = value ?? DateTime.Today; }
|
||||
private DateTime? _validTo { get => _model.ValidTo; set => _model.ValidTo = value ?? DateTime.Today; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var empRes = await LeaveRequestService.GetEmployeeReferenceAsync();
|
||||
if (empRes?.IsSuccess == true) _employees = empRes.Value ?? new();
|
||||
var catRes = await LeaveCategoryService.GetLeaveCategoryListAsync();
|
||||
if (catRes?.IsSuccess == true) _categories = catRes.Value ?? new();
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate(); if (!_form.IsValid) return;
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
_model.Remaining = (_model.Entitlement + _model.CarryForward) - _model.Used;
|
||||
var res = await LeaveBalanceService.CreateLeaveBalanceAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (res?.IsSuccess == true) { Snackbar.Add("Balance created", Severity.Success); await OnSuccess.InvokeAsync(); }
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user