Skip to content

Conversation

hichamboushaba
Copy link
Member

@hichamboushaba hichamboushaba commented Aug 21, 2025

Closes WOOMOB-873

Description

This PR introduces updated UI for the purchase in-progress and failure screens, and below is a detailed list of the added changes:

  1. Update the purchase in-progress UI to match the web counterpart closely.
  2. Update the purchase failure UI to match the web counterpart closely.
  3. Allow purchasing a new label after an async failure. This is a bug that we had, as the failure was also treated like success, with the only difference being the use of different text, but the whole UI was read-only, and there was no way to retry.
  4. Don't show the green check mark on the shipment tab when the purchase is in progress.
  5. Disable splitting shipments when there is a purchase in progress (to match the web behavior).

Note

Some notes about the changes:

  • The PR appears larger than it's, because GitHub is marking the file ShippingLabelPurchaseStatusSection as a new file, but it's just a renaming of the old file PrintShippingLabelSection, and the file has 423 lines.
  • I included some refactorings that caused the PR to touch more places, it would be better to review them separately:
    • The commit 61dcbc1 updated the logic to introduce ShipmentUI#isReadOnly, and a separate isPurchased, this was needed as previously in progress was treated like success, while it should be just a flag for read-only form.
    • b3ee1f4 I renamed the ShipmentUIModel#purchased to ShipmentUIModel#isPurchasedOrInProgress to better clarify its role.

Important

This PR will be followed by a second PR that:

  • Updates the tracking logic to match iOS, I'll explain more on the PR.
  • Fix an issue with in-progress labels.

Even though the issues above have been here before this PR, it would be better not to merge this until the second PR is done too.

Steps to reproduce

Success
  1. Start creating a new shipping label.
  2. Check the in-progress UI and the success UI.
Failure
  1. To trigger a failure, use the tip that was suggested here p1750956225617989/1750246257.598949-slack-C05VBLKHHV1 (ping me if you need more details)
  2. Buy a new shipping a label.
  3. Check the in-progress and failure UI.

Testing information

  • Confirm the updated UI looks as expected.
  • Confirm that the split button is hidden when there is a purchase in-progress.
  • Confirm that the UI allows you to re-purchase a new label after failure.

The tests that have been performed

The above.

Images/gif

Light Dark
Purchase then success
success.mp4
Screen_recording_20250821_143059.mp4
Purchsae then failure
failure.mp4
Screen_recording_20250821_143024.mp4
  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

And replace it with a single Boolean.
PurchaseState was confusing because it represented only the state for the API request, while the label purchase itself was asynchronous, and given we weren't using any of the states except `InProgress`, a Boolean value is clearer.
We now have two properties to better represent the actual status.
@hichamboushaba hichamboushaba added type: enhancement A request for an enhancement. feature: shipping labels Related to creating, ordering, or printing shipping labels. labels Aug 21, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Aug 21, 2025

1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Aug 21, 2025

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commita27333f
Direct Downloadwoocommerce-wear-prototype-build-pr14498-a27333f.apk

@hichamboushaba hichamboushaba force-pushed the issue/WOOMOB-873-improve-SL-in-progress-UI branch from 005c26c to 972758a Compare August 21, 2025 13:28
@@ -8,22 +8,10 @@ data class ShipmentUIModel(
val localId: String,
val remoteId: String? = null,
val items: List<ShippableItemModel>,
val purchaseState: PurchaseState = PurchaseState.NoStarted,
val isPurchaseAPILoading: Boolean = false,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PurchaseState was confusing, as we already have ShippingLabelStatus that reflects purchase status.
The confusing part here is that the Shipping Label purchase happens in two steps:

  • We make an API request to the backend to trigger the purchase, then the purchase will continue async.
  • We observe the purchase status which is represented by ShippingLabelStatus.

PurchaseState was only used to show the loading UI for the first step, but its other statuses weren't used at all, so I opted to remove it and replace it with the new Boolean isPurchaseAPILoading, I hope the mention of API there makes this less confusing for future code readers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree, this simplification makes it much better.

* A shipment is considered purchased if the label was already purchased or is in the process of being purchased.
*/
val purchased: Boolean
val isPurchasedOrInProgress: Boolean
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the PR description, this change is not related to the PR itself, but an update to clarify the property role.

@@ -39,7 +39,8 @@ data class ShippingLabelModel(
val refund: Refund?,
val products: List<Order.Item> = emptyList(),
val originAddress: Address? = null,
val destinationAddress: Address? = null
val destinationAddress: Address? = null,
val error: String? = null,
Copy link
Member Author

@hichamboushaba hichamboushaba Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't cache this property, as it's used only after a purchase failure.

Comment on lines -707 to +705
if (accountSettings == null || shipments.any { it.purchaseState is PurchaseState.Error }) {
if (accountSettings == null) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition shipments.any { it.purchaseState is PurchaseState.Error } wasn't used at all, as we never set the purchaseState to the Error state.

Comment on lines -972 to +979
handlePurchaseSuccess(it, selectedShipmentIndex)
updateShipment(
selectedShipmentIndex,
shipments.value[selectedShipmentIndex].copy(
isPurchaseAPILoading = false,
label = it.labels.firstOrNull()
)
)
observeShippingLabelPurchaseStatus(selectedShipmentIndex)
// TODO check if we need to track this here or in the observeShippingLabelPurchaseStatus method
analyticsTracker.track(AnalyticsEvent.WCS_PURCHASE_STEP, mapOf(KEY_STATE to "purchase_success"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed handlePurchaseSuccess and moved its logic here, I did this because the Success part of the function was a source of confusion, as this is just an API success, and the label is yet to be purchased.

I'll revisit this in my next PR to see if we can avoid the LongMethod detekt issue.

Comment on lines +978 to +979
// TODO check if we need to track this here or in the observeShippingLabelPurchaseStatus method
analyticsTracker.track(AnalyticsEvent.WCS_PURCHASE_STEP, mapOf(KEY_STATE to "purchase_success"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the tracking issue that I mentioned in the PR description, we track the label as a success before it's actually purchased, this is different than iOS.

@hichamboushaba hichamboushaba marked this pull request as ready for review August 21, 2025 13:51
@hichamboushaba hichamboushaba added the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Aug 21, 2025
@hichamboushaba hichamboushaba requested review from JorgeMucientes and irfano and removed request for JorgeMucientes August 21, 2025 13:51
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Aug 21, 2025

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commita27333f
Direct Downloadwoocommerce-prototype-build-pr14498-a27333f.apk

import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Divider

Check warning

Code scanning / Android Lint

material and material3 are separate, incompatible design system libraries Warning

Using a material import while also using the material3 library
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Divider
import androidx.compose.material.DropdownMenu

Check warning

Code scanning / Android Lint

material and material3 are separate, incompatible design system libraries Warning

Using a material import while also using the material3 library
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Divider
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem

Check warning

Code scanning / Android Lint

material and material3 are separate, incompatible design system libraries Warning

Using a material import while also using the material3 library
import androidx.compose.material.Divider
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Icon

Check warning

Code scanning / Android Lint

material and material3 are separate, incompatible design system libraries Warning

Using a material import while also using the material3 library
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme

Check warning

Code scanning / Android Lint

material and material3 are separate, incompatible design system libraries Warning

Using a material import while also using the material3 library
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text

Check warning

Code scanning / Android Lint

material and material3 are separate, incompatible design system libraries Warning

Using a material import while also using the material3 library
Base automatically changed from issue/WOOMOB-972-new-SL-order-details-UI-2 to trunk August 21, 2025 17:34
Copy link
Contributor

@irfano irfano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! The changes look good. I also tested the API error and status code 500 error, all cases work as expected. LGTM! 👍🏻

@@ -8,22 +8,10 @@ data class ShipmentUIModel(
val localId: String,
val remoteId: String? = null,
val items: List<ShippableItemModel>,
val purchaseState: PurchaseState = PurchaseState.NoStarted,
val isPurchaseAPILoading: Boolean = false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree, this simplification makes it much better.

@hichamboushaba hichamboushaba added this to the 23.2 milestone Aug 22, 2025
@hichamboushaba hichamboushaba removed the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Aug 25, 2025
@hichamboushaba hichamboushaba merged commit e1ac335 into trunk Aug 25, 2025
18 checks passed
@hichamboushaba hichamboushaba deleted the issue/WOOMOB-873-improve-SL-in-progress-UI branch August 25, 2025 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: shipping labels Related to creating, ordering, or printing shipping labels. type: enhancement A request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants