Skip to content

Commit 4af9cd8

Browse files
fix : Loading and Empty states in Client Profile General flows (#2538)
1 parent a72352c commit 4af9cd8

File tree

9 files changed

+352
-314
lines changed

9 files changed

+352
-314
lines changed

feature/client/src/androidMain/kotlin/com/mifos/feature/client/clientUpcomingCharges/ClientUpcomingChargesScreen.android.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import com.mifos.core.designsystem.component.MifosSweetError
3333
import com.mifos.core.designsystem.theme.DesignToken
3434
import com.mifos.core.ui.components.Actions
3535
import com.mifos.core.ui.components.MifosActionsClientFeeListingComponent
36+
import com.mifos.core.ui.components.MifosEmptyCard
3637
import com.mifos.core.ui.components.MifosPagingAppendProgress
3738
import com.mifos.core.ui.components.MifosProgressIndicator
3839
import com.mifos.room.entities.client.ChargesEntity
@@ -64,6 +65,10 @@ actual fun ChargesListContent(
6465
setCount.invoke(chargesPagingList.itemCount)
6566
}
6667

68+
if (chargesPagingList.loadState.refresh is LoadState.NotLoading && chargesPagingList.itemCount == 0) {
69+
MifosEmptyCard()
70+
}
71+
6772
LazyColumn {
6873
items(
6974
count = chargesPagingList.itemCount,

feature/client/src/commonMain/kotlin/com/mifos/feature/client/clientLoanAccounts/ClientLoanAccountsScreen.kt

Lines changed: 79 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -104,89 +104,94 @@ private fun ClientLoanAccountsScreen(
104104
) {
105105
MifosBreadcrumbNavBar(navController)
106106

107-
Column(
108-
modifier = Modifier.fillMaxSize()
109-
.padding(horizontal = DesignToken.padding.large),
110-
) {
111-
ClientsAccountHeader(
112-
totalItem = state.loanAccounts.size.toString(),
113-
onAction = onAction,
114-
)
107+
when (state.isLoading) {
108+
true -> MifosProgressIndicator()
109+
false -> {
110+
Column(
111+
modifier = Modifier.fillMaxSize()
112+
.padding(horizontal = DesignToken.padding.large),
113+
) {
114+
ClientsAccountHeader(
115+
totalItem = state.loanAccounts.size.toString(),
116+
onAction = onAction,
117+
)
115118

116-
if (state.isSearchBarActive) {
117-
MifosSearchBar(
118-
query = state.searchText,
119-
onQueryChange = {
120-
onAction.invoke(
121-
ClientLoanAccountsAction.UpdateSearchValue(
122-
it,
123-
),
119+
if (state.isSearchBarActive) {
120+
MifosSearchBar(
121+
query = state.searchText,
122+
onQueryChange = {
123+
onAction.invoke(
124+
ClientLoanAccountsAction.UpdateSearchValue(
125+
it,
126+
),
127+
)
128+
},
129+
onSearchClick = { onAction.invoke(ClientLoanAccountsAction.OnSearchClick) },
130+
onBackClick = { onAction.invoke(ClientLoanAccountsAction.ToggleSearch) },
124131
)
125-
},
126-
onSearchClick = { onAction.invoke(ClientLoanAccountsAction.OnSearchClick) },
127-
onBackClick = { onAction.invoke(ClientLoanAccountsAction.ToggleSearch) },
128-
)
129-
}
132+
}
130133

131-
Spacer(modifier = Modifier.height(DesignToken.padding.large))
134+
Spacer(modifier = Modifier.height(DesignToken.padding.large))
132135

133-
if (state.loanAccounts.isEmpty()) {
134-
MifosEmptyCard()
135-
} else {
136-
LazyColumn {
137-
items(state.loanAccounts) { loan ->
138-
val symbol = loan.currency?.displaySymbol ?: ""
139-
MifosActionsLoanListingComponent(
140-
accountNo = (loan.accountNo ?: "Not Available"),
141-
loanProduct = loan.productName ?: "Not Available",
142-
originalLoan = symbol + (
143-
(loan.originalLoan ?: "Not Available").toString()
144-
),
145-
amountPaid = symbol + (
146-
(
147-
loan.amountPaid
148-
?: "Not Available"
149-
).toString()
150-
),
151-
loanBalance = symbol + (
152-
(loan.amountPaid ?: "Not Available").toString()
153-
),
154-
type = loan.loanType?.value ?: "Not Available",
155-
// TODO check if we need to add other options as well, such as disburse and all
156-
// currently didn't add it cuz its not in the UI design
157-
menuList = when {
158-
loan.status?.active == true -> {
159-
listOf(
160-
Actions.ViewAccount(
161-
vectorResource(Res.drawable.wallet),
136+
if (state.loanAccounts.isEmpty()) {
137+
MifosEmptyCard()
138+
} else {
139+
LazyColumn {
140+
items(state.loanAccounts) { loan ->
141+
val symbol = loan.currency?.displaySymbol ?: ""
142+
MifosActionsLoanListingComponent(
143+
accountNo = (loan.accountNo ?: "Not Available"),
144+
loanProduct = loan.productName ?: "Not Available",
145+
originalLoan = symbol + (
146+
(loan.originalLoan ?: "Not Available").toString()
162147
),
163-
Actions.MakeRepayment(
164-
vectorResource(Res.drawable.cash_bundel),
148+
amountPaid = symbol + (
149+
(
150+
loan.amountPaid
151+
?: "Not Available"
152+
).toString()
165153
),
166-
)
167-
}
168-
169-
else -> {
170-
listOf(
171-
Actions.ViewAccount(
172-
vectorResource(Res.drawable.wallet),
154+
loanBalance = symbol + (
155+
(loan.amountPaid ?: "Not Available").toString()
173156
),
174-
)
175-
}
176-
},
177-
onActionClicked = { actions ->
178-
when (actions) {
179-
is Actions.ViewAccount -> onAction(ClientLoanAccountsAction.ViewAccount)
180-
is Actions.MakeRepayment -> onAction(
181-
ClientLoanAccountsAction.MakeRepayment,
182-
)
157+
type = loan.loanType?.value ?: "Not Available",
158+
// TODO check if we need to add other options as well, such as disburse and all
159+
// currently didn't add it cuz its not in the UI design
160+
menuList = when {
161+
loan.status?.active == true -> {
162+
listOf(
163+
Actions.ViewAccount(
164+
vectorResource(Res.drawable.wallet),
165+
),
166+
Actions.MakeRepayment(
167+
vectorResource(Res.drawable.cash_bundel),
168+
),
169+
)
170+
}
183171

184-
else -> null
185-
}
186-
},
187-
)
172+
else -> {
173+
listOf(
174+
Actions.ViewAccount(
175+
vectorResource(Res.drawable.wallet),
176+
),
177+
)
178+
}
179+
},
180+
onActionClicked = { actions ->
181+
when (actions) {
182+
is Actions.ViewAccount -> onAction(ClientLoanAccountsAction.ViewAccount)
183+
is Actions.MakeRepayment -> onAction(
184+
ClientLoanAccountsAction.MakeRepayment,
185+
)
188186

189-
Spacer(modifier = Modifier.height(8.dp))
187+
else -> null
188+
}
189+
},
190+
)
191+
192+
Spacer(modifier = Modifier.height(8.dp))
193+
}
194+
}
190195
}
191196
}
192197
}
@@ -260,8 +265,6 @@ private fun ClientLoanAccountsDialog(
260265
)
261266
}
262267

263-
ClientLoanAccountsState.DialogState.Loading -> MifosProgressIndicator()
264-
265268
else -> null
266269
}
267270
}

feature/client/src/commonMain/kotlin/com/mifos/feature/client/clientLoanAccounts/ClientLoanAccountsViewModel.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class ClientLoanAccountsViewModel(
100100
private fun getLoanAccounts() {
101101
viewModelScope.launch {
102102
mutableStateFlow.update {
103-
it.copy(dialogState = ClientLoanAccountsState.DialogState.Loading)
103+
it.copy(isLoading = true)
104104
}
105105

106106
try {
@@ -114,6 +114,7 @@ class ClientLoanAccountsViewModel(
114114
it.copy(
115115
loanAccounts = loanAccounts,
116116
dialogState = null,
117+
isLoading = false,
117118
)
118119
}
119120
} catch (e: Exception) {
@@ -122,6 +123,7 @@ class ClientLoanAccountsViewModel(
122123
dialogState = ClientLoanAccountsState.DialogState.Error(
123124
e.message ?: "Unknown error",
124125
),
126+
isLoading = false,
125127
)
126128
}
127129
}
@@ -136,10 +138,10 @@ data class ClientLoanAccountsState(
136138
val loanAccounts: List<LoanAccountEntity> = emptyList(),
137139
val isFilterDialogOpen: Boolean = false,
138140
val dialogState: DialogState? = null,
141+
val isLoading: Boolean = false,
139142
) {
140143
sealed interface DialogState {
141144
data class Error(val message: String) : DialogState
142-
data object Loading : DialogState
143145
}
144146
}
145147

0 commit comments

Comments
 (0)