Skip to content

Commit

Permalink
Merge pull request #1886 from HedvigInsurance/feature/fetch-co-insure…
Browse files Browse the repository at this point in the history
…d-on-ssn

Show bottom sheet and fetch co-insured from ssn
  • Loading branch information
hugokallstrom authored Nov 23, 2023
2 parents 618f30b + 4e32fcd commit dd6e943
Show file tree
Hide file tree
Showing 18 changed files with 521 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fragment AgreementFragment on Agreement {
lastName
ssn
birthdate
needsMissingInfo
hasMissingInfo
}
displayItems {
...AgreementDisplayItemFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ fragment CoInsuredAgreementFragment on Agreement {
lastName
birthdate
ssn
needsMissingInfo
hasMissingInfo
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query PersonalInformation($ssn: String!) {
personalInformation(input: { personalNumber: $ssn }) {
firstName
lastName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ internal data class CoInsured(

fun identifier(dateTimeFormatter: DateTimeFormatter): String? =
ssn ?: birthDate?.toJavaLocalDate()?.format(dateTimeFormatter)

companion object {
fun fromPersonalInformation(personalInformation: CoInsuredPersonalInformation, ssn: String): CoInsured = CoInsured(
firstName = personalInformation.firstName,
lastName = personalInformation.lastName,
birthDate = null,
ssn = ssn,
hasMissingInfo = false,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.hedvig.android.feature.editcoinsured.data

import arrow.core.Either
import arrow.core.raise.either
import arrow.core.raise.ensureNotNull
import com.apollographql.apollo3.ApolloClient
import com.hedvig.android.apollo.safeExecute
import com.hedvig.android.apollo.toEither
import com.hedvig.android.core.common.ErrorMessage
import octopus.PersonalInformationQuery

internal interface FetchCoInsuredPersonalInformationUseCase {
suspend fun invoke(ssn: String): Either<ErrorMessage, CoInsuredPersonalInformation>
}

internal class FetchCoInsuredPersonalInformationUseCaseImpl(
private val apolloClient: ApolloClient,
) : FetchCoInsuredPersonalInformationUseCase {
override suspend fun invoke(ssn: String): Either<ErrorMessage, CoInsuredPersonalInformation> = either {
val result = apolloClient.query(PersonalInformationQuery(ssn))
.safeExecute()
.toEither(::ErrorMessage)
.bind()

ensureNotNull(result.personalInformation) {
ErrorMessage("No personal information found")
}

CoInsuredPersonalInformation(
firstName = result.personalInformation.firstName,
lastName = result.personalInformation.lastName,
)
}
}

internal data class CoInsuredPersonalInformation(
val firstName: String,
val lastName: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ internal class GetCoInsuredUseCaseImpl(
CoInsuredError.ContractNotFound
}

val currentCoInsured = contract.currentAgreement.coInsured?.map {
CoInsured(
it.firstName,
it.lastName,
it.birthdate,
it.ssn,
it.needsMissingInfo,
)
val currentCoInsured = contract.let {
it.currentAgreement.coInsured?.map {
CoInsured(
it.firstName,
it.lastName,
it.birthdate,
it.ssn,
it.hasMissingInfo,
)
}
}

CoInsuredResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.hedvig.android.feature.editcoinsured.data
internal data class Member(
val firstName: String,
val lastName: String,
val ssn: String?
val ssn: String?,
) {
val displayName: String = "$firstName $lastName"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@ package com.hedvig.android.feature.editcoinsured.di

import com.apollographql.apollo3.ApolloClient
import com.hedvig.android.apollo.octopus.di.octopusClient
import com.hedvig.android.core.demomode.DemoManager
import com.hedvig.android.feature.editcoinsured.data.FetchCoInsuredPersonalInformationUseCase
import com.hedvig.android.feature.editcoinsured.data.FetchCoInsuredPersonalInformationUseCaseImpl
import com.hedvig.android.feature.editcoinsured.data.GetCoInsuredUseCase
import com.hedvig.android.feature.editcoinsured.data.GetCoInsuredUseCaseImpl
import com.hedvig.android.feature.editcoinsured.ui.EditCoInsuredViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module

val editCoInsuredModule = module {
single<GetCoInsuredUseCaseImpl> {
single<GetCoInsuredUseCase> {
GetCoInsuredUseCaseImpl(
get<ApolloClient>(octopusClient),
)
}

single<GetCoInsuredUseCaseProvider> {
GetCoInsuredUseCaseProvider(
demoManager = get<DemoManager>(),
prodImpl = get<GetCoInsuredUseCaseImpl>(),
demoImpl = get<GetCoInsuredUseCaseImpl>(),
single<FetchCoInsuredPersonalInformationUseCase> {
FetchCoInsuredPersonalInformationUseCaseImpl(
get<ApolloClient>(octopusClient),
)
}

viewModel<EditCoInsuredViewModel> { (contractId: String) ->
EditCoInsuredViewModel(
contractId,
get<GetCoInsuredUseCaseProvider>(),
get<GetCoInsuredUseCase>(),
get<FetchCoInsuredPersonalInformationUseCase>(),
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ fun NavGraphBuilder.editCoInsuredGraph(navigateUp: () -> Unit) {
composable<EditCoInsuredDestination> { backStackEntry ->
EditCoInsuredDestination(
koinViewModel { parametersOf(contractId) },
contractId,
allowEdit,
navigateUp,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.hedvig.android.feature.editcoinsured.ui

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import com.hedvig.android.core.designsystem.component.button.HedvigContainedButton
import com.hedvig.android.core.designsystem.component.button.HedvigTextButton
import com.hedvig.android.core.designsystem.component.textfield.HedvigTextField
import com.hedvig.android.core.designsystem.preview.HedvigPreview
import com.hedvig.android.core.designsystem.theme.HedvigTheme
import com.hedvig.android.feature.editcoinsured.data.CoInsured
import hedvig.resources.R

@Composable
internal fun AddCoInsuredBottomSheetContent(
onSave: (CoInsured) -> Unit,
onFetchInfo: (ssn: String) -> Unit,
onDismiss: () -> Unit,
isLoading: Boolean,
errorMessage: String?,
coInsured: CoInsured?,
) {
var ssn by remember { mutableStateOf("") }

Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.padding(horizontal = 16.dp),
) {
Spacer(Modifier.height(16.dp))
Text(stringResource(id = R.string.CONTRACT_ADD_COINSURED))
Spacer(Modifier.height(24.dp))
HedvigTextField(
value = ssn,
label = {
Text(stringResource(id = R.string.CONTRACT_PERSONAL_IDENTITY))
},
onValueChange = { text: String ->
ssn = text
},
errorText = errorMessage,
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Number,
imeAction = ImeAction.Done,
),
keyboardActions = KeyboardActions(
onDone = {
onFetchInfo(ssn)
},
),
withNewDesign = true,
modifier = Modifier.fillMaxWidth(),
)
AnimatedVisibility(
visible = coInsured != null,
modifier = Modifier.padding(top = 4.dp),
) {
HedvigTextField(
value = coInsured?.displayName ?: "",
onValueChange = {},
label = {
Text(stringResource(id = R.string.FULL_NAME_TEXT))
},
enabled = false,
withNewDesign = true,
modifier = Modifier.fillMaxWidth(),
)
}
Spacer(Modifier.height(16.dp))
HedvigContainedButton(
text = if (coInsured != null) {
stringResource(id = R.string.CONTRACT_ADD_COINSURED)
} else {
stringResource(id = R.string.CONTRACT_SSN_FETCH_INFO)
},
enabled = ssn.isNotBlank(),
onClick = {
if (coInsured != null) {
onSave(coInsured)
} else {
onFetchInfo(ssn)
}
},
isLoading = isLoading,
)
Spacer(Modifier.height(8.dp))
HedvigTextButton(
onClick = onDismiss,
text = stringResource(id = R.string.general_cancel_button),
modifier = Modifier.fillMaxWidth(),
)
Spacer(Modifier.height(32.dp))
}
}

@Composable
@HedvigPreview
private fun AddCoInsuredBottomSheetContentPreview() {
HedvigTheme {
Surface(color = MaterialTheme.colorScheme.background) {
AddCoInsuredBottomSheetContent(
onFetchInfo = {},
onSave = {},
onDismiss = {},
isLoading = false,
coInsured = null,
errorMessage = null,
)
}
}
}

@Composable
@HedvigPreview
private fun AddCoInsuredBottomSheetContentWithCoInsuredPreview() {
HedvigTheme {
Surface(color = MaterialTheme.colorScheme.background) {
AddCoInsuredBottomSheetContent(
onFetchInfo = {},
onSave = {},
onDismiss = {},
isLoading = false,
coInsured = CoInsured(
"Tester",
"Testersson",
birthDate = null,
ssn = "144412022193",
hasMissingInfo = false,
),
errorMessage = null,
)
}
}
}
Loading

0 comments on commit dd6e943

Please sign in to comment.