Skip to content

Commit

Permalink
feat: Ask user to confirm canceling team migration (WPB-11268) (#3546)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohassine authored Oct 24, 2024
1 parent 46d80bb commit 8700565
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ import com.wire.android.ui.common.colorsScheme
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.common.preview.MultipleThemePreviews
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.userprofile.teammigration.common.ConfirmMigrationLeaveDialog

@OptIn(ExperimentalMaterialNavigationApi::class, ExperimentalAnimationApi::class)
@WireDestination(style = PopUpNavigationAnimation::class)
@Composable
fun TeamMigrationScreen(
navigator: Navigator,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
teamMigrationViewModel: TeamMigrationViewModel = hiltViewModel()
) {
val navHostEngine = rememberAnimatedNavHostEngine(
rootDefaultAnimations = RootNavGraphDefaultAnimations.ACCOMPANIST_FADING
Expand Down Expand Up @@ -93,8 +95,12 @@ fun TeamMigrationScreen(
IconButton(
modifier = Modifier.align(alignment = Alignment.End),
onClick = {
// TODO(next PR): show dialog to confirm exit before navigating back
navigator.navigateBack()
// If the user completed team migration, we don't need to show the dialog
if (navController.currentDestination?.route == NavGraphs.personalToTeamMigration.destinations.last().route) {
navigator.navigateBack()
} else {
teamMigrationViewModel.showMigrationLeaveDialog()
}
}
) {
Icon(
Expand All @@ -118,6 +124,17 @@ fun TeamMigrationScreen(
}
)
}

if (teamMigrationViewModel.teamMigrationState.shouldShowMigrationLeaveDialog) {
ConfirmMigrationLeaveDialog(
onContinue = {
teamMigrationViewModel.hideMigrationLeaveDialog()
}
) {
teamMigrationViewModel.hideMigrationLeaveDialog()
navigator.navigateBack()
}
}
}

@MultipleThemePreviews
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.android.ui.userprofile.teammigration

import androidx.compose.foundation.text.input.TextFieldState

data class TeamMigrationState(
val teamNameTextState: TextFieldState = TextFieldState(),
val passwordTextState: TextFieldState = TextFieldState(),
val shouldShowMigrationLeaveDialog: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@
*/
package com.wire.android.ui.userprofile.teammigration

import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class TeamMigrationViewModel @Inject constructor() : ViewModel() {
val teamNameTextState: TextFieldState = TextFieldState()
val passwordTextState: TextFieldState = TextFieldState()

var teamMigrationState by mutableStateOf(TeamMigrationState())
private set

fun showMigrationLeaveDialog() {
teamMigrationState = teamMigrationState.copy(shouldShowMigrationLeaveDialog = true)
}

fun hideMigrationLeaveDialog() {
teamMigrationState = teamMigrationState.copy(shouldShowMigrationLeaveDialog = false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.android.ui.userprofile.teammigration
package com.wire.android.ui.userprofile.teammigration.common

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.android.ui.userprofile.teammigration
package com.wire.android.ui.userprofile.teammigration.common

import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.android.ui.userprofile.teammigration.common

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.wire.android.R
import com.wire.android.ui.common.WireDialog
import com.wire.android.ui.common.WireDialogButtonProperties
import com.wire.android.ui.common.WireDialogButtonType
import com.wire.android.ui.theme.WireTheme
import com.wire.android.util.ui.PreviewMultipleThemes

@Composable
fun ConfirmMigrationLeaveDialog(
onContinue: () -> Unit,
onLeave: () -> Unit
) {
WireDialog(
title = stringResource(R.string.personal_to_team_migration_confirm_leave_dialog_title),
text = stringResource(R.string.personal_to_team_migration_confirm_leave_dialog_description),
onDismiss = { },
optionButton1Properties = WireDialogButtonProperties(
onClick = onContinue,
text = stringResource(R.string.personal_to_team_migration_confirm_leave_dialog_continue_button),
type = WireDialogButtonType.Primary
),
optionButton2Properties = WireDialogButtonProperties(
text = stringResource(id = R.string.personal_to_team_migration_confirm_leave_dialog_leave_button),
onClick = onLeave,
type = WireDialogButtonType.Secondary
),
buttonsHorizontalAlignment = false
)
}

@PreviewMultipleThemes
@Composable
private fun ConfirmMigrationLeaveDialogPreview() {
WireTheme {
ConfirmMigrationLeaveDialog({}, {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import com.wire.android.ui.common.dimensions
import com.wire.android.ui.destinations.TeamMigrationTeamNameStepScreenDestination
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireTypography
import com.wire.android.ui.userprofile.teammigration.BottomLineButtons
import com.wire.android.ui.userprofile.teammigration.common.BottomLineButtons
import com.wire.android.ui.userprofile.teammigration.PersonalToTeamMigrationNavGraph
import com.wire.android.util.CustomTabsHelper
import com.wire.android.util.ui.PreviewMultipleThemes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import com.wire.android.ui.common.textfield.WireTextField
import com.wire.android.ui.destinations.TeamMigrationConfirmationStepScreenDestination
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireTypography
import com.wire.android.ui.userprofile.teammigration.BottomLineButtons
import com.wire.android.ui.userprofile.teammigration.common.BottomLineButtons
import com.wire.android.ui.userprofile.teammigration.PersonalToTeamMigrationNavGraph
import com.wire.android.ui.userprofile.teammigration.TeamMigrationViewModel
import com.wire.android.util.ui.PreviewMultipleThemes
Expand All @@ -64,7 +64,7 @@ fun TeamMigrationTeamNameStepScreen(
onBackButtonClicked = {
navigator.popBackStack()
},
teamNameTextFieldState = teamMigrationViewModel.teamNameTextState
teamNameTextFieldState = teamMigrationViewModel.teamMigrationState.teamNameTextState
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ import com.wire.android.ui.common.textfield.WirePasswordTextField
import com.wire.android.ui.destinations.TeamMigrationDoneStepScreenDestination
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireTypography
import com.wire.android.ui.userprofile.teammigration.BottomLineButtons
import com.wire.android.ui.userprofile.teammigration.BulletList
import com.wire.android.ui.userprofile.teammigration.common.BottomLineButtons
import com.wire.android.ui.userprofile.teammigration.common.BulletList
import com.wire.android.ui.userprofile.teammigration.PersonalToTeamMigrationNavGraph
import com.wire.android.ui.userprofile.teammigration.TeamMigrationViewModel
import com.wire.android.util.CustomTabsHelper
Expand All @@ -80,7 +80,7 @@ fun TeamMigrationConfirmationStepScreen(
onBackPressed = {
navigator.popBackStack()
},
passwordTextState = teamMigrationViewModel.passwordTextState
passwordTextState = teamMigrationViewModel.teamMigrationState.passwordTextState
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import com.wire.android.ui.common.spacers.VerticalSpace.x32
import com.wire.android.ui.destinations.HomeScreenDestination
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireTypography
import com.wire.android.ui.userprofile.teammigration.BulletList
import com.wire.android.ui.userprofile.teammigration.common.BulletList
import com.wire.android.ui.userprofile.teammigration.PersonalToTeamMigrationNavGraph
import com.wire.android.ui.userprofile.teammigration.TeamMigrationViewModel
import com.wire.android.util.CustomTabsHelper
Expand Down Expand Up @@ -75,7 +75,7 @@ fun TeamMigrationDoneStepScreen(
onOpenTeamManagementClicked = {
CustomTabsHelper.launchUrl(context, teamManagementUrl)
},
teamName = teamMigrationViewModel.teamNameTextState.text.toString()
teamName = teamMigrationViewModel.teamMigrationState.teamNameTextState.text.toString()
)

BackHandler { }
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1557,4 +1557,9 @@ In group conversations, the group admin can overwrite this setting.</string>
<string name="personal_to_team_migration_done_step_bullet_list_first_item">Invite your first team members, and start working together</string>
<string name="personal_to_team_migration_done_step_bullet_list_second_item">Customize your team settings</string>

<string name="personal_to_team_migration_confirm_leave_dialog_title">Leave without saving?</string>
<string name="personal_to_team_migration_confirm_leave_dialog_description">When you leave now, you lose your progress and need to restart the team creation.</string>
<string name="personal_to_team_migration_confirm_leave_dialog_continue_button">Continue Team Creation</string>
<string name="personal_to_team_migration_confirm_leave_dialog_leave_button">Leave Without Saving</string>

</resources>

0 comments on commit 8700565

Please sign in to comment.