@W-19347548 feat: Guest users - add modal warning for potential address loss prior to switch to one address toggle action - #3280
Conversation
🎉 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) |
|
|
||
| // Handle toggle between single and multi-shipping | ||
| const handleToggleShippingMode = () => { | ||
| if (isMultiShipping && customer?.isGuest && hasUnpersistedGuestAddresses) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I wonder if it makes more sense to just have a generic onChange handler and a generic: warning your address changes will be lost.
There was a problem hiding this comment.
@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
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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"> |
There was a problem hiding this comment.
How would this look in a mobile layout? With specific values provided here.
There was a problem hiding this comment.
thanks for calling this out, mid-size devices like ipads are good, but need to account for even the smaller form factor of smartphones



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
Changes
How to Test-Drive This PR
Guest with No Addresses (Should NOT show warning)
Expected: No warning modal, toggle works normally
Guest with Saved Addresses (Should NOT show warning)
Expected: No warning modal, toggle works normally
Guest with Unsaved Addresses (Should show warning)
Expected: Warning modal appears
Registered User (Should NOT show warning)
Expected: No warning modal ever (only for guests)
Checklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization