This commit is contained in:
rossmill76 committed 2026-03-01 21:19:34 +00:00
1 parent 9faa49daa1
commit 08eefe2973
20 files changed
+572 -142

No files matched your search

+118 -3
View File
@@ -24,12 +24,11 @@
else
{
<EditForm Model="formModel" OnValidSubmit="AddTransaction" FormName="addTransaction">
<DataAnnotationsValidator />
<ToastValidator />
<div class="row g-3">
<div class="col-md-4">
<label class="form-label">Description</label>
<InputText @bind-Value="formModel.Description" class="form-control" placeholder="e.g. Food shopping" />
<ValidationMessage For="() => formModel.Description" />
</div>
<div class="col-md-2">
<label class="form-label">Amount</label>
@@ -86,7 +85,6 @@
<div class="col-md-2">
<label class="form-label">End Date <small class="text-muted">(max 1yr)</small></label>
<InputDate @bind-Value="formModel.RecurrenceEndDate" class="form-control" max="@formModel.Date.AddYears(1).ToString("yyyy-MM-dd")" />
<ValidationMessage For="() => formModel.RecurrenceEndDate" />
</div>
}
<div class="col-md-2 d-flex align-items-end">
@@ -174,6 +172,9 @@ else
@(t.Type == TransactionType.Income ? "+" : "-")@t.Account.FormatAmount(t.Amount)
</td>
<td class="text-end">
<button class="btn btn-outline-primary btn-sm" @onclick="() => OpenEditModal(t)">
Edit
</button>
<button class="btn btn-outline-danger btn-sm" @onclick="() => ConfirmDelete(t)">
Delete
</button>
@@ -209,6 +210,79 @@ else
</div>
</div>
}
@if (showEditModal)
{
<div class="modal d-block" tabindex="-1" style="background: rgba(0,0,0,.5);">
<div class="modal-dialog modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit Transaction</h5>
<button type="button" class="btn-close" @onclick="CloseEditModal"></button>
</div>
<EditForm Model="editModel" OnValidSubmit="SaveEdit" FormName="editTransaction">
<ToastValidator />
<div class="modal-body">
<div class="mb-3">
<label class="form-label">Description</label>
<InputText @bind-Value="editModel.Description" class="form-control" />
</div>
<div class="mb-3">
<label class="form-label">Amount</label>
<InputNumber @bind-Value="editModel.Amount" class="form-control numeric-input" />
</div>
<div class="mb-3">
<label class="form-label">Date</label>
<InputDate @bind-Value="editModel.Date" class="form-control" />
</div>
<div class="mb-3">
<label class="form-label">Type</label>
<InputSelect @bind-Value="editModel.Type" class="form-select">
<option value="@TransactionType.Expense">Expense</option>
<option value="@TransactionType.Income">Income</option>
</InputSelect>
</div>
<div class="mb-3">
<label class="form-label">Account</label>
<InputSelect @bind-Value="editModel.AccountId" class="form-select">
@if (accountsList is not null)
{
@foreach (var account in accountsList)
{
<option value="@account.Id">@account.Name</option>
}
}
</InputSelect>
</div>
<div class="mb-3">
<label class="form-label">Category</label>
<InputSelect @bind-Value="editModel.CategoryId" class="form-select">
<option value="">— None —</option>
@if (categoriesList is not null)
{
@foreach (var category in categoriesList)
{
<option value="@category.Id">@(string.IsNullOrEmpty(category.Icon) ? "" : category.Icon + " ")@category.Name</option>
}
}
</InputSelect>
</div>
@if (editIsPartOfSeries)
{
<div class="alert alert-info mb-0">
<i class="bi bi-info-circle"></i> Changes will apply to this and all future occurrences in the series.
</div>
}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" @onclick="CloseEditModal">Cancel</button>
<button type="submit" class="btn btn-primary">Save</button>
</div>
</EditForm>
</div>
</div>
</div>
}
}
@code {
@@ -319,6 +393,47 @@ else
private bool showDeleteModal;
private Transaction? pendingDeleteTransaction;
// Edit modal state
private bool showEditModal;
private int? editingTransactionId;
private bool editIsPartOfSeries;
private TransactionForm editModel = new();
private void OpenEditModal(Transaction t)
{
editingTransactionId = t.Id;
editIsPartOfSeries = t.RecurrenceType != RecurrenceType.None || t.ParentTransactionId is not null;
editModel = new TransactionForm
{
Description = t.Description,
Amount = t.Amount,
Date = t.Date,
Type = t.Type,
AccountId = t.AccountId,
CategoryId = t.CategoryId,
RecurrenceType = t.RecurrenceType,
RecurrenceEndDate = t.RecurrenceEndDate
};
showEditModal = true;
}
private void CloseEditModal() => showEditModal = false;
private async Task SaveEdit()
{
if (userId is null || editingTransactionId is null) return;
await TransactionService.UpdateTransactionAsync(
editingTransactionId.Value, userId,
editModel.Description, editModel.Amount, editModel.Date,
editModel.Type, editModel.AccountId, editModel.CategoryId,
editModel.RecurrenceType, editModel.RecurrenceEndDate);
showEditModal = false;
editingTransactionId = null;
await LoadData();
}
private void ConfirmDelete(Transaction t)
{
pendingDeleteTransaction = t;