BIT-1938: Display toast after updating cipher collection or moving cipher to an organization (#1058)

This commit is contained in:
David Perez 2024-02-22 18:12:05 -06:00 committed by Álison Fernandes
parent c779482bf8
commit 86756a4698
2 changed files with 33 additions and 12 deletions

View file

@ -10,7 +10,6 @@ import com.x8bit.bitwarden.data.auth.repository.AuthRepository
import com.x8bit.bitwarden.data.auth.repository.model.UserState import com.x8bit.bitwarden.data.auth.repository.model.UserState
import com.x8bit.bitwarden.data.platform.repository.model.DataState import com.x8bit.bitwarden.data.platform.repository.model.DataState
import com.x8bit.bitwarden.data.platform.repository.util.combineDataStates import com.x8bit.bitwarden.data.platform.repository.util.combineDataStates
import com.x8bit.bitwarden.data.platform.repository.util.map
import com.x8bit.bitwarden.data.vault.repository.VaultRepository import com.x8bit.bitwarden.data.vault.repository.VaultRepository
import com.x8bit.bitwarden.data.vault.repository.model.ShareCipherResult import com.x8bit.bitwarden.data.vault.repository.model.ShareCipherResult
import com.x8bit.bitwarden.ui.platform.base.BaseViewModel import com.x8bit.bitwarden.ui.platform.base.BaseViewModel
@ -165,6 +164,7 @@ class VaultMoveToOrganizationViewModel @Inject constructor(
is ShareCipherResult.Success -> { is ShareCipherResult.Success -> {
sendEvent(VaultMoveToOrganizationEvent.NavigateBack) sendEvent(VaultMoveToOrganizationEvent.NavigateBack)
sendEvent(VaultMoveToOrganizationEvent.ShowToast(action.successToast))
} }
} }
} }
@ -285,23 +285,30 @@ class VaultMoveToOrganizationViewModel @Inject constructor(
} }
viewModelScope.launch { viewModelScope.launch {
trySendAction( trySendAction(
VaultMoveToOrganizationAction.Internal.ShareCipherResultReceive( if (state.onlyShowCollections) {
if (state.onlyShowCollections) { VaultMoveToOrganizationAction.Internal.ShareCipherResultReceive(
vaultRepository.updateCipherCollections( shareCipherResult = vaultRepository.updateCipherCollections(
cipherId = mutableStateFlow.value.vaultItemId, cipherId = state.vaultItemId,
cipherView = cipherView, cipherView = cipherView,
collectionIds = collectionIds, collectionIds = collectionIds,
) ),
} else { successToast = R.string.item_updated.asText(),
vaultRepository.shareCipher( )
cipherId = mutableStateFlow.value.vaultItemId, } else {
VaultMoveToOrganizationAction.Internal.ShareCipherResultReceive(
shareCipherResult = vaultRepository.shareCipher(
cipherId = state.vaultItemId,
cipherView = cipherView.copy( cipherView = cipherView.copy(
organizationId = contentState.selectedOrganizationId, organizationId = contentState.selectedOrganizationId,
), ),
collectionIds = collectionIds, collectionIds = collectionIds,
) ),
}, successToast = R.string.moved_item_to_org.asText(
), requireNotNull(contentState.cipherToMove).name,
contentState.selectedOrganization.name,
),
)
},
) )
} }
} }
@ -491,6 +498,7 @@ sealed class VaultMoveToOrganizationAction {
*/ */
data class ShareCipherResultReceive( data class ShareCipherResultReceive(
val shareCipherResult: ShareCipherResult, val shareCipherResult: ShareCipherResult,
val successToast: Text,
) : Internal() ) : Internal()
} }
} }

View file

@ -368,6 +368,15 @@ class VaultMoveToOrganizationViewModelTest : BaseViewModelTest() {
VaultMoveToOrganizationEvent.NavigateBack, VaultMoveToOrganizationEvent.NavigateBack,
awaitItem(), awaitItem(),
) )
assertEquals(
VaultMoveToOrganizationEvent.ShowToast(
text = R.string.moved_item_to_org.asText(
"mockName-1",
"mockOrganizationName-1",
),
),
awaitItem(),
)
} }
coVerify { coVerify {
vaultRepository.shareCipher( vaultRepository.shareCipher(
@ -403,6 +412,10 @@ class VaultMoveToOrganizationViewModelTest : BaseViewModelTest() {
VaultMoveToOrganizationEvent.NavigateBack, VaultMoveToOrganizationEvent.NavigateBack,
awaitItem(), awaitItem(),
) )
assertEquals(
VaultMoveToOrganizationEvent.ShowToast(R.string.item_updated.asText()),
awaitItem(),
)
} }
coVerify { coVerify {
vaultRepository.updateCipherCollections( vaultRepository.updateCipherCollections(