Files
blazor-crm/Features/Utilities/Todo/Components/TodoPage.razor
T
2026-07-21 13:59:38 +07:00

53 lines
1.4 KiB
Plaintext

@page "/utilities/todo"
@using Indotalent.Features.Utilities.Todo
@using Indotalent.Features.Utilities.Todo.Cqrs
@using Indotalent.Features.Utilities.Todo.Components
@using MudBlazor
@if (_currentView == ViewMode.Create)
{
<_TodoCreateForm OnCancel="BackToTable"
OnSuccess="HandleSuccess" />
}
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
{
<_TodoUpdateForm Data="_selectedData!"
ReadOnly="@(_currentView == ViewMode.View)"
OnCancel="BackToTable"
OnSuccess="HandleSuccess" />
}
else
{
<_TodoDataTable OnAdd="() => ShowCreate()"
OnEdit="(item) => ShowUpdate(item, false)"
OnView="(item) => ShowUpdate(item, true)" />
}
@code {
private enum ViewMode { Table, Create, Update, View }
private ViewMode _currentView = ViewMode.Table;
private UpdateTodoRequest? _selectedData;
private void ShowCreate()
{
_currentView = ViewMode.Create;
}
private void ShowUpdate(UpdateTodoRequest data, bool isReadOnly)
{
_selectedData = data;
_currentView = isReadOnly ? ViewMode.View : ViewMode.Update;
}
private void BackToTable()
{
_currentView = ViewMode.Table;
_selectedData = null;
}
private void HandleSuccess()
{
_currentView = ViewMode.Table;
_selectedData = null;
}
}