initial commit
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
@using Indotalent.Features.Purchase.PurchaseOrder.Cqrs
|
||||
@using MudBlazor
|
||||
@inject PurchaseOrderService PurchaseOrderService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-0">Product</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.ProductId"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true"
|
||||
AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.Products)
|
||||
{
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Unit Price</MudText>
|
||||
<MudNumericField @bind-Value="_model.UnitPrice" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Quantity</MudText>
|
||||
<MudNumericField @bind-Value="_model.Quantity" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Summary</MudText>
|
||||
<MudTextField @bind-Value="_model.Summary" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</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: 4px;">
|
||||
@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 PurchaseOrderItemResponse Data { get; set; } = new();
|
||||
private MudForm _form = default!;
|
||||
private UpdatePurchaseOrderItemRequest _model = new();
|
||||
private PurchaseOrderLookupResponse _lookup = new();
|
||||
private bool _processing = false;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var res = await PurchaseOrderService.GetPurchaseOrderLookupAsync();
|
||||
if (res != null && res.IsSuccess)
|
||||
{
|
||||
_lookup = res.Value ?? new();
|
||||
}
|
||||
|
||||
_model.Id = Data.Id;
|
||||
_model.ProductId = Data.ProductId;
|
||||
_model.Summary = Data.Summary;
|
||||
_model.UnitPrice = Data.UnitPrice;
|
||||
_model.Quantity = Data.Quantity;
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void Cancel() => MudDialog.Cancel();
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await PurchaseOrderService.UpdatePurchaseOrderItemAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Item updated successfully", Severity.Success);
|
||||
MudDialog.Close(DialogResult.Ok(true));
|
||||
}
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user