Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ data class SelectContractForMovingKey(

/**
* Where the user entered the moving flow from. Reported to the backend when the move quotes are requested.
*
* [TERMINATION] is the only entry point the backend treats differently; [INSURANCE] and [OTHER] both end up recorded
* as an insurance-initiated move. Pick [OTHER] for an entry point that is neither the insurance screens nor the
* termination flow, so that the distinction stays available if the backend starts modelling it.
*/
@Serializable
enum class MovingSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal data class MovingFlowState(
// back to that step again
val lastSelectedHomeQuoteId: String?,
val mapOfPropertyStates: Map<HousingType, PropertyState>,
// Defaulted so that a flow which was persisted before this was tracked still deserializes
// Absent for a persisted flow whose entry point was not recorded
val movingSource: MovingSource = MovingSource.OTHER,
) {
@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ internal class MovingFlowRepository(
squareMeters: Int,
numberCoInsured: Int,
isStudent: Boolean,
) {
movingFlowStorage.editMovingFlowState { existingState ->
): MovingFlowState? {
return movingFlowStorage.editMovingFlowState { existingState ->
val updatedState = existingState.copy(
addressInfo = existingState.addressInfo.copy(
street = address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ internal class AddHouseInformationViewModel(
apolloClient: ApolloClient,
backstack: Backstack,
) : MoleculeViewModel<AddHouseInformationEvent, AddHouseInformationUiState>(
Loading,
AddHouseInformationPresenter(
moveIntentId,
movingFlowRepository,
apolloClient,
backstack,
),
)
Loading,
AddHouseInformationPresenter(
moveIntentId,
movingFlowRepository,
apolloClient,
backstack,
),
)

internal class AddHouseInformationPresenter(
private val moveIntentId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import com.hedvig.android.design.system.hedvig.clearFocusOnTap
import com.hedvig.android.design.system.hedvig.datepicker.HedvigDatePicker
import com.hedvig.android.design.system.hedvig.datepicker.HedvigDatePickerImmutableState
import com.hedvig.android.design.system.hedvig.datepicker.getLocale
import com.hedvig.android.feature.movingflow.MovingSource
import com.hedvig.android.feature.movingflow.compose.ConstrainedNumberInput
import com.hedvig.android.feature.movingflow.compose.NoopValidator
import com.hedvig.android.feature.movingflow.compose.ValidatedInput
Expand Down Expand Up @@ -423,7 +422,6 @@ fun PreviewEnterNewAddressScreen() {
EnterNewAddressScreen(
uiState = Content(
moveFromAddressId = "moveFromAddressId",
movingSource = MovingSource.INSURANCE,
movingDate = ValidatedInput(
Clock.System.now().toLocalDateTime(TimeZone.UTC).date,
NoopValidator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ internal class EnterNewAddressViewModel(
apolloClient: ApolloClient,
backstack: Backstack,
) : MoleculeViewModel<EnterNewAddressEvent, EnterNewAddressUiState>(
Loading,
EnterNewAddressPresenter(
moveIntentId,
movingFlowRepository,
apolloClient,
backstack,
),
)
Loading,
EnterNewAddressPresenter(
moveIntentId,
movingFlowRepository,
apolloClient,
backstack,
),
)

private class EnterNewAddressPresenter(
private val moveIntentId: String,
Expand Down Expand Up @@ -130,7 +130,7 @@ private class EnterNewAddressPresenter(
val validContent = content.validate()
if (validContent == null) return@CollectEvents
coroutineScope.launch {
movingFlowRepository.updateWithPropertyInput(
val movingFlowState = movingFlowRepository.updateWithPropertyInput(
movingDate = validContent.movingDate,
address = validContent.address,
postalCode = validContent.postalCode,
Expand All @@ -144,7 +144,11 @@ private class EnterNewAddressPresenter(
}

is Apartment -> {
inputForSubmission = validContent.toInputForSubmission()
if (movingFlowState != null) {
inputForSubmission = validContent.toInputForSubmission(movingFlowState.movingSource)
} else {
submittingInfoFailure = SubmittingInfoFailure.NetworkFailure
}
}
}
}
Expand Down Expand Up @@ -209,7 +213,7 @@ private class EnterNewAddressPresenter(
}
}

private fun ValidContent.toInputForSubmission(): InputForSubmission {
private fun ValidContent.toInputForSubmission(movingSource: MovingSource): InputForSubmission {
return InputForSubmission(
moveIntentRequestInput = MoveIntentRequestInput(
moveToAddress = MoveToAddressInput(
Expand Down Expand Up @@ -266,7 +270,6 @@ internal sealed interface EnterNewAddressUiState {

data class Content(
val moveFromAddressId: String,
val movingSource: MovingSource,
val movingDate: ValidatedInput<LocalDate?, LocalDate, EnterNewAddressValidationError>,
val allowedMovingDateRange: ClosedRange<LocalDate>,
val address: ValidatedInput<String?, String, EnterNewAddressValidationError>,
Expand Down Expand Up @@ -311,7 +314,6 @@ internal sealed interface EnterNewAddressUiState {

private class ValidContent(
val moveFromAddressId: String,
val movingSource: MovingSource,
val movingDate: LocalDate,
val address: String,
val postalCode: String,
Expand All @@ -338,7 +340,6 @@ private fun Content.validate(): ValidContent? {
return either {
ValidContent(
moveFromAddressId = moveFromAddressId,
movingSource = movingSource,
movingDate = movingDate.bind(),
address = address.bind(),
postalCode = postalCode.bind(),
Expand All @@ -364,7 +365,6 @@ private fun Content.validate(): ValidContent? {
private fun MovingFlowState.toContent(): Content {
return Content(
moveFromAddressId = moveFromAddressId,
movingSource = movingSource,
movingDate = ValidatedInput(
initialValue = movingDateState.selectedMovingDate,
validator = { movingDate ->
Expand Down
Loading