Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ import org.mifos.mobile.core.designsystem.component.MifosElevatedScaffold
import org.mifos.mobile.core.designsystem.theme.DesignToken
import org.mifos.mobile.core.designsystem.theme.MifosTypography
import org.mifos.mobile.core.ui.component.MifosDetailsCard
import org.mifos.mobile.core.ui.component.MifosErrorComponent
import org.mifos.mobile.core.ui.component.MifosPoweredCard
import org.mifos.mobile.core.ui.component.MifosProgressIndicator
import org.mifos.mobile.core.ui.component.MifosProgressIndicatorOverlay
import org.mifos.mobile.core.ui.utils.EventsEffect
import org.mifos.mobile.core.ui.utils.ScreenUiState

@Composable
internal fun ConfirmDetailsScreen(
Expand Down Expand Up @@ -99,10 +101,6 @@ internal fun ConfirmDetailsDialog(
)
}

ConfirmDetailsDialogState.Loading -> MifosProgressIndicator()

ConfirmDetailsDialogState.OverlayLoading -> MifosProgressIndicatorOverlay()

null -> {}
}
}
Expand All @@ -126,27 +124,52 @@ internal fun ConfirmDetailsScreenContent(
}
},
) {
Column(
modifier = modifier
.padding(DesignToken.padding.large)
.padding(top = DesignToken.padding.medium)
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(DesignToken.spacing.extraLarge),
) {
MifosDetailsCard(state.details)
when (state.uiState) {
is ScreenUiState.Error -> {
MifosErrorComponent(
isRetryEnabled = false,
message = stringResource(state.uiState.message),
)
}

ScreenUiState.Loading -> MifosProgressIndicator()

MifosButton(
modifier = Modifier.fillMaxWidth().height(DesignToken.sizes.inputHeight),
onClick = {
onAction(ConfirmDetailsAction.NavigateToAuthenticate)
},
shape = DesignToken.shapes.medium,
) {
Text(
text = stringResource(Res.string.feature_apply_loan_title),
style = MifosTypography.titleMedium,
ScreenUiState.Network -> {
MifosErrorComponent(
isNetworkConnected = false,
isRetryEnabled = false,
)
}

ScreenUiState.Success -> {
Column(
modifier = modifier
.padding(DesignToken.padding.large)
.padding(top = DesignToken.padding.medium)
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(DesignToken.spacing.extraLarge),
) {
MifosDetailsCard(state.details)

MifosButton(
modifier = Modifier.fillMaxWidth().height(DesignToken.sizes.inputHeight),
onClick = {
onAction(ConfirmDetailsAction.NavigateToAuthenticate)
},
shape = DesignToken.shapes.medium,
) {
Text(
text = stringResource(Res.string.feature_apply_loan_title),
style = MifosTypography.titleMedium,
)
}
}

if (state.showOverlay) {
MifosProgressIndicatorOverlay()
}
}
else -> { }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import mifos_mobile.feature.loan_application.generated.resources.feature_apply_l
import mifos_mobile.feature.loan_application.generated.resources.feature_apply_loan_status_success
import mifos_mobile.feature.loan_application.generated.resources.feature_apply_loan_status_success_action
import mifos_mobile.feature.loan_application.generated.resources.feature_apply_loan_status_success_tip
import okio.IOException
import org.jetbrains.compose.resources.StringResource
import org.jetbrains.compose.resources.getString
import org.mifos.mobile.core.common.DataState
Expand All @@ -41,6 +42,7 @@ import org.mifos.mobile.core.model.enums.LoanState
import org.mifos.mobile.core.ui.utils.AuthResult
import org.mifos.mobile.core.ui.utils.BaseViewModel
import org.mifos.mobile.core.ui.utils.ResultNavigator
import org.mifos.mobile.core.ui.utils.ScreenUiState
import org.mifos.mobile.core.ui.utils.observe

/**
Expand Down Expand Up @@ -122,21 +124,22 @@ internal class ConfirmDetailsViewModel(
*/
@Suppress("UnusedPrivateMember")
private fun showLoading() {
updateState { it.copy(dialogState = ConfirmDetailsDialogState.Loading) }
updateState { it.copy(uiState = ScreenUiState.Loading) }
}

/**
* Sets the dialog state to an overlay loading spinner.
*/
private fun showOverlayLoading() {
updateState { it.copy(dialogState = ConfirmDetailsDialogState.OverlayLoading) }
updateState { it.copy(showOverlay = !state.showOverlay) }
}

/**
* Displays an error dialog with a given message.
*
* @param error The [StringResource] for the error message to display.
*/
@Suppress("UnusedPrivateMember")
private fun showErrorDialog(error: StringResource) {
updateState { it.copy(dialogState = ConfirmDetailsDialogState.Error(error)) }
}
Expand Down Expand Up @@ -230,13 +233,23 @@ internal class ConfirmDetailsViewModel(
is DataState.Success -> {
updateState {
it.copy(
showOverlay = false,
loanTemplate = template.data,
)
}
sendAction(ConfirmDetailsAction.Internal.ApplyLoan)
}
is DataState.Error -> {
showErrorDialog(Res.string.feature_apply_loan_error_server)
updateState {
it.copy(
showOverlay = false,
uiState = if (template.exception is IOException) {
ScreenUiState.Network
} else {
ScreenUiState.Error(Res.string.feature_apply_loan_error_server)
},
)
}
}
}
}
Expand Down Expand Up @@ -268,6 +281,9 @@ internal class ConfirmDetailsViewModel(
private suspend fun handleLoanApplyStatus(status: DataState<String>) {
when (status) {
is DataState.Error -> {
updateState {
it.copy(showOverlay = false)
}
sendEvent(
ConfirmDetailsEvent.NavigateToStatus(
eventType = EventType.FAILURE.name,
Expand Down Expand Up @@ -343,7 +359,10 @@ internal data class ConfirmDetailsState(
val principalAmount: String,
val details: Map<StringResource, String> = emptyMap(),
val loanTemplate: LoanTemplate? = null,

val showOverlay: Boolean = false,
val dialogState: ConfirmDetailsDialogState? = null,
val uiState: ScreenUiState? = ScreenUiState.Success,
)

/**
Expand Down Expand Up @@ -435,12 +454,6 @@ sealed interface ConfirmDetailsAction {
* shown on the confirm details screen.
*/
internal sealed interface ConfirmDetailsDialogState {
/** Represents an overlay loading state. */
data object OverlayLoading : ConfirmDetailsDialogState

/** Represents a full-screen loading state. */
data object Loading : ConfirmDetailsDialogState

/**
* Represents a generic error dialog with a message.
* @property message The [StringResource] for the error message.
Expand Down
Loading
Loading