Skip to content

Commit

Permalink
Merge pull request #2333 from HedvigInsurance/fix/old-home-insurance-…
Browse files Browse the repository at this point in the history
…duration

GEN-2922 Fix/old home insurance duration
  • Loading branch information
panasetskaya authored Dec 2, 2024
2 parents c4c56bb + 6eddce7 commit d1322de
Show file tree
Hide file tree
Showing 21 changed files with 473 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mutation MoveIntentCreate {
id
street
postalCode
oldAddressCoverageDurationDays
}
}
userError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private fun MoveIntentCreateMutation.Data.MoveIntentCreate.MoveIntent.toMoveInte
maxApartmentNumberCoInsured = maxApartmentNumberCoInsured,
maxHouseNumberCoInsured = maxHouseNumberCoInsured,
extraBuildingTypes = extraBuildingTypes.map { it.toExtraBuildingType() },
oldAddressCoverageDurationDays = this.currentHomeAddresses.firstNotNullOfOrNull { it.oldAddressCoverageDurationDays },
)

private fun MoveIntentRequestMutation.Data.MoveIntentRequest.MoveIntent.toMoveQuotes(): List<MoveQuote> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ internal data class MoveIntent(
val maxApartmentSquareMeters: Int?,
val maxHouseSquareMeters: Int?,
val extraBuildingTypes: List<ExtraBuildingType>,
val oldAddressCoverageDurationDays: Int?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,13 @@ private fun ChangeAddressEnterNewAddressScreen(
)
}
Spacer(modifier = Modifier.height(16.dp))
VectorInfoCard(
text = stringResource(id = R.string.CHANGE_ADDRESS_COVERAGE_INFO_TEXT, 30),
modifier = Modifier.padding(horizontal = 16.dp),
)
Spacer(modifier = Modifier.height(16.dp))
if (uiState.oldAddressCoverageDurationDays != null) {
VectorInfoCard(
text = stringResource(id = R.string.CHANGE_ADDRESS_COVERAGE_INFO_TEXT, uiState.oldAddressCoverageDurationDays),
modifier = Modifier.padding(horizontal = 16.dp),
)
Spacer(modifier = Modifier.height(16.dp))
}
HedvigContainedButton(
text = stringResource(R.string.SAVE_AND_CONTINUE_BUTTON_LABEL),
onClick = onSaveNewAddress,
Expand Down Expand Up @@ -280,7 +282,10 @@ private fun PreviewChangeAddressEnterNewAddressScreen() {
HedvigTheme {
Surface(color = MaterialTheme.colorScheme.background) {
ChangeAddressEnterNewAddressScreen(
EnterNewAddressUiState(datePickerUiState = DatePickerUiState(Locale.ENGLISH, null)),
EnterNewAddressUiState(
datePickerUiState = DatePickerUiState(Locale.ENGLISH, null),
oldAddressCoverageDurationDays = 30,
),
{},
{},
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ internal class EnterNewAddressViewModel(
maxNumberCoInsured = previousParameters.maxNumberCoInsured,
maxSquareMeters = previousParameters.maxSquareMeters,
numberInsured = ValidatedInput(previousParameters.suggestedNumberInsured),
oldAddressCoverageDurationDays = previousParameters.oldAddressCoverageDurationDays,
),
presenter = EnterNewAddressPresenter(
previousParameters,
Expand Down Expand Up @@ -165,6 +166,7 @@ internal data class EnterNewAddressUiState(
val movingDate: ValidatedInput<LocalDate?> = ValidatedInput(null),
val maxNumberCoInsured: Int? = null,
val maxSquareMeters: Int? = null,
val oldAddressCoverageDurationDays: Int? = null,
val navParamsForVillaDestination: MovingParameters? = null,
val navParamsForOfferDestination: MovingParameters? = null,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,13 @@ private fun ChangeAddressEnterVillaInformationScreen(
.padding(horizontal = 16.dp)
.fillMaxWidth(),
)
Spacer(modifier = Modifier.height(16.dp))
VectorInfoCard(
text = stringResource(id = R.string.CHANGE_ADDRESS_COVERAGE_INFO_TEXT, 30),
modifier = Modifier.padding(horizontal = 16.dp),
)
if (uiState.oldAddressCoverageDurationDays != null) {
Spacer(modifier = Modifier.height(16.dp))
VectorInfoCard(
text = stringResource(id = R.string.CHANGE_ADDRESS_COVERAGE_INFO_TEXT, uiState.oldAddressCoverageDurationDays),
modifier = Modifier.padding(horizontal = 16.dp),
)
}
Spacer(modifier = Modifier.height(16.dp))
HedvigContainedButton(
text = stringResource(R.string.SAVE_AND_CONTINUE_BUTTON_LABEL),
Expand All @@ -208,6 +210,7 @@ private fun PreviewChangeAddressEnterVillaInformationScreen() {
ChangeAddressEnterVillaInformationScreen(
EnterVillaInformationUiState(
extraBuildingTypes = listOf(),
oldAddressCoverageDurationDays = 45,
),
{},
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal class EnterVillaInformationViewModel(
) : MoleculeViewModel<EnterVillaInformationEvent, EnterVillaInformationUiState>(
initialState = EnterVillaInformationUiState(
extraBuildingTypes = previousParameters.selectHousingTypeParameters.extraBuildingTypes,
oldAddressCoverageDurationDays = previousParameters.selectHousingTypeParameters.oldAddressCoverageDurationDays,
),
presenter = EnterVillaInformationPresenter(previousParameters = previousParameters),
)
Expand Down Expand Up @@ -103,6 +104,7 @@ internal data class EnterVillaInformationUiState(
val extraBuildings: List<ExtraBuilding> = listOf(),
val isLoading: Boolean = false,
val movingParameters: MovingParameters? = null,
val oldAddressCoverageDurationDays: Int?,
) {
val isHouseInputValid: Boolean
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,28 @@ 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 com.hedvig.android.core.designsystem.component.button.HedvigContainedButton
import com.hedvig.android.core.designsystem.component.card.HedvigCard
import com.hedvig.android.core.designsystem.component.progress.HedvigFullScreenCenterAlignedProgress
import com.hedvig.android.core.designsystem.preview.HedvigPreview
import com.hedvig.android.core.designsystem.theme.HedvigTheme
import com.hedvig.android.core.ui.ValidatedInput
import com.hedvig.android.core.ui.dialog.ErrorDialog
import com.hedvig.android.core.ui.infocard.VectorInfoCard
import com.hedvig.android.core.ui.scaffold.HedvigScaffold
import com.hedvig.android.feature.changeaddress.data.HousingType
import com.hedvig.android.feature.changeaddress.data.HousingType.APARTMENT_OWN
import com.hedvig.android.feature.changeaddress.data.HousingType.APARTMENT_RENT
import com.hedvig.android.feature.changeaddress.data.HousingType.VILLA
import com.hedvig.android.feature.changeaddress.data.MoveIntent
import com.hedvig.android.feature.changeaddress.data.MoveIntentId
import com.hedvig.android.feature.changeaddress.data.displayNameResource
import com.hedvig.android.feature.changeaddress.navigation.SelectHousingTypeParameters
import kotlinx.datetime.LocalDate

@Composable
internal fun SelectHousingTypeDestination(
Expand All @@ -40,15 +47,16 @@ internal fun SelectHousingTypeDestination(
navigateToEnterNewAddressDestination: (SelectHousingTypeParameters) -> Unit,
) {
val uiState: SelectHousingTypeUiState by viewModel.uiState.collectAsStateWithLifecycle()

LaunchedEffect(uiState.navigationParameters) {
val params = uiState.navigationParameters
if (params != null) {
viewModel.emit(SelectHousingTypeEvent.ClearNavigationParameters)
navigateToEnterNewAddressDestination(params)
val state = uiState
if (state is SelectHousingTypeUiState.Content) {
LaunchedEffect(state.navigationParameters) {
val params = state.navigationParameters
if (params != null) {
viewModel.emit(SelectHousingTypeEvent.ClearNavigationParameters)
navigateToEnterNewAddressDestination(params)
}
}
}

ChangeAddressSelectHousingTypeScreen(
uiState = uiState,
navigateUp = navigateUp,
Expand Down Expand Up @@ -76,22 +84,38 @@ private fun ChangeAddressSelectHousingTypeScreen(
onHousingTypeErrorDialogDismissed: () -> Unit,
onErrorDialogDismissed: () -> Unit,
) {
uiState.errorMessageRes?.let {
ErrorDialog(
when (uiState) {
is SelectHousingTypeUiState.Content -> SelectHousingTypeContentScreen(
uiState = uiState,
navigateUp = navigateUp,
onHousingTypeSelected = onHousingTypeSelected,
onHousingTypeSubmitted = onHousingTypeSubmitted,
onHousingTypeErrorDialogDismissed = onHousingTypeErrorDialogDismissed,
)
is SelectHousingTypeUiState.Error -> ErrorDialog(
title = stringResource(hedvig.resources.R.string.general_error),
message = stringResource(it),
onDismiss = { onHousingTypeErrorDialogDismissed() },
message = uiState.errorMessage,
onDismiss = { onErrorDialogDismissed() },
)
SelectHousingTypeUiState.Loading -> HedvigFullScreenCenterAlignedProgress()
}
}

uiState.errorMessage?.let {
@Composable
private fun SelectHousingTypeContentScreen(
uiState: SelectHousingTypeUiState.Content,
navigateUp: () -> Unit,
onHousingTypeSelected: (HousingType) -> Unit,
onHousingTypeSubmitted: () -> Unit,
onHousingTypeErrorDialogDismissed: () -> Unit,
) {
uiState.errorMessageRes?.let {
ErrorDialog(
title = stringResource(hedvig.resources.R.string.general_error),
message = it,
onDismiss = { onErrorDialogDismissed() },
message = stringResource(it),
onDismiss = { onHousingTypeErrorDialogDismissed() },
)
}

HedvigScaffold(
navigateUp = navigateUp,
) {
Expand All @@ -112,15 +136,20 @@ private fun ChangeAddressSelectHousingTypeScreen(
Spacer(modifier = Modifier.height(8.dp))
RadioButton(VILLA, uiState.housingType.input, onHousingTypeSelected)
Spacer(modifier = Modifier.height(16.dp))
VectorInfoCard(
text = stringResource(id = hedvig.resources.R.string.CHANGE_ADDRESS_COVERAGE_INFO_TEXT, 30),
modifier = Modifier.padding(horizontal = 16.dp),
)
Spacer(modifier = Modifier.height(16.dp))
if (uiState.oldHomeInsuranceDuration != null) {
VectorInfoCard(
text = stringResource(
id = hedvig.resources.R.string.CHANGE_ADDRESS_COVERAGE_INFO_TEXT,
uiState.oldHomeInsuranceDuration,
),
modifier = Modifier.padding(horizontal = 16.dp),
)
Spacer(modifier = Modifier.height(16.dp))
}
HedvigContainedButton(
text = stringResource(id = hedvig.resources.R.string.general_continue_button),
onClick = onHousingTypeSubmitted,
isLoading = uiState.isLoading,
isLoading = uiState.isButtonLoading,
modifier = Modifier.padding(horizontal = 16.dp),
)
Spacer(Modifier.height(16.dp))
Expand Down Expand Up @@ -162,11 +191,13 @@ private fun RadioButton(

@HedvigPreview
@Composable
private fun PreviewChangeAddressSelectHousingTypeScreen() {
private fun PreviewChangeAddressSelectHousingTypeScreen(
@PreviewParameter(SelectHousingTypeUiStateProvider::class) state: SelectHousingTypeUiState,
) {
HedvigTheme {
Surface(color = MaterialTheme.colorScheme.background) {
ChangeAddressSelectHousingTypeScreen(
SelectHousingTypeUiState(),
state,
{},
{},
{},
Expand All @@ -176,3 +207,46 @@ private fun PreviewChangeAddressSelectHousingTypeScreen() {
}
}
}

private class SelectHousingTypeUiStateProvider : CollectionPreviewParameterProvider<SelectHousingTypeUiState>(
listOf(
SelectHousingTypeUiState.Error("Unknown"),
SelectHousingTypeUiState.Loading,
SelectHousingTypeUiState.Content(
housingType = ValidatedInput(APARTMENT_OWN),
moveIntent = MoveIntent(
id = MoveIntentId("id"),
movingDateRange = LocalDate(2024, 11, 5)..LocalDate(2024, 12, 31),
maxHouseNumberCoInsured = null,
maxHouseSquareMeters = null,
maxApartmentNumberCoInsured = null,
maxApartmentSquareMeters = null,
isApartmentAvailableforStudent = null,
extraBuildingTypes = listOf(),
currentHomeAddresses = listOf(),
suggestedNumberInsured = 2,
oldAddressCoverageDurationDays = 30,
),
oldHomeInsuranceDuration = 30,
navigationParameters = null,
),
SelectHousingTypeUiState.Content(
housingType = ValidatedInput(APARTMENT_OWN),
moveIntent = MoveIntent(
id = MoveIntentId("id"),
movingDateRange = LocalDate(2024, 11, 5)..LocalDate(2024, 12, 31),
maxHouseNumberCoInsured = null,
maxHouseSquareMeters = null,
maxApartmentNumberCoInsured = null,
maxApartmentSquareMeters = null,
isApartmentAvailableforStudent = null,
extraBuildingTypes = listOf(),
currentHomeAddresses = listOf(),
suggestedNumberInsured = 2,
oldAddressCoverageDurationDays = null,
),
oldHomeInsuranceDuration = null,
navigationParameters = null,
),
),
)
Loading

0 comments on commit d1322de

Please sign in to comment.