BIT-511: Save identity items (#436)

This commit is contained in:
Ramsey Smith
2024-06-20 17:08:07 +01:00
committed by Álison Fernandes
parent f953066f22
commit a2e3984a5e
7 changed files with 329 additions and 19 deletions
@@ -213,6 +213,17 @@ fun LazyListScope.addEditIdentityItems(
.padding(horizontal = 16.dp),
)
}
item {
Spacer(modifier = Modifier.height(8.dp))
BitwardenTextField(
label = stringResource(id = R.string.state_province),
value = identityState.state,
onValueChange = identityItemTypeHandlers.onStateTextChange,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
)
}
item {
Spacer(modifier = Modifier.height(8.dp))
BitwardenTextField(
@@ -462,6 +462,10 @@ class VaultAddItemViewModel @Inject constructor(
handleIdentityCityTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.StateTextChange -> {
handleIdentityStateTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.CompanyTextChange -> {
handleIdentityCompanyTextChange(action)
}
@@ -536,6 +540,12 @@ class VaultAddItemViewModel @Inject constructor(
updateIdentityContent { it.copy(city = action.city) }
}
private fun handleIdentityStateTextChange(
action: VaultAddItemAction.ItemType.IdentityType.StateTextChange,
) {
updateIdentityContent { it.copy(state = action.state) }
}
private fun handleIdentityCompanyTextChange(
action: VaultAddItemAction.ItemType.IdentityType.CompanyTextChange,
) {
@@ -949,6 +959,7 @@ data class VaultAddItemState(
* @property address2 The address2 for the identity item.
* @property address3 The address3 for the identity item.
* @property city The city for the identity item.
* @property state the state for the identity item.
* @property zip The zip for the identity item.
* @property country The country for the identity item.
*/
@@ -969,6 +980,7 @@ data class VaultAddItemState(
val address2: String = "",
val address3: String = "",
val city: String = "",
val state: String = "",
val zip: String = "",
val country: String = "",
) : ItemType() {
@@ -1350,6 +1362,13 @@ sealed class VaultAddItemAction {
*/
data class CityTextChange(val city: String) : IdentityType()
/**
* Fired when the state text input is changed.
*
* @property state The new state text.
*/
data class StateTextChange(val state: String) : IdentityType()
/**
* Fired when the zip text input is changed.
*
@@ -42,6 +42,7 @@ class VaultAddIdentityItemTypeHandlers(
val onAddress2TextChange: (String) -> Unit,
val onAddress3TextChange: (String) -> Unit,
val onCityTextChange: (String) -> Unit,
val onStateTextChange: (String) -> Unit,
val onZipTextChange: (String) -> Unit,
val onCountryTextChange: (String) -> Unit,
) {
@@ -159,6 +160,13 @@ class VaultAddIdentityItemTypeHandlers(
),
)
},
onStateTextChange = { newState ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.StateTextChange(
state = newState,
),
)
},
onZipTextChange = { newZip ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.ZipTextChange(
@@ -14,6 +14,7 @@ import com.bitwarden.core.SecureNoteView
import com.bitwarden.core.UriMatchType
import com.x8bit.bitwarden.data.vault.repository.model.VaultData
import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.platform.base.util.orNullIfBlank
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState
import com.x8bit.bitwarden.ui.vault.feature.vault.VaultState
import java.time.Instant
@@ -160,26 +161,25 @@ private fun VaultAddItemState.ViewState.Content.ItemType.toCardView(): CardView?
private fun VaultAddItemState.ViewState.Content.ItemType.toIdentityView(): IdentityView? =
(this as? VaultAddItemState.ViewState.Content.ItemType.Identity)?.let {
// TODO Create real IdentityView from Content (BIT-508)
IdentityView(
title = null,
firstName = null,
lastName = null,
middleName = null,
address1 = null,
address2 = null,
address3 = null,
city = null,
state = null,
postalCode = null,
country = null,
company = null,
email = null,
phone = null,
ssn = null,
username = null,
passportNumber = null,
licenseNumber = null,
title = it.selectedTitle.name,
firstName = it.firstName.orNullIfBlank(),
lastName = it.lastName.orNullIfBlank(),
middleName = it.middleName.orNullIfBlank(),
address1 = it.address1.orNullIfBlank(),
address2 = it.address2.orNullIfBlank(),
address3 = it.address3.orNullIfBlank(),
city = it.city.orNullIfBlank(),
state = it.state.orNullIfBlank(),
postalCode = it.zip.orNullIfBlank(),
country = it.country.orNullIfBlank(),
company = it.company.orNullIfBlank(),
email = it.email.orNullIfBlank(),
phone = it.phone.orNullIfBlank(),
ssn = it.ssn.orNullIfBlank(),
username = it.username.orNullIfBlank(),
passportNumber = it.passportNumber.orNullIfBlank(),
licenseNumber = it.licenseNumber.orNullIfBlank(),
)
}