76 lines
2.2 KiB
Plaintext
76 lines
2.2 KiB
Plaintext
@using RobotNet10.FleetManager.Shared.DTOs.Robot
|
|
@using RobotNet10.FleetManager.Client.Services
|
|
@inject ISnackbar Snackbar
|
|
|
|
<MudDialog>
|
|
<TitleContent>
|
|
<MudText Typo="Typo.h6">
|
|
<MudIcon Icon="@Icons.Material.Filled.Delete" Color="Color.Error" Class="mr-2" />
|
|
Delete Robot
|
|
</MudText>
|
|
</TitleContent>
|
|
<DialogContent>
|
|
<MudStack Spacing="3">
|
|
<MudText Typo="Typo.body1">
|
|
Are you sure you want to delete the robot <strong>@Robot.Name</strong> (ID: <strong>@Robot.RobotId</strong>)?
|
|
</MudText>
|
|
|
|
<MudAlert Severity="Severity.Warning">
|
|
<MudText>This action cannot be undone.</MudText>
|
|
</MudAlert>
|
|
</MudStack>
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton OnClick="Cancel">Cancel</MudButton>
|
|
<MudButton Color="Color.Error"
|
|
Variant="Variant.Filled"
|
|
OnClick="Submit"
|
|
Disabled="@isDeleting">
|
|
@if (isDeleting)
|
|
{
|
|
<MudProgressCircular Class="mr-2" Size="Size.Small" Indeterminate="true" />
|
|
<span>Deleting...</span>
|
|
}
|
|
else
|
|
{
|
|
<span>Delete</span>
|
|
}
|
|
</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@code {
|
|
[CascadingParameter] private IMudDialogInstance? MudDialog { get; set; }
|
|
[Parameter] public RobotApiService RobotApiService { get; set; } = null!;
|
|
[Parameter] public RobotDto Robot { get; set; } = null!;
|
|
|
|
private bool isDeleting = false;
|
|
|
|
private void Cancel()
|
|
{
|
|
MudDialog?.Cancel();
|
|
}
|
|
|
|
private async Task Submit()
|
|
{
|
|
isDeleting = true;
|
|
StateHasChanged();
|
|
|
|
try
|
|
{
|
|
await RobotApiService.DeleteAsync(Robot.Id);
|
|
Snackbar.Add($"Robot '{Robot.Name}' deleted successfully", Severity.Success);
|
|
MudDialog?.Close(DialogResult.Ok(true));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"Error deleting robot: {ex.Message}", Severity.Error);
|
|
}
|
|
finally
|
|
{
|
|
isDeleting = false;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
}
|