Skip to content

Commit b983294

Browse files
committed
refactor(loan): show consistent loan actions for all account statuses
1 parent d83c760 commit b983294

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

core/model/src/commonMain/kotlin/org/mifos/mobile/core/model/LoanStatus.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,10 @@ enum class LoanStatus(val status: String) {
2424

2525
REJECTED("Rejected"),
2626

27-
WITHDRAWN("Withdrawn by applicant"),
27+
WITHDRAWN("Withdrawn by applicant");
28+
29+
companion object {
30+
fun fromStatus(value: String?): LoanStatus? =
31+
entries.firstOrNull { it.status.equals(value, ignoreCase = true) }
32+
}
2833
}

core/model/src/commonMain/kotlin/org/mifos/mobile/core/model/entity/accounts/loan/Status.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.mifos.mobile.core.model.entity.accounts.loan
1111

1212
import kotlinx.serialization.Serializable
13+
import org.mifos.mobile.core.model.LoanStatus
1314
import org.mifos.mobile.core.model.Parcelable
1415
import org.mifos.mobile.core.model.Parcelize
1516

@@ -40,6 +41,9 @@ data class Status(
4041

4142
) : Parcelable {
4243

44+
val loanStatus: LoanStatus?
45+
get() = LoanStatus.fromStatus(value)
46+
4347
fun isLoanTypeWithdrawn(): Boolean {
4448
return !(
4549
this.active == true || this.closed == true || this.pendingApproval == true ||

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/loanAccountDetails/LoanAccountDetailsScreen.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import androidx.compose.ui.unit.dp
3030
import androidx.lifecycle.compose.collectAsStateWithLifecycle
3131
import kotlinx.collections.immutable.ImmutableList
3232
import mifos_mobile.feature.loan_account.generated.resources.Res
33+
import mifos_mobile.feature.loan_account.generated.resources.feature_account_action_make_payment
3334
import mifos_mobile.feature.loan_account.generated.resources.feature_account_details_action
3435
import mifos_mobile.feature.loan_account.generated.resources.feature_account_details_top_bar_title
3536
import mifos_mobile.feature.loan_account.generated.resources.feature_loan_next_installment_label
@@ -45,6 +46,7 @@ import org.mifos.mobile.core.designsystem.theme.AppColors
4546
import org.mifos.mobile.core.designsystem.theme.DesignToken
4647
import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
4748
import org.mifos.mobile.core.designsystem.theme.MifosTypography
49+
import org.mifos.mobile.core.model.LoanStatus
4850
import org.mifos.mobile.core.model.entity.AccountDetails
4951
import org.mifos.mobile.core.model.entity.TransferSuccessDestination
5052
import org.mifos.mobile.core.model.enums.ChargeType
@@ -163,8 +165,9 @@ internal fun LoanAccountDetailsContent(
163165
)
164166
}
165167

166-
if (state.isActive) {
168+
if (state.shouldShowAction) {
167169
SavingsAccountActions(
170+
canMakeTransfer = state.canMakeTransfer,
168171
items = state.items,
169172
onActionClick = {
170173
onAction(LoanAccountDetailsAction.OnNavigateToAction(it))
@@ -222,6 +225,7 @@ internal fun AccountDetailsGrid(
222225

223226
@Composable
224227
internal fun SavingsAccountActions(
228+
canMakeTransfer: Boolean,
225229
items: ImmutableList<LoanActionItems>,
226230
// onAction: (LoanAccountDetailsAction) -> Unit,
227231
onActionClick: (String) -> Unit,
@@ -237,14 +241,16 @@ internal fun SavingsAccountActions(
237241
FlowRow(
238242
modifier = Modifier.fillMaxWidth(),
239243
) {
240-
items.forEach { item ->
244+
items
245+
.filter { item ->
246+
!(item.title == Res.string.feature_account_action_make_payment && !canMakeTransfer)
247+
}
248+
.forEach { item ->
241249
MifosActionCard(
242250
title = item.title,
243251
subTitle = item.subTitle,
244252
icon = item.icon,
245-
onClick = {
246-
onActionClick(item.route)
247-
},
253+
onClick = { onActionClick(item.route) },
248254
)
249255
}
250256
}

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/loanAccountDetails/LoanAccountDetailsViewModel.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ internal class LoanAccountDetailsViewModel(
178178
mutableStateFlow.update {
179179
it.copy(
180180
accountId = loan?.id?.toLong() ?: -1L,
181-
isActive = loan?.status?.value == LoanStatus.ACTIVE.status,
181+
accountStatus = loan?.status?.loanStatus,
182182
accountNumber = loan?.accountNo,
183183
clientName = loan?.clientName,
184184
product = loan?.loanProductName,
@@ -198,7 +198,7 @@ internal class LoanAccountDetailsViewModel(
198198
* @property accountId Unique ID for the loan account.
199199
* @property displayItems List of account metadata to be displayed.
200200
* @property transactionList List of most recent transaction details.
201-
* @property isActive True if the loan is active.
201+
* @property accountStatus True if the loan is active.
202202
* @property items List of quick action items (e.g., Repay, Foreclose).
203203
* @property isUpdatable Whether the loan is editable (e.g., in a pending state).
204204
* @property dialogState State representing UI dialogs like loading or error.
@@ -214,7 +214,7 @@ internal data class LoanAccountDetailsState(
214214
val product: String? = "",
215215
val displayItems: List<LabelValueItem> = emptyList(),
216216
val transactionList: List<LabelValueItem>? = emptyList(),
217-
val isActive: Boolean = false,
217+
val accountStatus: LoanStatus? = LoanStatus.ACTIVE,
218218
val items: ImmutableList<LoanActionItems>,
219219
val isUpdatable: Boolean = false,
220220
val dialogState: DialogState?,
@@ -229,6 +229,15 @@ internal data class LoanAccountDetailsState(
229229
/** Shown during loading state. */
230230
data object Loading : DialogState
231231
}
232+
233+
val shouldShowAction: Boolean
234+
get() = accountStatus !in setOf(
235+
LoanStatus.SUBMIT_AND_PENDING_APPROVAL,
236+
LoanStatus.REJECTED
237+
)
238+
239+
val canMakeTransfer: Boolean
240+
get() = accountStatus in setOf(LoanStatus.ACTIVE, LoanStatus.DISBURSED)
232241
}
233242

234243
/**

0 commit comments

Comments
 (0)