Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package com.mifos.feature.client.clientLoanAccounts
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.mifos.feature.loan.newLoanAccount.NewLoanAccountRoute
import kotlinx.serialization.Serializable

@Serializable
Expand Down Expand Up @@ -42,3 +43,10 @@ fun NavController.navigateToClientLoanAccountsRoute(
) {
this.navigate(ClientLoanAccountsRoute(clientId = clientId))
}

fun NavController.navigateToClientLoanAccounts(clientId: Int) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's the corrected one

fun NavController.navigateToClientLoanAccounts(clientId: Int) {
    navigate(ClientLoanAccountsRoute(clientId = clientId)) {
        popUpTo<NewLoanAccountRoute> { inclusive = true }
        launchSingleTop = true
    }
}

navigate(ClientLoanAccountsRoute(clientId = clientId)) {
popUpTo<NewLoanAccountRoute> { inclusive = true }
launchSingleTop = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import com.mifos.feature.client.clientIdentifiersList.clientIdentifiersListDesti
import com.mifos.feature.client.clientIdentifiersList.navigateBackToUpdateClientIdentifiersListScreen
import com.mifos.feature.client.clientIdentifiersList.navigateToClientIdentifiersListScreen
import com.mifos.feature.client.clientLoanAccounts.clientLoanAccountsDestination
import com.mifos.feature.client.clientLoanAccounts.navigateToClientLoanAccounts
import com.mifos.feature.client.clientLoanAccounts.navigateToClientLoanAccountsRoute
import com.mifos.feature.client.clientPinpoint.PinpointClientScreen
import com.mifos.feature.client.clientProfile.clientProfileDestination
Expand Down Expand Up @@ -376,6 +377,7 @@ fun NavGraphBuilder.clientNavGraph(
onMoreInfoClicked = onMoreInfoClicked,
onDocumentsClicked = navController::navigateToDocumentListScreen,
onNotesClicked = navController::navigateToNoteScreen,
onLoanCreated = navController::navigateToClientLoanAccounts,
)

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()
NewLoanAccountEvent.LoanCreationSuccess -> onLoanCreated(state.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 @@ -36,6 +36,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.first
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -344,6 +345,8 @@ internal class NewLoanAccountViewModel(
),
)
}
delay(1000)
sendEvent(NewLoanAccountEvent.LoanCreationSuccess)
}
}
}
Expand Down Expand Up @@ -1122,6 +1125,7 @@ constructor(
sealed interface NewLoanAccountEvent {
data object NavigateBack : NewLoanAccountEvent
data object Finish : NewLoanAccountEvent
data object LoanCreationSuccess : NewLoanAccountEvent
}

sealed interface NewLoanAccountAction {
Expand Down
Loading