Skip to content

Commit

Permalink
fix feedback on delete program enrollments (#3537)
Browse files Browse the repository at this point in the history
* fix feedback on delete program enrollments

* fix lint error

---------

Co-authored-by: Siddharth Agarwal <[email protected]>
  • Loading branch information
siddh1004 and Siddharth Agarwal authored Mar 14, 2024
1 parent d8de29e commit 79e5e8c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ class DashboardViewModel(
}
}

fun deleteEnrollment(onAuthorityError: () -> Unit) {
fun deleteEnrollment(
onSuccess: (Boolean?) -> Unit,
onAuthorityError: () -> Unit,
) {
viewModelScope.launch(dispatcher.io()) {
val result = async {
dashboardModel.value.takeIf { it is DashboardEnrollmentModel }?.let {
Expand All @@ -148,7 +151,8 @@ class DashboardViewModel(
}
}
try {
result.await()
val hasMoreEnrollments = result.await()
onSuccess(hasMoreEnrollments)
} catch (e: AuthorityException) {
onAuthorityError()
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public interface View extends AbstractActivityContracts.View {

void handleTeiDeletion();

void handleEnrollmentDeletion(Boolean hasMoreEnrollments);

void authorityErrorMessage();

void updateNoteBadge(int numberOfNotes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ class TeiDashboardMobileActivity :
finish()
}

override fun handleEnrollmentDeletion(hasMoreEnrollments: Boolean) {
fun handleEnrollmentDeletion(hasMoreEnrollments: Boolean) {
if (hasMoreEnrollments) {
startActivity(intent(this, teiUid, null, null))
finish()
Expand Down Expand Up @@ -694,7 +694,16 @@ class TeiDashboardMobileActivity :
),
mainButtonText = getString(R.string.remove),
onMainButtonClick = {
dashboardViewModel.deleteEnrollment { authorityErrorMessage() }
binding.toolbarProgress.show()
dashboardViewModel.deleteEnrollment(
onSuccess = {
binding.toolbarProgress.hide()
handleEnrollmentDeletion(it == true)
},
onAuthorityError = {
authorityErrorMessage()
},
)
},
).show(
supportFragmentManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ DeleteBottomSheetDialog(
},
text = mainButtonText,
colorStyle = ColorStyle.ERROR,
onClick = onMainButtonClick,
onClick = {
dismiss()
onMainButtonClick()
},
modifier = Modifier
.fillMaxWidth(),
)
Expand Down

0 comments on commit 79e5e8c

Please sign in to comment.