Skip to content

@W-19347548 feat: Guest users - add modal warning for potential address loss prior to switch to one address toggle action - #3280

Merged
sf-henry-semaganda merged 17 commits into
developfrom
W-19347548_multi_ship_toggle_warning_modal
Sep 11, 2025
Merged

@W-19347548 feat: Guest users - add modal warning for potential address loss prior to switch to one address toggle action#3280
sf-henry-semaganda merged 17 commits into
developfrom
W-19347548_multi_ship_toggle_warning_modal

Conversation

@sf-henry-semaganda

@sf-henry-semaganda sf-henry-semaganda commented Sep 10, 2025

Copy link
Copy Markdown
Contributor

Description

implemented a warning modal for guest users switching from multi-ship to single-address mode when they have unsaved local addresses

modal_warn.mov

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

  • Created SingleAddressToggleModal - Warning modal component for address loss
  • Implemented onUnsavedGuestAddressesToggleWarning callback - communication between shipping and multi address components

How to Test-Drive This PR

Guest with No Addresses (Should NOT show warning)

  • Go to checkout as guest with 2+ items in cart
  • Go to shipping address step
  • Toggle to "Ship to Multiple Addresses"
  • Toggle back to "Ship to Single Address"
    Expected: No warning modal, toggle works normally

Guest with Saved Addresses (Should NOT show warning)

  • Go to checkout as guest with 2+ items in cart
  • Go to shipping address step
  • Toggle to "Ship to Multiple Addresses"
  • Add addresses and click "Continue to Shipping Method" (saves addresses)
  • Go back to shipping address step
  • Toggle back to "Ship to Single Address"
    Expected: No warning modal, toggle works normally

Guest with Unsaved Addresses (Should show warning)

  • Go to checkout as guest with 2+ items in cart
  • Go to shipping address step
  • Toggle to "Ship to Multiple Addresses"
  • Add addresses but DON'T click "Continue to Shipping Method"
  • Toggle back to "Ship to Single Address"
    Expected: Warning modal appears

Registered User (Should NOT show warning)

  • Login as registered user
  • Follow any of the above scenarios
    Expected: No warning modal ever (only for guests)

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

@cc-prodsec

cc-prodsec commented Sep 10, 2025

Copy link
Copy Markdown
Collaborator

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@sf-henry-semaganda
sf-henry-semaganda marked this pull request as ready for review September 10, 2025 21:47
@sf-henry-semaganda
sf-henry-semaganda requested a review from a team as a code owner September 10, 2025 21:47
Comment thread packages/template-retail-react-app/CHANGELOG.md Outdated
@sf-henry-semaganda sf-henry-semaganda changed the title @W-19347548 feat: add modal warning for potential address loss prior to switch to one address toggle action @W-19347548 feat: Guest users: add modal warning for potential address loss prior to switch to one address toggle action Sep 10, 2025
@sf-henry-semaganda sf-henry-semaganda changed the title @W-19347548 feat: Guest users: add modal warning for potential address loss prior to switch to one address toggle action @W-19347548 feat: Guest users - add modal warning for potential address loss prior to switch to one address toggle action Sep 10, 2025

// Handle toggle between single and multi-shipping
const handleToggleShippingMode = () => {
if (isMultiShipping && customer?.isGuest && hasUnpersistedGuestAddresses) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the logic around hasUnpersistedGuestAddresses here and in the child component seems overly complicated. why not just run the test here? that way it only rns id the shopper actually clicks the button, and we simplify the logic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree, that was my initial implementation, there was a race condition between the hook here (useProductAddressassignemnt hook) and one in multi address, around the unsaved addresses, but I look again, and see if it is feasible

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i see, the child component basket with the new addresses is in a local state var from useProductAddressAssignment so the parent basket ref isn't updated? hmm... yeah, i don't see a good solution. ok.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes exactly, the local addresses present in one of the components i.e multi address was not available or did not reflect in the other - shipping address

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if it makes more sense to just have a generic onChange handler and a generic: warning your address changes will be lost.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@patricksullivansf not sure I understand what you meant sadly but I have trimmed down the function to do just a basic comparison. thoughts?
I am against moving logic to parent (shipping address) as moving the logic to the parent would require the parent to somehow access the child's (shipping multi address) local state, which isn't possible without lifting state up like moving useProductAddressAssignment to parent

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i was thinking with this small wording change "If you switch to one address, ANY shipping addresses you added for the items will be removed." then the entire effect handler driving onUnsavedGuestAddressesToggleWarning could be removed and replaced with an explicit call like `onCreateAddress(adr) => handleCreateAddress(adr), onUnsavedGuestAddressesToggleWarning?.()

@patricksullivansf patricksullivansf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I still think this solution is overly complex, but I'm not going to block it.

closeOnOverlayClick={true}
>
<AlertDialogOverlay />
<AlertDialogContent maxW="448px" w="448px" h="196px" borderRadius="6px">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How would this look in a mobile layout? With specific values provided here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for calling this out, mid-size devices like ipads are good, but need to account for even the smaller form factor of smartphones

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

adjusted.
mobile:
Screenshot 2025-09-11 at 11 38 32 AM

Screenshot 2025-09-11 at 11 38 59 AM

ipad:
Screenshot 2025-09-11 at 11 39 09 AM

@sf-henry-semaganda
sf-henry-semaganda merged commit 57bb51e into develop Sep 11, 2025
42 checks passed
@sf-henry-semaganda
sf-henry-semaganda deleted the W-19347548_multi_ship_toggle_warning_modal branch September 11, 2025 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants