Skip to content

Commit

Permalink
feat: Add option to manage team [#WPB-14873] (#3753)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-zagorski authored Dec 18, 2024
1 parent e0e5c8b commit 22a0b22
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.wire.kalium.logic.feature.personaltoteamaccount.CanMigrateFromPersona
import com.wire.kalium.logic.feature.publicuser.GetAllContactsUseCase
import com.wire.kalium.logic.feature.publicuser.GetKnownUserUseCase
import com.wire.kalium.logic.feature.publicuser.RefreshUsersWithoutMetadataUseCase
import com.wire.kalium.logic.feature.server.GetTeamUrlUseCase
import com.wire.kalium.logic.feature.user.DeleteAccountUseCase
import com.wire.kalium.logic.feature.user.GetSelfUserUseCase
import com.wire.kalium.logic.feature.user.GetUserInfoUseCase
Expand Down Expand Up @@ -191,6 +192,11 @@ class UserModule {
fun provideGetSelfUseCase(userScope: UserScope): GetSelfUserUseCase =
userScope.getSelfUser

@ViewModelScoped
@Provides
fun provideGetTeamUrlUseCase(userScope: UserScope): GetTeamUrlUseCase =
userScope.getTeamUrl

@ViewModelScoped
@Provides
fun provideGetAvatarAssetUseCase(userScope: UserScope): GetAvatarAssetUseCase =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.scrollable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.defaultMinSize
Expand All @@ -43,6 +44,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -208,6 +210,7 @@ private fun SelfUserProfileContent(
isUserInCall: () -> Boolean
) {
val snackbarHostState = LocalSnackbarHostState.current
val uriHandler = LocalUriHandler.current

state.errorMessageCode?.let { errorCode ->
val errorMessage = mapErrorCodeToString(errorCode)
Expand Down Expand Up @@ -345,7 +348,13 @@ private fun SelfUserProfileContent(

Divider(color = MaterialTheme.wireColorScheme.outline)

Box(modifier = Modifier.padding(dimensions().spacing16x)) {
Column(
modifier = Modifier.padding(dimensions().spacing16x),
verticalArrangement = Arrangement.spacedBy(dimensions().spacing8x)
) {
if (teamUrl != null) {
ManageTeamButton { uriHandler.openUri(teamUrl) }
}
NewTeamButton(onAddAccountClick, isUserInCall, context)
}
}
Expand Down Expand Up @@ -440,6 +449,17 @@ private fun CurrentSelfUserStatus(
}
}

@Composable
private fun ManageTeamButton(
onManageTeamClick: () -> Unit
) {
WireSecondaryButton(
text = stringResource(R.string.user_profile_account_management),
onClickDescription = stringResource(R.string.content_description_self_profile_manage_team_btn),
onClick = onManageTeamClick
)
}

@Composable
private fun NewTeamButton(
onAddAccountClick: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ data class SelfUserProfileState(
val fullName: String = "",
val userName: String = "",
val teamName: String? = "", // maybe teamId is better here
val teamUrl: String? = null,
val otherAccounts: List<OtherAccount> = emptyList(),
val statusDialogData: StatusDialogData? = null, // null means no dialog to display
val isAvatarLoading: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ import com.wire.kalium.logic.data.user.SelfUser
import com.wire.kalium.logic.data.user.UserAssetId
import com.wire.kalium.logic.data.user.UserAvailabilityStatus
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.type.UserType
import com.wire.kalium.logic.feature.auth.LogoutUseCase
import com.wire.kalium.logic.feature.call.usecase.EndCallUseCase
import com.wire.kalium.logic.feature.call.usecase.ObserveEstablishedCallsUseCase
import com.wire.kalium.logic.feature.legalhold.LegalHoldStateForSelfUser
import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldStateForSelfUserUseCase
import com.wire.kalium.logic.feature.personaltoteamaccount.CanMigrateFromPersonalToTeamUseCase
import com.wire.kalium.logic.feature.server.GetTeamUrlUseCase
import com.wire.kalium.logic.feature.team.GetUpdatedSelfTeamUseCase
import com.wire.kalium.logic.feature.user.GetSelfUserUseCase
import com.wire.kalium.logic.feature.user.IsReadOnlyAccountUseCase
Expand Down Expand Up @@ -98,7 +100,8 @@ class SelfUserProfileViewModel @Inject constructor(
private val notificationManager: WireNotificationManager,
private val globalDataStore: GlobalDataStore,
private val qualifiedIdMapper: QualifiedIdMapper,
private val anonymousAnalyticsManager: AnonymousAnalyticsManager
private val anonymousAnalyticsManager: AnonymousAnalyticsManager,
private val getTeamUrl: GetTeamUrlUseCase
) : ViewModel() {

var userProfileState by mutableStateOf(SelfUserProfileState(userId = selfUserId, isAvatarLoading = true))
Expand Down Expand Up @@ -176,6 +179,7 @@ class SelfUserProfileViewModel @Inject constructor(
fullName = name.orEmpty(),
userName = handle.orEmpty(),
teamName = selfTeam?.name,
teamUrl = getTeamUrl().takeIf { userType == UserType.OWNER || userType == UserType.ADMIN },
otherAccounts = otherAccounts,
avatarAsset = userProfileState.avatarAsset,
isAvatarLoading = false,
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
<string name="content_description_self_profile_team">Team name, %s</string>
<string name="content_description_self_profile_change_status">change availability status</string>
<string name="content_description_self_profile_new_account_btn">Create a new team or personal account or log in</string>
<string name="content_description_self_profile_manage_team_btn">Manage team</string>
<string name="content_description_change_picture_back_btn">Go back to your profile overview</string>
<string name="content_description_welcome_screen_close_btn">Close new team creation and login view</string>
<string name="content_description_login_back_btn">Go back to new team creation and login view</string>
Expand Down Expand Up @@ -612,6 +613,7 @@
<string name="user_profile_status_away">Away</string>
<string name="user_profile_status_none">None</string>
<string name="user_profile_new_account_text">New Team or Add Account</string>
<string name="user_profile_account_management">Manage Team</string>
<string name="user_profile_details_tab">Details</string>
<string name="user_profile_devices_tab">Devices</string>
<string name="user_profile_group_tab">Group</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.wire.kalium.logic.feature.call.usecase.ObserveEstablishedCallsUseCase
import com.wire.kalium.logic.feature.legalhold.LegalHoldStateForSelfUser
import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldStateForSelfUserUseCase
import com.wire.kalium.logic.feature.personaltoteamaccount.CanMigrateFromPersonalToTeamUseCase
import com.wire.kalium.logic.feature.server.GetTeamUrlUseCase
import com.wire.kalium.logic.feature.team.GetUpdatedSelfTeamUseCase
import com.wire.kalium.logic.feature.user.GetSelfUserUseCase
import com.wire.kalium.logic.feature.user.IsReadOnlyAccountUseCase
Expand Down Expand Up @@ -101,6 +102,9 @@ class SelfUserProfileViewModelArrangement {
@MockK
lateinit var canMigrateFromPersonalToTeam: CanMigrateFromPersonalToTeamUseCase

@MockK
lateinit var getTeamUrl: GetTeamUrlUseCase

private val viewModel by lazy {
SelfUserProfileViewModel(
selfUserId = TestUser.SELF_USER.id,
Expand All @@ -121,7 +125,8 @@ class SelfUserProfileViewModelArrangement {
globalDataStore = globalDataStore,
qualifiedIdMapper = qualifiedIdMapper,
anonymousAnalyticsManager = anonymousAnalyticsManager,
canMigrateFromPersonalToTeam = canMigrateFromPersonalToTeam
canMigrateFromPersonalToTeam = canMigrateFromPersonalToTeam,
getTeamUrl = getTeamUrl
)
}

Expand All @@ -136,6 +141,7 @@ class SelfUserProfileViewModelArrangement {
coEvery { observeEstablishedCalls.invoke() } returns flowOf(emptyList())
coEvery { observeEstablishedCalls.invoke() } returns flowOf(emptyList())
coEvery { canMigrateFromPersonalToTeam.invoke() } returns true
coEvery { getTeamUrl.invoke() } returns ""
}

fun withLegalHoldStatus(result: LegalHoldStateForSelfUser) = apply {
Expand Down

0 comments on commit 22a0b22

Please sign in to comment.