Skip to content

Commit aa9d7f8

Browse files
gurnoorpannubiplab1niyajali
authored
feat(loan): navigate to loan list after successful loan creation (#2674)
Co-authored-by: Biplab Dutta <biplabdutta27@gmail.com> Co-authored-by: Sk Niyaj Ali <niyaj639@gmail.com>
1 parent 2e9ce3f commit aa9d7f8

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

feature/client/src/commonMain/kotlin/com/mifos/feature/client/navigation/ClientNavigation.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import com.mifos.feature.client.clientIdentifiersAddUpdate.onNavigateToClientIde
5454
import com.mifos.feature.client.clientIdentifiersList.clientIdentifiersListDestination
5555
import com.mifos.feature.client.clientIdentifiersList.navigateBackToUpdateClientIdentifiersListScreen
5656
import com.mifos.feature.client.clientIdentifiersList.navigateToClientIdentifiersListScreen
57+
import com.mifos.feature.client.clientLoanAccounts.ClientLoanAccountsRoute
5758
import com.mifos.feature.client.clientLoanAccounts.clientLoanAccountsDestination
5859
import com.mifos.feature.client.clientLoanAccounts.navigateToClientLoanAccountsRoute
5960
import com.mifos.feature.client.clientPinpoint.PinpointClientScreen
@@ -98,6 +99,7 @@ import com.mifos.feature.loan.loanAccountProfile.navigateToLoanAccountProfileScr
9899
import com.mifos.feature.loan.loanAccountSummary.navigateToLoanAccountSummaryScreen
99100
import com.mifos.feature.loan.loanRepayment.navigateToLoanRepaymentScreen
100101
import com.mifos.feature.loan.navigation.loanDestination
102+
import com.mifos.feature.loan.newLoanAccount.NewLoanAccountRoute
101103
import com.mifos.feature.loan.newLoanAccount.navigateToNewLoanAccountRoute
102104
import com.mifos.feature.note.navigation.noteDestination
103105
import com.mifos.feature.note.notes.navigateToNoteScreen
@@ -376,6 +378,12 @@ fun NavGraphBuilder.clientNavGraph(
376378
onMoreInfoClicked = onMoreInfoClicked,
377379
onDocumentsClicked = navController::navigateToDocumentListScreen,
378380
onNotesClicked = navController::navigateToNoteScreen,
381+
onLoanCreated = { clientId ->
382+
navController.navigate(ClientLoanAccountsRoute(clientId = clientId)) {
383+
popUpTo<NewLoanAccountRoute> { inclusive = true }
384+
launchSingleTop = true
385+
}
386+
},
379387
)
380388

381389
dataTableRoute(

feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/navigation/LoanNavigation.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ fun NavGraphBuilder.loanDestination(
4141
onDocumentsClicked: (Int, String) -> Unit,
4242
onNotesClicked: (Int, String?) -> Unit,
4343
onMoreInfoClicked: (String, Int) -> Unit,
44+
onLoanCreated: (clientId: Int) -> Unit,
4445
) {
4546
loanAccountSummary(
4647
onBackPressed = navController::popBackStack,
@@ -76,6 +77,7 @@ fun NavGraphBuilder.loanDestination(
7677
newLoanAccountDestination(
7778
onNavigateBack = navController::popBackStack,
7879
onFinish = navController::popBackStack,
80+
onLoanCreated = onLoanCreated,
7981
navController = navController,
8082
)
8183

feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/newLoanAccount/NewLoanAccountRoute.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ fun NavGraphBuilder.newLoanAccountDestination(
2424
navController: NavController,
2525
onNavigateBack: () -> Unit,
2626
onFinish: () -> Unit,
27+
onLoanCreated: (clientId: Int) -> Unit,
2728
) {
2829
composable<NewLoanAccountRoute> {
2930
NewLoanAccountScreen(
3031
onNavigateBack = onNavigateBack,
3132
onFinish = onFinish,
33+
onLoanCreated = onLoanCreated,
3234
navController = navController,
3335
)
3436
}

feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/newLoanAccount/NewLoanAccountScreen.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ import com.mifos.feature.loan.newLoanAccount.pages.DetailsPage
7878
import com.mifos.feature.loan.newLoanAccount.pages.PreviewPage
7979
import com.mifos.feature.loan.newLoanAccount.pages.SchedulePage
8080
import com.mifos.feature.loan.newLoanAccount.pages.TermsPage
81-
import kotlinx.coroutines.delay
8281
import org.jetbrains.compose.resources.stringResource
8382
import org.koin.compose.viewmodel.koinViewModel
8483
import template.core.base.designsystem.theme.KptTheme
@@ -89,6 +88,7 @@ internal fun NewLoanAccountScreen(
8988
navController: NavController,
9089
onNavigateBack: () -> Unit,
9190
onFinish: () -> Unit,
91+
onLoanCreated: (clientId: Int) -> Unit,
9292
modifier: Modifier = Modifier,
9393
viewModel: NewLoanAccountViewModel = koinViewModel(),
9494
) {
@@ -98,6 +98,7 @@ internal fun NewLoanAccountScreen(
9898
when (event) {
9999
NewLoanAccountEvent.NavigateBack -> onNavigateBack()
100100
NewLoanAccountEvent.Finish -> onFinish()
101+
is NewLoanAccountEvent.LoanCreationSuccess -> onLoanCreated(event.clientId)
101102
}
102103
}
103104

@@ -239,14 +240,7 @@ private fun NewLoanAccountDialogs(
239240

240241
is NewLoanAccountState.DialogState.SuccessResponseStatus -> {
241242
LaunchedEffect(state.launchEffectKey) {
242-
snackbarHostState.showSnackbar(
243-
message = state.dialogState.msg,
244-
)
245-
246-
if (state.dialogState.successStatus) {
247-
delay(1000)
248-
onAction(NewLoanAccountAction.Finish)
249-
}
243+
snackbarHostState.showSnackbar(message = state.dialogState.msg)
250244
}
251245
}
252246

feature/loan/src/commonMain/kotlin/com/mifos/feature/loan/newLoanAccount/NewLoanAccountViewModel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import com.mifos.core.network.model.LoansPayload
3434
import com.mifos.core.ui.util.BaseViewModel
3535
import com.mifos.feature.loan.newLoanAccount.NewLoanAccountState.DialogState
3636
import com.mifos.room.entities.templates.loans.LoanTemplate
37+
import kotlinx.coroutines.delay
3738
import kotlinx.coroutines.flow.update
3839
import kotlinx.coroutines.launch
3940
import org.jetbrains.compose.resources.StringResource
@@ -322,6 +323,8 @@ internal class NewLoanAccountViewModel(
322323
),
323324
)
324325
}
326+
delay(1000)
327+
sendEvent(NewLoanAccountEvent.LoanCreationSuccess(state.clientId))
325328
}
326329
}
327330
}
@@ -1092,6 +1095,7 @@ constructor(
10921095
sealed interface NewLoanAccountEvent {
10931096
data object NavigateBack : NewLoanAccountEvent
10941097
data object Finish : NewLoanAccountEvent
1098+
data class LoanCreationSuccess(val clientId: Int) : NewLoanAccountEvent
10951099
}
10961100

10971101
sealed interface NewLoanAccountAction {

0 commit comments

Comments
 (0)