@@ -11,7 +11,6 @@ package org.mifos.mobile.feature.savingsaccount.savingsAccountDetails
1111
1212import androidx.compose.foundation.clickable
1313import androidx.compose.foundation.layout.Arrangement
14- import androidx.compose.foundation.layout.Box
1514import androidx.compose.foundation.layout.Column
1615import androidx.compose.foundation.layout.FlowRow
1716import androidx.compose.foundation.layout.Row
@@ -23,10 +22,7 @@ import androidx.compose.foundation.layout.padding
2322import androidx.compose.foundation.layout.size
2423import androidx.compose.foundation.rememberScrollState
2524import androidx.compose.foundation.verticalScroll
26- import androidx.compose.material3.DropdownMenu
27- import androidx.compose.material3.DropdownMenuItem
2825import androidx.compose.material3.Icon
29- import androidx.compose.material3.IconButton
3026import androidx.compose.material3.MaterialTheme
3127import androidx.compose.material3.Surface
3228import androidx.compose.material3.Text
@@ -37,17 +33,10 @@ import androidx.compose.ui.Alignment
3733import androidx.compose.ui.Modifier
3834import androidx.compose.ui.unit.dp
3935import androidx.lifecycle.compose.collectAsStateWithLifecycle
40- import kotlinx.collections.immutable.ImmutableList
4136import mifos_mobile.feature.savings_account.generated.resources.Res
4237import mifos_mobile.feature.savings_account.generated.resources.feature_account_action_update
4338import 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
4939import mifos_mobile.feature.savings_account.generated.resources.feature_savings_status_label
50- import mifos_mobile.feature.savings_account.generated.resources.feature_transaction_info_title
5140import org.jetbrains.compose.resources.StringResource
5241import org.jetbrains.compose.resources.stringResource
5342import org.jetbrains.compose.ui.tooling.preview.Preview
@@ -61,7 +50,6 @@ import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
6150import org.mifos.mobile.core.designsystem.theme.MifosTypography
6251import org.mifos.mobile.core.model.enums.ChargeType
6352import org.mifos.mobile.core.ui.component.MifosActionCard
64- import org.mifos.mobile.core.ui.component.MifosAlertDialog
6553import org.mifos.mobile.core.ui.component.MifosErrorComponent
6654import org.mifos.mobile.core.ui.component.MifosLabelValueCard
6755import 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
395296internal 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-
454326data class LabelValueItem (
455327 val label : StringResource ,
456328 val value : String ,
0 commit comments