From 376fe2976f4528a68215b8822686cc325941daa6 Mon Sep 17 00:00:00 2001 From: Hugo Linder Date: Wed, 11 Oct 2023 10:36:20 +0200 Subject: [PATCH] Use display items for move quote --- .../MutationMoveIntentRequest.graphql | 4 ++ .../data/ChangeAddressRepository.kt | 18 ++----- .../feature/changeaddress/data/MoveQuote.kt | 22 ++------ .../changeaddress/ui/offer/QuoteCard.kt | 51 ++----------------- 4 files changed, 15 insertions(+), 80 deletions(-) diff --git a/app/apollo/apollo-octopus-public/src/main/graphql/com/hedvig/android/apollo/octopus/graphql/changeaddress/MutationMoveIntentRequest.graphql b/app/apollo/apollo-octopus-public/src/main/graphql/com/hedvig/android/apollo/octopus/graphql/changeaddress/MutationMoveIntentRequest.graphql index 7702e48e69..273c1eaaa2 100644 --- a/app/apollo/apollo-octopus-public/src/main/graphql/com/hedvig/android/apollo/octopus/graphql/changeaddress/MutationMoveIntentRequest.graphql +++ b/app/apollo/apollo-octopus-public/src/main/graphql/com/hedvig/android/apollo/octopus/graphql/changeaddress/MutationMoveIntentRequest.graphql @@ -7,6 +7,10 @@ mutation MoveIntentRequest($intentId: ID!, $input: MoveIntentRequestInput!) { amount currencyCode } + displayItems { + displayValue + displayTitle + } startDate exposureName productVariant { diff --git a/app/feature/feature-changeaddress/src/main/kotlin/com/hedvig/android/feature/changeaddress/data/ChangeAddressRepository.kt b/app/feature/feature-changeaddress/src/main/kotlin/com/hedvig/android/feature/changeaddress/data/ChangeAddressRepository.kt index babbdd3d62..3eda02df10 100644 --- a/app/feature/feature-changeaddress/src/main/kotlin/com/hedvig/android/feature/changeaddress/data/ChangeAddressRepository.kt +++ b/app/feature/feature-changeaddress/src/main/kotlin/com/hedvig/android/feature/changeaddress/data/ChangeAddressRepository.kt @@ -8,6 +8,7 @@ import com.hedvig.android.apollo.toEither import com.hedvig.android.core.common.ErrorMessage import com.hedvig.android.core.ui.insurance.toProductVariant import com.hedvig.android.core.uidata.UiMoney +import kotlinx.collections.immutable.toImmutableList import octopus.MoveIntentCommitMutation import octopus.MoveIntentCreateMutation import octopus.MoveIntentRequestMutation @@ -106,25 +107,14 @@ private fun MoveIntentRequestMutation.Data.MoveIntentRequest.MoveIntent.toMoveQu id = id, insuranceName = quote.exposureName ?: quote.productVariant.displayName, moveIntentId = MoveIntentId(id), -// address = Address( -// id = AddressId(quote.address.id), -// postalCode = quote.address.postalCode, -// street = quote.address.street, -// ), - address = Address(AddressId("1"), postalCode = "", street = ""), -// numberInsured = quote.numberCoInsured?.plus(1) ?: 1, // numberInsured = numberCoInsured + member - numberInsured = 0, premium = UiMoney( amount = quote.premium.amount, currencyCode = quote.premium.currencyCode, ), startDate = quote.startDate, -// ancillaryArea = quote.ancilliaryArea, - ancillaryArea = null, -// yearOfConstruction = quote.yearOfConstruction, - yearOfConstruction = null, -// squareMeters = quote.squareMeters, - squareMeters = null, productVariant = quote.productVariant.toProductVariant(), + displayItems = quote.displayItems + .map { it.displayTitle to it.displayValue } + .toImmutableList(), ) } diff --git a/app/feature/feature-changeaddress/src/main/kotlin/com/hedvig/android/feature/changeaddress/data/MoveQuote.kt b/app/feature/feature-changeaddress/src/main/kotlin/com/hedvig/android/feature/changeaddress/data/MoveQuote.kt index 2ef5aef82b..d1eb93b26a 100644 --- a/app/feature/feature-changeaddress/src/main/kotlin/com/hedvig/android/feature/changeaddress/data/MoveQuote.kt +++ b/app/feature/feature-changeaddress/src/main/kotlin/com/hedvig/android/feature/changeaddress/data/MoveQuote.kt @@ -4,6 +4,7 @@ import com.hedvig.android.core.ui.insurance.ContractType import com.hedvig.android.core.ui.insurance.InsurableLimit import com.hedvig.android.core.ui.insurance.ProductVariant import com.hedvig.android.core.uidata.UiMoney +import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.datetime.LocalDate import octopus.type.CurrencyCode @@ -12,16 +13,13 @@ data class MoveQuote( val id: String, val insuranceName: String, val moveIntentId: MoveIntentId, - val address: Address, - val numberInsured: Int?, val premium: UiMoney, val startDate: LocalDate, - val ancillaryArea: Int?, - val yearOfConstruction: Int?, - val squareMeters: Int?, val productVariant: ProductVariant, val isExpanded: Boolean = false, + val displayItems: ImmutableList>, ) { + companion object { fun PreviewData(index: Int = 0): MoveQuote { @Suppress("NAME_SHADOWING") @@ -30,16 +28,6 @@ data class MoveQuote( id = index.toString(), insuranceName = "Insurance #$index", moveIntentId = MoveIntentId(""), - address = Address( - id = AddressId(""), - apartmentNumber = "1$index", - bbrId = null, - city = null, - floor = null, - postalCode = "124$index", - street = "Froedingsvaegen $index", - ), - numberInsured = index, premium = UiMoney(99.0 * index, CurrencyCode.SEK), startDate = LocalDate(2023, 5, 13), isExpanded = index == 1, @@ -58,9 +46,7 @@ data class MoveQuote( ), documents = persistentListOf(), ), - ancillaryArea = 10, - yearOfConstruction = 1991, - squareMeters = 30, + displayItems = persistentListOf() ) } } diff --git a/app/feature/feature-changeaddress/src/main/kotlin/com/hedvig/android/feature/changeaddress/ui/offer/QuoteCard.kt b/app/feature/feature-changeaddress/src/main/kotlin/com/hedvig/android/feature/changeaddress/ui/offer/QuoteCard.kt index 891a9df186..4e49336f5d 100644 --- a/app/feature/feature-changeaddress/src/main/kotlin/com/hedvig/android/feature/changeaddress/ui/offer/QuoteCard.kt +++ b/app/feature/feature-changeaddress/src/main/kotlin/com/hedvig/android/feature/changeaddress/ui/offer/QuoteCard.kt @@ -168,55 +168,10 @@ private fun ExpandedInformation( quote: MoveQuote, ) { Column { - HorizontalItemsWithMaximumSpaceTaken( - startSlot = { Text(stringResource(id = R.string.CHANGE_ADDRESS_NEW_ADDRESS_LABEL)) }, - endSlot = { Text(quote.address.street, textAlign = TextAlign.End) }, - spaceBetween = 4.dp, - ) - HorizontalItemsWithMaximumSpaceTaken( - startSlot = { Text(stringResource(id = R.string.CHANGE_ADDRESS_NEW_POSTAL_CODE_LABEL)) }, - endSlot = { Text(quote.address.postalCode, textAlign = TextAlign.End) }, - spaceBetween = 4.dp, - ) - quote.squareMeters?.let { - HorizontalItemsWithMaximumSpaceTaken( - startSlot = { Text(stringResource(id = R.string.CHANGE_ADDRESS_NEW_LIVING_SPACE_LABEL)) }, - endSlot = { - Text( - it.toString() + " " + stringResource(id = R.string.CHANGE_ADDRESS_SIZE_SUFFIX), - textAlign = TextAlign.End, - ) - }, - spaceBetween = 4.dp, - ) - } - quote.ancillaryArea?.let { + quote.displayItems.forEach { HorizontalItemsWithMaximumSpaceTaken( - startSlot = { Text(stringResource(id = R.string.CHANGE_ADDRESS_ANCILLARY_AREA_LABEL)) }, - endSlot = { Text(it.toString(), textAlign = TextAlign.End) }, - spaceBetween = 4.dp, - ) - } - quote.yearOfConstruction?.let { - HorizontalItemsWithMaximumSpaceTaken( - startSlot = { Text(stringResource(id = R.string.CHANGE_ADDRESS_YEAR_OF_CONSTRUCTION_LABEL)) }, - endSlot = { Text(it.toString(), textAlign = TextAlign.End) }, - spaceBetween = 4.dp, - ) - } - quote.numberInsured?.let { - HorizontalItemsWithMaximumSpaceTaken( - startSlot = { Text(stringResource(id = R.string.CHANGE_ADDRESS_CO_INSURED_LABEL)) }, - endSlot = { - Text( - if (it == 1) { - stringResource(id = R.string.CHANGE_ADDRESS_ONE_PERSON) - } else { - stringResource(id = R.string.CHANGE_ADDRESS_TOTAL_PERSONS, it) - }, - textAlign = TextAlign.End, - ) - }, + startSlot = { Text(it.first) }, + endSlot = { Text(it.second, textAlign = TextAlign.End) }, spaceBetween = 4.dp, ) }