Skip to content

Commit

Permalink
Merge pull request #195 from niscy-eudiw/bugfix/fix_VC_sharing
Browse files Browse the repository at this point in the history
Fix: Enable share button if at least one verification item or optional field is selected
  • Loading branch information
stzouvaras authored Oct 1, 2024
2 parents 5398529 + 2c5edbf commit 0163592
Showing 1 changed file with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ abstract class RequestViewModel : MviViewModel<Event, State, Effect>() {
}

open fun updateData(updatedItems: List<RequestDataUi<Event>>, allowShare: Boolean? = null) {
val hasVerificationItems = hasVerificationItems(updatedItems)

val hasAtLeastOneFieldSelected = hasAtLeastOneFieldSelected(updatedItems)

setState {
copy(
items = updatedItems,
Expand All @@ -126,7 +130,7 @@ abstract class RequestViewModel : MviViewModel<Event, State, Effect>() {
&& it.optionalFieldItemUi.requestDocumentItemUi.enabled
&& !it.optionalFieldItemUi.requestDocumentItemUi.checked
},
allowShare = allowShare ?: updatedItems.isNotEmpty()
allowShare = allowShare ?: (hasAtLeastOneFieldSelected || hasVerificationItems)
)
}
}
Expand Down Expand Up @@ -278,13 +282,9 @@ abstract class RequestViewModel : MviViewModel<Event, State, Effect>() {
}
}

val hasVerificationItems = updatedList.any { it is RequestDataUi.RequiredFields }
val hasVerificationItems = hasVerificationItems(updatedList)

val hasAtLeastOneFieldSelected = updatedList
.filterIsInstance<RequestDataUi.OptionalField<Event>>().any {
it.optionalFieldItemUi.requestDocumentItemUi.enabled
&& it.optionalFieldItemUi.requestDocumentItemUi.checked
}
val hasAtLeastOneFieldSelected = hasAtLeastOneFieldSelected(updatedList)

updateData(
updatedItems = updatedList,
Expand All @@ -310,4 +310,25 @@ abstract class RequestViewModel : MviViewModel<Event, State, Effect>() {
private fun unsubscribe() {
viewModelJob?.cancel()
}

private fun hasVerificationItems(list: List<RequestDataUi<Event>>): Boolean {
return list
.filterIsInstance<RequestDataUi.RequiredFields<Event>>()
.any { requiredFields ->
requiredFields.requiredFieldsItemUi.requestDocumentItemsUi
.any { itemUi ->
itemUi.checked
}
}
}

private fun hasAtLeastOneFieldSelected(list: List<RequestDataUi<Event>>): Boolean {
return list
.filterIsInstance<RequestDataUi.OptionalField<Event>>()
.any { optionalField ->
with(optionalField.optionalFieldItemUi.requestDocumentItemUi) {
enabled && checked
}
}
}
}

0 comments on commit 0163592

Please sign in to comment.