@@ -27,6 +27,7 @@ import mifos_mobile.feature.loan_application.generated.resources.feature_apply_l
27
27
import mifos_mobile.feature.loan_application.generated.resources.feature_apply_loan_status_success
28
28
import mifos_mobile.feature.loan_application.generated.resources.feature_apply_loan_status_success_action
29
29
import mifos_mobile.feature.loan_application.generated.resources.feature_apply_loan_status_success_tip
30
+ import okio.IOException
30
31
import org.jetbrains.compose.resources.StringResource
31
32
import org.jetbrains.compose.resources.getString
32
33
import org.mifos.mobile.core.common.DataState
@@ -41,6 +42,7 @@ import org.mifos.mobile.core.model.enums.LoanState
41
42
import org.mifos.mobile.core.ui.utils.AuthResult
42
43
import org.mifos.mobile.core.ui.utils.BaseViewModel
43
44
import org.mifos.mobile.core.ui.utils.ResultNavigator
45
+ import org.mifos.mobile.core.ui.utils.ScreenUiState
44
46
import org.mifos.mobile.core.ui.utils.observe
45
47
46
48
/* *
@@ -122,21 +124,22 @@ internal class ConfirmDetailsViewModel(
122
124
*/
123
125
@Suppress(" UnusedPrivateMember" )
124
126
private fun showLoading () {
125
- updateState { it.copy(dialogState = ConfirmDetailsDialogState .Loading ) }
127
+ updateState { it.copy(uiState = ScreenUiState .Loading ) }
126
128
}
127
129
128
130
/* *
129
131
* Sets the dialog state to an overlay loading spinner.
130
132
*/
131
133
private fun showOverlayLoading () {
132
- updateState { it.copy(dialogState = ConfirmDetailsDialogState . OverlayLoading ) }
134
+ updateState { it.copy(showOverlay = ! state.showOverlay ) }
133
135
}
134
136
135
137
/* *
136
138
* Displays an error dialog with a given message.
137
139
*
138
140
* @param error The [StringResource] for the error message to display.
139
141
*/
142
+ @Suppress(" UnusedPrivateMember" )
140
143
private fun showErrorDialog (error : StringResource ) {
141
144
updateState { it.copy(dialogState = ConfirmDetailsDialogState .Error (error)) }
142
145
}
@@ -230,13 +233,23 @@ internal class ConfirmDetailsViewModel(
230
233
is DataState .Success -> {
231
234
updateState {
232
235
it.copy(
236
+ showOverlay = false ,
233
237
loanTemplate = template.data,
234
238
)
235
239
}
236
240
sendAction(ConfirmDetailsAction .Internal .ApplyLoan )
237
241
}
238
242
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
+ }
240
253
}
241
254
}
242
255
}
@@ -268,6 +281,9 @@ internal class ConfirmDetailsViewModel(
268
281
private suspend fun handleLoanApplyStatus (status : DataState <String >) {
269
282
when (status) {
270
283
is DataState .Error -> {
284
+ updateState {
285
+ it.copy(showOverlay = false )
286
+ }
271
287
sendEvent(
272
288
ConfirmDetailsEvent .NavigateToStatus (
273
289
eventType = EventType .FAILURE .name,
@@ -343,7 +359,10 @@ internal data class ConfirmDetailsState(
343
359
val principalAmount : String ,
344
360
val details : Map <StringResource , String > = emptyMap(),
345
361
val loanTemplate : LoanTemplate ? = null ,
362
+
363
+ val showOverlay : Boolean = false ,
346
364
val dialogState : ConfirmDetailsDialogState ? = null ,
365
+ val uiState : ScreenUiState ? = ScreenUiState .Success ,
347
366
)
348
367
349
368
/* *
@@ -435,12 +454,6 @@ sealed interface ConfirmDetailsAction {
435
454
* shown on the confirm details screen.
436
455
*/
437
456
internal 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
-
444
457
/* *
445
458
* Represents a generic error dialog with a message.
446
459
* @property message The [StringResource] for the error message.
0 commit comments