Skip to content

Commit

Permalink
Merge pull request #2349 from HedvigInsurance/feature/45-to-60-upgrade
Browse files Browse the repository at this point in the history
Feature/45 to 60 upgrade
  • Loading branch information
panasetskaya authored Dec 12, 2024
2 parents 6bb9af1 + ba3b511 commit 5efc6f4
Show file tree
Hide file tree
Showing 11 changed files with 476 additions and 127 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package com.hedvig.android.design.system.hedvig

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import com.halilibo.richtext.ui.BasicRichText
import com.halilibo.richtext.ui.LinkClickHandler
import com.halilibo.richtext.ui.RichTextScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal sealed interface Addon {
val title: String,
val description: String,
val activationDate: LocalDate,
val currentTravelAddon: CurrentTravelAddon?,
) : Addon
}

Expand All @@ -30,3 +31,9 @@ internal data class AddonVariant(
val termsVersion: String,
val displayDetails: List<Pair<String, String>>,
)

@Serializable
internal data class CurrentTravelAddon(
val price: UiMoney,
val displayDetails: List<Pair<String, String>>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,89 @@ internal class GetTravelAddonOfferUseCaseImpl(
) : GetTravelAddonOfferUseCase {
override suspend fun invoke(id: String): Either<ErrorMessage, TravelAddonOffer> {
// todo: REMOVE MOCK!

return either {
TravelAddonOffer(
addonOptions = nonEmptyListOf(
TravelAddonQuote(
quoteId = "id",
addonId = "addonId1",
displayName = "45 days",
addonVariant = AddonVariant(
termsVersion = "terms",
documents = listOf(
InsuranceVariantDocument(
"Terms and conditions",
"www.url.com",
InsuranceVariantDocument.InsuranceDocumentType.TERMS_AND_CONDITIONS,
),
),
displayDetails = listOf(),
),
price = UiMoney(
49.0,
UiCurrencyCode.SEK,
),
),
TravelAddonQuote(
displayName = "60 days",
addonId = "addonId1",
quoteId = "id",
addonVariant = AddonVariant(
termsVersion = "terms",
documents = listOf(),
displayDetails = listOf(),
),
price = UiMoney(
60.0,
UiCurrencyCode.SEK,
),
),
),
title = "Travel plus",
description = "For those who travel often: luggage protection and 24/7 assistance worldwide",
activationDate = LocalDate(2025, 1, 1),
)
mockWithUpgrade
}
}
}

private val mockWithoutUpgrade = TravelAddonOffer(
addonOptions = nonEmptyListOf(
TravelAddonQuote(
quoteId = "id",
addonId = "addonId1",
displayName = "45 days",
addonVariant = AddonVariant(
termsVersion = "terms",
documents = listOf(
InsuranceVariantDocument(
"Terms and conditions",
"www.url.com",
InsuranceVariantDocument.InsuranceDocumentType.TERMS_AND_CONDITIONS,
),
),
displayDetails = listOf("Coverage" to "45 days", "Insured people" to "You+1"),
),
price = UiMoney(
49.0,
UiCurrencyCode.SEK,
),
),
TravelAddonQuote(
displayName = "60 days",
addonId = "addonId1",
quoteId = "id",
addonVariant = AddonVariant(
termsVersion = "terms",
documents = listOf(
InsuranceVariantDocument(
"Terms and conditions",
"www.url.com",
InsuranceVariantDocument.InsuranceDocumentType.TERMS_AND_CONDITIONS,
),
),
displayDetails = listOf("Coverage" to "60 days", "Insured people" to "You+1"),
),
price = UiMoney(
60.0,
UiCurrencyCode.SEK,
),
),
),
title = "Travel plus",
description = "For those who travel often: luggage protection and 24/7 assistance worldwide",
activationDate = LocalDate(2025, 1, 1),
currentTravelAddon = null,
)

private val mockWithUpgrade = TravelAddonOffer(
addonOptions = nonEmptyListOf(
TravelAddonQuote(
displayName = "60 days",
addonId = "addonId1",
quoteId = "id",
addonVariant = AddonVariant(
termsVersion = "terms",
documents = listOf(
InsuranceVariantDocument(
"Terms and conditions",
"www.url.com",
InsuranceVariantDocument.InsuranceDocumentType.TERMS_AND_CONDITIONS,
),
),
displayDetails = listOf("Coverage" to "60 days", "Insured people" to "You+1"),
),
price = UiMoney(
60.0,
UiCurrencyCode.SEK,
),
),
),
title = "Travel plus",
description = "For those who travel often: luggage protection and 24/7 assistance worldwide",
activationDate = LocalDate(2025, 1, 1),
currentTravelAddon = CurrentTravelAddon(
UiMoney(49.0, UiCurrencyCode.SEK),
listOf("Coverage" to "45 days", "Insured people" to "You+1"),
),
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hedvig.android.feature.addon.purchase.navigation

import com.hedvig.android.feature.addon.purchase.data.CurrentTravelAddon
import com.hedvig.android.feature.addon.purchase.data.TravelAddonQuote
import com.hedvig.android.navigation.common.Destination
import com.hedvig.android.navigation.common.DestinationNavTypeAware
Expand Down Expand Up @@ -45,4 +46,6 @@ internal data class SummaryParameters(
val offerDisplayName: String,
val quote: TravelAddonQuote,
val activationDate: LocalDate,
val currentTravelAddon: CurrentTravelAddon?,
val popCustomizeDestination: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,18 @@ fun NavGraphBuilder.addonPurchaseNavGraph(
navController.typedPopBackStack<AddonPurchaseGraphDestination>(inclusive = true)
},
navigateToSummary = { summaryParameters: SummaryParameters ->
navigator.navigateUnsafe(Summary(summaryParameters))
if (summaryParameters.popCustomizeDestination) {
navigator.navigateUnsafe(Summary(summaryParameters)) {
typedPopUpTo<CustomizeAddon> {
inclusive = true
}
}
} else {
navigator.navigateUnsafe(Summary(summaryParameters))
}
},
onNavigateToNewConversation = {
navController.typedPopBackStack<AddonPurchaseGraphDestination>(inclusive = true) // todo: is this the right thing?
navController.typedPopBackStack<AddonPurchaseGraphDestination>(inclusive = true)
onNavigateToNewConversation(backStackEntry)
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -90,8 +91,8 @@ internal fun CustomizeTravelAddonDestination(
navigateUp = navigateUp,
popBackStack = popBackStack,
popAddonFlow = popAddonFlow,
navigateToSummary = { summaryParams ->
navigateToSummary(summaryParams)
submitToSummary = {
viewModel.emit(CustomizeTravelAddonEvent.SubmitSelected)
},
reload = {
viewModel.emit(CustomizeTravelAddonEvent.Reload)
Expand All @@ -105,6 +106,10 @@ internal fun CustomizeTravelAddonDestination(
onSetOptionBackToPreviouslyChosen = {
viewModel.emit(CustomizeTravelAddonEvent.SetOptionBackToPreviouslyChosen)
},
navigateToSummary = { params ->
viewModel.emit(CustomizeTravelAddonEvent.ClearNavigation)
navigateToSummary(params)
},
navigateToChat = onNavigateToNewConversation,
)
}
Expand All @@ -114,7 +119,8 @@ private fun CustomizeTravelAddonScreen(
uiState: CustomizeTravelAddonState,
navigateUp: () -> Unit,
popBackStack: () -> Unit,
navigateToSummary: (SummaryParameters) -> Unit,
submitToSummary: () -> Unit,
navigateToSummary: (summaryParameters: SummaryParameters) -> Unit,
onChooseOptionInDialog: (TravelAddonQuote) -> Unit,
onChooseSelectedOption: () -> Unit,
onSetOptionBackToPreviouslyChosen: () -> Unit,
Expand All @@ -132,25 +138,27 @@ private fun CustomizeTravelAddonScreen(
popBackStack = popBackStack,
navigateToChat = navigateToChat,
)

CustomizeTravelAddonState.Loading -> HedvigFullScreenCenterAlignedProgress()
is CustomizeTravelAddonState.Success -> CustomizeTravelAddonScreenContent(
uiState = state,
navigateUp = navigateUp,
navigateToSummary = { quote ->
navigateToSummary(
SummaryParameters(
state.travelAddonOffer.title,
quote,
state.travelAddonOffer.activationDate,
),
CustomizeTravelAddonState.Loading -> {
HedvigFullScreenCenterAlignedProgress()
}
is CustomizeTravelAddonState.Success -> {
LaunchedEffect(state.summaryParamsToNavigateFurther) {
if (state.summaryParamsToNavigateFurther != null) {
navigateToSummary(state.summaryParamsToNavigateFurther)
}
}
if (state.summaryParamsToNavigateFurther == null) {
CustomizeTravelAddonScreenContent(
uiState = state,
navigateUp = navigateUp,
submitToSummary = submitToSummary,
onChooseSelectedOption = onChooseSelectedOption,
onChooseOptionInDialog = onChooseOptionInDialog,
onSetOptionBackToPreviouslyChosen = onSetOptionBackToPreviouslyChosen,
popAddonFlow = popAddonFlow,
)
},
onChooseSelectedOption = onChooseSelectedOption,
onChooseOptionInDialog = onChooseOptionInDialog,
onSetOptionBackToPreviouslyChosen = onSetOptionBackToPreviouslyChosen,
popAddonFlow = popAddonFlow,
)
}
}
}
}
}
Expand Down Expand Up @@ -206,7 +214,7 @@ private fun CustomizeTravelAddonScreenContent(
onChooseOptionInDialog: (TravelAddonQuote) -> Unit,
onChooseSelectedOption: () -> Unit,
onSetOptionBackToPreviouslyChosen: () -> Unit,
navigateToSummary: (travelAddonQuote: TravelAddonQuote) -> Unit,
submitToSummary: () -> Unit,
) {
val referralExplanationBottomSheetState = rememberHedvigBottomSheetState<Unit>()
HedvigScaffold(
Expand Down Expand Up @@ -261,7 +269,9 @@ private fun CustomizeTravelAddonScreenContent(
buttonSize = Large,
text = stringResource(R.string.ADDON_FLOW_ADD_TO_INSURANCE_BUTTON),
enabled = true,
onClick = dropUnlessResumed { navigateToSummary(uiState.currentlyChosenOption) },
onClick = dropUnlessResumed {
submitToSummary()
},
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
Expand Down Expand Up @@ -514,7 +524,8 @@ private fun SelectTierScreenPreview(
uiState = uiState,
{},
{},
{ _ -> },
{ },
{},
{},
{},
{},
Expand Down Expand Up @@ -575,4 +586,5 @@ private val fakeTravelAddon = TravelAddonOffer(
title = "Travel Plus",
description = "For those who travel often: luggage protection and 24/7 assistance worldwide",
activationDate = LocalDate(2024, 12, 30),
currentTravelAddon = null,
)
Loading

0 comments on commit 5efc6f4

Please sign in to comment.