@@ -39,9 +39,7 @@ import androidx.compose.material3.Icon
3939import androidx.compose.material3.Text
4040import androidx.compose.runtime.Composable
4141import androidx.compose.runtime.getValue
42- import androidx.compose.runtime.mutableStateOf
4342import androidx.compose.runtime.remember
44- import androidx.compose.runtime.setValue
4543import androidx.compose.ui.Modifier
4644import androidx.lifecycle.compose.collectAsStateWithLifecycle
4745import androidx.navigation.NavController
@@ -98,7 +96,6 @@ internal fun ClientIdentifiersListScreen(
9896 onAction : (ClientIdentifiersListAction ) -> Unit ,
9997) {
10098 val emptyMessage = stringResource(Res .string.client_identifiers_not_available)
101- var itemToDelete by remember { mutableStateOf<Pair <Int , String >? > (null ) }
10299
103100 MifosScaffold (
104101 onBackPressed = {
@@ -172,7 +169,9 @@ internal fun ClientIdentifiersListScreen(
172169 is Actions .DeleteDocument -> {
173170 val id = item.id
174171 if (id != null ) {
175- itemToDelete = id to uniqueKeyForHandleDocument
172+ onAction.invoke(
173+ ClientIdentifiersListAction .ShowDeleteConfirmation (id, uniqueKeyForHandleDocument),
174+ )
176175 }
177176 }
178177 else -> {}
@@ -196,26 +195,6 @@ internal fun ClientIdentifiersListScreen(
196195 }
197196 }
198197 }
199- if (itemToDelete != null ) {
200- MifosAlertDialog (
201- dialogTitle = stringResource(Res .string.delete_dialog_title),
202- dialogText = stringResource(Res .string.document_delete_dialog_message),
203- onDismissRequest = {
204- itemToDelete = null
205- },
206- onConfirmation = {
207- onAction.invoke(
208- ClientIdentifiersListAction .DeleteDocument (
209- itemToDelete!! .first,
210- itemToDelete!! .second,
211- ),
212- )
213- itemToDelete = null
214- },
215- confirmationText = stringResource(Res .string.remove),
216- dismissText = stringResource(Res .string.cancel),
217- )
218- }
219198}
220199
221200@Composable
@@ -266,11 +245,11 @@ private fun ClientIdentifiersDialog(
266245 state : ClientIdentifiersListState ,
267246 onAction : (ClientIdentifiersListAction ) -> Unit ,
268247) {
269- when (state.dialogState) {
248+ when (val dialogState = state.dialogState) {
270249 is ClientIdentifiersListState .DialogState .Error -> {
271250 MifosAlertDialog (
272251 dialogTitle = stringResource(Res .string.client_identifiers_error_text),
273- dialogText = state. dialogState.message,
252+ dialogText = dialogState.message,
274253 onDismissRequest = { onAction.invoke(ClientIdentifiersListAction .CloseDialog ) },
275254 onConfirmation = { onAction.invoke(ClientIdentifiersListAction .CloseDialog ) },
276255 )
@@ -288,12 +267,32 @@ private fun ClientIdentifiersDialog(
288267 MifosAlertDialog (
289268 dialogTitle = stringResource(Res .string.client_identifiers_identities_success_text),
290269 dialogText = stringResource(Res .string.client_identifiers_identities_client_identifier_deletion_success) +
291- " " + state. dialogState.id,
270+ " " + dialogState.id,
292271 onDismissRequest = { onAction.invoke(ClientIdentifiersListAction .CloseDialog ) },
293272 onConfirmation = { onAction.invoke(ClientIdentifiersListAction .CloseDialog ) },
294273 )
295274 }
296275
276+ is ClientIdentifiersListState .DialogState .DeleteConfirmation -> {
277+ MifosAlertDialog (
278+ dialogTitle = stringResource(Res .string.delete_dialog_title),
279+ dialogText = stringResource(Res .string.document_delete_dialog_message),
280+ onDismissRequest = {
281+ onAction.invoke(ClientIdentifiersListAction .CloseDialog )
282+ },
283+ onConfirmation = {
284+ onAction.invoke(
285+ ClientIdentifiersListAction .DeleteDocument (
286+ dialogState.id,
287+ dialogState.uniqueKey,
288+ ),
289+ )
290+ },
291+ confirmationText = stringResource(Res .string.remove),
292+ dismissText = stringResource(Res .string.cancel),
293+ )
294+ }
295+
297296 null -> {}
298297
299298 ClientIdentifiersListState .DialogState .NoInternet -> {
0 commit comments