Skip to content

Commit b6cd22c

Browse files
authored
Merge branch 'development' into MM-433
2 parents 7159c6d + bc3d86b commit b6cd22c

File tree

4 files changed

+76
-44
lines changed

4 files changed

+76
-44
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2025 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
9+
*/
10+
package org.mifos.mobile.core.model
11+
12+
import kotlinx.serialization.Serializable
13+
14+
@Serializable
15+
enum class SavingStatus(val status: String) {
16+
17+
ACTIVE("Active"),
18+
INACTIVE("Inactive"),
19+
CLOSED("Closed"),
20+
SUBMIT_AND_PENDING_APPROVAL("Submitted and pending approval"),
21+
;
22+
23+
companion object {
24+
fun fromStatus(status: String): SavingStatus {
25+
return entries.find { it.status.equals(status, ignoreCase = true) }
26+
?: throw IllegalArgumentException("Invalid status: $status")
27+
}
28+
}
29+
}

feature/savings-account/src/commonMain/composeResources/values/strings.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
<string name="feature_savings_withdraw_request_failed_message">Request to withdraw the account is failed. Please try again </string>
9696

9797
<string name="feature_savings_no_accounts_found">No Savings Accounts Found</string>
98-
<string name="feature_generic_error_server">Server issue from our side cannot proceed further, Try again after a moment</string>
99-
100-
</resources>
98+
<string name="feature_generic_error_server">Server issue from our side cannot proceed further, Try again after a moment</string>
99+
100+
101+
102+
</resources>

feature/savings-account/src/commonMain/kotlin/org/mifos/mobile/feature/savingsaccount/savingsAccountDetails/SavingsAccountDetailsScreen.kt

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import androidx.compose.ui.Alignment
3333
import androidx.compose.ui.Modifier
3434
import androidx.compose.ui.unit.dp
3535
import androidx.lifecycle.compose.collectAsStateWithLifecycle
36-
import kotlinx.collections.immutable.ImmutableList
3736
import mifos_mobile.feature.savings_account.generated.resources.Res
3837
import mifos_mobile.feature.savings_account.generated.resources.feature_account_action_update
3938
import mifos_mobile.feature.savings_account.generated.resources.feature_account_details_top_bar_title
@@ -81,12 +80,15 @@ internal fun SavingsAccountDetailsScreen(
8180
event.route == Constants.CHARGES -> {
8281
navigateToClientChargeScreen(ChargeType.SAVINGS.name, uiState.accountId)
8382
}
83+
8484
event.route == Constants.TRANSFER -> {
8585
navigateToTransferScreen(uiState.accountId)
8686
}
87+
8788
event.route == Constants.TRANSACTIONS -> {
8889
navigateToSavingsAccountTransactionScreen(uiState.accountId)
8990
}
91+
9092
event.route == Constants.QR_CODE -> {
9193
navigateToQrCodeScreen(viewModel.getQrString())
9294
}
@@ -111,13 +113,6 @@ internal fun SavingsAccountDetailsScreen(
111113
{ viewModel.trySendAction(it) }
112114
},
113115
)
114-
115-
SavingsAccountDialogs(
116-
dialogState = uiState.dialogState,
117-
onAction = remember(viewModel) {
118-
{ viewModel.trySendAction(it) }
119-
},
120-
)
121116
}
122117

123118
@Composable
@@ -175,22 +170,22 @@ internal fun SavingsAccountDetailsContent(
175170
isActive = state.isActive,
176171
)
177172

178-
if (state.isActive) {
173+
if (state.transactionList.isNotEmpty()) {
179174
AccountDetailsGrid(
180175
label = "Last Transactions",
181176
details = state.transactionList,
182177
isActive = state.isActive,
183178
)
184179
}
185180

186-
if (state.isActive) {
187-
SavingsAccountActions(
188-
items = state.items,
189-
onActionClick = {
190-
onAction(SavingsAccountDetailsAction.OnNavigateToAction(it))
191-
},
192-
)
193-
}
181+
val visibleActions = state.savingStatus?.allowedActions ?: emptySet()
182+
183+
SavingsAccountActions(
184+
visibleActions = visibleActions,
185+
onActionClick = {
186+
onAction(SavingsAccountDetailsAction.OnNavigateToAction(it))
187+
},
188+
)
194189
}
195190
}
196191
else -> { }
@@ -290,7 +285,7 @@ internal fun AccountDetailsGrid(
290285

291286
@Composable
292287
internal fun SavingsAccountActions(
293-
items: ImmutableList<SavingsActionItems>,
288+
visibleActions: Set<SavingsActionItems>,
294289
onActionClick: (String) -> Unit,
295290
) {
296291
Column(
@@ -304,7 +299,7 @@ internal fun SavingsAccountActions(
304299
FlowRow(
305300
modifier = Modifier.fillMaxWidth(),
306301
) {
307-
items.forEach { item ->
302+
visibleActions.forEach { item ->
308303
MifosActionCard(
309304
title = item.title,
310305
subTitle = item.subTitle,
@@ -318,24 +313,6 @@ internal fun SavingsAccountActions(
318313
}
319314
}
320315

321-
@Composable
322-
internal fun SavingsAccountDialogs(
323-
dialogState: SavingsAccountDetailsState.DialogState?,
324-
onAction: (SavingsAccountDetailsAction) -> Unit,
325-
) {
326-
when (dialogState) {
327-
is SavingsAccountDetailsState.DialogState.Error -> {
328-
MifosErrorComponent(
329-
message = dialogState.message,
330-
onRetry = { onAction(SavingsAccountDetailsAction.OnRetry) },
331-
isRetryEnabled = true,
332-
)
333-
}
334-
335-
null -> Unit
336-
}
337-
}
338-
339316
data class LabelValueItem(
340317
val label: StringResource,
341318
val value: String,

feature/savings-account/src/commonMain/kotlin/org/mifos/mobile/feature/savingsaccount/savingsAccountDetails/SavingsAccountDetailsViewModel.kt

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.compose.runtime.Immutable
1313
import androidx.lifecycle.SavedStateHandle
1414
import androidx.lifecycle.viewModelScope
1515
import androidx.navigation.toRoute
16+
import io.ktor.client.utils.EmptyContent.status
1617
import kotlinx.collections.immutable.ImmutableList
1718
import kotlinx.coroutines.flow.distinctUntilChanged
1819
import kotlinx.coroutines.flow.update
@@ -35,7 +36,7 @@ import org.mifos.mobile.core.common.DateHelper
3536
import org.mifos.mobile.core.data.repository.SavingsAccountRepository
3637
import org.mifos.mobile.core.data.util.NetworkMonitor
3738
import org.mifos.mobile.core.datastore.UserPreferencesRepository
38-
import org.mifos.mobile.core.model.LoanStatus
39+
import org.mifos.mobile.core.model.SavingStatus
3940
import org.mifos.mobile.core.model.entity.accounts.savings.SavingsWithAssociations
4041
import org.mifos.mobile.core.model.entity.templates.account.AccountType
4142
import org.mifos.mobile.core.qr.getAccountDetailsInString
@@ -227,8 +228,8 @@ internal class SavingsAccountDetailsViewModel(
227228
}
228229

229230
private fun extractDetails(savings: SavingsWithAssociations) {
230-
val isActive = savings.status?.value == LoanStatus.ACTIVE.status
231-
val isUpdate = savings.status?.value == LoanStatus.SUBMIT_AND_PENDING_APPROVAL.status
231+
val isActive = savings.status?.value == SavingStatus.ACTIVE.status
232+
val isUpdate = savings.status?.value == SavingStatus.SUBMIT_AND_PENDING_APPROVAL.status
232233

233234
val currencyCode = savings.currency?.code
234235
val decimalPlaces = savings.currency?.decimalPlaces
@@ -271,8 +272,9 @@ internal class SavingsAccountDetailsViewModel(
271272
)
272273
} ?: emptyList()
273274

274-
mutableStateFlow.update {
275+
updateState {
275276
it.copy(
277+
savingStatus = SavingStatus.fromStatus(savings.status?.value ?: ""),
276278
isActive = isActive,
277279
isUpdatable = isUpdate,
278280
accountId = savings.id ?: -1L,
@@ -308,6 +310,7 @@ internal data class SavingsAccountDetailsState(
308310
val product: String? = "",
309311
val displayItems: List<LabelValueItem> = emptyList(),
310312
val transactionList: List<LabelValueItem> = emptyList(),
313+
val savingStatus: SavingStatus? = null,
311314
val isActive: Boolean = false,
312315
val items: ImmutableList<SavingsActionItems>,
313316

@@ -325,6 +328,27 @@ internal data class SavingsAccountDetailsState(
325328
data class Error(val message: String) : DialogState
326329
}
327330
}
331+
val SavingStatus.allowedActions: Set<SavingsActionItems>
332+
get() = when (this) {
333+
SavingStatus.ACTIVE -> setOf(
334+
SavingsActionItems.Transactions,
335+
SavingsActionItems.Charges,
336+
SavingsActionItems.QrCode,
337+
SavingsActionItems.Transfer,
338+
)
339+
SavingStatus.INACTIVE -> setOf(
340+
SavingsActionItems.Transfer,
341+
SavingsActionItems.QrCode,
342+
)
343+
SavingStatus.CLOSED -> setOf(
344+
SavingsActionItems.QrCode,
345+
SavingsActionItems.Transfer,
346+
SavingsActionItems.Transactions,
347+
)
348+
SavingStatus.SUBMIT_AND_PENDING_APPROVAL -> setOf(
349+
SavingsActionItems.QrCode,
350+
)
351+
}
328352

329353
/**
330354
* One-time navigation or effect events for the SavingsAccountDetails screen.

0 commit comments

Comments
 (0)