@using Indotalent.ConfigBackEnd.Extensions @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 @(ReadOnly ? "Request Details" : "Edit Request") Reviewing leave application details and status. @if (_isInitialLoading) { Loading application data... } else { 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 @if (!ReadOnly && _model.Status == "Pending") { Approval Action Decision Status Pending Approved Rejected Notes / Reject Reason } Audit & Action History Created At @DateTimeExtensions.ToString(_model.CreatedAt) Created By @(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System") Action By @(!string.IsNullOrEmpty(_model.ApproverId) ? _model.ApproverId : "-") Action Date @(_model.ActionDate.HasValue? _model.ActionDate.Value.ToString("dd MMM yyyy HH:mm") : "-") @(ReadOnly ? "Back to List" : "Cancel") @if (!ReadOnly) { @if (_processing) { } else { Save Changes } } } @code { [Parameter] public UpdateLeaveRequestRequest Data { get; set; } = new(); [Parameter] public bool ReadOnly { get; set; } = false; [Parameter] public EventCallback OnCancel { get; set; } [Parameter] public EventCallback OnSuccess { get; set; } private MudForm _form = default!; private UpdateLeaveRequestValidator _validator = new(); private UpdateLeaveRequestRequest _model = new(); private List _employees = new(); private List _categories = new(); private bool _processing = false; private bool _isInitialLoading = true; 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() { _isInitialLoading = true; try { _model = new UpdateLeaveRequestRequest { Id = Data.Id, EmployeeId = Data.EmployeeId, EmployeeName = Data.EmployeeName, LeaveCategoryId = Data.LeaveCategoryId, LeaveType = Data.LeaveType, StartDate = Data.StartDate, EndDate = Data.EndDate, Days = Data.Days, Reason = Data.Reason, Status = Data.Status, AttachmentPath = Data.AttachmentPath, ApproverId = Data.ApproverId, ActionDate = Data.ActionDate, RejectReason = Data.RejectReason, CreatedAt = Data.CreatedAt, CreatedBy = Data.CreatedBy, UpdatedAt = Data.UpdatedAt, UpdatedBy = Data.UpdatedBy }; var empRes = await LeaveRequestService.GetEmployeeReferenceAsync(); if (empRes != null && empRes.IsSuccess) _employees = empRes.Value ?? new(); var catRes = await LeaveCategoryService.GetLeaveCategoryListAsync(); if (catRes != null && catRes.IsSuccess) _categories = catRes.Value ?? new(); } finally { _isInitialLoading = false; } } private void CalculateDays() { _model.Days = (_model.EndDate - _model.StartDate).TotalDays + 1; if (_model.Days < 0) _model.Days = 0; } private async Task Submit() { if (ReadOnly) return; await _form.Validate(); if (!_form.IsValid) return; _processing = true; try { var response = await LeaveRequestService.UpdateLeaveRequestAsync(_model); await Task.Delay(500); if (response != null && response.IsSuccess) { Snackbar.Add("Request updated successfully", Severity.Success); await OnSuccess.InvokeAsync(); } } finally { _processing = false; } } }