fix(client): resolve create new client logical issues and migrate to BaseViewModel
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.
[!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_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto 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.
Comment @coderabbitai help to get the list of available commands and usage tips.
@revanthkumarJ Please resolve the merge conflicts.
@revanthkumarJ Please resolve the merge conflicts.
done
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
@coderabbitai Improve PR title based on github.com/openMF/mobile-wallet/wiki/Commit-style-guide. Give us just the title.
[!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