Skip to content

Commit 541e63a

Browse files
committed
Update: added all the functionality properly
1 parent 8b48dfd commit 541e63a

File tree

3 files changed

+68
-198
lines changed

3 files changed

+68
-198
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/kotlin/org/mifos/mobile/feature/savingsaccount/savingsAccountDetails/SavingsAccountDetailsScreen.kt

Lines changed: 12 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ package org.mifos.mobile.feature.savingsaccount.savingsAccountDetails
1111

1212
import androidx.compose.foundation.clickable
1313
import androidx.compose.foundation.layout.Arrangement
14-
import androidx.compose.foundation.layout.Box
1514
import androidx.compose.foundation.layout.Column
1615
import androidx.compose.foundation.layout.FlowRow
1716
import androidx.compose.foundation.layout.Row
@@ -23,10 +22,7 @@ import androidx.compose.foundation.layout.padding
2322
import androidx.compose.foundation.layout.size
2423
import androidx.compose.foundation.rememberScrollState
2524
import androidx.compose.foundation.verticalScroll
26-
import androidx.compose.material3.DropdownMenu
27-
import androidx.compose.material3.DropdownMenuItem
2825
import androidx.compose.material3.Icon
29-
import androidx.compose.material3.IconButton
3026
import androidx.compose.material3.MaterialTheme
3127
import androidx.compose.material3.Surface
3228
import androidx.compose.material3.Text
@@ -37,17 +33,10 @@ import androidx.compose.ui.Alignment
3733
import androidx.compose.ui.Modifier
3834
import androidx.compose.ui.unit.dp
3935
import androidx.lifecycle.compose.collectAsStateWithLifecycle
40-
import kotlinx.collections.immutable.ImmutableList
4136
import mifos_mobile.feature.savings_account.generated.resources.Res
4237
import mifos_mobile.feature.savings_account.generated.resources.feature_account_action_update
4338
import mifos_mobile.feature.savings_account.generated.resources.feature_account_details_top_bar_title
44-
import mifos_mobile.feature.savings_account.generated.resources.feature_savings_account_options_title
45-
import mifos_mobile.feature.savings_account.generated.resources.feature_savings_menu_charges
46-
import mifos_mobile.feature.savings_account.generated.resources.feature_savings_menu_qr_code
47-
import mifos_mobile.feature.savings_account.generated.resources.feature_savings_menu_transaction_info
48-
import mifos_mobile.feature.savings_account.generated.resources.feature_savings_menu_transactions
4939
import mifos_mobile.feature.savings_account.generated.resources.feature_savings_status_label
50-
import mifos_mobile.feature.savings_account.generated.resources.feature_transaction_info_title
5140
import org.jetbrains.compose.resources.StringResource
5241
import org.jetbrains.compose.resources.stringResource
5342
import org.jetbrains.compose.ui.tooling.preview.Preview
@@ -61,7 +50,6 @@ import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
6150
import org.mifos.mobile.core.designsystem.theme.MifosTypography
6251
import org.mifos.mobile.core.model.enums.ChargeType
6352
import org.mifos.mobile.core.ui.component.MifosActionCard
64-
import org.mifos.mobile.core.ui.component.MifosAlertDialog
6553
import org.mifos.mobile.core.ui.component.MifosErrorComponent
6654
import org.mifos.mobile.core.ui.component.MifosLabelValueCard
6755
import org.mifos.mobile.core.ui.component.MifosPoweredCard
@@ -134,14 +122,6 @@ internal fun SavingsAccountDetailsScreen(
134122
{ viewModel.trySendAction(it) }
135123
},
136124
)
137-
138-
SavingsAccountDialogs(
139-
dialogState = uiState.dialogState,
140-
transectionInfo = uiState.transactionList,
141-
onAction = remember(viewModel) {
142-
{ viewModel.trySendAction(it) }
143-
},
144-
)
145125
}
146126

147127
@Composable
@@ -162,85 +142,6 @@ internal fun SavingsAccountDetailsContent(
162142
)
163143
}
164144
},
165-
actions = {
166-
Box {
167-
IconButton(onClick = { onAction(SavingsAccountDetailsAction.ToggleMenu) }) {
168-
Icon(
169-
imageVector = MifosIcons.MoreVert,
170-
contentDescription = stringResource(Res.string.feature_savings_account_options_title),
171-
)
172-
}
173-
174-
// Dropdown menu
175-
DropdownMenu(
176-
expanded = state.isMenuExpanded,
177-
onDismissRequest = { onAction(SavingsAccountDetailsAction.DismissMenu) },
178-
) {
179-
// Transactions option
180-
DropdownMenuItem(
181-
text = { Text(stringResource(Res.string.feature_savings_menu_transactions)) },
182-
onClick = {
183-
onAction(SavingsAccountDetailsAction.OnTransactionsClick)
184-
onAction(SavingsAccountDetailsAction.DismissMenu)
185-
},
186-
enabled = state.isActive,
187-
leadingIcon = {
188-
Icon(
189-
imageVector = MifosIcons.TransactionHistory,
190-
contentDescription = null,
191-
)
192-
},
193-
)
194-
195-
// Charges option
196-
DropdownMenuItem(
197-
text = { Text(stringResource(Res.string.feature_savings_menu_charges)) },
198-
onClick = {
199-
onAction(SavingsAccountDetailsAction.OnChargesClick)
200-
onAction(SavingsAccountDetailsAction.DismissMenu)
201-
},
202-
leadingIcon = {
203-
Icon(
204-
imageVector = MifosIcons.Receipt,
205-
contentDescription = null,
206-
)
207-
},
208-
)
209-
210-
// QR Code option
211-
DropdownMenuItem(
212-
text = { Text(stringResource(Res.string.feature_savings_menu_qr_code)) },
213-
onClick = {
214-
onAction(SavingsAccountDetailsAction.OnQrCodeClick)
215-
onAction(SavingsAccountDetailsAction.DismissMenu)
216-
},
217-
enabled = state.accountNumber != null,
218-
leadingIcon = {
219-
Icon(
220-
imageVector = MifosIcons.QrCode,
221-
contentDescription = null,
222-
)
223-
},
224-
)
225-
226-
// Transaction Info option
227-
DropdownMenuItem(
228-
text = { Text(stringResource(Res.string.feature_savings_menu_transaction_info)) },
229-
onClick = {
230-
onAction(SavingsAccountDetailsAction.OnTransactionInfoClick)
231-
onAction(SavingsAccountDetailsAction.DismissMenu)
232-
},
233-
enabled = state.transactionList.isNotEmpty(),
234-
leadingIcon = {
235-
Icon(
236-
imageVector = MifosIcons.Info,
237-
contentDescription = null,
238-
)
239-
},
240-
)
241-
}
242-
}
243-
},
244145
) {
245146
when (state.uiState) {
246147
is ScreenUiState.Error -> {
@@ -278,22 +179,22 @@ internal fun SavingsAccountDetailsContent(
278179
isActive = state.isActive,
279180
)
280181

281-
if (state.isActive) {
182+
if (state.transactionList.isNotEmpty()) {
282183
AccountDetailsGrid(
283184
label = "Last Transactions",
284185
details = state.transactionList,
285186
isActive = state.isActive,
286187
)
287188
}
288189

289-
if (state.isActive) {
290-
SavingsAccountActions(
291-
items = state.items,
292-
onActionClick = {
293-
onAction(SavingsAccountDetailsAction.OnNavigateToAction(it))
294-
},
295-
)
296-
}
190+
val visibleActions = state.savingStatus?.allowedActions ?: emptySet()
191+
192+
SavingsAccountActions(
193+
visibleActions = visibleActions,
194+
onActionClick = {
195+
onAction(SavingsAccountDetailsAction.OnNavigateToAction(it))
196+
},
197+
)
297198
}
298199
}
299200
else -> { }
@@ -393,7 +294,7 @@ internal fun AccountDetailsGrid(
393294

394295
@Composable
395296
internal fun SavingsAccountActions(
396-
items: ImmutableList<SavingsActionItems>,
297+
visibleActions: Set<SavingsActionItems>,
397298
onActionClick: (String) -> Unit,
398299
) {
399300
Column(
@@ -407,7 +308,8 @@ internal fun SavingsAccountActions(
407308
FlowRow(
408309
modifier = Modifier.fillMaxWidth(),
409310
) {
410-
items.forEach { item ->
311+
println("Visible Actions: $visibleActions")
312+
visibleActions.forEach { item ->
411313
MifosActionCard(
412314
title = item.title,
413315
subTitle = item.subTitle,
@@ -421,36 +323,6 @@ internal fun SavingsAccountActions(
421323
}
422324
}
423325

424-
@Composable
425-
internal fun SavingsAccountDialogs(
426-
dialogState: SavingsAccountDetailsState.DialogState?,
427-
transectionInfo: List<LabelValueItem>,
428-
onAction: (SavingsAccountDetailsAction) -> Unit,
429-
) {
430-
when (dialogState) {
431-
is SavingsAccountDetailsState.DialogState.Error -> {
432-
MifosErrorComponent(
433-
message = dialogState.message,
434-
onRetry = { onAction(SavingsAccountDetailsAction.OnRetry) },
435-
isRetryEnabled = true,
436-
)
437-
}
438-
439-
is SavingsAccountDetailsState.DialogState.TransactionInfo -> {
440-
MifosAlertDialog(
441-
onDismissRequest = { onAction(SavingsAccountDetailsAction.DismissDialog) },
442-
dialogTitle = stringResource(Res.string.feature_transaction_info_title),
443-
dialogText = transectionInfo.joinToString("\n ") { "${it.label}: ${it.value}" },
444-
confirmationText = "Close",
445-
dismissText = "",
446-
onConfirmation = { onAction(SavingsAccountDetailsAction.DismissDialog) },
447-
)
448-
}
449-
450-
null -> Unit
451-
}
452-
}
453-
454326
data class LabelValueItem(
455327
val label: StringResource,
456328
val value: String,

0 commit comments

Comments
 (0)