-
Notifications
You must be signed in to change notification settings - Fork 134
[Shipping labels] Improve address validation errors #14468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
irfano
merged 19 commits into
trunk
from
issue/WOOMOB-904-improve-address-validation-errors
Aug 20, 2025
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cb4ff85
Make NormalizationResponseDTO parameters nullable
irfano 2959c0b
Add errors to address normalization model
irfano d198fe5
Handle errors parameter for normalizeAddress in the repository
irfano 4f63487
Refactor NormalizeAddress error constants
irfano 8c4b9b3
Refactor NormalizeAddressException to support multiple errors
irfano f363a1f
Refactor address normalization error handling
irfano 68ee7b9
Refactor AddressStatus to be a sealed class
irfano 0103472
Improve address normalization error handling and analytics
irfano cab0e5d
Update address with normalize exception
irfano 3ac3773
Update address status according to normalize exception
irfano 61893fb
Update getErrorState() logic to handle new normalize exception
irfano b62508d
Shorten WooShippingEditAddressViewModel.kt class
irfano 4b1fc71
Update RELEASE-NOTES.txt
irfano 0a60b8b
Merge branch 'trunk' into issue/WOOMOB-904-improve-address-validation…
irfano 3feefd5
Merge branch 'trunk' into issue/WOOMOB-904-improve-address-validation…
irfano debbc11
Display individual field errors for address normalization API
irfano f42c834
Merge branch 'trunk' into issue/WOOMOB-904-improve-address-validation…
irfano 8577a2b
Merge branch 'trunk' into issue/WOOMOB-904-improve-address-validation…
irfano 105114e
Merge branch 'trunk' into issue/WOOMOB-904-improve-address-validation…
irfano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
104 changes: 104 additions & 0 deletions
104
...otlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/EditAddressViewState.kt
This file contains hidden or 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,104 @@ | ||
package com.woocommerce.android.ui.orders.wooshippinglabels.address | ||
|
||
import com.woocommerce.android.extensions.isNotNullOrEmpty | ||
import com.woocommerce.android.model.Address | ||
import com.woocommerce.android.model.AmbiguousLocation | ||
import com.woocommerce.android.model.Location | ||
import com.woocommerce.android.ui.orders.wooshippinglabels.models.AddressNormalizationModel | ||
|
||
data class EditAddressViewState( | ||
val isCompanyExpanded: Boolean, | ||
val editableAddress: EditableAddress, | ||
val loading: LoadingState, | ||
val error: EditAddressError?, | ||
val shouldUseStatesInput: Boolean, | ||
val addressStatus: AddressStatus, | ||
val addressValidationState: AddressValidationState | ||
) | ||
|
||
sealed class LoadingState { | ||
data object Hidden : LoadingState() | ||
data class DisplayLoading(val title: String, val message: String) : LoadingState() | ||
} | ||
|
||
data class EditAddressError(val message: String, val isIndefinite: Boolean = true, val onRetry: () -> Unit) | ||
|
||
sealed class AddressStatus { | ||
data object Verified : AddressStatus() | ||
data object Unverified : AddressStatus() | ||
data object MissingAddress : AddressStatus() | ||
data object MissingInfo : AddressStatus() | ||
data object SaveChanges : AddressStatus() | ||
data class VerifyFailed(val exception: NormalizeAddressException? = null) : AddressStatus() | ||
} | ||
|
||
sealed class AddressValidationState { | ||
data object NotStarted : AddressValidationState() | ||
data object VerifyingAddress : AddressValidationState() | ||
data class VerificationFailed( | ||
val editableAddress: EditableAddress, | ||
val exception: NormalizeAddressException? = null, | ||
) : AddressValidationState() | ||
|
||
data class AddressSelection( | ||
val addressNormalization: AddressNormalizationModel, | ||
val selectedAddress: Address | ||
) : AddressValidationState() | ||
|
||
data object UpdatingAddress : AddressValidationState() | ||
data class AddressUpdateFailed( | ||
val editableAddress: EditableAddress | ||
) : AddressValidationState() | ||
|
||
data class NormalizedAddressUpdateFailed( | ||
val selection: AddressSelection, | ||
) : AddressValidationState() | ||
} | ||
|
||
data class EditableAddress( | ||
val name: InputValue = InputValue.EMPTY, | ||
val company: InputValue = InputValue.EMPTY, | ||
val country: Location = Location.EMPTY, | ||
val address: InputValue = InputValue.EMPTY, | ||
val city: InputValue = InputValue.EMPTY, | ||
val state: Location = Location.EMPTY, | ||
val postalCode: InputValue = InputValue.EMPTY, | ||
val email: InputValue = InputValue.EMPTY, | ||
val phone: InputValue = InputValue.EMPTY | ||
) { | ||
val hasIncorrectOrMissingData: Boolean | ||
get() = address.error.isNotNullOrEmpty() || | ||
city.error.isNotNullOrEmpty() || | ||
postalCode.error.isNotNullOrEmpty() || | ||
email.error.isNotNullOrEmpty() || | ||
phone.error.isNotNullOrEmpty() || | ||
name.error.isNotNullOrEmpty() || | ||
company.error.isNotNullOrEmpty() | ||
} | ||
|
||
fun EditableAddress.toAddress() = Address( | ||
firstName = name.value, | ||
lastName = "", | ||
company = company.value, | ||
address1 = address.value, | ||
address2 = "", | ||
city = city.value, | ||
state = AmbiguousLocation.Defined(state), | ||
postcode = postalCode.value, | ||
country = country, | ||
email = email.value, | ||
phone = phone.value | ||
) | ||
|
||
data class InputValue(val value: String, val error: String? = null, val isRequired: Boolean = false) { | ||
companion object { | ||
val EMPTY = InputValue("") | ||
} | ||
} | ||
|
||
sealed class LocationState { | ||
data object Loading : LocationState() | ||
data object DisplayLoading : LocationState() | ||
data object Error : LocationState() | ||
data class Loaded(val locations: List<Location>) : LocationState() | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed
site.getOrNull()
tosite.get()
to align with the approach we use for our domain classes in the shipping label screens.