@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
Apply for Leave Submit a new leave application for approval.
Select Employee @foreach (var emp in _employees) { @emp.FullName (@emp.Code) } Leave Type @foreach (var cat in _categories) { @cat.Name } Start Date End Date Total Days Reason
Cancel @if (_processing) { Submitting... } else { Submit Application }
@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 _categories = new(); private List _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; } } }