@@ -63,10 +63,11 @@ import com.mifos.core.designsystem.icon.MifosIcons
63
63
import com.mifos.core.designsystem.theme.identifierTextStyleDark
64
64
import com.mifos.core.designsystem.theme.identifierTextStyleLight
65
65
import com.mifos.core.model.objects.noncoreobjects.Identifier
66
+ import com.mifos.core.model.objects.noncoreobjects.IdentifierPayload
66
67
import com.mifos.core.ui.components.MifosEmptyUi
67
68
import com.mifos.core.ui.util.DevicePreview
69
+ import com.mifos.feature.client.clientIdentifiersDialog.ClientIdentifierDialogUiState
68
70
import com.mifos.feature.client.clientIdentifiersDialog.ClientIdentifiersDialogScreen
69
- import com.mifos.feature.client.clientIdentifiersDialog.ClientIdentifiersDialogViewModel
70
71
import kotlinx.coroutines.launch
71
72
import org.jetbrains.compose.resources.getString
72
73
import org.jetbrains.compose.resources.stringResource
@@ -78,55 +79,44 @@ import org.koin.compose.viewmodel.koinViewModel
78
79
internal fun ClientIdentifiersScreen (
79
80
onBackPressed : () -> Unit ,
80
81
onDocumentClicked : (Int ) -> Unit ,
81
- clientIdentifiersviewModel : ClientIdentifiersViewModel = koinViewModel(),
82
- clientIdentifiersDialogViewModel : ClientIdentifiersDialogViewModel = koinViewModel(),
82
+ viewModel : ClientIdentifiersViewModel = koinViewModel(),
83
83
) {
84
- val clientId by clientIdentifiersviewModel.clientId .collectAsStateWithLifecycle()
85
- val state by clientIdentifiersviewModel.clientIdentifiersUiState .collectAsStateWithLifecycle()
86
- val refreshState by clientIdentifiersviewModel .isRefreshing.collectAsStateWithLifecycle()
84
+ val clientIdentifiersUiState by viewModel.clientIdentifiersUiState .collectAsStateWithLifecycle()
85
+ val clientIdentifiersDialogUiState by viewModel.clientIdentifierDialogUiState .collectAsStateWithLifecycle()
86
+ val refreshState by viewModel .isRefreshing.collectAsStateWithLifecycle()
87
87
88
88
ClientIdentifiersScreen (
89
- clientId = clientId,
90
- state = state,
89
+ state = clientIdentifiersUiState,
90
+ dialogState = clientIdentifiersDialogUiState,
91
+ onShowDialog = viewModel::loadClientIdentifierTemplate,
91
92
onBackPressed = onBackPressed,
92
93
onDeleteIdentifier = { identifierId ->
93
- clientIdentifiersviewModel.deleteIdentifier(clientId, identifierId)
94
- },
95
- refreshState = refreshState,
96
- onRefresh = {
97
- clientIdentifiersviewModel.refreshIdentifiersList(clientId)
94
+ viewModel.deleteIdentifier(identifierId)
98
95
},
99
- onRetry = {
100
- clientIdentifiersviewModel.loadIdentifiers(clientId)
101
- },
102
- onIdentifierCreated = {
103
- // resetUiState() is needed here to clear the success state immediately after successful
104
- // client identifier creation, so that reopening the dialog doesn’t reuse stale state and
105
- // accidentally retrigger main screen loading.
106
- // Downside: this causes two back-to-back loading states — one in the dialog and one on
107
- // the main screen.
108
- clientIdentifiersDialogViewModel.resetUiState()
109
- clientIdentifiersviewModel.loadIdentifiers(clientId)
96
+ onCreateIdentifier = { identifierPayload ->
97
+ viewModel.createClientIdentifier(identifierPayload)
110
98
},
99
+ refreshState = refreshState,
100
+ onRefresh = viewModel::refreshIdentifiersList,
101
+ onRetry = viewModel::loadIdentifiers,
111
102
onDocumentClicked = onDocumentClicked,
112
- onIdentifierDeleted = {
113
- clientIdentifiersviewModel.loadIdentifiers(clientId)
114
- },
103
+ reloadIdentifiers = viewModel::loadIdentifiers,
115
104
)
116
105
}
117
106
118
107
@Composable
119
108
internal fun ClientIdentifiersScreen (
120
- clientId : Int ,
121
109
state : ClientIdentifiersUiState ,
110
+ dialogState : ClientIdentifierDialogUiState ,
111
+ onShowDialog : () -> Unit ,
122
112
onBackPressed : () -> Unit ,
123
113
onDeleteIdentifier : (Int ) -> Unit ,
114
+ onCreateIdentifier : (IdentifierPayload ) -> Unit ,
124
115
refreshState : Boolean ,
125
116
onRefresh : () -> Unit ,
126
117
onRetry : () -> Unit ,
127
- onIdentifierCreated : () -> Unit ,
128
118
onDocumentClicked : (Int ) -> Unit ,
129
- onIdentifierDeleted : () -> Unit ,
119
+ reloadIdentifiers : () -> Unit ,
130
120
) {
131
121
val snackbarHostState = remember { SnackbarHostState () }
132
122
val pullToRefreshState = rememberPullToRefreshState()
@@ -136,13 +126,15 @@ internal fun ClientIdentifiersScreen(
136
126
137
127
if (showCreateIdentifierDialog) {
138
128
ClientIdentifiersDialogScreen (
139
- clientId = clientId ,
129
+ state = dialogState ,
140
130
onDismiss = { showCreateIdentifierDialog = false },
141
131
onIdentifierCreated = {
142
132
showCreateIdentifierDialog = false
143
133
showCreateSuccessMessage = true
144
- onIdentifierCreated ()
134
+ reloadIdentifiers ()
145
135
},
136
+ onRetry = onRetry,
137
+ onCreateIdentifier = onCreateIdentifier,
146
138
)
147
139
}
148
140
@@ -152,6 +144,7 @@ internal fun ClientIdentifiersScreen(
152
144
actions = {
153
145
IconButton (
154
146
onClick = {
147
+ onShowDialog()
155
148
showCreateIdentifierDialog = true
156
149
},
157
150
) {
@@ -196,7 +189,7 @@ internal fun ClientIdentifiersScreen(
196
189
}
197
190
198
191
is ClientIdentifiersUiState .IdentifierDeletedSuccessfully -> {
199
- onIdentifierDeleted ()
192
+ reloadIdentifiers ()
200
193
scope.launch {
201
194
snackbarHostState.showSnackbar(
202
195
message = getString(state.message),
@@ -351,16 +344,17 @@ private fun ClientIdentifiersScreenPreview(
351
344
@PreviewParameter(ClientIdentifiersUiStateProvider ::class ) state : ClientIdentifiersUiState ,
352
345
) {
353
346
ClientIdentifiersScreen (
354
- clientId = 1 ,
355
347
state = state,
348
+ dialogState = ClientIdentifierDialogUiState .Loading ,
356
349
onBackPressed = {},
357
350
onDeleteIdentifier = {},
358
351
refreshState = true ,
359
352
onRefresh = {},
360
353
onRetry = {},
361
- onIdentifierCreated = {},
362
354
onDocumentClicked = {},
363
- onIdentifierDeleted = {},
355
+ onShowDialog = {},
356
+ reloadIdentifiers = {},
357
+ onCreateIdentifier = {},
364
358
)
365
359
}
366
360
val sampleClientIdentifiers = List (10 ) {
0 commit comments