Skip to content
Merged
Changes from 2 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 @@ -40,6 +40,7 @@ import mifos_mobile.feature.savings_account.generated.resources.feature_account_
import mifos_mobile.feature.savings_account.generated.resources.feature_savings_account
import mifos_mobile.feature.savings_account.generated.resources.feature_savings_account_dashboard
import mifos_mobile.feature.savings_account.generated.resources.feature_savings_account_items
import mifos_mobile.feature.savings_account.generated.resources.feature_savings_filter_pending_account
import mifos_mobile.feature.savings_account.generated.resources.feature_savings_no_accounts_found
import org.jetbrains.compose.resources.StringResource
import org.jetbrains.compose.resources.stringResource
Expand All @@ -52,7 +53,7 @@ import org.mifos.mobile.core.designsystem.theme.AppColors
import org.mifos.mobile.core.designsystem.theme.DesignToken
import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
import org.mifos.mobile.core.designsystem.theme.MifosTypography
import org.mifos.mobile.core.model.LoanStatus
import org.mifos.mobile.core.model.SavingStatus
import org.mifos.mobile.core.ui.component.EmptyDataView
import org.mifos.mobile.core.ui.component.MifosAccountCard
import org.mifos.mobile.core.ui.component.MifosDashboardCard
Expand Down Expand Up @@ -254,6 +255,19 @@ internal fun SavingsAccountContent(
)
}
} else {
val statusOrder = remember {
listOf(
SavingStatus.ACTIVE.status,
SavingStatus.SUBMIT_AND_PENDING_APPROVAL.status,
SavingStatus.CLOSED.status,
SavingStatus.INACTIVE.status,
)
}
val sortedAccounts = remember(state.savingsAccount) {
state.savingsAccount.orEmpty().sortedWith(
compareBy { statusOrder.indexOf(it.status?.value) },
)
}
LazyColumn(
modifier = Modifier
.fillMaxSize()
Expand All @@ -262,30 +276,34 @@ internal fun SavingsAccountContent(
item {
Spacer(modifier = Modifier.height(DesignToken.spacing.small))
}
items(state.savingsAccount.orEmpty()) { account ->
items(sortedAccounts) { account ->
val color = when (account.status?.value) {
LoanStatus.ACTIVE.status -> AppColors.customEnable
LoanStatus.SUBMIT_AND_PENDING_APPROVAL.status -> AppColors.customYellow
LoanStatus.WITHDRAWN.status, LoanStatus.MATURED.status ->
MaterialTheme.colorScheme.error
SavingStatus.ACTIVE.status -> AppColors.customEnable
SavingStatus.SUBMIT_AND_PENDING_APPROVAL.status -> AppColors.customYellow

SavingStatus.INACTIVE.status -> MaterialTheme.colorScheme.error

else -> MaterialTheme.colorScheme.onSurface
}
val accountStatus = if (account.status?.active == true) {
CurrencyFormatter.format(
account.accountBalance,
account.currency?.code,
account.currency?.decimalPlaces,
)
} else {
if (account.status?.value == SavingStatus.SUBMIT_AND_PENDING_APPROVAL.status) {
stringResource(Res.string.feature_savings_filter_pending_account)
} else {
account.status?.value ?: ""
}
}

MifosAccountCard(
accountId = account.id,
accountNumber = account.accountNo,
accountType = account.productName,
accountStatus = (
if (account.status?.active == true) {
CurrencyFormatter.format(
account.accountBalance,
account.currency?.code,
account.currency?.decimalPlaces,
)
} else {
account.status?.value ?: ""
}
),
accountStatus = accountStatus,
accountStatusColor = color,
onAccountClick = {
onAction(
Expand Down
Loading