-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1886 from HedvigInsurance/feature/fetch-co-insure…
…d-on-ssn Show bottom sheet and fetch co-insured from ssn
- Loading branch information
Showing
18 changed files
with
521 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,6 @@ fragment CoInsuredAgreementFragment on Agreement { | |
lastName | ||
birthdate | ||
ssn | ||
needsMissingInfo | ||
hasMissingInfo | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
app/feature/feature-edit-coinsured/src/main/graphql/QueryPersonalInformation.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
query PersonalInformation($ssn: String!) { | ||
personalInformation(input: { personalNumber: $ssn }) { | ||
firstName | ||
lastName | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...com/hedvig/android/feature/editcoinsured/data/FetchCoInsuredPersonalInformationUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
...rc/main/kotlin/com/hedvig/android/feature/editcoinsured/di/GetCoInsuredUseCaseProvider.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
...main/kotlin/com/hedvig/android/feature/editcoinsured/ui/AddCoInsuredBottomSheetContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.