initial commit
This commit is contained in:
@@ -0,0 +1,225 @@
|
||||
@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
|
||||
|
||||
<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;">@(ReadOnly ? "Request Details" : "Edit Request")</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Reviewing leave application details and status.</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
||||
@if (_isInitialLoading)
|
||||
{
|
||||
<div class="d-flex flex-column align-center justify-center pa-10">
|
||||
<MudProgressCircular Color="Color.Primary" Indeterminate="true" Size="Size.Large" />
|
||||
<MudText Typo="Typo.body2" Class="mt-4">Loading application data...</MudText>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<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"
|
||||
ReadOnly="ReadOnly"
|
||||
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"
|
||||
ReadOnly="ReadOnly"
|
||||
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">Start Date</MudText>
|
||||
<MudDatePicker @bind-Date="_startDate" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="4">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Date</MudText>
|
||||
<MudDatePicker @bind-Date="_endDate" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="4">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Total Days</MudText>
|
||||
<MudNumericField @bind-Value="_model.Days" ReadOnly="true" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Reason</MudText>
|
||||
<MudTextField @bind-Value="_model.Reason" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Lines="2" />
|
||||
</MudItem>
|
||||
|
||||
@if (!ReadOnly && _model.Status == "Pending")
|
||||
{
|
||||
<MudItem xs="12" Class="mt-4">
|
||||
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Approval Action</MudText>
|
||||
<MudDivider Class="mt-2 mb-4" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Decision Status</MudText>
|
||||
<MudSelect @bind-Value="_model.Status"
|
||||
Variant="Variant.Outlined"
|
||||
Margin="Margin.Dense"
|
||||
AnchorOrigin="Origin.BottomLeft"
|
||||
TransformOrigin="Origin.TopLeft">
|
||||
<MudSelectItem Value="@("Pending")">Pending</MudSelectItem>
|
||||
<MudSelectItem Value="@("Approved")">Approved</MudSelectItem>
|
||||
<MudSelectItem Value="@("Rejected")">Rejected</MudSelectItem>
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Notes / Reject Reason</MudText>
|
||||
<MudTextField @bind-Value="_model.RejectReason"
|
||||
Variant="Variant.Outlined"
|
||||
Margin="Margin.Dense"
|
||||
FullWidth="true"
|
||||
Placeholder="Provide reason if rejected..." />
|
||||
</MudItem>
|
||||
}
|
||||
|
||||
<MudItem xs="12" Class="mt-4">
|
||||
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Audit & Action History</MudText>
|
||||
<MudDivider Class="mt-2 mb-4" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2">Created At</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.CreatedAt)</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2">Created By</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System")</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2">Action By</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.ApproverId) ? _model.ApproverId : "-")</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2">Action Date</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(_model.ActionDate.HasValue? _model.ActionDate.Value.ToString("dd MMM yyyy HH:mm") : "-")</MudText>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
<div class="d-flex justify-end gap-2 mt-10">
|
||||
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Disabled="_processing" Style="border: 1px solid #e0e0e0; border-radius: 4px; text-transform: none; font-weight: 700;">@(ReadOnly ? "Back to List" : "Cancel")</MudButton>
|
||||
@if (!ReadOnly)
|
||||
{
|
||||
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700;">
|
||||
@if (_processing)
|
||||
{
|
||||
<MudProgressCircular Size="Size.Small" Indeterminate="true" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Save Changes</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
</MudForm>
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
@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<EmployeeLeaveReferenceResponse> _employees = new();
|
||||
private List<GetLeaveCategoryListResponse> _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; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user