Feature: add Unmap button to prevent accidental receipt deletion

Add safer workflow for fixing incorrectly mapped receipts:
- Add OnPostUnmapReceiptAsync handler that sets TransactionId to null
- Add "Unmap" button (warning color) before Delete button
- Update Delete confirmation to emphasize PERMANENT deletion
- Unmap success message guides user to Receipts page

This prevents accidental loss of receipt files when users just want to remap them to a different transaction.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
AJ
2025-10-19 16:57:29 -04:00
parent 86b7312dd6
commit ff1d7ff0b0
2 changed files with 23 additions and 3 deletions

View File

@@ -159,7 +159,7 @@
</div>
<small class="text-muted">
@((item.Receipt.FileSizeBytes / 1024.0).ToString("F1")) KB
· @item.Receipt.UploadedAtUtc.ToLocalTime().ToString("MMM d, yyyy")
<EFBFBD> @item.Receipt.UploadedAtUtc.ToLocalTime().ToString("MMM d, yyyy")
</small>
@if (!string.IsNullOrWhiteSpace(item.Receipt.Merchant))
{
@@ -208,8 +208,11 @@
<button type="submit" class="btn btn-sm btn-outline-info">Parse</button>
</form>
}
<form method="post" asp-page-handler="UnmapReceipt" asp-route-receiptId="@item.Receipt.Id" class="d-inline">
<button type="submit" class="btn btn-sm btn-outline-warning" title="Unmap from this transaction (receipt will go back to Receipts page)">Unmap</button>
</form>
<form method="post" asp-page-handler="DeleteReceipt" asp-route-receiptId="@item.Receipt.Id"
onsubmit="return confirm('Delete this receipt?')" class="d-inline">
onsubmit="return confirm('Are you sure? This will PERMANENTLY DELETE the receipt file!')" class="d-inline">
<button type="submit" class="btn btn-sm btn-outline-danger">Delete</button>
</form>
</div>

View File

@@ -181,13 +181,30 @@ namespace MoneyMap.Pages
return RedirectToPage(new { id = Transaction.Id });
}
public async Task<IActionResult> OnPostUnmapReceiptAsync(long receiptId)
{
var receipt = await _db.Receipts.FindAsync(receiptId);
if (receipt != null)
{
receipt.TransactionId = null;
await _db.SaveChangesAsync();
SuccessMessage = "Receipt unmapped successfully! You can now find it on the Receipts page.";
}
else
{
ErrorMessage = "Receipt not found.";
}
return RedirectToPage(new { id = Transaction.Id });
}
public async Task<IActionResult> OnPostDeleteReceiptAsync(long receiptId)
{
var success = await _receiptManager.DeleteReceiptAsync(receiptId);
if (success)
{
SuccessMessage = "Receipt deleted successfully!";
SuccessMessage = "Receipt deleted permanently!";
}
else
{