Skip to content

Commit

Permalink
Merge pull request #2351 from HedvigInsurance/feature/2-home-insuranc…
Browse files Browse the repository at this point in the history
…es-error-screen

add go to chat button to error screen in the addon purchase flow
  • Loading branch information
panasetskaya authored Dec 12, 2024
2 parents 9be2bb2 + c87c6d0 commit cbef7fc
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ internal fun HedvigNavHost(
addonPurchaseNavGraph(
navigator = navigator,
navController = hedvigAppState.navController,
onNavigateToNewConversation = { navigateToNewConversation() },
)
changeTierGraph(
navigator = navigator,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hedvig.android.feature.addon.purchase.navigation

import androidx.compose.runtime.LaunchedEffect
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import com.hedvig.android.feature.addon.purchase.navigation.AddonPurchaseDestination.ChooseInsuranceToAddAddonDestination
Expand All @@ -25,7 +26,11 @@ import com.hedvig.android.navigation.core.Navigator
import org.koin.androidx.compose.koinViewModel
import org.koin.core.parameter.parametersOf

fun NavGraphBuilder.addonPurchaseNavGraph(navigator: Navigator, navController: NavController) {
fun NavGraphBuilder.addonPurchaseNavGraph(
navigator: Navigator,
navController: NavController,
onNavigateToNewConversation: (NavBackStackEntry) -> Unit,
) {
navgraph<AddonPurchaseGraphDestination>(
startDestination = ChooseInsuranceToAddAddonDestination::class,
) {
Expand Down Expand Up @@ -72,6 +77,10 @@ fun NavGraphBuilder.addonPurchaseNavGraph(navigator: Navigator, navController: N
navigateToSummary = { summaryParameters: SummaryParameters ->
navigator.navigateUnsafe(Summary(summaryParameters))
},
onNavigateToNewConversation = {
navController.typedPopBackStack<AddonPurchaseGraphDestination>(inclusive = true) // todo: is this the right thing?
onNavigateToNewConversation(backStackEntry)
},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ internal fun CustomizeTravelAddonDestination(
popBackStack: () -> Unit,
popAddonFlow: () -> Unit,
navigateToSummary: (summaryParameters: SummaryParameters) -> Unit,
onNavigateToNewConversation: () -> Unit,
) {
val uiState: CustomizeTravelAddonState by viewModel.uiState.collectAsStateWithLifecycle()
CustomizeTravelAddonScreen(
Expand All @@ -104,6 +105,7 @@ internal fun CustomizeTravelAddonDestination(
onSetOptionBackToPreviouslyChosen = {
viewModel.emit(CustomizeTravelAddonEvent.SetOptionBackToPreviouslyChosen)
},
navigateToChat = onNavigateToNewConversation,
)
}

Expand All @@ -118,12 +120,19 @@ private fun CustomizeTravelAddonScreen(
onSetOptionBackToPreviouslyChosen: () -> Unit,
reload: () -> Unit,
popAddonFlow: () -> Unit,
navigateToChat: () -> Unit,
) {
Box(
Modifier.fillMaxSize(),
) {
when (val state = uiState) {
is CustomizeTravelAddonState.Failure -> FailureScreen(state.errorMessage, reload, popBackStack)
is CustomizeTravelAddonState.Failure -> FailureScreen(
errorMessage = state.errorMessage,
reload = reload,
popBackStack = popBackStack,
navigateToChat = navigateToChat,
)

CustomizeTravelAddonState.Loading -> HedvigFullScreenCenterAlignedProgress()
is CustomizeTravelAddonState.Success -> CustomizeTravelAddonScreenContent(
uiState = state,
Expand All @@ -147,7 +156,12 @@ private fun CustomizeTravelAddonScreen(
}

@Composable
private fun FailureScreen(errorMessage: String?, reload: () -> Unit, popBackStack: () -> Unit) {
private fun FailureScreen(
errorMessage: String?,
reload: () -> Unit,
popBackStack: () -> Unit,
navigateToChat: () -> Unit,
) {
Box(Modifier.fillMaxSize()) {
Column(
modifier = Modifier
Expand All @@ -161,10 +175,16 @@ private fun FailureScreen(errorMessage: String?, reload: () -> Unit, popBackStac
),
) {
Spacer(Modifier.weight(1f))
val buttonText = if (errorMessage == null) {
stringResource(R.string.GENERAL_RETRY)
} else {
stringResource(R.string.open_chat)
}
HedvigErrorSection(
onButtonClick = reload,
onButtonClick = if (errorMessage == null) reload else navigateToChat,
subTitle = errorMessage ?: stringResource(R.string.GENERAL_ERROR_BODY),
modifier = Modifier.fillMaxSize(),
buttonText = buttonText,
)
Spacer(Modifier.weight(1f))
HedvigTextButton(
Expand Down Expand Up @@ -500,6 +520,7 @@ private fun SelectTierScreenPreview(
{},
{},
{},
{},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ private fun DeflectGlassDamageScreen(
.fillMaxWidth(),
) {
Surface(
color = HedvigTheme.colorScheme.backgroundPrimary.copy(0.95f).compositeOver(HedvigTheme.colorScheme.fillWhite),
color = HedvigTheme.colorScheme.backgroundPrimary.copy(
0.95f,
).compositeOver(HedvigTheme.colorScheme.fillWhite),
contentColor = HedvigTheme.colorScheme.fillPrimary,
) {
Column(Modifier.padding(16.dp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private fun DeflectPestsScreen(
"""
|Partner URL was null for DeflectPestsDestination! Deflect partner:[$this].
|This is problematic because the UI offers no real help to the member, the CTA button does nothing.
""".trimMargin()
""".trimMargin()
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private fun DeflectTowingScreen(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
) {
) {
Column(Modifier.padding(16.dp)) {
AsyncImage(
model = partner.imageUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class TerminateInsuranceRepositoryImplTest {
fixedMap = mapOf(
Feature.TIER to false,
Feature.TRAVEL_ADDON to false,
)
),
)

val repo = TerminateInsuranceRepositoryImpl(
Expand Down Expand Up @@ -185,7 +185,7 @@ class TerminateInsuranceRepositoryImplTest {
fixedMap = mapOf(
Feature.TIER to true,
Feature.TRAVEL_ADDON to false,
)
),
)

val repo = TerminateInsuranceRepositoryImpl(
Expand Down Expand Up @@ -230,7 +230,7 @@ class TerminateInsuranceRepositoryImplTest {
fixedMap = mapOf(
Feature.TIER to false,
Feature.TRAVEL_ADDON to false,
)
),
)

val repo = TerminateInsuranceRepositoryImpl(
Expand Down Expand Up @@ -261,7 +261,7 @@ class TerminateInsuranceRepositoryImplTest {
fixedMap = mapOf(
Feature.TIER to true,
Feature.TRAVEL_ADDON to false,
)
),
)

val repo = TerminateInsuranceRepositoryImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.LineBreak
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.hedvig.android.design.system.hedvig.AccordionData
import com.hedvig.android.design.system.hedvig.AccordionList
Expand Down Expand Up @@ -62,7 +61,9 @@ fun EmergencyScreen(
Spacer(Modifier.height(8.dp))
HedvigTheme(darkTheme = true) {
Surface(
color = HedvigTheme.colorScheme.backgroundPrimary.copy(0.95f).compositeOver(HedvigTheme.colorScheme.fillWhite),
color = HedvigTheme.colorScheme.backgroundPrimary.copy(
0.95f,
).compositeOver(HedvigTheme.colorScheme.fillWhite),
contentColor = HedvigTheme.colorScheme.fillPrimary,
shape = HedvigTheme.shapes.cornerXLarge,
modifier = Modifier
Expand Down

0 comments on commit cbef7fc

Please sign in to comment.