Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.mifos.feature.client.clientIdentifiersAddUpdate.onNavigateToClientIde
import com.mifos.feature.client.clientIdentifiersList.clientIdentifiersListDestination
import com.mifos.feature.client.clientIdentifiersList.navigateBackToUpdateClientIdentifiersListScreen
import com.mifos.feature.client.clientIdentifiersList.navigateToClientIdentifiersListScreen
import com.mifos.feature.client.clientLoanAccounts.ClientLoanAccountsRoute
import com.mifos.feature.client.clientLoanAccounts.clientLoanAccountsDestination
import com.mifos.feature.client.clientLoanAccounts.navigateToClientLoanAccountsRoute
import com.mifos.feature.client.clientPinpoint.PinpointClientScreen
Expand Down Expand Up @@ -98,6 +99,7 @@ import com.mifos.feature.loan.loanAccountProfile.navigateToLoanAccountProfileScr
import com.mifos.feature.loan.loanAccountSummary.navigateToLoanAccountSummaryScreen
import com.mifos.feature.loan.loanRepayment.navigateToLoanRepaymentScreen
import com.mifos.feature.loan.navigation.loanDestination
import com.mifos.feature.loan.newLoanAccount.NewLoanAccountRoute
import com.mifos.feature.loan.newLoanAccount.navigateToNewLoanAccountRoute
import com.mifos.feature.note.navigation.noteDestination
import com.mifos.feature.note.notes.navigateToNoteScreen
Expand Down Expand Up @@ -376,6 +378,12 @@ fun NavGraphBuilder.clientNavGraph(
onMoreInfoClicked = onMoreInfoClicked,
onDocumentsClicked = navController::navigateToDocumentListScreen,
onNotesClicked = navController::navigateToNoteScreen,
onLoanCreated = { clientId ->
navController.navigate(ClientLoanAccountsRoute(clientId = clientId)) {
popUpTo<NewLoanAccountRoute> { inclusive = true }
launchSingleTop = true
}
},
)

dataTableRoute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fun NavGraphBuilder.loanDestination(
onDocumentsClicked: (Int, String) -> Unit,
onNotesClicked: (Int, String?) -> Unit,
onMoreInfoClicked: (String, Int) -> Unit,
onLoanCreated: (clientId: Int) -> Unit,
) {
loanAccountSummary(
onBackPressed = navController::popBackStack,
Expand Down Expand Up @@ -76,6 +77,7 @@ fun NavGraphBuilder.loanDestination(
newLoanAccountDestination(
onNavigateBack = navController::popBackStack,
onFinish = navController::popBackStack,
onLoanCreated = onLoanCreated,
navController = navController,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ fun NavGraphBuilder.newLoanAccountDestination(
navController: NavController,
onNavigateBack: () -> Unit,
onFinish: () -> Unit,
onLoanCreated: (clientId: Int) -> Unit,
) {
composable<NewLoanAccountRoute> {
NewLoanAccountScreen(
onNavigateBack = onNavigateBack,
onFinish = onFinish,
onLoanCreated = onLoanCreated,
navController = navController,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ import com.mifos.feature.loan.newLoanAccount.pages.DetailsPage
import com.mifos.feature.loan.newLoanAccount.pages.PreviewPage
import com.mifos.feature.loan.newLoanAccount.pages.SchedulePage
import com.mifos.feature.loan.newLoanAccount.pages.TermsPage
import kotlinx.coroutines.delay
import org.jetbrains.compose.resources.stringResource
import org.koin.compose.viewmodel.koinViewModel
import template.core.base.designsystem.theme.KptTheme
Expand All @@ -89,6 +88,7 @@ internal fun NewLoanAccountScreen(
navController: NavController,
onNavigateBack: () -> Unit,
onFinish: () -> Unit,
onLoanCreated: (clientId: Int) -> Unit,
modifier: Modifier = Modifier,
viewModel: NewLoanAccountViewModel = koinViewModel(),
) {
Expand All @@ -98,6 +98,7 @@ internal fun NewLoanAccountScreen(
when (event) {
NewLoanAccountEvent.NavigateBack -> onNavigateBack()
NewLoanAccountEvent.Finish -> onFinish()
is NewLoanAccountEvent.LoanCreationSuccess -> onLoanCreated(event.clientId)
}
}

Expand Down Expand Up @@ -239,14 +240,7 @@ private fun NewLoanAccountDialogs(

is NewLoanAccountState.DialogState.SuccessResponseStatus -> {
LaunchedEffect(state.launchEffectKey) {
snackbarHostState.showSnackbar(
message = state.dialogState.msg,
)

if (state.dialogState.successStatus) {
delay(1000)
onAction(NewLoanAccountAction.Finish)
}
snackbarHostState.showSnackbar(message = state.dialogState.msg)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.mifos.core.network.model.LoansPayload
import com.mifos.core.ui.util.BaseViewModel
import com.mifos.feature.loan.newLoanAccount.NewLoanAccountState.DialogState
import com.mifos.room.entities.templates.loans.LoanTemplate
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.StringResource
Expand Down Expand Up @@ -322,6 +323,8 @@ internal class NewLoanAccountViewModel(
),
)
}
delay(1000)
sendEvent(NewLoanAccountEvent.LoanCreationSuccess(state.clientId))
}
}
}
Expand Down Expand Up @@ -1092,6 +1095,7 @@ constructor(
sealed interface NewLoanAccountEvent {
data object NavigateBack : NewLoanAccountEvent
data object Finish : NewLoanAccountEvent
data class LoanCreationSuccess(val clientId: Int) : NewLoanAccountEvent
}

sealed interface NewLoanAccountAction {
Expand Down
Loading