Skip to content

Refactor Add Contribution wizard to support editing existing contributions #1510

Description

@pedrazamiguez

Problem / Motivation

Currently, the app only supports adding new contributions via the Add Contribution wizard. If a user makes a mistake (e.g., wrong amount, wrong scope, or wrong date), they cannot edit the contribution and must delete and recreate it. We need the ability to modify an existing contribution, reusing the existing wizard flow just as we do for expenses and groups.

Proposed Solution

We need to refactor the current Add Contribution wizard to support both creation and editing.

  • Domain Layer:
    • Ensure there is an UpdateContributionUseCase available in :domain to handle modifying the record.
  • Presentation Layer (:features:contributions):
    • Update the navigation route/graph to accept an optional contributionId argument (e.g., Route.ContributionWizard(groupId: String, contributionId: String?)).
    • Refactor AddContributionFeature, AddContributionViewModel, and related state classes (possibly renaming to AddEditContribution... or ContributionWizard... to match convention).
    • If contributionId is provided, load the existing contribution data upon ViewModel initialization and pre-fill the wizard state.
    • Update the submit handler: if a contributionId is present, invoke the update use case; otherwise, invoke the add use case.
    • Update AddContributionUiMapper.kt and the top app bar to display appropriate titles (e.g., "Edit Contribution" vs. "Add Contribution") based on the mode.

Acceptance Criteria

  • The contribution wizard route accepts an optional contributionId.
  • If a contributionId is passed, the wizard pre-fills with the existing contribution's data (amount, scope, date, etc.).
  • The UI text and titles accurately reflect "Edit" mode when modifying an existing contribution.
  • Submitting the wizard in edit mode successfully updates the existing contribution in the database.
  • Adding a new contribution (without a contributionId) continues to work as before.
  • All existing tests pass; new tests added for the edit mode logic.
  • make fast-check passes during iterative development (~15–30s).
  • make check > build.log 2>&1 && echo "Check passed successfully" || (tail -n 100 build.log && exit 1) passes with 0 failures before merging.
  • No new detekt findings introduced.

Out of Scope

  • Modifying paired contributions that were generated automatically from an expense (these should be edited via the parent expense instead).

Related Issues / PRs

  • N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions