From 27811bc0b5c057888c6539e2340a29735798d43e Mon Sep 17 00:00:00 2001 From: Arin Yadav Date: Wed, 5 Nov 2025 21:31:24 +0530 Subject: [PATCH] Connect saving account item list to saving account detail Page # Conflicts: # feature/client/src/commonMain/kotlin/com/mifos/feature/client/fixedDepositAccount/FixedDepositAccountScreen.kt # feature/client/src/commonMain/kotlin/com/mifos/feature/client/recurringDepositAccount/RecurringDepositAccountScreen.kt # feature/client/src/commonMain/kotlin/com/mifos/feature/client/savingsAccounts/SavingsAccounts.kt --- .../MifosActionsListingCardComponent.kt | 12 +++-- .../components/MifosAllUiComponentsPreview.kt | 2 + .../FixedDepositAccountScreen.kt | 13 +++++- .../client/navigation/ClientNavigation.kt | 5 ++- .../RecurringDepositAccountScreen.kt | 19 +++++--- .../client/savingsAccounts/SavingsAccounts.kt | 44 ++++++++++++++----- .../savingsAccounts/SavingsAccountsRoute.kt | 5 ++- .../SavingsAccountsViewModel.kt | 17 ++++--- 8 files changed, 88 insertions(+), 29 deletions(-) diff --git a/core/ui/src/commonMain/kotlin/com/mifos/core/ui/components/MifosActionsListingCardComponent.kt b/core/ui/src/commonMain/kotlin/com/mifos/core/ui/components/MifosActionsListingCardComponent.kt index 64f3049559f..52b379c1bbd 100644 --- a/core/ui/src/commonMain/kotlin/com/mifos/core/ui/components/MifosActionsListingCardComponent.kt +++ b/core/ui/src/commonMain/kotlin/com/mifos/core/ui/components/MifosActionsListingCardComponent.kt @@ -732,17 +732,19 @@ fun MifosActionsSavingsListingComponent( savingsProductName: String, lastActive: String, balance: String, + isExpanded: Boolean, + onExpandToggle: () -> Unit, menuList: List, onActionClicked: (Actions) -> Unit, ) { - var isExpanded by rememberSaveable { mutableStateOf(false) } - Column { MifosActionsListingComponentOutline( isExpanded = isExpanded, ) { Column( - modifier = Modifier.padding(DesignToken.padding.large), + modifier = Modifier.padding(DesignToken.padding.large).onClick { + onExpandToggle() + }, ) { MifosListingRowItemHeader( text = accountNo, @@ -771,7 +773,7 @@ fun MifosActionsSavingsListingComponent( } } - if (isExpanded) { + AnimatedVisibility(isExpanded) { Surface( modifier = Modifier.fillMaxWidth(), shape = RoundedCornerShape( @@ -1137,6 +1139,8 @@ private fun PreviewMifosActionsSavingsListingComponent() { else -> println("Action not Handled") } }, + isExpanded = true, + onExpandToggle = {}, ) } } diff --git a/core/ui/src/commonMain/kotlin/com/mifos/core/ui/components/MifosAllUiComponentsPreview.kt b/core/ui/src/commonMain/kotlin/com/mifos/core/ui/components/MifosAllUiComponentsPreview.kt index 8ca447d6669..b2e7e870a88 100644 --- a/core/ui/src/commonMain/kotlin/com/mifos/core/ui/components/MifosAllUiComponentsPreview.kt +++ b/core/ui/src/commonMain/kotlin/com/mifos/core/ui/components/MifosAllUiComponentsPreview.kt @@ -167,6 +167,8 @@ private fun PreviewMifosActionsSavingsListingComponent() { else -> println("Action not Handled") } }, + isExpanded = true, + onExpandToggle = {}, ) } } diff --git a/feature/client/src/commonMain/kotlin/com/mifos/feature/client/fixedDepositAccount/FixedDepositAccountScreen.kt b/feature/client/src/commonMain/kotlin/com/mifos/feature/client/fixedDepositAccount/FixedDepositAccountScreen.kt index 1bbfb36ede4..6de8734dbe5 100644 --- a/feature/client/src/commonMain/kotlin/com/mifos/feature/client/fixedDepositAccount/FixedDepositAccountScreen.kt +++ b/feature/client/src/commonMain/kotlin/com/mifos/feature/client/fixedDepositAccount/FixedDepositAccountScreen.kt @@ -30,7 +30,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.material3.AlertDialog import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon @@ -38,7 +38,10 @@ import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.navigation.NavController @@ -130,6 +133,8 @@ fun FixedDepositAccountScaffold( modifier: Modifier = Modifier, onAction: (FixedDepositAccountAction) -> Unit, ) { + var expandedIndex by rememberSaveable { mutableStateOf(-1) } + MifosScaffold( onBackPressed = { onAction(FixedDepositAccountAction.NavigateBack) @@ -187,7 +192,7 @@ fun FixedDepositAccountScaffold( MifosEmptyCard(msg = stringResource(Res.string.client_empty_card_message)) } else { LazyColumn { - items(state.fixedDepositAccount) { fixedDepositAccount -> + itemsIndexed(state.fixedDepositAccount) { index, fixedDepositAccount -> MifosActionsSavingsListingComponent( accountNo = fixedDepositAccount.accountNo ?: notAvailableText, savingsProduct = stringResource(Res.string.client_product_fixed_deposit_account), @@ -205,6 +210,10 @@ fun FixedDepositAccountScaffold( } else { notAvailableText }, + isExpanded = expandedIndex == index, + onExpandToggle = { + expandedIndex = if (expandedIndex == index) -1 else index + }, menuList = if (fixedDepositAccount.status?.submittedAndPendingApproval == true) { listOf( Actions.ViewAccount(MifosIcons.ShielOutlined), diff --git a/feature/client/src/commonMain/kotlin/com/mifos/feature/client/navigation/ClientNavigation.kt b/feature/client/src/commonMain/kotlin/com/mifos/feature/client/navigation/ClientNavigation.kt index 0ab69cc7483..1efe372765f 100644 --- a/feature/client/src/commonMain/kotlin/com/mifos/feature/client/navigation/ClientNavigation.kt +++ b/feature/client/src/commonMain/kotlin/com/mifos/feature/client/navigation/ClientNavigation.kt @@ -95,6 +95,7 @@ import com.mifos.feature.note.notes.navigateToNoteScreen import com.mifos.feature.recurringDeposit.newRecurringDepositAccount.navigateToRecurringAccountRoute import com.mifos.feature.recurringDeposit.newRecurringDepositAccount.recurringAccountDestination import com.mifos.feature.savings.navigation.navigateToAddSavingsAccount +import com.mifos.feature.savings.navigation.navigateToSavingsAccountApproval import com.mifos.feature.savings.navigation.navigateToSavingsAccountSummaryScreen import com.mifos.feature.savings.navigation.savingsDestination import com.mifos.feature.savings.savingsAccountv2.navigateToSavingsAccountRoute @@ -298,8 +299,10 @@ fun NavGraphBuilder.clientNavGraph( ) savingsAccountsDestination( navigateBack = navController::popBackStack, - navigateToViewAccount = { }, + navigateToViewAccount = navController::navigateToSavingsAccountSummaryScreen, navController = navController, + navigateToApproveAccount = navController::navigateToSavingsAccountApproval, + ) clientCollateralDestination( onNavigateBack = navController::popBackStack, diff --git a/feature/client/src/commonMain/kotlin/com/mifos/feature/client/recurringDepositAccount/RecurringDepositAccountScreen.kt b/feature/client/src/commonMain/kotlin/com/mifos/feature/client/recurringDepositAccount/RecurringDepositAccountScreen.kt index bd5af5d15f6..a8331d70ddf 100644 --- a/feature/client/src/commonMain/kotlin/com/mifos/feature/client/recurringDepositAccount/RecurringDepositAccountScreen.kt +++ b/feature/client/src/commonMain/kotlin/com/mifos/feature/client/recurringDepositAccount/RecurringDepositAccountScreen.kt @@ -30,7 +30,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.material3.AlertDialog import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon @@ -38,7 +38,10 @@ import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.navigation.NavController @@ -130,6 +133,8 @@ internal fun RecurringDepositAccountScaffold( modifier: Modifier = Modifier, onAction: (RecurringDepositAccountAction) -> Unit, ) { + var expandedIndex by rememberSaveable { mutableStateOf(-1) } + MifosScaffold( onBackPressed = { onAction(RecurringDepositAccountAction.NavigateBack) @@ -187,7 +192,7 @@ internal fun RecurringDepositAccountScaffold( MifosEmptyCard(msg = stringResource(Res.string.client_empty_card_message)) } else { LazyColumn { - items(state.recurringDepositAccounts) { recurringDeposit -> + itemsIndexed(state.recurringDepositAccounts) { index, recurringDeposit -> MifosActionsSavingsListingComponent( accountNo = recurringDeposit.accountNo ?: notAvailableText, savingsProduct = stringResource(Res.string.client_product_recurring_deposit_account), @@ -205,6 +210,10 @@ internal fun RecurringDepositAccountScaffold( } else { notAvailableText }, + isExpanded = expandedIndex == index, + onExpandToggle = { + expandedIndex = if (expandedIndex == index) -1 else index + }, menuList = if (recurringDeposit.status?.submittedAndPendingApproval == true) { listOf( Actions.ViewAccount(MifosIcons.Calendar), @@ -225,10 +234,8 @@ internal fun RecurringDepositAccountScaffold( ) } is Actions.ApproveAccount -> { - onAction( - RecurringDepositAccountAction.ApproveAccount( - recurringDeposit.accountNo ?: "", - ), + RecurringDepositAccountAction.ApproveAccount( + recurringDeposit.accountNo ?: "", ) } else -> null diff --git a/feature/client/src/commonMain/kotlin/com/mifos/feature/client/savingsAccounts/SavingsAccounts.kt b/feature/client/src/commonMain/kotlin/com/mifos/feature/client/savingsAccounts/SavingsAccounts.kt index 4f41556e075..6253fdee697 100644 --- a/feature/client/src/commonMain/kotlin/com/mifos/feature/client/savingsAccounts/SavingsAccounts.kt +++ b/feature/client/src/commonMain/kotlin/com/mifos/feature/client/savingsAccounts/SavingsAccounts.kt @@ -28,7 +28,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.material3.AlertDialog import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon @@ -38,7 +38,10 @@ import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle @@ -54,6 +57,7 @@ import com.mifos.core.ui.components.MifosBreadcrumbNavBar import com.mifos.core.ui.components.MifosProgressIndicator import com.mifos.core.ui.components.MifosSearchBar import com.mifos.core.ui.util.EventsEffect +import com.mifos.room.entities.accounts.savings.SavingAccountDepositTypeEntity import org.jetbrains.compose.resources.painterResource import org.jetbrains.compose.resources.stringResource import org.koin.compose.viewmodel.koinViewModel @@ -63,27 +67,32 @@ internal fun SavingsAccountsScreenRoute( navigateBack: () -> Unit, navController: NavController, viewModel: SavingsAccountsViewModel = koinViewModel(), - navigateToViewAccount: (Int) -> Unit, + navigateToViewAccount: (Int, SavingAccountDepositTypeEntity) -> Unit, + navigateToApproveAccount: (Int) -> Unit, ) { val state by viewModel.stateFlow.collectAsStateWithLifecycle() EventsEffect(viewModel.eventFlow) { event -> when (event) { SavingsAccountEvent.NavigateBack -> navigateBack() - is SavingsAccountEvent.ViewAccount -> navigateToViewAccount(2) - SavingsAccountEvent.ApproveAccount -> {} + is SavingsAccountEvent.ViewAccount -> navigateToViewAccount( + event.accountId, + event.accountType, + ) + + is SavingsAccountEvent.ApproveAccount -> navigateToApproveAccount(event.accountId) } } - SavingsAccountsDialog( + SavingsAccountsScreen( state = state, onAction = remember(viewModel) { { viewModel.trySendAction(it) } }, + navController = navController, ) - SavingsAccountsScreen( + SavingsAccountsDialog( state = state, onAction = remember(viewModel) { { viewModel.trySendAction(it) } }, - navController = navController, ) } @@ -93,6 +102,8 @@ fun SavingsAccountsScreen( state: SavingsAccountState, navController: NavController, ) { + var expandedIndex by rememberSaveable { mutableStateOf(-1) } + MifosScaffold( title = stringResource(Res.string.update_default_account_title), onBackPressed = { onAction(SavingsAccountAction.NavigateBack) }, @@ -122,7 +133,13 @@ fun SavingsAccountsScreen( if (state.isSearchBarActive) { MifosSearchBar( query = state.searchText, - onQueryChange = { onAction.invoke(SavingsAccountAction.UpdateSearchValue(it)) }, + onQueryChange = { + onAction.invoke( + SavingsAccountAction.UpdateSearchValue( + it, + ), + ) + }, onSearchClick = { onAction.invoke(SavingsAccountAction.OnSearchClick) }, onBackClick = { onAction.invoke(SavingsAccountAction.ToggleSearch) }, ) @@ -134,7 +151,7 @@ fun SavingsAccountsScreen( EmptySavingsCard() } else { LazyColumn { - items(state.savingsAccounts) { savings -> + itemsIndexed(state.savingsAccounts) { index, savings -> MifosActionsSavingsListingComponent( accountNo = savings.accountNo.toString(), savingsProduct = stringResource(Res.string.client_product_saving_account), @@ -159,7 +176,9 @@ fun SavingsAccountsScreen( when (actions) { is Actions.ViewAccount -> onAction.invoke( SavingsAccountAction.ViewAccount( - state.clientId, + savings.id ?: 0, + savings.depositType + ?: SavingAccountDepositTypeEntity(), ), ) @@ -179,6 +198,11 @@ fun SavingsAccountsScreen( } else { stringResource(Res.string.client_savings_not_avilable) }, + isExpanded = expandedIndex == index, + onExpandToggle = { + expandedIndex = + if (expandedIndex == index) -1 else index + }, ) Spacer(modifier = Modifier.height(DesignToken.spacing.small)) diff --git a/feature/client/src/commonMain/kotlin/com/mifos/feature/client/savingsAccounts/SavingsAccountsRoute.kt b/feature/client/src/commonMain/kotlin/com/mifos/feature/client/savingsAccounts/SavingsAccountsRoute.kt index a975eb4ee48..6f69c3290f0 100644 --- a/feature/client/src/commonMain/kotlin/com/mifos/feature/client/savingsAccounts/SavingsAccountsRoute.kt +++ b/feature/client/src/commonMain/kotlin/com/mifos/feature/client/savingsAccounts/SavingsAccountsRoute.kt @@ -12,6 +12,7 @@ package com.mifos.feature.client.savingsAccounts import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.compose.composable +import com.mifos.room.entities.accounts.savings.SavingAccountDepositTypeEntity import kotlinx.serialization.Serializable @Serializable @@ -22,12 +23,14 @@ data class SavingsAccountsRoute( fun NavGraphBuilder.savingsAccountsDestination( navigateBack: () -> Unit, navController: NavController, - navigateToViewAccount: (Int) -> Unit, + navigateToViewAccount: (Int, SavingAccountDepositTypeEntity) -> Unit, + navigateToApproveAccount: (Int) -> Unit, ) { composable { SavingsAccountsScreenRoute( navigateBack = navigateBack, navigateToViewAccount = navigateToViewAccount, + navigateToApproveAccount = navigateToApproveAccount, navController = navController, ) } diff --git a/feature/client/src/commonMain/kotlin/com/mifos/feature/client/savingsAccounts/SavingsAccountsViewModel.kt b/feature/client/src/commonMain/kotlin/com/mifos/feature/client/savingsAccounts/SavingsAccountsViewModel.kt index 3ed1df51b94..9a51479181b 100644 --- a/feature/client/src/commonMain/kotlin/com/mifos/feature/client/savingsAccounts/SavingsAccountsViewModel.kt +++ b/feature/client/src/commonMain/kotlin/com/mifos/feature/client/savingsAccounts/SavingsAccountsViewModel.kt @@ -29,7 +29,11 @@ internal class SavingsAccountsViewModel( override fun handleAction(action: SavingsAccountAction) { when (action) { - is SavingsAccountAction.ApproveAccount -> sendEvent(SavingsAccountEvent.ApproveAccount) + is SavingsAccountAction.ApproveAccount -> sendEvent( + SavingsAccountEvent.ApproveAccount( + action.accountId, + ), + ) SavingsAccountAction.ToggleFilter -> { mutableStateFlow.update { @@ -44,7 +48,7 @@ internal class SavingsAccountsViewModel( } is SavingsAccountAction.ViewAccount -> { - sendEvent(SavingsAccountEvent.ViewAccount(state.clientId)) + sendEvent(SavingsAccountEvent.ViewAccount(action.accountId, action.accountType)) } SavingsAccountAction.Refresh -> { @@ -127,8 +131,9 @@ data class SavingsAccountState( sealed interface SavingsAccountEvent { data object NavigateBack : SavingsAccountEvent - data object ApproveAccount : SavingsAccountEvent - data class ViewAccount(val id: Int) : SavingsAccountEvent + data class ApproveAccount(val accountId: Int) : SavingsAccountEvent + data class ViewAccount(val accountId: Int, val accountType: SavingAccountDepositTypeEntity) : + SavingsAccountEvent } sealed interface SavingsAccountAction { @@ -137,7 +142,9 @@ sealed interface SavingsAccountAction { data object ToggleFilter : SavingsAccountAction data object Refresh : SavingsAccountAction data class ApproveAccount(val accountId: Int) : SavingsAccountAction - data class ViewAccount(val accountId: Int) : SavingsAccountAction + data class ViewAccount(val accountId: Int, val accountType: SavingAccountDepositTypeEntity) : + SavingsAccountAction + data class UpdateSearchValue(val query: String) : SavingsAccountAction data object OnSearchClick : SavingsAccountAction data object CloseDialog : SavingsAccountAction