Skip to content

Commit

Permalink
chore: wrong url when opening team management after migration - RC (W…
Browse files Browse the repository at this point in the history
…PB-14872) (#3731)

Co-authored-by: Yamil Medina <[email protected]>
  • Loading branch information
ohassine and yamilmedina authored Dec 12, 2024
1 parent 8d320d0 commit 412a932
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 11 deletions.
10 changes: 8 additions & 2 deletions app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ class UseCaseModule {
fun provideMigrateFromPersonalToTeamUseCase(
@KaliumCoreLogic coreLogic: CoreLogic,
@CurrentAccount currentAccount: UserId
) =
coreLogic.getSessionScope(currentAccount).migrateFromPersonalToTeam
) = coreLogic.getSessionScope(currentAccount).migrateFromPersonalToTeam

@ViewModelScoped
@Provides
fun provideGetTeamUrlUseCase(
@KaliumCoreLogic coreLogic: CoreLogic,
@CurrentAccount currentAccount: UserId
) = coreLogic.getSessionScope(currentAccount).getTeamUrlUseCase
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ fun SelfUserProfileScreen(
) {
val legalHoldSubjectDialogState = rememberVisibilityState<Unit>()

LaunchedEffect(Unit) {
// Check if the user is able to migrate to a team account, every time the screen is shown
viewModelSelf.checkIfUserAbleToMigrateToTeamAccount()
}

SelfUserProfileContent(
state = viewModelSelf.userProfileState,
onCloseClick = navigator::navigateBack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,15 @@ class SelfUserProfileViewModel @Inject constructor(
init {
viewModelScope.launch {
fetchSelfUser()
checkIfUserAbleToMigrateToTeamAccount()
observeEstablishedCall()
fetchIsReadOnlyAccount()
observeLegalHoldStatus()
markCreateTeamNoticeAsRead()
}
}

private suspend fun checkIfUserAbleToMigrateToTeamAccount() {
val isAbleToMigrateToTeamAccount = canMigrateFromPersonalToTeam() && userProfileState.teamName.isNullOrBlank()
userProfileState = userProfileState.copy(isAbleToMigrateToTeamAccount = isAbleToMigrateToTeamAccount)
suspend fun checkIfUserAbleToMigrateToTeamAccount() {
userProfileState = userProfileState.copy(isAbleToMigrateToTeamAccount = canMigrateFromPersonalToTeam())
}

private suspend fun fetchIsReadOnlyAccount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ data class TeamMigrationState(
val teamNameTextState: TextFieldState = TextFieldState(),
val shouldShowMigrationLeaveDialog: Boolean = false,
val currentStep: Int = 0,
val username: String = "",
val teamUrl: String = "",
val migrationFailure: MigrateFromPersonalToTeamFailure? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wire.android.feature.analytics.AnonymousAnalyticsManager
import com.wire.android.feature.analytics.model.AnalyticsEvent
import com.wire.kalium.logic.feature.server.GetTeamUrlUseCase
import com.wire.kalium.logic.feature.user.GetSelfUserUseCase
import com.wire.kalium.logic.feature.user.migration.MigrateFromPersonalToTeamFailure
import com.wire.kalium.logic.feature.user.migration.MigrateFromPersonalToTeamResult
import com.wire.kalium.logic.feature.user.migration.MigrateFromPersonalToTeamUseCase
Expand All @@ -34,12 +36,19 @@ import javax.inject.Inject
@HiltViewModel
class TeamMigrationViewModel @Inject constructor(
private val anonymousAnalyticsManager: AnonymousAnalyticsManager,
private val migrateFromPersonalToTeam: MigrateFromPersonalToTeamUseCase
private val migrateFromPersonalToTeam: MigrateFromPersonalToTeamUseCase,
private val getSelfUser: GetSelfUserUseCase,
private val getTeamUrl: GetTeamUrlUseCase,
) : ViewModel() {

var teamMigrationState by mutableStateOf(TeamMigrationState())
private set

init {
setUsername()
setTeamUrl()
}

fun showMigrationLeaveDialog() {
teamMigrationState = teamMigrationState.copy(shouldShowMigrationLeaveDialog = true)
}
Expand Down Expand Up @@ -117,4 +126,20 @@ class TeamMigrationViewModel @Inject constructor(
private fun onMigrationFailure(failure: MigrateFromPersonalToTeamFailure) {
teamMigrationState = teamMigrationState.copy(migrationFailure = failure)
}

private fun setUsername() {
viewModelScope.launch {
getSelfUser().collect { selfUser ->
selfUser.name?.let {
teamMigrationState = teamMigrationState.copy(username = it)
}
}
}
}

private fun setTeamUrl() {
viewModelScope.launch {
teamMigrationState = teamMigrationState.copy(teamUrl = getTeamUrl())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ fun TeamMigrationDoneStepScreen(
) {
val context = LocalContext.current

val teamManagementUrl = stringResource(R.string.url_team_management)
TeamMigrationDoneStepContent(
onBackToWireClicked = {
teamMigrationViewModel.sendPersonalTeamCreationFlowCompletedEvent(
Expand All @@ -79,11 +78,14 @@ fun TeamMigrationDoneStepScreen(
)
},
onOpenTeamManagementClicked = {
val teamManagementUrl = teamMigrationViewModel.teamMigrationState.teamUrl

teamMigrationViewModel.sendPersonalTeamCreationFlowCompletedEvent(
modalOpenTeamManagementButtonClicked = true
)
CustomTabsHelper.launchUrl(context, teamManagementUrl)
},
username = teamMigrationViewModel.teamMigrationState.username,
teamName = teamMigrationViewModel.teamMigrationState.teamNameTextState.text.toString()
)

Expand All @@ -98,6 +100,7 @@ fun TeamMigrationDoneStepScreen(
private fun TeamMigrationDoneStepContent(
onBackToWireClicked: () -> Unit,
onOpenTeamManagementClicked: () -> Unit,
username: String,
teamName: String,
modifier: Modifier = Modifier
) {
Expand Down Expand Up @@ -130,7 +133,7 @@ private fun TeamMigrationDoneStepContent(
bottom = dimensions().spacing56x
)
.align(alignment = Alignment.CenterHorizontally),
text = stringResource(R.string.personal_to_team_migration_done_step, teamName),
text = stringResource(R.string.personal_to_team_migration_done_step, username),
style = MaterialTheme.wireTypography.title01,
color = colorsScheme().onBackground
)
Expand Down Expand Up @@ -187,6 +190,6 @@ private fun TeamMigrationDoneStepContent(
@Composable
private fun TeamMigrationDoneStepScreenPreview() {
WireTheme {
TeamMigrationDoneStepContent({}, {}, teamName = "teamName")
TeamMigrationDoneStepContent({}, {}, username = "John", teamName = "teamName")
}
}
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@
<string name="url_why_verify_conversation" translatable="false">https://support.wire.com/hc/articles/207859815</string>
<string name="url_how_to_add_favorites" translatable="false">https://support.wire.com/hc/articles/360002855557</string>
<string name="url_wire_plans" translatable="false">https://wire.com/pricing</string>
<string name="url_team_management" translatable="false">https://teams.wire.com/</string>
<!-- Navigation -->
<string name="vault_screen_title">Vault</string>
<string name="archive_screen_title">Archive</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import com.wire.android.config.CoroutineTestExtension
import com.wire.android.feature.analytics.AnonymousAnalyticsManager
import com.wire.android.feature.analytics.model.AnalyticsEvent
import com.wire.kalium.logic.NetworkFailure
import com.wire.kalium.logic.feature.server.GetTeamUrlUseCase
import com.wire.kalium.logic.feature.user.GetSelfUserUseCase
import com.wire.kalium.logic.feature.user.migration.MigrateFromPersonalToTeamFailure
import com.wire.kalium.logic.feature.user.migration.MigrateFromPersonalToTeamResult
import com.wire.kalium.logic.feature.user.migration.MigrateFromPersonalToTeamUseCase
Expand All @@ -31,6 +33,7 @@ import io.mockk.coVerify
import io.mockk.impl.annotations.MockK
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.internal.assertEquals
import org.junit.jupiter.api.Assertions
Expand Down Expand Up @@ -251,13 +254,23 @@ class TeamMigrationViewModelTest {
@MockK
lateinit var migrateFromPersonalToTeam: MigrateFromPersonalToTeamUseCase

@MockK
lateinit var getSelfUser: GetSelfUserUseCase

@MockK
lateinit var getTeamUrl: GetTeamUrlUseCase

init {
MockKAnnotations.init(this, relaxUnitFun = true)
coEvery { getSelfUser() } returns flowOf()
coEvery { getTeamUrl() } returns "TeamUrl"
}

fun arrange() = this to TeamMigrationViewModel(
anonymousAnalyticsManager = anonymousAnalyticsManager,
migrateFromPersonalToTeam = migrateFromPersonalToTeam,
getSelfUser = getSelfUser,
getTeamUrl = getTeamUrl
).also { viewModel ->
viewModel.teamMigrationState.teamNameTextState.setTextAndPlaceCursorAtEnd(TEAM_NAME)
}
Expand Down

0 comments on commit 412a932

Please sign in to comment.