Skip to content

Commit

Permalink
Merge pull request #13640 from woocommerce/issue/add-customs-product-…
Browse files Browse the repository at this point in the history
…details-validation

[Shipping Labels Revamp] Add Customs Shippable product details validation
  • Loading branch information
atorresveiga authored Mar 5, 2025
2 parents e91e3b7 + 4ab5646 commit 9b23bcf
Show file tree
Hide file tree
Showing 8 changed files with 640 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.woocommerce.android.R
import com.woocommerce.android.extensions.handleDialogResult
import com.woocommerce.android.extensions.handleResult
import com.woocommerce.android.extensions.navigateSafely
import com.woocommerce.android.model.Location
import com.woocommerce.android.ui.base.BaseFragment
import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground
import com.woocommerce.android.ui.orders.wooshippinglabels.customs.WooShippingCustomsFormViewModel.ContentType
import com.woocommerce.android.ui.orders.wooshippinglabels.customs.WooShippingCustomsFormViewModel.RestrictionType
import com.woocommerce.android.ui.orders.wooshippinglabels.customs.WooShippingCustomsFormViewModel.ShowContentTypeDialog
import com.woocommerce.android.ui.orders.wooshippinglabels.customs.WooShippingCustomsFormViewModel.ShowCountrySelector
import com.woocommerce.android.ui.orders.wooshippinglabels.customs.WooShippingCustomsFormViewModel.ShowRestrictionTypeDialog
import com.woocommerce.android.ui.searchfilter.SearchFilterItem
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down Expand Up @@ -67,6 +71,8 @@ class WooShippingCustomsFormFragment : BaseFragment() {
.toTypedArray()
)
}

is ShowCountrySelector -> showCountrySearchScreen(event.countries)
}
}
}
Expand All @@ -89,6 +95,10 @@ class WooShippingCustomsFormFragment : BaseFragment() {
.firstOrNull { it.toString() == result }
?.let { viewModel.onRestrictionTypeSelected(it) }
}

handleResult<String>(SELECT_COUNTRY_REQUEST) { countryCode ->
viewModel.onShippableProductOriginCountryChanged(countryCode)
}
}

private fun handleItemSelection(
Expand All @@ -106,8 +116,24 @@ class WooShippingCustomsFormFragment : BaseFragment() {
).let { findNavController().navigateSafely(it) }
}

private fun showCountrySearchScreen(countries: List<Location>) {
val action = WooShippingCustomsFormFragmentDirections.actionSearchFilterFragment(
items = countries.map {
SearchFilterItem(
name = it.name,
value = it.code
)
}.toTypedArray(),
hint = getString(R.string.shipping_label_edit_address_country_search_hint),
requestKey = SELECT_COUNTRY_REQUEST,
title = getString(R.string.shipping_label_edit_address_country)
)
findNavController().navigateSafely(action)
}

companion object {
const val SELECTOR_CONTENT_REQUEST_KEY = "label_customs_content_selector"
const val SELECTOR_RESTRICTION_REQUEST_KEY = "label_customs_restriction_selector"
const val SELECT_COUNTRY_REQUEST = "select_address_country_request"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Checkbox
import androidx.compose.material3.CheckboxDefaults
import androidx.compose.material3.MaterialTheme
Expand All @@ -25,6 +24,7 @@ import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.woocommerce.android.R
import com.woocommerce.android.ui.compose.component.WCColoredButton
import com.woocommerce.android.ui.compose.component.WCOutlinedSpinner
import com.woocommerce.android.ui.compose.component.WCOutlinedTextField
import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground
Expand Down Expand Up @@ -54,7 +54,12 @@ fun WooShippingCustomsFormScreen(viewModel: WooShippingCustomsFormViewModel) {
onOtherContentDetailsInputChanged = viewModel::onOtherContentInputChanged,
onOtherRestrictionDetailsInputChanged = viewModel::onRestrictionDetailsInputChanged,
onReturnToSenderChanged = viewModel::onReturnToSenderChanged,
onProductExpanded = viewModel::onProductExpanded,
onProductExpanded = viewModel::onShippableProductExpanded,
onDescriptionChanged = viewModel::onShippableProductDescriptionChanged,
onTariffChanged = viewModel::onShippableProductTariffNumberChanged,
onValuePerUnitChanged = viewModel::onShippableProductValuePerUnitChanged,
onWeightPerUnitChanged = viewModel::onShippableProductWeightPerUnitChanged,
onCountrySelectorClick = viewModel::onCountrySelectorClick,
onAddCustomsDataClick = viewModel::onAddCustomsDataClick
)
}
Expand All @@ -78,7 +83,12 @@ fun WooShippingCustomsFormScreen(
onReturnToSenderChanged: (Boolean) -> Unit,
onOtherContentDetailsInputChanged: (String) -> Unit,
onOtherRestrictionDetailsInputChanged: (String) -> Unit,
onProductExpanded: (WooShippingCustomsProductUIModel, Boolean) -> Unit,
onProductExpanded: (position: Int, isExpanded: Boolean) -> Unit,
onDescriptionChanged: (position: Int, description: String) -> Unit,
onTariffChanged: (position: Int, tariff: String) -> Unit,
onValuePerUnitChanged: (position: Int, valuePerUnit: String) -> Unit,
onWeightPerUnitChanged: (position: Int, weightPerUnit: String) -> Unit,
onCountrySelectorClick: (position: Int) -> Unit,
onAddCustomsDataClick: () -> Unit

) {
Expand Down Expand Up @@ -174,21 +184,25 @@ fun WooShippingCustomsFormScreen(
style = MaterialTheme.typography.titleMedium,
)

shippingProducts.forEach { product ->
shippingProducts.forEachIndexed { index, product ->
WooShippingCustomsProductListItem(
modifier = modifier.fillMaxWidth(),
itemData = product,
onExpand = { onProductExpanded(product, it) }
onExpand = { onProductExpanded(index, it) },
onDescriptionChanged = { onDescriptionChanged(index, it) },
onTariffChanged = { onTariffChanged(index, it) },
onValuePerUnitChanged = { onValuePerUnitChanged(index, it) },
onWeightPerUnitChanged = { onWeightPerUnitChanged(index, it) },
onCountrySelectorClick = { onCountrySelectorClick(index) }
)
}
}
Button(
WCColoredButton(
modifier = modifier.fillMaxWidth(),
enabled = isAddCustomsButtonEnabled,
onClick = onAddCustomsDataClick
) {
Text(stringResource(id = R.string.woo_shipping_labels_customs_add_missing_information))
}
onClick = onAddCustomsDataClick,
text = stringResource(id = R.string.woo_shipping_labels_customs_add_missing_information)
)
}
}

Expand All @@ -214,6 +228,7 @@ fun PreviewWooShippingCustomsFormScreen() {
valuePerUnit = InputValue.Data("10.00"),
weightPerUnit = InputValue.Data("1.00"),
originCountry = "US",
quantity = 1F,
isExpanded = false
),
WooShippingCustomsProductUIModel(
Expand All @@ -223,6 +238,7 @@ fun PreviewWooShippingCustomsFormScreen() {
valuePerUnit = InputValue.Data("10.00"),
weightPerUnit = InputValue.Data("1.00"),
originCountry = "US",
quantity = 1F,
isExpanded = true
)
),
Expand All @@ -233,7 +249,12 @@ fun PreviewWooShippingCustomsFormScreen() {
onOtherContentDetailsInputChanged = {},
onOtherRestrictionDetailsInputChanged = {},
onProductExpanded = { _, _ -> },
onAddCustomsDataClick = {}
onAddCustomsDataClick = {},
onDescriptionChanged = { _, _ -> },
onTariffChanged = { _, _ -> },
onValuePerUnitChanged = { _, _ -> },
onWeightPerUnitChanged = { _, _ -> },
onCountrySelectorClick = { }
)
}
}
Loading

0 comments on commit 9b23bcf

Please sign in to comment.