Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -732,17 +732,19 @@ fun MifosActionsSavingsListingComponent(
savingsProductName: String,
lastActive: String,
balance: String,
isExpanded: Boolean,
onExpandToggle: () -> Unit,
menuList: List<Actions>,
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,
Expand Down Expand Up @@ -771,7 +773,7 @@ fun MifosActionsSavingsListingComponent(
}
}

if (isExpanded) {
AnimatedVisibility(isExpanded) {
Surface(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(
Expand Down Expand Up @@ -1137,6 +1139,8 @@ private fun PreviewMifosActionsSavingsListingComponent() {
else -> println("Action not Handled")
}
},
isExpanded = true,
onExpandToggle = {},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ private fun PreviewMifosActionsSavingsListingComponent() {
else -> println("Action not Handled")
}
},
isExpanded = true,
onExpandToggle = {},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@ 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
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
Expand Down Expand Up @@ -130,6 +133,8 @@ fun FixedDepositAccountScaffold(
modifier: Modifier = Modifier,
onAction: (FixedDepositAccountAction) -> Unit,
) {
var expandedIndex by rememberSaveable { mutableStateOf(-1) }

MifosScaffold(
onBackPressed = {
onAction(FixedDepositAccountAction.NavigateBack)
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -298,8 +299,10 @@ fun NavGraphBuilder.clientNavGraph(
)
savingsAccountsDestination(
navigateBack = navController::popBackStack,
navigateToViewAccount = { },
navigateToViewAccount = navController::navigateToSavingsAccountSummaryScreen,
navController = navController,
navigateToApproveAccount = navController::navigateToSavingsAccountApproval,

)
clientCollateralDestination(
onNavigateBack = navController::popBackStack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@ 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
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
Expand Down Expand Up @@ -130,6 +133,8 @@ internal fun RecurringDepositAccountScaffold(
modifier: Modifier = Modifier,
onAction: (RecurringDepositAccountAction) -> Unit,
) {
var expandedIndex by rememberSaveable { mutableStateOf(-1) }

MifosScaffold(
onBackPressed = {
onAction(RecurringDepositAccountAction.NavigateBack)
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -225,10 +234,8 @@ internal fun RecurringDepositAccountScaffold(
)
}
is Actions.ApproveAccount -> {
onAction(
RecurringDepositAccountAction.ApproveAccount(
recurringDeposit.accountNo ?: "",
),
RecurringDepositAccountAction.ApproveAccount(
recurringDeposit.accountNo ?: "",
)
}
else -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
)
}

Expand All @@ -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) },
Expand Down Expand Up @@ -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) },
)
Expand All @@ -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),
Expand All @@ -159,7 +176,9 @@ fun SavingsAccountsScreen(
when (actions) {
is Actions.ViewAccount -> onAction.invoke(
SavingsAccountAction.ViewAccount(
state.clientId,
savings.id ?: 0,
savings.depositType
?: SavingAccountDepositTypeEntity(),
),
)

Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<SavingsAccountsRoute> {
SavingsAccountsScreenRoute(
navigateBack = navigateBack,
navigateToViewAccount = navigateToViewAccount,
navigateToApproveAccount = navigateToApproveAccount,
navController = navController,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -44,7 +48,7 @@ internal class SavingsAccountsViewModel(
}

is SavingsAccountAction.ViewAccount -> {
sendEvent(SavingsAccountEvent.ViewAccount(state.clientId))
sendEvent(SavingsAccountEvent.ViewAccount(action.accountId, action.accountType))
}

SavingsAccountAction.Refresh -> {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down