android-client icon indicating copy to clipboard operation
android-client copied to clipboard

fix(client): resolve create new client logical issues and migrate to BaseViewModel

Open revanthkumarJ opened this issue 8 months ago • 6 comments

Fixes - Jira-#754

Before:

https://github.com/user-attachments/assets/c36874c8-b566-4df5-baf0-1c1b52f29a51

After:

https://github.com/user-attachments/assets/8f8b7212-f2b4-4c96-a6ea-e787d8f9ff5d

Summary by CodeRabbit

  • Refactor

    • Consolidated client-creation UI into a single state-driven, unidirectional flow and renamed the creation screen for a simpler, consistent experience.
  • New Features

    • Centralized event-driven handling for navigation, snackbars, and datatables callbacks.
    • Overlay progress indicator for long-running operations.
    • Helper to merge loading states from multiple data sources.
  • Bug Fixes

    • Date picker now restricts to past dates.
    • Improved image selection, preview, removal, and submit behavior.
    • Address validation runs only when address input is enabled.

revanthkumarJ avatar Mar 18 '26 17:03 revanthkumarJ

[!NOTE]

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • [ ] ▶️ Resume reviews
  • [ ] 🔍 Trigger review
📝 Walkthrough

Walkthrough

Replaces sealed UI-state branching with a unidirectional state/action/event architecture for the Create New Client flow: removed CreateNewClientUiState, introduced CreateNewClientState, CreateNewClientAction, and CreateNewClientEvent; ViewModel moved to BaseViewModel pattern and composable now accepts state, snackbarHostState, and onAction.

Changes

Cohort / File(s) Summary
Screen / Composables
feature/client/src/commonMain/kotlin/com/mifos/feature/client/createNewClient/CreateNewClientScreen.kt
Replaced legacy UI-state branching with CreateNewClientScreen(state, snackbarHostState, onAction) driven by state.screenState; moved to event-driven side effects via EventsEffect(viewModel.eventFlow); form inputs dispatch CreateNewClientAction.*; overlay/loading controlled by state.showOverLayProgressIndicator; date/image pickers and image removal now dispatch actions; image preview uses toImageBitmap/produceState.
ViewModel & State model
feature/client/src/commonMain/kotlin/com/mifos/feature/client/createNewClient/CreateNewClientViewModel.kt
Converted to BaseViewModel<CreateNewClientState, CreateNewClientEvent, CreateNewClientAction>; centralized initial loading with combineDataState(...); single CreateNewClientState container and handleAction updates; added validation, payload creation, submit flow, event emissions (snackbar, navigation, HasDatatables), and overlay-driven image upload flow.
Removed legacy sealed state
feature/client/src/commonMain/kotlin/com/mifos/feature/client/createNewClient/CreateNewClientUiState.kt
Deleted sealed CreateNewClientUiState and all nested UI variants (progress, error, success, upload states).
Navigation API rename / call sites
feature/client/src/commonMain/kotlin/com/mifos/feature/client/navigation/ClientNavigation.kt
Renamed composable/type CreateNewClientScreenRoute → CreateNewClientScreen and updated NavGraphBuilder usage to call the new composable.
Utility added
core/common/src/commonMain/kotlin/com/mifos/core/common/utils/CombineDataState.kt
Added combineDataState helper to merge two Flow<DataState<...>> sources into a single DataState flow with precedence rules (Loading/Error) and a success transform.
Signatures, validation & previews
various files under feature/client/.../createNewClient
Validation now takes isAddressEnabled; address validation runs only when enabled; activation date/selectability logic uses formState.activationDate and utcTimeMillis <= now; previews updated to use CreateNewClientState.ScreenState.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant Screen as CreateNewClientScreen
    participant VM as CreateNewClientViewModel
    participant Repo as Repository/API/DB
    participant Nav as Navigation

    User->>Screen: fill form / pick date / pick image / submit
    Screen->>VM: onAction(UpdateField / TogglePicker / SelectImage / CreateClient)
    VM->>Repo: fetch templates/offices OR createClient(payload) OR uploadImage
    Repo-->>VM: template/offices OR create response / upload result
    VM-->>Screen: emit event (ShowSnackBar / NavigateToClientDetails / HasDatatables)
    Screen->>Screen: show snackbar via SnackbarHostState
    Screen->>Nav: perform navigation on Navigate event

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • openMF/mifos-x-field-officer-app#2645 — similar adjustments to error/notification handling and Create New Client UI flow (event/snackbar changes).

Suggested reviewers

  • biplab1
  • Nagarjuna0033

Poem

🐰 I hopped through fields both old and new,

Actions guide the form in steady queue.
Events now chatter where states once sprawled,
Snackbars sing and uploads stand tall.
A rabbit cheers — the flow's refreshed and true!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: fixes for logical issues in the create new client feature and migration to BaseViewModel architecture.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Mar 18 '26 17:03 coderabbitai[bot]

@revanthkumarJ Please resolve the merge conflicts.

biplab1 avatar Mar 23 '26 23:03 biplab1

@revanthkumarJ Please resolve the merge conflicts.

done

revanthkumarJ avatar Mar 25 '26 15:03 revanthkumarJ

@coderabbitai Improve PR title based on github.com/openMF/mobile-wallet/wiki/Commit-style-guide. Give us just the title.

biplab1 avatar Apr 13 '26 04:04 biplab1

[!TIP] For best results, initiate chat on the files or code changes.

@biplab1: Based on the Commit Style Guide, here is the improved PR title:

fix(client): resolve create new client logical issues and migrate to BaseViewModel

coderabbitai[bot] avatar Apr 13 '26 04:04 coderabbitai[bot]