CodingNic

Categories and Summary

Delete Categories with the Same Confirmation Pattern

Categories and Summary 18 min read

Delete Categories with the Same Confirmation Pattern

Reuse ConfirmDialog on the Categories page instead of creating a second confirmation implementation.

The server must also prevent deletion when an expense still refers to that category.

javascript
const inUse = db.transactions.some(
  (transaction) =>
    transaction.type === "expense" &&
    transaction.category === name
);

Return a conflict response when the category is still in use.

Test it

Try to remove Housing while the seeded rent entry exists. The dialog should appear first, and the server should reject the confirmed deletion.

Checkpoint

Both the UI and API respect the category dependency rule.