@@ -27,6 +27,7 @@ import mifos_mobile.feature.loan_application.generated.resources.feature_apply_l
2727import mifos_mobile.feature.loan_application.generated.resources.feature_apply_loan_status_success
2828import mifos_mobile.feature.loan_application.generated.resources.feature_apply_loan_status_success_action
2929import mifos_mobile.feature.loan_application.generated.resources.feature_apply_loan_status_success_tip
30+ import okio.IOException
3031import org.jetbrains.compose.resources.StringResource
3132import org.jetbrains.compose.resources.getString
3233import org.mifos.mobile.core.common.DataState
@@ -41,6 +42,7 @@ import org.mifos.mobile.core.model.enums.LoanState
4142import org.mifos.mobile.core.ui.utils.AuthResult
4243import org.mifos.mobile.core.ui.utils.BaseViewModel
4344import org.mifos.mobile.core.ui.utils.ResultNavigator
45+ import org.mifos.mobile.core.ui.utils.ScreenUiState
4446import org.mifos.mobile.core.ui.utils.observe
4547
4648/* *
@@ -122,21 +124,22 @@ internal class ConfirmDetailsViewModel(
122124 */
123125 @Suppress(" UnusedPrivateMember" )
124126 private fun showLoading () {
125- updateState { it.copy(dialogState = ConfirmDetailsDialogState .Loading ) }
127+ updateState { it.copy(uiState = ScreenUiState .Loading ) }
126128 }
127129
128130 /* *
129131 * Sets the dialog state to an overlay loading spinner.
130132 */
131133 private fun showOverlayLoading () {
132- updateState { it.copy(dialogState = ConfirmDetailsDialogState . OverlayLoading ) }
134+ updateState { it.copy(showOverlay = ! state.showOverlay ) }
133135 }
134136
135137 /* *
136138 * Displays an error dialog with a given message.
137139 *
138140 * @param error The [StringResource] for the error message to display.
139141 */
142+ @Suppress(" UnusedPrivateMember" )
140143 private fun showErrorDialog (error : StringResource ) {
141144 updateState { it.copy(dialogState = ConfirmDetailsDialogState .Error (error)) }
142145 }
@@ -230,13 +233,23 @@ internal class ConfirmDetailsViewModel(
230233 is DataState .Success -> {
231234 updateState {
232235 it.copy(
236+ showOverlay = false ,
233237 loanTemplate = template.data,
234238 )
235239 }
236240 sendAction(ConfirmDetailsAction .Internal .ApplyLoan )
237241 }
238242 is DataState .Error -> {
239- showErrorDialog(Res .string.feature_apply_loan_error_server)
243+ updateState {
244+ it.copy(
245+ showOverlay = false ,
246+ uiState = if (template.exception is IOException ) {
247+ ScreenUiState .Network
248+ } else {
249+ ScreenUiState .Error (Res .string.feature_apply_loan_error_server)
250+ },
251+ )
252+ }
240253 }
241254 }
242255 }
@@ -268,6 +281,9 @@ internal class ConfirmDetailsViewModel(
268281 private suspend fun handleLoanApplyStatus (status : DataState <String >) {
269282 when (status) {
270283 is DataState .Error -> {
284+ updateState {
285+ it.copy(showOverlay = false )
286+ }
271287 sendEvent(
272288 ConfirmDetailsEvent .NavigateToStatus (
273289 eventType = EventType .FAILURE .name,
@@ -343,7 +359,10 @@ internal data class ConfirmDetailsState(
343359 val principalAmount : String ,
344360 val details : Map <StringResource , String > = emptyMap(),
345361 val loanTemplate : LoanTemplate ? = null ,
362+
363+ val showOverlay : Boolean = false ,
346364 val dialogState : ConfirmDetailsDialogState ? = null ,
365+ val uiState : ScreenUiState ? = ScreenUiState .Success ,
347366)
348367
349368/* *
@@ -435,12 +454,6 @@ sealed interface ConfirmDetailsAction {
435454 * shown on the confirm details screen.
436455 */
437456internal sealed interface ConfirmDetailsDialogState {
438- /* * Represents an overlay loading state. */
439- data object OverlayLoading : ConfirmDetailsDialogState
440-
441- /* * Represents a full-screen loading state. */
442- data object Loading : ConfirmDetailsDialogState
443-
444457 /* *
445458 * Represents a generic error dialog with a message.
446459 * @property message The [StringResource] for the error message.
0 commit comments