Files
nimbusflow/frontend/Components/Pages/Schedules.razor

303 lines
11 KiB
Plaintext

@page "/schedules"
@using NimbusFlow.Frontend.Services
@using NimbusFlow.Frontend.Models
@inject IApiService ApiService
@inject IJSRuntime JSRuntime
<PageTitle>Schedules</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="nimbus-page-title">
<i class="bi bi-calendar3 me-3"></i>Schedules
</h1>
<a href="/schedules/create" class="btn btn-nimbus-primary">
<i class="bi bi-calendar-plus-fill me-2"></i>Schedule Member
</a>
</div>
@if (loading)
{
<div class="text-center">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
}
else if (schedules.Any())
{
<!-- Filter Controls -->
<div class="row mb-3">
<div class="col-md-4">
<select class="form-select" @bind="selectedStatus">
<option value="">All Statuses</option>
<option value="pending">Pending</option>
<option value="accepted">Accepted</option>
<option value="declined">Declined</option>
</select>
</div>
<div class="col-md-4">
<input type="date" class="form-control" @bind="filterDate" />
</div>
<div class="col-md-4">
<button class="btn btn-outline-secondary" @onclick="ClearFilters">Clear Filters</button>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Member</th>
<th>Service Date</th>
<th>Service Type</th>
<th>Status</th>
<th>Scheduled At</th>
<th>Response Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var schedule in filteredSchedules.OrderByDescending(s => s.ScheduledAt))
{
<tr>
<td>
<strong>@schedule.Member?.FullName</strong>
</td>
<td>
@schedule.Service?.ServiceDate.ToString("MMM dd, yyyy")
</td>
<td>
<span class="badge" style="background-color: var(--nimbus-gold); color: var(--nimbus-navy);">@schedule.Service?.ServiceTypeName</span>
</td>
<td>
<span class="badge @GetStatusBadgeClass(schedule.Status)">
@schedule.Status.ToUpper()
</span>
</td>
<td>
@schedule.ScheduledAt.ToString("MMM dd, yyyy HH:mm")
</td>
<td>
@if (schedule.AcceptedAt.HasValue)
{
@schedule.AcceptedAt.Value.ToString("MMM dd, yyyy HH:mm")
}
else if (schedule.DeclinedAt.HasValue)
{
@schedule.DeclinedAt.Value.ToString("MMM dd, yyyy HH:mm")
}
else
{
<span class="text-muted">-</span>
}
</td>
<td>
<div class="btn-group" role="group">
<button class="btn btn-sm btn-success me-1"
disabled="@(schedule.Status != "pending")"
@onclick="() => AcceptSchedule(schedule.ScheduleId)">
<i class="bi bi-check-circle-fill me-1"></i>Accept
</button>
<button class="btn btn-sm btn-warning me-1"
disabled="@(schedule.Status != "pending")"
@onclick="() => ShowDeclineModal(schedule)">
<i class="bi bi-x-circle-fill me-1"></i>Decline
</button>
<a href="/schedules/@schedule.ScheduleId" class="btn btn-sm btn-nimbus-secondary me-1">
<i class="bi bi-eye-fill me-1"></i>View
</a>
<button class="btn btn-sm btn-outline-danger" @onclick="() => ConfirmRemove(schedule)">
<i class="bi bi-trash-fill me-1"></i>Remove
</button>
</div>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="row mt-3">
<div class="col-md-12">
<small class="text-muted">
Showing @filteredSchedules.Count() of @schedules.Count schedules
</small>
</div>
</div>
}
else
{
<div class="text-center">
<div class="alert alert-info">
<h4>No Schedules Found</h4>
<p>There are currently no schedules in the system.</p>
<a href="/schedules/create" class="btn btn-primary">Create Your First Schedule</a>
</div>
</div>
}
<!-- Decline Modal -->
@if (showDeclineModal)
{
<div class="modal d-block" tabindex="-1" style="background: rgba(0,0,0,0.5);">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Decline Schedule</h5>
<button type="button" class="btn-close" @onclick="HideDeclineModal"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label">Decline Reason (Optional)</label>
<textarea class="form-control" @bind="declineReason" rows="3" placeholder="Enter reason for declining..."></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" @onclick="HideDeclineModal">Cancel</button>
<button type="button" class="btn btn-warning" @onclick="ConfirmDecline">Decline Schedule</button>
</div>
</div>
</div>
</div>
}
@code {
private List<Schedule> schedules = new();
private bool loading = true;
private string selectedStatus = "";
private DateTime? filterDate;
private bool showDeclineModal = false;
private Schedule? scheduleToDecline;
private string declineReason = "";
private IEnumerable<Schedule> filteredSchedules
{
get
{
var filtered = schedules.AsEnumerable();
if (!string.IsNullOrEmpty(selectedStatus))
{
filtered = filtered.Where(s => s.Status == selectedStatus);
}
if (filterDate.HasValue)
{
filtered = filtered.Where(s => s.Service?.ServiceDate.Date == filterDate.Value.Date);
}
return filtered;
}
}
protected override async Task OnInitializedAsync()
{
await LoadSchedules();
}
private async Task LoadSchedules()
{
try
{
loading = true;
schedules = await ApiService.GetSchedulesAsync();
}
catch (Exception ex)
{
Console.WriteLine($"Error loading schedules: {ex.Message}");
}
finally
{
loading = false;
}
}
private string GetStatusBadgeClass(string status)
{
return status switch
{
"pending" => "badge-nimbus-pending",
"accepted" => "badge-nimbus-accepted",
"declined" => "badge-nimbus-declined",
_ => "badge-nimbus-inactive"
};
}
private async Task AcceptSchedule(int scheduleId)
{
try
{
await ApiService.AcceptScheduleAsync(scheduleId);
await LoadSchedules(); // Refresh the list
}
catch (Exception ex)
{
Console.WriteLine($"Error accepting schedule: {ex.Message}");
}
}
private void ShowDeclineModal(Schedule schedule)
{
scheduleToDecline = schedule;
declineReason = "";
showDeclineModal = true;
}
private void HideDeclineModal()
{
showDeclineModal = false;
scheduleToDecline = null;
declineReason = "";
}
private async Task ConfirmDecline()
{
if (scheduleToDecline != null)
{
try
{
await ApiService.DeclineScheduleAsync(scheduleToDecline.ScheduleId, declineReason);
await LoadSchedules(); // Refresh the list
HideDeclineModal();
}
catch (Exception ex)
{
Console.WriteLine($"Error declining schedule: {ex.Message}");
}
}
}
private async Task ConfirmRemove(Schedule schedule)
{
var confirmed = await JSRuntime.InvokeAsync<bool>("confirm", $"Are you sure you want to remove the schedule for {schedule.Member?.FullName}?");
if (confirmed)
{
try
{
var success = await ApiService.RemoveScheduleAsync(schedule.ScheduleId);
if (success)
{
await LoadSchedules(); // Refresh the list
}
}
catch (Exception ex)
{
Console.WriteLine($"Error removing schedule: {ex.Message}");
}
}
}
private void ClearFilters()
{
selectedStatus = "";
filterDate = null;
}
}