Skip to content

Commit 0aa1b28

Browse files
revanthkumarJArinyadav1
authored andcommitted
fix : Loading and Empty states in Client Profile General flows (#2538)
1 parent ad92e8b commit 0aa1b28

File tree

9 files changed

+121
-95
lines changed

9 files changed

+121
-95
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

feature/client/src/commonMain/kotlin/com/mifos/feature/client/fixedDepositAccount/FixedDepositAccountScreen.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ fun FixedDepositAccountScaffold(
184184
)
185185
}
186186

187-
Spacer(modifier = Modifier.height(DesignToken.padding.largeIncreasedExtra))
187+
Spacer(modifier = Modifier.height(DesignToken.padding.largeIncreasedExtra))
188188

189189
if (state.fixedDepositAccount.isEmpty()) {
190190
MifosEmptyCard(msg = stringResource(Res.string.client_empty_card_message))
@@ -232,17 +232,21 @@ fun FixedDepositAccountScaffold(
232232
)
233233
}
234234

235-
is Actions.ApproveAccount -> {
236-
FixedDepositAccountAction.ApproveAccount(
237-
fixedDepositAccount.accountNo ?: "",
238-
)
235+
is Actions.ApproveAccount -> {
236+
onAction(
237+
FixedDepositAccountAction.ApproveAccount(
238+
fixedDepositAccount.accountNo ?: "",
239+
),
240+
)
241+
}
242+
243+
else -> null
244+
}
239245
}
240246

241-
else -> null
247+
Spacer(modifier = Modifier.height(DesignToken.spacing.small))
242248
}
243249
}
244-
245-
Spacer(modifier = Modifier.height(DesignToken.spacing.small))
246250
}
247251
}
248252
}

feature/client/src/commonMain/kotlin/com/mifos/feature/client/fixedDepositAccount/FixedDepositAccountViewModel.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,17 @@ class FixedDepositAccountViewModel(
123123
dialogState = FixedDepositAccountState.DialogState.Error(
124124
result.message,
125125
),
126+
isLoading = false,
126127
)
127128
}
128129
}
129130

130131
is DataState.Loading -> {
131132
mutableStateFlow.update {
132-
it.copy(dialogState = FixedDepositAccountState.DialogState.Loading)
133+
it.copy(
134+
isLoading = true,
135+
dialogState = null,
136+
)
133137
}
134138
}
135139

@@ -150,6 +154,7 @@ class FixedDepositAccountViewModel(
150154
dialogState = null,
151155
clientId = route.clientId,
152156
fixedDepositAccount = fixedDepositAccount,
157+
isLoading = false,
153158
)
154159
}
155160
}
@@ -166,10 +171,10 @@ data class FixedDepositAccountState(
166171
val dialogState: DialogState? = null,
167172
val isSearchBarActive: Boolean = false,
168173
val isFilterDialogOpen: Boolean = false,
174+
val isLoading: Boolean = false,
169175
) {
170176
sealed interface DialogState {
171177
data class Error(val message: String) : DialogState
172-
data object Loading : DialogState
173178
}
174179
}
175180

feature/client/src/commonMain/kotlin/com/mifos/feature/client/recurringDepositAccount/RecurringDepositAccountScreen.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ internal fun RecurringDepositAccountScaffold(
240240
}
241241
}
242242

243-
Spacer(modifier = Modifier.height(DesignToken.spacing.small))
243+
Spacer(modifier = Modifier.height(DesignToken.spacing.small))
244+
}
245+
}
244246
}
245247
}
246248
}

feature/client/src/commonMain/kotlin/com/mifos/feature/client/recurringDepositAccount/RecurringDepositAccountViewModel.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,17 @@ class RecurringDepositAccountViewModel(
118118
dialogState = RecurringDepositAccountState.DialogState.Error(
119119
result.message,
120120
),
121+
isLoading = false,
121122
)
122123
}
123124
}
124125

125126
is DataState.Loading -> {
126127
mutableStateFlow.update {
127-
it.copy(dialogState = RecurringDepositAccountState.DialogState.Loading)
128+
it.copy(
129+
isLoading = true,
130+
dialogState = null,
131+
)
128132
}
129133
}
130134

@@ -143,6 +147,7 @@ class RecurringDepositAccountViewModel(
143147
dialogState = null,
144148
clientId = route.clientId,
145149
recurringDepositAccounts = recurringDepositAccount,
150+
isLoading = false,
146151
)
147152
}
148153
}
@@ -159,10 +164,10 @@ data class RecurringDepositAccountState(
159164
val dialogState: DialogState? = null,
160165
val isSearchBarActive: Boolean = false,
161166
val isFilterDialogOpen: Boolean = false,
167+
val isLoading: Boolean = false,
162168
) {
163169
sealed interface DialogState {
164170
data class Error(val message: String) : DialogState
165-
data object Loading : DialogState
166171
}
167172
}
168173

feature/client/src/commonMain/kotlin/com/mifos/feature/client/savingsAccounts/SavingsAccounts.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,7 @@ private fun SavingsAccountsDialog(
291291
onDismissRequest = {},
292292
)
293293
}
294-
295294
SavingsAccountState.DialogState.Loading -> MifosProgressIndicator()
296-
297295
else -> null
298296
}
299297
}

0 commit comments

Comments
 (0)