Skip to content

Commit

Permalink
Add exit dialog in tier flow
Browse files Browse the repository at this point in the history
  • Loading branch information
StylianosGakis committed Nov 13, 2024
1 parent 1c64b69 commit 31ab83f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryViewModel
import com.hedvig.android.navigation.compose.navdestination
import com.hedvig.android.navigation.compose.navgraph
import com.hedvig.android.navigation.compose.typed.getRouteFromBackStack
import com.hedvig.android.navigation.compose.typedPopBackStack
import com.hedvig.android.navigation.compose.typedPopUpTo
import com.hedvig.android.navigation.core.Navigator
import com.hedvig.android.shared.tier.comparison.navigation.ComparisonParameters
Expand Down Expand Up @@ -121,6 +122,9 @@ fun NavGraphBuilder.changeTierGraph(navigator: Navigator, navController: NavCont
ChangeTierSummaryDestination(
viewModel = viewModel,
navigateUp = navigator::navigateUp,
onExitTierFlow = {
navController.typedPopBackStack<ChooseTierGraphDestination>(inclusive = true)
},
onFailure = {
navigator.navigateUnsafe(ChooseTierDestination.SubmitFailure)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.compose.dropUnlessResumed
import com.hedvig.android.core.uidata.UiCurrencyCode.SEK
import com.hedvig.android.core.uidata.UiMoney
import com.hedvig.android.data.changetier.data.Deductible
Expand All @@ -29,8 +33,10 @@ import com.hedvig.android.data.contract.ContractType
import com.hedvig.android.data.productvariant.ProductVariant
import com.hedvig.android.design.system.hedvig.ButtonDefaults.ButtonSize.Large
import com.hedvig.android.design.system.hedvig.ButtonDefaults.ButtonStyle.Primary
import com.hedvig.android.design.system.hedvig.DialogDefaults.DialogStyle.Buttons
import com.hedvig.android.design.system.hedvig.HedvigAlertDialog
import com.hedvig.android.design.system.hedvig.HedvigButton
import com.hedvig.android.design.system.hedvig.HedvigDialog
import com.hedvig.android.design.system.hedvig.HedvigErrorSection
import com.hedvig.android.design.system.hedvig.HedvigFullScreenCenterAlignedLinearProgress
import com.hedvig.android.design.system.hedvig.HedvigFullScreenCenterAlignedProgress
Expand All @@ -39,7 +45,11 @@ import com.hedvig.android.design.system.hedvig.HedvigScaffold
import com.hedvig.android.design.system.hedvig.HedvigText
import com.hedvig.android.design.system.hedvig.HedvigTheme
import com.hedvig.android.design.system.hedvig.HorizontalItemsWithMaximumSpaceTaken
import com.hedvig.android.design.system.hedvig.Icon
import com.hedvig.android.design.system.hedvig.IconButton
import com.hedvig.android.design.system.hedvig.Surface
import com.hedvig.android.design.system.hedvig.icon.Close
import com.hedvig.android.design.system.hedvig.icon.HedvigIcons
import com.hedvig.android.feature.change.tier.ui.stepcustomize.ContractData
import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryState.Failure
import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryState.Loading
Expand All @@ -53,6 +63,7 @@ import hedvig.resources.R
internal fun ChangeTierSummaryDestination(
viewModel: SummaryViewModel,
navigateUp: () -> Unit,
onExitTierFlow: () -> Unit,
onSuccess: () -> Unit,
onFailure: () -> Unit,
) {
Expand All @@ -74,6 +85,7 @@ internal fun ChangeTierSummaryDestination(
onSubmitQuoteClick = {
viewModel.emit(SummaryEvent.SubmitQuote)
},
onExitTierFlow = onExitTierFlow,
)
}

Expand All @@ -85,6 +97,7 @@ private fun SummaryScreen(
navigateUp: () -> Unit,
onFailure: () -> Unit,
onSubmitQuoteClick: () -> Unit,
onExitTierFlow: () -> Unit,
) {
when (uiState) {
Failure -> HedvigScaffold(navigateUp) {
Expand Down Expand Up @@ -120,6 +133,7 @@ private fun SummaryScreen(
uiState = uiState,
navigateUp = navigateUp,
onConfirmClick = onSubmitQuoteClick,
onExitTierFlow = onExitTierFlow,
)
}
}
Expand All @@ -134,9 +148,17 @@ private fun MakingChangesScreen() {
}

@Composable
private fun SummarySuccessScreen(uiState: Success, onConfirmClick: () -> Unit, navigateUp: () -> Unit) {
private fun SummarySuccessScreen(
uiState: Success,
onConfirmClick: () -> Unit,
navigateUp: () -> Unit,
onExitTierFlow: () -> Unit,
) {
HedvigScaffold(
navigateUp,
topAppBarActions = {
SummaryTopAppBar(onExitTierFlow)
},
topAppBarText = stringResource(R.string.TIER_FLOW_SUMMARY_TITLE),
) {
var showConfirmationDialog by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -194,6 +216,40 @@ private fun SummarySuccessScreen(uiState: Success, onConfirmClick: () -> Unit, n
}
}

@Composable
private fun SummaryTopAppBar(onExitTierFlow: () -> Unit) {
var showExitDialog by rememberSaveable { mutableStateOf(false) }
if (showExitDialog) {
HedvigDialog(
onDismissRequest = { showExitDialog = false },
style = Buttons(
onDismissRequest = { showExitDialog = false },
dismissButtonText = stringResource(R.string.GENERAL_NO),
onConfirmButtonClick = dropUnlessResumed {
showExitDialog = false
onExitTierFlow()
},
confirmButtonText = stringResource(R.string.GENERAL_YES),
),
) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
HedvigText(
text = stringResource(R.string.GENERAL_ARE_YOU_SURE),
textAlign = TextAlign.Center,
)
HedvigText(
text = stringResource(R.string.GENERAL_PROGRESS_WILL_BE_LOST_ALERT),
textAlign = TextAlign.Center,
color = HedvigTheme.colorScheme.textSecondary,
)
}
}
}
IconButton({ showExitDialog = true }) {
Icon(HedvigIcons.Close, null, Modifier.size(24.dp))
}
}

@Composable
private fun SummaryCard(uiState: Success, modifier: Modifier = Modifier) {
QuoteCard(
Expand Down Expand Up @@ -239,6 +295,7 @@ private fun PreviewChooseInsuranceScreen(
{},
{},
{},
{},
)
}
}
Expand Down

0 comments on commit 31ab83f

Please sign in to comment.