Skip to content

Commit

Permalink
Merge pull request #2378 from HedvigInsurance/feature/moving-flow-add…
Browse files Browse the repository at this point in the history
…on-exclusion-bottom-sheet

Add bottom sheet with info when excluding an addon
  • Loading branch information
panasetskaya authored Jan 18, 2025
2 parents 990bbe3 + 0aba92a commit e86c8e6
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.hedvig.android.data.addons.data
import arrow.core.Either
import arrow.core.NonEmptyList
import arrow.core.raise.either
import arrow.core.raise.ensureNotNull
import arrow.core.toNonEmptyListOrNull
import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo.cache.normalized.FetchPolicy.CacheAndNetwork
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import com.hedvig.android.design.system.hedvig.tokens.SmallSizeDefaultToggleToke
import com.hedvig.android.design.system.hedvig.tokens.SmallSizeDetailedToggleTokens
import com.hedvig.android.design.system.hedvig.tokens.ToggleColorTokens
import com.hedvig.android.design.system.hedvig.tokens.ToggleIconSizeTokens
import com.hedvig.android.logger.logcat
import kotlin.math.roundToInt
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mutation MoveIntentV2Request($intentId: ID!,
mutation MoveIntentV2Request(
$intentId: ID!,
$moveIntentRequestInput: MoveIntentRequestInput!,
$addonsFlagOn: Boolean!) {
$addonsFlagOn: Boolean!,
) {
moveIntentRequest(intentId: $intentId, input: $moveIntentRequestInput) {
moveIntent {
...MoveIntentQuotesFragment
Expand Down Expand Up @@ -79,4 +81,10 @@ fragment MoveAddonQuoteFragment on MoveAddonQuote {
addonVariant {
...AddonVariantFragment
}
removeDialogInfo {
title
description
confirmButtonTitle
cancelButtonTitle
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.hedvig.android.feature.movingflow.data.MovingFlowQuotes.DisplayItem
import com.hedvig.android.feature.movingflow.data.MovingFlowQuotes.MoveHomeQuote
import com.hedvig.android.feature.movingflow.data.MovingFlowQuotes.MoveHomeQuote.Deductible
import com.hedvig.android.feature.movingflow.data.MovingFlowQuotes.MoveMtaQuote
import com.hedvig.android.feature.movingflow.data.MovingFlowQuotes.UserExcludable.ExclusionDialogInfo
import kotlinx.datetime.LocalDate
import kotlinx.serialization.Serializable
import octopus.feature.movingflow.fragment.MoveIntentQuotesFragment
Expand Down Expand Up @@ -72,7 +73,7 @@ internal data class MovingFlowQuotes(
)

internal sealed interface AddonQuote {
val addonId: String
val addonId: AddonId
val premium: UiMoney
val startDate: LocalDate
val displayItems: List<DisplayItem>
Expand All @@ -81,18 +82,19 @@ internal data class MovingFlowQuotes(

@Serializable
data class HomeAddonQuote(
override val addonId: String,
override val addonId: AddonId,
override val premium: UiMoney,
override val startDate: LocalDate,
override val displayItems: List<DisplayItem>,
override val exposureName: String,
override val addonVariant: AddonVariant,
override val isExcludedByUser: Boolean,
override val exclusionDialogInfo: ExclusionDialogInfo?,
) : AddonQuote, UserExcludable

@Serializable
data class MtaAddonQuote(
override val addonId: String,
override val addonId: AddonId,
override val premium: UiMoney,
override val startDate: LocalDate,
override val displayItems: List<DisplayItem>,
Expand All @@ -103,9 +105,23 @@ internal data class MovingFlowQuotes(

internal interface UserExcludable {
val isExcludedByUser: Boolean
val exclusionDialogInfo: ExclusionDialogInfo?

@Serializable
data class ExclusionDialogInfo(
val addonId: AddonId,
val title: String,
val description: String,
val confirmButtonTitle: String,
val cancelButtonTitle: String,
)
}
}

@Serializable
@JvmInline
internal value class AddonId(val id: String)

internal fun MoveIntentQuotesFragment.toMovingFlowQuotes(): MovingFlowQuotes {
return MovingFlowQuotes(
homeQuotes = homeQuotes.orEmpty().map { houseQuote ->
Expand All @@ -129,7 +145,7 @@ internal fun MoveIntentQuotesFragment.toMovingFlowQuotes(): MovingFlowQuotes {
defaultChoice = houseQuote.defaultChoice,
relatedAddonQuotes = houseQuote.addons.orEmpty().map { addon ->
HomeAddonQuote(
addonId = addon.addonId,
addonId = AddonId(addon.addonId),
premium = UiMoney.fromMoneyFragment(addon.premium),
startDate = addon.startDate,
exposureName = addon.displayName,
Expand All @@ -141,6 +157,15 @@ internal fun MoveIntentQuotesFragment.toMovingFlowQuotes(): MovingFlowQuotes {
)
},
addonVariant = addon.addonVariant.toAddonVariant(),
exclusionDialogInfo = addon.removeDialogInfo?.let { removeDialogInfo ->
ExclusionDialogInfo(
addonId = AddonId(addon.addonId),
title = removeDialogInfo.title,
description = removeDialogInfo.description,
confirmButtonTitle = removeDialogInfo.confirmButtonTitle,
cancelButtonTitle = removeDialogInfo.cancelButtonTitle,
)
},
isExcludedByUser = false,
)
},
Expand All @@ -155,7 +180,7 @@ internal fun MoveIntentQuotesFragment.toMovingFlowQuotes(): MovingFlowQuotes {
displayItems = mtaQuote.displayItems.map { it.toDisplayItem() },
relatedAddonQuotes = mtaQuote.addons.orEmpty().map { addon ->
MtaAddonQuote(
addonId = addon.addonId,
addonId = AddonId(addon.addonId),
premium = UiMoney.fromMoneyFragment(addon.premium),
startDate = addon.startDate,
exposureName = addon.displayName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hedvig.android.feature.movingflow.storage

import com.hedvig.android.feature.movingflow.data.AddonId
import com.hedvig.android.feature.movingflow.data.HousingType
import com.hedvig.android.feature.movingflow.data.MovingFlowQuotes
import com.hedvig.android.feature.movingflow.data.MovingFlowState
import com.hedvig.android.feature.movingflow.data.MovingFlowState.PropertyState.ApartmentState
import com.hedvig.android.feature.movingflow.data.MovingFlowState.PropertyState.ApartmentState.IsAvailableForStudentState.Available
Expand Down Expand Up @@ -122,14 +122,14 @@ internal class MovingFlowRepository(
}

// Flips the mark of a home addon which determines if they do not wish to contain that addon in their new quote
suspend fun toggleHomeAddonExclusion(addonQuoteToToggle: MovingFlowQuotes.AddonQuote) {
suspend fun toggleHomeAddonExclusion(addonId: AddonId) {
movingFlowStorage.editMovingFlowState { existingState ->
existingState.copy(
movingFlowQuotes = existingState.movingFlowQuotes?.copy(
existingState.movingFlowQuotes.homeQuotes.map { homeQuote ->
homeQuote.copy(
relatedAddonQuotes = homeQuote.relatedAddonQuotes.map { addonQuote ->
if (addonQuote == addonQuoteToToggle) {
if (addonQuote.addonId == addonId) {
addonQuote.copy(isExcludedByUser = !addonQuote.isExcludedByUser)
} else {
addonQuote
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ internal class AddHouseInformationPresenter(
apolloClient
.mutation(
MoveIntentV2RequestMutation(
moveIntentId,
inputForSubmissionValue.moveIntentRequestInput,
isAddonFlagEnabled,
intentId = moveIntentId,
moveIntentRequestInput = inputForSubmissionValue.moveIntentRequestInput,
addonsFlagOn = isAddonFlagEnabled,
),
)
.safeExecute()
Expand Down
Loading

0 comments on commit e86c8e6

Please sign in to comment.