mirror of
https://github.com/openMF/mifos-mobile.git
synced 2026-02-06 11:26:51 +00:00
refactor: apis setup for receiving server messages (#2904)
This commit is contained in:
parent
dd40f1e728
commit
e583dc3d72
@ -9,6 +9,8 @@
|
||||
*/
|
||||
package org.mifos.mobile.core.data.repositoryImpl
|
||||
|
||||
import io.ktor.client.plugins.ClientRequestException
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
@ -43,16 +45,10 @@ class BeneficiaryRepositoryImp(
|
||||
try {
|
||||
val response = dataManager.beneficiaryApi.createBeneficiary(beneficiaryPayload)
|
||||
|
||||
if (response.status.value != 200) {
|
||||
val errorMessage = extractErrorMessage(response)
|
||||
return@withContext DataState.Error(
|
||||
Exception(errorMessage),
|
||||
null,
|
||||
)
|
||||
}
|
||||
DataState.Success("Created successfully")
|
||||
} catch (e: Exception) {
|
||||
DataState.Error(e, null)
|
||||
DataState.Success(response.bodyAsText())
|
||||
} catch (e: ClientRequestException) {
|
||||
val errorMessage = extractErrorMessage(e.response)
|
||||
DataState.Error(Exception(errorMessage), null)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -63,18 +59,11 @@ class BeneficiaryRepositoryImp(
|
||||
): DataState<String> {
|
||||
return withContext(ioDispatcher) {
|
||||
try {
|
||||
val response =
|
||||
beneficiaryId?.let { dataManager.beneficiaryApi.updateBeneficiary(it, payload) }
|
||||
if (response?.status?.value != 200) {
|
||||
val errorMessage = response?.let { extractErrorMessage(it) }
|
||||
return@withContext DataState.Error(
|
||||
Exception(errorMessage ?: "Something went wrong"),
|
||||
null,
|
||||
)
|
||||
}
|
||||
DataState.Success("Updated successfully")
|
||||
} catch (e: Exception) {
|
||||
DataState.Error(e, null)
|
||||
val response = dataManager.beneficiaryApi.updateBeneficiary(beneficiaryId!!, payload)
|
||||
DataState.Success(response.bodyAsText())
|
||||
} catch (e: ClientRequestException) {
|
||||
val errorMessage = extractErrorMessage(e.response)
|
||||
DataState.Error(Exception(errorMessage), null)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -82,18 +71,12 @@ class BeneficiaryRepositoryImp(
|
||||
override suspend fun deleteBeneficiary(beneficiaryId: Long?): DataState<String> {
|
||||
return withContext(ioDispatcher) {
|
||||
try {
|
||||
val response =
|
||||
beneficiaryId?.let { dataManager.beneficiaryApi.deleteBeneficiary(it) }
|
||||
if (response?.status?.value != 200) {
|
||||
val errorMessage = response?.let { extractErrorMessage(it) }
|
||||
return@withContext DataState.Error(
|
||||
Exception(errorMessage ?: "Something went wrong"),
|
||||
null,
|
||||
)
|
||||
}
|
||||
DataState.Success("Deleted successfully")
|
||||
} catch (e: Exception) {
|
||||
DataState.Error(e, null)
|
||||
val response = dataManager.beneficiaryApi.deleteBeneficiary(beneficiaryId!!)
|
||||
|
||||
DataState.Success(response.bodyAsText())
|
||||
} catch (e: ClientRequestException) {
|
||||
val errorMessage = extractErrorMessage(e.response)
|
||||
DataState.Error(Exception(errorMessage), null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
*/
|
||||
package org.mifos.mobile.core.data.repositoryImpl
|
||||
|
||||
import io.ktor.client.plugins.ClientRequestException
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
@ -17,6 +19,7 @@ import kotlinx.coroutines.withContext
|
||||
import org.mifos.mobile.core.common.DataState
|
||||
import org.mifos.mobile.core.common.asDataStateFlow
|
||||
import org.mifos.mobile.core.data.repository.GuarantorRepository
|
||||
import org.mifos.mobile.core.data.util.extractErrorMessage
|
||||
import org.mifos.mobile.core.model.entity.guarantor.GuarantorApplicationPayload
|
||||
import org.mifos.mobile.core.model.entity.guarantor.GuarantorPayload
|
||||
import org.mifos.mobile.core.model.entity.guarantor.GuarantorTemplatePayload
|
||||
@ -36,13 +39,14 @@ class GuarantorRepositoryImp(
|
||||
loanId: Long?,
|
||||
payload: GuarantorApplicationPayload?,
|
||||
): DataState<String> {
|
||||
return try {
|
||||
withContext(ioDispatcher) {
|
||||
dataManager.guarantorApi.createGuarantor(loanId!!, payload)
|
||||
return withContext(ioDispatcher) {
|
||||
try {
|
||||
val response = dataManager.guarantorApi.createGuarantor(loanId!!, payload)
|
||||
DataState.Success(response.bodyAsText())
|
||||
} catch (e: ClientRequestException) {
|
||||
val errorMessage = extractErrorMessage(e.response)
|
||||
DataState.Error(Exception(errorMessage), null)
|
||||
}
|
||||
DataState.Success("Created successfully")
|
||||
} catch (e: Exception) {
|
||||
DataState.Error(e, null)
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,24 +55,30 @@ class GuarantorRepositoryImp(
|
||||
loanId: Long?,
|
||||
guarantorId: Long?,
|
||||
): DataState<String> {
|
||||
return try {
|
||||
withContext(ioDispatcher) {
|
||||
dataManager.guarantorApi.updateGuarantor(payload, loanId!!, guarantorId!!)
|
||||
return withContext(ioDispatcher) {
|
||||
try {
|
||||
val response = dataManager.guarantorApi.updateGuarantor(
|
||||
payload,
|
||||
loanId!!,
|
||||
guarantorId!!,
|
||||
)
|
||||
DataState.Success(response.bodyAsText())
|
||||
} catch (e: ClientRequestException) {
|
||||
val errorMessage = extractErrorMessage(e.response)
|
||||
DataState.Error(Exception(errorMessage), null)
|
||||
}
|
||||
DataState.Success("Created successfully")
|
||||
} catch (e: Exception) {
|
||||
DataState.Error(e, null)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteGuarantor(loanId: Long?, guarantorId: Long?): DataState<String> {
|
||||
return try {
|
||||
withContext(ioDispatcher) {
|
||||
dataManager.guarantorApi.deleteGuarantor(loanId!!, guarantorId!!)
|
||||
return withContext(ioDispatcher) {
|
||||
try {
|
||||
val response = dataManager.guarantorApi.deleteGuarantor(loanId!!, guarantorId!!)
|
||||
DataState.Success(response.bodyAsText())
|
||||
} catch (e: ClientRequestException) {
|
||||
val errorMessage = extractErrorMessage(e.response)
|
||||
DataState.Error(Exception(errorMessage), null)
|
||||
}
|
||||
DataState.Success("Created successfully")
|
||||
} catch (e: Exception) {
|
||||
DataState.Error(e, null)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
*/
|
||||
package org.mifos.mobile.core.data.repositoryImpl
|
||||
|
||||
import io.ktor.client.plugins.ClientRequestException
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
@ -50,16 +52,10 @@ class LoanRepositoryImp(
|
||||
try {
|
||||
val response =
|
||||
dataManager.loanAccountsListApi.withdrawLoanAccount(loanId!!, loanWithdraw)
|
||||
if (response.status.value != 200) {
|
||||
val errorMessage = extractErrorMessage(response)
|
||||
return@withContext DataState.Error(
|
||||
Exception(errorMessage),
|
||||
null,
|
||||
)
|
||||
}
|
||||
DataState.Success("withdraw successful")
|
||||
} catch (e: Exception) {
|
||||
DataState.Error(e, null)
|
||||
DataState.Success(response.bodyAsText())
|
||||
} catch (e: ClientRequestException) {
|
||||
val errorMessage = extractErrorMessage(e.response)
|
||||
DataState.Error(Exception(errorMessage), null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,16 +56,10 @@ class SavingsAccountRepositoryImp(
|
||||
try {
|
||||
val response =
|
||||
dataManager.savingAccountsListApi.submitSavingAccountApplication(payload)
|
||||
if (response.status.value != 200) {
|
||||
val errorMessage = extractErrorMessage(response)
|
||||
return@withContext DataState.Error(
|
||||
Exception(errorMessage),
|
||||
null,
|
||||
)
|
||||
}
|
||||
DataState.Success("Submitted successfully")
|
||||
} catch (e: Exception) {
|
||||
DataState.Error(e, null)
|
||||
DataState.Success(response.bodyAsText())
|
||||
} catch (e: ClientRequestException) {
|
||||
val errorMessage = extractErrorMessage(e.response)
|
||||
DataState.Error(Exception(errorMessage), null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,21 +105,14 @@ class UserAuthRepositoryImp(
|
||||
password = newPassword,
|
||||
repeatPassword = confirmPassword,
|
||||
)
|
||||
return try {
|
||||
withContext(ioDispatcher) {
|
||||
val result = dataManager.userDetailsApi.updateAccountPassword(payload)
|
||||
val errorMessage = result.bodyAsText()
|
||||
when (result.status.value) {
|
||||
200 -> DataState.Success("User Verified Successfully")
|
||||
else -> DataState.Error(
|
||||
Exception("Error in verifying user: $errorMessage"),
|
||||
null,
|
||||
)
|
||||
}
|
||||
return withContext(ioDispatcher) {
|
||||
try {
|
||||
val response = dataManager.userDetailsApi.updateAccountPassword(payload)
|
||||
DataState.Success(response.bodyAsText())
|
||||
} catch (e: ClientRequestException) {
|
||||
val errorMessage = extractErrorMessage(e.response)
|
||||
DataState.Error(Exception(errorMessage), null)
|
||||
}
|
||||
DataState.Success("Password Updated Successfully")
|
||||
} catch (e: Exception) {
|
||||
DataState.Error(e, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +54,7 @@ import androidx.compose.material.icons.rounded.Home
|
||||
import androidx.compose.material.icons.rounded.SwapHoriz
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import fluent.ui.system.icons.FluentIcons
|
||||
import fluent.ui.system.icons.colored.Alert
|
||||
import fluent.ui.system.icons.colored.Warning
|
||||
import fluent.ui.system.icons.filled.ArrowDownload
|
||||
import fluent.ui.system.icons.filled.CaretDown
|
||||
@ -210,4 +211,6 @@ object MifosIcons {
|
||||
val CoinMultiple = FluentIcons.Filled.CoinMultiple
|
||||
|
||||
val Warning = FluentIcons.Colored.Warning
|
||||
|
||||
val Notification = FluentIcons.Colored.Alert
|
||||
}
|
||||
|
||||
@ -11,7 +11,9 @@ package org.mifos.mobile.core.ui.component
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.Icon
|
||||
@ -20,6 +22,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
@ -30,7 +33,9 @@ import org.jetbrains.compose.resources.StringResource
|
||||
import org.jetbrains.compose.resources.painterResource
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import org.mifos.mobile.core.designsystem.icon.MifosIcons
|
||||
import org.mifos.mobile.core.designsystem.theme.DesignToken
|
||||
import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
|
||||
import org.mifos.mobile.core.designsystem.theme.MifosTypography
|
||||
import org.mifos.mobile.core.ui.utils.DevicePreview
|
||||
|
||||
@Composable
|
||||
@ -47,16 +52,15 @@ fun EmptyDataView(
|
||||
) {
|
||||
Icon(
|
||||
modifier = Modifier
|
||||
.size(100.dp)
|
||||
.padding(bottom = 12.dp),
|
||||
.size(50.dp),
|
||||
imageVector = icon,
|
||||
contentDescription = null,
|
||||
tint = Color.Unspecified,
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(DesignToken.spacing.small))
|
||||
Text(
|
||||
modifier = Modifier.padding(horizontal = 20.dp),
|
||||
text = errorString ?: stringResource(error),
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
style = MifosTypography.titleSmallEmphasized,
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
package org.mifos.mobile.feature.beneficiary.beneficiaryApplication
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
@ -31,7 +30,6 @@ import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.withStyle
|
||||
import androidx.compose.ui.unit.dp
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.Res
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.account_number
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.beneficiary_name
|
||||
@ -65,7 +63,7 @@ internal fun BeneficiaryApplicationContent(
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(
|
||||
horizontal = DesignToken.padding.large,
|
||||
vertical = DesignToken.padding.extraLargeIncreased
|
||||
vertical = DesignToken.padding.extraLargeIncreased,
|
||||
),
|
||||
) {
|
||||
MifosOutlinedTextField(
|
||||
@ -90,7 +88,7 @@ internal fun BeneficiaryApplicationContent(
|
||||
label = stringResource(Res.string.account_number),
|
||||
config = MifosTextFieldConfig(
|
||||
isError = state.accountNumberError != null && state.beneficiaryState !=
|
||||
BeneficiaryState.UPDATE,
|
||||
BeneficiaryState.UPDATE,
|
||||
enabled = state.beneficiaryState != BeneficiaryState.UPDATE,
|
||||
errorText = state.accountNumberError?.let { stringResource(it) } ?: "",
|
||||
keyboardOptions = KeyboardOptions(
|
||||
@ -115,8 +113,6 @@ internal fun BeneficiaryApplicationContent(
|
||||
supportingText = state.accountTypeError?.let { stringResource(it) } ?: "",
|
||||
)
|
||||
|
||||
|
||||
|
||||
MifosOutlinedTextField(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
value = state.officeName,
|
||||
@ -173,7 +169,7 @@ internal fun BeneficiaryApplicationContent(
|
||||
onAction(BeneficiaryApplicationAction.NavigateToQR)
|
||||
},
|
||||
style = MifosTypography.labelMediumEmphasized,
|
||||
textAlign = TextAlign.Center
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ fun NavController.navigateToManualBeneficiaryAddScreen(
|
||||
|
||||
fun NavGraphBuilder.manualBeneficiaryAddDestination(
|
||||
navigateBack: () -> Unit,
|
||||
navigateToQR:()->Unit,
|
||||
navigateToQR: () -> Unit,
|
||||
navigateToConfirmationScreen: (
|
||||
beneficiaryId: Int,
|
||||
beneficiaryState: String,
|
||||
@ -47,7 +47,7 @@ fun NavGraphBuilder.manualBeneficiaryAddDestination(
|
||||
BeneficiaryApplicationScreen(
|
||||
navigateBack = navigateBack,
|
||||
navigateToConfirmationScreen = navigateToConfirmationScreen,
|
||||
navigateToQR=navigateToQR
|
||||
navigateToQR = navigateToQR,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,18 +9,14 @@
|
||||
*/
|
||||
package org.mifos.mobile.feature.beneficiary.beneficiaryApplication
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import co.touchlab.kermit.Logger
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.Res
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.error_fetching_beneficiary_template
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
@ -32,7 +28,6 @@ import org.mifos.mobile.core.model.enums.BeneficiaryState
|
||||
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
|
||||
|
||||
@Composable
|
||||
@ -88,7 +83,6 @@ internal fun BeneficiaryApplicationScreen(
|
||||
{ viewModel.trySendAction(it) }
|
||||
},
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ -137,12 +131,12 @@ private fun BeneficiaryApplicationScreen(
|
||||
)
|
||||
}
|
||||
},
|
||||
){
|
||||
if (state.dialogState == null && state.template!=null) {
|
||||
BeneficiaryApplicationContent(
|
||||
state = state,
|
||||
onAction = onAction,
|
||||
)
|
||||
) {
|
||||
if (state.dialogState == null && state.template != null) {
|
||||
BeneficiaryApplicationContent(
|
||||
state = state,
|
||||
onAction = onAction,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,7 +184,12 @@ internal class BeneficiaryApplicationViewModel(
|
||||
beneficiaryRepositoryImp.beneficiaryList(),
|
||||
beneficiaryRepositoryImp.beneficiaryTemplate(),
|
||||
) { beneficiaryList, beneficiaryTemplate ->
|
||||
sendAction(BeneficiaryApplicationAction.Internal.ReceiveBeneficiaryResult(beneficiaryList, beneficiaryTemplate))
|
||||
sendAction(
|
||||
BeneficiaryApplicationAction.Internal.ReceiveBeneficiaryResult(
|
||||
beneficiaryList,
|
||||
beneficiaryTemplate,
|
||||
),
|
||||
)
|
||||
}.catch { error ->
|
||||
setDialogState(
|
||||
BeneficiaryApplicationState.DialogState.Error(
|
||||
@ -259,7 +264,8 @@ internal class BeneficiaryApplicationViewModel(
|
||||
null
|
||||
},
|
||||
|
||||
accountNumberError = if (state.beneficiaryState != BeneficiaryState.UPDATE && state.accountNumber.trim().isEmpty()
|
||||
accountNumberError = if (
|
||||
state.beneficiaryState != BeneficiaryState.UPDATE && state.accountNumber.trim().isEmpty()
|
||||
) {
|
||||
hasError = true
|
||||
Res.string.enter_account_number
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
*
|
||||
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
|
||||
*/
|
||||
@file:Suppress("MatchingDeclarationName")
|
||||
|
||||
package org.mifos.mobile.feature.beneficiary.beneficiaryApplicationConfirmation
|
||||
|
||||
import androidx.navigation.NavController
|
||||
|
||||
@ -22,15 +22,7 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.Res
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.account_number_label
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.account_type_label
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.account_type_loan
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.account_type_savings
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.account_type_share
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.beneficiary_name_label
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.confirm_details
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.office_label
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.transfer_limit_label
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.validate_details
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import org.koin.compose.viewmodel.koinViewModel
|
||||
|
||||
@ -28,14 +28,12 @@ import mifos_mobile.feature.beneficiary.generated.resources.beneficiary_created_
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.beneficiary_created_successfully_account
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.beneficiary_creation_failed
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.beneficiary_name_label
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.beneficiary_updated_successfully
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.office_label
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.transfer_limit_label
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.try_again
|
||||
import mifos_mobile.feature.beneficiary.generated.resources.update_beneficiary
|
||||
import org.jetbrains.compose.resources.StringResource
|
||||
import org.jetbrains.compose.resources.getString
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import org.mifos.mobile.core.common.DataState
|
||||
import org.mifos.mobile.core.data.repository.BeneficiaryRepository
|
||||
import org.mifos.mobile.core.data.util.NetworkMonitor
|
||||
@ -57,7 +55,11 @@ internal class BeneficiaryApplicationConfirmationViewModel(
|
||||
private val networkMonitor: NetworkMonitor,
|
||||
private val navigator: ResultNavigator,
|
||||
private val savedStateHandle: SavedStateHandle,
|
||||
) : BaseViewModel<BeneficiaryApplicationConfirmationState, BeneficiaryApplicationConfirmationEvent, BeneficiaryApplicationConfirmationAction>(
|
||||
) : BaseViewModel<
|
||||
BeneficiaryApplicationConfirmationState,
|
||||
BeneficiaryApplicationConfirmationEvent,
|
||||
BeneficiaryApplicationConfirmationAction,
|
||||
>(
|
||||
initialState = run {
|
||||
val route = savedStateHandle.toRoute<BeneficiaryApplicationConfirmationNavRoute>()
|
||||
BeneficiaryApplicationConfirmationState(
|
||||
@ -89,7 +91,9 @@ internal class BeneficiaryApplicationConfirmationViewModel(
|
||||
/**
|
||||
* Updates the ViewModel state using the provided transformation.
|
||||
*/
|
||||
private fun updateState(update: (BeneficiaryApplicationConfirmationState) -> BeneficiaryApplicationConfirmationState) {
|
||||
private fun updateState(
|
||||
update: (BeneficiaryApplicationConfirmationState) -> BeneficiaryApplicationConfirmationState,
|
||||
) {
|
||||
mutableStateFlow.update(update)
|
||||
}
|
||||
|
||||
@ -135,7 +139,6 @@ internal class BeneficiaryApplicationConfirmationViewModel(
|
||||
private fun createBeneficiary(payload: BeneficiaryPayload?) {
|
||||
setDialogState(BeneficiaryApplicationConfirmationState.DialogState.Loading)
|
||||
viewModelScope.launch {
|
||||
val successMsg = getString(Res.string.beneficiary_created_successfully)
|
||||
val response = beneficiaryRepositoryImp.createBeneficiary(payload)
|
||||
|
||||
when (response) {
|
||||
@ -161,7 +164,11 @@ internal class BeneficiaryApplicationConfirmationViewModel(
|
||||
eventType = EventType.SUCCESS.name,
|
||||
eventDestination = "",
|
||||
title = getString(Res.string.beneficiary_created_successfully),
|
||||
subtitle = getString(Res.string.beneficiary_created_successfully_account,state.accountNumber,state.name),
|
||||
subtitle = getString(
|
||||
Res.string.beneficiary_created_successfully_account,
|
||||
state.accountNumber,
|
||||
state.name,
|
||||
),
|
||||
buttonText = getString(Res.string.back_to_home),
|
||||
),
|
||||
)
|
||||
@ -177,7 +184,6 @@ internal class BeneficiaryApplicationConfirmationViewModel(
|
||||
private fun updateBeneficiary(beneficiaryId: Long?, payload: BeneficiaryUpdatePayload?) {
|
||||
setDialogState(BeneficiaryApplicationConfirmationState.DialogState.Loading)
|
||||
viewModelScope.launch {
|
||||
val successMsg = getString(Res.string.beneficiary_updated_successfully)
|
||||
val response = beneficiaryRepositoryImp.updateBeneficiary(beneficiaryId, payload)
|
||||
when (response) {
|
||||
is DataState.Error -> {
|
||||
@ -230,7 +236,7 @@ internal class BeneficiaryApplicationConfirmationViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun initializeMapDetails(){
|
||||
private suspend fun initializeMapDetails() {
|
||||
val route = savedStateHandle.toRoute<BeneficiaryApplicationConfirmationNavRoute>()
|
||||
val details = mapOf(
|
||||
Res.string.beneficiary_name_label to route.name,
|
||||
@ -246,7 +252,7 @@ internal class BeneficiaryApplicationConfirmationViewModel(
|
||||
)
|
||||
updateState {
|
||||
it.copy(
|
||||
details=details
|
||||
details = details,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +41,6 @@ fun NavController.navigateToBeneficiaryApplicationScreen(
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
fun NavGraphBuilder.beneficiaryNavGraph(
|
||||
navController: NavController,
|
||||
openQrReaderScreen: () -> Unit,
|
||||
|
||||
@ -14,8 +14,6 @@ import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.NavOptions
|
||||
import androidx.navigation.navigation
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.mifos.mobile.core.model.entity.AccountDetails
|
||||
import org.mifos.mobile.feature.beneficiary.beneficiaryApplication.BeneficiaryApplicationNavRoute
|
||||
import org.mifos.mobile.feature.beneficiary.beneficiaryApplication.manualBeneficiaryAddDestination
|
||||
import org.mifos.mobile.feature.beneficiary.beneficiaryApplication.navigateToManualBeneficiaryAddScreen
|
||||
import org.mifos.mobile.feature.beneficiary.beneficiaryApplicationConfirmation.beneficiaryAddConfirmationDestination
|
||||
@ -26,13 +24,12 @@ import org.mifos.mobile.feature.beneficiary.beneficiaryList.beneficiaryListScree
|
||||
@Serializable
|
||||
data object BeneficiaryNavRoute
|
||||
|
||||
|
||||
fun NavController.navigateToBeneficiaryNavGraph(navOptions: NavOptions? = null) =
|
||||
navigate(BeneficiaryNavRoute, navOptions)
|
||||
|
||||
fun NavGraphBuilder.beneficiaryNavGraph(
|
||||
navController: NavController,
|
||||
navigateToQR:()->Unit,
|
||||
navigateToQR: () -> Unit,
|
||||
navigateToStatusScreen: (String, String, String, String, String) -> Unit,
|
||||
navigateToAuthenticateScreen: () -> Unit,
|
||||
) {
|
||||
@ -45,13 +42,12 @@ fun NavGraphBuilder.beneficiaryNavGraph(
|
||||
navController.navigateToManualBeneficiaryAddScreen()
|
||||
},
|
||||
onBeneficiaryItemClick = {
|
||||
|
||||
},
|
||||
)
|
||||
|
||||
manualBeneficiaryAddDestination(
|
||||
navigateToConfirmationScreen =
|
||||
navController::navigateToBeneficiaryApplicationAddConfirmationScreen,
|
||||
navController::navigateToBeneficiaryApplicationAddConfirmationScreen,
|
||||
navigateBack = navController::popBackStack,
|
||||
navigateToQR = navigateToQR,
|
||||
)
|
||||
@ -63,4 +59,3 @@ fun NavGraphBuilder.beneficiaryNavGraph(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -43,8 +43,9 @@ import org.jetbrains.compose.resources.painterResource
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import org.koin.compose.viewmodel.koinViewModel
|
||||
import org.mifos.mobile.core.common.DateHelper
|
||||
import org.mifos.mobile.core.designsystem.component.MifosScaffold
|
||||
import org.mifos.mobile.core.designsystem.component.MifosElevatedScaffold
|
||||
import org.mifos.mobile.core.designsystem.component.MifosTextButton
|
||||
import org.mifos.mobile.core.designsystem.icon.MifosIcons
|
||||
import org.mifos.mobile.core.model.entity.MifosNotification
|
||||
import org.mifos.mobile.core.ui.component.EmptyDataView
|
||||
import org.mifos.mobile.core.ui.component.MifosErrorComponent
|
||||
@ -83,9 +84,9 @@ private fun NotificationScreen(
|
||||
onRefresh: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
MifosScaffold(
|
||||
MifosElevatedScaffold(
|
||||
topBarTitle = stringResource(Res.string.notification),
|
||||
onNavigationIconClick = navigateBack,
|
||||
onNavigateBack = navigateBack,
|
||||
modifier = modifier,
|
||||
content = {
|
||||
Box(modifier = Modifier) {
|
||||
@ -112,7 +113,7 @@ private fun NotificationScreen(
|
||||
|
||||
is NotificationUiState.Empty -> {
|
||||
EmptyDataView(
|
||||
image = Res.drawable.ic_notifications,
|
||||
icon = MifosIcons.Notification,
|
||||
error = Res.string.no_notification,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user