initial commit
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
@using Indotalent.Features.Utilities.Todo.Cqrs
|
||||
@using MudBlazor
|
||||
@inject TodoService TodoService
|
||||
@inject ISnackbar Snackbar
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Item Name</MudText>
|
||||
<MudTextField @bind-Value="_model.Name" Required="true" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Date</MudText>
|
||||
<MudDatePicker @bind-Date="_startDate" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Time</MudText>
|
||||
<MudTimePicker @bind-Time="_startTime" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Date</MudText>
|
||||
<MudDatePicker @bind-Date="_endDate" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">End Time</MudText>
|
||||
<MudTimePicker @bind-Time="_endTime" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudCheckBox @bind-Value="_model.IsCompleted" Label="Completed" Color="Color.Primary" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudForm>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="Cancel" Variant="Variant.Text">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="Submit" Variant="Variant.Filled" Disabled="_processing" Style="text-transform: none; font-weight: 700; border-radius: 8px;">
|
||||
@if (_processing)
|
||||
{
|
||||
<MudProgressCircular Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2">Updating...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Save Changes</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!;
|
||||
[Parameter] public TodoItemResponse Data { get; set; } = new();
|
||||
private MudForm _form = default!;
|
||||
private UpdateTodoItemRequest _model = new();
|
||||
private bool _processing = false;
|
||||
|
||||
private DateTime? _startDate;
|
||||
private TimeSpan? _startTime;
|
||||
private DateTime? _endDate;
|
||||
private TimeSpan? _endTime;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_model.Id = Data.Id;
|
||||
_model.Name = Data.Name;
|
||||
_model.Description = Data.Description;
|
||||
_model.IsCompleted = Data.IsCompleted;
|
||||
_model.StartTime = Data.StartTime;
|
||||
_model.EndTime = Data.EndTime;
|
||||
|
||||
_startDate = _model.StartTime?.Date;
|
||||
_startTime = _model.StartTime?.TimeOfDay;
|
||||
_endDate = _model.EndTime?.Date;
|
||||
_endTime = _model.EndTime?.TimeOfDay;
|
||||
}
|
||||
|
||||
private void Cancel() => MudDialog.Cancel();
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
if (_startDate.HasValue && _startTime.HasValue)
|
||||
_model.StartTime = _startDate.Value.Date.Add(_startTime.Value);
|
||||
|
||||
if (_endDate.HasValue && _endTime.HasValue)
|
||||
_model.EndTime = _endDate.Value.Date.Add(_endTime.Value);
|
||||
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await TodoService.UpdateTodoItemAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.Value!.Success)
|
||||
{
|
||||
Snackbar.Add("Item updated successfully", Severity.Success);
|
||||
MudDialog.Close(DialogResult.Ok(true));
|
||||
}
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user